From a21139193e23650c0d11e7c1da6599470c41c75e Mon Sep 17 00:00:00 2001 From: Exynox Date: Thu, 28 Mar 2024 22:27:09 +0200 Subject: [PATCH] Upgraded to DirectX 9 --- src/EffectLib/EffectInstance.cpp | 10 +- src/EffectLib/EffectMesh.h | 2 +- src/EffectLib/EffectMeshInstance.cpp | 2 +- src/EffectLib/SimpleLightData.cpp | 2 +- src/EffectLib/SimpleLightData.h | 4 +- src/EffectLib/SimpleLightInstance.cpp | 2 +- src/EterGrnLib/Material.cpp | 10 +- src/EterGrnLib/Material.h | 6 +- src/EterGrnLib/Model.cpp | 4 +- src/EterGrnLib/Model.h | 4 +- src/EterGrnLib/ModelInstance.h | 2 +- src/EterGrnLib/ModelInstanceModel.cpp | 2 +- src/EterGrnLib/ModelInstanceRender.cpp | 57 +- src/EterGrnLib/StdAfx.h | 2 +- src/EterLib/BlockTexture.cpp | 4 +- src/EterLib/BlockTexture.h | 2 +- src/EterLib/Camera.cpp | 2 +- src/EterLib/Decal.cpp | 2 +- src/EterLib/GrpBase.cpp | 18 +- src/EterLib/GrpBase.h | 12 +- src/EterLib/GrpDetector.cpp | 34 +- src/EterLib/GrpDetector.h | 22 +- src/EterLib/GrpDevice.cpp | 143 +- src/EterLib/GrpExpandedImageInstance.cpp | 2 +- src/EterLib/GrpImageInstance.cpp | 2 +- src/EterLib/GrpImageTexture.cpp | 42 +- src/EterLib/GrpIndexBuffer.cpp | 18 +- src/EterLib/GrpIndexBuffer.h | 4 +- src/EterLib/GrpLightManager.cpp | 4 +- src/EterLib/GrpLightManager.h | 6 +- src/EterLib/GrpMarkInstance.cpp | 2 +- src/EterLib/GrpPixelShader.cpp | 15 +- src/EterLib/GrpPixelShader.h | 2 +- src/EterLib/GrpScreen.cpp | 55 +- src/EterLib/GrpShadowTexture.cpp | 62 +- src/EterLib/GrpShadowTexture.h | 16 +- src/EterLib/GrpTextInstance.cpp | 2 +- src/EterLib/GrpTexture.cpp | 2 +- src/EterLib/GrpTexture.h | 4 +- src/EterLib/GrpVertexBuffer.cpp | 17 +- src/EterLib/GrpVertexBuffer.h | 4 +- src/EterLib/GrpVertexShader.cpp | 17 +- src/EterLib/GrpVertexShader.h | 2 +- src/EterLib/LensFlare.cpp | 4 +- src/EterLib/Ray.h | 2 +- src/EterLib/SkyBox.cpp | 10 +- src/EterLib/StateManager.cpp | 308 +++-- src/EterLib/StateManager.h | 122 +- src/EterLib/StdAfx.h | 7 +- src/EterLib/Util.h | 2 +- src/EterPythonLib/PythonGraphic.cpp | 34 +- src/EterPythonLib/PythonGraphic.h | 4 +- src/GameLib/ActorInstance.cpp | 8 +- src/GameLib/ActorInstanceRender.cpp | 4 +- src/GameLib/Area.cpp | 6 +- src/GameLib/AreaTerrain.cpp | 10 +- src/GameLib/AreaTerrain.h | 8 +- src/GameLib/DungeonBlock.cpp | 8 +- src/GameLib/FlyTrace.cpp | 4 +- src/GameLib/FlyTrace.h | 2 +- src/GameLib/MapBase.h | 2 +- src/GameLib/MapManager.cpp | 2 +- src/GameLib/MapManager.h | 4 +- src/GameLib/MapOutdoor.cpp | 16 +- src/GameLib/MapOutdoor.h | 26 +- src/GameLib/MapOutdoorCharacterShadow.cpp | 23 +- src/GameLib/MapOutdoorLoad.cpp | 2 +- src/GameLib/MapOutdoorRender.cpp | 46 +- src/GameLib/MapOutdoorRenderHTP.cpp | 47 +- src/GameLib/MapOutdoorRenderSTP.cpp | 85 +- src/GameLib/MapOutdoorUpdate.cpp | 2 +- src/GameLib/MapOutdoorWater.cpp | 24 +- src/GameLib/MapType.h | 4 +- src/GameLib/SnowEnvironment.cpp | 40 +- src/GameLib/SnowEnvironment.h | 20 +- src/GameLib/TerrainDecal.cpp | 10 +- src/GameLib/TerrainPatch.cpp | 4 +- src/GameLib/TerrainPatch.h | 8 +- src/GameLib/WeaponTrace.cpp | 6 +- src/MilesLib/SoundData.h | 2 +- src/PRTerrainLib/Terrain.h | 6 +- src/PRTerrainLib/TerrainType.h | 2 +- src/PRTerrainLib/TextureSet.h | 2 +- src/SpeedTreeLib/CSpeedTreeDirectX.cpp | 246 ++++ src/SpeedTreeLib/CSpeedTreeDirectX.h | 23 + src/SpeedTreeLib/SpeedGrassRT.cpp | 769 ----------- src/SpeedTreeLib/SpeedGrassRT.h | 180 --- src/SpeedTreeLib/SpeedGrassWrapper.cpp | 322 ----- src/SpeedTreeLib/SpeedGrassWrapper.h | 64 - src/SpeedTreeLib/SpeedTreeConfig.h | 44 +- src/SpeedTreeLib/SpeedTreeForest.cpp | 52 +- src/SpeedTreeLib/SpeedTreeForest.h | 12 +- src/SpeedTreeLib/SpeedTreeForestDirectX8.cpp | 344 ----- src/SpeedTreeLib/SpeedTreeForestDirectX8.h | 64 - src/SpeedTreeLib/SpeedTreeLib.vcxproj | 65 +- src/SpeedTreeLib/SpeedTreeLib.vcxproj.filters | 24 +- src/SpeedTreeLib/SpeedTreeMaterial.h | 32 +- src/SpeedTreeLib/SpeedTreeWrapper.cpp | 1209 ++++++----------- src/SpeedTreeLib/SpeedTreeWrapper.h | 100 +- src/SpeedTreeLib/StdAfx.h | 17 +- src/SpeedTreeLib/VertexShaders.h | 360 +---- src/SphereLib/StdAfx.h | 4 +- src/UserInterface/PythonApplication.cpp | 4 +- src/UserInterface/PythonApplicationLogo.cpp | 12 +- src/UserInterface/PythonMiniMap.cpp | 52 +- src/UserInterface/PythonMiniMap.h | 2 +- src/UserInterface/PythonSystem.cpp | 12 +- src/UserInterface/UserInterface.cpp | 6 +- src/UserInterface/UserInterface.vcxproj | 6 +- src/vcpkg.json | 4 + 110 files changed, 1604 insertions(+), 3977 deletions(-) create mode 100644 src/SpeedTreeLib/CSpeedTreeDirectX.cpp create mode 100644 src/SpeedTreeLib/CSpeedTreeDirectX.h delete mode 100644 src/SpeedTreeLib/SpeedGrassRT.cpp delete mode 100644 src/SpeedTreeLib/SpeedGrassRT.h delete mode 100644 src/SpeedTreeLib/SpeedGrassWrapper.cpp delete mode 100644 src/SpeedTreeLib/SpeedGrassWrapper.h delete mode 100644 src/SpeedTreeLib/SpeedTreeForestDirectX8.cpp delete mode 100644 src/SpeedTreeLib/SpeedTreeForestDirectX8.h diff --git a/src/EffectLib/EffectInstance.cpp b/src/EffectLib/EffectInstance.cpp index 686ab55c..1e20d55a 100644 --- a/src/EffectLib/EffectInstance.cpp +++ b/src/EffectLib/EffectInstance.cpp @@ -91,8 +91,8 @@ void CEffectInstance::OnUpdate() void CEffectInstance::OnRender() { - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_NONE); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_NONE); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE); STATEMANAGER.SaveRenderState(D3DRS_ALPHABLENDENABLE, TRUE); STATEMANAGER.SaveRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); STATEMANAGER.SaveRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); @@ -107,13 +107,13 @@ void CEffectInstance::OnRender() STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_TEX1); std::for_each(m_ParticleInstanceVector.begin(),m_ParticleInstanceVector.end(),std::void_mem_fun(&CEffectElementBaseInstance::Render)); std::for_each(m_MeshInstanceVector.begin(),m_MeshInstanceVector.end(),std::void_mem_fun(&CEffectElementBaseInstance::Render)); ///// - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MINFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MAGFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MINFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MAGFILTER); STATEMANAGER.RestoreRenderState(D3DRS_ALPHABLENDENABLE); STATEMANAGER.RestoreRenderState(D3DRS_SRCBLEND); STATEMANAGER.RestoreRenderState(D3DRS_DESTBLEND); diff --git a/src/EffectLib/EffectMesh.h b/src/EffectLib/EffectMesh.h index b0219af0..c4fc2d2c 100644 --- a/src/EffectLib/EffectMesh.h +++ b/src/EffectLib/EffectMesh.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../eterlib/GrpScreen.h" #include "../eterlib/Resource.h" diff --git a/src/EffectLib/EffectMeshInstance.cpp b/src/EffectLib/EffectMeshInstance.cpp index a749055e..fdb8583a 100644 --- a/src/EffectLib/EffectMeshInstance.cpp +++ b/src/EffectLib/EffectMeshInstance.cpp @@ -168,7 +168,7 @@ void CEffectMeshInstance::OnRender() Color.a = fAlpha * rFrameData.fVisibility; STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, DWORD(Color)); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_TEX1); STATEMANAGER.DrawPrimitiveUP(D3DPT_TRIANGLELIST, rFrameData.dwIndexCount/3, &rFrameData.PDTVertexVector[0], diff --git a/src/EffectLib/SimpleLightData.cpp b/src/EffectLib/SimpleLightData.cpp index b3fedf47..f220f2be 100644 --- a/src/EffectLib/SimpleLightData.cpp +++ b/src/EffectLib/SimpleLightData.cpp @@ -145,7 +145,7 @@ float CLightData::GetDuration() { return m_fDuration; } -void CLightData::InitializeLight(D3DLIGHT8& light) +void CLightData::InitializeLight(D3DLIGHT9& light) { light.Type = D3DLIGHT_POINT; diff --git a/src/EffectLib/SimpleLightData.h b/src/EffectLib/SimpleLightData.h index d296bf00..732a5bb8 100644 --- a/src/EffectLib/SimpleLightData.h +++ b/src/EffectLib/SimpleLightData.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../eterLib/TextFileLoader.h" @@ -24,7 +24,7 @@ class CLightData : public CEffectElementBase { return m_iLoopCount; } - void InitializeLight(D3DLIGHT8& light); + void InitializeLight(D3DLIGHT9& light); protected: void OnClear(); diff --git a/src/EffectLib/SimpleLightInstance.cpp b/src/EffectLib/SimpleLightInstance.cpp index 0a22410a..0fd214ae 100644 --- a/src/EffectLib/SimpleLightInstance.cpp +++ b/src/EffectLib/SimpleLightInstance.cpp @@ -29,7 +29,7 @@ void CLightInstance::OnSetDataPointer(CEffectElementBase * pElement) m_iLoopCount = m_pData->GetLoopCount(); - D3DLIGHT8 Light; + D3DLIGHT9 Light; m_pData->InitializeLight(Light); CLightManager::Instance().RegisterLight(LIGHT_TYPE_DYNAMIC, &m_LightID, Light); } diff --git a/src/EterGrnLib/Material.cpp b/src/EterGrnLib/Material.cpp index b6ff1d79..70a7363c 100644 --- a/src/EterGrnLib/Material.cpp +++ b/src/EterGrnLib/Material.cpp @@ -139,7 +139,7 @@ bool CGrannyMaterial::IsEqual(granny_material* pgrnMaterial) const } -LPDIRECT3DTEXTURE8 CGrannyMaterial::GetD3DTexture(int iStage) const +LPDIRECT3DTEXTURE9 CGrannyMaterial::GetD3DTexture(int iStage) const { const CGraphicImage::TRef & ratImage = m_roImage[iStage]; @@ -333,8 +333,8 @@ void CGrannyMaterial::__ApplySpecularRenderState() STATEMANAGER.SetTransform(D3DTS_TEXTURE1, &ms_matSpecular); STATEMANAGER.SaveTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); } void CGrannyMaterial::__RestoreSpecularRenderState() @@ -346,8 +346,8 @@ void CGrannyMaterial::__RestoreSpecularRenderState() } STATEMANAGER.RestoreTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSV); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSV); STATEMANAGER.RestoreTextureStageState(1, D3DTSS_TEXCOORDINDEX); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); diff --git a/src/EterGrnLib/Material.h b/src/EterGrnLib/Material.h index 368c5cb4..67ac9ff6 100644 --- a/src/EterGrnLib/Material.h +++ b/src/EterGrnLib/Material.h @@ -1,8 +1,8 @@ #pragma once -#include +#include #include -#include +#include #include "../eterlib/ReferenceObject.h" #include "../eterlib/Ref.h" @@ -58,7 +58,7 @@ class CGrannyMaterial : public CReferenceObject const CGraphicTexture * GetDiffuseTexture() const; const CGraphicTexture * GetOpacityTexture() const; - LPDIRECT3DTEXTURE8 GetD3DTexture(int iStage) const; + LPDIRECT3DTEXTURE9 GetD3DTexture(int iStage) const; bool IsTwoSided() const { return m_bTwoSideRender; } diff --git a/src/EterGrnLib/Model.cpp b/src/EterGrnLib/Model.cpp index b8d53afe..e054891b 100644 --- a/src/EterGrnLib/Model.cpp +++ b/src/EterGrnLib/Model.cpp @@ -72,12 +72,12 @@ granny_model* CGrannyModel::GetGrannyModelPointer() return m_pgrnModel; } -LPDIRECT3DINDEXBUFFER8 CGrannyModel::GetD3DIndexBuffer() const +LPDIRECT3DINDEXBUFFER9 CGrannyModel::GetD3DIndexBuffer() const { return m_idxBuf.GetD3DIndexBuffer(); } -LPDIRECT3DVERTEXBUFFER8 CGrannyModel::GetPNTD3DVertexBuffer() const +LPDIRECT3DVERTEXBUFFER9 CGrannyModel::GetPNTD3DVertexBuffer() const { return m_pntVtxBuf.GetD3DVertexBuffer(); } diff --git a/src/EterGrnLib/Model.h b/src/EterGrnLib/Model.h index 553d9df4..54d603c3 100644 --- a/src/EterGrnLib/Model.h +++ b/src/EterGrnLib/Model.h @@ -38,8 +38,8 @@ class CGrannyModel : public CReferenceObject granny_model * GetGrannyModelPointer(); const CGrannyMesh* GetMeshPointer(int iMesh) const; - LPDIRECT3DVERTEXBUFFER8 GetPNTD3DVertexBuffer() const; - LPDIRECT3DINDEXBUFFER8 GetD3DIndexBuffer() const; + LPDIRECT3DVERTEXBUFFER9 GetPNTD3DVertexBuffer() const; + LPDIRECT3DINDEXBUFFER9 GetD3DIndexBuffer() const; const CGrannyModel::TMeshNode* GetMeshNodeList(CGrannyMesh::EType eMeshType, CGrannyMaterial::EType eMtrlType) const; diff --git a/src/EterGrnLib/ModelInstance.h b/src/EterGrnLib/ModelInstance.h index c7a9a335..57f11f50 100644 --- a/src/EterGrnLib/ModelInstance.h +++ b/src/EterGrnLib/ModelInstance.h @@ -137,7 +137,7 @@ class CGrannyModelInstance : public CGraphicCollisionObject bool __IsDeformableVertexBuffer(); void __SetSharedDeformableVertexBuffer(CGraphicVertexBuffer* pkSharedDeformableVertexBuffer); - IDirect3DVertexBuffer8* __GetDeformableD3DVertexBufferPtr(); + IDirect3DVertexBuffer9* __GetDeformableD3DVertexBufferPtr(); CGraphicVertexBuffer& __GetDeformableVertexBufferRef(); granny_world_pose* __GetWorldPosePtr() const; diff --git a/src/EterGrnLib/ModelInstanceModel.cpp b/src/EterGrnLib/ModelInstanceModel.cpp index 03ca8174..29bdbbcc 100644 --- a/src/EterGrnLib/ModelInstanceModel.cpp +++ b/src/EterGrnLib/ModelInstanceModel.cpp @@ -208,7 +208,7 @@ bool CGrannyModelInstance::__IsDeformableVertexBuffer() return m_kLocalDeformableVertexBuffer.IsEmpty(); } -IDirect3DVertexBuffer8* CGrannyModelInstance::__GetDeformableD3DVertexBufferPtr() +IDirect3DVertexBuffer9* CGrannyModelInstance::__GetDeformableD3DVertexBufferPtr() { return __GetDeformableVertexBufferRef().GetD3DVertexBuffer(); } diff --git a/src/EterGrnLib/ModelInstanceRender.cpp b/src/EterGrnLib/ModelInstanceRender.cpp index 33fcddeb..f8b9a5b9 100644 --- a/src/EterGrnLib/ModelInstanceRender.cpp +++ b/src/EterGrnLib/ModelInstanceRender.cpp @@ -58,13 +58,9 @@ void CGrannyModelInstance::RenderWithOneTexture() return; #endif - STATEMANAGER.SetVertexShader(ms_pntVS); - - // WORK - LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr(); - // END_OF_WORK - - LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); + LPDIRECT3DVERTEXBUFFER9 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr(); + LPDIRECT3DVERTEXBUFFER9 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); + STATEMANAGER.SetFVF(ms_pntVS); if (lpd3dDeformPNTVtxBuf) { @@ -83,12 +79,9 @@ void CGrannyModelInstance::BlendRenderWithOneTexture() if (IsEmpty()) return; - // WORK - LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr(); - // END_OF_WORK - LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); - - STATEMANAGER.SetVertexShader(ms_pntVS); + LPDIRECT3DVERTEXBUFFER9 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr(); + LPDIRECT3DVERTEXBUFFER9 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); + STATEMANAGER.SetFVF(ms_pntVS); if (lpd3dDeformPNTVtxBuf) { @@ -110,12 +103,9 @@ void CGrannyModelInstance::RenderWithTwoTexture() if (IsEmpty()) return; - STATEMANAGER.SetVertexShader(ms_pntVS); - - // WORK - LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr(); - // END_OF_WORK - LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); + LPDIRECT3DVERTEXBUFFER9 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr(); + LPDIRECT3DVERTEXBUFFER9 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); + STATEMANAGER.SetFVF(ms_pntVS); if (lpd3dDeformPNTVtxBuf) { @@ -134,12 +124,9 @@ void CGrannyModelInstance::BlendRenderWithTwoTexture() if (IsEmpty()) return; - // WORK - LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr(); - // END_OF_WORK - LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); - - STATEMANAGER.SetVertexShader(ms_pntVS); + LPDIRECT3DVERTEXBUFFER9 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr(); + LPDIRECT3DVERTEXBUFFER9 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); + STATEMANAGER.SetFVF(ms_pntVS); if (lpd3dDeformPNTVtxBuf) { @@ -159,14 +146,12 @@ void CGrannyModelInstance::RenderWithoutTexture() if (IsEmpty()) return; - STATEMANAGER.SetVertexShader(ms_pntVS); + STATEMANAGER.SetFVF(ms_pntVS); STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTexture(1, NULL); - // WORK - LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr(); - // END_OF_WORK - LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); + LPDIRECT3DVERTEXBUFFER9 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr(); + LPDIRECT3DVERTEXBUFFER9 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); if (lpd3dDeformPNTVtxBuf) { @@ -195,7 +180,7 @@ void CGrannyModelInstance::RenderMeshNodeListWithOneTexture(CGrannyMesh::EType e { assert(m_pModel != NULL); - LPDIRECT3DINDEXBUFFER8 lpd3dIdxBuf = m_pModel->GetD3DIndexBuffer(); + LPDIRECT3DINDEXBUFFER9 lpd3dIdxBuf = m_pModel->GetD3DIndexBuffer(); assert(lpd3dIdxBuf != NULL); const CGrannyModel::TMeshNode * pMeshNode = m_pModel->GetMeshNodeList(eMeshType, eMtrlType); @@ -217,7 +202,7 @@ void CGrannyModelInstance::RenderMeshNodeListWithOneTexture(CGrannyMesh::EType e CGrannyMaterial& rkMtrl=m_kMtrlPal.GetMaterialRef(pTriGroupNode->mtrlIndex); rkMtrl.ApplyRenderState(); - STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vtxCount, pTriGroupNode->idxPos, pTriGroupNode->triCount); + STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vtxCount, pTriGroupNode->idxPos, pTriGroupNode->triCount, vtxMeshBasePos); rkMtrl.RestoreRenderState(); pTriGroupNode = pTriGroupNode->pNextTriGroupNode; @@ -233,7 +218,7 @@ void CGrannyModelInstance::RenderMeshNodeListWithTwoTexture(CGrannyMesh::EType e { assert(m_pModel != NULL); - LPDIRECT3DINDEXBUFFER8 lpd3dIdxBuf = m_pModel->GetD3DIndexBuffer(); + LPDIRECT3DINDEXBUFFER9 lpd3dIdxBuf = m_pModel->GetD3DIndexBuffer(); assert(lpd3dIdxBuf != NULL); const CGrannyModel::TMeshNode * pMeshNode = m_pModel->GetMeshNodeList(eMeshType, eMtrlType); @@ -256,7 +241,7 @@ void CGrannyModelInstance::RenderMeshNodeListWithTwoTexture(CGrannyMesh::EType e const CGrannyMaterial& rkMtrl=m_kMtrlPal.GetMaterialRef(pTriGroupNode->mtrlIndex); STATEMANAGER.SetTexture(0, rkMtrl.GetD3DTexture(0)); STATEMANAGER.SetTexture(1, rkMtrl.GetD3DTexture(1)); - STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vtxCount, pTriGroupNode->idxPos, pTriGroupNode->triCount); + STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vtxCount, pTriGroupNode->idxPos, pTriGroupNode->triCount, vtxMeshBasePos); pTriGroupNode = pTriGroupNode->pNextTriGroupNode; } ///// @@ -270,7 +255,7 @@ void CGrannyModelInstance::RenderMeshNodeListWithoutTexture(CGrannyMesh::EType e { assert(m_pModel != NULL); - LPDIRECT3DINDEXBUFFER8 lpd3dIdxBuf = m_pModel->GetD3DIndexBuffer(); + LPDIRECT3DINDEXBUFFER9 lpd3dIdxBuf = m_pModel->GetD3DIndexBuffer(); assert(lpd3dIdxBuf != NULL); const CGrannyModel::TMeshNode * pMeshNode = m_pModel->GetMeshNodeList(eMeshType, eMtrlType); @@ -290,7 +275,7 @@ void CGrannyModelInstance::RenderMeshNodeListWithoutTexture(CGrannyMesh::EType e while (pTriGroupNode) { ms_faceCount += pTriGroupNode->triCount; - STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vtxCount, pTriGroupNode->idxPos, pTriGroupNode->triCount); + STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vtxCount, pTriGroupNode->idxPos, pTriGroupNode->triCount, vtxMeshBasePos); pTriGroupNode = pTriGroupNode->pNextTriGroupNode; } ///// diff --git a/src/EterGrnLib/StdAfx.h b/src/EterGrnLib/StdAfx.h index 7fb6d3dd..e7ff8ae1 100644 --- a/src/EterGrnLib/StdAfx.h +++ b/src/EterGrnLib/StdAfx.h @@ -3,7 +3,7 @@ #pragma warning(disable:4786) // character 255 ³Ñ¾î°¡´Â°Å ²ô±â //#include -#include +#include #include "../eterBase/Utils.h" #include "../eterBase/Debug.h" diff --git a/src/EterLib/BlockTexture.cpp b/src/EterLib/BlockTexture.cpp index cede0053..a89e06f1 100644 --- a/src/EterLib/BlockTexture.cpp +++ b/src/EterLib/BlockTexture.cpp @@ -93,7 +93,7 @@ void CBlockTexture::Render(int ix, int iy) STATEMANAGER.SetTexture(0, m_lpd3dTexture); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_DIFFUSE); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_DIFFUSE); STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2); } } @@ -155,7 +155,7 @@ void CBlockTexture::InvalidateRect(const RECT & c_rsrcRect) bool CBlockTexture::Create(CGraphicDib * pDIB, const RECT & c_rRect, DWORD dwWidth, DWORD dwHeight) { - if (FAILED(ms_lpd3dDevice->CreateTexture(dwWidth, dwHeight, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_lpd3dTexture))) + if (FAILED(ms_lpd3dDevice->CreateTexture(dwWidth, dwHeight, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_lpd3dTexture, NULL))) { Tracef("Failed to create block texture %u, %u\n", dwWidth, dwHeight); return false; diff --git a/src/EterLib/BlockTexture.h b/src/EterLib/BlockTexture.h index 0b747d05..9d45d9bc 100644 --- a/src/EterLib/BlockTexture.h +++ b/src/EterLib/BlockTexture.h @@ -22,5 +22,5 @@ class CBlockTexture : public CGraphicBase BOOL m_bClipEnable; DWORD m_dwWidth; DWORD m_dwHeight; - LPDIRECT3DTEXTURE8 m_lpd3dTexture; + LPDIRECT3DTEXTURE9 m_lpd3dTexture; }; diff --git a/src/EterLib/Camera.cpp b/src/EterLib/Camera.cpp index 68fe5ea8..1d9110ec 100644 --- a/src/EterLib/Camera.cpp +++ b/src/EterLib/Camera.cpp @@ -279,7 +279,7 @@ void CCamera::SetViewMatrix() D3DXMatrixLookAtRH(&m_matView, &m_v3Eye, &m_v3Target, &m_v3Up); - float fDeterminantD3DMatView = D3DXMatrixfDeterminant(&m_matView); + float fDeterminantD3DMatView = D3DXMatrixDeterminant(&m_matView); D3DXMatrixInverse(&m_matInverseView, &fDeterminantD3DMatView, &m_matView); m_matBillboard = m_matInverseView; diff --git a/src/EterLib/Decal.cpp b/src/EterLib/Decal.cpp index c1bb6a19..30f6a327 100644 --- a/src/EterLib/Decal.cpp +++ b/src/EterLib/Decal.cpp @@ -225,7 +225,7 @@ void CDecal::Render() D3DXMatrixIdentity(&matWorld); STATEMANAGER.SetTransform(D3DTS_WORLD, &matWorld); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); for (DWORD dwi = 0; dwi < m_TriangleFanStructVector.size(); ++dwi) STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLEFAN, diff --git a/src/EterLib/GrpBase.cpp b/src/EterLib/GrpBase.cpp index b843e373..ca5bab91 100644 --- a/src/EterLib/GrpBase.cpp +++ b/src/EterLib/GrpBase.cpp @@ -27,11 +27,11 @@ D3D_CDisplayModeAutoDetector CGraphicBase::ms_kD3DDetector; HWND CGraphicBase::ms_hWnd; HDC CGraphicBase::ms_hDC; -LPDIRECT3D8 CGraphicBase::ms_lpd3d = NULL; -LPDIRECT3DDEVICE8 CGraphicBase::ms_lpd3dDevice = NULL; +LPDIRECT3D9 CGraphicBase::ms_lpd3d = NULL; +LPDIRECT3DDEVICE9 CGraphicBase::ms_lpd3dDevice = NULL; ID3DXMatrixStack * CGraphicBase::ms_lpd3dMatStack = NULL; D3DPRESENT_PARAMETERS CGraphicBase::ms_d3dPresentParameter; -D3DVIEWPORT8 CGraphicBase::ms_Viewport; +D3DVIEWPORT9 CGraphicBase::ms_Viewport; HRESULT CGraphicBase::ms_hLastResult = NULL; @@ -40,7 +40,7 @@ int CGraphicBase::ms_iHeight; DWORD CGraphicBase::ms_faceCount = 0; -D3DCAPS8 CGraphicBase::ms_d3dCaps; +D3DCAPS9 CGraphicBase::ms_d3dCaps; DWORD CGraphicBase::ms_dwD3DBehavior = 0; @@ -96,9 +96,9 @@ std::vector CGraphicBase::ms_fillCubeIdxVector; LPD3DXMESH CGraphicBase::ms_lpSphereMesh = NULL; LPD3DXMESH CGraphicBase::ms_lpCylinderMesh = NULL; -LPDIRECT3DVERTEXBUFFER8 CGraphicBase::ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM]; +LPDIRECT3DVERTEXBUFFER9 CGraphicBase::ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM]; -LPDIRECT3DINDEXBUFFER8 CGraphicBase::ms_alpd3dDefIB[DEFAULT_IB_NUM]; +LPDIRECT3DINDEXBUFFER9 CGraphicBase::ms_alpd3dDefIB[DEFAULT_IB_NUM]; bool CGraphicBase::IsLowTextureMemory() { @@ -158,7 +158,7 @@ bool CGraphicBase::SetPDTStream(SPDTVertexRaw* pSrcVertices, UINT uVtxCount) if (s_dwVBPos>=PDT_VERTEXBUFFER_NUM) s_dwVBPos=0; - IDirect3DVertexBuffer8* plpd3dFillRectVB=ms_alpd3dPDTVB[s_dwVBPos]; + IDirect3DVertexBuffer9* plpd3dFillRectVB = ms_alpd3dPDTVB[s_dwVBPos]; ++s_dwVBPos; assert(PDT_VERTEX_NUM>=uVtxCount); @@ -166,9 +166,7 @@ bool CGraphicBase::SetPDTStream(SPDTVertexRaw* pSrcVertices, UINT uVtxCount) return false; TPDTVertex* pDstVertices; - if (FAILED( - plpd3dFillRectVB->Lock(0, sizeof(TPDTVertex)*uVtxCount, (BYTE**)&pDstVertices, D3DLOCK_DISCARD) - )) + if (FAILED(plpd3dFillRectVB->Lock(0, sizeof(TPDTVertex) * uVtxCount, (void**)&pDstVertices, D3DLOCK_DISCARD))) { STATEMANAGER.SetStreamSource(0, NULL, 0); return false; diff --git a/src/EterLib/GrpBase.h b/src/EterLib/GrpBase.h index 543ca5c8..eeafa076 100644 --- a/src/EterLib/GrpBase.h +++ b/src/EterLib/GrpBase.h @@ -247,13 +247,13 @@ class CGraphicBase static HWND ms_hWnd; static HDC ms_hDC; - static LPDIRECT3D8 ms_lpd3d; - static LPDIRECT3DDEVICE8 ms_lpd3dDevice; + static LPDIRECT3D9 ms_lpd3d; + static LPDIRECT3DDEVICE9 ms_lpd3dDevice; static ID3DXMatrixStack* ms_lpd3dMatStack; - static D3DVIEWPORT8 ms_Viewport; + static D3DVIEWPORT9 ms_Viewport; static DWORD ms_faceCount; - static D3DCAPS8 ms_d3dCaps; + static D3DCAPS9 ms_d3dCaps; static D3DPRESENT_PARAMETERS ms_d3dPresentParameter; static DWORD ms_dwD3DBehavior; @@ -307,6 +307,6 @@ class CGraphicBase }; - static LPDIRECT3DVERTEXBUFFER8 ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM]; - static LPDIRECT3DINDEXBUFFER8 ms_alpd3dDefIB[DEFAULT_IB_NUM]; + static LPDIRECT3DVERTEXBUFFER9 ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM]; + static LPDIRECT3DINDEXBUFFER9 ms_alpd3dDefIB[DEFAULT_IB_NUM]; }; diff --git a/src/EterLib/GrpDetector.cpp b/src/EterLib/GrpDetector.cpp index 878dc3e7..9a3e975f 100644 --- a/src/EterLib/GrpDetector.cpp +++ b/src/EterLib/GrpDetector.cpp @@ -67,7 +67,7 @@ const D3DFORMAT& D3D_CAdapterDisplayModeList::GetPixelFormatr(UINT iD3DFmt) return m_aeD3DFmt[iD3DFmt]; } -VOID D3D_CAdapterDisplayModeList::Build(IDirect3D8& rkD3D, D3DFORMAT eD3DFmtDefault, UINT iD3DAdapterInfo) +VOID D3D_CAdapterDisplayModeList::Build(IDirect3D9& rkD3D, D3DFORMAT eD3DFmtDefault, UINT iD3DAdapterInfo) { D3DDISPLAYMODE* akD3DDM=m_akD3DDM; D3DFORMAT* aeD3DFmt=m_aeD3DFmt; @@ -77,11 +77,11 @@ VOID D3D_CAdapterDisplayModeList::Build(IDirect3D8& rkD3D, D3DFORMAT eD3DFmtDefa aeD3DFmt[uD3DFmtNum++]=eD3DFmtDefault; - UINT uAdapterModeNum=rkD3D.GetAdapterModeCount(iD3DAdapterInfo); + UINT uAdapterModeNum = rkD3D.GetAdapterModeCount(iD3DAdapterInfo, eD3DFmtDefault); for (UINT iD3DAdapterInfoMode=0; iD3DAdapterInfoMode +#include #include -typedef BOOL (*PFNCONFIRMDEVICE) (D3DCAPS8& rkD3DCaps, UINT uBehavior, D3DFORMAT eD3DFmt); +typedef BOOL(*PFNCONFIRMDEVICE) (D3DCAPS9& rkD3DCaps, UINT uBehavior, D3DFORMAT eD3DFmt); enum { @@ -29,7 +29,7 @@ class D3D_CAdapterDisplayModeList public: D3D_CAdapterDisplayModeList() {} ~D3D_CAdapterDisplayModeList() {} - VOID Build(IDirect3D8& rkD3D, D3DFORMAT eD3DFmtDefault, UINT iAdapter); + VOID Build(IDirect3D9& rkD3D, D3DFORMAT eD3DFmtDefault, UINT iAdapter); UINT GetDisplayModeNum(); UINT GetPixelFormatNum(); @@ -61,14 +61,14 @@ class D3D_CDeviceInfo public: D3D_CDeviceInfo() {} ~D3D_CDeviceInfo() {} - BOOL Build(IDirect3D8& rkD3D, UINT iAdapter, UINT iDevType, D3D_CAdapterDisplayModeList& rkD3DADMList, PFNCONFIRMDEVICE pfnConfirmDevice); - BOOL Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo); + BOOL Build(IDirect3D9& rkD3D, UINT iAdapter, UINT iDevType, D3D_CAdapterDisplayModeList& rkD3DADMList, PFNCONFIRMDEVICE pfnConfirmDevice); + BOOL Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo); UINT GetD3DModeInfoNum(); VOID GetString(std::string* pstEnumList); - BOOL FindDepthStencilFormat(IDirect3D8& rkD3D, UINT iAdapter, D3DDEVTYPE DeviceType, D3DFORMAT TargetFormat, D3DFORMAT* pDepthStencilFormat); + BOOL FindDepthStencilFormat(IDirect3D9& rkD3D, UINT iAdapter, D3DDEVTYPE DeviceType, D3DFORMAT TargetFormat, D3DFORMAT* pDepthStencilFormat); D3D_SModeInfo& GetD3DModeInfor(UINT iD3DModeInfo); D3D_SModeInfo* GetD3DModeInfop(UINT iD3DModeInfo); @@ -84,7 +84,7 @@ class D3D_CDeviceInfo const TCHAR* m_szDevDesc; D3DDEVTYPE m_eD3DDevType; - D3DCAPS8 m_kD3DCaps; + D3DCAPS9 m_kD3DCaps; BOOL m_canDoWindowed; UINT m_iCurD3DModeInfo; @@ -110,10 +110,10 @@ class D3D_CAdapterInfo ~D3D_CAdapterInfo() {} BOOL Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo); - BOOL Build(IDirect3D8& rkD3D, UINT iAdapter, PFNCONFIRMDEVICE pfnConfirmDevice); + BOOL Build(IDirect3D9& rkD3D, UINT iAdapter, PFNCONFIRMDEVICE pfnConfirmDevice); VOID GetString(std::string* pstEnumList); - D3DADAPTER_IDENTIFIER8& GetIdentifier() + D3DADAPTER_IDENTIFIER9& GetIdentifier() { return m_kD3DAdapterIdentifier; } @@ -132,7 +132,7 @@ class D3D_CAdapterInfo protected: - D3DADAPTER_IDENTIFIER8 m_kD3DAdapterIdentifier; + D3DADAPTER_IDENTIFIER9 m_kD3DAdapterIdentifier; D3DDISPLAYMODE m_kD3DDMDesktop; UINT m_iCurD3DDevInfo; @@ -148,7 +148,7 @@ class D3D_CDisplayModeAutoDetector ~D3D_CDisplayModeAutoDetector(); BOOL Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo, UINT* piD3DAdapterInfo); - BOOL Build(IDirect3D8& rkD3D, PFNCONFIRMDEVICE pfnConfirmDevice); + BOOL Build(IDirect3D9& rkD3D, PFNCONFIRMDEVICE pfnConfirmDevice); D3D_CAdapterInfo* GetD3DAdapterInfop(UINT iD3DAdapterInfo); D3D_SModeInfo* GetD3DModeInfop(UINT iD3DAdapterInfo, UINT iD3DDevInfo, UINT iD3DModeInfo); diff --git a/src/EterLib/GrpDevice.cpp b/src/EterLib/GrpDevice.cpp index 22ef0b45..bda3aa23 100644 --- a/src/EterLib/GrpDevice.cpp +++ b/src/EterLib/GrpDevice.cpp @@ -76,11 +76,11 @@ void CGraphicDevice::EnableWebBrowserMode(const RECT& c_rcWebPage) g_rcBrowser=c_rcWebPage; //rkD3DPP.Windowed=TRUE; - rkD3DPP.SwapEffect=D3DSWAPEFFECT_COPY; - rkD3DPP.BackBufferCount = 1; - rkD3DPP.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + rkD3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD; + rkD3DPP.BackBufferCount = 0; + rkD3DPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice; + IDirect3DDevice9& rkD3DDev = *ms_lpd3dDevice; HRESULT hr=rkD3DDev.Reset(&rkD3DPP); if (FAILED(hr)) return; @@ -99,7 +99,7 @@ void CGraphicDevice::DisableWebBrowserMode() rkD3DPP=g_kD3DPP; - IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice; + IDirect3DDevice9& rkD3DDev=*ms_lpd3dDevice; HRESULT hr=rkD3DDev.Reset(&rkD3DPP); if (FAILED(hr)) return; @@ -120,7 +120,7 @@ bool CGraphicDevice::ResizeBackBuffer(UINT uWidth, UINT uHeight) rkD3DPP.BackBufferWidth=uWidth; rkD3DPP.BackBufferHeight=uHeight; - IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice; + IDirect3DDevice9& rkD3DDev=*ms_lpd3dDevice; HRESULT hr=rkD3DDev.Reset(&rkD3DPP); if (FAILED(hr)) @@ -138,91 +138,13 @@ bool CGraphicDevice::ResizeBackBuffer(UINT uWidth, UINT uHeight) DWORD CGraphicDevice::CreatePNTStreamVertexShader() { assert(ms_lpd3dDevice != NULL); - - DWORD declVector[] = - { - D3DVSD_STREAM(0), - D3DVSD_REG(0, D3DVSDT_FLOAT3), - D3DVSD_REG(3, D3DVSDT_FLOAT3), - D3DVSD_REG(7, D3DVSDT_FLOAT2), - D3DVSD_END() - }; - - DWORD ret; - - if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0))) - return 0; - - return ret; + return D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1; } DWORD CGraphicDevice::CreatePNT2StreamVertexShader() { assert(ms_lpd3dDevice != NULL); - - DWORD declVector[] = - { - D3DVSD_STREAM(0), - D3DVSD_REG(0, D3DVSDT_FLOAT3), - D3DVSD_REG(3, D3DVSDT_FLOAT3), - D3DVSD_REG(7, D3DVSDT_FLOAT2), - D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2), -// D3DVSD_STREAM(1), - D3DVSD_END() - }; - - DWORD ret; - - if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0))) - return 0; - - return ret; -} - -DWORD CGraphicDevice::CreatePTStreamVertexShader() -{ - assert(ms_lpd3dDevice != NULL); - - DWORD declVector[] = - { - D3DVSD_STREAM(0), - D3DVSD_REG(0, D3DVSDT_FLOAT3), - D3DVSD_STREAM(1), - D3DVSD_REG(7, D3DVSDT_FLOAT2), - D3DVSD_END() - }; - - DWORD ret; - - if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0))) - return 0; - - return (ret); -} - -DWORD CGraphicDevice::CreateDoublePNTStreamVertexShader() -{ - assert(ms_lpd3dDevice != NULL); - - DWORD declVector[] = - { - D3DVSD_STREAM(0), - D3DVSD_REG(0, D3DVSDT_FLOAT3), - D3DVSD_REG(3, D3DVSDT_FLOAT3), - D3DVSD_REG(7, D3DVSDT_FLOAT2), - D3DVSD_STREAM(1), - D3DVSD_REG(D3DVSDE_POSITION2, D3DVSDT_FLOAT3), - D3DVSD_REG(D3DVSDE_NORMAL2, D3DVSDT_FLOAT3), - D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2), - D3DVSD_END() - }; - - DWORD ret; - - if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0))) - return 0; - - return ret; + return D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 | D3DFVF_TEX2; } CGraphicDevice::EDeviceState CGraphicDevice::GetDeviceState() @@ -256,10 +178,10 @@ bool CGraphicDevice::Reset() return true; } -static LPDIRECT3DSURFACE8 s_lpStencil; +static LPDIRECT3DSURFACE9 s_lpStencil; static DWORD s_MaxTextureWidth, s_MaxTextureHeight; -BOOL EL3D_ConfirmDevice(D3DCAPS8& rkD3DCaps, UINT uBehavior, D3DFORMAT /*eD3DFmt*/) +BOOL EL3D_ConfirmDevice(D3DCAPS9& rkD3DCaps, UINT uBehavior, D3DFORMAT /*eD3DFmt*/) { // PUREDEVICE´Â GetTransform / GetViewport µîÀÌ µÇÁö ¾Ê´Â´Ù. if (uBehavior & D3DCREATE_PUREDEVICE) @@ -307,7 +229,7 @@ DWORD GetMaxTextureHeight() bool CGraphicDevice::__IsInDriverBlackList(D3D_CAdapterInfo& rkD3DAdapterInfo) { - D3DADAPTER_IDENTIFIER8& rkD3DAdapterIdentifier=rkD3DAdapterInfo.GetIdentifier(); + D3DADAPTER_IDENTIFIER9& rkD3DAdapterIdentifier = rkD3DAdapterInfo.GetIdentifier(); char szSrcDriver[256]; strncpy(szSrcDriver, rkD3DAdapterIdentifier.Driver, sizeof(szSrcDriver)-1); @@ -356,7 +278,7 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int / ms_hWnd = hWnd; ms_hDC = GetDC(hWnd); - ms_lpd3d = Direct3DCreate8(D3D_SDK_VERSION); + ms_lpd3d = Direct3DCreate9(D3D_SDK_VERSION); if (!ms_lpd3d) return CREATE_NO_DIRECTX; @@ -393,7 +315,7 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int / return CREATE_DETECT; } - D3DADAPTER_IDENTIFIER8& rkD3DAdapterId=pkD3DAdapterInfo->GetIdentifier(); + D3DADAPTER_IDENTIFIER9& rkD3DAdapterId = pkD3DAdapterInfo->GetIdentifier(); if (Windowed && strnicmp(rkD3DAdapterId.Driver, "3dfx", 4)==0 && 22 == pkD3DAdapterInfo->GetDesktopD3DDisplayModer().Format) @@ -526,11 +448,11 @@ RETRY: ms_lpd3dDevice->GetViewport(&ms_Viewport); m_pStateManager = new CStateManager(ms_lpd3dDevice); + m_pStateManager->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE); D3DXCreateMatrixStack(0, &ms_lpd3dMatStack); ms_lpd3dMatStack->LoadIdentity(); - ms_ptVS = CreatePTStreamVertexShader(); ms_pntVS = CreatePNTStreamVertexShader(); ms_pnt2VS = CreatePNT2StreamVertexShader(); @@ -580,7 +502,7 @@ RETRY: else GRAPHICS_CAPS_CAN_NOT_TEXTURE_ADDRESS_BORDER=true; - //D3DADAPTER_IDENTIFIER8& rkD3DAdapterId=pkD3DAdapterInfo->GetIdentifier(); + //D3DADAPTER_IDENTIFIER9& rkD3DAdapterId=pkD3DAdapterInfo->GetIdentifier(); if (strnicmp(rkD3DAdapterId.Driver, "SIS", 3) == 0) { GRAPHICS_CAPS_CAN_NOT_DRAW_LINE = true; @@ -622,11 +544,12 @@ bool CGraphicDevice::__CreatePDTVertexBufferList() { if (FAILED( ms_lpd3dDevice->CreateVertexBuffer( - sizeof(TPDTVertex)*PDT_VERTEX_NUM, - D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, - D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1, - D3DPOOL_SYSTEMMEM, - &ms_alpd3dPDTVB[i]) + sizeof(TPDTVertex) * PDT_VERTEX_NUM, + D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, + D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1, + D3DPOOL_SYSTEMMEM, + &ms_alpd3dPDTVB[i], + NULL) )) return false; } @@ -655,17 +578,17 @@ bool CGraphicDevice::__CreateDefaultIndexBuffer(UINT eDefIB, UINT uIdxCount, con if (FAILED( ms_lpd3dDevice->CreateIndexBuffer( - sizeof(WORD)*uIdxCount, - D3DUSAGE_WRITEONLY, + sizeof(WORD) * uIdxCount, + D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, - &ms_alpd3dDefIB[eDefIB]) + &ms_alpd3dDefIB[eDefIB], + NULL) )) return false; WORD* dstIndices; - if (FAILED( - ms_alpd3dDefIB[eDefIB]->Lock(0, 0, (BYTE**)&dstIndices, 0) - )) return false; + if (FAILED(ms_alpd3dDefIB[eDefIB]->Lock(0, 0, (VOID**)&dstIndices, 0))) + return false; memcpy(dstIndices, c_awIndices, sizeof(WORD)*uIdxCount); @@ -729,23 +652,11 @@ void CGraphicDevice::Destroy() ms_hDC = NULL; } - if (ms_ptVS) - { - ms_lpd3dDevice->DeleteVertexShader(ms_ptVS); - ms_ptVS = 0;; - } - if (ms_pntVS) - { - ms_lpd3dDevice->DeleteVertexShader(ms_pntVS); ms_pntVS = 0; - } if (ms_pnt2VS) - { - ms_lpd3dDevice->DeleteVertexShader(ms_pnt2VS); ms_pnt2VS = 0; - } safe_release(ms_lpSphereMesh); safe_release(ms_lpCylinderMesh); diff --git a/src/EterLib/GrpExpandedImageInstance.cpp b/src/EterLib/GrpExpandedImageInstance.cpp index 1398b86d..a634a506 100644 --- a/src/EterLib/GrpExpandedImageInstance.cpp +++ b/src/EterLib/GrpExpandedImageInstance.cpp @@ -123,7 +123,7 @@ void CGraphicExpandedImageInstance::OnRender() STATEMANAGER.SetTexture(0, pTexture->GetD3DTexture()); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2); } //STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, c_FillRectIndices, D3DFMT_INDEX16, vertices, sizeof(TPDTVertex)); diff --git a/src/EterLib/GrpImageInstance.cpp b/src/EterLib/GrpImageInstance.cpp index 31a903f3..023f9c98 100644 --- a/src/EterLib/GrpImageInstance.cpp +++ b/src/EterLib/GrpImageInstance.cpp @@ -90,7 +90,7 @@ void CGraphicImageInstance::OnRender() STATEMANAGER.SetTexture(0, pTexture->GetD3DTexture()); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2); } //OLD: STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, c_FillRectIndices, D3DFMT_INDEX16, vertices, sizeof(TPDTVertex)); diff --git a/src/EterLib/GrpImageTexture.cpp b/src/EterLib/GrpImageTexture.cpp index 488fa5ee..95d72397 100644 --- a/src/EterLib/GrpImageTexture.cpp +++ b/src/EterLib/GrpImageTexture.cpp @@ -45,7 +45,7 @@ bool CGraphicImageTexture::CreateDeviceObjects() if (m_stFileName.empty()) { // ÆùÆ® ÅؽºÃÄ - if (FAILED(ms_lpd3dDevice->CreateTexture(m_width, m_height, 1, 0, m_d3dFmt, D3DPOOL_MANAGED, &m_lpd3dTexture))) + if (FAILED(ms_lpd3dDevice->CreateTexture(m_width, m_height, 1, 0, m_d3dFmt, D3DPOOL_MANAGED, &m_lpd3dTexture, NULL))) return false; } else @@ -96,7 +96,7 @@ bool CGraphicImageTexture::CreateDDSTexture(CDXTCImage & image, const BYTE * /*c int mipmapCount = image.m_dwMipMapCount == 0 ? 1 : image.m_dwMipMapCount; D3DFORMAT format; - LPDIRECT3DTEXTURE8 lpd3dTexture; + LPDIRECT3DTEXTURE9 lpd3dTexture; D3DPOOL pool = ms_bSupportDXT ? D3DPOOL_MANAGED : D3DPOOL_SCRATCH;; if(image.m_CompFormat == PF_DXT5) @@ -173,13 +173,13 @@ bool CGraphicImageTexture::CreateDDSTexture(CDXTCImage & image, const BYTE * /*c return false; } - IDirect3DTexture8* pkTexSrc=lpd3dTexture; - IDirect3DTexture8* pkTexDst=m_lpd3dTexture; + IDirect3DTexture9* pkTexSrc = lpd3dTexture; + IDirect3DTexture9* pkTexDst = m_lpd3dTexture; for(int i=0; iGetSurfaceLevel(i, &ppsSrc))) { @@ -216,22 +216,12 @@ bool CGraphicImageTexture::CreateFromMemoryFile(UINT bufSize, const void * c_pvB else { D3DXIMAGE_INFO imageInfo; - if (FAILED(D3DXCreateTextureFromFileInMemoryEx( - ms_lpd3dDevice, - c_pvBuf, - bufSize, - D3DX_DEFAULT, - D3DX_DEFAULT, - D3DX_DEFAULT, - 0, - d3dFmt, - D3DPOOL_MANAGED, - dwFilter, - dwFilter, - 0xffff00ff, - &imageInfo, - NULL, - &m_lpd3dTexture))) + if (FAILED(D3DXGetImageInfoFromFileInMemory(c_pvBuf, bufSize, &imageInfo))) + { + TraceError("CreateFromMemoryFile: Cannot GetImageInfo from texture"); + return false; + } + if (FAILED(D3DXCreateTextureFromFileInMemoryEx(ms_lpd3dDevice, c_pvBuf, bufSize, imageInfo.Width, imageInfo.Height, D3DX_DEFAULT, 0, d3dFmt, D3DPOOL_MANAGED, dwFilter, dwFilter, 0xffff00ff, NULL, NULL, &m_lpd3dTexture))) { TraceError("CreateFromMemoryFile: Cannot create texture"); return false; @@ -261,8 +251,8 @@ bool CGraphicImageTexture::CreateFromMemoryFile(UINT bufSize, const void * c_pvB if (IsLowTextureMemory()) if (uTexBias || format!=imageInfo.Format) { - IDirect3DTexture8* pkTexSrc=m_lpd3dTexture; - IDirect3DTexture8* pkTexDst; + IDirect3DTexture9* pkTexSrc=m_lpd3dTexture; + IDirect3DTexture9* pkTexDst; if (SUCCEEDED(D3DXCreateTexture( @@ -279,8 +269,8 @@ bool CGraphicImageTexture::CreateFromMemoryFile(UINT bufSize, const void * c_pvB for(int i=0; iGetSurfaceLevel(i, &ppsSrc))) { diff --git a/src/EterLib/GrpIndexBuffer.cpp b/src/EterLib/GrpIndexBuffer.cpp index dcdfa2b9..2608d416 100644 --- a/src/EterLib/GrpIndexBuffer.cpp +++ b/src/EterLib/GrpIndexBuffer.cpp @@ -3,7 +3,7 @@ #include "GrpIndexBuffer.h" #include "StateManager.h" -LPDIRECT3DINDEXBUFFER8 CGraphicIndexBuffer::GetD3DIndexBuffer() const +LPDIRECT3DINDEXBUFFER9 CGraphicIndexBuffer::GetD3DIndexBuffer() const { assert(m_lpd3dIdxBuf!=NULL); return m_lpd3dIdxBuf; @@ -20,7 +20,7 @@ bool CGraphicIndexBuffer::Lock(void** pretIndices) const { assert(m_lpd3dIdxBuf!=NULL); - if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (BYTE**)pretIndices, 0))) + if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, pretIndices, 0))) return false; return true; @@ -37,7 +37,7 @@ bool CGraphicIndexBuffer::Lock(void** pretIndices) { assert(m_lpd3dIdxBuf!=NULL); - if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (BYTE**)pretIndices, 0))) + if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, pretIndices, 0))) return false; return true; @@ -55,7 +55,7 @@ bool CGraphicIndexBuffer::Copy(int bufSize, const void* srcIndices) assert(m_lpd3dIdxBuf!=NULL); BYTE* dstIndices; - if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, &dstIndices, 0))) + if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (void**)&dstIndices, 0))) return false; memcpy(dstIndices, srcIndices, bufSize); @@ -73,7 +73,7 @@ bool CGraphicIndexBuffer::Create(int faceCount, TFace* faces) return false; WORD* dstIndices; - if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (BYTE**)&dstIndices, 0))) + if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (void**)&dstIndices, 0))) return false; for (int i = 0; iCreateIndexBuffer( - m_dwBufferSize, - D3DUSAGE_WRITEONLY, - m_d3dFmt, - D3DPOOL_MANAGED, - &m_lpd3dIdxBuf) - )) + if (FAILED(ms_lpd3dDevice->CreateIndexBuffer(m_dwBufferSize, D3DUSAGE_WRITEONLY, m_d3dFmt, D3DPOOL_MANAGED, &m_lpd3dIdxBuf, NULL))) return false; return true; diff --git a/src/EterLib/GrpIndexBuffer.h b/src/EterLib/GrpIndexBuffer.h index ba7cabb3..f793ee94 100644 --- a/src/EterLib/GrpIndexBuffer.h +++ b/src/EterLib/GrpIndexBuffer.h @@ -25,7 +25,7 @@ class CGraphicIndexBuffer : public CGraphicBase void SetIndices(int startIndex=0) const; - LPDIRECT3DINDEXBUFFER8 GetD3DIndexBuffer() const; + LPDIRECT3DINDEXBUFFER9 GetD3DIndexBuffer() const; int GetIndexCount() const {return m_iidxCount;} @@ -33,7 +33,7 @@ class CGraphicIndexBuffer : public CGraphicBase void Initialize(); protected: - LPDIRECT3DINDEXBUFFER8 m_lpd3dIdxBuf; + LPDIRECT3DINDEXBUFFER9 m_lpd3dIdxBuf; DWORD m_dwBufferSize; D3DFORMAT m_d3dFmt; int m_iidxCount; diff --git a/src/EterLib/GrpLightManager.cpp b/src/EterLib/GrpLightManager.cpp index f404ed07..bd76e6a0 100644 --- a/src/EterLib/GrpLightManager.cpp +++ b/src/EterLib/GrpLightManager.cpp @@ -32,7 +32,7 @@ void CLightManager::Initialize() m_LightPool.FreeAll(); } -void CLightManager::RegisterLight(ELightType /*LightType*/, TLightID * poutLightID, D3DLIGHT8 & LightData) +void CLightManager::RegisterLight(ELightType /*LightType*/, TLightID * poutLightID, D3DLIGHT9& LightData) { CLight * pLight = m_LightPool.Alloc(); TLightID ID = NewLightID(); @@ -212,7 +212,7 @@ void CLight::SetDeviceLight(BOOL bActive) } } -void CLight::SetParameter(TLightID id, const D3DLIGHT8 & c_rLight) +void CLight::SetParameter(TLightID id, const D3DLIGHT9 & c_rLight) { m_LightID = id; m_d3dLight = c_rLight; diff --git a/src/EterLib/GrpLightManager.h b/src/EterLib/GrpLightManager.h index 7000678e..a0567c4f 100644 --- a/src/EterLib/GrpLightManager.h +++ b/src/EterLib/GrpLightManager.h @@ -39,7 +39,7 @@ class CLight : public CGraphicBase, public CLightBase void Update(); - void SetParameter(TLightID id, const D3DLIGHT8 & c_rLight); + void SetParameter(TLightID id, const D3DLIGHT9 & c_rLight); void SetDistance(float fDistance); float GetDistance() const { return m_fDistance; } @@ -63,7 +63,7 @@ class CLight : public CGraphicBase, public CLightBase private: TLightID m_LightID; // Light ID. equal to D3D light index - D3DLIGHT8 m_d3dLight; + D3DLIGHT9 m_d3dLight; BOOL m_isEdited; float m_fDistance; @@ -100,7 +100,7 @@ class CLightManager : public CGraphicBase, public CLightBase, public CSingleton< void RestoreLight(); ///// - void RegisterLight(ELightType LightType, TLightID * poutLightID, D3DLIGHT8 & LightData); + void RegisterLight(ELightType LightType, TLightID * poutLightID, D3DLIGHT9 & LightData); CLight * GetLight(TLightID LightID); void DeleteLight(TLightID LightID); ///// diff --git a/src/EterLib/GrpMarkInstance.cpp b/src/EterLib/GrpMarkInstance.cpp index 6cce87c6..e78261e6 100644 --- a/src/EterLib/GrpMarkInstance.cpp +++ b/src/EterLib/GrpMarkInstance.cpp @@ -108,7 +108,7 @@ void CGraphicMarkInstance::OnRender() STATEMANAGER.SetTexture(0, pTexture->GetD3DTexture()); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2); //OLD: STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, c_FillRectIndices, D3DFMT_INDEX16, vertices, sizeof(TPDTVertex)); } diff --git a/src/EterLib/GrpPixelShader.cpp b/src/EterLib/GrpPixelShader.cpp index 0b1ffbe8..955bc4c6 100644 --- a/src/EterLib/GrpPixelShader.cpp +++ b/src/EterLib/GrpPixelShader.cpp @@ -21,11 +21,7 @@ void CPixelShader::Initialize() void CPixelShader::Destroy() { if (m_handle) - { - if (ms_lpd3dDevice) - ms_lpd3dDevice->DeletePixelShader(m_handle); m_handle=0; - } } bool CPixelShader::CreateFromDiskFile(const char* c_szFileName) @@ -34,16 +30,11 @@ bool CPixelShader::CreateFromDiskFile(const char* c_szFileName) LPD3DXBUFFER lpd3dxShaderBuffer; LPD3DXBUFFER lpd3dxErrorBuffer; - - if (FAILED( - D3DXAssembleShaderFromFile(c_szFileName, 0, NULL, &lpd3dxShaderBuffer, &lpd3dxErrorBuffer) - )) + + if (FAILED(D3DXAssembleShaderFromFileA(c_szFileName, 0, NULL, 0, &lpd3dxShaderBuffer, &lpd3dxErrorBuffer))) return false; - CDirect3DXBuffer shaderBuffer(lpd3dxShaderBuffer); - CDirect3DXBuffer errorBuffer(lpd3dxErrorBuffer); - - if (FAILED(ms_lpd3dDevice->CreatePixelShader((DWORD*)shaderBuffer.GetPointer(), &m_handle))) + if (FAILED(ms_lpd3dDevice->CreatePixelShader((const DWORD*)lpd3dxShaderBuffer->GetBufferPointer(), &m_handle))) return false; return true; diff --git a/src/EterLib/GrpPixelShader.h b/src/EterLib/GrpPixelShader.h index 2fb860a5..5f58106a 100644 --- a/src/EterLib/GrpPixelShader.h +++ b/src/EterLib/GrpPixelShader.h @@ -17,5 +17,5 @@ class CPixelShader : public CGraphicBase void Initialize(); protected: - DWORD m_handle; + LPDIRECT3DPIXELSHADER9 m_handle; }; diff --git a/src/EterLib/GrpScreen.cpp b/src/EterLib/GrpScreen.cpp index c2ed2da7..80cd27da 100644 --- a/src/EterLib/GrpScreen.cpp +++ b/src/EterLib/GrpScreen.cpp @@ -29,7 +29,7 @@ void CScreen::RenderLine3d(float sx, float sy, float sz, float ex, float ey, flo { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawPrimitive(D3DPT_LINELIST, 0, 1); } } @@ -61,7 +61,7 @@ void CScreen::RenderBox3d(float sx, float sy, float sz, float ex, float ey, floa { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawPrimitive(D3DPT_LINELIST, 0, 4); } } @@ -84,7 +84,7 @@ void CScreen::RenderBar3d(float sx, float sy, float sz, float ex, float ey, floa { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); } } @@ -106,7 +106,7 @@ void CScreen::RenderBar3d(const D3DXVECTOR3 * c_pv3Positions) { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); } } @@ -129,7 +129,7 @@ void CScreen::RenderGradationBar3d(float sx, float sy, float sz, float ex, float { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); } } @@ -153,7 +153,7 @@ void CScreen::RenderLineCube(float sx, float sy, float sz, float ex, float ey, f { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop()); SetDefaultIndexBuffer(DEFAULT_IB_LINE_CUBE); @@ -174,13 +174,13 @@ void CScreen::RenderCube(float sx, float sy, float sz, float ex, float ey, float { sx, ey, ez, ms_diffuseColor, 0.0f, 0.0f }, { ex, ey, ez, ms_diffuseColor, 0.0f, 0.0f }, }; - + if (SetPDTStream(vertices, 8)) { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop()); SetDefaultIndexBuffer(DEFAULT_IB_FILL_CUBE); @@ -220,7 +220,7 @@ void CScreen::RenderCube(float sx, float sy, float sz, float ex, float ey, float { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop()); SetDefaultIndexBuffer(DEFAULT_IB_FILL_CUBE); @@ -315,7 +315,7 @@ public: CD3DXMeshRenderingOption(D3DFILLMODE d3dFillMode, const D3DXMATRIX & c_rmatWorld) { - ms_lpd3dDevice->GetVertexShader(&m_dwVS); + ms_lpd3dDevice->GetFVF(&m_dwVS); STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); @@ -329,7 +329,7 @@ public: virtual ~CD3DXMeshRenderingOption() { - ms_lpd3dDevice->SetVertexShader(m_dwVS); + ms_lpd3dDevice->SetFVF(m_dwVS); STATEMANAGER.RestoreTransform(D3DTS_WORLD); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLORARG1); @@ -356,11 +356,11 @@ void CScreen::RenderD3DXMesh(LPD3DXMESH lpMesh, const D3DXMATRIX * c_pmatWorld, } CD3DXMeshRenderingOption SetRenderingOption(d3dFillMode, matWorld); - LPDIRECT3DINDEXBUFFER8 lpIndexBuffer; - LPDIRECT3DVERTEXBUFFER8 lpVertexBuffer; + LPDIRECT3DINDEXBUFFER9 lpIndexBuffer; + LPDIRECT3DVERTEXBUFFER9 lpVertexBuffer; lpMesh->GetIndexBuffer(&lpIndexBuffer); lpMesh->GetVertexBuffer(&lpVertexBuffer); - STATEMANAGER.SetVertexShader(lpMesh->GetFVF()); + STATEMANAGER.SetFVF(lpMesh->GetFVF()); STATEMANAGER.SetIndices(lpIndexBuffer, 0); STATEMANAGER.SetStreamSource(0, lpVertexBuffer, 24); STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, lpMesh->GetNumVertices(), 0, lpMesh->GetNumFaces()); @@ -401,7 +401,7 @@ void CScreen::RenderTextureBox(float sx, float sy, float ex, float ey, float z, #ifdef WORLD_EDITOR STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop()); #endif - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); // 2004.11.18.myevan.DrawIndexPrimitiveUP -> DynamicVertexBuffer SetDefaultIndexBuffer(DEFAULT_IB_FILL_RECT); @@ -431,8 +431,8 @@ void CScreen::RenderBillboard(D3DXVECTOR3 * Position, D3DXCOLOR & Color) vertices[3].position = TPosition(Position[3].x, Position[3].y, Position[3].z); vertices[3].diffuse = Color; vertices[3].texCoord = TTextureCoordinate(1, 1); - - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); // 2004.11.18.myevan.DrawIndexPrimitiveUP -> DynamicVertexBuffer SetDefaultIndexBuffer(DEFAULT_IB_FILL_RECT); @@ -631,7 +631,7 @@ BOOL CScreen::IsLostDevice() if (!ms_lpd3dDevice) return TRUE; - IDirect3DDevice8 & rkD3DDev = *ms_lpd3dDevice; + IDirect3DDevice9 & rkD3DDev = *ms_lpd3dDevice; HRESULT hrTestCooperativeLevel = rkD3DDev.TestCooperativeLevel(); if (FAILED(hrTestCooperativeLevel)) return TRUE; @@ -645,8 +645,8 @@ BOOL CScreen::RestoreDevice() return FALSE; UINT iD3DAdapterInfo = ms_iD3DAdapterInfo; - IDirect3D8 & rkD3D = *ms_lpd3d; - IDirect3DDevice8 & rkD3DDev = *ms_lpd3dDevice; + IDirect3D9& rkD3D = *ms_lpd3d; + IDirect3DDevice9& rkD3DDev = *ms_lpd3dDevice; D3DPRESENT_PARAMETERS & rkD3DPP = ms_d3dPresentParameter; D3D_CDisplayModeAutoDetector & rkD3DDetector = ms_kD3DDetector; @@ -848,11 +848,12 @@ void CScreen::BuildViewFrustum() { const D3DXVECTOR3& c_rv3Eye=CCameraManager::Instance().GetCurrentCamera()->GetEye(); const D3DXVECTOR3& c_rv3View=CCameraManager::Instance().GetCurrentCamera()->GetView(); - ms_frustum.BuildViewFrustum2( - ms_matView*ms_matProj, - ms_fNearY, - ms_fFarY, - ms_fFieldOfView, - ms_fAspect, - c_rv3Eye, c_rv3View); + D3DXMATRIX mat = ms_matView * ms_matProj; + ms_frustum.BuildViewFrustum2( + mat, + ms_fNearY, + ms_fFarY, + ms_fFieldOfView, + ms_fAspect, + c_rv3Eye, c_rv3View); } \ No newline at end of file diff --git a/src/EterLib/GrpShadowTexture.cpp b/src/EterLib/GrpShadowTexture.cpp index 1e02e78c..a49f9a4b 100644 --- a/src/EterLib/GrpShadowTexture.cpp +++ b/src/EterLib/GrpShadowTexture.cpp @@ -35,13 +35,13 @@ bool CGraphicShadowTexture::Create(int width, int height) m_width = width; m_height = height; - if (FAILED(ms_lpd3dDevice->CreateTexture(m_width, m_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_lpd3dShadowTexture))) + if (FAILED(ms_lpd3dDevice->CreateTexture(m_width, m_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_lpd3dShadowTexture, NULL))) return false; if (FAILED(m_lpd3dShadowTexture->GetSurfaceLevel(0, &m_lpd3dShadowSurface))) return false; - if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_width, m_height, D3DFMT_D16, D3DMULTISAMPLE_NONE, &m_lpd3dDepthSurface))) + if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_width, m_height, D3DFMT_R32F, D3DMULTISAMPLE_NONE, 0, false, &m_lpd3dDepthSurface, NULL))) return false; return true; @@ -57,7 +57,7 @@ const D3DXMATRIX& CGraphicShadowTexture::GetLightVPMatrixReference() const return m_d3dLightVPMatrix; } -LPDIRECT3DTEXTURE8 CGraphicShadowTexture::GetD3DTexture() const +LPDIRECT3DTEXTURE9 CGraphicShadowTexture::GetD3DTexture() const { return m_lpd3dShadowTexture; } @@ -66,13 +66,14 @@ void CGraphicShadowTexture::Begin() { D3DXMatrixMultiply(&m_d3dLightVPMatrix, &ms_matView, &ms_matProj); - ms_lpd3dDevice->GetRenderTarget(&m_lpd3dOldBackBufferSurface); + ms_lpd3dDevice->GetRenderTarget(0, &m_lpd3dOldBackBufferSurface); ms_lpd3dDevice->GetDepthStencilSurface(&m_lpd3dOldDepthBufferSurface); ms_lpd3dDevice->GetViewport(&m_d3dOldViewport); - ms_lpd3dDevice->SetRenderTarget(m_lpd3dShadowSurface, m_lpd3dDepthSurface); + ms_lpd3dDevice->GetRenderTarget(0, &m_lpd3dShadowSurface); + ms_lpd3dDevice->GetDepthStencilSurface(&m_lpd3dDepthSurface); - D3DVIEWPORT8 d3dViewport; + D3DVIEWPORT9 d3dViewport; d3dViewport.MinZ = 0.0f; d3dViewport.MaxZ = 1.0f; d3dViewport.X = 0; @@ -83,7 +84,7 @@ void CGraphicShadowTexture::Begin() ms_lpd3dDevice->SetViewport(&d3dViewport); ms_lpd3dDevice->BeginScene(); - ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L); + ms_lpd3dDevice->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0); STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_NONE); STATEMANAGER.SaveRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL); @@ -91,7 +92,7 @@ void CGraphicShadowTexture::Begin() STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, true); STATEMANAGER.SaveRenderState(D3DRS_TEXTUREFACTOR, 0xbb000000); - STATEMANAGER.SetTexture(0, NULL); + STATEMANAGER.SetTexture(0, m_lpd3dShadowTexture); STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR); STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE); STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); @@ -99,13 +100,13 @@ void CGraphicShadowTexture::Begin() STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE); STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); - STATEMANAGER.SetTexture(1, NULL); + STATEMANAGER.SetTexture(1, nullptr); STATEMANAGER.SaveTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT); STATEMANAGER.SaveTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE); STATEMANAGER.SaveTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1); @@ -113,11 +114,11 @@ void CGraphicShadowTexture::Begin() STATEMANAGER.SaveTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_TEXTURE); STATEMANAGER.SaveTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_MIPFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); } void CGraphicShadowTexture::End() @@ -127,7 +128,8 @@ void CGraphicShadowTexture::End() ms_lpd3dDevice->EndScene(); - ms_lpd3dDevice->SetRenderTarget(m_lpd3dOldBackBufferSurface, m_lpd3dOldDepthBufferSurface); + ms_lpd3dDevice->SetRenderTarget(0, m_lpd3dOldBackBufferSurface); + ms_lpd3dDevice->SetDepthStencilSurface(m_lpd3dOldDepthBufferSurface); ms_lpd3dDevice->SetViewport(&m_d3dOldViewport); m_lpd3dOldBackBufferSurface->Release(); @@ -149,11 +151,11 @@ void CGraphicShadowTexture::End() STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ALPHAARG2); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ALPHAOP); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MINFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MAGFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MIPFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSV); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MINFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MAGFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MIPFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSV); STATEMANAGER.RestoreTextureStageState(1, D3DTSS_COLORARG1); STATEMANAGER.RestoreTextureStageState(1, D3DTSS_COLORARG2); @@ -162,11 +164,11 @@ void CGraphicShadowTexture::End() STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ALPHAARG2); STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ALPHAOP); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MINFILTER); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MAGFILTER); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MIPFILTER); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSV); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_MINFILTER); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_MAGFILTER); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_MIPFILTER); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSV); } void CGraphicShadowTexture::Initialize() diff --git a/src/EterLib/GrpShadowTexture.h b/src/EterLib/GrpShadowTexture.h index e6b28825..0fb794e3 100644 --- a/src/EterLib/GrpShadowTexture.h +++ b/src/EterLib/GrpShadowTexture.h @@ -17,19 +17,19 @@ class CGraphicShadowTexture : public CGraphicTexture void Set(int stage = 0) const; const D3DXMATRIX& GetLightVPMatrixReference() const; - LPDIRECT3DTEXTURE8 GetD3DTexture() const; + LPDIRECT3DTEXTURE9 GetD3DTexture() const; protected: void Initialize(); protected: D3DXMATRIX m_d3dLightVPMatrix; - D3DVIEWPORT8 m_d3dOldViewport; - - LPDIRECT3DTEXTURE8 m_lpd3dShadowTexture; - LPDIRECT3DSURFACE8 m_lpd3dShadowSurface; - LPDIRECT3DSURFACE8 m_lpd3dDepthSurface; + D3DVIEWPORT9 m_d3dOldViewport; - LPDIRECT3DSURFACE8 m_lpd3dOldBackBufferSurface; - LPDIRECT3DSURFACE8 m_lpd3dOldDepthBufferSurface; + LPDIRECT3DTEXTURE9 m_lpd3dShadowTexture; + LPDIRECT3DSURFACE9 m_lpd3dShadowSurface; + LPDIRECT3DSURFACE9 m_lpd3dDepthSurface; + + LPDIRECT3DSURFACE9 m_lpd3dOldBackBufferSurface; + LPDIRECT3DSURFACE9 m_lpd3dOldDepthBufferSurface; }; diff --git a/src/EterLib/GrpTextInstance.cpp b/src/EterLib/GrpTextInstance.cpp index 1e08bffc..0b3e4145 100644 --- a/src/EterLib/GrpTextInstance.cpp +++ b/src/EterLib/GrpTextInstance.cpp @@ -539,7 +539,7 @@ void CGraphicTextInstance::Render(RECT * pClipRect) STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE); STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); diff --git a/src/EterLib/GrpTexture.cpp b/src/EterLib/GrpTexture.cpp index f1168e6a..9214a4b4 100644 --- a/src/EterLib/GrpTexture.cpp +++ b/src/EterLib/GrpTexture.cpp @@ -34,7 +34,7 @@ void CGraphicTexture::SetTextureStage(int stage) const STATEMANAGER.SetTexture(stage, m_lpd3dTexture); } -LPDIRECT3DTEXTURE8 CGraphicTexture::GetD3DTexture() const +LPDIRECT3DTEXTURE9 CGraphicTexture::GetD3DTexture() const { return m_lpd3dTexture; } diff --git a/src/EterLib/GrpTexture.h b/src/EterLib/GrpTexture.h index d56b1344..fc0f0ea8 100644 --- a/src/EterLib/GrpTexture.h +++ b/src/EterLib/GrpTexture.h @@ -11,7 +11,7 @@ class CGraphicTexture : public CGraphicBase int GetHeight() const; void SetTextureStage(int stage) const; - LPDIRECT3DTEXTURE8 GetD3DTexture() const; + LPDIRECT3DTEXTURE9 GetD3DTexture() const; void DestroyDeviceObjects(); @@ -28,5 +28,5 @@ class CGraphicTexture : public CGraphicBase int m_width; int m_height; - LPDIRECT3DTEXTURE8 m_lpd3dTexture; + LPDIRECT3DTEXTURE9 m_lpd3dTexture; }; diff --git a/src/EterLib/GrpVertexBuffer.cpp b/src/EterLib/GrpVertexBuffer.cpp index ef7b6c12..e6bfe1ac 100644 --- a/src/EterLib/GrpVertexBuffer.cpp +++ b/src/EterLib/GrpVertexBuffer.cpp @@ -31,7 +31,7 @@ bool CGraphicVertexBuffer::LockRange(unsigned count, void** pretVertices) const return false; DWORD dwLockSize=GetVertexStride() * count; - if (FAILED(m_lpd3dVB->Lock(0, dwLockSize, (BYTE **) pretVertices, m_dwLockFlag))) + if (FAILED(m_lpd3dVB->Lock(0, dwLockSize, pretVertices, m_dwLockFlag))) return false; return true; @@ -43,7 +43,7 @@ bool CGraphicVertexBuffer::Lock(void ** pretVertices) const return false; DWORD dwLockSize=GetVertexStride()*GetVertexCount(); - if (FAILED(m_lpd3dVB->Lock(0, dwLockSize, (BYTE **) pretVertices, m_dwLockFlag))) + if (FAILED(m_lpd3dVB->Lock(0, dwLockSize, pretVertices, m_dwLockFlag))) return false; return true; @@ -72,7 +72,7 @@ bool CGraphicVertexBuffer::LockDynamic(void** pretVertices) if (!m_lpd3dVB) return false; - if (FAILED(m_lpd3dVB->Lock(0, 0, (BYTE**)pretVertices, 0))) + if (FAILED(m_lpd3dVB->Lock(0, 0, pretVertices, 0))) return false; return true; @@ -83,7 +83,7 @@ bool CGraphicVertexBuffer::Lock(void ** pretVertices) if (!m_lpd3dVB) return false; - if (FAILED(m_lpd3dVB->Lock(0, 0, (BYTE**)pretVertices, m_dwLockFlag))) + if (FAILED(m_lpd3dVB->Lock(0, 0, pretVertices, m_dwLockFlag))) return false; return true; @@ -117,14 +117,7 @@ bool CGraphicVertexBuffer::CreateDeviceObjects() assert(ms_lpd3dDevice != NULL); assert(m_lpd3dVB == NULL); - if (FAILED( - ms_lpd3dDevice->CreateVertexBuffer( - m_dwBufferSize, - m_dwUsage, - m_dwFVF, - m_d3dPool, - &m_lpd3dVB) - )) + if (FAILED(ms_lpd3dDevice->CreateVertexBuffer(m_dwBufferSize, m_dwUsage, m_dwFVF, m_d3dPool, &m_lpd3dVB, NULL))) return false; return true; diff --git a/src/EterLib/GrpVertexBuffer.h b/src/EterLib/GrpVertexBuffer.h index 5bba8d7f..2e92d807 100644 --- a/src/EterLib/GrpVertexBuffer.h +++ b/src/EterLib/GrpVertexBuffer.h @@ -30,7 +30,7 @@ class CGraphicVertexBuffer : public CGraphicBase int GetVertexStride() const; DWORD GetFlexibleVertexFormat() const; - inline LPDIRECT3DVERTEXBUFFER8 GetD3DVertexBuffer() const { return m_lpd3dVB; } + inline LPDIRECT3DVERTEXBUFFER9 GetD3DVertexBuffer() const { return m_lpd3dVB; } inline DWORD GetBufferSize() const { return m_dwBufferSize; } bool IsEmpty() const; @@ -39,7 +39,7 @@ class CGraphicVertexBuffer : public CGraphicBase void Initialize(); protected: - LPDIRECT3DVERTEXBUFFER8 m_lpd3dVB; + LPDIRECT3DVERTEXBUFFER9 m_lpd3dVB; DWORD m_dwBufferSize; DWORD m_dwFVF; diff --git a/src/EterLib/GrpVertexShader.cpp b/src/EterLib/GrpVertexShader.cpp index 1592b41b..282cfa91 100644 --- a/src/EterLib/GrpVertexShader.cpp +++ b/src/EterLib/GrpVertexShader.cpp @@ -22,9 +22,7 @@ void CVertexShader::Destroy() { if (m_handle) { - if (ms_lpd3dDevice) - ms_lpd3dDevice->DeleteVertexShader(m_handle); - + m_handle->Release(); m_handle = 0; } } @@ -35,17 +33,10 @@ bool CVertexShader::CreateFromDiskFile(const char* c_szFileName, const DWORD* c_ LPD3DXBUFFER lpd3dxShaderBuffer; LPD3DXBUFFER lpd3dxErrorBuffer; - - if (FAILED( - D3DXAssembleShaderFromFile(c_szFileName, 0, NULL, &lpd3dxShaderBuffer, &lpd3dxErrorBuffer) - )) return false; + if (FAILED(D3DXAssembleShaderFromFile(c_szFileName, 0, NULL, 0, &lpd3dxShaderBuffer, &lpd3dxErrorBuffer))) + return false; - CDirect3DXBuffer shaderBuffer(lpd3dxShaderBuffer); - CDirect3DXBuffer errorBuffer(lpd3dxErrorBuffer); - - if (FAILED( - ms_lpd3dDevice->CreateVertexShader(c_pdwVertexDecl, (DWORD*)shaderBuffer.GetPointer(), &m_handle, 0 ) - )) + if (FAILED(ms_lpd3dDevice->CreateVertexShader((const DWORD*)lpd3dxShaderBuffer->GetBufferPointer(), &m_handle))) return false; return true; diff --git a/src/EterLib/GrpVertexShader.h b/src/EterLib/GrpVertexShader.h index 00da2677..52e9a06f 100644 --- a/src/EterLib/GrpVertexShader.h +++ b/src/EterLib/GrpVertexShader.h @@ -17,5 +17,5 @@ class CVertexShader : public CGraphicBase void Initialize(); protected: - DWORD m_handle; + LPDIRECT3DVERTEXSHADER9 m_handle; }; diff --git a/src/EterLib/LensFlare.cpp b/src/EterLib/LensFlare.cpp index c9e5d0b5..b9d13130 100644 --- a/src/EterLib/LensFlare.cpp +++ b/src/EterLib/LensFlare.cpp @@ -259,7 +259,7 @@ void CLensFlare::DrawBeforeFlare() STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(SVertex)); STATEMANAGER.RestoreRenderState(D3DRS_LIGHTING); @@ -540,7 +540,7 @@ void CFlare::Draw(float fBrightScale, int nWidth, int nHeight, int nX, int nY) float fDY = float(nY) - float(nHeight) / 2.0f; STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); diff --git a/src/EterLib/Ray.h b/src/EterLib/Ray.h index 6319b42e..b40ce093 100644 --- a/src/EterLib/Ray.h +++ b/src/EterLib/Ray.h @@ -1,6 +1,6 @@ #pragma once -#include +#include class CRay { diff --git a/src/EterLib/SkyBox.cpp b/src/EterLib/SkyBox.cpp index b80994bb..fcc743cb 100644 --- a/src/EterLib/SkyBox.cpp +++ b/src/EterLib/SkyBox.cpp @@ -820,7 +820,7 @@ void CSkyBox::Render() STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.SetTransform(D3DTS_WORLD, &m_matWorld); @@ -828,8 +828,8 @@ void CSkyBox::Render() if( m_ucRenderMode == CSkyObject::SKY_RENDER_MODE_TEXTURE ) { STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); for (unsigned int i = 0; i < 6; ++i) { @@ -844,8 +844,8 @@ void CSkyBox::Render() //STATEMANAGER.SetTexture( 0, NULL ); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSV); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSV); } else { diff --git a/src/EterLib/StateManager.cpp b/src/EterLib/StateManager.cpp index 5f3724a0..02dd76c5 100644 --- a/src/EterLib/StateManager.cpp +++ b/src/EterLib/StateManager.cpp @@ -10,20 +10,20 @@ struct SLightData { LIGHT_NUM = 8, }; - D3DLIGHT8 m_akD3DLight[LIGHT_NUM]; + D3DLIGHT9 m_akD3DLight[LIGHT_NUM]; } m_kLightData; -void CStateManager::SetLight(DWORD index, CONST D3DLIGHT8* pLight) +void CStateManager::SetLight(DWORD index, CONST D3DLIGHT9* pLight) { - assert(indexSetLight(index, pLight); } -void CStateManager::GetLight(DWORD index, D3DLIGHT8* pLight) +void CStateManager::GetLight(DWORD index, D3DLIGHT9* pLight) { assert(index<8); *pLight=m_kLightData.m_akD3DLight[index]; @@ -54,7 +54,7 @@ void CStateManager::EndScene() m_bScene=false; } -CStateManager::CStateManager(LPDIRECT3DDEVICE8 lpDevice) : m_lpD3DDev(NULL) +CStateManager::CStateManager(LPDIRECT3DDEVICE9 lpDevice) : m_lpD3DDev(NULL) { m_bScene = false; m_dwBestMinFilter = D3DTEXF_LINEAR; @@ -71,7 +71,7 @@ CStateManager::~CStateManager() } } -void CStateManager::SetDevice(LPDIRECT3DDEVICE8 lpDevice) +void CStateManager::SetDevice(LPDIRECT3DDEVICE9 lpDevice) { StateManager_Assert(lpDevice); lpDevice->AddRef(); @@ -84,7 +84,7 @@ void CStateManager::SetDevice(LPDIRECT3DDEVICE8 lpDevice) m_lpD3DDev = lpDevice; - D3DCAPS8 d3dCaps; + D3DCAPS9 d3dCaps; m_lpD3DDev->GetDeviceCaps(&d3dCaps); if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC) @@ -101,16 +101,16 @@ void CStateManager::SetDevice(LPDIRECT3DDEVICE8 lpDevice) dwMax = dwMax < 4 ? dwMax : 4; for (int i = 0; i < 8; ++i) - m_lpD3DDev->SetTextureStageState(i, D3DTSS_MAXANISOTROPY, dwMax); + m_lpD3DDev->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, dwMax); SetDefaultState(); } void CStateManager::SetBestFiltering(DWORD dwStage) { - SetTextureStageState(dwStage, D3DTSS_MINFILTER, m_dwBestMinFilter); - SetTextureStageState(dwStage, D3DTSS_MAGFILTER, m_dwBestMagFilter); - SetTextureStageState(dwStage, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); + SetSamplerState(dwStage, D3DSAMP_MINFILTER, m_dwBestMinFilter); + SetSamplerState(dwStage, D3DSAMP_MAGFILTER, m_dwBestMagFilter); + SetSamplerState(dwStage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); } void CStateManager::Restore() @@ -126,6 +126,10 @@ void CStateManager::Restore() for (j = 0; j < STATEMANAGER_MAX_TEXTURESTATES; ++j) SetTextureStageState(i, D3DTEXTURESTAGESTATETYPE(j), m_CurrentState.m_TextureStates[i][j]); + for (i = 0; i < STATEMANAGER_MAX_STAGES; ++i) + for (j = 0; j < STATEMANAGER_MAX_SAMPLERSTATES; ++j) + SetSamplerState(i, D3DSAMPLERSTATETYPE(j), m_CurrentState.m_SamplerStates[i][j]); + for (i = 0; i < STATEMANAGER_MAX_STAGES; ++i) SetTexture(i, m_CurrentState.m_Textures[i]); @@ -148,8 +152,8 @@ void CStateManager::SetDefaultState() SetTransform(D3DTS_VIEW, &Identity); SetTransform(D3DTS_PROJECTION, &Identity); - D3DMATERIAL8 DefaultMat; - ZeroMemory(&DefaultMat, sizeof(D3DMATERIAL8)); + D3DMATERIAL9 DefaultMat; + ZeroMemory(&DefaultMat, sizeof(D3DMATERIAL9)); DefaultMat.Diffuse.r = 1.0f; DefaultMat.Diffuse.g = 1.0f; @@ -176,24 +180,20 @@ void CStateManager::SetDefaultState() SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL); - SetRenderState(D3DRS_LINEPATTERN, 0xFFFFFFFF); SetRenderState(D3DRS_LASTPIXEL, FALSE); SetRenderState(D3DRS_ALPHAREF, 1); SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); - SetRenderState(D3DRS_ZVISIBLE, FALSE); SetRenderState(D3DRS_FOGSTART, 0); SetRenderState(D3DRS_FOGEND, 0); SetRenderState(D3DRS_FOGDENSITY, 0); - SetRenderState(D3DRS_EDGEANTIALIAS, FALSE); - SetRenderState(D3DRS_ZBIAS, 0); SetRenderState(D3DRS_STENCILWRITEMASK, 0xFFFFFFFF); SetRenderState(D3DRS_AMBIENT, 0x00000000); SetRenderState(D3DRS_LOCALVIEWER, FALSE); SetRenderState(D3DRS_NORMALIZENORMALS, FALSE); SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_DISABLE); SetRenderState(D3DRS_CLIPPLANEENABLE, 0); - SetRenderState(D3DRS_SOFTWAREVERTEXPROCESSING, FALSE); - SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE); + m_lpD3DDev->SetSoftwareVertexProcessing(false); + SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE); SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF); SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE); SetRenderState(D3DRS_COLORWRITEENABLE, 0xFFFFFFFF); @@ -293,75 +293,18 @@ void CStateManager::SetDefaultState() SetTextureStageState(6, D3DTSS_TEXCOORDINDEX, 6); SetTextureStageState(7, D3DTSS_TEXCOORDINDEX, 7); - SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - - SetTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - SetTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - SetTextureStageState(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - - SetTextureStageState(2, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - SetTextureStageState(2, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - SetTextureStageState(2, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - - SetTextureStageState(3, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - SetTextureStageState(3, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - SetTextureStageState(3, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - - SetTextureStageState(4, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - SetTextureStageState(4, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - SetTextureStageState(4, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - - SetTextureStageState(5, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - SetTextureStageState(5, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - SetTextureStageState(5, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - - SetTextureStageState(6, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - SetTextureStageState(6, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - SetTextureStageState(6, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - - SetTextureStageState(7, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - SetTextureStageState(7, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - SetTextureStageState(7, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - - SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - SetTextureStageState(2, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - SetTextureStageState(2, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - SetTextureStageState(3, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - SetTextureStageState(3, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - SetTextureStageState(4, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - SetTextureStageState(4, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - SetTextureStageState(5, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - SetTextureStageState(5, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - SetTextureStageState(6, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - SetTextureStageState(6, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - SetTextureStageState(7, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - SetTextureStageState(7, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - - SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, 0); - SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, 0); - SetTextureStageState(2, D3DTSS_TEXTURETRANSFORMFLAGS, 0); - SetTextureStageState(3, D3DTSS_TEXTURETRANSFORMFLAGS, 0); - SetTextureStageState(4, D3DTSS_TEXTURETRANSFORMFLAGS, 0); - SetTextureStageState(5, D3DTSS_TEXTURETRANSFORMFLAGS, 0); - SetTextureStageState(6, D3DTSS_TEXTURETRANSFORMFLAGS, 0); - SetTextureStageState(7, D3DTSS_TEXTURETRANSFORMFLAGS, 0); - - SetTexture(0, NULL); - SetTexture(1, NULL); - SetTexture(2, NULL); - SetTexture(3, NULL); - SetTexture(4, NULL); - SetTexture(5, NULL); - SetTexture(6, NULL); - SetTexture(7, NULL); - + for (DWORD i = 0; i < 8; ++i) + { + SetSamplerState(i, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + SetSamplerState(i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + SetSamplerState(i, D3DSAMP_MIPFILTER, D3DTEXF_ANISOTROPIC); + SetSamplerState(i, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + SetSamplerState(i, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); + SetTextureStageState(i, D3DTSS_TEXTURETRANSFORMFLAGS, 0); + SetTexture(i, NULL); + } SetPixelShader(0); - SetVertexShader(D3DFVF_XYZ); + SetFVF(D3DFVF_XYZ); D3DXVECTOR4 av4Null[STATEMANAGER_MAX_VCONSTANTS]; memset(av4Null, 0, sizeof(av4Null)); @@ -381,6 +324,10 @@ void CStateManager::SetDefaultState() for (j = 0; j < STATEMANAGER_MAX_STAGES; ++j) for (i = 0; i < STATEMANAGER_MAX_TEXTURESTATES; ++i) m_bTextureStageStateSavingFlag[j][i] = FALSE; + + for (j = 0; j < STATEMANAGER_MAX_STAGES; ++j) + for (i = 0; i < STATEMANAGER_MAX_SAMPLERSTATES; ++i) + m_bSamplerStateSavingFlag[j][i] = FALSE; #endif _DEBUG } @@ -390,7 +337,7 @@ void CStateManager::SaveMaterial() m_CopyState.m_D3DMaterial = m_CurrentState.m_D3DMaterial; } -void CStateManager::SaveMaterial(const D3DMATERIAL8 * pMaterial) +void CStateManager::SaveMaterial(const D3DMATERIAL9* pMaterial) { // Check that we have set this up before, if not, the default is this. m_CopyState.m_D3DMaterial = m_CurrentState.m_D3DMaterial; @@ -402,13 +349,13 @@ void CStateManager::RestoreMaterial() SetMaterial(&m_CopyState.m_D3DMaterial); } -void CStateManager::SetMaterial(const D3DMATERIAL8 * pMaterial) +void CStateManager::SetMaterial(const D3DMATERIAL9* pMaterial) { m_lpD3DDev->SetMaterial(pMaterial); m_CurrentState.m_D3DMaterial = *pMaterial; } -void CStateManager::GetMaterial(D3DMATERIAL8 * pMaterial) +void CStateManager::GetMaterial(D3DMATERIAL9* pMaterial) { // Set the renderstate and remember it. *pMaterial = m_CurrentState.m_D3DMaterial; @@ -465,7 +412,7 @@ void CStateManager::GetRenderState(D3DRENDERSTATETYPE Type, DWORD * pdwValue) } // Textures -void CStateManager::SaveTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture) +void CStateManager::SaveTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9 pTexture) { // Check that we have set this up before, if not, the default is this. m_CopyState.m_Textures[dwStage] = m_CurrentState.m_Textures[dwStage]; @@ -477,7 +424,7 @@ void CStateManager::RestoreTexture(DWORD dwStage) SetTexture(dwStage, m_CopyState.m_Textures[dwStage]); } -void CStateManager::SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture) +void CStateManager::SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9 pTexture) { if (pTexture == m_CurrentState.m_Textures[dwStage]) return; @@ -486,13 +433,13 @@ void CStateManager::SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture) m_CurrentState.m_Textures[dwStage] = pTexture; } -void CStateManager::GetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 * ppTexture) +void CStateManager::GetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9* ppTexture) { *ppTexture = m_CurrentState.m_Textures[dwStage]; } // Texture stage states -void CStateManager::SaveTextureStageState(DWORD dwStage,D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue) +void CStateManager::SaveTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue) { // Check that we have set this up before, if not, the default is this. #ifdef _DEBUG @@ -534,8 +481,52 @@ void CStateManager::GetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE *pdwValue = m_CurrentState.m_TextureStates[dwStage][Type]; } +// DirectX 9 upgrade +void CStateManager::SaveSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD dwValue) +{ + // Check that we have set this up before, if not, the default is this. +#ifdef _DEBUG + if (m_bSamplerStateSavingFlag[dwStage][Type]) + { + Tracef(" CStateManager::SaveSamplerState - This sampler state is already saved [%d, %d]\n", dwStage, Type); + StateManager_Assert(!" This sampler state is already saved!"); + } + m_bSamplerStateSavingFlag[dwStage][Type] = TRUE; +#endif _DEBUG + m_CopyState.m_SamplerStates[dwStage][Type] = m_CurrentState.m_SamplerStates[dwStage][Type]; + SetSamplerState(dwStage, Type, dwValue); +} + +void CStateManager::RestoreSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type) +{ +#ifdef _DEBUG + if (!m_bSamplerStateSavingFlag[dwStage][Type]) + { + Tracef(" CStateManager::RestoreSamplerState - This sampler state was not saved [%d, %d]\n", dwStage, Type); + StateManager_Assert(!" This sampler state was not saved!"); + } + m_bSamplerStateSavingFlag[dwStage][Type] = FALSE; +#endif _DEBUG + SetSamplerState(dwStage, Type, m_CopyState.m_SamplerStates[dwStage][Type]); +} + +void CStateManager::SetSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD dwValue) +{ + if (m_CurrentState.m_SamplerStates[dwStage][Type] == dwValue) + return; + + m_lpD3DDev->SetSamplerState(dwStage, Type, dwValue); + + m_CurrentState.m_SamplerStates[dwStage][Type] = dwValue; +} + +void CStateManager::GetSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD* pdwValue) +{ + *pdwValue = m_CurrentState.m_SamplerStates[dwStage][Type]; +} + // Vertex Shader -void CStateManager::SaveVertexShader(DWORD dwShader) +void CStateManager::SaveVertexShader(LPDIRECT3DVERTEXSHADER9 dwShader) { m_CopyState.m_dwVertexShader = m_CurrentState.m_dwVertexShader; SetVertexShader(dwShader); @@ -546,22 +537,49 @@ void CStateManager::RestoreVertexShader() SetVertexShader(m_CopyState.m_dwVertexShader); } -void CStateManager::SetVertexShader(DWORD dwShader) +void CStateManager::SetVertexShader(LPDIRECT3DVERTEXSHADER9 dwShader) { - if (m_CurrentState.m_dwVertexShader == dwShader) - return; - - m_lpD3DDev->SetVertexShader(dwShader); - m_CurrentState.m_dwVertexShader = dwShader; + if (m_CurrentState.m_dwVertexShader != dwShader) + { + m_CurrentState.m_dwVertexShader = dwShader; + m_lpD3DDev->SetVertexShader(dwShader); + } } -void CStateManager::GetVertexShader(DWORD * pdwShader) +void CStateManager::GetVertexShader(LPDIRECT3DVERTEXSHADER9* pdwShader) { *pdwShader = m_CurrentState.m_dwVertexShader; } + +// Vertex Declaration +void CStateManager::SaveVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 dwShader) +{ + m_CopyState.m_dwVertexDeclaration = m_CurrentState.m_dwVertexDeclaration; + SetVertexDeclaration(dwShader); +} + +void CStateManager::RestoreVertexDeclaration() +{ + SetVertexDeclaration(m_CopyState.m_dwVertexDeclaration); +} + +void CStateManager::SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 dwShader) +{ + if (m_CurrentState.m_dwVertexDeclaration == dwShader) + return; + + m_lpD3DDev->SetVertexDeclaration(dwShader); + m_CurrentState.m_dwVertexDeclaration = dwShader; +} + +void CStateManager::GetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9* pdwShader) +{ + *pdwShader = m_CurrentState.m_dwVertexDeclaration; +} + // Pixel Shader -void CStateManager::SavePixelShader(DWORD dwShader) +void CStateManager::SavePixelShader(LPDIRECT3DPIXELSHADER9 dwShader) { m_CopyState.m_dwPixelShader = m_CurrentState.m_dwPixelShader; SetPixelShader(dwShader); @@ -572,20 +590,46 @@ void CStateManager::RestorePixelShader() SetPixelShader(m_CopyState.m_dwPixelShader); } -void CStateManager::SetPixelShader(DWORD dwShader) +void CStateManager::SetPixelShader(LPDIRECT3DPIXELSHADER9 dwShader) { - if (m_CurrentState.m_dwPixelShader == dwShader) - return; - - m_lpD3DDev->SetPixelShader(dwShader); - m_CurrentState.m_dwPixelShader = dwShader; + if (m_CurrentState.m_dwPixelShader != dwShader) { + m_CurrentState.m_dwPixelShader = dwShader; + m_lpD3DDev->SetPixelShader(dwShader); + } } -void CStateManager::GetPixelShader(DWORD * pdwShader) +void CStateManager::GetPixelShader(LPDIRECT3DPIXELSHADER9* pdwShader) { *pdwShader = m_CurrentState.m_dwPixelShader; } + +// FVF +void CStateManager::SaveFVF(DWORD dwFVF) +{ + m_CopyState.m_dwFVF = m_CurrentState.m_dwFVF; + SetFVF(dwFVF); +} + +void CStateManager::RestoreFVF() +{ + SetFVF(m_CopyState.m_dwFVF); +} + +void CStateManager::SetFVF(DWORD dwFVF) +{ + if (m_CurrentState.m_dwFVF != dwFVF) + { + m_lpD3DDev->SetFVF(dwFVF); + m_CurrentState.m_dwFVF = dwFVF; + } +} + +void CStateManager::GetFVF(DWORD* dwFVF) +{ + *dwFVF = m_CurrentState.m_dwFVF; +} + // *** These states are cached, but not protected from multiple sends of the same value. // Transform void CStateManager::SaveTransform(D3DTRANSFORMSTATETYPE Type, const D3DMATRIX* pMatrix) @@ -640,9 +684,7 @@ void CStateManager::GetTransform(D3DTRANSFORMSTATETYPE Type, D3DMATRIX * pMatrix // SetVertexShaderConstant void CStateManager::SaveVertexShaderConstant(DWORD dwRegister,CONST void* pConstantData,DWORD dwConstantCount) { - DWORD i; - - for (i = 0; i < dwConstantCount; i++) + for (DWORD i = 0; i < dwConstantCount; i++) { StateManager_Assert((dwRegister + i) < STATEMANAGER_MAX_VCONSTANTS); m_CopyState.m_VertexShaderConstants[dwRegister + i] = m_CurrentState.m_VertexShaderConstants[dwRegister + i]; @@ -651,14 +693,14 @@ void CStateManager::SaveVertexShaderConstant(DWORD dwRegister,CONST void* pConst SetVertexShaderConstant(dwRegister, pConstantData, dwConstantCount); } -void CStateManager::RestoreVertexShaderConstant(DWORD dwRegister, DWORD dwConstantCount) +void CStateManager::RestoreVertexShaderConstant(UINT dwRegister, UINT dwConstantCount) { SetVertexShaderConstant(dwRegister, &m_CopyState.m_VertexShaderConstants[dwRegister], dwConstantCount); } void CStateManager::SetVertexShaderConstant(DWORD dwRegister,CONST void* pConstantData,DWORD dwConstantCount) { - m_lpD3DDev->SetVertexShaderConstant(dwRegister, pConstantData, dwConstantCount); + m_lpD3DDev->SetVertexShaderConstantF(dwRegister, (const float*)pConstantData, dwConstantCount); // Set the renderstate and remember it. for (DWORD i = 0; i < dwConstantCount; i++) @@ -671,9 +713,7 @@ void CStateManager::SetVertexShaderConstant(DWORD dwRegister,CONST void* pConsta // SetPixelShaderConstant void CStateManager::SavePixelShaderConstant(DWORD dwRegister,CONST void* pConstantData,DWORD dwConstantCount) { - DWORD i; - - for (i = 0; i < dwConstantCount; i++) + for (DWORD i = 0; i < dwConstantCount; i++) { StateManager_Assert((dwRegister + i) < STATEMANAGER_MAX_VCONSTANTS); m_CopyState.m_PixelShaderConstants[dwRegister + i] = *(((D3DXVECTOR4*)pConstantData) + i); @@ -682,14 +722,9 @@ void CStateManager::SavePixelShaderConstant(DWORD dwRegister,CONST void* pConsta SetPixelShaderConstant(dwRegister, pConstantData, dwConstantCount); } -void CStateManager::RestorePixelShaderConstant(DWORD dwRegister, DWORD dwConstantCount) -{ - SetPixelShaderConstant(dwRegister, &m_CopyState.m_PixelShaderConstants[dwRegister], dwConstantCount); -} - void CStateManager::SetPixelShaderConstant(DWORD dwRegister,CONST void* pConstantData,DWORD dwConstantCount) { - m_lpD3DDev->SetPixelShaderConstant(dwRegister, pConstantData, dwConstantCount); + m_lpD3DDev->SetPixelShaderConstantF(dwRegister, (const float*)pConstantData, dwConstantCount); // Set the renderstate and remember it. for (DWORD i = 0; i < dwConstantCount; i++) @@ -699,7 +734,12 @@ void CStateManager::SetPixelShaderConstant(DWORD dwRegister,CONST void* pConstan } } -void CStateManager::SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData,UINT Stride) +void CStateManager::RestorePixelShaderConstant(UINT dwRegister, UINT dwConstantCount) +{ + SetPixelShaderConstant(dwRegister, &m_CopyState.m_PixelShaderConstants[dwRegister], dwConstantCount); +} + +void CStateManager::SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER9 pStreamData, UINT Stride) { // Check that we have set this up before, if not, the default is this. m_CopyState.m_StreamData[StreamNumber] = m_CurrentState.m_StreamData[StreamNumber]; @@ -713,17 +753,17 @@ void CStateManager::RestoreStreamSource(UINT StreamNumber) m_CopyState.m_StreamData[StreamNumber].m_Stride); } -void CStateManager::SetStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData, UINT Stride) +void CStateManager::SetStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER9 pStreamData, UINT Stride) { CStreamData kStreamData(pStreamData, Stride); if (m_CurrentState.m_StreamData[StreamNumber] == kStreamData) return; - m_lpD3DDev->SetStreamSource(StreamNumber, pStreamData, Stride); + m_lpD3DDev->SetStreamSource(StreamNumber, pStreamData, 0, Stride); m_CurrentState.m_StreamData[StreamNumber] = kStreamData; } -void CStateManager::SaveIndices(LPDIRECT3DINDEXBUFFER8 pIndexData, UINT BaseVertexIndex) +void CStateManager::SaveIndices(LPDIRECT3DINDEXBUFFER9 pIndexData, UINT BaseVertexIndex) { m_CopyState.m_IndexData = m_CurrentState.m_IndexData; SetIndices(pIndexData, BaseVertexIndex); @@ -734,14 +774,14 @@ void CStateManager::RestoreIndices() SetIndices(m_CopyState.m_IndexData.m_lpIndexData, m_CopyState.m_IndexData.m_BaseVertexIndex); } -void CStateManager::SetIndices(LPDIRECT3DINDEXBUFFER8 pIndexData, UINT BaseVertexIndex) +void CStateManager::SetIndices(LPDIRECT3DINDEXBUFFER9 pIndexData, UINT BaseVertexIndex) { CIndexData kIndexData(pIndexData, BaseVertexIndex); if (m_CurrentState.m_IndexData == kIndexData) return; - - m_lpD3DDev->SetIndices(pIndexData, BaseVertexIndex); + + m_lpD3DDev->SetIndices(pIndexData); m_CurrentState.m_IndexData = kIndexData; } @@ -756,9 +796,9 @@ HRESULT CStateManager::DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT Prim return (m_lpD3DDev->DrawPrimitiveUP(PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride)); } -HRESULT CStateManager::DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT minIndex, UINT NumVertices, UINT startIndex, UINT primCount) +HRESULT CStateManager::DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT minIndex, UINT NumVertices, UINT startIndex, UINT primCount, INT baseVertexIndex) { - return (m_lpD3DDev->DrawIndexedPrimitive(PrimitiveType, minIndex, NumVertices, startIndex, primCount)); + return (m_lpD3DDev->DrawIndexedPrimitive(PrimitiveType, baseVertexIndex, minIndex, NumVertices, startIndex, primCount)); } HRESULT CStateManager::DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, CONST void * pIndexData, D3DFORMAT IndexDataFormat, CONST void * pVertexStreamZeroData, UINT VertexStreamZeroStride) diff --git a/src/EterLib/StateManager.h b/src/EterLib/StateManager.h index 01dd9b48..dc58dc92 100644 --- a/src/EterLib/StateManager.h +++ b/src/EterLib/StateManager.h @@ -38,11 +38,10 @@ ******************************************************************************/ -#ifndef __CSTATEMANAGER_H -#define __CSTATEMANAGER_H +#pragma once -#include -#include +#include +#include #include @@ -58,6 +57,7 @@ static const DWORD STATEMANAGER_MAX_RENDERSTATES = 256; static const DWORD STATEMANAGER_MAX_TEXTURESTATES = 128; +static const DWORD STATEMANAGER_MAX_SAMPLERSTATES = 128; static const DWORD STATEMANAGER_MAX_STAGES = 8; static const DWORD STATEMANAGER_MAX_VCONSTANTS = 96; static const DWORD STATEMANAGER_MAX_PCONSTANTS = 8; @@ -67,7 +67,7 @@ static const DWORD STATEMANAGER_MAX_STREAMS = 16; class CStreamData { public: - CStreamData(LPDIRECT3DVERTEXBUFFER8 pStreamData = NULL, UINT Stride = 0) : m_lpStreamData(pStreamData), m_Stride(Stride) + CStreamData(LPDIRECT3DVERTEXBUFFER9 pStreamData = NULL, UINT Stride = 0) : m_lpStreamData(pStreamData), m_Stride(Stride) { } @@ -75,15 +75,14 @@ class CStreamData { return ((m_lpStreamData == rhs.m_lpStreamData) && (m_Stride == rhs.m_Stride)); } - - LPDIRECT3DVERTEXBUFFER8 m_lpStreamData; + LPDIRECT3DVERTEXBUFFER9 m_lpStreamData; UINT m_Stride; }; class CIndexData { public: - CIndexData(LPDIRECT3DINDEXBUFFER8 pIndexData = NULL, UINT BaseVertexIndex = 0) + CIndexData(LPDIRECT3DINDEXBUFFER9 pIndexData = NULL, UINT BaseVertexIndex = 0) : m_lpIndexData(pIndexData), m_BaseVertexIndex(BaseVertexIndex) { @@ -94,7 +93,7 @@ class CIndexData return ((m_lpIndexData == rhs.m_lpIndexData) && (m_BaseVertexIndex == rhs.m_BaseVertexIndex)); } - LPDIRECT3DINDEXBUFFER8 m_lpIndexData; + LPDIRECT3DINDEXBUFFER9 m_lpIndexData; UINT m_BaseVertexIndex; }; @@ -170,10 +169,14 @@ class CStateManagerState for (i = 0; i < STATEMANAGER_MAX_RENDERSTATES; i++) m_RenderStates[i] = 0x7FFFFFFF; - for (i = 0; i < STATEMANAGER_MAX_STAGES; i++) - for (y = 0; y < STATEMANAGER_MAX_TEXTURESTATES; y++) + for (i = 0; i < STATEMANAGER_MAX_STAGES; ++i) + for (y = 0; y < STATEMANAGER_MAX_TEXTURESTATES; ++y) m_TextureStates[i][y] = 0x7FFFFFFF; + for (i = 0; i < STATEMANAGER_MAX_STAGES; ++i) + for (y = 0; y < STATEMANAGER_MAX_SAMPLERSTATES; ++y) + m_SamplerStates[i][y] = 0x7FFFFFFF; + for (i = 0; i < STATEMANAGER_MAX_STREAMS; i++) m_StreamData[i] = CStreamData(); @@ -182,7 +185,7 @@ class CStateManagerState for (i = 0; i < STATEMANAGER_MAX_STAGES; i++) m_Textures[i] = NULL; - // Matrices and constants are not cached, just restored. It's silly to check all the + // Matrices and constants are not cached, just restored. It's silly to check all the // data elements (by which time the driver could have been sent them). for (i = 0; i < STATEMANAGER_MAX_TRANSFORMSTATES; i++) D3DXMatrixIdentity(&m_Matrices[i]); @@ -193,8 +196,9 @@ class CStateManagerState for (i = 0; i < STATEMANAGER_MAX_PCONSTANTS; i++) m_PixelShaderConstants[i] = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f); - m_dwPixelShader = 0; - m_dwVertexShader = D3DFVF_XYZ; + m_dwFVF = D3DFVF_XYZ; + m_dwVertexShader = NULL; + m_dwPixelShader = NULL; ZeroMemory(&m_Matrices, sizeof(D3DXMATRIX) * STATEMANAGER_MAX_TRANSFORMSTATES); } @@ -205,6 +209,9 @@ class CStateManagerState // Texture stage states DWORD m_TextureStates[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_TEXTURESTATES]; + // Texture sampler states + DWORD m_SamplerStates[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_SAMPLERSTATES]; + // Vertex shader constants D3DXVECTOR4 m_VertexShaderConstants[STATEMANAGER_MAX_VCONSTANTS]; @@ -212,15 +219,18 @@ class CStateManagerState D3DXVECTOR4 m_PixelShaderConstants[STATEMANAGER_MAX_PCONSTANTS]; // Textures - LPDIRECT3DBASETEXTURE8 m_Textures[STATEMANAGER_MAX_STAGES]; + LPDIRECT3DBASETEXTURE9 m_Textures[STATEMANAGER_MAX_STAGES]; // Shaders - DWORD m_dwPixelShader; - DWORD m_dwVertexShader; + LPDIRECT3DVERTEXSHADER9 m_dwVertexShader; + LPDIRECT3DVERTEXDECLARATION9 m_dwVertexDeclaration; + LPDIRECT3DPIXELSHADER9 m_dwPixelShader; + + DWORD m_dwFVF; D3DXMATRIX m_Matrices[STATEMANAGER_MAX_TRANSFORMSTATES]; - D3DMATERIAL8 m_D3DMaterial; + D3DMATERIAL9 m_D3DMaterial; CStreamData m_StreamData[STATEMANAGER_MAX_STREAMS]; CIndexData m_IndexData; @@ -229,7 +239,7 @@ class CStateManagerState class CStateManager : public CSingleton { public: - CStateManager(LPDIRECT3DDEVICE8 lpDevice); + CStateManager(LPDIRECT3DDEVICE9 lpDevice); virtual ~CStateManager(); void SetDefaultState(); @@ -237,47 +247,60 @@ class CStateManager : public CSingleton bool BeginScene(); void EndScene(); - + // Material void SaveMaterial(); - void SaveMaterial(const D3DMATERIAL8 * pMaterial); + void SaveMaterial(const D3DMATERIAL9* pMaterial); void RestoreMaterial(); - void SetMaterial(const D3DMATERIAL8 * pMaterial); - void GetMaterial(D3DMATERIAL8 * pMaterial); + void SetMaterial(const D3DMATERIAL9* pMaterial); + void GetMaterial(D3DMATERIAL9* pMaterial); - void SetLight(DWORD index, CONST D3DLIGHT8* pLight); - void GetLight(DWORD index, D3DLIGHT8* pLight); + void SetLight(DWORD index, CONST D3DLIGHT9* pLight); + void GetLight(DWORD index, D3DLIGHT9* pLight); // Renderstates void SaveRenderState(D3DRENDERSTATETYPE Type, DWORD dwValue); void RestoreRenderState(D3DRENDERSTATETYPE Type); void SetRenderState(D3DRENDERSTATETYPE Type, DWORD Value); - void GetRenderState(D3DRENDERSTATETYPE Type, DWORD * pdwValue); + void GetRenderState(D3DRENDERSTATETYPE Type, DWORD* pdwValue); // Textures - void SaveTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture); + void SaveTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9 pTexture); void RestoreTexture(DWORD dwStage); - void SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture); - void GetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 * ppTexture); + void SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9 pTexture); + void GetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9* ppTexture); // Texture stage states void SaveTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue); void RestoreTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type); void SetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue); - void GetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD * pdwValue); + void GetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pdwValue); + void SaveSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD dwValue); + void RestoreSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type); + void SetSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD dwValue); + void GetSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD* pdwValue); void SetBestFiltering(DWORD dwStage); // if possible set anisotropy filtering, or use trilinear // Vertex Shader - void SaveVertexShader(DWORD dwShader); + void SaveVertexShader(LPDIRECT3DVERTEXSHADER9 dwShader); void RestoreVertexShader(); - void SetVertexShader(DWORD dwShader); - void GetVertexShader(DWORD * pdwShader); + void SetVertexShader(LPDIRECT3DVERTEXSHADER9 dwShader); + void GetVertexShader(LPDIRECT3DVERTEXSHADER9* pdwShader); + void SaveVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 dwShader); + void RestoreVertexDeclaration(); + void SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 dwShader); + void GetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9* pdwShader); // Pixel Shader - void SavePixelShader(DWORD dwShader); + void SavePixelShader(LPDIRECT3DPIXELSHADER9 lpShader); void RestorePixelShader(); - void SetPixelShader(DWORD dwShader); - void GetPixelShader(DWORD * pdwShader); + void SetPixelShader(LPDIRECT3DPIXELSHADER9 lpShader); + void GetPixelShader(LPDIRECT3DPIXELSHADER9* lppShader); + + void SaveFVF(DWORD dwFVF); + void RestoreFVF(); + void SetFVF(DWORD dwFVF); + void GetFVF(DWORD* dwFVF); // *** These states are cached, but not protected from multiple sends of the same value. // Transform @@ -286,36 +309,36 @@ class CStateManager : public CSingleton // Don't cache-check the transform. To much to do void SetTransform(D3DTRANSFORMSTATETYPE Type, const D3DMATRIX* pMatrix); - void GetTransform(D3DTRANSFORMSTATETYPE Type, D3DMATRIX * pMatrix); + void GetTransform(D3DTRANSFORMSTATETYPE Type, D3DMATRIX* pMatrix); // SetVertexShaderConstant void SaveVertexShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount); - void RestoreVertexShaderConstant(DWORD dwRegister, DWORD dwConstantCount); + void RestoreVertexShaderConstant(UINT uiRegister, UINT uiConstantCount); void SetVertexShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount); // SetPixelShaderConstant void SavePixelShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount); - void RestorePixelShaderConstant(DWORD dwRegister, DWORD dwConstantCount); + void RestorePixelShaderConstant(UINT uiRegister, UINT uiConstantCount); void SetPixelShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount); - void SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData, UINT Stride); + void SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER9 pStreamData, UINT Stride); void RestoreStreamSource(UINT StreamNumber); - void SetStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData, UINT Stride); + void SetStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER9 pStreamData, UINT Stride); - void SaveIndices(LPDIRECT3DINDEXBUFFER8 pIndexData, UINT BaseVertexIndex); + void SaveIndices(LPDIRECT3DINDEXBUFFER9 pIndexData, UINT BaseVertexIndex); void RestoreIndices(); - void SetIndices(LPDIRECT3DINDEXBUFFER8 pIndexData,UINT BaseVertexIndex); - + void SetIndices(LPDIRECT3DINDEXBUFFER9 pIndexData, UINT BaseVertexIndex); + HRESULT DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount); HRESULT DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride); - HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT minIndex, UINT NumVertices, UINT startIndex, UINT primCount); - HRESULT DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, CONST void * pIndexData, D3DFORMAT IndexDataFormat, CONST void * pVertexStreamZeroData, UINT VertexStreamZeroStride); + HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT minIndex, UINT NumVertices, UINT startIndex, UINT primCount, INT baseVertexIndex = 0); + HRESULT DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData, D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride); // Codes For Debug DWORD GetRenderState(D3DRENDERSTATETYPE Type); private: - void SetDevice(LPDIRECT3DDEVICE8 lpDevice); + void SetDevice(LPDIRECT3DDEVICE9 lpDevice); private: CStateManagerState m_ChipState; @@ -326,16 +349,15 @@ class CStateManager : public CSingleton bool m_bScene; DWORD m_dwBestMinFilter; DWORD m_dwBestMagFilter; - LPDIRECT3DDEVICE8 m_lpD3DDev; + LPDIRECT3DDEVICE9 m_lpD3DDev; #ifdef _DEBUG // Saving Flag BOOL m_bRenderStateSavingFlag[STATEMANAGER_MAX_RENDERSTATES]; BOOL m_bTextureStageStateSavingFlag[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_TEXTURESTATES]; + BOOL m_bSamplerStateSavingFlag[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_SAMPLERSTATES]; BOOL m_bTransformSavingFlag[STATEMANAGER_MAX_TRANSFORMSTATES]; #endif _DEBUG }; #define STATEMANAGER (CStateManager::Instance()) - -#endif __CSTATEMANAGER_H diff --git a/src/EterLib/StdAfx.h b/src/EterLib/StdAfx.h index 99dcc2a0..9eb0782c 100644 --- a/src/EterLib/StdAfx.h +++ b/src/EterLib/StdAfx.h @@ -20,8 +20,8 @@ #pragma warning(disable:4201 4512 4238 4239) #endif -#include -#include +#include +#include #define DIRECTINPUT_VERSION 0x0800 @@ -38,8 +38,7 @@ #include #pragma comment(lib, "winmm.lib") -#pragma comment(lib, "d3d8.lib") -#pragma comment(lib, "d3dx8.lib") +#pragma comment(lib, "d3d9.lib") #include "../eterBase/StdAfx.h" #include "../eterBase/Debug.h" diff --git a/src/EterLib/Util.h b/src/EterLib/Util.h index dc13a91a..422bb36e 100644 --- a/src/EterLib/Util.h +++ b/src/EterLib/Util.h @@ -6,7 +6,7 @@ #include #include -#include +#include template class CTransitor diff --git a/src/EterPythonLib/PythonGraphic.cpp b/src/EterPythonLib/PythonGraphic.cpp index 67c9be9f..e0fe26d5 100644 --- a/src/EterPythonLib/PythonGraphic.cpp +++ b/src/EterPythonLib/PythonGraphic.cpp @@ -9,7 +9,7 @@ void CPythonGraphic::Destroy() { } -LPDIRECT3D8 CPythonGraphic::GetD3D() +LPDIRECT3D9 CPythonGraphic::GetD3D() { return ms_lpd3d; } @@ -25,9 +25,9 @@ void CPythonGraphic::SetInterfaceRenderState() STATEMANAGER.SetTransform(D3DTS_VIEW, &ms_matIdentity); STATEMANAGER.SetTransform(D3DTS_WORLD, &ms_matIdentity); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_NONE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_NONE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_NONE); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); STATEMANAGER.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); STATEMANAGER.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); @@ -41,9 +41,9 @@ void CPythonGraphic::SetInterfaceRenderState() void CPythonGraphic::SetGameRenderState() { - STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); STATEMANAGER.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); STATEMANAGER.SetRenderState(D3DRS_LIGHTING, TRUE); @@ -57,13 +57,13 @@ void CPythonGraphic::SetCursorPosition(int x, int y) void CPythonGraphic::SetOmniLight() { // Set up a material - D3DMATERIAL8 Material; + D3DMATERIAL9 Material; Material.Ambient = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f); Material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); Material.Emissive = D3DXCOLOR(0.1f, 0.1f, 0.1f, 1.0f); STATEMANAGER.SetMaterial(&Material); - D3DLIGHT8 Light; + D3DLIGHT9 Light; Light.Type = D3DLIGHT_SPOT; Light.Position = D3DXVECTOR3(50.0f, 150.0f, 350.0f); Light.Direction = D3DXVECTOR3(-0.15f, -0.3f, -0.9f); @@ -98,7 +98,7 @@ void CPythonGraphic::SetViewport(float fx, float fy, float fWidth, float fHeight { ms_lpd3dDevice->GetViewport(&m_backupViewport); - D3DVIEWPORT8 ViewPort; + D3DVIEWPORT9 ViewPort; ViewPort.X = fx; ViewPort.Y = fy; ViewPort.Width = fWidth; @@ -123,7 +123,7 @@ void CPythonGraphic::RestoreViewport() void CPythonGraphic::SetGamma(float fGammaFactor) { - D3DCAPS8 d3dCaps; + D3DCAPS9 d3dCaps; D3DGAMMARAMP NewRamp; int ui, val; @@ -151,7 +151,7 @@ void CPythonGraphic::SetGamma(float fGammaFactor) NewRamp.blue[i] = (WORD) (val | (32768 * ui)); } - ms_lpd3dDevice->SetGammaRamp(D3DSGR_NO_CALIBRATION, &NewRamp); + ms_lpd3dDevice->SetGammaRamp(0, D3DSGR_NO_CALIBRATION, &NewRamp); } void GenScreenShotTag(const char* src, DWORD crc32, char* leaf, size_t leafLen) @@ -172,10 +172,10 @@ bool CPythonGraphic::SaveJPEG(const char * pszFileName, LPBYTE pbyBuffer, UINT u bool CPythonGraphic::SaveScreenShot(const char * c_pszFileName) { HRESULT hr; - LPDIRECT3DSURFACE8 lpSurface; + LPDIRECT3DSURFACE9 lpSurface; D3DSURFACE_DESC stSurfaceDesc; - if (FAILED(hr = ms_lpd3dDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &lpSurface))) + if (FAILED(hr = ms_lpd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &lpSurface))) { TraceError("Failed to get back buffer (0x%08x)", hr); return false; @@ -481,7 +481,7 @@ void CPythonGraphic::RenderAlphaImage(CGraphicImageInstance* pImageInstance, flo vertices[3].diffuse = DiffuseColor2; vertices[3].texCoord = TTextureCoordinate(eu, ev); - STATEMANAGER.SetVertexShader(ms_pntVS); + STATEMANAGER.SetFVF(ms_pntVS); // 2004.11.18.myevan.DrawIndexPrimitiveUP -> DynamicVertexBuffer CGraphicBase::SetDefaultIndexBuffer(DEFAULT_IB_FILL_RECT); if (CGraphicBase::SetPDTStream(vertices, 4)) @@ -563,7 +563,7 @@ void CPythonGraphic::RenderCoolTimeBox(float fxCenter, float fyCenter, float fRa STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTexture(1, NULL); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLEFAN, 0, iTriCount); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLORARG1); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLOROP); @@ -613,7 +613,7 @@ CPythonGraphic::CPythonGraphic() m_lightColor = GetColor(1.0f, 1.0f, 1.0f); m_darkColor = GetColor(0.0f, 0.0f, 0.0f); - memset(&m_backupViewport, 0, sizeof(D3DVIEWPORT8)); + memset(&m_backupViewport, 0, sizeof(D3DVIEWPORT9)); m_fOrthoDepth = 1000.0f; } diff --git a/src/EterPythonLib/PythonGraphic.h b/src/EterPythonLib/PythonGraphic.h index ae48ae7b..2d7ae227 100644 --- a/src/EterPythonLib/PythonGraphic.h +++ b/src/EterPythonLib/PythonGraphic.h @@ -18,7 +18,7 @@ class CPythonGraphic : public CScreen, public CSingleton void PushState(); void PopState(); - LPDIRECT3D8 GetD3D(); + LPDIRECT3D9 GetD3D(); float GetOrthoDepth(); void SetInterfaceRenderState(); @@ -62,7 +62,7 @@ class CPythonGraphic : public CScreen, public CSingleton CCullingManager m_CullingManager; - D3DVIEWPORT8 m_backupViewport; + D3DVIEWPORT9 m_backupViewport; float m_fOrthoDepth; }; \ No newline at end of file diff --git a/src/GameLib/ActorInstance.cpp b/src/GameLib/ActorInstance.cpp index e9f0f02a..0e3254c9 100644 --- a/src/GameLib/ActorInstance.cpp +++ b/src/GameLib/ActorInstance.cpp @@ -2,7 +2,7 @@ #include "ActorInstance.h" #include "AreaTerrain.h" #include "RaceData.h" -#include "../SpeedTreeLib/SpeedTreeForestDirectX8.h" +#include "../SpeedTreeLib/CSpeedTreeDirectX.h" #include "../SpeedTreeLib/SpeedTreeWrapper.h" enum @@ -801,8 +801,8 @@ void CActorInstance::__CreateTree(const char * c_szFileName) { __DestroyTree(); - CSpeedTreeForestDirectX8& rkForest=CSpeedTreeForestDirectX8::Instance(); - m_pkTree=rkForest.CreateInstance(m_x, m_y, m_z, GetCaseCRC32(c_szFileName, strlen(c_szFileName)), c_szFileName); + CSpeedTreeForest& rkForest = CSpeedTreeForest::Instance(); + m_pkTree = rkForest.CreateInstance(m_x, m_y, m_z, GetCaseCRC32(c_szFileName, strlen(c_szFileName)), c_szFileName); m_pkTree->SetPosition(m_x, m_y, m_z); m_pkTree->UpdateBoundingSphere(); m_pkTree->UpdateCollisionData(); @@ -813,7 +813,7 @@ void CActorInstance::__DestroyTree() if (!m_pkTree) return; - CSpeedTreeForestDirectX8::Instance().DeleteInstance(m_pkTree); + CSpeedTreeForest::Instance().DeleteInstance(m_pkTree); } void CActorInstance::__SetTreePosition(float fx, float fy, float fz) diff --git a/src/GameLib/ActorInstanceRender.cpp b/src/GameLib/ActorInstanceRender.cpp index ff588a3f..18bdb5cb 100644 --- a/src/GameLib/ActorInstanceRender.cpp +++ b/src/GameLib/ActorInstanceRender.cpp @@ -32,7 +32,7 @@ void CActorInstance::SetMaterialAlpha(DWORD dwAlpha) void CActorInstance::OnRender() { - D3DMATERIAL8 kMtrl; + D3DMATERIAL9 kMtrl; STATEMANAGER.GetMaterial(&kMtrl); kMtrl.Diffuse=D3DXCOLOR(m_dwMtrlColor); @@ -127,7 +127,7 @@ void CActorInstance::OnRender() STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLORARG1); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLOROP); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ALPHAOP); - STATEMANAGER.RestoreVertexShader(); + STATEMANAGER.RestoreFVF(); } } diff --git a/src/GameLib/Area.cpp b/src/GameLib/Area.cpp index 1b54d283..f1272a0b 100644 --- a/src/GameLib/Area.cpp +++ b/src/GameLib/Area.cpp @@ -3,7 +3,7 @@ #include "../eterLib/ResourceManager.h" #include "../eterLib/StateManager.h" #include "../effectLib/EffectManager.h" -#include "../SpeedTreeLib/SpeedTreeForestDirectX8.h" +#include "../SpeedTreeLib/CSpeedTreeDirectX.h" #include "../eterBase/Timer.h" #include "Area.h" @@ -585,7 +585,7 @@ void CArea::__SetObjectInstance_SetTree(TObjectInstance * pObjectInstance, const void CArea::TObjectInstance::SetTree(float x, float y, float z, DWORD dwTreeCRC, const char* c_szTreeName) { - CSpeedTreeForestDirectX8& rkForest=CSpeedTreeForestDirectX8::Instance(); + CSpeedTreeForest& rkForest = CSpeedTreeForest::Instance(); pTree=rkForest.CreateInstance(x, y, z, dwTreeCRC, c_szTreeName); dwType = prt::PROPERTY_TYPE_TREE; } @@ -1245,7 +1245,7 @@ void CArea::__Clear_DestroyObjectInstance(TObjectInstance * pObjectInstance) if (pObjectInstance->pTree) { pObjectInstance->pTree->Clear(); - CSpeedTreeForestDirectX8::Instance().DeleteInstance(pObjectInstance->pTree); + CSpeedTreeForest::Instance().DeleteInstance(pObjectInstance->pTree); pObjectInstance->pTree = NULL; } diff --git a/src/GameLib/AreaTerrain.cpp b/src/GameLib/AreaTerrain.cpp index bba84f5a..eb86a165 100644 --- a/src/GameLib/AreaTerrain.cpp +++ b/src/GameLib/AreaTerrain.cpp @@ -757,7 +757,7 @@ void CTerrain::RAW_GenerateSplat(bool bBGLoading) } } -LPDIRECT3DTEXTURE8 CTerrain::AddTexture32(BYTE byImageNum, BYTE * pbyImage, long lTextureWidth, long lTextureHeight) +LPDIRECT3DTEXTURE9 CTerrain::AddTexture32(BYTE byImageNum, BYTE* pbyImage, long lTextureWidth, long lTextureHeight) { assert(NULL==m_lpAlphaTexture[byImageNum]); @@ -777,13 +777,11 @@ LPDIRECT3DTEXTURE8 CTerrain::AddTexture32(BYTE byImageNum, BYTE * pbyImage, long bool bResizedAndSuccess = false; - IDirect3DTexture8* pkTex=NULL; + IDirect3DTexture9* pkTex = NULL; UINT uiNewWidth = 256; UINT uiNewHeight = 256; - hr = ms_lpd3dDevice->CreateTexture( - uiNewWidth, uiNewHeight, 5, 0, - format, D3DPOOL_MANAGED, &pkTex); + hr = ms_lpd3dDevice->CreateTexture(uiNewWidth, uiNewHeight, 5, 0, format, D3DPOOL_MANAGED, &pkTex, NULL); if (FAILED(hr)) { TraceError("CTerrain::AddTexture32 - CreateTexture Error"); @@ -1153,7 +1151,7 @@ void CTerrain::AllocateMarkedSplats(BYTE * pbyAlphaMap) do { - hr = ms_lpd3dDevice->CreateTexture(ATTRMAP_XSIZE, ATTRMAP_YSIZE, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_lpMarkedTexture); + hr = ms_lpd3dDevice->CreateTexture(ATTRMAP_XSIZE, ATTRMAP_YSIZE, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_lpMarkedTexture, NULL); } while(FAILED(hr)); D3DLOCKED_RECT d3dlr; diff --git a/src/GameLib/AreaTerrain.h b/src/GameLib/AreaTerrain.h index 1d3d9b3d..d246fa6b 100644 --- a/src/GameLib/AreaTerrain.h +++ b/src/GameLib/AreaTerrain.h @@ -78,7 +78,7 @@ class CTerrain : public CTerrainImpl, public CGraphicBase // MiniMap void LoadMiniMapTexture(const char * c_pszFileName); - inline LPDIRECT3DTEXTURE8 GetMiniMapTexture() { return m_lpMiniMapTexture; } + inline LPDIRECT3DTEXTURE9 GetMiniMapTexture() { return m_lpMiniMapTexture; } // Marked Area BOOL IsMarked() { return m_bMarked; } @@ -107,7 +107,7 @@ class CTerrain : public CTerrainImpl, public CGraphicBase void RAW_DeallocateSplats(bool bBGLoading = false); virtual void RAW_CountTiles(); - LPDIRECT3DTEXTURE8 AddTexture32(BYTE byImageNum, BYTE * pbyImage, long lTextureWidth, long lTextureHeight); + LPDIRECT3DTEXTURE9 AddTexture32(BYTE byImageNum, BYTE * pbyImage, long lTextureWidth, long lTextureHeight); void PutImage32(BYTE * pbySrc, BYTE * pbyDst, long src_pitch, long dst_pitch, long lTextureWidth, long lTextureHeight, bool bResize = false); void PutImage16(BYTE * pbySrc, BYTE * pbyDst, long src_pitch, long dst_pitch, long lTextureWidth, long lTextureHeight, bool bResize = false); @@ -126,7 +126,7 @@ class CTerrain : public CTerrainImpl, public CGraphicBase //MiniMap CGraphicImageInstance m_MiniMapGraphicImageInstance; - LPDIRECT3DTEXTURE8 m_lpMiniMapTexture; + LPDIRECT3DTEXTURE9 m_lpMiniMapTexture; // Owner COutdoorMap poineter @@ -142,7 +142,7 @@ class CTerrain : public CTerrainImpl, public CGraphicBase BOOL m_bMarked; TTerrainSplatPatch m_MarkedSplatPatch; - LPDIRECT3DTEXTURE8 m_lpMarkedTexture; + LPDIRECT3DTEXTURE9 m_lpMarkedTexture; public: CTerrainPatch * GetTerrainPatchPtr(BYTE byPatchNumX, BYTE byPatchNumY); diff --git a/src/GameLib/DungeonBlock.cpp b/src/GameLib/DungeonBlock.cpp index ba11b454..c08211cb 100644 --- a/src/GameLib/DungeonBlock.cpp +++ b/src/GameLib/DungeonBlock.cpp @@ -14,8 +14,8 @@ class CDungeonModelInstance : public CGrannyModelInstance if (IsEmpty()) return; - STATEMANAGER.SetVertexShader(ms_pnt2VS); - LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); + STATEMANAGER.SetFVF(ms_pnt2VS); + LPDIRECT3DVERTEXBUFFER9 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); if (lpd3dRigidPNTVtxBuf) { STATEMANAGER.SetStreamSource(0, lpd3dRigidPNTVtxBuf, sizeof(TPNT2Vertex)); @@ -36,8 +36,8 @@ class CDungeonModelInstance : public CGrannyModelInstance STATEMANAGER.SaveRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO); STATEMANAGER.SaveRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR); - STATEMANAGER.SetVertexShader(ms_pnt2VS); - LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); + STATEMANAGER.SetFVF(ms_pnt2VS); + LPDIRECT3DVERTEXBUFFER9 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer(); if (lpd3dRigidPNTVtxBuf) { STATEMANAGER.SetStreamSource(0, lpd3dRigidPNTVtxBuf, sizeof(TPNT2Vertex)); diff --git a/src/GameLib/FlyTrace.cpp b/src/GameLib/FlyTrace.cpp index 80620450..1e15861a 100644 --- a/src/GameLib/FlyTrace.cpp +++ b/src/GameLib/FlyTrace.cpp @@ -130,7 +130,7 @@ void CFlyTrace::Render() D3DXMatrixIdentity(&matWorld); STATEMANAGER.SaveTransform(D3DTS_WORLD, &matWorld); - STATEMANAGER.SaveVertexShader(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); + STATEMANAGER.SaveFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_NONE); STATEMANAGER.SaveRenderState(D3DRS_ALPHABLENDENABLE, TRUE); @@ -278,7 +278,7 @@ void CFlyTrace::Render() STATEMANAGER.RestoreRenderState(D3DRS_SRCBLEND); STATEMANAGER.RestoreRenderState(D3DRS_ALPHABLENDENABLE); STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE); - STATEMANAGER.RestoreVertexShader(); + STATEMANAGER.RestoreFVF(); STATEMANAGER.RestoreTransform(D3DTS_WORLD); //STATEMANAGER.RestoreRenderState(D3DRS_ZWRITEENABLE); STATEMANAGER.RestoreRenderState(D3DRS_ZFUNC); diff --git a/src/GameLib/FlyTrace.h b/src/GameLib/FlyTrace.h index 6adbc513..727c4cf7 100644 --- a/src/GameLib/FlyTrace.h +++ b/src/GameLib/FlyTrace.h @@ -23,7 +23,7 @@ class CFlyTrace : public CScreen typedef std::deque TTimePositionDeque; //CGraphicImageInstance m_ImageInstance; - //LPDIRECT3DTEXTURE8 m_lpTexture; + //LPDIRECT3DTEXTURE9 m_lpTexture; bool m_bRectShape; DWORD m_dwColor; diff --git a/src/GameLib/MapBase.h b/src/GameLib/MapBase.h index 2784efd4..e32c55f9 100644 --- a/src/GameLib/MapBase.h +++ b/src/GameLib/MapBase.h @@ -24,7 +24,7 @@ class CMapBase : public CScreen virtual float GetHeight(float fx, float fy) = 0; virtual void OnBeginEnvironment() = 0; // ·»´õ¸µ ÇÒ ¶§ ºÒ·ÁÁö¸ç ¿©±â¼­ Environment¿¡ °ü·Ã ÀÖ´Â °ÍµéÀ» ¼ÂÆà ÇÑ´Ù. - virtual void ApplyLight(DWORD dwVersion, const D3DLIGHT8& c_rkLight) = 0; + virtual void ApplyLight(DWORD dwVersion, const D3DLIGHT9& c_rkLight) = 0; protected: virtual void OnRender() = 0; diff --git a/src/GameLib/MapManager.cpp b/src/GameLib/MapManager.cpp index 6cb01106..356a45ea 100644 --- a/src/GameLib/MapManager.cpp +++ b/src/GameLib/MapManager.cpp @@ -259,7 +259,7 @@ void CMapManager::BeginEnvironment() } else { - CSpeedTreeForestDirectX8& rkForest=CSpeedTreeForestDirectX8::Instance(); + CSpeedTreeForest& rkForest = CSpeedTreeForest::Instance(); rkForest.SetFog( mc_pcurEnvironmentData->GetFogNearDistance(), mc_pcurEnvironmentData->GetFogFarDistance() diff --git a/src/GameLib/MapManager.h b/src/GameLib/MapManager.h index c35ecf79..829693f7 100644 --- a/src/GameLib/MapManager.h +++ b/src/GameLib/MapManager.h @@ -106,8 +106,8 @@ class CMapManager : public CScreen, public IPhysicsWorld ////////////////////////////////////////////////////////////////////////// // Map ////////////////////////////////////////////////////////////////////////// - CMapOutdoor * m_pkMap; - CSpeedTreeForestDirectX8 m_Forest; + CMapOutdoor * m_pkMap; + CSpeedTreeDirectX m_Forest; public: // 2004.10.14.myevan.TEMP_CAreaLoaderThread diff --git a/src/GameLib/MapOutdoor.cpp b/src/GameLib/MapOutdoor.cpp index a6e9503a..f8ff254b 100644 --- a/src/GameLib/MapOutdoor.cpp +++ b/src/GameLib/MapOutdoor.cpp @@ -190,7 +190,7 @@ bool CMapOutdoor::Initialize() m_bEnableTerrainOnlyForHeight = FALSE; m_bEnablePortal = FALSE; - m_wShadowMapSize = 512; + m_wShadowMapSize = 2048; return true; } @@ -218,7 +218,7 @@ bool CMapOutdoor::Destroy() m_kPool_kMonsterAreaInfo.Destroy(); m_AlphaFogImageInstance.Destroy(); - CSpeedTreeForestDirectX8::Instance().Clear(); + CSpeedTreeForest::Instance().Clear(); return true; } @@ -248,13 +248,13 @@ void CMapOutdoor::OnBeginEnvironment() if (!mc_pEnvironmentData) return; - CSpeedTreeForestDirectX8& rkForest=CSpeedTreeForestDirectX8::Instance(); + CSpeedTreeForest& rkForest = CSpeedTreeForest::Instance(); rkForest.SetFog( mc_pEnvironmentData->GetFogNearDistance(), mc_pEnvironmentData->GetFogFarDistance() ); - const D3DLIGHT8& c_rkLight = mc_pEnvironmentData->DirLights[ENV_DIRLIGHT_CHARACTER]; + const D3DLIGHT9& c_rkLight = mc_pEnvironmentData->DirLights[ENV_DIRLIGHT_CHARACTER]; rkForest.SetLight( (const float *)&c_rkLight.Direction, (const float *)&c_rkLight.Ambient, @@ -1068,8 +1068,8 @@ void CMapOutdoor::SaveAlphaFogOperation() STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2); STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); STATEMANAGER.SetTransform(D3DTS_TEXTURE1, &m_matAlphaFogTexture); STATEMANAGER.SaveRenderState(D3DRS_ALPHABLENDENABLE, TRUE); @@ -1350,7 +1350,7 @@ void CMapOutdoor::XMasTree_Destroy() { if (m_kXMas.m_pkTree) { - CSpeedTreeForestDirectX8& rkForest=CSpeedTreeForestDirectX8::Instance(); + CSpeedTreeForest& rkForest = CSpeedTreeForest::Instance(); m_kXMas.m_pkTree->Clear(); rkForest.DeleteInstance(m_kXMas.m_pkTree); m_kXMas.m_pkTree=NULL; @@ -1368,7 +1368,7 @@ void CMapOutdoor::__XMasTree_Create(float x, float y, float z, const char* c_szT assert(NULL==m_kXMas.m_pkTree); assert(-1==m_kXMas.m_iEffectID); - CSpeedTreeForestDirectX8& rkForest=CSpeedTreeForestDirectX8::Instance(); + CSpeedTreeForest& rkForest = CSpeedTreeForest::Instance(); DWORD dwCRC32 = GetCaseCRC32(c_szTreeName, strlen(c_szTreeName)); m_kXMas.m_pkTree=rkForest.CreateInstance(x, y, z, dwCRC32, c_szTreeName); diff --git a/src/GameLib/MapOutdoor.h b/src/GameLib/MapOutdoor.h index 2fa45084..ae015f4d 100644 --- a/src/GameLib/MapOutdoor.h +++ b/src/GameLib/MapOutdoor.h @@ -7,7 +7,7 @@ #include "../PRTerrainLib/TerrainType.h" #include "../PRTerrainLib/TextureSet.h" -#include "../SpeedTreeLib/SpeedTreeForestDirectX8.h" +#include "../SpeedTreeLib/CSpeedTreeDirectX.h" #include "MapBase.h" #include "Area.h" @@ -100,7 +100,7 @@ class CMapOutdoor : public CMapBase bool LoadSetting(const char * c_szFileName); - void ApplyLight(DWORD dwVersion, const D3DLIGHT8& c_rkLight); + void ApplyLight(DWORD dwVersion, const D3DLIGHT9& c_rkLight); void SetEnvironmentScreenFilter(); void SetEnvironmentSkyBox(); void SetEnvironmentLensFlare(); @@ -431,16 +431,16 @@ class CMapOutdoor : public CMapBase ////////////////////////////////////////////////////////////////////////// // Character Shadow - LPDIRECT3DTEXTURE8 m_lpCharacterShadowMapTexture; - LPDIRECT3DSURFACE8 m_lpCharacterShadowMapRenderTargetSurface; - LPDIRECT3DSURFACE8 m_lpCharacterShadowMapDepthSurface; - D3DVIEWPORT8 m_ShadowMapViewport; + LPDIRECT3DTEXTURE9 m_lpCharacterShadowMapTexture; + LPDIRECT3DSURFACE9 m_lpCharacterShadowMapRenderTargetSurface; + LPDIRECT3DSURFACE9 m_lpCharacterShadowMapDepthSurface; + D3DVIEWPORT9 m_ShadowMapViewport; WORD m_wShadowMapSize; // Backup Device Context - LPDIRECT3DSURFACE8 m_lpBackupRenderTargetSurface; - LPDIRECT3DSURFACE8 m_lpBackupDepthSurface; - D3DVIEWPORT8 m_BackupViewport; + LPDIRECT3DSURFACE9 m_lpBackupRenderTargetSurface; + LPDIRECT3DSURFACE9 m_lpBackupDepthSurface; + D3DVIEWPORT9 m_BackupViewport; // Character Shadow ////////////////////////////////////////////////////////////////////////// @@ -593,8 +593,8 @@ class CMapOutdoor : public CMapBase NONE_VB_NUM = 8, }; - IDirect3DVertexBuffer8* m_pkVBSplat[SPLAT_VB_NUM]; - IDirect3DVertexBuffer8* m_pkVBNone[NONE_VB_NUM]; + IDirect3DVertexBuffer9* m_pkVBSplat[SPLAT_VB_NUM]; + IDirect3DVertexBuffer9* m_pkVBNone[NONE_VB_NUM]; DWORD m_dwSplatPos; DWORD m_dwNonePos; DWORD m_dwLightVersion; @@ -604,8 +604,8 @@ class CMapOutdoor : public CMapBase D3DXMATRIX m_m4Proj; D3DXMATRIX m_m4Frustum; D3DXMATRIX m_m4DynamicShadow; - D3DLIGHT8 m_kLight; - D3DMATERIAL8 m_kMtrl; + D3DLIGHT9 m_kLight; + D3DMATERIAL9 m_kMtrl; D3DXVECTOR3 m_v3Player; DWORD m_dwFogColor; float m_fScreenHalfWidth; diff --git a/src/GameLib/MapOutdoorCharacterShadow.cpp b/src/GameLib/MapOutdoorCharacterShadow.cpp index 20cd4cd8..86fa15c5 100644 --- a/src/GameLib/MapOutdoorCharacterShadow.cpp +++ b/src/GameLib/MapOutdoorCharacterShadow.cpp @@ -36,7 +36,7 @@ void CMapOutdoor::CreateCharacterShadowTexture() m_ShadowMapViewport.MinZ = 0.0f; m_ShadowMapViewport.MaxZ = 1.0f; - if (FAILED(ms_lpd3dDevice->CreateTexture(m_wShadowMapSize, m_wShadowMapSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &m_lpCharacterShadowMapTexture))) + if (FAILED(ms_lpd3dDevice->CreateTexture(m_wShadowMapSize, m_wShadowMapSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &m_lpCharacterShadowMapTexture, NULL))) { TraceError("CMapOutdoor Unable to create Character Shadow render target texture\n"); return; @@ -48,7 +48,13 @@ void CMapOutdoor::CreateCharacterShadowTexture() return; } - if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_wShadowMapSize, m_wShadowMapSize, D3DFMT_D16, D3DMULTISAMPLE_NONE, &m_lpCharacterShadowMapDepthSurface))) + IDirect3DSurface9* pBackBufferSurface; + ms_lpd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBufferSurface); + D3DSURFACE_DESC kDesc; + pBackBufferSurface->GetDesc(&kDesc); + pBackBufferSurface->Release(); + + if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_wShadowMapSize, m_wShadowMapSize, D3DFMT_D16, kDesc.MultiSampleType, kDesc.MultiSampleQuality, FALSE, &m_lpCharacterShadowMapDepthSurface, NULL))) { TraceError("CMapOutdoor Unable to create Character Shadow depth Surface\n"); return; @@ -107,7 +113,7 @@ bool CMapOutdoor::BeginRenderCharacterShadowToTexture() bool bSuccess = true; // Backup Device Context - if (FAILED(ms_lpd3dDevice->GetRenderTarget(&m_lpBackupRenderTargetSurface))) + if (FAILED(ms_lpd3dDevice->GetRenderTarget(0, &m_lpBackupRenderTargetSurface))) { TraceError("CMapOutdoor::BeginRenderCharacterShadowToTexture : Unable to Save Window Render Target\n"); bSuccess = false; @@ -119,11 +125,17 @@ bool CMapOutdoor::BeginRenderCharacterShadowToTexture() bSuccess = false; } - if (FAILED(ms_lpd3dDevice->SetRenderTarget(m_lpCharacterShadowMapRenderTargetSurface, m_lpCharacterShadowMapDepthSurface))) + if (FAILED(ms_lpd3dDevice->SetRenderTarget(0, m_lpCharacterShadowMapRenderTargetSurface))) { TraceError("CMapOutdoor::BeginRenderCharacterShadowToTexture : Unable to Set Shadow Map Render Target\n"); bSuccess = false; } + + if (FAILED(ms_lpd3dDevice->SetDepthStencilSurface(m_lpCharacterShadowMapDepthSurface))) + { + TraceError("CMapOutdoor::BeginRenderCharacterShadowToTexture : Unable to Set Shadow Map Depth Surface\n"); + bSuccess = false; + } if (FAILED(ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0xFF, 0xFF, 0xFF), 1.0f, 0))) { @@ -150,7 +162,8 @@ void CMapOutdoor::EndRenderCharacterShadowToTexture() { ms_lpd3dDevice->SetViewport(&m_BackupViewport); - ms_lpd3dDevice->SetRenderTarget(m_lpBackupRenderTargetSurface, m_lpBackupDepthSurface); + ms_lpd3dDevice->SetRenderTarget(0, m_lpBackupRenderTargetSurface); + ms_lpd3dDevice->SetDepthStencilSurface(m_lpBackupDepthSurface); SAFE_RELEASE(m_lpBackupRenderTargetSurface); SAFE_RELEASE(m_lpBackupDepthSurface); diff --git a/src/GameLib/MapOutdoorLoad.cpp b/src/GameLib/MapOutdoorLoad.cpp index 353749ef..99d55cd1 100644 --- a/src/GameLib/MapOutdoorLoad.cpp +++ b/src/GameLib/MapOutdoorLoad.cpp @@ -37,7 +37,7 @@ bool CMapOutdoor::Load(float x, float y, float z) m_lOldReadX = -1; // TODO: SetRenderingDevice¿¡¼­ Environment·Î ºÎÅÍ ¶óÀÌÆ® ¼Ó¼ºÀ» ³Ñ°ÜÁà¾ß ½ºÅÂƽ ¶óÀÌÆ®°¡ Á¦´ë·Î ÀÛµ¿ÇÑ´Ù. - CSpeedTreeForestDirectX8::Instance().SetRenderingDevice(ms_lpd3dDevice); + CSpeedTreeDirectX::Instance().SetRenderingDevice(); Update(x, y, z); diff --git a/src/GameLib/MapOutdoorRender.cpp b/src/GameLib/MapOutdoorRender.cpp index 8b410ba9..d60fd1bb 100644 --- a/src/GameLib/MapOutdoorRender.cpp +++ b/src/GameLib/MapOutdoorRender.cpp @@ -127,7 +127,7 @@ void CMapOutdoor::__RenderTerrain_AppendPatch(const D3DXVECTOR3& c_rv3Center, fl m_PatchVector.push_back(std::make_pair(fDistance, lPatchNum)); } -void CMapOutdoor::ApplyLight(DWORD dwVersion, const D3DLIGHT8& c_rkLight) +void CMapOutdoor::ApplyLight(DWORD dwVersion, const D3DLIGHT9& c_rkLight) { m_kSTPD.m_dwLightVersion=dwVersion; STATEMANAGER.SetLight(0, &c_rkLight); @@ -236,7 +236,7 @@ void CMapOutdoor::RenderCloud() void CMapOutdoor::RenderTree() { if (IsVisiblePart(PART_TREE)) - CSpeedTreeForestDirectX8::Instance().Render(); + CSpeedTreeForest::Instance().Render(); } void CMapOutdoor::SetInverseViewAndDynamicShaodwMatrices() @@ -422,17 +422,17 @@ void CMapOutdoor::RenderArea(bool bRenderAmbience) STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_BORDER); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_BORDER); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_BORDERCOLOR, 0xFFFFFFFF); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_BORDERCOLOR, 0xFFFFFFFF); std::for_each(m_ShadowReceiverVector.begin(), m_ShadowReceiverVector.end(), FAreaRenderShadow()); STATEMANAGER.RestoreTextureStageState(1, D3DTSS_TEXCOORDINDEX); STATEMANAGER.RestoreTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSV); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_BORDERCOLOR); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSV); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_BORDERCOLOR); STATEMANAGER.RestoreTransform(D3DTS_TEXTURE1); @@ -630,8 +630,8 @@ void CMapOutdoor::RenderPCBlocker() STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); STATEMANAGER.SaveTransform(D3DTS_TEXTURE1, &m_matBuildingTransparent); STATEMANAGER.SetTexture(1, m_BuildingTransparentImageInstance.GetTexturePointer()->GetD3DTexture()); @@ -647,8 +647,8 @@ void CMapOutdoor::RenderPCBlocker() STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSV); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSV); STATEMANAGER.RestoreRenderState(D3DRS_ALPHABLENDENABLE); } #endif @@ -858,11 +858,11 @@ void CMapOutdoor::RenderMarkedArea() STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE); STATEMANAGER.SaveTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION); STATEMANAGER.SaveTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_MIPFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); STATEMANAGER.SetTexture(0, m_attrImageInstance.GetTexturePointer()->GetD3DTexture()); @@ -872,11 +872,11 @@ void CMapOutdoor::RenderMarkedArea() STATEMANAGER.RestoreTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS); STATEMANAGER.RestoreTextureStageState(1, D3DTSS_TEXCOORDINDEX); STATEMANAGER.RestoreTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MINFILTER); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MAGFILTER); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MIPFILTER); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSV); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_MINFILTER); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_MAGFILTER); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_MIPFILTER); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSV); STATEMANAGER.RestoreTransform(D3DTS_TEXTURE0); STATEMANAGER.RestoreTransform(D3DTS_TEXTURE1); @@ -949,7 +949,7 @@ void CMapOutdoor::DrawPatchAttr(long patchnum) TTerrainSplatPatch & rAttrSplatPatch = pTerrain->GetMarkedSplatPatch(); STATEMANAGER.SetTexture(1, rAttrSplatPatch.Splats[0].pd3dTexture); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ | D3DFVF_NORMAL); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL); STATEMANAGER.SetStreamSource(0, pTerrainPatchProxy->HardwareTransformPatch_GetVertexBufferPtr()->GetD3DVertexBuffer(), m_iPatchTerrainVertexSize); #ifdef WORLD_EDITOR diff --git a/src/GameLib/MapOutdoorRenderHTP.cpp b/src/GameLib/MapOutdoorRenderHTP.cpp index ffdbd37a..7ce43543 100644 --- a/src/GameLib/MapOutdoorRenderHTP.cpp +++ b/src/GameLib/MapOutdoorRenderHTP.cpp @@ -41,39 +41,38 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch() STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); #ifdef WORLD_EDITOR if (GetAsyncKeyState(VK_CAPITAL)) { CSpeedTreeWrapper::ms_bSelfShadowOn = false; - STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_GAUSSIANCUBIC); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_GAUSSIANCUBIC); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_GAUSSIANCUBIC); - STATEMANAGER.SetTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_GAUSSIANCUBIC); - STATEMANAGER.SetTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_GAUSSIANCUBIC); - STATEMANAGER.SetTextureStageState(1, D3DTSS_MIPFILTER, D3DTEXF_GAUSSIANCUBIC); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_GAUSSIANQUAD); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_GAUSSIANQUAD); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_GAUSSIANQUAD); + STATEMANAGER.SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_GAUSSIANQUAD); + STATEMANAGER.SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_GAUSSIANQUAD); + STATEMANAGER.SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_GAUSSIANQUAD); } else { CSpeedTreeWrapper::ms_bSelfShadowOn = true; - STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); } #else - CSpeedTreeWrapper::ms_bSelfShadowOn = true; STATEMANAGER.SetBestFiltering(0); STATEMANAGER.SetBestFiltering(1); #endif @@ -88,7 +87,7 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch() // Render State & TextureStageState ////////////////////////////////////////////////////////////////////////// - STATEMANAGER.SetVertexShader(D3DFVF_XYZ | D3DFVF_NORMAL); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL); m_iRenderedSplatNumSqSum = 0; m_iRenderedPatchNum = 0; @@ -624,8 +623,8 @@ void CMapOutdoor::__HardwareTransformPatch_RenderPatchSplat(long patchnum, WORD STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CURRENT); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); if (m_bDrawChrShadow) { @@ -636,8 +635,8 @@ void CMapOutdoor::__HardwareTransformPatch_RenderPatchSplat(long patchnum, WORD STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); } else { @@ -661,8 +660,8 @@ void CMapOutdoor::__HardwareTransformPatch_RenderPatchSplat(long patchnum, WORD STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); STATEMANAGER.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); diff --git a/src/GameLib/MapOutdoorRenderSTP.cpp b/src/GameLib/MapOutdoorRenderSTP.cpp index 3c2b4a21..9c82255d 100644 --- a/src/GameLib/MapOutdoorRenderSTP.cpp +++ b/src/GameLib/MapOutdoorRenderSTP.cpp @@ -43,7 +43,7 @@ void CMapOutdoor::__RenderTerrain_RenderSoftwareTransformPatch() SelectIndexBuffer(0, &wPrimitiveCount, &ePrimitiveType); - STATEMANAGER.SetVertexShader(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_SPECULAR|D3DFVF_TEX2); + STATEMANAGER.SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2); std::vector >::iterator it = m_PatchVector.begin(); @@ -100,7 +100,7 @@ void CMapOutdoor::__RenderTerrain_RenderSoftwareTransformPatch() STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - STATEMANAGER.SetVertexShader(D3DFVF_XYZRHW); + STATEMANAGER.SetFVF(D3DFVF_XYZRHW); if (IsFastTNL()) { @@ -315,16 +315,15 @@ void CMapOutdoor::__SoftwareTransformPatch_RenderPatchNone(SoftwareTransformPatc } - IDirect3DVertexBuffer8* pkVB=m_kSTPD.m_pkVBNone[m_kSTPD.m_dwNonePos++]; + IDirect3DVertexBuffer9* pkVB = m_kSTPD.m_pkVBNone[m_kSTPD.m_dwNonePos++]; m_kSTPD.m_dwNonePos%=SoftwareTransformPatch_SData::NONE_VB_NUM; if (!pkVB) return; DWORD dwVBSize=sizeof(SoftwareTransformPatch_STVertex)*CTerrainPatch::TERRAIN_VERTEX_COUNT; SoftwareTransformPatch_STVertex* akDstVertex; - if (FAILED( - pkVB->Lock(0, dwVBSize, (BYTE**)&akDstVertex, D3DLOCK_DISCARD) - )) return; + if (FAILED(pkVB->Lock(0, dwVBSize, (VOID**)&akDstVertex, D3DLOCK_DISCARD))) + return; memcpy(akDstVertex, akTransVertex, dwVBSize); @@ -345,8 +344,8 @@ void CMapOutdoor::__SoftwareTransformPatch_ApplyStaticShadowRenderState() STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); } @@ -359,8 +358,8 @@ void CMapOutdoor::__SoftwareTransformPatch_ApplyDynamicShadowRenderState() STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); } void CMapOutdoor::__SoftwareTransformPatch_ApplyFogShadowRenderState() @@ -377,9 +376,9 @@ void CMapOutdoor::__SoftwareTransformPatch_RestoreStaticShadowRenderState() STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); + STATEMANAGER.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); STATEMANAGER.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); } @@ -394,8 +393,8 @@ void CMapOutdoor::__SoftwareTransformPatch_RestoreDynamicShadowRenderState() STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); } @@ -421,8 +420,6 @@ void CMapOutdoor::__SoftwareTransformPatch_ApplyRenderState() if (!IsTLVertexClipping()) isSoftwareVertexClipping=TRUE; - STATEMANAGER.SaveRenderState(D3DRS_SOFTWAREVERTEXPROCESSING, isSoftwareVertexClipping); - STATEMANAGER.SaveRenderState(D3DRS_ALPHABLENDENABLE, TRUE); STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, TRUE); STATEMANAGER.SaveRenderState(D3DRS_ALPHAREF, 0x00000000); @@ -437,8 +434,8 @@ void CMapOutdoor::__SoftwareTransformPatch_ApplyRenderState() STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + STATEMANAGER.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); STATEMANAGER.SetBestFiltering(0); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT); @@ -447,8 +444,8 @@ void CMapOutdoor::__SoftwareTransformPatch_ApplyRenderState() STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); STATEMANAGER.SetBestFiltering(1); CSpeedTreeWrapper::ms_bSelfShadowOn = true; @@ -491,8 +488,6 @@ void CMapOutdoor::__SoftwareTransformPatch_RestoreRenderState(DWORD dwFogEnable) STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE); STATEMANAGER.RestoreRenderState(D3DRS_ALPHAREF); STATEMANAGER.RestoreRenderState(D3DRS_ALPHAFUNC); - - STATEMANAGER.RestoreRenderState(D3DRS_SOFTWAREVERTEXPROCESSING); // Render State & TextureStageState ////////////////////////////////////////////////////////////////////////// @@ -677,16 +672,15 @@ bool CMapOutdoor::__SoftwareTransformPatch_SetTransform(SoftwareTransformPatch_S bool CMapOutdoor::__SoftwareTransformPatch_SetSplatStream(SoftwareTransformPatch_STLVertex* akSrcVertex) { - IDirect3DVertexBuffer8* pkVB=m_kSTPD.m_pkVBSplat[m_kSTPD.m_dwSplatPos++]; + IDirect3DVertexBuffer9* pkVB = m_kSTPD.m_pkVBSplat[m_kSTPD.m_dwSplatPos++]; m_kSTPD.m_dwSplatPos%=SoftwareTransformPatch_SData::SPLAT_VB_NUM; if (!pkVB) return false; DWORD dwVBSize=sizeof(SoftwareTransformPatch_SSplatVertex)*CTerrainPatch::TERRAIN_VERTEX_COUNT; SoftwareTransformPatch_SSplatVertex* akDstVertex; - if (FAILED( - pkVB->Lock(0, dwVBSize, (BYTE**)&akDstVertex, 0)//D3DLOCK_DISCARD) - )) return false; + if (FAILED(pkVB->Lock(0, dwVBSize, (VOID**)&akDstVertex, 0))) + return false; for (UINT uIndex=0; uIndex!=CTerrainPatch::TERRAIN_VERTEX_COUNT; ++uIndex) *(akDstVertex+uIndex)=*((SoftwareTransformPatch_SSplatVertex*)(akSrcVertex+uIndex)); @@ -699,16 +693,15 @@ bool CMapOutdoor::__SoftwareTransformPatch_SetSplatStream(SoftwareTransformPatch bool CMapOutdoor::__SoftwareTransformPatch_SetShadowStream(SoftwareTransformPatch_STLVertex* akSrcVertex) { - IDirect3DVertexBuffer8* pkVB=m_kSTPD.m_pkVBSplat[m_kSTPD.m_dwSplatPos++]; + IDirect3DVertexBuffer9* pkVB = m_kSTPD.m_pkVBSplat[m_kSTPD.m_dwSplatPos++]; m_kSTPD.m_dwSplatPos%=SoftwareTransformPatch_SData::SPLAT_VB_NUM; if (!pkVB) return false; DWORD dwVBSize=sizeof(SoftwareTransformPatch_SSplatVertex)*CTerrainPatch::TERRAIN_VERTEX_COUNT; SoftwareTransformPatch_SSplatVertex* akDstVertex; - if (FAILED( - pkVB->Lock(0, dwVBSize, (BYTE**)&akDstVertex, 0)//D3DLOCK_DISCARD) - )) return false; + if (FAILED(pkVB->Lock(0, dwVBSize, (VOID**)&akDstVertex, 0))) + return false; SoftwareTransformPatch_STLVertex* pkSrcVertex; SoftwareTransformPatch_SSplatVertex* pkDstVertex; @@ -725,7 +718,7 @@ bool CMapOutdoor::__SoftwareTransformPatch_SetShadowStream(SoftwareTransformPatc pkVB->Unlock(); - ms_lpd3dDevice->SetStreamSource(0, pkVB, sizeof(SoftwareTransformPatch_SSplatVertex)); + ms_lpd3dDevice->SetStreamSource(0, pkVB, 0, sizeof(SoftwareTransformPatch_SSplatVertex)); return true; } @@ -753,13 +746,15 @@ bool CMapOutdoor::__SoftwareTransformPatch_Create() assert(NULL==m_kSTPD.m_pkVBSplat[uIndex]); if (FAILED( ms_lpd3dDevice->CreateVertexBuffer( - sizeof(SoftwareTransformPatch_SSplatVertex)*CTerrainPatch::TERRAIN_VERTEX_COUNT, - D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, - D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_SPECULAR|D3DFVF_TEX2, - D3DPOOL_SYSTEMMEM, - &m_kSTPD.m_pkVBSplat[uIndex] + sizeof(SoftwareTransformPatch_SSplatVertex) * CTerrainPatch::TERRAIN_VERTEX_COUNT, + D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2, + D3DPOOL_SYSTEMMEM, + &m_kSTPD.m_pkVBSplat[uIndex], + NULL ) - )) return false; + )) + return false; } } @@ -769,13 +764,15 @@ bool CMapOutdoor::__SoftwareTransformPatch_Create() assert(NULL==m_kSTPD.m_pkVBNone[uIndex]); if (FAILED( ms_lpd3dDevice->CreateVertexBuffer( - sizeof(SoftwareTransformPatch_STVertex)*CTerrainPatch::TERRAIN_VERTEX_COUNT, - D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, - D3DFVF_XYZRHW, - D3DPOOL_SYSTEMMEM, - &m_kSTPD.m_pkVBNone[uIndex] + sizeof(SoftwareTransformPatch_STVertex) * CTerrainPatch::TERRAIN_VERTEX_COUNT, + D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, + D3DFVF_XYZRHW, + D3DPOOL_SYSTEMMEM, + &m_kSTPD.m_pkVBNone[uIndex], + NULL ) - )) return false; + )) + return false; } } return true; diff --git a/src/GameLib/MapOutdoorUpdate.cpp b/src/GameLib/MapOutdoorUpdate.cpp index e4ac72e1..5fdf9ecb 100644 --- a/src/GameLib/MapOutdoorUpdate.cpp +++ b/src/GameLib/MapOutdoorUpdate.cpp @@ -112,7 +112,7 @@ bool CMapOutdoor::Update(float fX, float fY, float fZ) #ifdef __PERFORMANCE_CHECKER__ DWORD t3=ELTimer_GetMSec(); #endif - CSpeedTreeForestDirectX8::Instance().UpdateSystem(CTimer::Instance().GetCurrentSecond()); + CSpeedTreeForest::Instance().UpdateSystem(CTimer::Instance().GetCurrentSecond()); #ifdef __PERFORMANCE_CHECKER__ DWORD t4=ELTimer_GetMSec(); #endif diff --git a/src/GameLib/MapOutdoorWater.cpp b/src/GameLib/MapOutdoorWater.cpp index a56a9b91..e5670b76 100644 --- a/src/GameLib/MapOutdoorWater.cpp +++ b/src/GameLib/MapOutdoorWater.cpp @@ -46,15 +46,15 @@ void CMapOutdoor::RenderWater() D3DXMatrixMultiply(&matTexTransformWater, &m_matViewInverse, &matTexTransformWater); STATEMANAGER.SaveTransform(D3DTS_TEXTURE0, &matTexTransformWater); - STATEMANAGER.SaveVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE); + STATEMANAGER.SaveFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE); STATEMANAGER.SaveTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION); STATEMANAGER.SaveTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); @@ -121,13 +121,13 @@ void CMapOutdoor::RenderWater() ////////////////////////////////////////////////////////////////////////// // RenderState - STATEMANAGER.RestoreVertexShader(); + STATEMANAGER.RestoreFVF(); STATEMANAGER.RestoreTransform(D3DTS_TEXTURE0); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MINFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MAGFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MIPFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSV); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MINFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MAGFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MIPFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSV); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_TEXCOORDINDEX); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS); diff --git a/src/GameLib/MapType.h b/src/GameLib/MapType.h index 1a1d01a8..11e26cea 100644 --- a/src/GameLib/MapType.h +++ b/src/GameLib/MapType.h @@ -127,10 +127,10 @@ typedef struct SEnvironmentData { // Light BOOL bDirLightsEnable[ENV_DIRLIGHT_NUM]; - D3DLIGHT8 DirLights[ENV_DIRLIGHT_NUM]; + D3DLIGHT9 DirLights[ENV_DIRLIGHT_NUM]; // Material - D3DMATERIAL8 Material; + D3DMATERIAL9 Material; // Fog BOOL bFogEnable; diff --git a/src/GameLib/SnowEnvironment.cpp b/src/GameLib/SnowEnvironment.cpp index f63c002e..11ffd146 100644 --- a/src/GameLib/SnowEnvironment.cpp +++ b/src/GameLib/SnowEnvironment.cpp @@ -90,10 +90,11 @@ void CSnowEnvironment::__BeginBlur() if (!m_bBlurEnable) return; - ms_lpd3dDevice->GetRenderTarget(&m_lpOldSurface); + ms_lpd3dDevice->GetRenderTarget(0, &m_lpOldSurface); ms_lpd3dDevice->GetDepthStencilSurface(&m_lpOldDepthStencilSurface); - ms_lpd3dDevice->SetRenderTarget(m_lpSnowRenderTargetSurface, m_lpSnowDepthSurface); - ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L); + ms_lpd3dDevice->SetRenderTarget(0, m_lpSnowRenderTargetSurface); + ms_lpd3dDevice->SetDepthStencilSurface(m_lpSnowDepthSurface); + ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L); STATEMANAGER.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); STATEMANAGER.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); @@ -145,7 +146,8 @@ void CSnowEnvironment::__ApplyBlur() /////////////// { - ms_lpd3dDevice->SetRenderTarget(m_lpOldSurface, m_lpOldDepthStencilSurface); + ms_lpd3dDevice->SetRenderTarget(0, m_lpOldSurface); + ms_lpd3dDevice->SetDepthStencilSurface(m_lpOldDepthStencilSurface); STATEMANAGER.SetTexture(0,m_lpSnowTexture); STATEMANAGER.SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE); @@ -162,7 +164,7 @@ void CSnowEnvironment::__ApplyBlur() BlurVertex(D3DXVECTOR3(0.0f,sy,0.0f),1.0f ,0xFFFFFF, 0,1) , BlurVertex(D3DXVECTOR3(sx,sy,0.0f),1.0f ,0xFFFFFF, 1,1) }; - STATEMANAGER.SetVertexShader( D3DFVF_XYZRHW | D3DFVF_DIFFUSE|D3DFVF_TEX1 ); + STATEMANAGER.SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,V,sizeof(BlurVertex)); } } @@ -187,7 +189,7 @@ void CSnowEnvironment::Render() const D3DXVECTOR3 & c_rv3Cross = pCamera->GetCross(); SParticleVertex * pv3Verticies; - if (SUCCEEDED(m_pVB->Lock(0, sizeof(SParticleVertex)*dwParticleCount*4, (BYTE **) &pv3Verticies, D3DLOCK_DISCARD))) + if (SUCCEEDED(m_pVB->Lock(0, sizeof(SParticleVertex) * dwParticleCount * 4, (void**)&pv3Verticies, D3DLOCK_DISCARD))) { int i = 0; std::vector::iterator itor = m_kVct_pkParticleSnow.begin(); @@ -219,7 +221,7 @@ void CSnowEnvironment::Render() m_pImageInstance->GetGraphicImagePointer()->GetTextureReference().SetTextureStage(0); STATEMANAGER.SetIndices(m_pIB, 0); STATEMANAGER.SetStreamSource(0, m_pVB, sizeof(SParticleVertex)); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_TEX1); STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, dwParticleCount*4, 0, dwParticleCount*2); STATEMANAGER.RestoreRenderState(D3DRS_ALPHABLENDENABLE); STATEMANAGER.RestoreRenderState(D3DRS_ZWRITEENABLE); @@ -233,18 +235,18 @@ bool CSnowEnvironment::__CreateBlurTexture() if (!m_bBlurEnable) return true; - if (FAILED(ms_lpd3dDevice->CreateTexture(m_wBlurTextureSize, m_wBlurTextureSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &m_lpSnowTexture))) + if (FAILED(ms_lpd3dDevice->CreateTexture(m_wBlurTextureSize, m_wBlurTextureSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &m_lpSnowTexture, NULL))) return false; if (FAILED(m_lpSnowTexture->GetSurfaceLevel(0, &m_lpSnowRenderTargetSurface))) return false; - if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_wBlurTextureSize, m_wBlurTextureSize, D3DFMT_D16, D3DMULTISAMPLE_NONE, &m_lpSnowDepthSurface))) + if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_wBlurTextureSize, m_wBlurTextureSize, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, FALSE, &m_lpSnowDepthSurface, NULL))) return false; - if (FAILED(ms_lpd3dDevice->CreateTexture(m_wBlurTextureSize, m_wBlurTextureSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &m_lpAccumTexture))) + if (FAILED(ms_lpd3dDevice->CreateTexture(m_wBlurTextureSize, m_wBlurTextureSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &m_lpAccumTexture, NULL))) return false; if (FAILED(m_lpAccumTexture->GetSurfaceLevel(0, &m_lpAccumRenderTargetSurface))) return false; - if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_wBlurTextureSize, m_wBlurTextureSize, D3DFMT_D16, D3DMULTISAMPLE_NONE, &m_lpAccumDepthSurface))) + if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_wBlurTextureSize, m_wBlurTextureSize, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, FALSE, &m_lpAccumDepthSurface, NULL))) return false; return true; @@ -252,22 +254,14 @@ bool CSnowEnvironment::__CreateBlurTexture() bool CSnowEnvironment::__CreateGeometry() { - if (FAILED(ms_lpd3dDevice->CreateVertexBuffer(sizeof(SParticleVertex)*m_dwParticleMaxNum*4, - D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY, - D3DFVF_XYZ | D3DFVF_TEX1, - D3DPOOL_SYSTEMMEM, - &m_pVB))) + if (FAILED(ms_lpd3dDevice->CreateVertexBuffer(sizeof(SParticleVertex) * m_dwParticleMaxNum * 4, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_XYZ | D3DFVF_TEX1, D3DPOOL_SYSTEMMEM, &m_pVB, NULL))) return false; - if (FAILED(ms_lpd3dDevice->CreateIndexBuffer(sizeof(WORD)*m_dwParticleMaxNum*6, - D3DUSAGE_WRITEONLY, - D3DFMT_INDEX16, - D3DPOOL_MANAGED, - &m_pIB))) + if (FAILED(ms_lpd3dDevice->CreateIndexBuffer(sizeof(WORD) * m_dwParticleMaxNum * 6, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIB, NULL))) return false; WORD* dstIndices; - if (FAILED(m_pIB->Lock(0, sizeof(WORD)*m_dwParticleMaxNum*6, (BYTE**)&dstIndices, 0))) + if (FAILED(m_pIB->Lock(0, sizeof(WORD) * m_dwParticleMaxNum * 6, (VOID**)&dstIndices, 0))) return false; const WORD c_awFillRectIndices[6] = { 0, 2, 1, 2, 3, 1, }; @@ -275,7 +269,7 @@ bool CSnowEnvironment::__CreateGeometry() { for (int j = 0; j < 6; ++j) { - dstIndices[i*6 + j] = i*4 + c_awFillRectIndices[j]; + dstIndices[i * 6 + j] = i * 4 + c_awFillRectIndices[j]; } } diff --git a/src/GameLib/SnowEnvironment.h b/src/GameLib/SnowEnvironment.h index 3ec91cff..16d0a7cd 100644 --- a/src/GameLib/SnowEnvironment.h +++ b/src/GameLib/SnowEnvironment.h @@ -28,19 +28,19 @@ class CSnowEnvironment : public CScreen void __ApplyBlur(); protected: - LPDIRECT3DSURFACE8 m_lpOldSurface; - LPDIRECT3DSURFACE8 m_lpOldDepthStencilSurface; + LPDIRECT3DSURFACE9 m_lpOldSurface; + LPDIRECT3DSURFACE9 m_lpOldDepthStencilSurface; - LPDIRECT3DTEXTURE8 m_lpSnowTexture; - LPDIRECT3DSURFACE8 m_lpSnowRenderTargetSurface; - LPDIRECT3DSURFACE8 m_lpSnowDepthSurface; + LPDIRECT3DTEXTURE9 m_lpSnowTexture; + LPDIRECT3DSURFACE9 m_lpSnowRenderTargetSurface; + LPDIRECT3DSURFACE9 m_lpSnowDepthSurface; - LPDIRECT3DTEXTURE8 m_lpAccumTexture; - LPDIRECT3DSURFACE8 m_lpAccumRenderTargetSurface; - LPDIRECT3DSURFACE8 m_lpAccumDepthSurface; + LPDIRECT3DTEXTURE9 m_lpAccumTexture; + LPDIRECT3DSURFACE9 m_lpAccumRenderTargetSurface; + LPDIRECT3DSURFACE9 m_lpAccumDepthSurface; - LPDIRECT3DVERTEXBUFFER8 m_pVB; - LPDIRECT3DINDEXBUFFER8 m_pIB; + LPDIRECT3DVERTEXBUFFER9 m_pVB; + LPDIRECT3DINDEXBUFFER9 m_pIB; D3DXVECTOR3 m_v3Center; diff --git a/src/GameLib/TerrainDecal.cpp b/src/GameLib/TerrainDecal.cpp index 326e440f..ecc75464 100644 --- a/src/GameLib/TerrainDecal.cpp +++ b/src/GameLib/TerrainDecal.cpp @@ -95,9 +95,9 @@ void CTerrainDecal::Render() STATEMANAGER.SaveTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0); STATEMANAGER.SaveTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); - + STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); @@ -110,8 +110,8 @@ void CTerrainDecal::Render() STATEMANAGER.RestoreTextureStageState(0, D3DTSS_TEXCOORDINDEX); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSV); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSV); STATEMANAGER.RestoreRenderState(D3DRS_ALPHABLENDENABLE); } diff --git a/src/GameLib/TerrainPatch.cpp b/src/GameLib/TerrainPatch.cpp index bd957c4a..bf4811eb 100644 --- a/src/GameLib/TerrainPatch.cpp +++ b/src/GameLib/TerrainPatch.cpp @@ -117,7 +117,7 @@ void CTerrainPatch::__BuildHardwareTerrainVertexBuffer(HardwareTransformPatch_SS } } -void CTerrainPatch::SoftwareTransformPatch_UpdateTerrainLighting(DWORD dwVersion, const D3DLIGHT8& c_rkLight, const D3DMATERIAL8& c_rkMtrl) +void CTerrainPatch::SoftwareTransformPatch_UpdateTerrainLighting(DWORD dwVersion, const D3DLIGHT9& c_rkLight, const D3DMATERIAL9& c_rkMtrl) { if (m_dwVersion==dwVersion) return; @@ -200,7 +200,7 @@ bool CTerrainPatchProxy::IsIn(const D3DXVECTOR3& c_rv3Target, float fRadius) return false; } -void CTerrainPatchProxy::SoftwareTransformPatch_UpdateTerrainLighting(DWORD dwVersion, const D3DLIGHT8& c_rkLight, const D3DMATERIAL8& c_rkMtrl) +void CTerrainPatchProxy::SoftwareTransformPatch_UpdateTerrainLighting(DWORD dwVersion, const D3DLIGHT9& c_rkLight, const D3DMATERIAL9& c_rkMtrl) { if (m_pTerrainPatch) m_pTerrainPatch->SoftwareTransformPatch_UpdateTerrainLighting(dwVersion, c_rkLight, c_rkMtrl); diff --git a/src/GameLib/TerrainPatch.h b/src/GameLib/TerrainPatch.h index 1fec89dc..75dc02c6 100644 --- a/src/GameLib/TerrainPatch.h +++ b/src/GameLib/TerrainPatch.h @@ -95,8 +95,8 @@ public: UINT GetWaterFaceCount(); - void SoftwareTransformPatch_UpdateTerrainLighting(DWORD dwVersion, const D3DLIGHT8& c_rkLight, const D3DMATERIAL8& c_rkMtrl); - + void SoftwareTransformPatch_UpdateTerrainLighting(DWORD dwVersion, const D3DLIGHT9& c_rkLight, const D3DMATERIAL9& c_rkMtrl); + void BuildTerrainVertexBuffer(HardwareTransformPatch_SSourceVertex* akSrcVertex); void BuildWaterVertexBuffer(SWaterVertex* akSrcVertex, UINT uWaterVertexCount); @@ -194,8 +194,8 @@ public: SoftwareTransformPatch_SSourceVertex* SoftwareTransformPatch_GetTerrainVertexDataPtr(); CGraphicVertexBuffer* HardwareTransformPatch_GetVertexBufferPtr(); - void SoftwareTransformPatch_UpdateTerrainLighting(DWORD dwVersion, const D3DLIGHT8& c_rkLight, const D3DMATERIAL8& c_rkMtrl); - + void SoftwareTransformPatch_UpdateTerrainLighting(DWORD dwVersion, const D3DLIGHT9& c_rkLight, const D3DMATERIAL9& c_rkMtrl); + protected: bool m_bUsed; short m_sPatchNum; // Patch Number diff --git a/src/GameLib/WeaponTrace.cpp b/src/GameLib/WeaponTrace.cpp index 7dc81aa2..c447c49f 100644 --- a/src/GameLib/WeaponTrace.cpp +++ b/src/GameLib/WeaponTrace.cpp @@ -290,14 +290,14 @@ void CWeaponTrace::Render() return; - LPDIRECT3DTEXTURE8 lpTexture=NULL; + LPDIRECT3DTEXTURE9 lpTexture=NULL; // Have to optimize D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); STATEMANAGER.SaveTransform(D3DTS_WORLD, &matWorld); - STATEMANAGER.SaveVertexShader(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); + STATEMANAGER.SaveFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1); STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_NONE); STATEMANAGER.SaveRenderState(D3DRS_ALPHABLENDENABLE, TRUE); @@ -346,7 +346,7 @@ void CWeaponTrace::Render() STATEMANAGER.RestoreRenderState(D3DRS_DESTBLEND); STATEMANAGER.RestoreTransform(D3DTS_WORLD); - STATEMANAGER.RestoreVertexShader(); + STATEMANAGER.RestoreFVF(); STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE); } diff --git a/src/MilesLib/SoundData.h b/src/MilesLib/SoundData.h index dc28cfe1..13ddb1c5 100644 --- a/src/MilesLib/SoundData.h +++ b/src/MilesLib/SoundData.h @@ -1,7 +1,7 @@ #ifndef __MILESLIB_CSOUNDDATA_H__ #define __MILESLIB_CSOUNDDATA_H__ -#include +#include #include "../eterBase/MappedFile.h" class CSoundData diff --git a/src/PRTerrainLib/Terrain.h b/src/PRTerrainLib/Terrain.h index fdaeb6a8..d6cc607b 100644 --- a/src/PRTerrainLib/Terrain.h +++ b/src/PRTerrainLib/Terrain.h @@ -91,7 +91,7 @@ class CTerrainImpl bool LoadWaterMap(const char * c_szWaterMapName); bool LoadWaterMapFile(const char * c_szWaterMapName); - LPDIRECT3DTEXTURE8 GetShadowTexture() { return m_lpShadowTexture; } + LPDIRECT3DTEXTURE9 GetShadowTexture() { return m_lpShadowTexture; } DWORD GetShadowMapColor(float fx, float fy); @@ -109,7 +109,7 @@ class CTerrainImpl __forceinline WORD GetHeightMapValue(short sx, short sy); protected: - LPDIRECT3DTEXTURE8 m_lpAlphaTexture[MAXTERRAINTEXTURES]; + LPDIRECT3DTEXTURE9 m_lpAlphaTexture[MAXTERRAINTEXTURES]; WORD m_awRawHeightMap[HEIGHTMAP_RAW_YSIZE*HEIGHTMAP_RAW_XSIZE]; BYTE m_abyTileMap[TILEMAP_RAW_YSIZE*TILEMAP_RAW_XSIZE]; @@ -139,7 +139,7 @@ class CTerrainImpl ////////////////////////////////////////////////////////////////////////// // Shadow Map - LPDIRECT3DTEXTURE8 m_lpShadowTexture; + LPDIRECT3DTEXTURE9 m_lpShadowTexture; WORD m_awShadowMap[SHADOWMAP_YSIZE*SHADOWMAP_XSIZE]; // 16bit R5 G6 B5 protected: diff --git a/src/PRTerrainLib/TerrainType.h b/src/PRTerrainLib/TerrainType.h index 50f6213e..84540cb4 100644 --- a/src/PRTerrainLib/TerrainType.h +++ b/src/PRTerrainLib/TerrainType.h @@ -13,7 +13,7 @@ typedef struct { long Active; long NeedsUpdate; - LPDIRECT3DTEXTURE8 pd3dTexture; + LPDIRECT3DTEXTURE9 pd3dTexture; } TTerainSplat; typedef struct diff --git a/src/PRTerrainLib/TextureSet.h b/src/PRTerrainLib/TextureSet.h index 731a79b3..b62d9038 100644 --- a/src/PRTerrainLib/TextureSet.h +++ b/src/PRTerrainLib/TextureSet.h @@ -21,7 +21,7 @@ typedef struct STerrainTexture } std::string stFilename; - LPDIRECT3DTEXTURE8 pd3dTexture; + LPDIRECT3DTEXTURE9 pd3dTexture; CGraphicImageInstance ImageInstance; float UScale; float VScale; diff --git a/src/SpeedTreeLib/CSpeedTreeDirectX.cpp b/src/SpeedTreeLib/CSpeedTreeDirectX.cpp new file mode 100644 index 00000000..59b63a8b --- /dev/null +++ b/src/SpeedTreeLib/CSpeedTreeDirectX.cpp @@ -0,0 +1,246 @@ +#include "StdAfx.h" +#include "CSpeedTreeDirectX.h" +#include +#include +#include +#include "VertexShaders.h" +#include "../eterBase/Timer.h" +#include "../eterLib/StateManager.h" +#include "../eterLib/Camera.h" + +CSpeedTreeDirectX::CSpeedTreeDirectX() : m_dwBranchVertexShader(NULL), m_dwLeafVertexShader(NULL) {} + +CSpeedTreeDirectX::~CSpeedTreeDirectX() +{ + SAFE_RELEASE(m_dwBranchVertexShader); + SAFE_RELEASE(m_dwLeafVertexShader); +} + +void CSpeedTreeDirectX::UploadWindMatrix(unsigned int uiLocation, const float* pMatrix) const +{ + STATEMANAGER.SetVertexShaderConstant(uiLocation, pMatrix, 4); +} + +void CSpeedTreeDirectX::UpdateCompundMatrix(const D3DXVECTOR3& c_rEyeVec, const D3DXMATRIX& c_rmatView, const D3DXMATRIX& c_rmatProj) +{ + D3DXMATRIX matBlend; + D3DXMatrixIdentity(&matBlend); + + D3DXMATRIX matBlendShader; + D3DXMatrixMultiply(&matBlendShader, &c_rmatView, &c_rmatProj); + + float afDirection[3]; + afDirection[0] = matBlendShader.m[0][2]; + afDirection[1] = matBlendShader.m[1][2]; + afDirection[2] = matBlendShader.m[2][2]; + CSpeedTreeRT::SetCamera(c_rEyeVec, afDirection); + + D3DXMatrixTranspose(&matBlendShader, &matBlendShader); + STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_CompoundMatrix, (const float*)&matBlendShader, 4); +} + +bool CSpeedTreeDirectX::SetRenderingDevice() +{ + if (!InitVertexShaders()) + return false; + + const float c_afLightPosition[4] = { -0.707f, -0.300f, 0.707f, 0.0f }; + const float c_afLightAmbient[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; + const float c_afLightDiffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + const float c_afLightSpecular[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + float afLight1[] = + { + c_afLightPosition[0], c_afLightPosition[1], c_afLightPosition[2], + c_afLightDiffuse[0], c_afLightDiffuse[1], c_afLightDiffuse[2], + c_afLightAmbient[0], c_afLightAmbient[1], c_afLightAmbient[2], + c_afLightSpecular[0], c_afLightSpecular[1], c_afLightSpecular[2], + c_afLightPosition[3], + 1.0f, 0.0f, 0.0f + }; + + CSpeedTreeRT::SetLightAttributes(0, afLight1); + CSpeedTreeRT::SetLightState(0, true); + return true; +} + +void CSpeedTreeDirectX::Render(unsigned long ulRenderBitVector) +{ + if (m_pMainTreeMap.empty()) + return; + + if (!(ulRenderBitVector & Forest_RenderToShadow) && !(ulRenderBitVector & Forest_RenderToMiniMap)) + UpdateCompundMatrix(CCameraManager::Instance().GetCurrentCamera()->GetEye(), ms_matView, ms_matProj); + + DWORD dwLightState = STATEMANAGER.GetRenderState(D3DRS_LIGHTING); + DWORD dwColorVertexState = STATEMANAGER.GetRenderState(D3DRS_COLORVERTEX); + DWORD dwFogVertexMode = STATEMANAGER.GetRenderState(D3DRS_FOGVERTEXMODE); + + STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE); + STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, TRUE); + + UINT uiCount; + TTreeMap::const_iterator itor = m_pMainTreeMap.begin(); + + while (itor != m_pMainTreeMap.end()) + { + CSpeedTreeWrapper* pMainTree = (itor++)->second; + CSpeedTreeWrapper** ppInstances = pMainTree->GetInstances(uiCount); + + for (UINT i = 0; i < uiCount; ++i) + { + ppInstances[i]->Advance(); + } + } + + STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_Light, m_afLighting, 3); + STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_Fog, m_afFog, 1); + + if (ulRenderBitVector & Forest_RenderToShadow) + { + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); + } + else + { + STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_ANISOTROPIC); + + STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE); + STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT); + STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE); + STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); + } + + STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, TRUE); + STATEMANAGER.SaveRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); + STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_CW); + + if (STATEMANAGER.GetRenderState(D3DRS_FOGENABLE)){} + + STATEMANAGER.SetFVF(D3DFVF_SPEEDTREE_BRANCH_VERTEX); + STATEMANAGER.SetVertexShader(m_dwBranchVertexShader); + + if (ulRenderBitVector & Forest_RenderBranches) + { + itor = m_pMainTreeMap.begin(); + + while (itor != m_pMainTreeMap.end()) + { + CSpeedTreeWrapper* pMainTree = (itor++)->second; + CSpeedTreeWrapper** ppInstances = pMainTree->GetInstances(uiCount); + + pMainTree->SetupBranchForTreeType(); + + for (UINT i = 0; i < uiCount; ++i) + if (ppInstances[i]->isShow()) + ppInstances[i]->RenderBranches(); + } + } + + STATEMANAGER.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); + + if (ulRenderBitVector & Forest_RenderFronds) + { + itor = m_pMainTreeMap.begin(); + + while (itor != m_pMainTreeMap.end()) + { + CSpeedTreeWrapper* pMainTree = (itor++)->second; + CSpeedTreeWrapper** ppInstances = pMainTree->GetInstances(uiCount); + + pMainTree->SetupFrondForTreeType(); + + for (UINT i = 0; i < uiCount; ++i) + if (ppInstances[i]->isShow()) + ppInstances[i]->RenderFronds(); + } + } + + if (ulRenderBitVector & Forest_RenderLeaves) + { + STATEMANAGER.SetFVF(D3DFVF_SPEEDTREE_LEAF_VERTEX); + STATEMANAGER.SetVertexShader(m_dwLeafVertexShader); + + if (STATEMANAGER.GetRenderState(D3DRS_FOGENABLE)){} + if (ulRenderBitVector & Forest_RenderToShadow || ulRenderBitVector & Forest_RenderToMiniMap) + { + STATEMANAGER.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL); + STATEMANAGER.SaveRenderState(D3DRS_ALPHAREF, 0x00000000); + } + + itor = m_pMainTreeMap.begin(); + + while (itor != m_pMainTreeMap.end()) + { + CSpeedTreeWrapper* pMainTree = (itor++)->second; + CSpeedTreeWrapper** ppInstances = pMainTree->GetInstances(uiCount); + + pMainTree->SetupLeafForTreeType(); + + for (UINT i = 0; i < uiCount; ++i) + if (ppInstances[i]->isShow()) + ppInstances[i]->RenderLeaves(); + } + + if (ulRenderBitVector & Forest_RenderToShadow || ulRenderBitVector & Forest_RenderToMiniMap) + { + STATEMANAGER.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); + STATEMANAGER.RestoreRenderState(D3DRS_ALPHAREF); + } + } + + if (ulRenderBitVector & Forest_RenderBillboards) + { + STATEMANAGER.SetVertexShader(NULL); + STATEMANAGER.SetFVF(D3DFVF_SPEEDTREE_BILLBOARD_VERTEX); + STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE); + STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, FALSE); + + itor = m_pMainTreeMap.begin(); + + while (itor != m_pMainTreeMap.end()) + { + CSpeedTreeWrapper* pMainTree = (itor++)->second; + CSpeedTreeWrapper** ppInstances = pMainTree->GetInstances(uiCount); + + pMainTree->SetupBranchForTreeType(); + + for (UINT i = 0; i < uiCount; ++i) + if (ppInstances[i]->isShow()) + ppInstances[i]->RenderBillboards(); + } + } + + STATEMANAGER.SetRenderState(D3DRS_LIGHTING, dwLightState); + STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, dwColorVertexState); + STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, dwFogVertexMode); + + if (!(ulRenderBitVector & Forest_RenderToShadow)) + { + STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); + STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); + + } + + STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE); + STATEMANAGER.RestoreRenderState(D3DRS_ALPHAFUNC); + STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE); +} + +bool CSpeedTreeDirectX::InitVertexShaders(void) +{ + m_dwBranchVertexShader = LoadBranchShader(ms_lpd3dDevice); + m_dwLeafVertexShader = LoadLeafShader(ms_lpd3dDevice); + + return true; +} diff --git a/src/SpeedTreeLib/CSpeedTreeDirectX.h b/src/SpeedTreeLib/CSpeedTreeDirectX.h new file mode 100644 index 00000000..b241ba6e --- /dev/null +++ b/src/SpeedTreeLib/CSpeedTreeDirectX.h @@ -0,0 +1,23 @@ +#pragma once +#include +#include "SpeedTreeForest.h" +#include "SpeedTreeMaterial.h" + +class CSpeedTreeDirectX : public CSpeedTreeForest, public CGraphicBase +{ +public: + CSpeedTreeDirectX(); + ~CSpeedTreeDirectX(); + + void UploadWindMatrix(unsigned int uiLocation, const float* pMatrix) const; + bool SetRenderingDevice(); + void Render(unsigned long ulRenderBitVector = Forest_RenderAll); + void UpdateCompundMatrix(const D3DXVECTOR3& c_rEyeVec, const D3DXMATRIX& c_rmatView, const D3DXMATRIX& c_rmatProj); + +private: + bool InitVertexShaders(); + +private: + LPDIRECT3DVERTEXSHADER9 m_dwBranchVertexShader; + LPDIRECT3DVERTEXSHADER9 m_dwLeafVertexShader; +}; \ No newline at end of file diff --git a/src/SpeedTreeLib/SpeedGrassRT.cpp b/src/SpeedTreeLib/SpeedGrassRT.cpp deleted file mode 100644 index b52c1a5c..00000000 --- a/src/SpeedTreeLib/SpeedGrassRT.cpp +++ /dev/null @@ -1,769 +0,0 @@ -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT Class -// -// (c) 2003 IDV, Inc. -// -// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION *** -// -// This software is supplied under the terms of a license agreement or -// nondisclosure agreement with Interactive Data Visualization and may -// not be copied or disclosed except in accordance with the terms of -// that agreement. -// -// Copyright (c) 2001-2003 IDV, Inc. -// All Rights Reserved. -// -// IDV, Inc. -// 1233 Washington St. Suite 610 -// Columbia, SC 29201 -// Voice: (803) 799-1699 -// Fax: (803) 931-0320 -// Web: http://www.idvinc.com - - -#include "StdAfx.h" -#include "BoundaryShapeManager.h" - -#ifdef USE_SPEEDGRASS - -inline float VecInterpolate(float fStart, float fEnd, float fPercent) -{ - return fStart + (fEnd - fStart) * fPercent; -} - -#define VectorSinD(x) sinf((x) / 57.29578f) -#define VectorCosD(x) cosf((x) / 57.29578f) - -using namespace std; - -// macros -#ifndef max -#define max(a, b) (((a) > (b)) ? (a) : (b)) -#endif -#ifndef min -#define min(a, b) (((a) < (b)) ? (a) : (b)) -#endif - -// static variables -float CSpeedGrassRT::m_fLodFarDistance = 100.0f; -float CSpeedGrassRT::m_fLodTransitionLength = 37.5f; -float CSpeedGrassRT::m_afUnitBillboard[12] = { 0.0f }; -float CSpeedGrassRT::m_afWindDir[4] = { 1.0f, 0.3f, 0.0f, 0.0f }; - -// camera -float CSpeedGrassRT::m_afCameraOut[3] = { 0.0f, 1.0f, 0.0f }; -float CSpeedGrassRT::m_afCameraUp[3] = { 0.0f, 0.0f, 1.0f }; -float CSpeedGrassRT::m_afCameraRight[3] = { 1.0f, 0.0f, 0.0f }; -float CSpeedGrassRT::m_afCameraPos[3] = { 0.0f, 0.0f, 0.0f }; -float CSpeedGrassRT::m_fFieldOfView = D3DXToRadian(40.0f); -float CSpeedGrassRT::m_fAspectRatio = 4.0f / 3.0f; - -// culling -float CSpeedGrassRT::m_afFrustumBox[6] = { 0.0f }; -float CSpeedGrassRT::m_afFrustumMin[2] = { FLT_MAX, FLT_MAX }; -float CSpeedGrassRT::m_afFrustumMax[2] = { -FLT_MAX, -FLT_MAX }; -float CSpeedGrassRT::m_afFrustumPlanes[5][4] = { 0.0f }; - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::SBlade::SBlade - -CSpeedGrassRT::SBlade::SBlade( ) : - m_fSize(1.0f), - m_fNoise(0.0f), - m_fThrow(0.0f), - m_ucWhichTexture(0) -{ - m_afBottomColor[0] = m_afBottomColor[1] = m_afBottomColor[2] = 1.0f; - m_afTopColor[0] = m_afTopColor[1] = m_afTopColor[2] = 1.0f; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::SRegion::SRegion - -CSpeedGrassRT::SRegion::SRegion( ) : - m_bCulled(false), - m_fCullingRadius(1.0f) -{ - m_afCenter[0] = m_afCenter[1] = m_afCenter[2] = 0.5f; - m_afMin[0] = m_afMin[1] = m_afMin[2] = 0.0f; - m_afMax[0] = m_afMax[1] = m_afMax[2] = 1.0f; - m_VertexBuffer.Destroy(); -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::CSpeedGrassRT - -CSpeedGrassRT::CSpeedGrassRT( ) : - m_nNumRegions(0), - m_nNumRegionCols(0), - m_nNumRegionRows(0), - m_pRegions(NULL), - m_bAllRegionsCulled(false) -{ - m_afBoundingBox[0] = m_afBoundingBox[1] = m_afBoundingBox[2] = 0.0f; - m_afBoundingBox[3] = m_afBoundingBox[4] = m_afBoundingBox[5] = 1.0f; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::~CSpeedGrassRT - -CSpeedGrassRT::~CSpeedGrassRT( ) -{ -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::DeleteRegions - -void CSpeedGrassRT::DeleteRegions(void) -{ - delete[] m_pRegions; - m_pRegions = NULL; - m_nNumRegions = 0; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::GetRegions - -const CSpeedGrassRT::SRegion* CSpeedGrassRT::GetRegions(unsigned int& uiNumRegions) -{ - uiNumRegions = m_nNumRegions; - - return m_pRegions; -} - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::ParseBsfFile - -bool CSpeedGrassRT::ParseBsfFile(const char* pFilename, unsigned int nNumBlades, unsigned int uiRows, unsigned int uiCols, float fCollisionDistance) -{ - bool bSuccess = false; - - // copy region settings - m_nNumRegionCols = int(uiCols); - m_nNumRegionRows = int(uiRows); - - // initialize bounding box - m_afBoundingBox[0] = m_afBoundingBox[1] = m_afBoundingBox[2] = FLT_MAX; - m_afBoundingBox[3] = m_afBoundingBox[4] = m_afBoundingBox[5] = -FLT_MAX; - - CBoundaryShapeManager cManager; - vector vSceneBlades; - - if (cManager.LoadBsfFile(pFilename)) - { - for (unsigned int i = 0; i < nNumBlades; ++i) - { - SBlade sBlade; - - // try to place a blade - if (cManager.RandomPoint(sBlade.m_afPos[0], sBlade.m_afPos[1])) - { - sBlade.m_afPos[2] = Height(sBlade.m_afPos[0], sBlade.m_afPos[1], sBlade.m_afNormal); - -// CVec3 cNormal(sBlade.m_afNormal[0], sBlade.m_afNormal[1], sBlade.m_afNormal[2]); -// cNormal.Normalize( ); -// cNormal[2] = -cNormal[2]; -// memcpy(sBlade.m_afNormal, cNormal, 3 * sizeof(float)); - D3DXVECTOR3 v3Normal(sBlade.m_afNormal[0], sBlade.m_afNormal[1], sBlade.m_afNormal[2]); - D3DXVec3Normalize(&v3Normal, &v3Normal); - v3Normal.z = -v3Normal.z; - sBlade.m_afNormal[0] = v3Normal.x; - sBlade.m_afNormal[1] = v3Normal.y; - sBlade.m_afNormal[2] = v3Normal.z; - - // check against overall scene bounding box - for (int nAxis = 0; nAxis < 3; ++nAxis) - { - m_afBoundingBox[nAxis] = min(m_afBoundingBox[nAxis], sBlade.m_afPos[nAxis]); - m_afBoundingBox[nAxis + 3] = max(m_afBoundingBox[nAxis + 3], sBlade.m_afPos[nAxis]); - } - - // set bottom and top color - float fHeightPercent = Color(sBlade.m_afPos[0], sBlade.m_afPos[1], sBlade.m_afNormal, sBlade.m_afTopColor, sBlade.m_afBottomColor); - sBlade.m_fSize = VecInterpolate(c_fMinBladeSize, c_fMaxBladeSize, fHeightPercent); - - // assign which blade texture map - sBlade.m_ucWhichTexture = GetRandom(0, c_nNumBladeMaps - 1); - - // compute wind effects - sBlade.m_fNoise = GetRandom(c_fMinBladeNoise, c_fMaxBladeNoise); - sBlade.m_fThrow = GetRandom(c_fMinBladeThrow, c_fMaxBladeThrow); - - // store all blades together - vSceneBlades.push_back(sBlade); - } - } - - bSuccess = true; - } - else - fprintf(stderr, "%s\n", cManager.GetCurrentError( ).c_str( )); - - if (bSuccess) - CreateRegions(vSceneBlades, fCollisionDistance); - - return bSuccess; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::CustomPlacement -// -// Use this function to perform custom grass blade placement. Feel free -// to add parameters as necessary but be sure to call CreateRegions( ) -// at the end of the function to set up the SpeedGrass region system. - -bool CSpeedGrassRT::CustomPlacement(unsigned int uiRows, unsigned int uiCols) -{ - // copy region settings (do not remove) - m_nNumRegionCols = int(uiCols); - m_nNumRegionRows = int(uiRows); - - // initialize bounding box (do not remove) - m_afBoundingBox[0] = m_afBoundingBox[1] = m_afBoundingBox[2] = FLT_MAX; - m_afBoundingBox[3] = m_afBoundingBox[4] = m_afBoundingBox[5] = -FLT_MAX; - - // place one blade as an example - vector vSceneBlades; - - SBlade sBlade; - - sBlade.m_afPos[0] = 0.0f; - sBlade.m_afPos[1] = 0.0f; - sBlade.m_afPos[2] = 0.0f; - - sBlade.m_afNormal[0] = 0.0f; - sBlade.m_afNormal[1] = 0.0f; - sBlade.m_afNormal[2] = 1.0f; - - // check against overall scene bounding box (always do this) - for (int nAxis = 0; nAxis < 3; ++nAxis) - { - m_afBoundingBox[nAxis] = min(m_afBoundingBox[nAxis], sBlade.m_afPos[nAxis]); - m_afBoundingBox[nAxis + 3] = max(m_afBoundingBox[nAxis + 3], sBlade.m_afPos[nAxis]); - } - - // set bottom and top color - memcpy(sBlade.m_afBottomColor, sBlade.m_afNormal, 12); - memcpy(sBlade.m_afTopColor, sBlade.m_afNormal, 12); - - // assign which blade texture map - sBlade.m_ucWhichTexture = GetRandom(0, c_nNumBladeMaps - 1); - - // compute wind effects - sBlade.m_fNoise = GetRandom(c_fMinBladeNoise, c_fMaxBladeNoise); - sBlade.m_fThrow = GetRandom(c_fMinBladeThrow, c_fMaxBladeThrow); - - // compute dimensions - sBlade.m_fSize = GetRandom(c_fMinBladeSize, c_fMaxBladeSize); - - // store all blades together - vSceneBlades.push_back(sBlade); - - // create regions based on blades (do not remove) - CreateRegions(vSceneBlades); - - // true = success, false = error - return true; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::GetLodParams - -void CSpeedGrassRT::GetLodParams(float& fFarDistance, float& fTransitionLength) -{ - fFarDistance = m_fLodFarDistance; - fTransitionLength = m_fLodTransitionLength; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::SetLodParams - -void CSpeedGrassRT::SetLodParams(float fFarDistance, float fTransitionLength) -{ - m_fLodFarDistance = fFarDistance; - m_fLodTransitionLength = fTransitionLength; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::Cull -// -// Using a two-dimensional projection, determine which regions -// intersect with the view frustum (+Z is assumed to be up) - -void CSpeedGrassRT::Cull(void) -{ - // convert raw frustum min and max values into min and max region cell indices - int anFrustumCellsMin[2], anFrustumCellsMax[2]; - ConvertCoordsToCell(m_afFrustumMin, anFrustumCellsMin); - ConvertCoordsToCell(m_afFrustumMax, anFrustumCellsMax); - - // set all regions to culled, modify later - for (int i = 0; i < m_nNumRegions; ++i) - m_pRegions[i].m_bCulled = true; - - int nRegionsDrawn = 0; - - // is the entire set of regions culled? - if ((anFrustumCellsMin[0] < 0 && anFrustumCellsMax[0] < 0) || - (anFrustumCellsMin[0] >= m_nNumRegionCols && anFrustumCellsMax[0] >= m_nNumRegionCols) || - (anFrustumCellsMin[1] < 0 && anFrustumCellsMax[1] < 0) || - (anFrustumCellsMin[1] >= m_nNumRegionRows && anFrustumCellsMax[1] >= m_nNumRegionRows)) - m_bAllRegionsCulled = true; - else - { - // clip cell values - anFrustumCellsMin[0] = max(anFrustumCellsMin[0], 0); - anFrustumCellsMin[1] = max(anFrustumCellsMin[1], 0); - anFrustumCellsMax[0] = min(anFrustumCellsMax[0], m_nNumRegionCols - 1); - anFrustumCellsMax[1] = min(anFrustumCellsMax[1], m_nNumRegionRows - 1); - - for (i = anFrustumCellsMin[0]; i <= anFrustumCellsMax[0]; ++i) - for (int j = anFrustumCellsMin[1]; j <= anFrustumCellsMax[1]; ++j) - { - SRegion* pRegion = m_pRegions + GetRegionIndex(j, i); - pRegion->m_bCulled = OutsideFrustum(pRegion); - } - - m_bAllRegionsCulled = false; - } -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::SetWindDirection - -void CSpeedGrassRT::SetWindDirection(const float* pWindDir) -{ - memcpy(m_afWindDir, pWindDir, 3 * sizeof(float)); - m_afWindDir[3] = 0.0f; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::GetWindDirection - -const float* CSpeedGrassRT::GetWindDirection(void) -{ - return m_afWindDir; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::GetCameraPos - -const float* CSpeedGrassRT::GetCameraPos(void) -{ - return m_afCameraPos; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::SetCamera - -void CSpeedGrassRT::SetCamera(const float* pPosition, const double* pModelviewMatrix) -{ - memcpy(m_afCameraPos, pPosition, 3 * sizeof(float)); - - // "right" vector - m_afCameraRight[0] = pModelviewMatrix[0]; - m_afCameraRight[1] = pModelviewMatrix[4]; - m_afCameraRight[2] = pModelviewMatrix[8]; - - // "up" vector - m_afCameraUp[0] = pModelviewMatrix[1]; - m_afCameraUp[1] = pModelviewMatrix[5]; - m_afCameraUp[2] = pModelviewMatrix[9]; - - // "out of screen" vector - m_afCameraOut[0] = pModelviewMatrix[2]; - m_afCameraOut[1] = pModelviewMatrix[6]; - m_afCameraOut[2] = pModelviewMatrix[10]; - - // with direction changed, billboard turns - ComputeUnitBillboard( ); - - // compute new frustum box - ComputeFrustum( ); -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::SetPerspective - -void CSpeedGrassRT::SetPerspective(float fAspectRatio, float fFieldOfView) -{ - m_fAspectRatio = fAspectRatio; - m_fFieldOfView = D3DXToRadian(fAspectRatio * fFieldOfView); -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::CreateRegions - -void CSpeedGrassRT::CreateRegions(const vector& vSceneBlades, float fCollisionDistance) -{ - // create regions based on overall extents - DeleteRegions( ); - m_nNumRegions = int(m_nNumRegionRows * m_nNumRegionCols); - m_pRegions = new SRegion[m_nNumRegions]; - - // run through all regions, computing extents for each - float fCellWidth = (m_afBoundingBox[3] - m_afBoundingBox[0]) / m_nNumRegionCols; - float fCellHeight = (m_afBoundingBox[4] - m_afBoundingBox[1]) / m_nNumRegionRows; - - float fY = m_afBoundingBox[1]; - for (int nRow = 0; nRow < m_nNumRegionRows; ++nRow) - { - float fX = m_afBoundingBox[0]; - for (int nCol = 0; nCol < m_nNumRegionCols; ++nCol) - { - SRegion* pRegion = m_pRegions + GetRegionIndex(nRow, nCol); - - // compute extents - pRegion->m_afMin[0] = fX; - pRegion->m_afMax[0] = fX + fCellWidth; - pRegion->m_afMin[1] = fY; - pRegion->m_afMax[1] = fY + fCellHeight; - - // compute center - pRegion->m_afCenter[0] = 0.5f * (pRegion->m_afMin[0] + pRegion->m_afMax[0]); - pRegion->m_afCenter[1] = 0.5f * (pRegion->m_afMin[1] + pRegion->m_afMax[1]); - - // compute culling radius - pRegion->m_fCullingRadius = 1.1f * sqrt( - ((pRegion->m_afMax[0] - pRegion->m_afCenter[0]) * (pRegion->m_afMax[0] - pRegion->m_afCenter[0])) + - ((pRegion->m_afMax[1] - pRegion->m_afCenter[1]) * (pRegion->m_afMax[1] - pRegion->m_afCenter[1])) - ); - - fX += fCellWidth; - } - - fY += fCellHeight; - } - - // assign each blade of grass to its particular region - for (vector::const_iterator iBlade = vSceneBlades.begin( ); iBlade != vSceneBlades.end( ); ++iBlade) - { - // convert position to row/col index - float fPercentAlongX = (iBlade->m_afPos[0] - m_afBoundingBox[0]) / (m_afBoundingBox[3] - m_afBoundingBox[0]); - float fPercentAlongY = (iBlade->m_afPos[1] - m_afBoundingBox[1]) / (m_afBoundingBox[4] - m_afBoundingBox[1]); - - // clip values - unsigned int uiCol = min(fPercentAlongX * m_nNumRegionCols, m_nNumRegionCols - 1); - unsigned int uiRow = min(fPercentAlongY * m_nNumRegionRows, m_nNumRegionRows - 1); - - m_pRegions[GetRegionIndex(uiRow, uiCol)].m_vBlades.push_back(*iBlade); - } - - // compute z extents (now that the blades are in) - for (int i = 0; i < m_nNumRegions; ++i) - { - SRegion* pRegion = m_pRegions + i; - - pRegion->m_afMin[2] = FLT_MAX; - pRegion->m_afMax[2] = -FLT_MAX; - for (vector::iterator iBlade = pRegion->m_vBlades.begin( ); iBlade != pRegion->m_vBlades.end( ); ++iBlade) - { - pRegion->m_afMin[2] = min(pRegion->m_afMin[2], iBlade->m_afPos[2]); - pRegion->m_afMax[2] = max(pRegion->m_afMax[2], iBlade->m_afPos[2] + iBlade->m_fSize); - } - - pRegion->m_afCenter[0] = 0.5f * (pRegion->m_afMin[0] + pRegion->m_afMax[0]); - pRegion->m_afCenter[1] = 0.5f * (pRegion->m_afMin[1] + pRegion->m_afMax[1]); - pRegion->m_afCenter[2] = 0.5f * (pRegion->m_afMin[2] + pRegion->m_afMax[2]); - - // compute culling radius - pRegion->m_fCullingRadius = 1.1f * sqrt( - ((pRegion->m_afMax[0] - pRegion->m_afCenter[0]) * (pRegion->m_afMax[0] - pRegion->m_afCenter[0])) + - ((pRegion->m_afMax[1] - pRegion->m_afCenter[1]) * (pRegion->m_afMax[1] - pRegion->m_afCenter[1])) + - ((pRegion->m_afMax[2] - pRegion->m_afCenter[2]) * (pRegion->m_afMax[2] - pRegion->m_afCenter[2])) - ); - } - - // collision detection - if (fCollisionDistance > 0.0f) - { - fCollisionDistance *= fCollisionDistance; - for (int nRow = 0; nRow < m_nNumRegionRows; ++nRow) - { - float fX = m_afBoundingBox[0]; - for (int nCol = 0; nCol < m_nNumRegionCols; ++nCol) - { - SRegion* pRegion = m_pRegions + GetRegionIndex(nRow, nCol); - - // check each blade against all other blades in the region - for (DWORD i = 0; i < pRegion->m_vBlades.size( ); ++i) - { - float fX = pRegion->m_vBlades[i].m_afPos[0]; - float fY = pRegion->m_vBlades[i].m_afPos[1]; - bool bCollision = false; - for (DWORD j = 0; j < pRegion->m_vBlades.size( ) && !bCollision; ++j) - { - if (i != j) - { - float fDistance = (fX - pRegion->m_vBlades[j].m_afPos[0]) * (fX - pRegion->m_vBlades[j].m_afPos[0]) + (fY - pRegion->m_vBlades[j].m_afPos[1]) * (fY - pRegion->m_vBlades[j].m_afPos[1]); - if (fDistance < fCollisionDistance) - bCollision = true; - } - } - - // delete the blade if necessary and adjust the main loop counter to compensate - if (bCollision) - pRegion->m_vBlades.erase(pRegion->m_vBlades.begin( ) + i--); - } - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::RotateAxisFromIdentity - -__forceinline void CSpeedGrassRT::RotateAxisFromIdentity(D3DXMATRIX * pMat, const float & c_fAngle, const D3DXVECTOR3 & c_rv3Axis) -{ - float s = VectorSinD(c_fAngle); - float c = VectorCosD(c_fAngle); - float t = 1.0 - c; - - float x = c_rv3Axis.x; - float y = c_rv3Axis.y; - float z = c_rv3Axis.z; - - pMat->_11 = t * x * x + c; - pMat->_12 = t * x * y + s * z; - pMat->_13 = t * x * z - s * y; - pMat->_21 = t * x * y - s * z; - pMat->_22 = t * y * y + c; - pMat->_23 = t * y * z + s * x; - pMat->_31 = t * x * z + s * y; - pMat->_32 = t * y * z - s * x; - pMat->_33 = t * z * z + c; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::ComputeFrustum - -void CSpeedGrassRT::ComputeFrustum(void) -{ - // setup useful vectors -// CVec3 cCameraIn(-m_afCameraOut[0], -m_afCameraOut[1], -m_afCameraOut[2]); -// CVec3 cCameraUp(m_afCameraUp[0], m_afCameraUp[1], m_afCameraUp[2]); -// CVec3 cCameraRight(m_afCameraRight[0], m_afCameraRight[1], m_afCameraRight[2]); -// CVec3 cCameraPos(m_afCameraPos[0], m_afCameraPos[1], m_afCameraPos[2]); -// CVec3 cFarPoint = cCameraPos + cCameraIn * (m_fLodFarDistance + m_fLodTransitionLength); - D3DXVECTOR3 cCameraIn(-m_afCameraOut[0], -m_afCameraOut[1], -m_afCameraOut[2]); - D3DXVECTOR3 cCameraUp(m_afCameraUp[0], m_afCameraUp[1], m_afCameraUp[2]); - D3DXVECTOR3 cCameraRight(m_afCameraRight[0], m_afCameraRight[1], m_afCameraRight[2]); - D3DXVECTOR3 cCameraPos(m_afCameraPos[0], m_afCameraPos[1], m_afCameraPos[2]); - D3DXVECTOR3 cFarPoint = cCameraPos + cCameraIn * (m_fLodFarDistance + m_fLodTransitionLength); - - // far plane -// memcpy(m_afFrustumPlanes[0], cCameraIn, 3 * sizeof(float)); -// m_afFrustumPlanes[0][3] = -(cCameraIn ^ cFarPoint); // operator^ is dot product - m_afFrustumPlanes[0][0] = cCameraIn.x; - m_afFrustumPlanes[0][1] = cCameraIn.y; - m_afFrustumPlanes[0][2] = cCameraIn.z; - m_afFrustumPlanes[0][3] = -D3DXVec3Dot(&cCameraIn, &cFarPoint); // operator^ is dot product - -// CRotTransform cRotate(true); - D3DXMATRIX cRotate; - D3DXMatrixIdentity(&cRotate); - D3DXVECTOR3 cNormal; - - // upper plane -// cRotate.RotateAxisFromIdentity(VecRad2Deg(0.5f * m_fFieldOfView * m_fAspectRatio + c_fHalfPi) , cCameraRight); -// CVec3 cNormal = cCameraIn * cRotate; -// cNormal.Normalize( ); -// memcpy(m_afFrustumPlanes[1], cNormal, 3 * sizeof(float)); -// m_afFrustumPlanes[1][3] = -(cNormal ^ cCameraPos); - - // left plane -// cRotate.RotateAxisFromIdentity(VecRad2Deg(0.5f * m_fFieldOfView + c_fHalfPi) , cCameraUp); -// cNormal = cCameraIn * cRotate; -// cNormal.Normalize( ); -// memcpy(m_afFrustumPlanes[2], cNormal, 3 * sizeof(float)); -// m_afFrustumPlanes[2][3] = -(cNormal ^ cCameraPos); - - // lower plane -// cRotate.RotateAxisFromIdentity(-VecRad2Deg(0.5f * m_fFieldOfView * m_fAspectRatio + c_fHalfPi) , cCameraRight); -// cNormal = cCameraIn * cRotate; -// cNormal.Normalize( ); -// memcpy(m_afFrustumPlanes[3], cNormal, 3 * sizeof(float)); -// m_afFrustumPlanes[3][3] = -(cNormal ^ cCameraPos); - - // right plane -// cRotate.RotateAxisFromIdentity(-VecRad2Deg(0.5f * m_fFieldOfView + c_fHalfPi) , cCameraUp); -// cNormal = cCameraIn * cRotate; -// cNormal.Normalize( ); -// memcpy(m_afFrustumPlanes[4], cNormal, 3 * sizeof(float)); -// m_afFrustumPlanes[4][3] = -(cNormal ^ cCameraPos); - - RotateAxisFromIdentity(&cRotate, D3DXToDegree(0.5f * m_fFieldOfView * m_fAspectRatio + c_fHalfPi), cCameraRight); - D3DXVec3TransformCoord(&cNormal, &cCameraIn, &cRotate); - D3DXVec3Normalize(&cNormal, &cNormal); - m_afFrustumPlanes[1][0] = cNormal.x; - m_afFrustumPlanes[1][1] = cNormal.y; - m_afFrustumPlanes[1][2] = cNormal.z; - m_afFrustumPlanes[1][3] = -D3DXVec3Dot(&cNormal, &cCameraPos); // operator^ is dot product - - RotateAxisFromIdentity(&cRotate, D3DXToDegree(0.5f * m_fFieldOfView + c_fHalfPi), cCameraUp); - D3DXVec3TransformCoord(&cNormal, &cCameraIn, &cRotate); - D3DXVec3Normalize(&cNormal, &cNormal); - m_afFrustumPlanes[2][0] = cNormal.x; - m_afFrustumPlanes[2][1] = cNormal.y; - m_afFrustumPlanes[2][2] = cNormal.z; - m_afFrustumPlanes[2][3] = -D3DXVec3Dot(&cNormal, &cCameraPos); // operator^ is dot product - - RotateAxisFromIdentity(&cRotate, -D3DXToDegree(0.5f * m_fFieldOfView * m_fAspectRatio + c_fHalfPi), cCameraRight); - D3DXVec3TransformCoord(&cNormal, &cCameraIn, &cRotate); - D3DXVec3Normalize(&cNormal, &cNormal); - m_afFrustumPlanes[3][0] = cNormal.x; - m_afFrustumPlanes[3][1] = cNormal.y; - m_afFrustumPlanes[3][2] = cNormal.z; - m_afFrustumPlanes[3][3] = -D3DXVec3Dot(&cNormal, &cCameraPos); // operator^ is dot product - - RotateAxisFromIdentity(&cRotate, -D3DXToDegree(0.5f * m_fFieldOfView + c_fHalfPi), cCameraUp); - D3DXVec3TransformCoord(&cNormal, &cCameraIn, &cRotate); - D3DXVec3Normalize(&cNormal, &cNormal); - m_afFrustumPlanes[4][0] = cNormal.x; - m_afFrustumPlanes[4][1] = cNormal.y; - m_afFrustumPlanes[4][2] = cNormal.z; - m_afFrustumPlanes[4][3] = -D3DXVec3Dot(&cNormal, &cCameraPos); // operator^ is dot product - - // frustum points - float fFrustumHeight = (m_fLodFarDistance + m_fLodTransitionLength) * tanf(0.5f * m_fFieldOfView); - float fFrustumWidth = (m_fLodFarDistance + m_fLodTransitionLength) * tanf(0.5f * m_fFieldOfView * m_fAspectRatio); - -// CVec3 acFrustum[5]; - D3DXVECTOR3 acFrustum[5]; - acFrustum[0] = cCameraPos; - acFrustum[1] = cFarPoint + cCameraRight * fFrustumWidth + cCameraUp * fFrustumHeight; - acFrustum[2] = cFarPoint - cCameraRight * fFrustumWidth + cCameraUp * fFrustumHeight; - acFrustum[3] = cFarPoint - cCameraRight * fFrustumWidth - cCameraUp * fFrustumHeight; - acFrustum[4] = cFarPoint + cCameraRight * fFrustumWidth - cCameraUp * fFrustumHeight; - - // find min/max (x,y) coordinates - m_afFrustumMin[0] = m_afFrustumMin[1] = FLT_MAX; - m_afFrustumMax[0] = m_afFrustumMax[1] = -FLT_MAX; - for (int i = 0; i < 5; ++i) - { - m_afFrustumMin[0] = min(m_afFrustumMin[0], acFrustum[i][0]); - m_afFrustumMax[0] = max(m_afFrustumMax[0], acFrustum[i][0]); - m_afFrustumMin[1] = min(m_afFrustumMin[1], acFrustum[i][1]); - m_afFrustumMax[1] = max(m_afFrustumMax[1], acFrustum[i][1]); - } -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::ComputeUnitBillboard - -void CSpeedGrassRT::ComputeUnitBillboard(void) -{ -// float fAzimuth = D3DXToDegree(atan2(-m_afCameraOut[1], -m_afCameraOut[0])); - float fAzimuth = atan2(-m_afCameraOut[1], -m_afCameraOut[0]); - -// CRotTransform cTrans; -// cTrans.RotateZ(fAzimuth); -// -// static CVec3 afCorner1(0.0f, 0.5f, 1.0f); -// static CVec3 afCorner2(0.0f, -0.5f, 1.0f); -// static CVec3 afCorner3(0.0f, -0.5f, 0.0f); -// static CVec3 afCorner4(0.0f, 0.5f, 0.0f); -// -// CVec3 afNewCorner1 = afCorner1 * cTrans; -// CVec3 afNewCorner2 = afCorner2 * cTrans; -// CVec3 afNewCorner3 = afCorner3 * cTrans; -// CVec3 afNewCorner4 = afCorner4 * cTrans; -// -// memcpy(m_afUnitBillboard + 0, afNewCorner1.m_afData, 3 * sizeof(float)); -// memcpy(m_afUnitBillboard + 3, afNewCorner2.m_afData, 3 * sizeof(float)); -// memcpy(m_afUnitBillboard + 6, afNewCorner3.m_afData, 3 * sizeof(float)); -// memcpy(m_afUnitBillboard + 9, afNewCorner4.m_afData, 3 * sizeof(float)); - - D3DXMATRIX cTrans; - D3DXMatrixRotationZ(&cTrans, fAzimuth); - - static D3DXVECTOR3 afCorner1(0.0f, 0.5f, 1.0f); - static D3DXVECTOR3 afCorner2(0.0f, -0.5f, 1.0f); - static D3DXVECTOR3 afCorner3(0.0f, -0.5f, 0.0f); - static D3DXVECTOR3 afCorner4(0.0f, 0.5f, 0.0f); - - D3DXVECTOR3 afNewCorner1; - D3DXVECTOR3 afNewCorner2; - D3DXVECTOR3 afNewCorner3; - D3DXVECTOR3 afNewCorner4; - - D3DXVec3TransformCoord(&afNewCorner1, &afCorner1, &cTrans); - D3DXVec3TransformCoord(&afNewCorner2, &afCorner2, &cTrans); - D3DXVec3TransformCoord(&afNewCorner3, &afCorner3, &cTrans); - D3DXVec3TransformCoord(&afNewCorner4, &afCorner4, &cTrans); - - m_afUnitBillboard[0] = afNewCorner1.x; - m_afUnitBillboard[1] = afNewCorner1.y; - m_afUnitBillboard[2] = afNewCorner1.z; - m_afUnitBillboard[3] = afNewCorner2.x; - m_afUnitBillboard[4] = afNewCorner2.y; - m_afUnitBillboard[5] = afNewCorner2.z; - m_afUnitBillboard[6] = afNewCorner3.x; - m_afUnitBillboard[7] = afNewCorner3.y; - m_afUnitBillboard[8] = afNewCorner3.z; - m_afUnitBillboard[9] = afNewCorner4.x; - m_afUnitBillboard[10] = afNewCorner4.y; - m_afUnitBillboard[11] = afNewCorner4.z; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::ConvertCoordsToCell - -void CSpeedGrassRT::ConvertCoordsToCell(const float* pCoords, int* pGridCoords) const -{ - float fPercentAlongX = (pCoords[0] - m_afBoundingBox[0]) / (m_afBoundingBox[3] - m_afBoundingBox[0]); - float fPercentAlongY = (pCoords[1] - m_afBoundingBox[1]) / (m_afBoundingBox[4] - m_afBoundingBox[1]); - - if (fPercentAlongX < 0.0f) - pGridCoords[0] = -1; - else if (fPercentAlongX > 1.0f) - pGridCoords[0] = m_nNumRegionCols; - else - pGridCoords[0] = fPercentAlongX * m_nNumRegionCols; - - if (fPercentAlongY < 0.0f) - pGridCoords[1] = -1; - else if (fPercentAlongY > 1.0f) - pGridCoords[1] = m_nNumRegionRows; - else - pGridCoords[1] = fPercentAlongY * m_nNumRegionRows; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT::OutsideFrustum - -__forceinline bool CSpeedGrassRT::OutsideFrustum(CSpeedGrassRT::SRegion* pRegion) -{ - bool bOutside = false; - - for (int i = 0; i < 5 && !bOutside; ++i) - if (m_afFrustumPlanes[i][0] * pRegion->m_afCenter[0] + - m_afFrustumPlanes[i][1] * pRegion->m_afCenter[1] + - m_afFrustumPlanes[i][2] * pRegion->m_afCenter[2] + - m_afFrustumPlanes[i][3] > pRegion->m_fCullingRadius) - bOutside = true; - - return bOutside; -} - -#endif // USE_SPEEDGRASS \ No newline at end of file diff --git a/src/SpeedTreeLib/SpeedGrassRT.h b/src/SpeedTreeLib/SpeedGrassRT.h deleted file mode 100644 index fd8a2bab..00000000 --- a/src/SpeedTreeLib/SpeedGrassRT.h +++ /dev/null @@ -1,180 +0,0 @@ -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassRT Class -// -// (c) 2003 IDV, Inc. -// -// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION *** -// -// This software is supplied under the terms of a license agreement or -// nondisclosure agreement with Interactive Data Visualization and may -// not be copied or disclosed except in accordance with the terms of -// that agreement. -// -// Copyright (c) 2001-2003 IDV, Inc. -// All Rights Reserved. -// -// IDV, Inc. -// 1233 Washington St. Suite 610 -// Columbia, SC 29201 -// Voice: (803) 799-1699 -// Fax: (803) 931-0320 -// Web: http://www.idvinc.com - -#pragma once - -//#include -//#include "Constants.h" -//#include "../Common Source/IdvVertexBuffer.h" - -#ifdef USE_SPEEDGRASS - - -// forward reference -class CIdvTerrain; - - -/////////////////////////////////////////////////////////////////////// -// class CSpeedGrassRT declaration - -class CSpeedGrassRT -{ -public: - CSpeedGrassRT( ); - virtual ~CSpeedGrassRT( ); - - - /////////////////////////////////////////////////////////////////////// - // struct SBlade - - struct SBlade - { - SBlade( ); - - // geometry - float m_afPos[3]; - float m_afNormal[3]; - float m_fSize; - unsigned char m_ucWhichTexture; - - // wind - float m_fNoise; - float m_fThrow; - - // color - float m_afBottomColor[3]; - float m_afTopColor[3]; - }; - - - /////////////////////////////////////////////////////////////////////// - // struct SRegion - - struct SRegion - { - SRegion( ); - - // dimensions - float m_afCenter[3]; - float m_afMin[3]; - float m_afMax[3]; - - // culling - bool m_bCulled; - float m_fCullingRadius; - - // grass/brush blades - std::vector m_vBlades; -// CIdvVertexBuffer* m_pVertexBuffer; - CGraphicVertexBuffer m_VertexBuffer; - }; - - void DeleteRegions(void); - const SRegion* GetRegions(unsigned int& uiNumRegions); - bool ParseBsfFile(const char* pFilename, unsigned int nNumBlades, unsigned int uiRows, unsigned int uiCols, float fCollisionDistance = 0.0f); - bool CustomPlacement(unsigned int uiRows, unsigned int uiCols); - - ////////////////////////////////////////////////////////////////////////// - // Utility -static void RotateAxisFromIdentity(D3DXMATRIX * pMat, const float & c_fAngle, const D3DXVECTOR3 & c_rv3Axis); - - /////////////////////////////////////////////////////////////////////// - // Geometry - -static const float* GetUnitBillboard(void) { return m_afUnitBillboard; } - - - /////////////////////////////////////////////////////////////////////// - // LOD - -static void GetLodParams(float& fFarDistance, float& fTransitionLength); -static void SetLodParams(float fFarDistance, float fTransitionLength); - - - /////////////////////////////////////////////////////////////////////// - // Culling - - bool AllRegionsAreCulled(void) const { return m_bAllRegionsCulled; } - void Cull(void); - - - /////////////////////////////////////////////////////////////////////// - // Wind - -static void SetWindDirection(const float* pWindDir); -static const float* GetWindDirection(void); - - - /////////////////////////////////////////////////////////////////////// - // Camera - -static const float* GetCameraPos(void); -static void SetCamera(const float* pPosition, const double* pModelviewMatrix); -static void SetPerspective(float fAspectRatio, float fFieldOfView); - - - /////////////////////////////////////////////////////////////////////// - // Terrain hugging - -virtual float Color(float fX, float fY, const float* pNormal, float* pTopColor, float* pBottomColor) const { return 0.0f; } -virtual float Height(float fX, float fY, float* pNormal) const { return 0.0f; } - -protected: - - void CreateRegions(const std::vector& vSceneBlades, float fCollisionDistance = 0.0f); -static void ComputeFrustum(void); -static void ComputeUnitBillboard(void); - void ConvertCoordsToCell(const float* pCoords, int* pGridCoords) const; - unsigned int GetRegionIndex(unsigned int uiRow, unsigned int uiCol) const { return uiRow * m_nNumRegionCols + uiCol; } -static bool OutsideFrustum(SRegion* pRegion); - - // general -static float m_fLodFarDistance; -static float m_fLodTransitionLength; -static float m_afUnitBillboard[12]; -static float m_afWindDir[4]; - - // regions - int m_nNumRegions; - int m_nNumRegionCols; - int m_nNumRegionRows; - SRegion* m_pRegions; - - // camera -static float m_afCameraOut[3]; -static float m_afCameraRight[3]; -static float m_afCameraUp[3]; -static float m_afCameraPos[3]; -static float m_fFieldOfView; -static float m_fAspectRatio; - - // culling -static float m_afFrustumBox[6]; -static float m_afFrustumMin[2]; -static float m_afFrustumMax[2]; -static float m_afFrustumPlanes[5][4]; - float m_afBoundingBox[6]; - bool m_bAllRegionsCulled; -}; - -extern float VecInterpolate(float fStart, float fEnd, float fPercent); -#endif // USE_SPEEDGRASS \ No newline at end of file diff --git a/src/SpeedTreeLib/SpeedGrassWrapper.cpp b/src/SpeedTreeLib/SpeedGrassWrapper.cpp deleted file mode 100644 index dd9ede60..00000000 --- a/src/SpeedTreeLib/SpeedGrassWrapper.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassWrapper Class -// -// (c) 2003 IDV, Inc. -// -// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION *** -// -// This software is supplied under the terms of a license agreement or -// nondisclosure agreement with Interactive Data Visualization and may -// not be copied or disclosed except in accordance with the terms of -// that agreement. -// -// Copyright (c) 2001-2003 IDV, Inc. -// All Rights Reserved. -// -// IDV, Inc. -// 1233 Washington St. Suite 610 -// Columbia, SC 29201 -// Voice: (803) 799-1699 -// Fax: (803) 931-0320 -// Web: http://www.idvinc.com - -#include "StdAfx.h" - -#include -#include -#include -//#include "../Common Source/extgl.h" -//#include "SpeedGrassWrapper.h" -//#include "Scene.h" -//#include "../Common Source/nv_dds.h" -//#include "../Common Source/Random.h" -//#include "TextureLayers.h" - -using namespace std; - -#ifdef USE_SPEEDGRASS - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassWrapper::CSpeedGrassWrapper - -CSpeedGrassWrapper::CSpeedGrassWrapper() : m_pMapOutdoor(NULL), m_lpD3DTexure8(NULL)//m_uiTexture(0) -{ -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassWrapper::~CSpeedGrassWrapper - -CSpeedGrassWrapper::~CSpeedGrassWrapper( ) -{ -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassWrapper::Draw - -int CSpeedGrassWrapper::Draw(float fDensity) -{ - int nTriangleCount = 0; - -// // determine which regions are visible -// Cull( ); -// -// // setup opengl state -// glPushAttrib(GL_ENABLE_BIT); -// glDisable(GL_CULL_FACE); -// glDisable(GL_BLEND); -// -// glEnable(GL_TEXTURE_2D); -// glBindTexture(GL_TEXTURE_2D, m_uiTexture); -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); -// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); -// -// glEnable(GL_ALPHA_TEST); -// glAlphaFunc(GL_GREATER, 0.4f); -// glDisable(GL_LIGHTING); -// -// unsigned int uiCount = 0; -// unsigned int uiNumRegions = 0; -// const SRegion* pRegions = GetRegions(uiNumRegions); -// -// // setup for vertex buffer rendering (enable client buffers) -// CIdvVertexBuffer::Enable(true); -// if (uiNumRegions > 0) -// pRegions[0].m_pVertexBuffer->EnableClientStates( ); -// -// // run through the regions and render those that aren't culled -// for (unsigned int i = 0; i < uiNumRegions; ++i) -// { -// if (!pRegions[i].m_bCulled) -// { -// pRegions[i].m_pVertexBuffer->Bind( ); -// unsigned int uiNumBlades = int(fDensity * pRegions[i].m_vBlades.size( )); -// glDrawArrays(GL_QUADS, 0, uiNumBlades * 4); -// nTriangleCount += uiNumBlades * 2; -// } -// } -// -// // disable client buffers -// if (uiNumRegions > 0) -// pRegions[0].m_pVertexBuffer->DisableClientStates( ); -// CIdvVertexBuffer::Disable(true); -// -// // restore opengl state -// glPopAttrib( ); - - return nTriangleCount; -} - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassWrapper::InitFromBsfFile - -bool CSpeedGrassWrapper::InitFromBsfFile(const char* pFilename, - unsigned int nNumBlades, - unsigned int uiRows, - unsigned int uiCols, - float fCollisionDistance) -{ - bool bSuccess = false; - - if (pFilename) - { - // use SpeedGrass's built-in parse function - if (ParseBsfFile(pFilename, nNumBlades, uiRows, uiCols, fCollisionDistance)) - bSuccess = true; - } - InitGraphics( ); - - return bSuccess; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassWrapper::Color - -float CSpeedGrassWrapper::Color(float fX, float fY, const float* pNormal, float* pTopColor, float* pBottomColor) const -{ - const float c_fColorAdjust = 0.3f; // controls how much the color of the top vertices of each grass blade can vary - const float c_fColorThrow = 1.0f; // controls how much the r, g, and b components can vary - const float c_fColorRandomness = 0.01f; // controls how much the r, g, and b components can vary - const float c_TopLight = 0.75f; - - float afLowColor[4] = { 0.0f }, afHighColor[4] = { 0.0f }; - if (m_pMapOutdoor->GetBrushColor(fX, fY, afLowColor, afHighColor)) - { - pBottomColor[0] = afLowColor[2]; - pBottomColor[1] = afLowColor[1]; - pBottomColor[2] = afLowColor[0]; - - float fColorThrow = GetRandom(0.0f, c_fColorThrow); - pTopColor[0] = VecInterpolate(pBottomColor[0], afHighColor[2], fColorThrow) + GetRandom(-c_fColorRandomness, c_fColorRandomness); - pTopColor[1] = VecInterpolate(pBottomColor[1], afHighColor[1], fColorThrow) + GetRandom(-c_fColorRandomness, c_fColorRandomness); - pTopColor[2] = VecInterpolate(pBottomColor[2], afHighColor[0], fColorThrow) + GetRandom(-c_fColorRandomness, c_fColorRandomness); - - float fLargest = pTopColor[0]; - if (pTopColor[1] > fLargest) - fLargest = pTopColor[1]; - if (pTopColor[2] > fLargest) - fLargest = pTopColor[2]; - if (fLargest > 1.0f) - { - pTopColor[0] /= fLargest; - pTopColor[1] /= fLargest; - pTopColor[2] /= fLargest; - } - pTopColor[0] = max(0.0f, pTopColor[0]); - pTopColor[1] = max(0.0f, pTopColor[1]); - pTopColor[2] = max(0.0f, pTopColor[2]); - } - - return afLowColor[3]; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassWrapper::Height - -float CSpeedGrassWrapper::Height(float fX, float fY, float* pNormal) const -{ - float fHeight = 0.0f; - float afPos[3] = { fX, fY, 0.0f }; - fHeight = m_pMapOutdoor->GetHeight(afPos); - - pNormal[0] = 0.0f; - pNormal[1] = 0.0f; - pNormal[2] = 1.0f; - - return fHeight; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassWrapper::InitGraphics - -void CSpeedGrassWrapper::InitGraphics(void) -{ - // load texture -// m_uiTexture = LoadDDS((c_strDataPath + string("brush_2.dds")).c_str( )); - CGraphicImage * pImage = (CGraphicImage *) CResourceManager::Instance().GetResourcePointer("D:/ymir work/special/brush_2.dds"); - m_GrassImageInstance.SetImagePointer(pImage); - m_lpD3DTexure8 = m_GrassImageInstance.GetTexturePointer()->GetD3DTexture(); - - // prepare static vertex buffers - for (int i = 0; i < m_nNumRegions; ++i) - { - SRegion* pRegion = m_pRegions + i; - -// pRegion->m_pVertexBuffer = new CIdvVertexBuffer; - - // setup up temporary buffer to copy later - const int c_nNumCorners = 4; - unsigned int uiNumBlades = pRegion->m_vBlades.size( ); - unsigned int uiBufferSize = uiNumBlades * c_nNumCorners * c_nGrassVertexTotalSize; - unsigned char* pBuffer = new unsigned char[uiBufferSize]; - - // setup initial pointers for individual attribute copying - float* pTexCoords0 = reinterpret_cast(pBuffer + 0); - float* pTexCoords1 = reinterpret_cast(pTexCoords0 + c_nGrassVertexTexture0Size * uiNumBlades * c_nNumCorners / sizeof(float)); - unsigned char* pColors = (unsigned char*) pTexCoords1 + c_nGrassVertexTexture1Size * uiNumBlades * c_nNumCorners; - float* pPositions = reinterpret_cast(pColors + c_nGrassVertexColorSize * uiNumBlades * c_nNumCorners); - - for (vector::const_iterator iBlade = pRegion->m_vBlades.begin( ); iBlade != pRegion->m_vBlades.end( ); ++iBlade) - { - float fS1 = float(iBlade->m_ucWhichTexture) / c_nNumBladeMaps; - float fS2 = float(iBlade->m_ucWhichTexture + 1) / c_nNumBladeMaps; - - for (int nCorner = 0; nCorner < c_nNumCorners; ++nCorner) - { - // texcoord 0 - switch (nCorner) - { - case 0: - pTexCoords0[0] = fS2; - pTexCoords0[1] = 1.0f; - break; - case 1: - pTexCoords0[0] = fS1; - pTexCoords0[1] = 1.0f; - break; - case 2: - pTexCoords0[0] = fS1; - pTexCoords0[1] = 0.0f; - break; - case 3: - pTexCoords0[0] = fS2; - pTexCoords0[1] = 0.0f; - break; - default: - assert(false); - } - pTexCoords0 += c_nGrassVertexTexture0Size / sizeof(float); - - // texcoord 1 - switch (nCorner) - { - case 0: - pTexCoords1[0] = c_nShaderGrassBillboard; - pTexCoords1[2] = iBlade->m_fThrow; - break; - case 1: - pTexCoords1[0] = c_nShaderGrassBillboard + 1; - pTexCoords1[2] = iBlade->m_fThrow; - break; - case 2: - pTexCoords1[0] = c_nShaderGrassBillboard + 2; - pTexCoords1[2] = 0.0f; - break; - case 3: - pTexCoords1[0] = c_nShaderGrassBillboard + 3; - pTexCoords1[2] = 0.0f; - break; - default: - assert(false); - } - // same for all corners - pTexCoords1[1] = iBlade->m_fSize; - pTexCoords1[3] = iBlade->m_fNoise; - pTexCoords1 += c_nGrassVertexTexture1Size / sizeof(float); - - // color - unsigned long ulColor = 0; - if (nCorner == 0 || nCorner == 1) - ulColor = (int(iBlade->m_afTopColor[0] * 255.0f) << 0) + - (int(iBlade->m_afTopColor[1] * 255.0f) << 8) + - (int(iBlade->m_afTopColor[2] * 255.0f) << 16) + - 0xff000000; - else - ulColor = (int(iBlade->m_afBottomColor[0] * 255.0f) << 0) + - (int(iBlade->m_afBottomColor[1] * 255.0f) << 8) + - (int(iBlade->m_afBottomColor[2] * 255.0f) << 16) + - 0xff000000; - memcpy(pColors, &ulColor, c_nGrassVertexColorSize); - pColors += c_nGrassVertexColorSize; - - // position - memcpy(pPositions, iBlade->m_afPos, c_nGrassVertexPositionSize); - pPositions += c_nGrassVertexPositionSize / sizeof(float); - } - } - -// assert((unsigned char*) pTexCoords0 - pBuffer == c_nGrassVertexTexture0Size * uiNumBlades * c_nNumCorners); -// assert(pTexCoords1 - pTexCoords0 == (c_nGrassVertexTexture1Size * uiNumBlades * c_nNumCorners) / sizeof(float)); -// assert(pColors - (unsigned char*) pTexCoords1 == c_nGrassVertexColorSize * uiNumBlades * c_nNumCorners); -// assert((unsigned char*) pPositions - pColors == c_nGrassVertexPositionSize * uiNumBlades * c_nNumCorners); - -// pRegion->m_pVertexBuffer->SetBuffer(pBuffer, uiBufferSize, true); -// pRegion->m_pVertexBuffer->SetStride(CIdvVertexBuffer::VERTEX_TEXCOORD0, 2, GL_FLOAT, 0, 0); -// pRegion->m_pVertexBuffer->SetStride(CIdvVertexBuffer::VERTEX_TEXCOORD1, 4, GL_FLOAT, 0, (unsigned char*) pTexCoords0 - pBuffer); -// pRegion->m_pVertexBuffer->SetStride(CIdvVertexBuffer::VERTEX_COLOR, 4, GL_UNSIGNED_BYTE, 0, (unsigned char*) pTexCoords1 - pBuffer); -// pRegion->m_pVertexBuffer->SetStride(CIdvVertexBuffer::VERTEX_POSITION, 3, GL_FLOAT, 0, pColors - pBuffer); - - DWORD dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; -// pRegion->m_VertexBuffer.Create(); - - delete[] pBuffer; - } -} - -#endif // USE_SPEEDGRASS - diff --git a/src/SpeedTreeLib/SpeedGrassWrapper.h b/src/SpeedTreeLib/SpeedGrassWrapper.h deleted file mode 100644 index 5bcf73db..00000000 --- a/src/SpeedTreeLib/SpeedGrassWrapper.h +++ /dev/null @@ -1,64 +0,0 @@ -/////////////////////////////////////////////////////////////////////// -// CSpeedGrassWrapper Class -// -// (c) 2003 IDV, Inc. -// -// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION *** -// -// This software is supplied under the terms of a license agreement or -// nondisclosure agreement with Interactive Data Visualization and may -// not be copied or disclosed except in accordance with the terms of -// that agreement. -// -// Copyright (c) 2001-2003 IDV, Inc. -// All Rights Reserved. -// -// IDV, Inc. -// 1233 Washington St. Suite 610 -// Columbia, SC 29201 -// Voice: (803) 799-1699 -// Fax: (803) 931-0320 -// Web: http://www.idvinc.com - - -#pragma once -//#include "SpeedGrassRT.h" -#ifdef USE_SPEEDGRASS -//#include "../Common Source/IdvVertexBuffer.h" -//#include - -// forward reference -//class CScene; -class CMapOutdoor; - - -/////////////////////////////////////////////////////////////////////// -// class CSpeedGrassWrapper declaration - -class CSpeedGrassWrapper : public CSpeedGrassRT -{ -public: - CSpeedGrassWrapper( ); - virtual ~CSpeedGrassWrapper( ); - - void SetMapOutdoor(CMapOutdoor* pMapOutdoor) { m_pMapOutdoor = pMapOutdoor; } - int Draw(float fDensity); - bool InitFromBsfFile(const char* pFilename, - unsigned int nNumBlades, - unsigned int uiRows, - unsigned int uiCols, - float fCollisionDistance); - -private: -virtual float Color(float fX, float fY, const float* pNormal, float* pTopColor, float* pBottomColor) const; -virtual float Height(float fX, float fY, float* pNormal) const; - void InitGraphics(void); - - CMapOutdoor * m_pMapOutdoor; - - LPDIRECT3DTEXTURE8 m_lpD3DTexure8; - - CGraphicImageInstance m_GrassImageInstance; -}; - -#endif // USE_SPEEDGRASS diff --git a/src/SpeedTreeLib/SpeedTreeConfig.h b/src/SpeedTreeLib/SpeedTreeConfig.h index 9a0f86f3..548230da 100644 --- a/src/SpeedTreeLib/SpeedTreeConfig.h +++ b/src/SpeedTreeLib/SpeedTreeConfig.h @@ -22,15 +22,9 @@ #pragma once -const int c_nNumWindMatrices = 4; -const int c_nNumInstancesPerModel = 10; -const float c_fForestSize = 200.0f; -const float c_fSpacingTolerance = 30.0f; -const int c_nMaxPlacementIterations = 500; -const int c_nDefaultAlphaTestValue = 84; -const float c_fNearLodFactor = 2.0f; -const float c_fFarLodFactor = 9.0f; -const float c_fBenchmarkPeriod = 1.0f; +const int c_nNumWindMatrices = 40; +const float c_fNearLodFactor = 1000000000.0f; +const float c_fFarLodFactor = 50000000000.0f; // vertex shader constant locations const int c_nVertexShader_LeafLightingAdjustment = 70; @@ -42,14 +36,6 @@ const int c_nVertexShader_WindMatrices = 54; const int c_nVertexShader_LeafTables = 4; const int c_nVertexShader_Fog = 85; -// lighting -const float c_afLightPosition[4] = { -0.707f, 0.0f, 0.707f, 0.0f }; -const float c_afLightAmbient[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; -const float c_afLightDiffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; -const float c_afLightSpecular[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; -const float c_afLightGlobalAmbient[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; - - // setup lighting (enable ONE of the two below) #define WRAPPER_USE_STATIC_LIGHTING //#define WRAPPER_USE_DYNAMIC_LIGHTING @@ -91,8 +77,8 @@ const float c_afLightGlobalAmbient[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; #endif // loading from STF or clones/instances? (enable ONE of the two below) -//#define WRAPPER_FOREST_FROM_STF -#define WRAPPER_FOREST_FROM_INSTANCES +#define WRAPPER_FOREST_FROM_STF +//#define WRAPPER_FOREST_FROM_INSTANCES #if defined WRAPPER_FOREST_FROM_STF && defined WRAPPER_FOREST_FROM_INSTANCES #error Please define exactly one loading mechanism @@ -103,18 +89,18 @@ const float c_afLightGlobalAmbient[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; //#define WRAPPER_RENDER_HORIZONTAL_BILLBOARD // render self-shadows -#define WRAPPER_RENDER_SELF_SHADOWS +//#define WRAPPER_RENDER_SELF_SHADOWS // use fog #define WRAPPER_USE_FOG // derived constants -#ifdef WRAPPER_USE_GPU_WIND - #define BRANCHES_USE_SHADERS - #define FRONDS_USE_SHADERS - #define LEAVES_USE_SHADERS -#endif - -#ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT - #define LEAVES_USE_SHADERS -#endif +//#ifdef WRAPPER_USE_GPU_WIND +// #define BRANCHES_USE_SHADERS +// #define FRONDS_USE_SHADERS +// #define LEAVES_USE_SHADERS +//#endif +// +//#ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT +// #define LEAVES_USE_SHADERS +//#endif diff --git a/src/SpeedTreeLib/SpeedTreeForest.cpp b/src/SpeedTreeLib/SpeedTreeForest.cpp index b7342de8..6512770b 100644 --- a/src/SpeedTreeLib/SpeedTreeForest.cpp +++ b/src/SpeedTreeLib/SpeedTreeForest.cpp @@ -87,6 +87,7 @@ BOOL CSpeedTreeForest::GetMainTree(DWORD dwCRC, CSpeedTreeWrapper ** ppMainTree, if (!pTree->LoadTree(c_pszFileName, (const BYTE *) c_pvData, file.Size())) { delete pTree; + pTree = nullptr; return FALSE; } @@ -230,63 +231,12 @@ void CSpeedTreeForest::SetupWindMatrices(float fTimeInSecs) afMatrix[9] = -fSinX; afMatrix[10] = fCosX * fCosY; afMatrix[15] = 1.0f; - - #ifdef WRAPPER_USE_CPU_WIND - CSpeedTreeRT::SetWindMatrix(j, afMatrix); - #endif - - #ifdef WRAPPER_USE_GPU_WIND - // graphics API specific - UploadWindMatrix(c_nVertexShader_WindMatrices + j * 4, afMatrix); - #endif } // track wind strength fOldStrength = m_fWindStrength; } - -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeForest::SetLodLimits -/* -void CSpeedTreeForest::SetLodLimits(void) -{ - // find tallest tree - float fTallest = -1.0f; - - TTreeMap::iterator itor = m_pMainTreeMap.begin(); - UINT uiCount; - - while (itor != m_pMainTreeMap.end()) - { - CSpeedTreeWrapper * pMainTree = (itor++)->second; - CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount); - - float fHeight; - fHeight = pMainTree->GetBoundingBox()[5] - pMainTree->GetBoundingBox()[0]; - fTallest = __max(fHeight, fTallest); - - for (UINT i = 0; i < uiCount; ++i) - { - fHeight = ppInstances[i]->GetBoundingBox()[5] - ppInstances[i]->GetBoundingBox()[0]; - fTallest = __max(fHeight, fTallest); - } - } - - itor = m_pMainTreeMap.begin(); - - while (itor != m_pMainTreeMap.end()) - { - CSpeedTreeWrapper * pMainTree = (itor++)->second; - CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount); - - pMainTree->GetSpeedTree()->SetLodLimits(fTallest * c_fNearLodFactor, fTallest * c_fFarLodFactor); - - for (UINT i = 0; i < uiCount; ++i) - ppInstances[i]->GetSpeedTree()->SetLodLimits(fTallest * c_fNearLodFactor, fTallest * c_fFarLodFactor); - } -} -*/ void CSpeedTreeForest::SetLight(const float * afDirection, const float * afAmbient, const float * afDiffuse) { m_afLighting[0] = afDirection[0]; diff --git a/src/SpeedTreeLib/SpeedTreeForest.h b/src/SpeedTreeLib/SpeedTreeForest.h index e4bd382a..f800777f 100644 --- a/src/SpeedTreeLib/SpeedTreeForest.h +++ b/src/SpeedTreeLib/SpeedTreeForest.h @@ -32,7 +32,7 @@ /////////////////////////////////////////////////////////////////////// // Include Files -#include +#include #include "SpeedTreeWrapper.h" #include @@ -52,7 +52,7 @@ /////////////////////////////////////////////////////////////////////// // class CSpeedTreeForest declaration -class CSpeedTreeForest +class CSpeedTreeForest : public CSingleton { public: typedef std::map TTreeMap; @@ -71,8 +71,6 @@ class CSpeedTreeForest CSpeedTreeWrapper * CreateInstance(float x, float y, float z, DWORD dwTreeCRC, const char * c_pszTreeName); void DeleteInstance(CSpeedTreeWrapper * pTree); - //void SetLodLimits(void); - void UpdateSystem(float fCurrentTime); void Clear(); @@ -90,8 +88,10 @@ class CSpeedTreeForest // overridden by specific graphics API virtual void UploadWindMatrix(unsigned int uiLocation, const float* pMatrix) const = 0; - virtual void Render(unsigned long ulRenderBitVector) = 0; - + virtual void Render(unsigned long ulRenderBitVector = Forest_RenderAll) = 0; + virtual bool SetRenderingDevice() = 0; + virtual void UpdateCompundMatrix(const D3DXVECTOR3& c_rEyeVec, const D3DXMATRIX& c_rmatView, const D3DXMATRIX& c_rmatProj) = 0; + protected: TTreeMap m_pMainTreeMap; diff --git a/src/SpeedTreeLib/SpeedTreeForestDirectX8.cpp b/src/SpeedTreeLib/SpeedTreeForestDirectX8.cpp deleted file mode 100644 index 1b2e3a15..00000000 --- a/src/SpeedTreeLib/SpeedTreeForestDirectX8.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeForestDirectX8 Class -// -// (c) 2003 IDV, Inc. -// -// This class is provided to illustrate one way to incorporate -// SpeedTreeRT into an OpenGL application. All of the SpeedTreeRT -// calls that must be made on a per tree basis are done by this class. -// Calls that apply to all trees (i.e. static SpeedTreeRT functions) -// are made in the functions in main.cpp. -// -// -// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION *** -// -// This software is supplied under the terms of a license agreement or -// nondisclosure agreement with Interactive Data Visualization and may -// not be copied or disclosed except in accordance with the terms of -// that agreement. -// -// Copyright (c) 2001-2003 IDV, Inc. -// All Rights Reserved. -// -// IDV, Inc. -// 1233 Washington St. Suite 610 -// Columbia, SC 29201 -// Voice: (803) 799-1699 -// Fax: (803) 931-0320 -// Web: http://www.idvinc.com - -#include "StdAfx.h" - -#include -#include -#include -#include - -#include "../eterBase/Timer.h" -#include "../eterlib/StateManager.h" -#include "../eterlib/Camera.h" - -#include "SpeedTreeForestDirectX8.h" -#include "SpeedTreeConfig.h" -#include "VertexShaders.h" - -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeForestDirectX8::CSpeedTreeForestDirectX8 - -CSpeedTreeForestDirectX8::CSpeedTreeForestDirectX8() : m_dwBranchVertexShader(0), m_dwLeafVertexShader(0) -{ -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeForestDirectX8::~CSpeedTreeForestDirectX8 - -CSpeedTreeForestDirectX8::~CSpeedTreeForestDirectX8() -{ -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeForestDirectX8::InitVertexShaders -bool CSpeedTreeForestDirectX8::InitVertexShaders(void) -{ - NANOBEGIN - // load the vertex shaders - if (!m_dwBranchVertexShader) - m_dwBranchVertexShader = LoadBranchShader(m_pDx); - - if (!m_dwLeafVertexShader) - m_dwLeafVertexShader = LoadLeafShader(m_pDx); - - if (m_dwBranchVertexShader && m_dwLeafVertexShader) - { - CSpeedTreeWrapper::SetVertexShaders(m_dwBranchVertexShader, m_dwLeafVertexShader); - return true; - } - - NANOEND - return false; -} - -bool CSpeedTreeForestDirectX8::SetRenderingDevice(LPDIRECT3DDEVICE8 lpDevice) -{ - m_pDx = lpDevice; - - if (!InitVertexShaders()) - return false; - - const float c_afLightPosition[4] = { -0.707f, -0.300f, 0.707f, 0.0f }; - const float c_afLightAmbient[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; - const float c_afLightDiffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - const float c_afLightSpecular[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; - - float afLight1[] = - { - c_afLightPosition[0], c_afLightPosition[1], c_afLightPosition[2], // pos - c_afLightDiffuse[0], c_afLightDiffuse[1], c_afLightDiffuse[2], // diffuse - c_afLightAmbient[0], c_afLightAmbient[1], c_afLightAmbient[2], // ambient - c_afLightSpecular[0], c_afLightSpecular[1], c_afLightSpecular[2], // specular - c_afLightPosition[3], // directional flag - 1.0f, 0.0f, 0.0f // attenuation (constant, linear, quadratic) - }; - - CSpeedTreeRT::SetNumWindMatrices(c_nNumWindMatrices); - - CSpeedTreeRT::SetLightAttributes(0, afLight1); - CSpeedTreeRT::SetLightState(0, true); - return true; -} - -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeForestDirectX8::UploadWindMatrix - -void CSpeedTreeForestDirectX8::UploadWindMatrix(UINT uiLocation, const float* pMatrix) const -{ - STATEMANAGER.SetVertexShaderConstant(uiLocation, pMatrix, 4); -} - -void CSpeedTreeForestDirectX8::UpdateCompundMatrix(const D3DXVECTOR3 & c_rEyeVec, const D3DXMATRIX & c_rmatView, const D3DXMATRIX & c_rmatProj) -{ - // setup composite matrix for shader - D3DXMATRIX matBlend; - D3DXMatrixIdentity(&matBlend); - - D3DXMATRIX matBlendShader; - D3DXMatrixMultiply(&matBlendShader, &c_rmatView, &c_rmatProj); - - float afDirection[3]; - afDirection[0] = matBlendShader.m[0][2]; - afDirection[1] = matBlendShader.m[1][2]; - afDirection[2] = matBlendShader.m[2][2]; - CSpeedTreeRT::SetCamera(c_rEyeVec, afDirection); - - D3DXMatrixTranspose(&matBlendShader, &matBlendShader); - STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_CompoundMatrix, &matBlendShader, 4); -} - -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeForestDirectX8::Render - -void CSpeedTreeForestDirectX8::Render(unsigned long ulRenderBitVector) -{ - UpdateSystem(CTimer::Instance().GetCurrentSecond()); - - if (m_pMainTreeMap.empty()) - return; - - if (!(ulRenderBitVector & Forest_RenderToShadow) && !(ulRenderBitVector & Forest_RenderToMiniMap)) - UpdateCompundMatrix(CCameraManager::Instance().GetCurrentCamera()->GetEye(), ms_matView, ms_matProj); - - DWORD dwLightState = STATEMANAGER.GetRenderState(D3DRS_LIGHTING); - DWORD dwColorVertexState = STATEMANAGER.GetRenderState(D3DRS_COLORVERTEX); - DWORD dwFogVertexMode = STATEMANAGER.GetRenderState(D3DRS_FOGVERTEXMODE); - -#ifdef WRAPPER_USE_DYNAMIC_LIGHTING - STATEMANAGER.SetRenderState(D3DRS_LIGHTING, TRUE); -#else - STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE); - STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, TRUE); -#endif - - TTreeMap::iterator itor; - UINT uiCount; - - itor = m_pMainTreeMap.begin(); - - while (itor != m_pMainTreeMap.end()) - { - CSpeedTreeWrapper * pMainTree = (itor++)->second; - CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount); - - for (UINT i = 0; i < uiCount; ++i) - { - ppInstances[i]->Advance(); - } - } - - STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_Light, m_afLighting, 3); - STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_Fog, m_afFog, 1); - - if (ulRenderBitVector & Forest_RenderToShadow) - { - //STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - } - else - { - STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); - - STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE); - STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT); - STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - } - - STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, TRUE); - STATEMANAGER.SaveRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); - STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_CW); - - // set up fog if it is enabled - if (STATEMANAGER.GetRenderState(D3DRS_FOGENABLE)) - { - #ifdef WRAPPER_USE_GPU_WIND - STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_NONE); // GPU needs to work on all cards - #endif - } - - // choose fixed function pipeline or custom shader for fronds and branches - STATEMANAGER.SetVertexShader(m_dwBranchVertexShader); - - // render branches - if (ulRenderBitVector & Forest_RenderBranches) - { - itor = m_pMainTreeMap.begin(); - - while (itor != m_pMainTreeMap.end()) - { - CSpeedTreeWrapper * pMainTree = (itor++)->second; - CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount); - - pMainTree->SetupBranchForTreeType(); - - for (UINT i = 0; i < uiCount; ++i) - if (ppInstances[i]->isShow()) - ppInstances[i]->RenderBranches(); - } - } - - // set render states - STATEMANAGER.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - - // render fronds - if (ulRenderBitVector & Forest_RenderFronds) - { - itor = m_pMainTreeMap.begin(); - - while (itor != m_pMainTreeMap.end()) - { - CSpeedTreeWrapper * pMainTree = (itor++)->second; - CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount); - - pMainTree->SetupFrondForTreeType(); - - for (UINT i = 0; i < uiCount; ++i) - if (ppInstances[i]->isShow()) - ppInstances[i]->RenderFronds(); - } - } - - // render leaves - if (ulRenderBitVector & Forest_RenderLeaves) - { - STATEMANAGER.SetVertexShader(m_dwLeafVertexShader); - - if (STATEMANAGER.GetRenderState(D3DRS_FOGENABLE)) - { - #if defined WRAPPER_USE_GPU_WIND || defined WRAPPER_USE_GPU_LEAF_PLACEMENT - STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_NONE); - #endif - } - - if (ulRenderBitVector & Forest_RenderToShadow || ulRenderBitVector & Forest_RenderToMiniMap) - { - STATEMANAGER.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL); - STATEMANAGER.SaveRenderState(D3DRS_ALPHAREF, 0x00000000); - } - - itor = m_pMainTreeMap.begin(); - - while (itor != m_pMainTreeMap.end()) - { - CSpeedTreeWrapper * pMainTree = (itor++)->second; - CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount); - - pMainTree->SetupLeafForTreeType(); - - for (UINT i = 0; i < uiCount; ++i) - if (ppInstances[i]->isShow()) - ppInstances[i]->RenderLeaves(); - } - - while (itor != m_pMainTreeMap.end()) - (itor++)->second->EndLeafForTreeType(); - - if (ulRenderBitVector & Forest_RenderToShadow || ulRenderBitVector & Forest_RenderToMiniMap) - { - STATEMANAGER.SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); - STATEMANAGER.RestoreRenderState(D3DRS_ALPHAREF); - } - } - - // render billboards - #ifndef WRAPPER_NO_BILLBOARD_MODE - if (ulRenderBitVector & Forest_RenderBillboards) - { - STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE); - STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, FALSE); - - itor = m_pMainTreeMap.begin(); - - while (itor != m_pMainTreeMap.end()) - { - CSpeedTreeWrapper * pMainTree = (itor++)->second; - CSpeedTreeWrapper ** ppInstances = pMainTree->GetInstances(uiCount); - - pMainTree->SetupBranchForTreeType(); - - for (UINT i = 0; i < uiCount; ++i) - if (ppInstances[i]->isShow()) - ppInstances[i]->RenderBillboards(); - } - } - #endif - - STATEMANAGER.SetRenderState(D3DRS_LIGHTING, dwLightState); - STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, dwColorVertexState); - STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, dwFogVertexMode); - - // ¼¿ÇÁ¼¨µµ¿ì·Î ¾²´Â TextureStage 1ÀÇ COLOROP¿Í ALPHAOP¸¦ ²¨Áà¾ß ´ÙÀ½ ·»´õ¸µ ÇÒ ³ðµéÀÌ - // Á¦´ë·Î ³ª¿Â´Ù. (¾È±×·¯¸é °Ë°Ô ³ª¿Ã °¡´É¼ºÀÌ..) - if (!(ulRenderBitVector & Forest_RenderToShadow)) - { - STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); - } - - STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE); - STATEMANAGER.RestoreRenderState(D3DRS_ALPHAFUNC); - STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE); -} - diff --git a/src/SpeedTreeLib/SpeedTreeForestDirectX8.h b/src/SpeedTreeLib/SpeedTreeForestDirectX8.h deleted file mode 100644 index 186d00d9..00000000 --- a/src/SpeedTreeLib/SpeedTreeForestDirectX8.h +++ /dev/null @@ -1,64 +0,0 @@ -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeForestOpenGL Class -// -// (c) 2003 IDV, Inc. -// -// This class is provided to illustrate one way to incorporate -// SpeedTreeRT into an OpenGL application. All of the SpeedTreeRT -// calls that must be made on a per tree basis are done by this class. -// Calls that apply to all trees (i.e. static SpeedTreeRT functions) -// are made in the functions in main.cpp. -// -// -// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION *** -// -// This software is supplied under the terms of a license agreement or -// nondisclosure agreement with Interactive Data Visualization and may -// not be copied or disclosed except in accordance with the terms of -// that agreement. -// -// Copyright (c) 2001-2003 IDV, Inc. -// All Rights Reserved. -// -// IDV, Inc. -// 1233 Washington St. Suite 610 -// Columbia, SC 29201 -// Voice: (803) 799-1699 -// Fax: (803) 931-0320 -// Web: http://www.idvinc.com - -#pragma once - - -/////////////////////////////////////////////////////////////////////// -// Include Files - -//#include -#define SPEEDTREE_DATA_FORMAT_DIRECTX - -#include "SpeedTreeForest.h" -#include "SpeedTreeMaterial.h" - -/////////////////////////////////////////////////////////////////////// -// class CSpeedTreeForestDirectX8 declaration -class CSpeedTreeForestDirectX8 : public CSpeedTreeForest, public CGraphicBase, public CSingleton -{ - public: - CSpeedTreeForestDirectX8(); - virtual ~CSpeedTreeForestDirectX8(); - - void UploadWindMatrix(unsigned int uiLocation, const float* pMatrix) const; - void UpdateCompundMatrix(const D3DXVECTOR3 & c_rEyeVec, const D3DXMATRIX & c_rmatView, const D3DXMATRIX & c_rmatProj); - - void Render(unsigned long ulRenderBitVector = Forest_RenderAll); - bool SetRenderingDevice(LPDIRECT3DDEVICE8 pDevice); - - private: - bool InitVertexShaders(); - - private: - LPDIRECT3DDEVICE8 m_pDx; // the rendering context - - DWORD m_dwBranchVertexShader; // branch/frond vertex shaders - DWORD m_dwLeafVertexShader; // leaf vertex shader -}; diff --git a/src/SpeedTreeLib/SpeedTreeLib.vcxproj b/src/SpeedTreeLib/SpeedTreeLib.vcxproj index 78c5a761..9ad8da5d 100644 --- a/src/SpeedTreeLib/SpeedTreeLib.vcxproj +++ b/src/SpeedTreeLib/SpeedTreeLib.vcxproj @@ -339,46 +339,7 @@ - - Disabled - EnableFastChecks - - - true - MaxSpeed - - - Disabled - EnableFastChecks - true - MaxSpeed - MaxSpeed - - - Size - - - - - Disabled - EnableFastChecks - - - true - MaxSpeed - - - Disabled - EnableFastChecks - true - MaxSpeed - MaxSpeed - - - Size - - - + Disabled EnableFastChecks @@ -399,26 +360,6 @@ - - Disabled - EnableFastChecks - - - true - MaxSpeed - - - Disabled - EnableFastChecks - true - MaxSpeed - MaxSpeed - - - Size - - - Disabled EnableFastChecks @@ -457,11 +398,9 @@ - - + - diff --git a/src/SpeedTreeLib/SpeedTreeLib.vcxproj.filters b/src/SpeedTreeLib/SpeedTreeLib.vcxproj.filters index b619f3e8..5e48d79a 100644 --- a/src/SpeedTreeLib/SpeedTreeLib.vcxproj.filters +++ b/src/SpeedTreeLib/SpeedTreeLib.vcxproj.filters @@ -14,24 +14,18 @@ Source Files - - Source Files - - - Source Files - Source Files - - Source Files - Source Files Source Files + + Source Files + @@ -40,21 +34,12 @@ Header Files - - Header Files - - - Header Files - Header Files Header Files - - Header Files - Header Files @@ -67,5 +52,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/src/SpeedTreeLib/SpeedTreeMaterial.h b/src/SpeedTreeLib/SpeedTreeMaterial.h index 6a8127d2..c40da088 100644 --- a/src/SpeedTreeLib/SpeedTreeMaterial.h +++ b/src/SpeedTreeLib/SpeedTreeMaterial.h @@ -30,14 +30,15 @@ #pragma once -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // Include Files -#include -#include -#include +#include +#include +#include +#include "../eterLib/StateManager.h" -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // class CSpeedTreeMaterial declaration/definiton class CSpeedTreeMaterial @@ -45,10 +46,10 @@ class CSpeedTreeMaterial public: CSpeedTreeMaterial() { - m_cMaterial.Ambient.r = m_cMaterial.Diffuse.r = m_cMaterial.Specular.r = m_cMaterial.Emissive.r = 1.0f; - m_cMaterial.Ambient.g = m_cMaterial.Diffuse.g = m_cMaterial.Specular.g = m_cMaterial.Emissive.g = 1.0f; - m_cMaterial.Ambient.b = m_cMaterial.Diffuse.b = m_cMaterial.Specular.b = m_cMaterial.Emissive.b = 1.0f; - m_cMaterial.Ambient.a = m_cMaterial.Diffuse.a = m_cMaterial.Specular.a = m_cMaterial.Emissive.a = 1.0f; + m_cMaterial.Ambient.r = m_cMaterial.Diffuse.r = m_cMaterial.Specular.r = m_cMaterial.Emissive.r = 3.0f; + m_cMaterial.Ambient.g = m_cMaterial.Diffuse.g = m_cMaterial.Specular.g = m_cMaterial.Emissive.g = 3.0f; + m_cMaterial.Ambient.b = m_cMaterial.Diffuse.b = m_cMaterial.Specular.b = m_cMaterial.Emissive.b = 3.0f; + m_cMaterial.Ambient.a = m_cMaterial.Diffuse.a = m_cMaterial.Specular.a = m_cMaterial.Emissive.a = 3.0f; m_cMaterial.Power = 5.0f; } @@ -68,12 +69,11 @@ class CSpeedTreeMaterial m_cMaterial.Power = pMaterialArray[12]; } - - D3DMATERIAL8 * Get() + + void Activate(const LPDIRECT3DDEVICE9& pDx) const { - return &m_cMaterial; + STATEMANAGER.SetMaterial(&m_cMaterial); } - - private: - D3DMATERIAL8 m_cMaterial; // the material object -}; + + D3DMATERIAL9 m_cMaterial; // the material object +}; \ No newline at end of file diff --git a/src/SpeedTreeLib/SpeedTreeWrapper.cpp b/src/SpeedTreeLib/SpeedTreeWrapper.cpp index 87eb8367..1faa7325 100644 --- a/src/SpeedTreeLib/SpeedTreeWrapper.cpp +++ b/src/SpeedTreeLib/SpeedTreeWrapper.cpp @@ -17,8 +17,8 @@ // not be copied or disclosed except in accordance with the terms of // that agreement. // -// Copyright (c) 2001-2003 IDV, Inc. -// All Rights Reserved. +// Copyright (c) 2001-2003 IDV, Inc. +// All Rights Reserved. // // IDV, Inc. // 1233 Washington St. Suite 610 @@ -28,9 +28,7 @@ // Web: http://www.idvinc.com // -#pragma warning(disable:4786) - -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // Include Files #include "StdAfx.h" @@ -44,77 +42,52 @@ #include "../eterLib/StateManager.h" #include "SpeedTreeConfig.h" -#include "SpeedTreeForestDirectX8.h" +#include "CSpeedTreeDirectX.h" #include "SpeedTreeWrapper.h" #include "VertexShaders.h" using namespace std; -DWORD CSpeedTreeWrapper::ms_dwBranchVertexShader = 0; -DWORD CSpeedTreeWrapper::ms_dwLeafVertexShader = 0; +unsigned int CSpeedTreeWrapper::m_unNumWrappersActive = 0; +LPDIRECT3DVERTEXSHADER9 CSpeedTreeWrapper::ms_lpBranchVertexShader = NULL; +LPDIRECT3DVERTEXSHADER9 CSpeedTreeWrapper::ms_lpLeafVertexShader = NULL; bool CSpeedTreeWrapper::ms_bSelfShadowOn = true; +#define AGBR2ARGB(dwColor) (dwColor & 0xff00ff00) + ((dwColor & 0x00ff0000) >> 16) + ((dwColor & 0x000000ff) << 16) -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // CSpeedTreeWrapper::CSpeedTreeWrapper CSpeedTreeWrapper::CSpeedTreeWrapper() : -m_pSpeedTree(new CSpeedTreeRT), -m_bIsInstance(false), -m_pInstanceOf(NULL), -m_pGeometryCache(NULL), -m_usNumLeafLods(0), -m_pBranchIndexCounts(NULL), -m_pBranchIndexBuffer(NULL), -m_pBranchVertexBuffer(NULL), -m_pFrondIndexCounts(NULL), -m_pFrondIndexBuffer(NULL), -m_pFrondVertexBuffer(NULL), -m_pLeafVertexBuffer(NULL), -m_pLeavesUpdatedByCpu(NULL), -m_unBranchVertexCount(0), -m_unFrondVertexCount(0), -m_pTextureInfo(NULL) + m_pSpeedTree(new CSpeedTreeRT), + m_bIsInstance(false), + m_pInstanceOf(NULL), + m_pGeometryCache(NULL), + m_usNumLeafLods(0), + m_unNumFrondLods(0), + m_pBranchIndexCounts(NULL), + m_pBranchIndexBuffer(NULL), + m_pBranchVertexBuffer(NULL), + m_pFrondIndexCounts(NULL), + m_pFrondIndexBuffers(NULL), + m_pFrondVertexBuffer(NULL), + m_pLeafVertexBuffer(NULL), + m_pLeavesUpdatedByCpu(NULL), + m_unBranchVertexCount(0), + m_unFrondVertexCount(0), + m_pTextureInfo(NULL) { // set initial position m_afPos[0] = m_afPos[1] = m_afPos[2] = 0.0f; - - m_pSpeedTree->SetWindStrength(1.0f); - m_pSpeedTree->SetLocalMatrices(0, 4); -} - -void CSpeedTreeWrapper::SetVertexShaders(DWORD dwBranchVertexShader, DWORD dwLeafVertexShader) -{ - ms_dwBranchVertexShader = dwBranchVertexShader; - ms_dwLeafVertexShader = dwLeafVertexShader; + m_unNumWrappersActive++; } void CSpeedTreeWrapper::OnRenderPCBlocker() { - if (ms_dwBranchVertexShader == 0) - { - ms_dwBranchVertexShader = LoadBranchShader(ms_lpd3dDevice); - //LogBox("Vertex Shader not assigned. You must call CSpeedTreeWrapper::SetVertexShader for this"); - } - - if (ms_dwLeafVertexShader == 0) - { - ms_dwLeafVertexShader = LoadLeafShader(ms_lpd3dDevice); - //LogBox("Vertex Shader not assigned. You must call CSpeedTreeWrapper::SetVertexShader for this"); - } - - CSpeedTreeForestDirectX8::Instance().UpdateSystem(ELTimer_GetMSec() / 1000.0f); - - // Çϳª¸¸ ·»´õ¸µ ÇÒ ¶§´Â LOD »ç¿ëÇÏÁö ¾ÊÀ½ - m_pSpeedTree->SetLodLevel(1.0f); - //Advance(); - - CSpeedTreeForestDirectX8::Instance().UpdateCompundMatrix(CCameraManager::Instance().GetCurrentCamera()->GetEye(), ms_matView, ms_matProj); - - STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT); @@ -123,190 +96,244 @@ void CSpeedTreeWrapper::OnRenderPCBlocker() DWORD dwLighting = STATEMANAGER.GetRenderState(D3DRS_LIGHTING); DWORD dwFogEnable = STATEMANAGER.GetRenderState(D3DRS_FOGENABLE); DWORD dwAlphaBlendEnable = STATEMANAGER.GetRenderState(D3DRS_ALPHABLENDENABLE); - STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE); + STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE); STATEMANAGER.SaveRenderState(D3DRS_COLORVERTEX, TRUE); - STATEMANAGER.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); - STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, TRUE); - STATEMANAGER.SaveRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); + STATEMANAGER.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); + STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, TRUE); + STATEMANAGER.SaveRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_CW); - STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE); - + STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE); + STATEMANAGER.SetFVF(D3DFVF_SPEEDTREE_BRANCH_VERTEX); + // choose fixed function pipeline or custom shader for fronds and branches - STATEMANAGER.SetVertexShader(ms_dwBranchVertexShader); - -// SetupBranchForTreeType(); + STATEMANAGER.SetVertexShader(ms_lpBranchVertexShader); { - // update the branch geometry for CPU wind -#ifdef WRAPPER_USE_CPU_WIND - m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_BranchGeometry); - - if (m_pGeometryCache->m_sBranches.m_usNumStrips > 0) - { - // update the vertex array - SFVFBranchVertex* pVertexBuffer = NULL; - m_pBranchVertexBuffer->Lock(0, 0, reinterpret_cast(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); - for (UINT i = 0; i < m_unBranchVertexCount; ++i) - { - memcpy(&(pVertexBuffer[i].m_vPosition), &(m_pGeometryCache->m_sBranches.m_pCoords[i * 3]), 3 * sizeof(float)); - } - m_pBranchVertexBuffer->Unlock(); - } -#endif - - LPDIRECT3DTEXTURE8 lpd3dTexture; - - // set texture map + LPDIRECT3DTEXTURE9 lpd3dTexture; if ((lpd3dTexture = m_BranchImageInstance.GetTextureReference().GetD3DTexture())) STATEMANAGER.SetTexture(0, lpd3dTexture); - + if (m_pGeometryCache->m_sBranches.m_usVertexCount > 0) { - // activate the branch vertex buffer STATEMANAGER.SetStreamSource(0, m_pBranchVertexBuffer, sizeof(SFVFBranchVertex)); - // set the index buffer STATEMANAGER.SetIndices(m_pBranchIndexBuffer, 0); + RenderBranches(); } } - RenderBranches(); - STATEMANAGER.SetTexture(0, m_CompositeImageInstance.GetTextureReference().GetD3DTexture()); STATEMANAGER.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - -// SetupFrondForTreeType(); { - // update the frond geometry for CPU wind -#ifdef WRAPPER_USE_CPU_WIND - m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_FrondGeometry); - if (m_pGeometryCache->m_sFronds.m_usNumStrips > 0) + if (m_pGeometryCache->m_sFronds.m_usVertexCount > 0 && + m_pGeometryCache->m_sFronds.m_nDiscreteLodLevel > -1 && + m_pFrondIndexCounts[m_pGeometryCache->m_sFronds.m_nDiscreteLodLevel] > 0) { - // update the vertex array - SFVFBranchVertex * pVertexBuffer = NULL; - m_pFrondVertexBuffer->Lock(0, 0, reinterpret_cast(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); - for (UINT i = 0; i < m_unFrondVertexCount; ++i) - { - memcpy(&(pVertexBuffer[i].m_vPosition), &(m_pGeometryCache->m_sFronds.m_pCoords[i * 3]), 3 * sizeof(float)); - } - m_pFrondVertexBuffer->Unlock(); - } -#endif - - if (!m_CompositeImageInstance.IsEmpty()) - STATEMANAGER.SetTexture(0, m_CompositeImageInstance.GetTextureReference().GetD3DTexture()); - - if (m_pGeometryCache->m_sFronds.m_usVertexCount > 0) - { - // activate the frond vertex buffer + if (!m_CompositeImageInstance.IsEmpty()) + STATEMANAGER.SetTexture(0, m_CompositeImageInstance.GetTextureReference().GetD3DTexture()); + STATEMANAGER.SetStreamSource(0, m_pFrondVertexBuffer, sizeof(SFVFBranchVertex)); - // set the index buffer - STATEMANAGER.SetIndices(m_pFrondIndexBuffer, 0); + STATEMANAGER.SetIndices(m_pFrondIndexBuffers[m_pGeometryCache->m_sFronds.m_nDiscreteLodLevel], 0); + RenderFronds(); } } - RenderFronds(); - - STATEMANAGER.SetVertexShader(ms_dwLeafVertexShader); - -// SetupLeafForTreeType(); { - // pass leaf tables to shader -#ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT - UploadLeafTables(c_nVertexShader_LeafTables); -#endif - + STATEMANAGER.SetFVF(D3DFVF_SPEEDTREE_LEAF_VERTEX); + STATEMANAGER.SetVertexShader(ms_lpLeafVertexShader); + if (!m_CompositeImageInstance.IsEmpty()) STATEMANAGER.SetTexture(0, m_CompositeImageInstance.GetTextureReference().GetD3DTexture()); + + RenderLeaves(); + EndLeafForTreeType(); } - RenderLeaves(); - EndLeafForTreeType(); - + + STATEMANAGER.SetVertexShader(NULL); + STATEMANAGER.SetFVF(D3DFVF_SPEEDTREE_BILLBOARD_VERTEX); STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE); STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, FALSE); RenderBillboards(); - + STATEMANAGER.RestoreRenderState(D3DRS_COLORVERTEX); STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE); STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE); STATEMANAGER.RestoreRenderState(D3DRS_ALPHAFUNC); STATEMANAGER.SetRenderState(D3DRS_ALPHABLENDENABLE, dwAlphaBlendEnable); STATEMANAGER.SetRenderState(D3DRS_LIGHTING, dwLighting); - STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable); + STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); } void CSpeedTreeWrapper::OnRender() { - if (ms_dwBranchVertexShader == 0) - { - ms_dwBranchVertexShader = LoadBranchShader(ms_lpd3dDevice); - //LogBox("Vertex Shader not assigned. You must call CSpeedTreeWrapper::SetVertexShader for this"); - } - - if (ms_dwLeafVertexShader == 0) - { - ms_dwLeafVertexShader = LoadLeafShader(ms_lpd3dDevice); - //LogBox("Vertex Shader not assigned. You must call CSpeedTreeWrapper::SetVertexShader for this"); - } - - CSpeedTreeForestDirectX8::Instance().UpdateSystem(ELTimer_GetMSec() / 1000.0f); - - // Çϳª¸¸ ·»´õ¸µ ÇÒ ¶§´Â LOD »ç¿ëÇÏÁö ¾ÊÀ½ - m_pSpeedTree->SetLodLevel(1.0f); - //Advance(); - - CSpeedTreeForestDirectX8::Instance().UpdateCompundMatrix(CCameraManager::Instance().GetCurrentCamera()->GetEye(), ms_matView, ms_matProj); - - STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); - STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - + STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE); + STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); + STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP); - STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP); - + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); + STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP); + STATEMANAGER.SaveRenderState(D3DRS_LIGHTING, FALSE); STATEMANAGER.SaveRenderState(D3DRS_COLORVERTEX, TRUE); - STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, TRUE); + STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, TRUE); STATEMANAGER.SaveRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_CW); STATEMANAGER.SaveRenderState(D3DRS_FOGENABLE, FALSE); - + STATEMANAGER.SetFVF(D3DFVF_SPEEDTREE_BRANCH_VERTEX); + // choose fixed function pipeline or custom shader for fronds and branches - STATEMANAGER.SetVertexShader(ms_dwBranchVertexShader); - + STATEMANAGER.SetVertexShader(ms_lpBranchVertexShader); + SetupBranchForTreeType(); RenderBranches(); - + STATEMANAGER.SetTexture(0, m_CompositeImageInstance.GetTextureReference().GetD3DTexture()); STATEMANAGER.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - + SetupFrondForTreeType(); RenderFronds(); - - STATEMANAGER.SetVertexShader(ms_dwLeafVertexShader); - + + STATEMANAGER.SetFVF(D3DFVF_SPEEDTREE_LEAF_VERTEX); + STATEMANAGER.SetVertexShader(ms_lpLeafVertexShader); + SetupLeafForTreeType(); RenderLeaves(); EndLeafForTreeType(); - + + STATEMANAGER.SetVertexShader(NULL); + STATEMANAGER.SetFVF(D3DFVF_SPEEDTREE_BILLBOARD_VERTEX); STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE); STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, FALSE); RenderBillboards(); - + STATEMANAGER.RestoreRenderState(D3DRS_LIGHTING); STATEMANAGER.RestoreRenderState(D3DRS_COLORVERTEX); - STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE); + STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE); STATEMANAGER.RestoreRenderState(D3DRS_ALPHAFUNC); STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE); STATEMANAGER.RestoreRenderState(D3DRS_FOGENABLE); } -/////////////////////////////////////////////////////////////////////// +UINT CSpeedTreeWrapper::GetCollisionObjectCount() +{ + assert(m_pSpeedTree); + return m_pSpeedTree->GetCollisionObjectCount(); +} + +void CSpeedTreeWrapper::GetCollisionObject(UINT nIndex, CSpeedTreeRT::ECollisionObjectType& eType, float* pPosition, float* pDimensions) +{ + assert(m_pSpeedTree); + m_pSpeedTree->GetCollisionObject(nIndex, eType, pPosition, pDimensions); +} + +void CSpeedTreeWrapper::OnUpdateCollisionData(const CStaticCollisionDataVector*) +{ + D3DXMATRIX mat; + D3DXMatrixTranslation(&mat, m_afPos[0], m_afPos[1], m_afPos[2]); + for (UINT i = 0; i < GetCollisionObjectCount(); ++i) + { + CSpeedTreeRT::ECollisionObjectType ObjectType; + CStaticCollisionData CollisionData; + + GetCollisionObject(i, ObjectType, (float*)&CollisionData.v3Position, CollisionData.fDimensions); + + if (ObjectType == CSpeedTreeRT::CO_BOX) + continue; + + switch (ObjectType) + { + case CSpeedTreeRT::CO_SPHERE: + CollisionData.dwType = COLLISION_TYPE_SPHERE; + CollisionData.fDimensions[0] = CollisionData.fDimensions[0]; + break; + + case CSpeedTreeRT::CO_CYLINDER: + CollisionData.dwType = COLLISION_TYPE_CYLINDER; + CollisionData.fDimensions[0] = CollisionData.fDimensions[0]; + CollisionData.fDimensions[1] = CollisionData.fDimensions[1]; + break; + } + AddCollision(&CollisionData, &mat); + } +} + +bool CSpeedTreeWrapper::GetBoundingSphere(D3DXVECTOR3& v3Center, float& fRadius) +{ + float fX, fY, fZ; + fX = m_afBoundingBox[3] - m_afBoundingBox[0]; + fY = m_afBoundingBox[4] - m_afBoundingBox[1]; + fZ = m_afBoundingBox[5] - m_afBoundingBox[2]; + v3Center.x = 0.0f; + v3Center.y = 0.0f; + v3Center.z = fZ * 0.5f; + fRadius = sqrtf(fX * fX + fY * fY + fZ * fZ) * 0.5f * 0.9f; + D3DXVECTOR3 vec = m_pSpeedTree->GetTreePosition(); + v3Center += vec; + return true; +} + +void CSpeedTreeWrapper::CalculateBBox() +{ + float fX, fY, fZ; + + fX = m_afBoundingBox[3] - m_afBoundingBox[0]; + fY = m_afBoundingBox[4] - m_afBoundingBox[1]; + fZ = m_afBoundingBox[5] - m_afBoundingBox[2]; + + m_v3BBoxMin.x = -fX / 2.0f; + m_v3BBoxMin.y = -fY / 2.0f; + m_v3BBoxMin.z = 0.0f; + m_v3BBoxMax.x = fX / 2.0f; + m_v3BBoxMax.y = fY / 2.0f; + m_v3BBoxMax.z = fZ; + + m_v4TBBox[0] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMin.y, m_v3BBoxMin.z, 1.0f); + m_v4TBBox[1] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMax.y, m_v3BBoxMin.z, 1.0f); + m_v4TBBox[2] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMin.y, m_v3BBoxMin.z, 1.0f); + m_v4TBBox[3] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMax.y, m_v3BBoxMin.z, 1.0f); + m_v4TBBox[4] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMin.y, m_v3BBoxMax.z, 1.0f); + m_v4TBBox[5] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMax.y, m_v3BBoxMax.z, 1.0f); + m_v4TBBox[6] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMin.y, m_v3BBoxMax.z, 1.0f); + m_v4TBBox[7] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMax.y, m_v3BBoxMax.z, 1.0f); + + const D3DXMATRIX& c_rmatTransform = GetTransform(); + + for (DWORD i = 0; i < 8; ++i) + { + D3DXVec4Transform(&m_v4TBBox[i], &m_v4TBBox[i], &c_rmatTransform); + if (0 == i) + { + m_v3TBBoxMin.x = m_v4TBBox[i].x; + m_v3TBBoxMin.y = m_v4TBBox[i].y; + m_v3TBBoxMin.z = m_v4TBBox[i].z; + m_v3TBBoxMax.x = m_v4TBBox[i].x; + m_v3TBBoxMax.y = m_v4TBBox[i].y; + m_v3TBBoxMax.z = m_v4TBBox[i].z; + } + else + { + if (m_v3TBBoxMin.x > m_v4TBBox[i].x) + m_v3TBBoxMin.x = m_v4TBBox[i].x; + if (m_v3TBBoxMax.x < m_v4TBBox[i].x) + m_v3TBBoxMax.x = m_v4TBBox[i].x; + if (m_v3TBBoxMin.y > m_v4TBBox[i].y) + m_v3TBBoxMin.y = m_v4TBBox[i].y; + if (m_v3TBBoxMax.y < m_v4TBBox[i].y) + m_v3TBBoxMax.y = m_v4TBBox[i].y; + if (m_v3TBBoxMin.z > m_v4TBBox[i].z) + m_v3TBBoxMin.z = m_v4TBBox[i].z; + if (m_v3TBBoxMax.z < m_v4TBBox[i].z) + m_v3TBBoxMax.z = m_v4TBBox[i].z; + } + } +} + +/////////////////////////////////////////////////////////////////////// // CSpeedTreeWrapper::~CSpeedTreeWrapper CSpeedTreeWrapper::~CSpeedTreeWrapper() @@ -320,25 +347,30 @@ CSpeedTreeWrapper::~CSpeedTreeWrapper() SAFE_RELEASE(m_pBranchIndexBuffer); SAFE_DELETE_ARRAY(m_pBranchIndexCounts); } - + if (m_unFrondVertexCount > 0) - { + { SAFE_RELEASE(m_pFrondVertexBuffer); - SAFE_RELEASE(m_pFrondIndexBuffer); + + for (unsigned int i = 0; i < m_unNumFrondLods; ++i) + if (m_pFrondIndexCounts[i] > 0) + SAFE_RELEASE(m_pFrondIndexBuffers[i]); + + SAFE_DELETE_ARRAY(m_pFrondIndexBuffers); SAFE_DELETE_ARRAY(m_pFrondIndexCounts); } - - for (short i = 0; i < m_usNumLeafLods; ++i) - { + + for (unsigned short i = 0; i < m_usNumLeafLods; ++i) + { m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_LeafGeometry, -1, -1, i); - + if (m_pGeometryCache->m_sLeaves0.m_usLeafCount > 0) SAFE_RELEASE(m_pLeafVertexBuffer[i]); } - + SAFE_DELETE_ARRAY(m_pLeavesUpdatedByCpu); SAFE_DELETE_ARRAY(m_pLeafVertexBuffer); - + SAFE_DELETE(m_pTextureInfo); SAFE_DELETE(m_pGeometryCache); @@ -347,16 +379,17 @@ CSpeedTreeWrapper::~CSpeedTreeWrapper() // always delete the speedtree SAFE_DELETE(m_pSpeedTree); + --m_unNumWrappersActive; + Clear(); } - -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // CSpeedTreeWrapper::LoadTree -bool CSpeedTreeWrapper::LoadTree(const char * pszSptFile, const BYTE * c_pbBlock, unsigned int uiBlockSize, UINT nSeed, float fSize, float fSizeVariance) +bool CSpeedTreeWrapper::LoadTree(const char* pszSptFile, const BYTE* c_pbBlock = NULL, unsigned int uiBlockSize = 0, unsigned int nSeed, float fSize, float fSizeVariance) { - bool bSuccess = false; - + bool bSuccess = false; + // directx, so allow for flipping of the texture coordinate #ifdef WRAPPER_FLIP_T_TEXCOORD m_pSpeedTree->SetTextureFlip(true); @@ -371,29 +404,13 @@ bool CSpeedTreeWrapper::LoadTree(const char * pszSptFile, const BYTE * c_pbBlock return false; } } - + // override the lighting method stored in the spt file -#ifdef WRAPPER_USE_DYNAMIC_LIGHTING - m_pSpeedTree->SetBranchLightingMethod(CSpeedTreeRT::LIGHT_DYNAMIC); - m_pSpeedTree->SetLeafLightingMethod(CSpeedTreeRT::LIGHT_DYNAMIC); - m_pSpeedTree->SetFrondLightingMethod(CSpeedTreeRT::LIGHT_DYNAMIC); -#else m_pSpeedTree->SetBranchLightingMethod(CSpeedTreeRT::LIGHT_STATIC); m_pSpeedTree->SetLeafLightingMethod(CSpeedTreeRT::LIGHT_STATIC); m_pSpeedTree->SetFrondLightingMethod(CSpeedTreeRT::LIGHT_STATIC); -#endif - + // set the wind method -#ifdef WRAPPER_USE_GPU_WIND - m_pSpeedTree->SetBranchWindMethod(CSpeedTreeRT::WIND_GPU); - m_pSpeedTree->SetLeafWindMethod(CSpeedTreeRT::WIND_GPU); - m_pSpeedTree->SetFrondWindMethod(CSpeedTreeRT::WIND_GPU); -#endif -#ifdef WRAPPER_USE_CPU_WIND - m_pSpeedTree->SetBranchWindMethod(CSpeedTreeRT::WIND_CPU); - m_pSpeedTree->SetLeafWindMethod(CSpeedTreeRT::WIND_CPU); - m_pSpeedTree->SetFrondWindMethod(CSpeedTreeRT::WIND_CPU); -#endif #ifdef WRAPPER_USE_NO_WIND m_pSpeedTree->SetBranchWindMethod(CSpeedTreeRT::WIND_NONE); m_pSpeedTree->SetLeafWindMethod(CSpeedTreeRT::WIND_NONE); @@ -414,14 +431,10 @@ bool CSpeedTreeWrapper::LoadTree(const char * pszSptFile, const BYTE * c_pbBlock // make the leaves rock in the wind m_pSpeedTree->SetLeafRockingState(true); - + // billboard setup -#ifdef WRAPPER_NO_BILLBOARD_MODE - CSpeedTreeRT::SetDropToBillboard(false); -#else CSpeedTreeRT::SetDropToBillboard(true); -#endif - + // query & set materials m_cBranchMaterial.Set(m_pSpeedTree->GetBranchMaterial()); m_cFrondMaterial.Set(m_pSpeedTree->GetFrondMaterial()); @@ -429,19 +442,13 @@ bool CSpeedTreeWrapper::LoadTree(const char * pszSptFile, const BYTE * c_pbBlock // adjust lod distances float fHeight = m_afBoundingBox[5] - m_afBoundingBox[2]; - m_pSpeedTree->SetLodLimits(fHeight * c_fNearLodFactor, fHeight * c_fFarLodFactor); - - // query textures m_pTextureInfo = new CSpeedTreeRT::STextures; m_pSpeedTree->GetTextures(*m_pTextureInfo); - - // load branch textures LoadTexture((CFileNameHelper::GetPath(string(pszSptFile)) + CFileNameHelper::NoExtension(string(m_pTextureInfo->m_pBranchTextureFilename)) + ".dds").c_str(), m_BranchImageInstance); - -#ifdef WRAPPER_RENDER_SELF_SHADOWS + if (m_pTextureInfo->m_pSelfShadowFilename != NULL) LoadTexture((CFileNameHelper::GetPath(string(pszSptFile)) + CFileNameHelper::NoExtension(string(m_pTextureInfo->m_pSelfShadowFilename)) + ".dds").c_str(), m_ShadowImageInstance); -#endif + if (m_pTextureInfo->m_pCompositeFilename) LoadTexture((CFileNameHelper::GetPath(string(pszSptFile)) + CFileNameHelper::NoExtension(string(m_pTextureInfo->m_pCompositeFilename)) + ".dds").c_str(), m_CompositeImageInstance); @@ -464,8 +471,6 @@ bool CSpeedTreeWrapper::LoadTree(const char * pszSptFile, const BYTE * c_pbBlock void CSpeedTreeWrapper::SetupBuffers(void) { // read all the geometry for highest LOD into the geometry cache (just a precaution, it's updated later) - m_pSpeedTree->SetLodLevel(1.0f); - if (m_pGeometryCache == NULL) m_pGeometryCache = new CSpeedTreeRT::SGeometry; @@ -491,58 +496,38 @@ void CSpeedTreeWrapper::SetupBranchBuffers(void) { // create the vertex buffer for storing branch vertices SFVFBranchVertex * pVertexBuffer = NULL; - -#ifndef WRAPPER_USE_CPU_WIND - ms_lpd3dDevice->CreateVertexBuffer(m_unBranchVertexCount * sizeof(SFVFBranchVertex), D3DUSAGE_WRITEONLY, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_MANAGED, &m_pBranchVertexBuffer); + + ms_lpd3dDevice->CreateVertexBuffer(m_unBranchVertexCount * sizeof(SFVFBranchVertex), D3DUSAGE_WRITEONLY, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_MANAGED, &m_pBranchVertexBuffer, NULL); // fill the vertex buffer by interleaving SpeedTree data - m_pBranchVertexBuffer->Lock(0, 0, reinterpret_cast(&pVertexBuffer), 0); -#else - ms_lpd3dDevice->CreateVertexBuffer(m_unBranchVertexCount * sizeof(SFVFBranchVertex), D3DUSAGE_DYNAMIC, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_SYSTEMMEM, &m_pBranchVertexBuffer); - // fill the vertex buffer by interleaving SpeedTree data - m_pBranchVertexBuffer->Lock(0, 0, reinterpret_cast(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); -#endif + m_pBranchVertexBuffer->Lock(0, 0, reinterpret_cast(&pVertexBuffer), 0); + + for (unsigned int i = 0; i < m_unBranchVertexCount; ++i) { - for (UINT i = 0; i < m_unBranchVertexCount; ++i) - { - // position - memcpy(&pVertexBuffer->m_vPosition, &(pBranches->m_pCoords[i * 3]), 3 * sizeof(float)); - - // normal or color -#ifdef WRAPPER_USE_DYNAMIC_LIGHTING - memcpy(&pVertexBuffer->m_vNormal, &(pBranches->m_pNormals[i * 3]), 3 * sizeof(float)); -#else - pVertexBuffer->m_dwDiffuseColor = pBranches->m_pColors[i]; -#endif - - // texcoords for layer 0 - pVertexBuffer->m_fTexCoords[0] = pBranches->m_pTexCoords0[i * 2]; - pVertexBuffer->m_fTexCoords[1] = pBranches->m_pTexCoords0[i * 2 + 1]; - - // texcoords for layer 1 (if enabled) -#ifdef WRAPPER_RENDER_SELF_SHADOWS - pVertexBuffer->m_fShadowCoords[0] = pBranches->m_pTexCoords1[i * 2]; - pVertexBuffer->m_fShadowCoords[1] = pBranches->m_pTexCoords1[i * 2 + 1]; -#endif - - // extra data for gpu wind -#ifdef WRAPPER_USE_GPU_WIND - pVertexBuffer->m_fWindIndex = 4.0f * pBranches->m_pWindMatrixIndices[i]; - pVertexBuffer->m_fWindWeight = pBranches->m_pWindWeights[i]; -#endif - - ++pVertexBuffer; - } - m_pBranchVertexBuffer->Unlock(); + // position + memcpy(&pVertexBuffer->m_vPosition, &(pBranches->m_pCoords[i * 3]), 3 * sizeof(float)); + + // normal or color + pVertexBuffer->m_dwDiffuseColor = AGBR2ARGB(pBranches->m_pColors[i]); + + // texcoords for layer 0 + pVertexBuffer->m_fShadowCoords[0] = pBranches->m_pTexCoords1[i * 2]; + pVertexBuffer->m_fShadowCoords[1] = pBranches->m_pTexCoords1[i * 2 + 1]; + + // texcoords for layer 1 (if enabled) + pVertexBuffer->m_fTexCoords[0] = pBranches->m_pTexCoords0[i * 2]; + pVertexBuffer->m_fTexCoords[1] = pBranches->m_pTexCoords0[i * 2 + 1]; + + ++pVertexBuffer; } - - // create and fill the index counts for each LOD - UINT unNumLodLevels = m_pSpeedTree->GetNumBranchLodLevels(); + m_pBranchVertexBuffer->Unlock(); + + unsigned int unNumLodLevels = m_pSpeedTree->GetNumBranchLodLevels(); m_pBranchIndexCounts = new unsigned short[unNumLodLevels]; - for (UINT i = 0; i < unNumLodLevels; ++i) + for (unsigned int i = 0; i < unNumLodLevels; ++i) { // force update for particular LOD - m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_BranchGeometry, i); - + m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_BranchGeometry, (short)i); + // check if this LOD has branches if (pBranches->m_usNumStrips > 0) m_pBranchIndexCounts[i] = pBranches->m_pStripLengths[0]; @@ -551,14 +536,14 @@ void CSpeedTreeWrapper::SetupBranchBuffers(void) } // set back to highest LOD m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_BranchGeometry, 0); - + // the first LOD level contains the most indices of all the levels, so // we use its size to allocate the index buffer - ms_lpd3dDevice->CreateIndexBuffer(m_pBranchIndexCounts[0] * sizeof(unsigned short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pBranchIndexBuffer); - + ms_lpd3dDevice->CreateIndexBuffer(m_pBranchIndexCounts[0] * sizeof(unsigned short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pBranchIndexBuffer, NULL); + // fill the index buffer unsigned short* pIndexBuffer = NULL; - m_pBranchIndexBuffer->Lock(0, 0, reinterpret_cast(&pIndexBuffer), 0); + m_pBranchIndexBuffer->Lock(0, 0, reinterpret_cast(&pIndexBuffer), 0); memcpy(pIndexBuffer, pBranches->m_pStrips[0], pBranches->m_pStripLengths[0] * sizeof(unsigned short)); m_pBranchIndexBuffer->Unlock(); } @@ -579,73 +564,61 @@ void CSpeedTreeWrapper::SetupFrondBuffers(void) { // create the vertex buffer for storing frond vertices SFVFBranchVertex * pVertexBuffer = NULL; -#ifndef WRAPPER_USE_CPU_WIND - ms_lpd3dDevice->CreateVertexBuffer(m_unFrondVertexCount * sizeof(SFVFBranchVertex), D3DUSAGE_WRITEONLY, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_MANAGED, &m_pFrondVertexBuffer); + ms_lpd3dDevice->CreateVertexBuffer(m_unFrondVertexCount * sizeof(SFVFBranchVertex), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_SYSTEMMEM, &m_pFrondVertexBuffer, NULL); // fill the vertex buffer by interleaving SpeedTree data - m_pFrondVertexBuffer->Lock(0, 0, reinterpret_cast(&pVertexBuffer), 0); -#else - ms_lpd3dDevice->CreateVertexBuffer(m_unFrondVertexCount * sizeof(SFVFBranchVertex), D3DUSAGE_DYNAMIC, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_SYSTEMMEM, &m_pFrondVertexBuffer); - // fill the vertex buffer by interleaving SpeedTree data - m_pFrondVertexBuffer->Lock(0, 0, reinterpret_cast(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); -#endif - for (UINT i = 0; i < m_unFrondVertexCount; ++i) + m_pFrondVertexBuffer->Lock(0, 0, reinterpret_cast(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); + + for (unsigned short i = 0; i < m_unFrondVertexCount; ++i) { // position memcpy(&pVertexBuffer->m_vPosition, &(pFronds->m_pCoords[i * 3]), 3 * sizeof(float)); - + // normal or color -#ifdef WRAPPER_USE_DYNAMIC_LIGHTING - memcpy(&pVertexBuffer->m_vNormal, &(pFronds->m_pNormals[i * 3]), 3 * sizeof(float)); -#else - pVertexBuffer->m_dwDiffuseColor = pFronds->m_pColors[i]; -#endif - + pVertexBuffer->m_dwDiffuseColor = AGBR2ARGB(pFronds->m_pColors[i]); + // texcoords for layer 0 - pVertexBuffer->m_fTexCoords[0] = pFronds->m_pTexCoords0[i * 2]; - pVertexBuffer->m_fTexCoords[1] = pFronds->m_pTexCoords0[i * 2 + 1]; - - // texcoords for layer 1 (if enabled) -#ifdef WRAPPER_RENDER_SELF_SHADOWS pVertexBuffer->m_fShadowCoords[0] = pFronds->m_pTexCoords1[i * 2]; pVertexBuffer->m_fShadowCoords[1] = pFronds->m_pTexCoords1[i * 2 + 1]; -#endif - - // extra data for gpu wind -#ifdef WRAPPER_USE_GPU_WIND - pVertexBuffer->m_fWindIndex = 4.0f * pFronds->m_pWindMatrixIndices[i]; - pVertexBuffer->m_fWindWeight = pFronds->m_pWindWeights[i]; -#endif - + + // texcoords for layer 1 (if enabled) + pVertexBuffer->m_fTexCoords[0] = pFronds->m_pTexCoords0[i * 2]; + pVertexBuffer->m_fTexCoords[1] = pFronds->m_pTexCoords0[i * 2 + 1]; + ++pVertexBuffer; } m_pFrondVertexBuffer->Unlock(); - + // create and fill the index counts for each LOD - UINT unNumLodLevels = m_pSpeedTree->GetNumFrondLodLevels(); - m_pFrondIndexCounts = new unsigned short[unNumLodLevels]; - for (WORD j = 0; j < unNumLodLevels; ++j) + m_unNumFrondLods = m_pSpeedTree->GetNumFrondLodLevels(); + m_pFrondIndexCounts = new unsigned short[m_unNumFrondLods]; + m_pFrondIndexBuffers = new LPDIRECT3DINDEXBUFFER9[m_unNumFrondLods]; + + for (unsigned short i = 0; i < m_unNumFrondLods; ++i) { // force update for this LOD - m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_FrondGeometry, -1, j); - + m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_FrondGeometry, -1, i); + // check if this LOD has fronds if (pFronds->m_usNumStrips > 0) - m_pFrondIndexCounts[j] = pFronds->m_pStripLengths[0]; + m_pFrondIndexCounts[i] = pFronds->m_pStripLengths[0]; else - m_pFrondIndexCounts[j] = 0; + m_pFrondIndexCounts[i] = 0; + + if (m_pFrondIndexCounts[i] > 0) + { + // the first LOD level contains the most indices of all the levels, so + // we use its size to allocate the index buffer + ms_lpd3dDevice->CreateIndexBuffer(m_pFrondIndexCounts[i] * sizeof(unsigned short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pFrondIndexBuffers[i], NULL); + + // fill the index buffer + unsigned short* pIndexBuffer = NULL; + m_pFrondIndexBuffers[i]->Lock(0, 0, reinterpret_cast(&pIndexBuffer), 0); + memcpy(pIndexBuffer, pFronds->m_pStrips[0], m_pFrondIndexCounts[i] * sizeof(unsigned short)); + m_pFrondIndexBuffers[i]->Unlock(); + } } - // go back to highest LOD + m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_FrondGeometry, -1, 0); - - // the first LOD level contains the most indices of all the levels, so - // we use its size to allocate the index buffer - ms_lpd3dDevice->CreateIndexBuffer(m_pFrondIndexCounts[0] * sizeof(unsigned short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pFrondIndexBuffer); - - // fill the index buffer - unsigned short * pIndexBuffer = NULL; - m_pFrondIndexBuffer->Lock(0, 0, reinterpret_cast(&pIndexBuffer), 0); - memcpy(pIndexBuffer, pFronds->m_pStrips[0], pFronds->m_pStripLengths[0] * sizeof(unsigned short)); - m_pFrondIndexBuffer->Unlock(); } } @@ -661,18 +634,18 @@ void CSpeedTreeWrapper::SetupLeafBuffers(void) // set up the leaf counts for each LOD m_usNumLeafLods = m_pSpeedTree->GetNumLeafLodLevels(); - + // create array of vertex buffers (one for each LOD) - m_pLeafVertexBuffer = new LPDIRECT3DVERTEXBUFFER8[m_usNumLeafLods]; - + m_pLeafVertexBuffer = new LPDIRECT3DVERTEXBUFFER9[m_usNumLeafLods]; + // create array of bools for CPU updating (so we don't update for each instance) m_pLeavesUpdatedByCpu = new bool[m_usNumLeafLods]; - + // cycle through LODs - for (UINT unLod = 0; unLod < m_usNumLeafLods; ++unLod) + for (unsigned int unLod = 0; unLod < m_usNumLeafLods; ++unLod) { + m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_LeafGeometry, -1, -1, unLod); m_pLeavesUpdatedByCpu[unLod] = false; - m_pLeafVertexBuffer[unLod] = NULL; // if this LOD has no leaves, skip it unsigned short usLeafCount = m_pGeometryCache->m_sLeaves0.m_usLeafCount; @@ -682,47 +655,24 @@ void CSpeedTreeWrapper::SetupLeafBuffers(void) SFVFLeafVertex* pVertexBuffer = NULL; // create the vertex buffer for storing leaf vertices -#ifndef WRAPPER_USE_CPU_LEAF_PLACEMENT - ms_lpd3dDevice->CreateVertexBuffer(usLeafCount * 6 * sizeof(SFVFLeafVertex), D3DUSAGE_WRITEONLY, D3DFVF_SPEEDTREE_LEAF_VERTEX, D3DPOOL_MANAGED, &m_pLeafVertexBuffer[unLod]); + ms_lpd3dDevice->CreateVertexBuffer(usLeafCount * 6 * sizeof(SFVFLeafVertex), D3DUSAGE_DYNAMIC, D3DFVF_SPEEDTREE_LEAF_VERTEX, D3DPOOL_SYSTEMMEM, &m_pLeafVertexBuffer[unLod], NULL); // fill the vertex buffer by interleaving SpeedTree data - m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast(&pVertexBuffer), 0); -#else - ms_lpd3dDevice->CreateVertexBuffer(usLeafCount * 6 * sizeof(SFVFLeafVertex), D3DUSAGE_DYNAMIC, D3DFVF_SPEEDTREE_LEAF_VERTEX, D3DPOOL_SYSTEMMEM, &m_pLeafVertexBuffer[unLod]); - // fill the vertex buffer by interleaving SpeedTree data - m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); -#endif + m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); SFVFLeafVertex* pVertex = pVertexBuffer; - for (UINT unLeaf = 0; unLeaf < usLeafCount; ++unLeaf) + for (unsigned int unLeaf = 0; unLeaf < usLeafCount; ++unLeaf) { const CSpeedTreeRT::SGeometry::SLeaf* pLeaf = &(m_pGeometryCache->m_sLeaves0); - for (UINT unVert = 0; unVert < 6; ++unVert) // 6 verts == 2 triangles + for (unsigned int unVert = 0; unVert < 6; ++unVert) // 6 verts == 2 triangles { // position memcpy(pVertex->m_vPosition, &(pLeaf->m_pCenterCoords[unLeaf * 3]), 3 * sizeof(float)); - -#ifdef WRAPPER_USE_DYNAMIC_LIGHTING - // normal - memcpy(&pVertex->m_vNormal, &(pLeaf->m_pNormals[unLeaf * 3]), 3 * sizeof(float)); -#else + // color - pVertex->m_dwDiffuseColor = pLeaf->m_pColors[unLeaf]; -#endif - + pVertex->m_dwDiffuseColor = AGBR2ARGB(pLeaf->m_pColors[unLeaf]); + // tex coord memcpy(pVertex->m_fTexCoords, &(pLeaf->m_pLeafMapTexCoords[unLeaf][anVertexIndices[unVert] * 2]), 2 * sizeof(float)); - - // wind weights -#ifdef WRAPPER_USE_GPU_WIND - pVertex->m_fWindIndex = 4.0f * pLeaf->m_pWindMatrixIndices[unLeaf]; - pVertex->m_fWindWeight = pLeaf->m_pWindWeights[unLeaf]; -#endif - - // GPU placement data -#ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT - pVertex->m_fLeafPlacementIndex = c_nVertexShader_LeafTables + pLeaf->m_pLeafClusterIndices[unLeaf] * 4.0f + anVertexIndices[unVert]; - pVertex->m_fLeafScalarValue = m_pSpeedTree->GetLeafLodSizeAdjustments()[unLod]; -#endif - + ++pVertex; } } @@ -730,26 +680,14 @@ void CSpeedTreeWrapper::SetupLeafBuffers(void) } } - -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // CSpeedTreeWrapper::Advance -void CSpeedTreeWrapper::Advance(void) -{ - // compute LOD level (based on distance from camera) - m_pSpeedTree->ComputeLodLevel(); - m_pSpeedTree->SetLodLevel(1.0f); - - // compute wind -#ifdef WRAPPER_USE_CPU_WIND - m_pSpeedTree->ComputeWindEffects(true, true, true); -#endif -} +void CSpeedTreeWrapper::Advance(void){} - -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // CSpeedTreeWrapper::MakeInstance -CSpeedTreeWrapper * CSpeedTreeWrapper::MakeInstance() +CSpeedTreeWrapper * CSpeedTreeWrapper::MakeInstance(void) { CSpeedTreeWrapper * pInstance = new CSpeedTreeWrapper; @@ -758,7 +696,7 @@ CSpeedTreeWrapper * CSpeedTreeWrapper::MakeInstance() pInstance->m_pSpeedTree = m_pSpeedTree->MakeInstance(); if (pInstance->m_pSpeedTree) - { + { // use the same materials pInstance->m_cBranchMaterial = m_cBranchMaterial; pInstance->m_cLeafMaterial = m_cLeafMaterial; @@ -779,8 +717,9 @@ CSpeedTreeWrapper * CSpeedTreeWrapper::MakeInstance() pInstance->m_pBranchIndexCounts = m_pBranchIndexCounts; pInstance->m_pBranchVertexBuffer = m_pBranchVertexBuffer; pInstance->m_unBranchVertexCount = m_unBranchVertexCount; - - pInstance->m_pFrondIndexBuffer = m_pFrondIndexBuffer; + + pInstance->m_pFrondIndexBuffers = m_pFrondIndexBuffers; + pInstance->m_unNumFrondLods = m_unNumFrondLods; pInstance->m_pFrondIndexCounts = m_pFrondIndexCounts; pInstance->m_pFrondVertexBuffer = m_pFrondVertexBuffer; pInstance->m_unFrondVertexCount = m_unFrondVertexCount; @@ -794,28 +733,25 @@ CSpeedTreeWrapper * CSpeedTreeWrapper::MakeInstance() memcpy(pInstance->m_afBoundingBox, m_afBoundingBox, 6 * sizeof(float)); pInstance->m_pInstanceOf = this; m_vInstances.push_back(pInstance); - } - else + } + else { fprintf(stderr, "SpeedTreeRT Error: %s\n", m_pSpeedTree->GetCurrentError()); - delete pInstance; - pInstance = NULL; + delete pInstance; + pInstance = NULL; } - + return pInstance; } -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // CSpeedTreeWrapper::GetInstances -CSpeedTreeWrapper ** CSpeedTreeWrapper::GetInstances(UINT& nCount) +CSpeedTreeWrapper** CSpeedTreeWrapper::GetInstances(unsigned int& nCount) { nCount = m_vInstances.size(); - if (nCount) - return &(m_vInstances[0]); - else - return NULL; + return nCount ? &(m_vInstances[0]) : NULL; } void CSpeedTreeWrapper::DeleteInstance(CSpeedTreeWrapper * pInstance) @@ -826,12 +762,12 @@ void CSpeedTreeWrapper::DeleteInstance(CSpeedTreeWrapper * pInstance) { if (*itor == pInstance) { + delete pInstance; itor = m_vInstances.erase(itor); } else ++itor; } - delete pInstance; } /////////////////////////////////////////////////////////////////////// @@ -839,43 +775,18 @@ void CSpeedTreeWrapper::DeleteInstance(CSpeedTreeWrapper * pInstance) void CSpeedTreeWrapper::SetupBranchForTreeType(void) const { -#ifdef WRAPPER_USE_DYNAMIC_LIGHTING - // set lighting material - STATEMANAGER.SetMaterial(m_cBranchMaterial.Get()); - SetShaderConstants(m_pSpeedTree->GetBranchMaterial()); -#endif - - // update the branch geometry for CPU wind -#ifdef WRAPPER_USE_CPU_WIND - m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_BranchGeometry); - - if (m_pGeometryCache->m_sBranches.m_usNumStrips > 0) - { - // update the vertex array - SFVFBranchVertex* pVertexBuffer = NULL; - m_pBranchVertexBuffer->Lock(0, 0, reinterpret_cast(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); - for (UINT i = 0; i < m_unBranchVertexCount; ++i) - { - memcpy(&(pVertexBuffer[i].m_vPosition), &(m_pGeometryCache->m_sBranches.m_pCoords[i * 3]), 3 * sizeof(float)); - } - m_pBranchVertexBuffer->Unlock(); - } -#endif - - LPDIRECT3DTEXTURE8 lpd3dTexture; - - // set texture map - if ((lpd3dTexture = m_BranchImageInstance.GetTextureReference().GetD3DTexture())) - STATEMANAGER.SetTexture(0, lpd3dTexture); - + LPDIRECT3DTEXTURE9 lpd3dTexture; + + // set texture map + if ((lpd3dTexture = m_BranchImageInstance.GetTextureReference().GetD3DTexture())) + STATEMANAGER.SetTexture(0, lpd3dTexture); + // bind shadow texture -#ifdef WRAPPER_RENDER_SELF_SHADOWS if (ms_bSelfShadowOn && (lpd3dTexture = m_ShadowImageInstance.GetTextureReference().GetD3DTexture())) STATEMANAGER.SetTexture(1, lpd3dTexture); else STATEMANAGER.SetTexture(1, NULL); -#endif - + if (m_pGeometryCache->m_sBranches.m_usVertexCount > 0) { // activate the branch vertex buffer @@ -892,16 +803,17 @@ void CSpeedTreeWrapper::SetupBranchForTreeType(void) const void CSpeedTreeWrapper::RenderBranches(void) const { m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_BranchGeometry); - - if (m_pGeometryCache->m_fBranchAlphaTestValue) + + if (m_pGeometryCache->m_fBranchAlphaTestValue > 0.0f) { PositionTree(); // set alpha test value STATEMANAGER.SetRenderState(D3DRS_ALPHAREF, DWORD(m_pGeometryCache->m_fBranchAlphaTestValue)); - + // render if this LOD has branches - if (m_pBranchIndexCounts && + if (m_pBranchIndexCounts && + m_pGeometryCache->m_sBranches.m_nDiscreteLodLevel > -1 && m_pBranchIndexCounts[m_pGeometryCache->m_sBranches.m_nDiscreteLodLevel] > 0) { ms_faceCount += m_pBranchIndexCounts[m_pGeometryCache->m_sBranches.m_nDiscreteLodLevel] - 2; @@ -916,45 +828,19 @@ void CSpeedTreeWrapper::RenderBranches(void) const void CSpeedTreeWrapper::SetupFrondForTreeType(void) const { -#ifdef SPEEDTREE_LIGHTING_DYNAMIC - // set lighting material - STATEMANAGER.SetMaterial(m_cFrondMaterial.Get()); - SetShaderConstants(m_pSpeedTree->GetFrondMaterial()); -#endif - - // update the frond geometry for CPU wind -#ifdef WRAPPER_USE_CPU_WIND - m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_FrondGeometry); - if (m_pGeometryCache->m_sFronds.m_usNumStrips > 0) - { - // update the vertex array - SFVFBranchVertex * pVertexBuffer = NULL; - m_pFrondVertexBuffer->Lock(0, 0, reinterpret_cast(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); - for (UINT i = 0; i < m_unFrondVertexCount; ++i) - { - memcpy(&(pVertexBuffer[i].m_vPosition), &(m_pGeometryCache->m_sFronds.m_pCoords[i * 3]), 3 * sizeof(float)); - } - m_pFrondVertexBuffer->Unlock(); - } -#endif - - if (!m_CompositeImageInstance.IsEmpty()) - STATEMANAGER.SetTexture(0, m_CompositeImageInstance.GetTextureReference().GetD3DTexture()); - // bind shadow texture -#ifdef WRAPPER_RENDER_SELF_SHADOWS - LPDIRECT3DTEXTURE8 lpd3dTexture; - + LPDIRECT3DTEXTURE9 lpd3dTexture; + + if ((lpd3dTexture = m_CompositeImageInstance.GetTextureReference().GetD3DTexture())) + STATEMANAGER.SetTexture(0, lpd3dTexture); + if ((lpd3dTexture = m_ShadowImageInstance.GetTextureReference().GetD3DTexture())) STATEMANAGER.SetTexture(1, lpd3dTexture); -#endif - + if (m_pGeometryCache->m_sFronds.m_usVertexCount > 0) { // activate the frond vertex buffer STATEMANAGER.SetStreamSource(0, m_pFrondVertexBuffer, sizeof(SFVFBranchVertex)); - // set the index buffer - STATEMANAGER.SetIndices(m_pFrondIndexBuffer, 0); } } @@ -965,7 +851,7 @@ void CSpeedTreeWrapper::SetupFrondForTreeType(void) const void CSpeedTreeWrapper::RenderFronds(void) const { m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_FrondGeometry); - + if (m_pGeometryCache->m_fFrondAlphaTestValue > 0.0f) { PositionTree(); @@ -975,8 +861,11 @@ void CSpeedTreeWrapper::RenderFronds(void) const // render if this LOD has fronds if (m_pFrondIndexCounts && + m_pGeometryCache->m_sFronds.m_nDiscreteLodLevel > -1 && m_pFrondIndexCounts[m_pGeometryCache->m_sFronds.m_nDiscreteLodLevel] > 0) { + STATEMANAGER.SetIndices(m_pFrondIndexBuffers[m_pGeometryCache->m_sFronds.m_nDiscreteLodLevel], 0); + ms_faceCount += m_pFrondIndexCounts[m_pGeometryCache->m_sFronds.m_nDiscreteLodLevel] - 2; STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, m_pGeometryCache->m_sFronds.m_usVertexCount, 0, m_pFrondIndexCounts[m_pGeometryCache->m_sFronds.m_nDiscreteLodLevel] - 2); } @@ -989,174 +878,62 @@ void CSpeedTreeWrapper::RenderFronds(void) const void CSpeedTreeWrapper::SetupLeafForTreeType(void) const { -#ifdef SPEEDTREE_LIGHTING_DYNAMIC - // set lighting material - STATEMANAGER.SetMaterial(m_cLeafMaterial.Get()); - SetShaderConstants(m_pSpeedTree->GetLeafMaterial()); -#endif - - // pass leaf tables to shader -#ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT - UploadLeafTables(c_nVertexShader_LeafTables); -#endif - if (!m_CompositeImageInstance.IsEmpty()) STATEMANAGER.SetTexture(0, m_CompositeImageInstance.GetTextureReference().GetD3DTexture()); - + // bind shadow texture -#ifdef WRAPPER_RENDER_SELF_SHADOWS STATEMANAGER.SetTexture(1, NULL); -#endif } - -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeWrapper::UploadLeafTables - -#ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT -void CSpeedTreeWrapper::UploadLeafTables(UINT uiLocation) const -{ - // query leaf cluster table from RT - UINT uiEntryCount = 0; - const float * pTable = m_pSpeedTree->GetLeafBillboardTable(uiEntryCount); - - // upload for vertex shader use - STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_LeafTables, pTable, uiEntryCount / 4); -} -#endif - - -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // CSpeedTreeWrapper::RenderLeaves void CSpeedTreeWrapper::RenderLeaves(void) const { // update leaf geometry m_pSpeedTree->GetGeometry(*m_pGeometryCache, SpeedTree_LeafGeometry); - - // update the LOD level vertex arrays we need -#if defined(WRAPPER_USE_GPU_LEAF_PLACEMENT) && defined(WRAPPER_USE_GPU_WIND) - // do nothing, needs no updates -#else + #if !defined WRAPPER_USE_NO_WIND || defined WRAPPER_USE_CPU_LEAF_PLACEMENT // possibly need to update both leaf LOD's - for (UINT i = 0; i < 2; ++i) + for (unsigned int i = 0; i < 2; ++i) { // reference to leaf structure const CSpeedTreeRT::SGeometry::SLeaf* pLeaf = (i == 0) ? &m_pGeometryCache->m_sLeaves0 : &m_pGeometryCache->m_sLeaves1; int unLod = pLeaf->m_nDiscreteLodLevel; - -#if defined WRAPPER_USE_GPU_LEAF_PLACEMENT - if (pLeaf->m_bIsActive && !m_pLeavesUpdatedByCpu[unLod]) + + if (pLeaf->m_bIsActive && pLeaf->m_usLeafCount > 0) { // update the centers SFVFLeafVertex* pVertex = NULL; - m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast(&pVertex), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); - for (UINT unLeaf = 0; unLeaf < pLeaf->m_usLeafCount; ++unLeaf) + m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast(&pVertex), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); + for (unsigned int unLeaf = 0; unLeaf < pLeaf->m_usLeafCount; ++unLeaf) { D3DXVECTOR3 vecCenter(&(pLeaf->m_pCenterCoords[unLeaf * 3])); - (pVertex++)->m_vPosition = vecCenter; // vertex 0 - (pVertex++)->m_vPosition = vecCenter; // vertex 1 - (pVertex++)->m_vPosition = vecCenter; // vertex 2 - (pVertex++)->m_vPosition = vecCenter; // vertex 0 - (pVertex++)->m_vPosition = vecCenter; // vertex 2 - (pVertex++)->m_vPosition = vecCenter; // vertex 3 + D3DXVECTOR3 vec0(&pLeaf->m_pLeafMapCoords[unLeaf][0]); + D3DXVECTOR3 vec1(&pLeaf->m_pLeafMapCoords[unLeaf][4]); + D3DXVECTOR3 vec2(&pLeaf->m_pLeafMapCoords[unLeaf][8]); + D3DXVECTOR3 vec3(&pLeaf->m_pLeafMapCoords[unLeaf][12]); + + (pVertex++)->m_vPosition = vecCenter + vec0; + (pVertex++)->m_vPosition = vecCenter + vec1; + (pVertex++)->m_vPosition = vecCenter + vec2; + (pVertex++)->m_vPosition = vecCenter + vec0; + (pVertex++)->m_vPosition = vecCenter + vec2; + (pVertex++)->m_vPosition = vecCenter + vec3; } m_pLeafVertexBuffer[unLod]->Unlock(); - m_pLeavesUpdatedByCpu[unLod] = true; - } -#else - if (pLeaf->m_bIsActive && m_pLeafVertexBuffer[unLod]) - { - // update the vertex positions - SFVFLeafVertex * pVertex = NULL; - - const UINT VERTEX_NUM = 8192; - if (pLeaf->m_usLeafCount*3>=VERTEX_NUM) - return; - - D3DXVECTOR3 akPosition[VERTEX_NUM]; - D3DXVECTOR3*pkPosition=akPosition; - const float* center=pLeaf->m_pCenterCoords; - for (UINT unLeaf = 0; unLeaf < pLeaf->m_usLeafCount; ++unLeaf) - { - pkPosition[0].x=pLeaf->m_pLeafMapCoords[unLeaf][0]+center[0]; - pkPosition[0].y=pLeaf->m_pLeafMapCoords[unLeaf][1]+center[1]; - pkPosition[0].z=pLeaf->m_pLeafMapCoords[unLeaf][2]+center[2]; - pkPosition[1].x=pLeaf->m_pLeafMapCoords[unLeaf][4]+center[0]; - pkPosition[1].y=pLeaf->m_pLeafMapCoords[unLeaf][5]+center[1]; - pkPosition[1].z=pLeaf->m_pLeafMapCoords[unLeaf][6]+center[2]; - pkPosition[2].x=pLeaf->m_pLeafMapCoords[unLeaf][8]+center[0]; - pkPosition[2].y=pLeaf->m_pLeafMapCoords[unLeaf][9]+center[1]; - pkPosition[2].z=pLeaf->m_pLeafMapCoords[unLeaf][10]+center[2]; - pkPosition[3]=pkPosition[0]; - pkPosition[4]=pkPosition[2]; - pkPosition[5].x=pLeaf->m_pLeafMapCoords[unLeaf][12]+center[0]; - pkPosition[5].y=pLeaf->m_pLeafMapCoords[unLeaf][13]+center[1]; - pkPosition[5].z=pLeaf->m_pLeafMapCoords[unLeaf][14]+center[2]; - pkPosition+=6; - center+=3; - } - - if (SUCCEEDED( - m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast(&pVertex), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK) - )) - { - UINT uVtxCount=pLeaf->m_usLeafCount*6; - for (UINT i = 0; im_pLeafMapCoords[unLeaf]+0, sizeof(D3DXVECTOR3)); - memcpy(vec1, pLeaf->m_pLeafMapCoords[unLeaf]+4, sizeof(D3DXVECTOR3)); - memcpy(vec2, pLeaf->m_pLeafMapCoords[unLeaf]+8, sizeof(D3DXVECTOR3)); - memcpy(vec3, pLeaf->m_pLeafMapCoords[unLeaf]+12, sizeof(D3DXVECTOR3)); - memcpy(vecCenter, pLeaf->m_pCenterCoords + unLeaf * 3, sizeof(D3DXVECTOR3)); - vec0 += vecCenter; - vec1 += vecCenter; - vec2 += vecCenter; - vec3 += vecCenter; - - pVertex[0].m_vPosition = vec0; - pVertex[3].m_vPosition = vec0; - pVertex[1].m_vPosition = vec1; - pVertex[4].m_vPosition = vec2; - pVertex[2].m_vPosition = vec2; - pVertex[5].m_vPosition = vec3; - */ - /* - for (UINT unLeaf = 0; unLeaf < pLeaf->m_usLeafCount; ++unLeaf) - { - D3DXVECTOR3 vecCenter(&(pLeaf->m_pCenterCoords[unLeaf * 3])); - D3DXVECTOR3 vec0(&pLeaf->m_pLeafMapCoords[unLeaf][0]); - D3DXVECTOR3 vec1(&pLeaf->m_pLeafMapCoords[unLeaf][4]); - D3DXVECTOR3 vec2(&pLeaf->m_pLeafMapCoords[unLeaf][8]); - D3DXVECTOR3 vec3(&pLeaf->m_pLeafMapCoords[unLeaf][12]); - - (pVertex++)->m_vPosition = vecCenter + vec0; // vertex 0 - (pVertex++)->m_vPosition = vecCenter + vec1; // vertex 1 - (pVertex++)->m_vPosition = vecCenter + vec2; // vertex 2 - (pVertex++)->m_vPosition = vecCenter + vec0; // vertex 0 - (pVertex++)->m_vPosition = vecCenter + vec2; // vertex 2 - (pVertex++)->m_vPosition = vecCenter + vec3; // vertex 3 - } - */ - m_pLeafVertexBuffer[unLod]->Unlock(); - } } #endif } -#endif -#endif - + PositionTree(); - + // render LODs, if needed - for (UINT unLeafLevel = 0; unLeafLevel < 2; ++unLeafLevel) + for (unsigned int unLeafLevel = 0; unLeafLevel < 2; ++unLeafLevel) { const CSpeedTreeRT::SGeometry::SLeaf* pLeaf = (unLeafLevel == 0) ? - &m_pGeometryCache->m_sLeaves0 : &m_pGeometryCache->m_sLeaves1; - + &m_pGeometryCache->m_sLeaves0 : pLeaf = &m_pGeometryCache->m_sLeaves1; + int unLod = pLeaf->m_nDiscreteLodLevel; if (unLod > -1 && pLeaf->m_bIsActive && pLeaf->m_usLeafCount > 0) @@ -1170,33 +947,16 @@ void CSpeedTreeWrapper::RenderLeaves(void) const } } - -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeWrapper::EndLeafForTreeType - -void CSpeedTreeWrapper::EndLeafForTreeType(void) -{ - // reset copy flags for CPU wind - for (UINT i = 0; i < m_usNumLeafLods; ++i) - m_pLeavesUpdatedByCpu[i] = false; -} - - -/////////////////////////////////////////////////////////////////////// -// CSpeedTreeWrapper::RenderBillboards +void CSpeedTreeWrapper::EndLeafForTreeType(void){} void CSpeedTreeWrapper::RenderBillboards(void) const { - // render billboards in immediate mode (as close as DirectX comes to immediate mode) #ifdef WRAPPER_BILLBOARD_MODE - if (!m_CompositeImageInstance.IsEmpty()) - STATEMANAGER.SetTexture(0, m_CompositeImageInstance.GetTextureReference().GetD3DTexture()); - - PositionTree(); - - struct SBillboardVertex + PositionTree(); + struct SBillboardVertex { float fX, fY, fZ; + DWORD dColor; float fU, fV; }; @@ -1206,17 +966,15 @@ void CSpeedTreeWrapper::RenderBillboards(void) const { const float* pCoords = m_pGeometryCache->m_sBillboard0.m_pCoords; const float* pTexCoords = m_pGeometryCache->m_sBillboard0.m_pTexCoords; - SBillboardVertex sVertex[4] = - { - { pCoords[0], pCoords[1], pCoords[2], pTexCoords[0], pTexCoords[1] }, - { pCoords[3], pCoords[4], pCoords[5], pTexCoords[2], pTexCoords[3] }, - { pCoords[6], pCoords[7], pCoords[8], pTexCoords[4], pTexCoords[5] }, - { pCoords[9], pCoords[10], pCoords[11], pTexCoords[6], pTexCoords[7] }, - }; - - STATEMANAGER.SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1); + SBillboardVertex sVertex[4] = + { + { pCoords[0], pCoords[1], pCoords[2], 0xffffff, pTexCoords[0], pTexCoords[1] }, + { pCoords[3], pCoords[4], pCoords[5], 0xffffff, pTexCoords[2], pTexCoords[3] }, + { pCoords[6], pCoords[7], pCoords[8], 0xffffff, pTexCoords[4], pTexCoords[5] }, + { pCoords[9], pCoords[10], pCoords[11], 0xffffff, pTexCoords[6], pTexCoords[7] }, + }; STATEMANAGER.SetRenderState(D3DRS_ALPHAREF, DWORD(m_pGeometryCache->m_sBillboard0.m_fAlphaTestValue)); - + ms_faceCount += 2; STATEMANAGER.DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, sVertex, sizeof(SBillboardVertex)); } @@ -1226,39 +984,18 @@ void CSpeedTreeWrapper::RenderBillboards(void) const { const float* pCoords = m_pGeometryCache->m_sBillboard1.m_pCoords; const float* pTexCoords = m_pGeometryCache->m_sBillboard1.m_pTexCoords; - SBillboardVertex sVertex[4] = - { - { pCoords[0], pCoords[1], pCoords[2], pTexCoords[0], pTexCoords[1] }, - { pCoords[3], pCoords[4], pCoords[5], pTexCoords[2], pTexCoords[3] }, - { pCoords[6], pCoords[7], pCoords[8], pTexCoords[4], pTexCoords[5] }, - { pCoords[9], pCoords[10], pCoords[11], pTexCoords[6], pTexCoords[7] }, - }; + SBillboardVertex sVertex[4] = + { + { pCoords[0], pCoords[1], pCoords[2], 0xffffff, pTexCoords[0], pTexCoords[1] }, + { pCoords[3], pCoords[4], pCoords[5], 0xffffff, pTexCoords[2], pTexCoords[3] }, + { pCoords[6], pCoords[7], pCoords[8], 0xffffff, pTexCoords[4], pTexCoords[5] }, + { pCoords[9], pCoords[10], pCoords[11], 0xffffff, pTexCoords[6], pTexCoords[7] }, + }; STATEMANAGER.SetRenderState(D3DRS_ALPHAREF, DWORD(m_pGeometryCache->m_sBillboard1.m_fAlphaTestValue)); ms_faceCount += 2; STATEMANAGER.DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, sVertex, sizeof(SBillboardVertex)); } - -#ifdef WRAPPER_RENDER_HORIZONTAL_BILLBOARD - // render horizontal billboard (if enabled) - if (m_pGeometryCache->m_sHorizontalBillboard.m_bIsActive) - { - const float* pCoords = m_pGeometryCache->m_sHorizontalBillboard.m_pCoords; - const float* pTexCoords = m_pGeometryCache->m_sHorizontalBillboard.m_pTexCoords; - SBillboardVertex sVertex[4] = - { - { pCoords[0], pCoords[1], pCoords[2], pTexCoords[0], pTexCoords[1] }, - { pCoords[3], pCoords[4], pCoords[5], pTexCoords[2], pTexCoords[3] }, - { pCoords[6], pCoords[7], pCoords[8], pTexCoords[4], pTexCoords[5] }, - { pCoords[9], pCoords[10], pCoords[11], pTexCoords[6], pTexCoords[7] }, - }; - STATEMANAGER.SetRenderState(D3DRS_ALPHAREF, DWORD(m_pGeometryCache->m_sHorizontalBillboard.m_fAlphaTestValue)); - - ms_faceCount += 2; - STATEMANAGER.DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, sVertex, sizeof(SBillboardVertex)); - } - -#endif #endif } @@ -1311,19 +1048,17 @@ bool CSpeedTreeWrapper::LoadTexture(const char * pFilename, CGraphicImageInstanc void CSpeedTreeWrapper::SetShaderConstants(const float* pMaterial) const { - const float afUsefulConstants[] = - { - m_pSpeedTree->GetLeafLightingAdjustment(), 0.0f, 0.0f, 0.0f, - }; - + const float afUsefulConstants[] = + { + m_pSpeedTree->GetLeafLightingAdjustment(), 0.0f, 0.0f, 0.0f + }; STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_LeafLightingAdjustment, afUsefulConstants, 1); - - const float afMaterial[] = - { - pMaterial[0], pMaterial[1], pMaterial[2], 1.0f, - pMaterial[3], pMaterial[4], pMaterial[5], 1.0f - }; - + + const float afMaterial[] = + { + pMaterial[0], pMaterial[1], pMaterial[2], 1.0f, + pMaterial[3], pMaterial[4], pMaterial[5], 1.0f + }; STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_Material, afMaterial, 2); } @@ -1335,143 +1070,3 @@ void CSpeedTreeWrapper::SetPosition(float x, float y, float z) m_pSpeedTree->SetTreePosition(x, y, z); CGraphicObjectInstance::SetPosition(x, y, z); } - -bool CSpeedTreeWrapper::GetBoundingSphere(D3DXVECTOR3 & v3Center, float & fRadius) -{ - float fX, fY, fZ; - - fX = m_afBoundingBox[3] - m_afBoundingBox[0]; - fY = m_afBoundingBox[4] - m_afBoundingBox[1]; - fZ = m_afBoundingBox[5] - m_afBoundingBox[2]; - - v3Center.x = 0.0f; - v3Center.y = 0.0f; - v3Center.z = fZ * 0.5f; - - fRadius = sqrtf(fX * fX + fY * fY + fZ * fZ) * 0.5f * 0.9f; // 0.9f for reduce size - - D3DXVECTOR3 vec = m_pSpeedTree->GetTreePosition(); - - v3Center+=vec; - - return true; -} - -void CSpeedTreeWrapper::CalculateBBox() -{ - float fX, fY, fZ; - - fX = m_afBoundingBox[3] - m_afBoundingBox[0]; - fY = m_afBoundingBox[4] - m_afBoundingBox[1]; - fZ = m_afBoundingBox[5] - m_afBoundingBox[2]; - - m_v3BBoxMin.x = -fX / 2.0f; - m_v3BBoxMin.y = -fY / 2.0f; - m_v3BBoxMin.z = 0.0f; - m_v3BBoxMax.x = fX / 2.0f; - m_v3BBoxMax.y = fY / 2.0f; - m_v3BBoxMax.z = fZ; - - m_v4TBBox[0] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMin.y, m_v3BBoxMin.z, 1.0f); - m_v4TBBox[1] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMax.y, m_v3BBoxMin.z, 1.0f); - m_v4TBBox[2] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMin.y, m_v3BBoxMin.z, 1.0f); - m_v4TBBox[3] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMax.y, m_v3BBoxMin.z, 1.0f); - m_v4TBBox[4] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMin.y, m_v3BBoxMax.z, 1.0f); - m_v4TBBox[5] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMax.y, m_v3BBoxMax.z, 1.0f); - m_v4TBBox[6] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMin.y, m_v3BBoxMax.z, 1.0f); - m_v4TBBox[7] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMax.y, m_v3BBoxMax.z, 1.0f); - - const D3DXMATRIX & c_rmatTransform = GetTransform(); - - for (DWORD i = 0; i < 8; ++i) - { - D3DXVec4Transform(&m_v4TBBox[i], &m_v4TBBox[i], &c_rmatTransform); - if (0 == i) - { - m_v3TBBoxMin.x = m_v4TBBox[i].x; - m_v3TBBoxMin.y = m_v4TBBox[i].y; - m_v3TBBoxMin.z = m_v4TBBox[i].z; - m_v3TBBoxMax.x = m_v4TBBox[i].x; - m_v3TBBoxMax.y = m_v4TBBox[i].y; - m_v3TBBoxMax.z = m_v4TBBox[i].z; - } - else - { - if (m_v3TBBoxMin.x > m_v4TBBox[i].x) - m_v3TBBoxMin.x = m_v4TBBox[i].x; - if (m_v3TBBoxMax.x < m_v4TBBox[i].x) - m_v3TBBoxMax.x = m_v4TBBox[i].x; - if (m_v3TBBoxMin.y > m_v4TBBox[i].y) - m_v3TBBoxMin.y = m_v4TBBox[i].y; - if (m_v3TBBoxMax.y < m_v4TBBox[i].y) - m_v3TBBoxMax.y = m_v4TBBox[i].y; - if (m_v3TBBoxMin.z > m_v4TBBox[i].z) - m_v3TBBoxMin.z = m_v4TBBox[i].z; - if (m_v3TBBoxMax.z < m_v4TBBox[i].z) - m_v3TBBoxMax.z = m_v4TBBox[i].z; - } - } -} - -// collision detection routines -UINT CSpeedTreeWrapper::GetCollisionObjectCount() -{ - assert(m_pSpeedTree); - return m_pSpeedTree->GetCollisionObjectCount(); -} - -void CSpeedTreeWrapper::GetCollisionObject(UINT nIndex, CSpeedTreeRT::ECollisionObjectType& eType, float* pPosition, float* pDimensions) -{ - assert(m_pSpeedTree); - m_pSpeedTree->GetCollisionObject(nIndex, eType, pPosition, pDimensions); -} - - -const float * CSpeedTreeWrapper::GetPosition() -{ - return m_afPos; -} - -void CSpeedTreeWrapper::GetTreeSize(float & r_fSize, float & r_fVariance) -{ - m_pSpeedTree->GetTreeSize(r_fSize, r_fVariance); -} - -// pscdVector may be null -void CSpeedTreeWrapper::OnUpdateCollisionData(const CStaticCollisionDataVector * /*pscdVector*/) -{ - D3DXMATRIX mat; - D3DXMatrixTranslation(&mat, m_afPos[0], m_afPos[1], m_afPos[2]); - - ///// - for (UINT i = 0; i < GetCollisionObjectCount(); ++i) - { - CSpeedTreeRT::ECollisionObjectType ObjectType; - CStaticCollisionData CollisionData; - - GetCollisionObject(i, ObjectType, (float * )&CollisionData.v3Position, CollisionData.fDimensions); - - if (ObjectType == CSpeedTreeRT::CO_BOX) - continue; - - switch(ObjectType) - { - case CSpeedTreeRT::CO_SPHERE: - CollisionData.dwType = COLLISION_TYPE_SPHERE; - CollisionData.fDimensions[0] = CollisionData.fDimensions[0] /** fSizeRatio*/; - //AddCollision(&CollisionData); - break; - - case CSpeedTreeRT::CO_CYLINDER: - CollisionData.dwType = COLLISION_TYPE_CYLINDER; - CollisionData.fDimensions[0] = CollisionData.fDimensions[0] /** fSizeRatio*/; - CollisionData.fDimensions[1] = CollisionData.fDimensions[1] /** fSizeRatio*/; - //AddCollision(&CollisionData); - break; - - /*case CSpeedTreeRT::CO_BOX: - break;*/ - } - AddCollision(&CollisionData, &mat); - } -} diff --git a/src/SpeedTreeLib/SpeedTreeWrapper.h b/src/SpeedTreeLib/SpeedTreeWrapper.h index ea9e9ce9..94647035 100644 --- a/src/SpeedTreeLib/SpeedTreeWrapper.h +++ b/src/SpeedTreeLib/SpeedTreeWrapper.h @@ -29,17 +29,16 @@ // #pragma once -#pragma warning (disable : 4786) -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // Include files #include "SpeedTreeMaterial.h" -#include +#include -#include -#include -#include +#include +#include +#include #include #include "../eterLib/GrpObjectInstance.h" @@ -57,13 +56,12 @@ #define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } } #endif -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// // class CSpeedTreeWrapper declaration -#pragma warning(push) -#pragma warning(disable:4100) class CSpeedTreeWrapper : public CGraphicObjectInstance { +public: enum { ID = TREE_OBJECT @@ -72,13 +70,15 @@ class CSpeedTreeWrapper : public CGraphicObjectInstance // Collision Data protected: - virtual void OnUpdateCollisionData(const CStaticCollisionDataVector * pscdVector); - virtual void OnUpdateHeighInstance(CAttributeInstance * pAttributeInstance) {} - virtual bool OnGetObjectHeight(float fX, float fY, float * pfHeight) { return false; } + UINT GetCollisionObjectCount(); + void GetCollisionObject(UINT nIndex, CSpeedTreeRT::ECollisionObjectType& eType, float* pPosition, float* pDimensions); + virtual void OnUpdateCollisionData(const CStaticCollisionDataVector* pscdVector); + virtual void OnUpdateHeighInstance(CAttributeInstance* pAttributeInstance) {} + virtual bool OnGetObjectHeight(float fX, float fY, float* pfHeight) { return false; } // Bounding Sphere public: virtual bool GetBoundingSphere(D3DXVECTOR3 & v3Center, float & fRadius); - + public: static bool ms_bSelfShadowOn; @@ -86,62 +86,47 @@ public: // methods from CGraphicObjectInstance virtual void SetPosition(float x, float y, float z); virtual void CalculateBBox(); - - virtual void OnRender(); // Render ½Ã¿¡ ¸Þ¼Òµå, ±×·¯³ª ÇÁ¸®ºä³ª Ư¼öÇÑ °æ¿ì¿¡¸¸ Á÷Á¢ Render ÄÝÀ» ºÎ¸£¸ç - // ±× ÀÌ¿Ü¿¡´Â RenderBranches, RenderFronds µîÀÇ ¸Þ¼Òµå¸¦ CSpeedTreeForest¿¡¼­ È£ÃâÇÑ´Ù. + virtual void OnRender(); + virtual void OnRenderPCBlocker(); virtual void OnBlendRender() {} virtual void OnRenderToShadowMap() {} virtual void OnRenderShadow() {} - virtual void OnRenderPCBlocker(); public: CSpeedTreeWrapper(); virtual ~CSpeedTreeWrapper(); - - const float * GetPosition(); - static void SetVertexShaders(DWORD dwBranchVertexShader, DWORD dwLeafVertexShader); - // geometry - bool LoadTree(const char * pszSptFile, const BYTE * c_pbBlock = NULL, unsigned int uiBlockSize = 0, unsigned int nSeed = 1, float fSize = -1.0f, float fSizeVariance = -1.0f); - const float * GetBoundingBox(void) const { return m_afBoundingBox; } - void GetTreeSize(float & r_fSize, float & r_fVariance); - UINT GetCollisionObjectCount(); - void GetCollisionObject(unsigned int nIndex, CSpeedTreeRT::ECollisionObjectType& eType, float* pPosition, float* pDimensions); + // geometry + bool LoadTree(const char* pszSptFile, const BYTE* c_pbBlock, unsigned int uiBlockSize, unsigned int nSeed = 1, float fSize = -1.0f, float fSizeVariance = -1.0f); + const float* GetBoundingBox(void) const { return m_afBoundingBox; } // rendering void SetupBranchForTreeType(void) const; void SetupFrondForTreeType(void) const; void SetupLeafForTreeType(void) const; void EndLeafForTreeType(void); - -#ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT - void UploadLeafTables(unsigned int uiLocation) const; -#endif - void RenderBranches(void) const; - void RenderFronds(void) const; + void RenderFronds(void) const; void RenderLeaves(void) const; void RenderBillboards(void) const; - + // instancing - CSpeedTreeWrapper ** GetInstances(unsigned int& nCount); - CSpeedTreeWrapper * InstanceOf(void) const { return m_pInstanceOf; } - CSpeedTreeWrapper * MakeInstance(); - void DeleteInstance(CSpeedTreeWrapper * pInstance); - CSpeedTreeRT * GetSpeedTree(void) const { return m_pSpeedTree; } - - // lighting + CSpeedTreeWrapper** GetInstances(unsigned int& nCount); + CSpeedTreeWrapper* InstanceOf(void) const { return m_pInstanceOf; } + CSpeedTreeWrapper* MakeInstance(void); + void DeleteInstance(CSpeedTreeWrapper* pInstance); + CSpeedTreeRT* GetSpeedTree(void) const { return m_pSpeedTree; } + + // lighting const CSpeedTreeMaterial & GetBranchMaterial(void) const { return m_cBranchMaterial; } const CSpeedTreeMaterial & GetFrondMaterial(void) const { return m_cFrondMaterial; } const CSpeedTreeMaterial & GetLeafMaterial(void) const { return m_cLeafMaterial; } float GetLeafLightingAdjustment(void) const { return m_pSpeedTree->GetLeafLightingAdjustment( ); } - - // wind - void SetWindStrength(float fStrength) { m_pSpeedTree->SetWindStrength(fStrength); } + + // wind void Advance(void); - + // utility - LPDIRECT3DTEXTURE8 GetBranchTexture(void) const; void CleanUpMemory(void); private: @@ -166,20 +151,21 @@ private: CSpeedTreeRT::SGeometry* m_pGeometryCache; // cache for pulling geometry from SpeedTree avoids lots of reallocation // branch buffers - LPDIRECT3DVERTEXBUFFER8 m_pBranchVertexBuffer; // branch vertex buffer + LPDIRECT3DVERTEXBUFFER9 m_pBranchVertexBuffer; // branch vertex buffer unsigned int m_unBranchVertexCount; // number of vertices in branches - LPDIRECT3DINDEXBUFFER8 m_pBranchIndexBuffer; // branch index buffer + LPDIRECT3DINDEXBUFFER9 m_pBranchIndexBuffer; // branch index buffer unsigned short* m_pBranchIndexCounts; // number of indexes per branch LOD level - + // frond buffers - LPDIRECT3DVERTEXBUFFER8 m_pFrondVertexBuffer; // frond vertex buffer + LPDIRECT3DVERTEXBUFFER9 m_pFrondVertexBuffer; // frond vertex buffer unsigned int m_unFrondVertexCount; // number of vertices in frond - LPDIRECT3DINDEXBUFFER8 m_pFrondIndexBuffer; // frond index buffer - unsigned short* m_pFrondIndexCounts; // number of indexes per frond LOD level - + unsigned int m_unNumFrondLods; + LPDIRECT3DINDEXBUFFER9* m_pFrondIndexBuffers; + unsigned short* m_pFrondIndexCounts; + // leaf buffers unsigned short m_usNumLeafLods; // the number of leaf LODs - LPDIRECT3DVERTEXBUFFER8* m_pLeafVertexBuffer; // leaf vertex buffer + LPDIRECT3DVERTEXBUFFER9* m_pLeafVertexBuffer; // leaf vertex buffer bool* m_pLeavesUpdatedByCpu; // stores which LOD's have been updated already per frame // tree properties @@ -196,8 +182,8 @@ private: CGraphicImageInstance m_ShadowImageInstance; // shadow texture object (used if shadows are enabled) CGraphicImageInstance m_CompositeImageInstance; - static DWORD ms_dwBranchVertexShader; - static DWORD ms_dwLeafVertexShader; -}; + static unsigned int m_unNumWrappersActive; -#pragma warning(pop) + static LPDIRECT3DVERTEXSHADER9 ms_lpBranchVertexShader; + static LPDIRECT3DVERTEXSHADER9 ms_lpLeafVertexShader; +}; diff --git a/src/SpeedTreeLib/StdAfx.h b/src/SpeedTreeLib/StdAfx.h index 3340daf1..c708c122 100644 --- a/src/SpeedTreeLib/StdAfx.h +++ b/src/SpeedTreeLib/StdAfx.h @@ -1,19 +1,4 @@ #pragma once -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers - #include -//#include - -//#include "Forest.h" -#include "SpeedTreeForestDirectX8.h" - -// Armadillo nanomite protection -#if !defined(NANOBEGIN) && !defined(NANOEND) - #ifdef _DEBUG - #define NANOBEGIN - #define NANOEND - #else - #include - #endif -#endif +#include "CSpeedTreeDirectX.h" diff --git a/src/SpeedTreeLib/VertexShaders.h b/src/SpeedTreeLib/VertexShaders.h index 6d5f2f9d..9d011182 100644 --- a/src/SpeedTreeLib/VertexShaders.h +++ b/src/SpeedTreeLib/VertexShaders.h @@ -1,332 +1,84 @@ -/////////////////////////////////////////////////////////////////////// -// SpeedTreeRT DirectX Example -// -// (c) 2003 IDV, Inc. -// -// This example demonstrates how to render trees using SpeedTreeRT -// and DirectX. Techniques illustrated include ".spt" file parsing, -// static lighting, dynamic lighting, LOD implementation, cloning, -// instancing, and dynamic wind effects. -// -// -// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION *** -// -// This software is supplied under the terms of a license agreement or -// nondisclosure agreement with Interactive Data Visualization and may -// not be copied or disclosed except in accordance with the terms of -// that agreement. -// -// Copyright (c) 2001-2003 IDV, Inc. -// All Rights Reserved. -// -// IDV, Inc. -// 1233 Washington St. Suite 610 -// Columbia, SC 29201 -// Voice: (803) 799-1699 -// Fax: (803) 931-0320 -// Web: http://www.idvinc.com - -/////////////////////////////////////////////////////////////////////// -// Includes - #pragma once +#include +#include #include "SpeedTreeConfig.h" #include #include -/////////////////////////////////////////////////////////////////////// -// Branch & Frond Vertex Formats - -static DWORD D3DFVF_SPEEDTREE_BRANCH_VERTEX = - D3DFVF_XYZ | // always have the position - #ifdef WRAPPER_USE_DYNAMIC_LIGHTING // precomputed colors or geometric normals - D3DFVF_NORMAL | - #else - D3DFVF_DIFFUSE | - #endif - #ifdef WRAPPER_RENDER_SELF_SHADOWS - D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1) // shadow texture coordinates - #else - D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0) // always have first texture layer coords - #endif - #ifdef WRAPPER_USE_GPU_WIND - | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE2(2) // GPU Only - wind weight and index passed in second texture layer - #endif - ; - -/////////////////////////////////////////////////////////////////////// -// FVF Branch Vertex Structure +static DWORD D3DFVF_SPEEDTREE_BRANCH_VERTEX = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1); struct SFVFBranchVertex { - D3DXVECTOR3 m_vPosition; // Always Used -#ifdef WRAPPER_USE_DYNAMIC_LIGHTING - D3DXVECTOR3 m_vNormal; // Dynamic Lighting Only -#else - DWORD m_dwDiffuseColor; // Static Lighting Only -#endif - FLOAT m_fTexCoords[2]; // Always Used -#ifdef WRAPPER_RENDER_SELF_SHADOWS - FLOAT m_fShadowCoords[2]; // Texture coordinates for the shadows -#endif -#ifdef WRAPPER_USE_GPU_WIND - FLOAT m_fWindIndex; // GPU Only - FLOAT m_fWindWeight; -#endif + D3DXVECTOR3 m_vPosition; + DWORD m_dwDiffuseColor; + FLOAT m_fTexCoords[2]; + FLOAT m_fShadowCoords[2]; }; - -/////////////////////////////////////////////////////////////////////// -// Branch/Frond Vertex Program - -static const char g_achSimpleVertexProgram[] = +static const char g_achSimpleVertexProgram[] = { - "vs.1.1\n" // identity shader version - - "mov oT0.xy, v7\n" // always pass texcoord0 through - - #ifdef WRAPPER_RENDER_SELF_SHADOWS - "mov oT1.xy, v8\n" // pass shadow texcoords through if enabled - #endif - - // retrieve and convert wind matrix index - "mov a0.x, v9.x\n" - - // perform wind interpolation - "m4x4 r1, v0, c[54+a0.x]\n" // compute full wind effect - "sub r2, r1, v0\n" // compute difference between full wind and none - "mov r3.x, v9.y\n" // mad can't access two v's at once, use r3.x as tmp - "mad r1, r2, r3.x, v0\n" // perform interpolation - - "add r2, c[52], r1\n" // translate to tree's position - "m4x4 oPos, r2, c[0]\n" // project to screen - - #ifdef WRAPPER_USE_FOG - "dp4 r1, r2, c[2]\n" // find distance to vertex - "sub r2.x, c[85].y, r1.z\n" // linear fogging - "mul oFog, r2.x, c[85].z\n" // write to fog register - #endif - - #ifdef WRAPPER_USE_STATIC_LIGHTING - "mov oD0, v5\n" // pass color through - #else - "mov r1, c[74]\n" // can only use one const register per instruction - "mul r5, c[73], r1\n" // diffuse values - - "mov r1, c[75]\n" // can only use one const register per instruction - "mul r4, c[72], r1\n" // ambient values - - "dp3 r2, v3, c[71]\n" // dot light direction with normal -// "max r2.x, r2.x, c[70].x\n" // limit it - "mad oD0, r2.x, r5, r4\n" // compute the final color - #endif + "vs.1.1\n" + "dcl_position v0\n" + "dcl_color v5\n" + "dcl_texcoord0 v7\n" + "dcl_texcoord1 v8\n" + "mov oT0.xy, v7\n" + "mov oT1.xy, v8\n" + "mov a0.x, v8.x\n" + "m4x4 r1, v0, c[54+a0.x]\n" + "sub r2, r1, v0\n" + "mov r3.x, v8.y\n" + "mad r1, r2, r3.x, v0\n" + "add r2, c[52], r1\n" + "m4x4 oPos, r2, c[0]\n" +#ifdef WRAPPER_USE_FOG + "dp4 r1, r2, c[2]\n" + "sub r2.x, c[85].y, r1.z\n" + "mul oFog, r2.x, c[85].z\n" +#endif + "mov oD0, v5\n" }; - -/////////////////////////////////////////////////////////////////////// -// LoadBranchShader - -static DWORD LoadBranchShader(LPDIRECT3DDEVICE8 pDx) +inline LPDIRECT3DVERTEXSHADER9 LoadBranchShader(LPDIRECT3DDEVICE9 pDx) { - #ifndef WRAPPER_USE_GPU_WIND - return D3DFVF_SPEEDTREE_BRANCH_VERTEX; - #endif - - // branch shader declaration - DWORD pBranchShaderDecl[] = - { - D3DVSD_STREAM(0), - D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), - #ifdef WRAPPER_USE_DYNAMIC_LIGHTING - D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT3), - #else - D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), - #endif - D3DVSD_REG(D3DVSDE_TEXCOORD0, D3DVSDT_FLOAT2), - #ifdef WRAPPER_RENDER_SELF_SHADOWS - D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2), - #endif - #ifdef WRAPPER_USE_GPU_WIND - D3DVSD_REG(D3DVSDE_TEXCOORD2, D3DVSDT_FLOAT2), - #endif - D3DVSD_END( ) - }; - - // assemble shader - DWORD dwShader; - LPD3DXBUFFER pCode, pError; - - if (D3DXAssembleShader(g_achSimpleVertexProgram, sizeof(g_achSimpleVertexProgram) - 1, 0, NULL, &pCode, &pError) == D3D_OK) - { - if (pDx->CreateVertexShader(pBranchShaderDecl, (DWORD*) pCode->GetBufferPointer( ), &dwShader, 0) != D3D_OK) - { - char szError[1024]; - sprintf(szError, "Failed to create branch vertex shader."); - MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP); - } - } - else - { - char szError[1024]; - sprintf(szError, "Failed to assemble branch vertex shader.\nThe error reported is [ %s ].\n", pError->GetBufferPointer( )); - MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP); - } - - if (pCode) - pCode->Release(); - - return dwShader; + UNREFERENCED_PARAMETER(pDx); + return NULL; } -/////////////////////////////////////////////////////////////////////// -// Leaf Vertex Formats - -static DWORD D3DFVF_SPEEDTREE_LEAF_VERTEX = - D3DFVF_XYZ | // always have the position - #ifdef WRAPPER_USE_DYNAMIC_LIGHTING // precomputed colors or geometric normals - D3DFVF_NORMAL | - #else - D3DFVF_DIFFUSE | - #endif - D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0) // always have first texture layer coords - #if defined WRAPPER_USE_GPU_WIND || defined WRAPPER_USE_GPU_LEAF_PLACEMENT - | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE4(2) // GPU Only - wind weight and index passed in second texture layer - #endif - ; - - -/////////////////////////////////////////////////////////////////////// -// FVF Leaf Vertex Structure +static DWORD D3DFVF_SPEEDTREE_LEAF_VERTEX = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE2(1) | D3DFVF_TEXCOORDSIZE2(2) | D3DFVF_TEX1; struct SFVFLeafVertex { - D3DXVECTOR3 m_vPosition; // Always Used - #ifdef WRAPPER_USE_DYNAMIC_LIGHTING - D3DXVECTOR3 m_vNormal; // Dynamic Lighting Only - #else - DWORD m_dwDiffuseColor; // Static Lighting Only - #endif - FLOAT m_fTexCoords[2]; // Always Used - #if defined WRAPPER_USE_GPU_WIND || defined WRAPPER_USE_GPU_LEAF_PLACEMENT - FLOAT m_fWindIndex; // Only used when GPU is involved - FLOAT m_fWindWeight; - FLOAT m_fLeafPlacementIndex; - FLOAT m_fLeafScalarValue; - #endif + D3DXVECTOR3 m_vPosition; + DWORD m_dwDiffuseColor; + FLOAT m_fTexCoords[2]; }; - -/////////////////////////////////////////////////////////////////////// -// Leaf Vertex Program - -static const char g_achLeafVertexProgram[] = +static const char g_achLeafVertexProgram[] = { - "vs.1.1\n" // identity shader version + "vs.1.1\n" - "mov oT0.xy, v7\n" // always pass texcoord0 through - - #ifdef WRAPPER_USE_GPU_WIND - // retrieve and convert wind matrix index - "mov a0.x, v9.x\n" + "dcl_position v0\n" + "dcl_color v5\n" + "dcl_texcoord0 v7\n" + "dcl_texcoord1 v8\n" + "dcl_texcoord2 v9\n" + "mov oT0.xy, v7\n" + "mov r0, v0\n" + "add r0, c[52], r0\n" + "m4x4 oPos, r0, c[0]\n" - // perform wind interpolation - "m4x4 r1, v0, c[54+a0.x]\n" // compute full wind effect - "sub r2, r1, v0\n" // compute difference between full wind and none - "mov r3.x, v9.y\n" // mad can't access two v's at once, use r3.x as tmp - "mad r0, r2, r3.x, v0\n" // perform interpolation - #else - "mov r0, v0\n" // wind already handled, pass the vertex through - #endif - - #ifdef WRAPPER_USE_GPU_LEAF_PLACEMENT - "mov a0.x, v9.z\n" // place the leaves - "mul r1, c[a0.x], v9.w\n" - "add r0, r1, r0\n" - #endif - - "add r0, c[52], r0\n" // translate to tree's position - "m4x4 oPos, r0, c[0]\n" // project to screen - - #ifdef WRAPPER_USE_FOG - "dp4 r1, r0, c[2]\n" // find distance to vertex - "sub r2.x, c[85].y, r1.z\n" // - "mul oFog, r2.x, c[85].z\n" - #endif - - #ifdef WRAPPER_USE_STATIC_LIGHTING - "mov oD0, v5\n" // pass color through - #else - "mov r1, c[74]\n" // can only use one const register per instruction - "mul r5, c[73], r1\n" // diffuse values - - "mov r1, c[75]\n" // can only use one const register per instruction - "mul r4, c[72], r1\n" // ambient values - - "dp3 r2.x, v3, c[71]\n" // dot light direction with normal - "max r2.x, r2.x, c[70].x\n" // limit it - "mad oD0, r2.x, r5, r4\n" // compute the final color - #endif +#ifdef WRAPPER_USE_FOG + "dp4 r1, r0, c[2]\n" + "sub r2.x, c[85].y, r1.z\n" + "mul oFog, r2.x, c[85].z\n" +#endif + "mov oD0, v5\n" }; - -/////////////////////////////////////////////////////////////////////// -// LoadLeafShader - -static DWORD LoadLeafShader(LPDIRECT3DDEVICE8 pDx) +inline LPDIRECT3DVERTEXSHADER9 LoadLeafShader(LPDIRECT3DDEVICE9 pDx) { - DWORD dwShader = D3DFVF_SPEEDTREE_LEAF_VERTEX; - - #if defined WRAPPER_USE_GPU_LEAF_PLACEMENT || defined WRAPPER_USE_GPU_WIND - - // leaf shader declaration - DWORD pLeafShaderDecl[ ] = - { - D3DVSD_STREAM(0), - D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), - #ifdef WRAPPER_USE_DYNAMIC_LIGHTING - D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT3), - #else - D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), - #endif - D3DVSD_REG(D3DVSDE_TEXCOORD0, D3DVSDT_FLOAT2), - D3DVSD_REG(D3DVSDE_TEXCOORD2, D3DVSDT_FLOAT4), - D3DVSD_END( ) - }; - - // assemble shader - LPD3DXBUFFER pCode, pError; - - if (D3DXAssembleShader(g_achLeafVertexProgram, sizeof(g_achLeafVertexProgram) - 1, 0, NULL, &pCode, &pError) == D3D_OK) - { - if (pDx->CreateVertexShader(pLeafShaderDecl, (DWORD*) pCode->GetBufferPointer( ), &dwShader, 0) != D3D_OK) - { - Tracef("Failed to create leaf vertex shader."); - /* - char szError[1024]; - sprintf(szError, "Failed to create leaf vertex shader."); - MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP); - */ - } - } - else - { - Tracef("Failed to assemble leaf vertex shader. The error reported is [ %s ].\n", pError->GetBufferPointer( )); - /* - char szError[1024]; - sprintf(szError, "Failed to assemble leaf vertex shader. The error reported is [ %s ].\n", pError->GetBufferPointer( )); - MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP); - */ - } - - if (pCode) - pCode->Release( ); - - #else - - dwShader = D3DFVF_SPEEDTREE_LEAF_VERTEX; - - #endif - - return dwShader; + LPDIRECT3DVERTEXSHADER9 dwShader = NULL; + return dwShader; } - \ No newline at end of file +static DWORD D3DFVF_SPEEDTREE_BILLBOARD_VERTEX = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; diff --git a/src/SphereLib/StdAfx.h b/src/SphereLib/StdAfx.h index 9a69b878..841c21ef 100644 --- a/src/SphereLib/StdAfx.h +++ b/src/SphereLib/StdAfx.h @@ -4,8 +4,8 @@ //#define SPHERELIB_STRICT //#include -#include -#include +#include +#include #include #include diff --git a/src/UserInterface/PythonApplication.cpp b/src/UserInterface/PythonApplication.cpp index 00bb8318..a6b2b8a6 100644 --- a/src/UserInterface/PythonApplication.cpp +++ b/src/UserInterface/PythonApplication.cpp @@ -902,9 +902,9 @@ bool CPythonApplication::CreateDevice(int width, int height, int Windowed, int b return false; case CGraphicDevice::CREATE_NO_DIRECTX: - //PyErr_SetString(PyExc_RuntimeError, "DirectX 8.1 or greater required to run game"); + //PyErr_SetString(PyExc_RuntimeError, "DirectX 9 or greater required to run game"); SET_EXCEPTION(CREATE_NO_DIRECTX); - TraceError("CreateDevice: DirectX 8.1 or greater required to run game"); + TraceError("CreateDevice: DirectX 9 or greater required to run game"); return false; case CGraphicDevice::CREATE_DEVICE: diff --git a/src/UserInterface/PythonApplicationLogo.cpp b/src/UserInterface/PythonApplicationLogo.cpp index 16f53ce6..5452b7ce 100644 --- a/src/UserInterface/PythonApplicationLogo.cpp +++ b/src/UserInterface/PythonApplicationLogo.cpp @@ -113,7 +113,7 @@ int CPythonApplication::OnLogoUpdate() { m_bLogoError = true; - LPDIRECT3DTEXTURE8 tex = m_pLogoTex->GetD3DTexture(); + LPDIRECT3DTEXTURE9 tex = m_pLogoTex->GetD3DTexture(); D3DLOCKED_RECT rt; ZeroMemory(&rt, sizeof(rt)); @@ -158,7 +158,7 @@ int CPythonApplication::OnLogoUpdate() } // Áغñ‰çÀ¸¸é ¹öÆÛ¿¡¼­ ÅؽºÃÄ·Î º¹»çÇؿ´Ù. - LPDIRECT3DTEXTURE8 tex = m_pLogoTex->GetD3DTexture(); + LPDIRECT3DTEXTURE9 tex = m_pLogoTex->GetD3DTexture(); D3DLOCKED_RECT rt; ZeroMemory(&rt, sizeof(rt)); @@ -197,8 +197,8 @@ void CPythonApplication::OnLogoRender() { if(!m_pLogoTex->IsEmpty() && !m_bLogoError && true == bInitializedLogo) { - STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); m_pLogoTex->SetTextureStage(0); CPythonGraphic::instance().RenderTextureBox(m_nLeft, m_nTop, m_nRight, m_nBottom, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f); } @@ -235,8 +235,8 @@ void CPythonApplication::OnLogoClose() if(m_pFilterSG != NULL) m_pFilterSG->Release(); m_pFilterSG = NULL; if(m_pGraphBuilder != NULL) m_pGraphBuilder->Release(); m_pGraphBuilder = NULL; - STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_POINT); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_POINT); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); } \ No newline at end of file diff --git a/src/UserInterface/PythonMiniMap.cpp b/src/UserInterface/PythonMiniMap.cpp index 3c4e68f0..6d794b04 100644 --- a/src/UserInterface/PythonMiniMap.cpp +++ b/src/UserInterface/PythonMiniMap.cpp @@ -264,17 +264,17 @@ void CPythonMiniMap::Render(float fScreenX, float fScreenY) __SetPosition(); } - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); STATEMANAGER.SaveTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION); STATEMANAGER.SaveTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); - STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); @@ -295,14 +295,14 @@ void CPythonMiniMap::Render(float fScreenX, float fScreenY) STATEMANAGER.SetTexture(1, m_MiniMapFilterGraphicImageInstance.GetTexturePointer()->GetD3DTexture()); STATEMANAGER.SetTransform(D3DTS_TEXTURE1, &m_matMiniMapCover); - STATEMANAGER.SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1); + STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_TEX1); STATEMANAGER.SetStreamSource(0, m_VertexBuffer.GetD3DVertexBuffer(), 20); STATEMANAGER.SetIndices(m_IndexBuffer.GetD3DIndexBuffer(), 0); STATEMANAGER.SetTransform(D3DTS_WORLD, &m_matWorld); for (BYTE byTerrainNum = 0; byTerrainNum < AROUND_AREA_NUM; ++byTerrainNum) { - LPDIRECT3DTEXTURE8 pMiniMapTexture = m_lpMiniMapTexture[byTerrainNum]; + LPDIRECT3DTEXTURE9 pMiniMapTexture = m_lpMiniMapTexture[byTerrainNum]; STATEMANAGER.SetTexture(0, pMiniMapTexture); if (pMiniMapTexture) { @@ -333,12 +333,12 @@ void CPythonMiniMap::Render(float fScreenX, float fScreenY) STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLORARG2); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLOROP); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSV); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSV); STATEMANAGER.RestoreTextureStageState(1, D3DTSS_TEXCOORDINDEX); STATEMANAGER.RestoreTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSU); - STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSV); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSU); + STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSV); SetDiffuseOperation(); STATEMANAGER.SetTransform(D3DTS_WORLD, &m_matIdentity); @@ -427,12 +427,12 @@ void CPythonMiniMap::Render(float fScreenX, float fScreenY) STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLORARG2); STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLOROP); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MIPFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MINFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MAGFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MIPFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MINFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MAGFILTER); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); // ij¸¯ÅÍ ¸¶Å© CInstanceBase * pkInst = CPythonCharacterManager::Instance().GetMainInstancePtr(); @@ -476,8 +476,8 @@ void CPythonMiniMap::Render(float fScreenX, float fScreenY) m_MiniMapCameraraphicImageInstance.SetRotation(pkCmrCur->GetRoll()); m_MiniMapCameraraphicImageInstance.Render(); } - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MINFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MAGFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MINFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MAGFILTER); } void CPythonMiniMap::SetScale(float fScale) @@ -969,8 +969,8 @@ void CPythonMiniMap::RenderAtlas(float fScreenX, float fScreenY) } STATEMANAGER.SetTransform(D3DTS_WORLD, &m_matWorldAtlas); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_POINT); - STATEMANAGER.SaveTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); + STATEMANAGER.SaveSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); m_AtlasImageInstance.Render(); STATEMANAGER.SaveRenderState(D3DRS_TEXTUREFACTOR, 0xFFFFFFFF); @@ -998,8 +998,8 @@ void CPythonMiniMap::RenderAtlas(float fScreenX, float fScreenY) ++m_AtlasMarkInfoVectorIterator; } - STATEMANAGER.SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); - STATEMANAGER.SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + STATEMANAGER.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, CInstanceBase::GetIndexedNameColor(CInstanceBase::NAMECOLOR_WAYPOINT)); m_AtlasMarkInfoVectorIterator = m_AtlasWayPointInfoVector.begin(); for (; m_AtlasMarkInfoVectorIterator != m_AtlasWayPointInfoVector.end(); ++m_AtlasMarkInfoVectorIterator) @@ -1030,8 +1030,8 @@ void CPythonMiniMap::RenderAtlas(float fScreenX, float fScreenY) if ((ELTimer_GetMSec() / 500) % 2) m_AtlasPlayerMark.Render(); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MINFILTER); - STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MAGFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MINFILTER); + STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MAGFILTER); STATEMANAGER.SetTransform(D3DTS_WORLD, &m_matIdentity); { diff --git a/src/UserInterface/PythonMiniMap.h b/src/UserInterface/PythonMiniMap.h index dbbe48ac..e6bf29b1 100644 --- a/src/UserInterface/PythonMiniMap.h +++ b/src/UserInterface/PythonMiniMap.h @@ -181,7 +181,7 @@ class CPythonMiniMap : public CScreen, public CSingleton float m_fMiniMapRadius; // ¸Ê ±×¸²... - LPDIRECT3DTEXTURE8 m_lpMiniMapTexture[AROUND_AREA_NUM]; + LPDIRECT3DTEXTURE9 m_lpMiniMapTexture[AROUND_AREA_NUM]; // ¹Ì´Ï¸Ê Ä¿¹ö CGraphicImageInstance m_MiniMapFilterGraphicImageInstance; diff --git a/src/UserInterface/PythonSystem.cpp b/src/UserInterface/PythonSystem.cpp index ec37bae0..ce02a8a3 100644 --- a/src/UserInterface/PythonSystem.cpp +++ b/src/UserInterface/PythonSystem.cpp @@ -36,21 +36,21 @@ void CPythonSystem::GetDisplaySettings() memset(m_ResolutionList, 0, sizeof(TResolution) * RESOLUTION_MAX_NUM); m_ResolutionCount = 0; - LPDIRECT3D8 lpD3D = CPythonGraphic::Instance().GetD3D(); + LPDIRECT3D9 lpD3D = CPythonGraphic::Instance().GetD3D(); - D3DADAPTER_IDENTIFIER8 d3dAdapterIdentifier; + D3DADAPTER_IDENTIFIER9 d3dAdapterIdentifier; D3DDISPLAYMODE d3ddmDesktop; - lpD3D->GetAdapterIdentifier(0, D3DENUM_NO_WHQL_LEVEL, &d3dAdapterIdentifier); - lpD3D->GetAdapterDisplayMode(0, &d3ddmDesktop); + lpD3D->GetAdapterIdentifier(D3DADAPTER_DEFAULT, D3DENUM_WHQL_LEVEL, &d3dAdapterIdentifier); + lpD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddmDesktop); // ÀÌ ¾îµªÅÍ°¡ °¡Áö°í ÀÖ´Â µð½ºÇ÷¡ÀÌ ¸ðµå°¹¼ö¸¦ ³ª¿­ÇÑ´Ù.. - DWORD dwNumAdapterModes = lpD3D->GetAdapterModeCount(0); + DWORD dwNumAdapterModes = lpD3D->GetAdapterModeCount(D3DADAPTER_DEFAULT, D3DFMT_UNKNOWN); for (UINT iMode = 0; iMode < dwNumAdapterModes; iMode++) { D3DDISPLAYMODE DisplayMode; - lpD3D->EnumAdapterModes(0, iMode, &DisplayMode); + lpD3D->EnumAdapterModes(D3DADAPTER_DEFAULT, D3DFMT_UNKNOWN, iMode, &DisplayMode); DWORD bpp = 0; // 800 600 ÀÌ»ó¸¸ °É·¯³½´Ù. diff --git a/src/UserInterface/UserInterface.cpp b/src/UserInterface/UserInterface.cpp index 62aa51d3..122f191c 100644 --- a/src/UserInterface/UserInterface.cpp +++ b/src/UserInterface/UserInterface.cpp @@ -15,8 +15,10 @@ #include "../eterBase/CPostIt.h" extern "C" { -extern int _fltused; -volatile int _AVOID_FLOATING_POINT_LIBRARY_BUG = _fltused; + extern int32_t _fltused; + volatile int32_t _AVOID_FLOATING_POINT_LIBRARY_BUG = _fltused; + __declspec(dllexport) uint32_t NvOptimusEnablement = 0x00000001; + __declspec(dllexport) int32_t AmdPowerXpressRequestHighPerformance = 1; }; #pragma comment(linker, "/NODEFAULTLIB:libci.lib") diff --git a/src/UserInterface/UserInterface.vcxproj b/src/UserInterface/UserInterface.vcxproj index 84318307..f0ffb321 100644 --- a/src/UserInterface/UserInterface.vcxproj +++ b/src/UserInterface/UserInterface.vcxproj @@ -177,7 +177,7 @@ Disabled - $(SolutionDir)extern\include;%(AdditionalIncludeDirectories) + $(SolutionDir)extern\include;$(SolutionDir)extern\include\directx;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;USE_LOD;HAVE_SNPRINTF;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug @@ -222,7 +222,7 @@ Disabled - $(SolutionDir)extern\include;%(AdditionalIncludeDirectories) + $(SolutionDir)extern\include;$(SolutionDir)extern\include\directx;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;USE_LOD;DUNGEON_WORK;%(PreprocessorDefinitions) MultiThreaded Use @@ -273,7 +273,7 @@ OnlyExplicitInline Size true - $(SolutionDir)extern\include;%(AdditionalIncludeDirectories) + $(SolutionDir)extern\include;$(SolutionDir)extern\include\directx;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;USE_LOD;__VTUNE__;%(PreprocessorDefinitions) true MultiThreaded diff --git a/src/vcpkg.json b/src/vcpkg.json index 6998ae28..377ede68 100644 --- a/src/vcpkg.json +++ b/src/vcpkg.json @@ -18,6 +18,10 @@ { "name": "python2", "version>=": "2.7.18#3" + }, + { + "name": "directxsdk", + "version>=": "jun10" } ] } \ No newline at end of file