In the OpenGL program, after linking the shader program, use the following steps to assign data to the uniform block in the fragment shader:
- Get the index of the uniform block using glGetUniformBlockIndex:
GLuint blockIndex = glGetUniformBlockIndex(programHandle, "BlobSettings");
- Allocate space for the buffer to contain the data for the uniform block. We get the size using glGetActiveUniformBlockiv:
GLint blockSize; glGetActiveUniformBlockiv(programHandle, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE, &blockSize); GLubyte * blockBuffer; blockBuffer = (GLubyte *) malloc(blockSize);
- Query for the offset of each variable within the block. To do so, we first find the index of each variable within the block:
const GLchar *names[] ...