我确实在为我的OpenGL应用程序设置动画着色器时遇到了一些麻烦。基本上它需要一个50 glm :: mat4矩阵的数组,并且应该在我的GLSL着色器中将它们设置为统一。然而,只有第一个值实际发送到着色器,着色器中的所有其他数组条目都设置为0.
我认为从C ++传递到GLSL时会出现问题:
class model{
...
glm::mat4 finalBoneTransforms[50];
...
}
model::draw(){
//Set Joints
int jointLoc = glGetUniformLocation(shaderID, "jointTransforms");
glUniformMatrix4fv(jointLoc, 50 , GL_FALSE, glm::value_ptr(finalBoneTransforms[0]));
...
}
那么为什么只传递第一个值呢?不应该将OpenGL存储在连续内存中的50个元素接收到第一个元素,这个元素是通过value_ptr引用的吗? 我更倾向于使用数组而不是向量来确保不会因重新分配而遭受任何指针丢失。数组中的非元素存储在连续的内存中?还有其他明显错误导致这种奇怪的行为吗?
编辑:下面是着色器代码:
#version 330 core
const int MAX_JOINTS = 50;
const int MAX_WEIGHTS = 4;
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormals;
layout (location = 2) in vec2 aTexCoord;
layout (location = 3) in vec4 aBoneWeight;
layout (location = 4) in ivec4 aBoneIndex;
out vec2 texCoords;
uniform mat4 jointTransforms[MAX_JOINTS];
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main(void) {
vec4 totalLocalPos = vec4(0.0);
vec4 totalNormal = vec4(0.0);
for (int i = 0; i<MAX_WEIGHTS; i++) {
mat4 jointTransform = jointTransforms[aBoneIndex[i]];
vec4 posePosition = jointTransform * vec4(aPos, 1.0);
totalLocalPos += posePosition * aBoneWeight[i];
}
gl_Position = projection*view * totalLocalPos;
texCoords = aTexCoord;
};