void GLshader::print_subroutines() { int maxSub,maxSubU,countActiveSU; char name[256]; int len, numCompS; GL_ASSERT(glGetIntegerv(GL_MAX_SUBROUTINES, &maxSub)); GL_ASSERT(glGetIntegerv(GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS, &maxSubU)); printf("Max Subroutines: %d Max Subroutine Uniforms: %d\n", maxSub,maxSubU); GL_ASSERT(glGetProgramStageiv(program, GL_VERTEX_SHADER, GL_ACTIVE_SUBROUTINE_UNIFORMS, &countActiveSU)); for (int i = 0; i < countActiveSU; ++i) { glGetActiveSubroutineUniformName(program, GL_VERTEX_SHADER, i, 256, &len, name); printf("Suroutine Uniform: %d name: %s\n", i,name); glGetActiveSubroutineUniformiv(program, GL_VERTEX_SHADER, i, GL_NUM_COMPATIBLE_SUBROUTINES, &numCompS); int *s = (int *) malloc(sizeof(int) * numCompS); glGetActiveSubroutineUniformiv(program, GL_VERTEX_SHADER, i, GL_COMPATIBLE_SUBROUTINES, s); printf("Compatible Subroutines:\n"); for (int j=0; j < numCompS; ++j) { glGetActiveSubroutineName(program, GL_VERTEX_SHADER, s[j], 256, &len, name); printf("\t%d - %s\n", s[j],name); } printf("\n"); free(s); } }
void GLProgram::getActiveSubroutineUniforms(std::vector<GLSLSubroutineUniform>& list, GLenum shaderType) const { GLint count; glGetProgramStageiv(_handle, shaderType, GL_ACTIVE_SUBROUTINE_UNIFORMS, &count); GLint biggerNameLength; glGetProgramStageiv(_handle, shaderType, GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH, &biggerNameLength); if (count != GL_INVALID_ENUM && biggerNameLength != GL_INVALID_ENUM) { list.reserve(count); GLchar* name = new GLchar[biggerNameLength]; for (GLuint index = 0; index < static_cast<GLuint>(count); ++index) { glGetActiveSubroutineUniformName(_handle, shaderType, index, biggerNameLength, 0, name); GLint location = glGetSubroutineUniformLocation(_handle, shaderType, name); GLint compatibleSubroutinesCount; glGetActiveSubroutineUniformiv(_handle, shaderType, index, GL_NUM_COMPATIBLE_SUBROUTINES, &compatibleSubroutinesCount); GLint* compatibleSubroutines = new GLint[compatibleSubroutinesCount]; glGetActiveSubroutineUniformiv(_handle, shaderType, index, GL_COMPATIBLE_SUBROUTINES, compatibleSubroutines); // @uniformArraySize is 1 if subroutine uniform is not an array GLint uniformArraySize; glGetActiveSubroutineUniformiv(_handle, shaderType, index, GL_UNIFORM_SIZE, &uniformArraySize); GLSLSubroutineUniform subroutineUniform; subroutineUniform.program = _handle; subroutineUniform.location = location; subroutineUniform.shaderType = shaderType; subroutineUniform.name = name; subroutineUniform.compatibleSubroutines = std::vector<GLint>(compatibleSubroutines, compatibleSubroutines + compatibleSubroutinesCount); subroutineUniform.uniformArraySize = uniformArraySize; list.push_back(subroutineUniform); delete[] compatibleSubroutines; } delete[] name; } }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL40_nglGetActiveSubroutineUniformiv(JNIEnv *__env, jclass clazz, jint program, jint shadertype, jint index, jint pname, jlong valuesAddress, jlong __functionAddress) { GLint *values = (GLint *)(intptr_t)valuesAddress; glGetActiveSubroutineUniformivPROC glGetActiveSubroutineUniformiv = (glGetActiveSubroutineUniformivPROC)(intptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) glGetActiveSubroutineUniformiv(program, shadertype, index, pname, values); }