Search code examples
c++openglglslglm-math

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


I have this code:

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

And in my shader a uniform array like this:

uniform mat4 jointTransforms[MAX_JOINT_COUNT];

The problem is, that the shader is not receiving any data at all. What am I missing?

Thanks in advance


Solution

  • This works fine:

    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 ) );
    }
    

    Without more information about your program - the contents of shader->getUniform - and the innards of your shader program, I cannot give you a better answer.

    Odds are you did not bind your program first.