JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL40_nglGetActiveSubroutineUniformName(JNIEnv *__env, jclass clazz, jint program, jint shadertype, jint index, jint bufsize, jlong lengthAddress, jlong nameAddress, jlong __functionAddress) {
	GLsizei *length = (GLsizei *)(intptr_t)lengthAddress;
	GLchar *name = (GLchar *)(intptr_t)nameAddress;
	glGetActiveSubroutineUniformNamePROC glGetActiveSubroutineUniformName = (glGetActiveSubroutineUniformNamePROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	glGetActiveSubroutineUniformName(program, shadertype, index, bufsize, length, name);
}
Example #2
0
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);
  }
}
Example #3
0
    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;
        }
    }
Example #4
0
void
UniformGroup::apply_subroutines(ProgramPtr prog, GLenum shadertype,
                                const std::unordered_map<std::string, std::string>& subroutines)
{
  assert_gl("apply_subroutines:enter");
  GLint num_uniform_locations;
  glGetProgramStageiv(prog->get_id(), shadertype, GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS, &num_uniform_locations);

  std::vector<GLuint> subroutine_mappings;
  for(int i = 0; i < num_uniform_locations; ++i)
  {
    char name[256];
    GLsizei length;
    glGetActiveSubroutineUniformName(prog->get_id(), shadertype, i, sizeof(name), &length, name);

    const auto& it = subroutines.find(name);
    if (it == subroutines.end())
    {
      log_error("unmapped subroutine: %s", name);
    }
    else
    {
      GLuint loc = glGetSubroutineIndex(prog->get_id(), shadertype, it->second.c_str());
      if (loc == GL_INVALID_INDEX)
      {
        log_error("unknown subroutine: %s", it->second);
      }
      else
      {
        subroutine_mappings.emplace_back(loc);
      }
    }
  }

  glUniformSubroutinesuiv(shadertype, subroutine_mappings.size(), subroutine_mappings.data());

  assert_gl("apply_subroutines:exit");
}