Revert "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)"

This reverts commit f57bfa089c.

This was committed by mistake. Fixes #1375.
shapetextures
Armin Burgmeier 2015-09-03 20:38:53 -04:00
parent 5f4978d3e6
commit db29160fea
4 changed files with 46 additions and 11 deletions

View File

@ -15,7 +15,11 @@
// Default Vertex Shader for mesh-based objects.
// Input uniforms:
// 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 vertex attributes:
// oc_BoneWeights0 and oc_BoneWeight1: vectors of bone influence weights.
@ -30,11 +34,15 @@
// inside the bone matrix array that contains the identity matrix, with a bone
// weight of 1.0.
#define MAX_BONE_COUNT 64
#define MAX_BONE_COUNT 80
varying vec3 normalDir;
uniform mat4 bones[MAX_BONE_COUNT];
#ifndef OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS
uniform mat4x3 bones[MAX_BONE_COUNT];
#else
uniform mat3x4 bones[MAX_BONE_COUNT];
#endif
// 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,
@ -49,10 +57,17 @@ attribute vec4 oc_BoneIndices1;
attribute vec4 oc_BoneWeights1;
#endif
vec4 merge_bone(vec4 vertex, vec4 original, mat4 bone, float weight)
#ifndef OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS
vec4 merge_bone(vec4 vertex, vec4 original, mat4x3 bone, float weight)
{
return (bone * original) * weight + vertex;
return (mat4(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,6 +260,15 @@ 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)
{
@ -819,6 +828,7 @@ void CStdGL::Default()
iPixelFormat=0;
sfcFmt=0;
iClrDpt=0;
Workarounds.LowMaxVertexUniformCount = false;
}
#endif // USE_CONSOLE

View File

@ -190,6 +190,11 @@ 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,7 +128,10 @@ namespace
);
}
return buf;
if (pGL->Workarounds.LowMaxVertexUniformCount)
return StdStrBuf("#define OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS\n") + buf;
else
return buf;
}
// Note this only gets the code which inserts the slices specific for the pass
@ -474,7 +477,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[4][4];
float m[3][4];
};
std::vector<BoneTransform> bones;
if (mesh_instance.GetBoneCount() == 0)
@ -483,7 +486,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, 1.0f
0.0f, 0.0f, 1.0f, 0.0f
};
bones.push_back(dummy_bone);
}
@ -496,8 +499,7 @@ 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),
0, 0, 0, 1
bone(2, 0), bone(2, 1), bone(2, 2), bone(2, 3)
};
bones.push_back(cooked_bone);
}
@ -622,7 +624,10 @@ namespace
// Upload the current bone transformation matrixes (if there are any)
if (!bones.empty())
{
call.SetUniformMatrix4x4fv(C4SSU_Bones, bones.size(), &bones[0].m[0][0]);
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]);
}
// Bind the vertex data of the mesh