// Render one tile in wireframe mode static void RenderWireTile(INDEX itt) { ASSERT(_ptrTerrain!=NULL); CTerrainTile &tt = _ptrTerrain->tr_attTiles[itt]; INDEX ctVertices = tt.GetVertices().Count(); GFXVertex4 *pavVertices; if(ter_bLerpVertices) { PrepareSmothVertices(itt); pavVertices = &_avLerpedVerices[0]; } else { pavVertices = &tt.GetVertices()[0]; } INDEX ctIndices = tt.GetIndices().Count(); if(ctIndices>0) { gfxDisableBlend(); gfxDisableTexture(); gfxSetConstantColor(_colTerrainEdges); gfxSetVertexArray(pavVertices,ctVertices); gfxLockArrays(); gfxDrawElements(ctIndices,&tt.GetIndices()[0]); gfxUnlockArrays(); } }
// Set current color index void shaSetColor(INDEX icolIndex) { ASSERT(icolIndex>=0); if(icolIndex>=_ctColors) { _colConstant = C_WHITE|CT_OPAQUE; } else { _colConstant = _paColors[icolIndex]; } // Set this color as constant color gfxSetConstantColor(_colConstant); }
// Render aditional pass for fog and haze void shaDoFogPass(void) { // if full bright if(shaGetFlags()&BASE_FULL_BRIGHT) { // no fog pass return; } ASSERT(_paFogUVMap==NULL); ASSERT(_paHazeUVMap==NULL); // Calculate fog and haze uvmap for this opaque surface RM_DoFogAndHaze(TRUE); // if fog uvmap has been given if(_paFogUVMap!=NULL) { // setup texture/color arrays and rendering mode gfxSetTextureWrapping( GFX_CLAMP, GFX_CLAMP); gfxSetTexture( _fog_ulTexture, _fog_tpLocal); gfxSetTexCoordArray(_paFogUVMap, FALSE); gfxSetConstantColor(_fog_fp.fp_colColor); gfxBlendFunc( GFX_SRC_ALPHA, GFX_INV_SRC_ALPHA); gfxEnableBlend(); // render fog pass gfxDrawElements( _ctIndices, _paIndices); } // if haze uvmap has been given if(_paHazeUVMap!=NULL) { gfxSetTextureWrapping( GFX_CLAMP, GFX_CLAMP); gfxSetTexture( _haze_ulTexture, _haze_tpLocal); gfxSetTexCoordArray(_paHazeUVMap, TRUE); gfxBlendFunc( GFX_SRC_ALPHA, GFX_INV_SRC_ALPHA); gfxEnableBlend(); // set vertex color array for haze if(_pacolVtxHaze !=NULL ) { gfxSetColorArray( _pacolVtxHaze); } // render fog pass gfxDrawElements( _ctIndices, _paIndices); } }
// Set constant color void shaSetConstantColor(const COLOR colConstant) { gfxSetConstantColor(colConstant); }
// Render one tile static void RenderTile(INDEX itt) { ASSERT(_ptrTerrain!=NULL); CTerrainTile &tt = _ptrTerrain->tr_attTiles[itt]; INDEX ctVertices = tt.GetVertices().Count(); extern INDEX ter_bOptimizeRendering; // if tile is in posible lowest lod and doesn't have any border vertices if(ter_bOptimizeRendering && tt.GetFlags()&TT_IN_LOWEST_LOD) { // delay tile rendering BatchTile(itt); return; } GFXVertex4 *pavVertices; // if vertex lerping is requested if(ter_bLerpVertices==1) { // Prepare smoth vertices PrepareSmothVertices(itt); pavVertices = &_avLerpedVerices[0]; } else { // use non smoth vertices pavVertices = &tt.GetVertices()[0]; } // if tile is in highest lod if(tt.tt_iLod==0) { gfxBlendFunc(GFX_SRC_ALPHA, GFX_INV_SRC_ALPHA); gfxSetVertexArray(pavVertices,ctVertices); gfxLockArrays(); // for each tile layer INDEX cttl= tt.GetTileLayers().Count(); for(INDEX itl=0;itl<cttl;itl++) { CTerrainLayer &tl = _ptrTerrain->tr_atlLayers[itl]; // if layer isn't visible if(!tl.tl_bVisible) { continue; // skip it } TileLayer &ttl = tt.GetTileLayers()[itl]; // Set tile stretch Matrix12 m12; SetMatrixDiagonal(m12,tl.tl_fStretchX); gfxSetTextureMatrix2(&m12); // Set tile blend mode if(tl.tl_fSmoothness==0) { gfxDisableBlend(); gfxEnableAlphaTest(); } else { gfxEnableBlend(); gfxDisableAlphaTest(); } // if this tile has any polygons in this layer INDEX ctIndices = ttl.tl_auiIndices.Count(); if(ctIndices>0) { gfxSetTextureWrapping(GFX_REPEAT,GFX_REPEAT); tl.tl_ptdTexture->SetAsCurrent(); // if this is tile layer if(tl.tl_ltType==LT_TILE) { gfxUnlockArrays(); GFXVertex4 *pavLayerVertices; if(ter_bLerpVertices==1) { PrepareSmothVerticesOnTileLayer(itt,itl); pavLayerVertices = &_avLerpedTileLayerVertices[0]; } else { pavLayerVertices = &ttl.tl_avVertices[0]; } gfxSetVertexArray(pavLayerVertices,ttl.tl_avVertices.Count()); gfxLockArrays(); // gfxSetColorArray(&ttl.tl_acColors[0]); gfxSetTexCoordArray(&ttl.tl_atcTexCoords[0], FALSE); // set wireframe mode /* gfxEnableDepthBias(); gfxPolygonMode(GFX_LINE); gfxDisableTexture();*/ gfxSetConstantColor(0xFFFFFFFF); // Draw tiled layer gfxDrawElements(ttl.tl_auiIndices.Count(),&ttl.tl_auiIndices[0]); _ctTris +=ttl.tl_auiIndices.Count()/2; /* // set fill mode gfxDisableDepthBias(); gfxPolygonMode(GFX_FILL);*/ // Set old vertex array gfxUnlockArrays(); gfxSetVertexArray(pavVertices,ctVertices); gfxLockArrays(); // if this is normal layer } else { // render layer gfxSetColorArray(&ttl.tl_acColors[0]); gfxSetTexCoordArray(&ttl.tl_atcTexCoords[0], FALSE); gfxDrawElements(ctIndices,&ttl.tl_auiIndices[0]); _ctTris +=ctIndices/2; } } } gfxSetTextureMatrix2(NULL); INDEX ctIndices = tt.GetIndices().Count(); if(ctIndices>0) { INDEX *paiIndices = &tt.GetIndices()[0]; // if detail map exists if(_ptrTerrain->tr_ptdDetailMap!=NULL) { gfxSetTextureWrapping(GFX_REPEAT,GFX_REPEAT); gfxDisableAlphaTest(); shaBlendFunc( GFX_DST_COLOR, GFX_SRC_COLOR); gfxEnableBlend(); gfxSetTexCoordArray(&tt.GetDetailTC()[0], FALSE); _ptrTerrain->tr_ptdDetailMap->SetAsCurrent(); gfxDrawElements(ctIndices,paiIndices); } // if shadows are visible if(_wrpWorldRenderPrefs.wrp_shtShadows!=CWorldRenderPrefs::SHT_NONE) { gfxDisableAlphaTest(); shaBlendFunc( GFX_DST_COLOR, GFX_SRC_COLOR); gfxEnableBlend(); gfxSetTextureWrapping(GFX_CLAMP,GFX_CLAMP); gfxSetTexCoordArray(&tt.GetShadowMapTC()[0], FALSE); _ptrTerrain->tr_tdShadowMap.SetAsCurrent(); gfxDrawElements(ctIndices,paiIndices); } } // if tile is not in highest lod } else { gfxSetTextureWrapping(GFX_CLAMP,GFX_CLAMP); // if tile is in lowest lod if(tt.tt_iLod == _ptrTerrain->tr_iMaxTileLod) { // use terrains global top map _ptrTerrain->tr_tdTopMap.SetAsCurrent(); // else tile is in some midle lod } else { // use its own topmap tt.GetTopMap()->SetAsCurrent(); } // Render tile INDEX ctIndices = tt.GetIndices().Count(); gfxEnableAlphaTest(); gfxDisableBlend(); gfxSetVertexArray(pavVertices,ctVertices); gfxSetTexCoordArray(&tt.GetTexCoords()[0], FALSE); FillConstColorArray(ctVertices); gfxSetColorArray(&_acolVtxConstColors[0]); gfxLockArrays(); gfxDrawElements(ctIndices,&tt.GetIndices()[0]); _ctTris +=ctIndices/2; gfxDisableAlphaTest(); // if shadows are visible if(_wrpWorldRenderPrefs.wrp_shtShadows!=CWorldRenderPrefs::SHT_NONE) { gfxDepthFunc(GFX_EQUAL); INDEX ctIndices = tt.GetIndices().Count(); INDEX *paiIndices = &tt.GetIndices()[0]; gfxSetTextureWrapping(GFX_CLAMP,GFX_CLAMP); gfxBlendFunc(GFX_DST_COLOR,GFX_SRC_COLOR); gfxEnableBlend(); gfxSetTexCoordArray(&tt.GetShadowMapTC()[0], FALSE); _ptrTerrain->tr_tdShadowMap.SetAsCurrent(); gfxDrawElements(ctIndices,paiIndices); gfxDepthFunc(GFX_LESS_EQUAL); } } if(_ptrTerrain->GetFlags()&TR_HAS_FOG) { RenderFogLayer(itt); } if(_ptrTerrain->GetFlags()&TR_HAS_HAZE) { RenderHazeLayer(itt); } gfxUnlockArrays(); }