GLuint GLContextManager::getProgramID(const osg::Program *program) { if (!program || !pContext->isValid()) return 0; if (hPrograms.count(program)) return hPrograms[program]; makeCurrent(); GLuint pid = glCreateProgram(); CHECK_GL(); hPrograms[program] = pid; for(unsigned int i = 0 ; i < program->getNumShaders() ; ++i) { const osg::Shader *shader = program->getShader(i); GLuint sid = getShaderID(shader); glAttachShader(pid, sid); CHECK_GL(); } glLinkProgram(pid); CHECK_GL(); GLint linked; glGetProgramiv(pid, GL_LINK_STATUS, &linked); CHECK_GL(); if (!linked) std::cerr << "program link error" << std::endl; const GLsizei max_len = 16384; GLchar *buffer = new GLchar[max_len + 1]; memset(buffer, 0, max_len + 1); GLsizei len; glGetProgramInfoLog(pid, max_len, &len, buffer); CHECK_GL(); if (len > 0) { std::cerr.write(buffer, len); std::cerr << std::endl; std::cerr << std::endl; } delete[] buffer; return pid; }
void DefaultMaterial::setUniforms(){ int colorLoc = glGetUniformLocation(getShaderID(), "color"); // Get the location of the uniform in the shader glUniform3f(colorLoc, color[0], color[1], color[2]); // Set the color }