/** * set uniform to the 3 components of value */ inline void setUniform3fv(const GLchar *name, GLfloat *value) { GlUniform uniform; setupUniform(uniform, name); uniform.set3fv(value); CGlErrorCheckWithMessage(name); }
/** * set uniform to the value */ inline void setUniform1i(const GLchar *name, GLint value) { GlUniform uniform; setupUniform(uniform, name); uniform.set1i(value); CGlErrorCheckWithMessage(name); }
/** * setup the offset value and scaling factor for the height as input * value for the color map */ void setupColorScaleAndOffset( float offset = 0.0, float scale = 1.0 ) { use(); height_color_scale.set1f(scale); height_color_offset.set1f(offset); disable(); }
/** * render skybox */ void renderWithProgram(GLSL::mat4 &p_pvm_matrix) { // CGlStateDisable depth_test(GL_DEPTH_TEST); CGlErrorCheck(); program.use(); pvm_matrix_uniform.set(p_pvm_matrix); vertex_buffer.bind(); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); glEnableVertexAttribArray(0); texture_cube_map.bind(); #if 0 CGlErrorCheck(); glDrawArrays(GL_TRIANGLES, 0, 3); CGlErrorCheck(); #else index_buffer.bind(); CGlErrorCheck(); glDrawElements(GL_TRIANGLE_STRIP, 20, GL_UNSIGNED_BYTE, 0); index_buffer.unbind(); #endif texture_cube_map.unbind(); glDisableVertexAttribArray(0); vertex_buffer.unbind(); program.disable(); CGlErrorCheck(); }
/** * setup the uniforms for rendering */ void setupUniformsMaterial( GlMaterial &material ) { CShaderBlinnSkeleton::setupUniformsMaterial(material); texture0_enabled.set1b(material.texture0 != nullptr); }
/** * setup the uniforms for rendering */ void setupUniforms( GlMaterial &material, Lights &lights ) { CShaderBlinnSkeleton::setupUniforms(material, lights); texture0_enabled.set1b(material.texture0 != nullptr); }
/** * setup the uniforms for rendering */ void setupUniforms( GlMaterial &material, Lights &lights, const GLSL::vec3 &light_view_pos3 ) { CShaderBlinnSkeleton::setupUniforms(material, lights, light_view_pos3); texture0_enabled.set1b(material.texture0 != nullptr); }
/** * render flat cube map */ void render( CGlCubeMap &cGlCubeMap, ///< handler to cube map float scale = 1.0f ///< scale flat cube map with this factor ) { cGlCubeMap.texture_cube_map.bind(); CGlViewport cGlViewport; cGlViewport.saveState(); GLSL::mat4 pmv = GLSL::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); program.use(); pvm_matrix_uniform.set(pmv); vao.bind(); CGlErrorCheck(); pmv = GLSL::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); // line in texture coordinates (offset = vertices) #define TEX_LINE(l) (sizeof(GLfloat)*4*4 + (l)*4*3*sizeof(GLfloat)) buffer.bind(); // LEFT glViewport(0*scale, cGlCubeMap.depth*scale, cGlCubeMap.depth*scale, cGlCubeMap.height*scale); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(1)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // FRONT glViewport(cGlCubeMap.depth*scale, cGlCubeMap.depth*scale, cGlCubeMap.width*scale, cGlCubeMap.height*scale); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(5)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // RIGHT glViewport(cGlCubeMap.depth*scale+cGlCubeMap.width*scale, cGlCubeMap.depth*scale, cGlCubeMap.depth*scale, cGlCubeMap.height*scale); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(0)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // BACK glViewport(cGlCubeMap.depth*2*scale+cGlCubeMap.width*scale, cGlCubeMap.depth*scale, cGlCubeMap.width*scale, cGlCubeMap.height*scale); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(4)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // BOTTOM glViewport(cGlCubeMap.depth*scale, 0, cGlCubeMap.width*scale, cGlCubeMap.depth*scale); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(3)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // TOP glViewport(cGlCubeMap.depth*scale, cGlCubeMap.depth*scale + cGlCubeMap.height*scale, cGlCubeMap.width*scale, cGlCubeMap.depth*scale); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)TEX_LINE(2)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); cGlViewport.restoreState(); vao.unbind(); program.disable(); CGlErrorCheck(); glFlush(); }
/** * setup the uniforms for rendering */ void setupUniformsShadowMapping( const GLSL::mat4 &shadow_map_matrix ) { shadow_map_matrix_uniform.set(shadow_map_matrix); }
void GlProgram::setUniforms() { int i,index,len,size; unsigned int type; char *name = new char [m_MaxLength + 1]; GlUniform uni; // set all types = NOT_USED std::vector<GlUniform>::iterator it; for(it = m_Uniforms.begin(); it != m_Uniforms.end(); it++) { it->setType(GlUniform::NOT_USED); } // add new uniforms and reset types for previous uniforms for (i = 0; i < m_NumUniforms; i++) { glGetActiveUniform (m_P, i, m_MaxLength, &len, &size, &type, name); std::string n (name); index = findUniform (n); if (-1 != index) { m_Uniforms[index].setType (type); m_Uniforms[index].setLoc (i); } else { uni.reset(); std::string ProgName (name); uni.setName (ProgName); uni.setType (type); uni.setLoc (i); m_Uniforms.push_back (uni); } if (size > 1) { for (int i = 0; i < size; i++) { std::stringstream s; s << n.c_str() << "[" << i << "]"; std::string Location = s.str(); index = findUniform (Location); int loc; loc = glGetUniformLocation(m_P, s.str().c_str()); if (-1 != index) { m_Uniforms[index].setType (type); m_Uniforms[index].setLoc (loc); } else { uni.reset(); std::string ProgName (s.str()); uni.setName (ProgName); uni.setType (type); uni.setLoc (loc); m_Uniforms.push_back (uni); } } } } // delete all uniforms where type is NOT_USED for(it = m_Uniforms.begin(), i = 0; it != m_Uniforms.end(); i++ ) { if (it->getType() == GlUniform::NOT_USED) { it = m_Uniforms.erase(it); } else { ++it; } } m_NumUniforms = m_Uniforms.size(); for (int i = 0; i < m_NumUniforms; i++) { setValueOfUniform (i); } }
void GlProgram::setValueOfUniform (int i) { GlUniform uni; uni = m_Uniforms[i]; switch(uni.getType()) { case GL_FLOAT: glUniform1f (uni.getLoc(),uni.getValues()[0]);break; case GL_FLOAT_VEC2: glUniform2fv (uni.getLoc(),1,uni.getValues());break; case GL_FLOAT_VEC3: glUniform3fv (uni.getLoc(),1,uni.getValues());break; case GL_FLOAT_VEC4: glUniform4fv (uni.getLoc(),1,uni.getValues());break; case GL_INT: case GL_BOOL: case GL_SAMPLER_2D: case GL_SAMPLER_2D_SHADOW: case GL_SAMPLER_1D: case GL_SAMPLER_3D: case GL_SAMPLER_CUBE: glUniform1i(uni.getLoc(),(int)uni.getValues()[0]);break; case GL_INT_VEC2: case GL_BOOL_VEC2: glUniform2i(uni.getLoc(),(int)uni.getValues()[0],(int)uni.getValues()[1]);break; case GL_INT_VEC3:case GL_BOOL_VEC3: glUniform3i(uni.getLoc(),(int)uni.getValues()[0],(int)uni.getValues()[1],(int)uni.getValues()[2]);break; case GL_INT_VEC4:case GL_BOOL_VEC4: glUniform4i(uni.getLoc(),(int)uni.getValues()[0],(int)uni.getValues()[1],(int)uni.getValues()[2],(int)uni.getValues()[3]);break; case GL_FLOAT_MAT2: glUniformMatrix2fv(uni.getLoc(),1,false,uni.getValues());break; case GL_FLOAT_MAT3: glUniformMatrix3fv(uni.getLoc(),1,false,uni.getValues());break; case GL_FLOAT_MAT4: glUniformMatrix4fv(uni.getLoc(),1,false,uni.getValues());break; } }