bool GeoMipMapping::Render() { //渲染所有patch for (int z = 0; z < m_iNumPatchesPerSide; z++) { for (int x = 0; x < m_iNumPatchesPerSide; x++) { RenderPatch(x, z); } } return true; }
void Renderer::RenderFace(bsp_face *face) { const bsp_face ¤t_face = *face; Shader *shader = shaderLoader::GetShader(current_face.texture); if (shader->q3_shader_.stages_.size() == 0) // skip no shader / no draw. should be sorted out before. { return; } // does everything in here need to be done every time? move into the // conditional below? SetupShader(shader, current_face.lm_index); if (current_shader_ != shader) { glUseProgram(shader->shader_); current_shader_ = shader; } if (shader->time_idx_ != -1) { glUniform1f(shader->time_idx_, time_); } glUniformMatrix4fv(shader->projection_idx_, 1, false, glm::value_ptr(projectionmatrix_)); glUniformMatrix4fv(shader->model_idx_, 1, false, glm::value_ptr(modelmatrix_)); if (current_face.type == POLYGON || current_face.type == MESH) { // RenderPolygon(face); } else if (current_face.type == PATCH) { RenderPatch(face); } else if (current_face.type == BILLBOARD) { // RenderBillboard(); } }
//-------------------------------------------------------------- // Name: CGEOMIPMAPPING::Render - public // Description: Render the geomipmapping system // Arguments: None // Return Value: None //-------------------------------------------------------------- void CGEOMIPMAPPING::Render( void ) { int x, z; //reset the counting variables m_iPatchesPerFrame = 0; m_iVertsPerFrame= 0; m_iTrisPerFrame = 0; //enable back-face culling glEnable( GL_CULL_FACE ); //render the multitexturing terrain if( m_bMultitexture && m_bDetailMapping && m_bTextureMapping ) { glDisable( GL_BLEND ); //bind the primary color texture to the first texture unit glActiveTextureARB( GL_TEXTURE0_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_texture.GetID( ) ); //bind the detail color texture to the second texture unit glActiveTextureARB( GL_TEXTURE1_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_detailMap.GetID( ) ); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB ); glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2 ); //render the patches for( z=0; z<m_iNumPatchesPerSide; z++ ) { for( x=0; x<m_iNumPatchesPerSide; x++ ) { if( m_pPatches[GetPatchNumber( x, z )].m_bVisible ) { RenderPatch( x, z, true, true ); m_iPatchesPerFrame++; } } } } //no hardware multitexturing available, or the user only wants to render //the detail texture or the color texture else { if( m_bTextureMapping ) { //bind the primary color texture (FOR THE PRIMARY TEXTURE PASS) glActiveTextureARB( GL_TEXTURE0_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_texture.GetID( ) ); //render the color texture for( z=0; z<m_iNumPatchesPerSide; z++ ) { for( x=0; x<m_iNumPatchesPerSide; x++ ) { if( m_pPatches[GetPatchNumber( x, z )].m_bVisible ) { RenderPatch( x, z, true, true ); m_iPatchesPerFrame++; } } } } if( !( m_bTextureMapping && !m_bDetailMapping ) ) { //if the user wants detail mapping, we need to set some things up if( m_bDetailMapping ) { //bind the detail texture glActiveTextureARB( GL_TEXTURE0_ARB ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, m_detailMap.GetID( ) ); //only use blending if a texture pass was made if( m_bTextureMapping ) { glEnable( GL_BLEND ); glBlendFunc( GL_ZERO, GL_SRC_COLOR ); } } //render either the detail map on top of the texture, //only the detail map, or neither for( z=0; z<m_iNumPatchesPerSide; z++ ) { for( x=0; x<m_iNumPatchesPerSide; x++ ) { if( m_pPatches[GetPatchNumber( x, z )].m_bVisible ) { RenderPatch( x, z, true, true ); m_iPatchesPerFrame++; } } } } } glDisable( GL_BLEND ); //unbind the texture occupying the second texture unit glActiveTextureARB( GL_TEXTURE1_ARB ); glDisable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, 0 ); //unbind the texture occupying the first texture unit glActiveTextureARB( GL_TEXTURE0_ARB ); glDisable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, 0 ); }