GLint ProgramData::GetUniformLocation(const GLchar* name) { Mutex::Autolock mutex(&lock_); if (linked_programs_.empty()) { GLES_ERROR(GL_INVALID_OPERATION, "The program has not been linked"); return -1; } // Look for known local locations. for (UniformLocationMap::const_iterator it = uniform_locations_.begin(); it != uniform_locations_.end(); ++it) { if (it->second.GetOriginalName() == name) { return it->first; } } // Look up matching active uniform. int array_index = -1; ProgramVariantPtr program = linked_programs_[0].GetProgram(); std::string base_name = program->ParseUniformName(name, &array_index); if (base_name.empty()) { return -1; } // A sanity check for the location in the underlying shader program. GLint global_location = program->GetUniformLocation(name); if (global_location == -1) { return -1; } // Add location to the uniform map. GLint local_location = ++uniform_location_gen_; uniform_locations_[local_location] = UniformLocation( name, base_name, array_index); return local_location; }
bool cShaderProgram::SetUniformMatrix( const std::string Name, const float * Value ) { Int32 Location = UniformLocation( Name ); if ( Location >= 0 ) { #ifdef EE_SHADERS_SUPPORTED glUniformMatrix4fv( Location, 1, false, Value ); #endif } return ( Location >= 0 ); }
bool cShaderProgram::SetUniform( const std::string& Name, Int32 Value ) { Int32 Location = UniformLocation( Name ); if ( Location >= 0 ) { #ifdef EE_SHADERS_SUPPORTED glUniform1i( Location, Value ); #endif } return ( Location >= 0 ); }
bool cShaderProgram::SetUniform( const std::string& Name, float x, float y, float z, float w ) { Int32 Location = UniformLocation( Name ); if ( Location >= 0 ) { #ifdef EE_SHADERS_SUPPORTED glUniform4f( Location, x, y, z, w ); #endif } return ( Location >= 0 ); }
bool cShaderProgram::SetUniform( const std::string& Name, eeVector3ff Value ) { Int32 Location = UniformLocation( Name ); if ( Location >= 0 ) { #ifdef EE_SHADERS_SUPPORTED glUniform3fv( Location, 1, reinterpret_cast<float*>( &Value ) ); #endif } return ( Location >= 0 ); }
void Graphics::renderGlowTexture() { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(-1,1,-1,1,0.5,5); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); gluLookAt(0.0,0.0,1.0, 0.0,0.0,0.0, 0.0,1.0,0.0); if(glowShader == NULL) { World &world = World::getInstance(); glowShader = InitProgram( (world.assetsDir + "shaders/glow.vert").c_str(), (world.assetsDir + "shaders/glow.frag").c_str() ); } glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, glowTexId); int glowLoc = UniformLocation(glowShader,"glowTexture"); glUniform1i(glowLoc,0); glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); glDisable(GL_LIGHTING); glColor3f(1.0,1.0,1.0); UseProgram(glowShader); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex3f(-1,-1,0); glTexCoord2f(1,0); glVertex3f(1,-1,0); glTexCoord2f(1,1); glVertex3f(1,1,0); glTexCoord2f(0,1); glVertex3f(-1,1,0); glEnd(); UseProgram(0); glDisable(GL_BLEND); glEnable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }