I uploaded the two matrixs data in the UBO i created, but now i don’t know how to bind these two matrix to the uniforms inside the uniform block.
I have this code to make a Program:
m_program = new CGLProgram();
m_program->AttachShader("recursos/shaders/simple.vert",GL_VERTEX_SHADER);
m_program->Link();
m_program->AttachShader("recursos/shaders/simple.frag",GL_FRAGMENT_SHADER);
m_program->Link();
m_program->Bind_Attribute_Location(0,"in_Position");
GLuint l_block_index = glGetUniformBlockIndex(m_program->m_ID,"MatriusGlobals");
//HERE I DON'T KNOW HOW TO BIND THE UNIFORM BUFFER WITH THE PROGRAM
glUniformBlockBinding(??????????????????????????????)
m_program->Use();
Can anyone explain me how to use glGetUniformBlockIndex and glUniformBlockBinding ? Reading the spec = more mess in my head…
This is not valid code, so I don’t know how it compiles. glBindBufferRange takes five parameters, not three. It needs the offset into the buffer object (in your case, 0), and the maximum size that this uniform block takes (in your case, sizeof(glm::mat4) * 2).
But this not answers my question at all. All I’m doing here is binding the entire UBO to the uniform block of a VBO. What i want to try is to bind only a part (a Matrix only) of the UBO to a uniform variable inside of the VBO uniform block.
Could you provide an example and which functions will I need? Thank you
But this not answers my question at all. All I’m doing here is binding the entire UBO to the uniform block of a VBO. What i want to try is to bind only a part (a Matrix only) of the UBO to a uniform variable inside of the VBO uniform block.
First, a word on terminology.
There are Buffer Objects. These are GPU-allocated linear memory arrays that store arbitrary data.
“Vertex buffer object” is what you call a buffer object when you are using it to store vertex data. “Uniform buffer object” is what you call a buffer object when you use it to store uniform data. There’s nothing stopping you from using a buffer object to store both at the same time. And there’s certainly no such thing as a “VBO uniform block”.
Now that that’s out of the way, what you want is not possible. A uniform block has its data defined by a buffer object. That’s what it is for. You cannot have part of the data of a uniform block come from one buffer and part of it come from another. If you want to have one matrix come from one buffer object and the other matrix come from another, then you need to put them in two separate uniform blocks.