#include "dxstdafx.h" #include ".\depthrenderstrategy.h" #include "PathMapEffect.h" #include "Entity.h" #include "SubEntity.h" DepthRenderStrategy::DepthRenderStrategy(PathMapEffect* pathMapEffect) :RenderStrategy(pathMapEffect) { } void DepthRenderStrategy::applyTargets() const { LPDIRECT3DDEVICE9 device = pathMapEffect->device; device->SetRenderTarget(0, pathMapEffect->fakeSurface); device->SetDepthStencilSurface( pathMapEffect->depthMapDepthStencilBuffer); } void DepthRenderStrategy::applyRenderState() const { LPDIRECT3DDEVICE9 device = pathMapEffect->device; device->SetRenderState(D3DRS_COLORWRITEENABLE, 0); // render backfaces to avoid z-fighting device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); device->Clear( 0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(255, 0, 0, 0), 1.0f, 0 ); } void DepthRenderStrategy::applyTechnique() const { pathMapEffect->effect->SetTechnique("Depth"); } void DepthRenderStrategy::applyTransforms(Entity* entity) const { LPD3DXEFFECT effect = pathMapEffect->effect; effect->SetMatrix("modelToProjMatrix", &( entity->modelWorldTransform * *camera.GetViewMatrix() * *camera.GetProjMatrix() ) ); effect->CommitChanges(); } void DepthRenderStrategy::resetRenderState() const { LPDIRECT3DDEVICE9 device = pathMapEffect->device; device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA); }