revert workaround made for #1368, doesn't work on (certain) Intel chipsets. Instead, limit the maximum bone count to 64 so to meet the limit of 1024 uniform components by certain graphics cards (#1285)

Controls
Tobias Zwick 2015-08-08 19:11:35 +02:00
parent a45c865be1
commit f57bfa089c
4 changed files with 11 additions and 46 deletions

View File

@ -15,11 +15,7 @@
// Default Vertex Shader for mesh-based objects.
// Input uniforms, if OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS is NOT defined:
// bones: array of 4x3 bone transformation matrices.
// Input uniforms, if OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS is defined:
// bones: array of 3x4 transposed bone transformation matrices.
// Input uniforms:
// Input vertex attributes:
// oc_BoneWeights0 and oc_BoneWeight1: vectors of bone influence weights.
@ -34,15 +30,11 @@
// inside the bone matrix array that contains the identity matrix, with a bone
// weight of 1.0.
#define MAX_BONE_COUNT 80
#define MAX_BONE_COUNT 64
varying vec3 normalDir;
#ifndef OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS
uniform mat4x3 bones[MAX_BONE_COUNT];
#else
uniform mat3x4 bones[MAX_BONE_COUNT];
#endif
uniform mat4 bones[MAX_BONE_COUNT];
// For more performance, this should be set by the engine, and this shader
// should be compiled three times: with BONE_COUNT set to 0, 4, and 8,
@ -57,17 +49,10 @@ attribute vec4 oc_BoneIndices1;
attribute vec4 oc_BoneWeights1;
#endif
#ifndef OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS
vec4 merge_bone(vec4 vertex, vec4 original, mat4x3 bone, float weight)
vec4 merge_bone(vec4 vertex, vec4 original, mat4 bone, float weight)
{
return (mat4(bone) * original) * weight + vertex;
return (bone * original) * weight + vertex;
}
#else
vec4 merge_bone(vec4 vertex, vec4 original, mat3x4 bone, float weight)
{
return (mat4(transpose(bone)) * original) * weight + vertex;
}
#endif
slice(position)
{

View File

@ -260,15 +260,6 @@ CStdGLCtx *CStdGL::CreateContext(C4Window * pWindow, C4AbstractApp *pApp)
LogSilentF("GLExt: %s", gl_extensions ? gl_extensions : "");
}
}
// Check which workarounds we have to apply
{
// If we have less than 2048 uniform components available, we
// need to upload bone matrices in a different way
GLint count;
glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &count);
Workarounds.LowMaxVertexUniformCount = count < 2048;
}
}
if (!success)
{
@ -828,7 +819,6 @@ void CStdGL::Default()
iPixelFormat=0;
sfcFmt=0;
iClrDpt=0;
Workarounds.LowMaxVertexUniformCount = false;
}
#endif // USE_CONSOLE

View File

@ -190,11 +190,6 @@ public:
C4Shader* GetSpriteShader(int ssc);
C4Shader* GetSpriteShader(bool haveBase, bool haveOverlay, bool haveNormal);
struct
{
bool LowMaxVertexUniformCount;
} Workarounds;
protected:
bool CreatePrimarySurfaces(unsigned int iXRes, unsigned int iYRes, int iColorDepth, unsigned int iMonitor);

View File

@ -128,10 +128,7 @@ namespace
);
}
if (pGL->Workarounds.LowMaxVertexUniformCount)
return StdStrBuf("#define OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS\n") + buf;
else
return buf;
return buf;
}
// Note this only gets the code which inserts the slices specific for the pass
@ -477,7 +474,7 @@ namespace
// Or, even better, we could upload them into a UBO, but Intel doesn't support them prior to Sandy Bridge.
struct BoneTransform
{
float m[3][4];
float m[4][4];
};
std::vector<BoneTransform> bones;
if (mesh_instance.GetBoneCount() == 0)
@ -486,7 +483,7 @@ namespace
static const BoneTransform dummy_bone = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f
0.0f, 0.0f, 1.0f, 1.0f
};
bones.push_back(dummy_bone);
}
@ -499,7 +496,8 @@ namespace
BoneTransform cooked_bone = {
bone(0, 0), bone(0, 1), bone(0, 2), bone(0, 3),
bone(1, 0), bone(1, 1), bone(1, 2), bone(1, 3),
bone(2, 0), bone(2, 1), bone(2, 2), bone(2, 3)
bone(2, 0), bone(2, 1), bone(2, 2), bone(2, 3),
0, 0, 0, 1
};
bones.push_back(cooked_bone);
}
@ -624,10 +622,7 @@ namespace
// Upload the current bone transformation matrixes (if there are any)
if (!bones.empty())
{
if (pGL->Workarounds.LowMaxVertexUniformCount)
glUniformMatrix3x4fv(shader->GetUniform(C4SSU_Bones), bones.size(), GL_FALSE, &bones[0].m[0][0]);
else
glUniformMatrix4x3fv(shader->GetUniform(C4SSU_Bones), bones.size(), GL_TRUE, &bones[0].m[0][0]);
call.SetUniformMatrix4x4fv(C4SSU_Bones, bones.size(), &bones[0].m[0][0]);
}
// Bind the vertex data of the mesh