std::vector<GLint> Program::getActiveUniforms(const std::vector<GLint> & uniformIndices, const GLenum pname) const { std::vector<GLuint> indices(uniformIndices.size()); for (unsigned i=0; i<uniformIndices.size(); ++i) indices[i] = static_cast<GLuint>(uniformIndices[i]); return getActiveUniforms(indices, pname); }
Program::Uniforms Program::getActiveUniforms() { GLint numActiveUniforms; glGetProgramInterfaceiv( getGLId(), GL_UNIFORM, GL_ACTIVE_RESOURCES, &numActiveUniforms ); std::vector<GLuint> indices; indices.resize(numActiveUniforms); for (GLint index = 0;index < numActiveUniforms;++index) { indices[index] = index; } return getActiveUniforms(indices); }
Program::Uniforms Program::getActiveUniforms( std::vector<std::string> const & uniformNames ) { std::vector<GLuint> indices; indices.reserve(uniformNames.size()); for ( size_t idx = 0; idx < uniformNames.size(); ++idx ) { GLuint locationIndex = glGetProgramResourceIndex( getGLId(), GL_UNIFORM, uniformNames[idx].c_str() ); if ( locationIndex != GL_INVALID_INDEX ) { indices.push_back(GLuint(locationIndex)); } } return getActiveUniforms( indices ); }
/////////////////////////////////////////////////////////////////////////////////////// /// Build a mapping of uniform names to uniform indices /////////////////////////////////////////////////////////////////////////////////////// void Program::mapUniformNamesToIndices(void) { for(int i = 0; i < getActiveUniforms(); ++i) { _uniform[getUniformName(i)] = i; } #if 1 std::map<std::string, GLuint>::const_iterator itr; for(itr = _uniform.begin(); itr != _uniform.end(); ++itr) { std::cout << "(name, index): (" << itr->first << "," << itr->second << ")" << std::endl; } #endif }
static int getCurrentShader(ShaderProgram *shader) { int haveGeometryShader = checkGLExtensionSupported("GL_EXT_geometry_shader4"); int error; /* get handle of currently active GLSL shader program */ ORIG_GL(glGetIntegerv)(GL_CURRENT_PROGRAM, (GLint*)&shader->programHandle); error = glError(); if (error) { return error; } if (shader->programHandle == 0) { return 0; } /* get attached shader objects */ error = getShaderObjects(shader); if (error) { return error; } /* get active uniforms and attributes */ error = getActiveUniforms(shader); if (error) { return error; } error = getActiveAttributes(shader); if (error) { return error; } /* if geometry shader is supported, get program parameters */ if (haveGeometryShader) { error = getProgramParameters(shader); if (error) { return error; } } else { shader->geoVerticesOut = 0; shader->geoOutputType = GL_NONE; shader->geoInputType = GL_NONE; } return DBG_NO_ERROR; }
// QUERIES const std::string GLSLProgram::getActiveUniformsStr() const { const std::vector< GLSLProgram::UniformInformations > uniforms = getActiveUniforms(); return toString( uniforms ); }
GLint Program::getActiveUniform(const GLuint uniformIndex, const GLenum pname) const { GLint result = 0; getActiveUniforms(1, &uniformIndex, pname, &result); return result; }
std::vector<GLint> Program::getActiveUniforms(const std::vector<GLuint> & uniformIndices, const GLenum pname) const { std::vector<GLint> result(uniformIndices.size()); getActiveUniforms(static_cast<GLint>(uniformIndices.size()), uniformIndices.data(), pname, result.data()); return result; }