Exemplo n.º 1
0
// Draw all tiles that are in lowest lod
static void RenderBatchedTiles(void)
{
  // Set texture wrapping
  gfxSetTextureWrapping(GFX_CLAMP,GFX_CLAMP);
  // Use terrains global top map as texture
  _ptrTerrain->tr_tdTopMap.SetAsCurrent();

  GFXVertex4  *pavVertices     = &_avDelayedVertices[0];
  GFXTexCoord *pauvTexCoords   = &_auvDelayedTexCoords[0];
  GFXTexCoord *pauvShadowMapTC = &_auvDelayedShadowMapTC[0];
  INDEX       *paiIndices      = &_aiDelayedIndices[0];
  INDEX        ctVertices      = _avDelayedVertices.Count();
  INDEX        ctIndices       = _aiDelayedIndices.Count();

  // Prepare white color array
  FillConstColorArray(ctVertices);
  GFXColor    *pacolColors     = &_acolVtxConstColors[0];

  gfxEnableAlphaTest();
  gfxDisableBlend();
  gfxSetVertexArray(pavVertices,ctVertices);
  gfxSetTexCoordArray(pauvTexCoords, FALSE);
  gfxSetColorArray(pacolColors);
  gfxLockArrays();
  gfxDrawElements(ctIndices,paiIndices);
  gfxDisableAlphaTest();
  _ctTris +=ctIndices/2;

  // if shadows are visible
  if(_wrpWorldRenderPrefs.wrp_shtShadows!=CWorldRenderPrefs::SHT_NONE) {
    gfxDepthFunc(GFX_EQUAL);

    gfxBlendFunc(GFX_DST_COLOR,GFX_SRC_COLOR);
    gfxEnableBlend();
    gfxSetTexCoordArray(pauvShadowMapTC, FALSE);
    _ptrTerrain->tr_tdShadowMap.SetAsCurrent();
    gfxDrawElements(ctIndices,paiIndices);
    gfxDepthFunc(GFX_LESS_EQUAL);
  }

  if(_ptrTerrain->GetFlags()&TR_HAS_FOG) {
    RenderFogLayer(-1);
  }
  if(_ptrTerrain->GetFlags()&TR_HAS_HAZE) {
    RenderHazeLayer(-1);
  }
  gfxUnlockArrays();

  // Popall delayed arrays 
  _avDelayedVertices.PopAll();
  _auvDelayedTexCoords.PopAll();
  _auvDelayedShadowMapTC.PopAll();
  _aiDelayedIndices.PopAll();
}
Exemplo n.º 2
0
// Render given model
void shaRender(void)
{
  ASSERT(_ctVertices>0);
  ASSERT(_ctIndices>0);
  ASSERT(_paVertices!=NULL);
  ASSERT(_paIndices!=NULL);

  // Set vertices
  gfxSetVertexArray(_paVertices,_ctVertices);
  gfxLockArrays();

  // if there is valid UVMap
  if(_pCurrentUVMap!=NULL) {
    gfxSetTexCoordArray(_pCurrentUVMap, FALSE);
  }

  // if there is valid vertex color array
  if(_pcolVtxColors!=NULL) {
    gfxSetColorArray(_pcolVtxColors);
  }

  // draw model with set params
  gfxDrawElements( _ctIndices, _paIndices);
  gfxUnlockArrays();
}
Exemplo n.º 3
0
// 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();
  }
}
Exemplo n.º 4
0
void CShockWaveEffect::Render()
{
	if(!PreRender())
	{
		return;
	}
	
	if (GetOwner() != NULL)
	{ // HIDDEN 속성의 NPC의 이펙트를 보기 위해서는 캐릭터가 ENF_SHOWHIDDEN을 가지고 있어야 한다.
		if (GetOwner()->IsFlagOn(ENF_HIDDEN) && (CEntity::GetPlayerEntity(0)->IsFlagOff(ENF_SHOWHIDDEN) ||
			(CEntity::GetPlayerEntity(0)->IsFlagOn(ENF_SHOWHIDDEN)&&!GetOwner()->IsEnemy())))//ENF_SHOWHIDDEN이면 npc effect는 볼 수 있다.
			return;
	}

	gfxSetBlendType(m_eBlendType);
	if(m_ptdTexture != NULL)
	{
		gfxSetTextureUnit(0);
		m_ptdTexture->SetAsCurrent();
		if(RM_AreHardwareShadersAvailable())
		{
			gfxSetVertexProgram( m_ulVertexProgramTex );
			gfxSetPixelProgram( m_ulPixelProgramTex );
		}
		else
		{
			gfxSetTextureModulation(1);
		}
	}
	else
	{
		if(RM_AreHardwareShadersAvailable())
		{
			gfxSetVertexProgram( m_ulVertexProgramNoTex );
			gfxSetPixelProgram( m_ulPixelProgramNoTex );
		}
		else
		{
			//gfxSetTextureSelectArg(0, GFX_TA_DIFFUSE, GFX_TA_DIFFUSE);
		}
	}

	gfxSetVertexArray( &m_vectorGFXVertex[0], m_vectorGFXVertex.size() );
	gfxSetColorArray( &m_vectorGFXColor[0] );
	if(m_ptdTexture != NULL) gfxSetTexCoordArray( &m_vectorTexCoord[0], FALSE );
	gfxDrawElements( m_iSplitCount * 2 * 3, &m_vectorIndex[0]);

	if(!RM_AreHardwareShadersAvailable())
	{
		//gfxSetTextureSelectArg(0, GFX_TA_TEXTURE, GFX_TA_TEXTURE);
		gfxSetTextureModulation(1);
	}
	PostRender();
}
Exemplo n.º 5
0
// 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);
  }
}
Exemplo n.º 6
0
static void RenderHazeLayer(INDEX itt)
{
  FLOAT3D vObjPosition = _ptrTerrain->tr_penEntity->en_plPlacement.pl_PositionVector;

  _fHazeAdd  = -_haze_hp.hp_fNear;
  _fHazeAdd += _vViewer(1) * (vObjPosition(1) - _aprProjection->pr_vViewerPosition(1));
  _fHazeAdd += _vViewer(2) * (vObjPosition(2) - _aprProjection->pr_vViewerPosition(2));
  _fHazeAdd += _vViewer(3) * (vObjPosition(3) - _aprProjection->pr_vViewerPosition(3));

  GFXVertex *pvVtx;
  INDEX     *piIndices;
  INDEX ctVertices;
  INDEX ctIndices;
  // if this is tile 
  if(itt>=0) {
    CTerrainTile &tt = _ptrTerrain->tr_attTiles[itt];
    pvVtx      = &tt.GetVertices()[0];
    piIndices  = &tt.GetIndices()[0];
    ctVertices = tt.GetVertices().Count();
    ctIndices  = tt.GetIndices().Count();
  // else this are batched tiles
  } else {
    pvVtx      = &_avDelayedVertices[0];
    piIndices  = &_aiDelayedIndices[0];
    ctVertices = _avDelayedVertices.Count();
    ctIndices  = _aiDelayedIndices.Count();
  }

  GFXTexCoord *pfHazeTC  = _atcHaze.Push(ctVertices);
  GFXColor    *pcolHaze  = _acolHaze.Push(ctVertices);

  const COLOR colH = AdjustColor( _haze_hp.hp_colColor, _slTexHueShift, _slTexSaturation);
  GFXColor colHaze(colH);
  // for each vertex in tile
  for(INDEX ivx=0;ivx<ctVertices;ivx++) {
    GetHazeMapInVertex(pvVtx[ivx],pfHazeTC[ivx]);
    pcolHaze[ivx] = colHaze;
  }

  // render haze layer
  gfxDepthFunc(GFX_EQUAL);
  gfxSetTextureWrapping( GFX_CLAMP, GFX_CLAMP);
  gfxSetTexture( _haze_ulTexture, _haze_tpLocal);
  gfxSetTexCoordArray(pfHazeTC, FALSE);
  gfxSetColorArray(pcolHaze);
  gfxBlendFunc( GFX_SRC_ALPHA, GFX_INV_SRC_ALPHA);
  gfxEnableBlend();
  gfxDrawElements(ctIndices,piIndices);
  gfxDepthFunc(GFX_LESS_EQUAL);

  _atcHaze.PopAll();
  _acolHaze.PopAll();
}
Exemplo n.º 7
0
// fill rate benchmark
static DOUBLE FillRatePass(INDEX ct)
{
  if( !_pdp->Lock()) {
    ASSERT(FALSE);
    return 0.0;
  }
  StartTimer();

  _pdp->Fill(C_GRAY|255);
  _pdp->FillZBuffer(1.0f);

  GFXVertex avtx[4];
  avtx[0].x = 0;          avtx[0].y = 0;          avtx[0].z = 0.5f;  
  avtx[1].x = 0;          avtx[1].y = _pixSizeJ;  avtx[1].z = 0.5f;  
  avtx[2].x = _pixSizeI;  avtx[2].y = _pixSizeJ;  avtx[2].z = 0.5f;  
  avtx[3].x = _pixSizeI;  avtx[3].y = 0;          avtx[3].z = 0.5f;  
  GFXTexCoord atex[4] = { {0,0}, {0,1}, {1,1}, {1,0} };
  GFXColor    acol[4] = { 0xFF0000FF, 0xFF00FF00, 0xFFFF0000, 0xFFFF00FF };
  INDEX_T     aidx[6] = { 0,1,2, 0,2,3};
  gfxSetVertexArray( &avtx[0], 4);
  gfxSetTexCoordArray( &atex[0], FALSE);
  gfxSetColorArray( &acol[0]);

  if(_bTexture) {
    gfxEnableTexture();
    if(_bMultiTexture) {
      gfxSetTextureUnit(1);
      gfxEnableTexture();
      gfxSetTexture( _ulTexObject, _tpLocal);
      gfxSetTexCoordArray(atex, FALSE);
      gfxSetTextureUnit(0);
    }
  } else {
    gfxDisableTexture();
  }

  if(_bBlend) {
    gfxEnableBlend();
    if(_bTexture) {
      gfxBlendFunc( GFX_SRC_ALPHA, GFX_INV_SRC_ALPHA); 
    } else {
      gfxBlendFunc( GFX_ONE, GFX_ONE);
    }
  } else {
    gfxDisableBlend();
  }

  if(_bDepth) {
    gfxEnableDepthTest();
    gfxEnableDepthWrite();
  } else {
    gfxDisableDepthTest();
    gfxDisableDepthWrite();
  }
  gfxDisableAlphaTest();

  for( INDEX i=0; i<ct; i++) gfxDrawElements( 6, &aidx[0]);

  if(_bMultiTexture) {
    gfxSetTextureUnit(1);
    gfxDisableTexture();
    gfxSetTextureUnit(0);
  }
  _pdp->Unlock();

  gfxFinish();
  _pvp->SwapBuffers();

  return StopTimer();
}
Exemplo n.º 8
0
static DOUBLE TrisTroughputPass(INDEX ct)
{
  if( !_pdp->Lock()) {
    ASSERT(FALSE);
    return 0.0;
  }

  StartTimer();

  gfxSetFrustum( -0.5f, +0.5f, -0.5f, +0.5f, 0.5f, 2.0f);
  gfxSetViewMatrix(NULL);
  gfxCullFace(GFX_NONE);

  _pdp->Fill(C_GRAY|255);
  _pdp->FillZBuffer(1.0f);

  if(_bTexture) {
    gfxEnableTexture();
  } else {
    gfxDisableTexture();
  }

  if(_bBlend) {
    gfxEnableBlend();
    gfxBlendFunc( GFX_ONE, GFX_ONE);
  } else {
    gfxDisableBlend();
  }

  if(_bDepth) {
    gfxEnableDepthTest();
    gfxEnableDepthWrite();
  } else {
    gfxDisableDepthTest();
    gfxDisableDepthWrite();
  }
  gfxDisableAlphaTest();

  gfxSetVertexArray( &_avtx[0], _avtx.Count());
  gfxLockArrays();
  gfxSetTexCoordArray( &_atex[0], FALSE);
  gfxSetColorArray( &_acol[0]);

  if(_bMultiTexture) {
    gfxSetTextureUnit(1);
    gfxEnableTexture();
    gfxSetTexture( _ulTexObject, _tpLocal);
    gfxSetTexCoordArray( &_atex[0], FALSE);
    gfxSetTextureUnit(0);
  }
  for( INDEX i=0; i<ct; i++) gfxDrawElements( _aiElements.Count(), &_aiElements[0]);
  gfxUnlockArrays();

  if(_bMultiTexture) {
    gfxSetTextureUnit(1);
    gfxDisableTexture();
    gfxSetTextureUnit(0);
  }
  _pdp->Unlock();

  gfxFinish();
  _pvp->SwapBuffers();

  return StopTimer();
}
Exemplo n.º 9
0
// 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();
}
Exemplo n.º 10
0
static void RenderFogLayer(INDEX itt)
{
  FLOATmatrix3D &mViewer = _aprProjection->pr_ViewerRotationMatrix;
  FLOAT3D vObjPosition = _ptrTerrain->tr_penEntity->en_plPlacement.pl_PositionVector;

  // get viewer -z in object space
  _vFViewerObj = FLOAT3D(0,0,-1) * !_mObjectToView;
  // get fog direction in object space
  _vHDirObj = _fog_vHDirAbs * !(!mViewer*_mObjectToView);
  // get viewer offset
  _fFogAddZ  = _vViewer(1) * (vObjPosition(1) - _aprProjection->pr_vViewerPosition(1));
  _fFogAddZ += _vViewer(2) * (vObjPosition(2) - _aprProjection->pr_vViewerPosition(2));
  _fFogAddZ += _vViewer(3) * (vObjPosition(3) - _aprProjection->pr_vViewerPosition(3));
  // get fog offset
  _fFogAddH = (_fog_vHDirAbs % vObjPosition) + _fog_fp.fp_fH3;

  GFXVertex *pvVtx;
  INDEX     *piIndices;
  INDEX ctVertices;
  INDEX ctIndices;
  // if this is tile 
  if(itt>=0) {
    CTerrainTile &tt = _ptrTerrain->tr_attTiles[itt];
    pvVtx      = &tt.GetVertices()[0];
    piIndices  = &tt.GetIndices()[0];
    ctVertices = tt.GetVertices().Count();
    ctIndices  = tt.GetIndices().Count();
  // else this are batched tiles
  } else {
    pvVtx      = &_avDelayedVertices[0];
    piIndices  = &_aiDelayedIndices[0];
    ctVertices = _avDelayedVertices.Count();
    ctIndices  = _aiDelayedIndices.Count();
  }

  GFXTexCoord *pfFogTC  = _atcHaze.Push(ctVertices);
  GFXColor    *pcolFog  = _acolHaze.Push(ctVertices);

  const COLOR colF = AdjustColor( _fog_fp.fp_colColor, _slTexHueShift, _slTexSaturation);
  GFXColor colFog(colF);

  // for each vertex in tile
  for(INDEX ivx=0;ivx<ctVertices;ivx++) {
    GetFogMapInVertex(pvVtx[ivx],pfFogTC[ivx]);
    pcolFog[ivx] = colFog;
  }

  // render fog layer
  gfxDepthFunc(GFX_EQUAL);
  gfxSetTextureWrapping( GFX_CLAMP, GFX_CLAMP);
  gfxSetTexture( _fog_ulTexture, _fog_tpLocal);
  gfxSetTexCoordArray(pfFogTC, FALSE);
  gfxSetColorArray(pcolFog);
  gfxBlendFunc( GFX_SRC_ALPHA, GFX_INV_SRC_ALPHA);
  gfxEnableBlend();
  gfxDisableAlphaTest();
  gfxDrawElements(ctIndices,piIndices);
  gfxDepthFunc(GFX_LESS_EQUAL);

  _atcHaze.PopAll();
  _acolHaze.PopAll();
}
Exemplo n.º 11
0
void ShowSelectionInternal(CTerrain *ptrTerrain, Rect &rcExtract, CTextureData *ptdBrush, GFXColor colSelection, FLOAT fStrenght, SelectionFill sfFill)
{
  ASSERT(ptrTerrain!=NULL);
  ASSERT(ptdBrush!=NULL);

  Rect rcSelection;
  FLOATaabbox3D bboxSelection;
  // Clamp rect used for extraction
  rcSelection.rc_iLeft   = Clamp(rcExtract.rc_iLeft   , 0, ptrTerrain->tr_pixHeightMapWidth);
  rcSelection.rc_iTop    = Clamp(rcExtract.rc_iTop    , 0, ptrTerrain->tr_pixHeightMapHeight);
  rcSelection.rc_iRight  = Clamp(rcExtract.rc_iRight  , 0, ptrTerrain->tr_pixHeightMapWidth);
  rcSelection.rc_iBottom = Clamp(rcExtract.rc_iBottom , 0, ptrTerrain->tr_pixHeightMapHeight);

  // Prepare box for vertex selection
  bboxSelection    = FLOAT3D(rcSelection.rc_iLeft,  0, rcSelection.rc_iTop);
  bboxSelection   |= FLOAT3D(rcSelection.rc_iRight, 0, rcSelection.rc_iBottom);

  // Stretch selection box
  bboxSelection.minvect(1) *= ptrTerrain->tr_vStretch(1);
  bboxSelection.minvect(3) *= ptrTerrain->tr_vStretch(3);
  bboxSelection.maxvect(1) *= ptrTerrain->tr_vStretch(1);
  bboxSelection.maxvect(3) *= ptrTerrain->tr_vStretch(3);

  // Set selection box height
  FLOATaabbox3D bboxAllTerrain;
  ptrTerrain->GetAllTerrainBBox(bboxAllTerrain);
  bboxSelection.minvect(2) = bboxAllTerrain.minvect(2);
  bboxSelection.maxvect(2) = bboxAllTerrain.maxvect(2);

  GFXVertex *pavVertices;
  INDEX     *paiIndices;
  INDEX      ctVertices;
  INDEX      ctIndices;
  
  // Extract vertices in selection rect
  ExtractVerticesInRect(ptrTerrain, rcSelection, &pavVertices, &paiIndices, ctVertices, ctIndices);

  if(ctVertices!=rcSelection.Width()*rcSelection.Height()) {
    ASSERT(FALSE);
    return;
  }

  // if no vertices
  if(ctVertices==0) {
    return;
  }

  // Prepare vertex colors for selection preview
  PIX pixWidth  = rcSelection.Width();
  PIX pixHeight = rcSelection.Height();
  INDEX iStepX  = ptdBrush->GetWidth() - pixWidth;
  INDEX iFirst  = 0;
  if(rcExtract.rc_iTop<0) {
    iFirst += -rcExtract.rc_iTop*ptdBrush->GetWidth();
  }
  if(rcExtract.rc_iLeft<0) {
    iFirst += -rcExtract.rc_iLeft;
  }

  _aiExtColors.Push(ctVertices);
  GFXColor *pacolColor = (GFXColor*)&_aiExtColors[0];
  GFXColor *pacolBrush = (GFXColor*)&ptdBrush->td_pulFrames[iFirst];

  // Fill vertex colors for selection preview
  SLONG slStrength = (SLONG) (Clamp(Abs(fStrenght),0.0f,1.0f) * 256.0f);
  // for each row
  for(INDEX iy=0;iy<pixHeight;iy++) {
    // for each col
    for(INDEX ix=0;ix<pixWidth;ix++) {
      pacolColor->ul.abgr = colSelection.ul.abgr;
      pacolColor->ub.a    = (pacolBrush->ub.r*slStrength)>>8;
      pacolColor++;
      pacolBrush++;
    }
    pacolBrush+=iStepX;
  }

  // Render selected polygons for selection preview
  if(sfFill == SF_WIREFRAME) {
    gfxPolygonMode(GFX_LINE);
    gfxEnableDepthBias();
  }

  if(sfFill != SF_POINTS) {
    // Draw selection
    gfxDisableTexture();
    gfxDisableAlphaTest();
    gfxEnableBlend();
    gfxBlendFunc(GFX_SRC_ALPHA, GFX_INV_SRC_ALPHA);
    gfxSetVertexArray(pavVertices,ctVertices);
    gfxSetColorArray(&_aiExtColors[0]);
    gfxLockArrays();
    gfxDrawElements(ctIndices,paiIndices);
    gfxUnlockArrays();
    gfxDisableBlend();
  }

  if(sfFill == SF_WIREFRAME) {
    gfxDisableDepthBias();
    gfxPolygonMode(GFX_FILL);
  }

  if(sfFill == SF_POINTS) {
    DrawSelectedVertices(pavVertices,&_aiExtColors[0],ctVertices);
  }
}