Skip to content

Commit

Permalink
Implement glGetActiveUniformBlockiv(GL_UNIFORM_BLOCK_NAME_LENGTH) and…
Browse files Browse the repository at this point in the history
… add a test. Closes #4514.
  • Loading branch information
juj committed Sep 2, 2016
1 parent c04ab7f commit 0cdefa6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/library_gl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2039,14 +2039,21 @@ var LibraryGL = {
#endif
program = GL.programs[program];

var result = GLctx['getActiveUniformBlockParameter'](program, uniformBlockIndex, pname);
if (!result) return; // If an error occurs, nothing will be written to params.
if (typeof result == 'number') {
{{{ makeSetValue('params', '0', 'result', 'i32') }}};
} else {
for (var i = 0; i < result.length; i++) {
{{{ makeSetValue('params', 'i*4', 'result[i]', 'i32') }}};
}
switch(pname) {
case 0x8A41: /* GL_UNIFORM_BLOCK_NAME_LENGTH */
var name = GLctx['getActiveUniformBlockName'](program, uniformBlockIndex);
{{{ makeSetValue('params', 0, 'name.length+1', 'i32') }}};
return;
default:
var result = GLctx['getActiveUniformBlockParameter'](program, uniformBlockIndex, pname);
if (!result) return; // If an error occurs, nothing will be written to params.
if (typeof result == 'number') {
{{{ makeSetValue('params', '0', 'result', 'i32') }}};
} else {
for (var i = 0; i < result.length; i++) {
{{{ makeSetValue('params', 'i*4', 'result[i]', 'i32') }}};
}
}
}
},

Expand Down
28 changes: 27 additions & 1 deletion tests/webgl2_ubos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,33 @@ int main()
glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &maxLength);
printf("GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: %d\n", maxLength);
assert(maxLength == 12);
glUseProgram(program);

GLint numActiveUniformBlocks = -1;
glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &numActiveUniformBlocks);
assert(numActiveUniformBlocks == 3);

// Dump all active uniform buffer blocks of the current program.
for(int i = 0; i < numActiveUniformBlocks; ++i)
{
char str[256] = {};
GLsizei length = -1;
glGetActiveUniformBlockName(program, i, 255, &length, str);
assert(length > 0);
printf("Active uniform block at index %d: %s\n", i, str);

GLint param = -1;
#define DUMPUNIFORMBLOCKSTATUS(stat) glGetActiveUniformBlockiv(program, i, stat, &param); printf("%s: %d\n", #stat, param);
DUMPUNIFORMBLOCKSTATUS(GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER);
DUMPUNIFORMBLOCKSTATUS(GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER);
DUMPUNIFORMBLOCKSTATUS(GL_UNIFORM_BLOCK_BINDING);
DUMPUNIFORMBLOCKSTATUS(GL_UNIFORM_BLOCK_DATA_SIZE);
DUMPUNIFORMBLOCKSTATUS(GL_UNIFORM_BLOCK_NAME_LENGTH);
DUMPUNIFORMBLOCKSTATUS(GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS);
GLint indices[16] = {};
glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, indices);
for(size_t i = 0; i < param; ++i)
printf("offset for index %d: %d\n", i, indices[i]);
}

#ifdef REPORT_RESULT
REPORT_RESULT();
Expand Down

0 comments on commit 0cdefa6

Please sign in to comment.