OpenGL 和 GLM:如何将矩阵数组发送到 GLSL

OpenGL and GLM: How to send a matrices array to GLSL

我有这个代码:

GLuint joint = shader->getUniform("jointTransforms"); //this is always 0
glUniformMatrix4fv(joint, MAX_JOINT_COUNT, GL_FALSE, glm::value_ptr(rotations[0]));

并且在我的着色器中有一个像这样的统一数组:

uniform mat4 jointTransforms[MAX_JOINT_COUNT];

问题是,着色器根本没有接收到任何数据。 我错过了什么?

提前致谢

这很好用:

GLuint id_bound_program;

void TextureMgr::bind_program( GLuint id_prog ) { 
    if( id_prog == id_bound_program ) {
        return;
    }

    id_bound_program = id_prog;
    glUseProgram( id_prog );
}

void TextureMgr::update_uniform( GLuint id_program, std::string const & name_uniform, glm::mat4 const & value ) { 
    bind_program( id_program );
    glUniformMatrix4fv( glGetUniformLocation( id_program, name_uniform.c_str( ) ), 1, GL_FALSE, glm::value_ptr( value ) );
}

如果没有关于您的程序的更多信息 - shader->getUniform 的内容 - 以及您的着色器程序的内部结构,我无法给您更好的答案。

很可能你没有先绑定你的程序。