ported to DX9

This commit is contained in:
d1str4ught
2025-08-19 03:18:56 +02:00
parent 97a82baa4a
commit e87b6fc67b
130 changed files with 19303 additions and 10435 deletions

View File

@@ -52,7 +52,7 @@ bool CBoundaryShapeManager::LoadBsfFile(const char* pszFilename)
bool bSuccess = true;
try
{
FILE* pFile = fopen(pszFilename, "rb");
FILE* pFile=fopen(pszFilename, "rb");
if (pFile)
{
// number of boundary shapes

View File

@@ -56,7 +56,7 @@ virtual float Height(float fX, float fY, float* pNormal) const;
CMapOutdoor * m_pMapOutdoor;
LPDIRECT3DTEXTURE8 m_lpD3DTexure8;
LPDIRECT3DTEXTURE9 m_lpD3DTexure8;
CGraphicImageInstance m_GrassImageInstance;
};

View File

@@ -7,8 +7,9 @@
#include <vector>
#include "../eterBase/Filename.h"
#include "../eterBase/MappedFile.h"
#include "../eterPack/EterPackManager.h"
#include "EterBase/MappedFile.h"
#include "EterPack/EterPackManager.h"
#include "SpeedTreeForest.h"
#include "SpeedTreeConfig.h"
@@ -78,20 +79,18 @@ BOOL CSpeedTreeForest::GetMainTree(DWORD dwCRC, CSpeedTreeWrapper ** ppMainTree,
CMappedFile file;
LPCVOID c_pvData;
// NOTE : 파일이 없을때는 return FALSE 아닌가요? - [levites]
if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData))
return FALSE;
pTree = new CSpeedTreeWrapper;
if (!pTree->LoadTree(c_pszFileName, (const BYTE *) c_pvData, file.Size()))
if (!pTree->LoadTree(c_pszFileName, (const BYTE*)c_pvData, file.Size()))
{
delete pTree;
return FALSE;
}
m_pMainTreeMap.insert(std::map<DWORD, CSpeedTreeWrapper *>::value_type(dwCRC, pTree));
m_pMainTreeMap.insert(std::map<DWORD, CSpeedTreeWrapper*>::value_type(dwCRC, pTree));
file.Destroy();
}
@@ -126,7 +125,7 @@ void CSpeedTreeForest::DeleteInstance(CSpeedTreeWrapper * pInstance)
void CSpeedTreeForest::UpdateSystem(float fCurrentTime)
{
// 업데이트 할 때 한번
// ¾÷µ¥ÀÌÆ® ÇÒ ¶§ Çѹø
static float fLastTime = fCurrentTime;
float fElapsedTime = fCurrentTime - fLastTime;
CSpeedTreeRT::SetTime(fElapsedTime);

View File

@@ -38,6 +38,8 @@
#include <vector>
#include <map>
#include "../EterBase/CRC32.h"
///////////////////////////////////////////////////////////////////////
// Render bit vector

View File

@@ -30,9 +30,9 @@
#include "StdAfx.h"
#include <stdio.h>
#include <d3d8.h>
#include <d3d8types.h>
#include <d3dx8.h>
#include <d3d9.h>
#include <d3d9types.h>
#include <d3dx9.h>
#include "../eterBase/Timer.h"
#include "../eterlib/StateManager.h"
@@ -62,7 +62,6 @@ CSpeedTreeForestDirectX8::~CSpeedTreeForestDirectX8()
// CSpeedTreeForestDirectX8::InitVertexShaders
bool CSpeedTreeForestDirectX8::InitVertexShaders(void)
{
NANOBEGIN
// load the vertex shaders
if (!m_dwBranchVertexShader)
m_dwBranchVertexShader = LoadBranchShader(m_pDx);
@@ -76,11 +75,10 @@ bool CSpeedTreeForestDirectX8::InitVertexShaders(void)
return true;
}
NANOEND
return false;
}
bool CSpeedTreeForestDirectX8::SetRenderingDevice(LPDIRECT3DDEVICE8 lpDevice)
bool CSpeedTreeForestDirectX8::SetRenderingDevice(LPDIRECT3DDEVICE9 lpDevice)
{
m_pDx = lpDevice;
@@ -117,7 +115,7 @@ void CSpeedTreeForestDirectX8::UploadWindMatrix(UINT uiLocation, const float* pM
STATEMANAGER.SetVertexShaderConstant(uiLocation, pMatrix, 4);
}
void CSpeedTreeForestDirectX8::UpdateCompundMatrix(const D3DXVECTOR3 & c_rEyeVec, const D3DXMATRIX & c_rmatView, const D3DXMATRIX & c_rmatProj)
void CSpeedTreeForestDirectX8::UpdateCompundMatrix(const D3DXVECTOR3& c_rEyeVec, const D3DXMATRIX& c_rmatView, const D3DXMATRIX& c_rmatProj)
{
// setup composite matrix for shader
D3DXMATRIX matBlend;
@@ -194,16 +192,16 @@ void CSpeedTreeForestDirectX8::Render(unsigned long ulRenderBitVector)
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.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
STATEMANAGER.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
STATEMANAGER.SetSamplerState(0, D3DSAMP_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.SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
STATEMANAGER.SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
}
STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, TRUE);
@@ -219,7 +217,7 @@ void CSpeedTreeForestDirectX8::Render(unsigned long ulRenderBitVector)
}
// choose fixed function pipeline or custom shader for fronds and branches
STATEMANAGER.SetVertexShader(m_dwBranchVertexShader);
STATEMANAGER.SetVertexDeclaration(m_dwBranchVertexShader);
// render branches
if (ulRenderBitVector & Forest_RenderBranches)
@@ -263,7 +261,7 @@ void CSpeedTreeForestDirectX8::Render(unsigned long ulRenderBitVector)
// render leaves
if (ulRenderBitVector & Forest_RenderLeaves)
{
STATEMANAGER.SetVertexShader(m_dwLeafVertexShader);
STATEMANAGER.SetVertexDeclaration(m_dwLeafVertexShader);
if (STATEMANAGER.GetRenderState(D3DRS_FOGENABLE))
{
@@ -329,8 +327,8 @@ void CSpeedTreeForestDirectX8::Render(unsigned long ulRenderBitVector)
STATEMANAGER.SetRenderState(D3DRS_COLORVERTEX, dwColorVertexState);
STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, dwFogVertexMode);
// 셀프섀도우로 쓰는 TextureStage 1의 COLOROP와 ALPHAOP를 꺼줘야 다음 렌더링 할 놈들이
// 제대로 나온다. (안그러면 검게 나올 가능성이..)
// 셀프섀도우로 쓰는 TextureStage 1의 COLOROP와 ALPHAOP를 꺼줘야 다음 렌더링 할 놈들이
// 제대로 나온다. (안그러면 검게 나올 가능성이..)
if (!(ulRenderBitVector & Forest_RenderToShadow))
{
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

View File

@@ -48,17 +48,17 @@ class CSpeedTreeForestDirectX8 : public CSpeedTreeForest, public CGraphicBase, p
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 UpdateCompundMatrix(const D3DXVECTOR3 & c_rEyeVec, const D3DXMATRIX & c_rmatView, const D3DXMATRIX& c_rmatProj);
void Render(unsigned long ulRenderBitVector = Forest_RenderAll);
bool SetRenderingDevice(LPDIRECT3DDEVICE8 pDevice);
bool SetRenderingDevice(LPDIRECT3DDEVICE9 pDevice);
private:
bool InitVertexShaders();
private:
LPDIRECT3DDEVICE8 m_pDx; // the rendering context
LPDIRECT3DDEVICE9 m_pDx; // the rendering context
DWORD m_dwBranchVertexShader; // branch/frond vertex shaders
DWORD m_dwLeafVertexShader; // leaf vertex shader
LPDIRECT3DVERTEXDECLARATION9 m_dwBranchVertexShader; // branch/frond vertex shaders
LPDIRECT3DVERTEXDECLARATION9 m_dwLeafVertexShader; // leaf vertex shader
};

View File

@@ -33,9 +33,9 @@
///////////////////////////////////////////////////////////////////////
// Include Files
#include <d3d8.h>
#include <d3d8types.h>
#include <d3dx8.h>
#include <d3d9.h>
#include <d3d9types.h>
#include <d3dx9.h>
///////////////////////////////////////////////////////////////////////
// class CSpeedTreeMaterial declaration/definiton
@@ -69,11 +69,11 @@ class CSpeedTreeMaterial
m_cMaterial.Power = pMaterialArray[12];
}
D3DMATERIAL8 * Get()
D3DMATERIAL9 * Get()
{
return &m_cMaterial;
}
private:
D3DMATERIAL8 m_cMaterial; // the material object
D3DMATERIAL9 m_cMaterial; // the material object
};

View File

@@ -50,8 +50,8 @@
using namespace std;
DWORD CSpeedTreeWrapper::ms_dwBranchVertexShader = 0;
DWORD CSpeedTreeWrapper::ms_dwLeafVertexShader = 0;
LPDIRECT3DVERTEXDECLARATION9 CSpeedTreeWrapper::ms_dwBranchVertexShader = 0;
LPDIRECT3DVERTEXDECLARATION9 CSpeedTreeWrapper::ms_dwLeafVertexShader = 0;
bool CSpeedTreeWrapper::ms_bSelfShadowOn = true;
///////////////////////////////////////////////////////////////////////
@@ -81,7 +81,7 @@ m_pTextureInfo(NULL)
m_pSpeedTree->SetLocalMatrices(0, 4);
}
void CSpeedTreeWrapper::SetVertexShaders(DWORD dwBranchVertexShader, DWORD dwLeafVertexShader)
void CSpeedTreeWrapper::SetVertexShaders(LPDIRECT3DVERTEXDECLARATION9 dwBranchVertexShader, LPDIRECT3DVERTEXDECLARATION9 dwLeafVertexShader)
{
ms_dwBranchVertexShader = dwBranchVertexShader;
ms_dwLeafVertexShader = dwLeafVertexShader;
@@ -103,7 +103,7 @@ void CSpeedTreeWrapper::OnRenderPCBlocker()
CSpeedTreeForestDirectX8::Instance().UpdateSystem(ELTimer_GetMSec() / 1000.0f);
// 하나만 렌더링 할 때는 LOD 사용하지 않음
// 하나만 렌더링 할 때는 LOD 사용하지 않음
m_pSpeedTree->SetLodLevel(1.0f);
//Advance();
@@ -132,7 +132,7 @@ void CSpeedTreeWrapper::OnRenderPCBlocker()
STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE);
// choose fixed function pipeline or custom shader for fronds and branches
STATEMANAGER.SetVertexShader(ms_dwBranchVertexShader);
STATEMANAGER.SetVertexDeclaration(ms_dwBranchVertexShader);
// SetupBranchForTreeType();
{
@@ -153,7 +153,7 @@ void CSpeedTreeWrapper::OnRenderPCBlocker()
}
#endif
LPDIRECT3DTEXTURE8 lpd3dTexture;
LPDIRECT3DTEXTURE9 lpd3dTexture;
// set texture map
if ((lpd3dTexture = m_BranchImageInstance.GetTextureReference().GetD3DTexture()))
@@ -204,7 +204,7 @@ void CSpeedTreeWrapper::OnRenderPCBlocker()
}
RenderFronds();
STATEMANAGER.SetVertexShader(ms_dwLeafVertexShader);
STATEMANAGER.SetVertexDeclaration(ms_dwLeafVertexShader);
// SetupLeafForTreeType();
{
@@ -250,7 +250,7 @@ void CSpeedTreeWrapper::OnRender()
CSpeedTreeForestDirectX8::Instance().UpdateSystem(ELTimer_GetMSec() / 1000.0f);
// 하나만 렌더링 할 때는 LOD 사용하지 않음
// 하나만 렌더링 할 때는 LOD 사용하지 않음
m_pSpeedTree->SetLodLevel(1.0f);
//Advance();
@@ -266,8 +266,8 @@ void CSpeedTreeWrapper::OnRender()
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);
@@ -277,7 +277,7 @@ void CSpeedTreeWrapper::OnRender()
STATEMANAGER.SaveRenderState(D3DRS_FOGENABLE, FALSE);
// choose fixed function pipeline or custom shader for fronds and branches
STATEMANAGER.SetVertexShader(ms_dwBranchVertexShader);
STATEMANAGER.SetVertexDeclaration(ms_dwBranchVertexShader);
SetupBranchForTreeType();
RenderBranches();
@@ -288,7 +288,7 @@ void CSpeedTreeWrapper::OnRender()
SetupFrondForTreeType();
RenderFronds();
STATEMANAGER.SetVertexShader(ms_dwLeafVertexShader);
STATEMANAGER.SetVertexDeclaration(ms_dwLeafVertexShader);
SetupLeafForTreeType();
RenderLeaves();
@@ -436,22 +436,14 @@ bool CSpeedTreeWrapper::LoadTree(const char * pszSptFile, const BYTE * c_pbBlock
m_pSpeedTree->GetTextures(*m_pTextureInfo);
// load branch textures
auto vs1 = std::string(pszSptFile);
auto vs2 = std::string(m_pTextureInfo->m_pBranchTextureFilename);
LoadTexture((CFileNameHelper::GetPath(vs1) + CFileNameHelper::NoExtension(vs2) + ".dds").c_str(), m_BranchImageInstance);
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)
{
auto vss = std::string(m_pTextureInfo->m_pSelfShadowFilename);
LoadTexture((CFileNameHelper::GetPath(vs1) + CFileNameHelper::NoExtension(vss) + ".dds").c_str(), m_ShadowImageInstance);
}
LoadTexture((CFileNameHelper::GetPath(string(pszSptFile)) + CFileNameHelper::NoExtension(string(m_pTextureInfo->m_pSelfShadowFilename)) + ".dds").c_str(), m_ShadowImageInstance);
#endif
if (m_pTextureInfo->m_pCompositeFilename)
{
auto vss = std::string(m_pTextureInfo->m_pCompositeFilename);
LoadTexture((CFileNameHelper::GetPath(vs1) + CFileNameHelper::NoExtension(vss) + ".dds").c_str(), m_CompositeImageInstance);
}
LoadTexture((CFileNameHelper::GetPath(string(pszSptFile)) + CFileNameHelper::NoExtension(string(m_pTextureInfo->m_pCompositeFilename)) + ".dds").c_str(), m_CompositeImageInstance);
// setup the index and vertex buffers
SetupBuffers();
@@ -501,13 +493,13 @@ void CSpeedTreeWrapper::SetupBranchBuffers(void)
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<BYTE**>(&pVertexBuffer), 0);
m_pBranchVertexBuffer->Lock(0, 0, reinterpret_cast<void**>(&pVertexBuffer), 0);
#else
ms_lpd3dDevice->CreateVertexBuffer(m_unBranchVertexCount * sizeof(SFVFBranchVertex), D3DUSAGE_DYNAMIC, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_SYSTEMMEM, &m_pBranchVertexBuffer);
ms_lpd3dDevice->CreateVertexBuffer(m_unBranchVertexCount * sizeof(SFVFBranchVertex), D3DUSAGE_DYNAMIC, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_SYSTEMMEM, &m_pBranchVertexBuffer, NULL);
// fill the vertex buffer by interleaving SpeedTree data
m_pBranchVertexBuffer->Lock(0, 0, reinterpret_cast<BYTE**>(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK);
m_pBranchVertexBuffer->Lock(0, 0, reinterpret_cast<void**>(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK);
#endif
{
for (UINT i = 0; i < m_unBranchVertexCount; ++i)
@@ -562,11 +554,11 @@ void CSpeedTreeWrapper::SetupBranchBuffers(void)
// 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<BYTE**>(&pIndexBuffer), 0);
m_pBranchIndexBuffer->Lock(0, 0, reinterpret_cast<void**>(&pIndexBuffer), 0);
memcpy(pIndexBuffer, pBranches->m_pStrips[0], pBranches->m_pStripLengths[0] * sizeof(unsigned short));
m_pBranchIndexBuffer->Unlock();
}
@@ -588,13 +580,13 @@ 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_WRITEONLY, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_MANAGED, &m_pFrondVertexBuffer, NULL);
// fill the vertex buffer by interleaving SpeedTree data
m_pFrondVertexBuffer->Lock(0, 0, reinterpret_cast<BYTE**>(&pVertexBuffer), 0);
m_pFrondVertexBuffer->Lock(0, 0, reinterpret_cast<void**>(&pVertexBuffer), 0);
#else
ms_lpd3dDevice->CreateVertexBuffer(m_unFrondVertexCount * sizeof(SFVFBranchVertex), D3DUSAGE_DYNAMIC, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_SYSTEMMEM, &m_pFrondVertexBuffer);
ms_lpd3dDevice->CreateVertexBuffer(m_unFrondVertexCount * sizeof(SFVFBranchVertex), D3DUSAGE_DYNAMIC, D3DFVF_SPEEDTREE_BRANCH_VERTEX, D3DPOOL_SYSTEMMEM, &m_pFrondVertexBuffer, NULL);
// fill the vertex buffer by interleaving SpeedTree data
m_pFrondVertexBuffer->Lock(0, 0, reinterpret_cast<BYTE**>(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK);
m_pFrondVertexBuffer->Lock(0, 0, reinterpret_cast<void**>(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK);
#endif
for (UINT i = 0; i < m_unFrondVertexCount; ++i)
{
@@ -647,11 +639,11 @@ void CSpeedTreeWrapper::SetupFrondBuffers(void)
// 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);
ms_lpd3dDevice->CreateIndexBuffer(m_pFrondIndexCounts[0] * sizeof(unsigned short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pFrondIndexBuffer, NULL);
// fill the index buffer
unsigned short * pIndexBuffer = NULL;
m_pFrondIndexBuffer->Lock(0, 0, reinterpret_cast<BYTE**>(&pIndexBuffer), 0);
m_pFrondIndexBuffer->Lock(0, 0, reinterpret_cast<void**>(&pIndexBuffer), 0);
memcpy(pIndexBuffer, pFronds->m_pStrips[0], pFronds->m_pStripLengths[0] * sizeof(unsigned short));
m_pFrondIndexBuffer->Unlock();
}
@@ -671,7 +663,7 @@ void CSpeedTreeWrapper::SetupLeafBuffers(void)
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];
@@ -695,9 +687,9 @@ void CSpeedTreeWrapper::SetupLeafBuffers(void)
// fill the vertex buffer by interleaving SpeedTree data
m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast<BYTE**>(&pVertexBuffer), 0);
#else
ms_lpd3dDevice->CreateVertexBuffer(usLeafCount * 6 * sizeof(SFVFLeafVertex), D3DUSAGE_DYNAMIC, D3DFVF_SPEEDTREE_LEAF_VERTEX, D3DPOOL_SYSTEMMEM, &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<BYTE**>(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK);
m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast<void**>(&pVertexBuffer), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK);
#endif
SFVFLeafVertex* pVertex = pVertexBuffer;
for (UINT unLeaf = 0; unLeaf < usLeafCount; ++unLeaf)
@@ -706,7 +698,7 @@ void CSpeedTreeWrapper::SetupLeafBuffers(void)
for (UINT unVert = 0; unVert < 6; ++unVert) // 6 verts == 2 triangles
{
// position
memcpy(pVertex->m_vPosition, &(pLeaf->m_pCenterCoords[unLeaf * 3]), 3 * sizeof(float));
memcpy(&pVertex->m_vPosition, &(pLeaf->m_pCenterCoords[unLeaf * 3]), 3 * sizeof(float));
#ifdef WRAPPER_USE_DYNAMIC_LIGHTING
// normal
@@ -763,6 +755,8 @@ CSpeedTreeWrapper * CSpeedTreeWrapper::MakeInstance()
// make an instance of this object's SpeedTree
pInstance->m_bIsInstance = true;
SAFE_DELETE(pInstance->m_pSpeedTree);
pInstance->m_pSpeedTree = m_pSpeedTree->MakeInstance();
if (pInstance->m_pSpeedTree)
@@ -870,7 +864,7 @@ void CSpeedTreeWrapper::SetupBranchForTreeType(void) const
}
#endif
LPDIRECT3DTEXTURE8 lpd3dTexture;
LPDIRECT3DTEXTURE9 lpd3dTexture;
// set texture map
if ((lpd3dTexture = m_BranchImageInstance.GetTextureReference().GetD3DTexture()))
@@ -951,7 +945,7 @@ void CSpeedTreeWrapper::SetupFrondForTreeType(void) const
// bind shadow texture
#ifdef WRAPPER_RENDER_SELF_SHADOWS
LPDIRECT3DTEXTURE8 lpd3dTexture;
LPDIRECT3DTEXTURE9 lpd3dTexture;
if ((lpd3dTexture = m_ShadowImageInstance.GetTextureReference().GetD3DTexture()))
STATEMANAGER.SetTexture(1, lpd3dTexture);
@@ -1062,7 +1056,7 @@ void CSpeedTreeWrapper::RenderLeaves(void) const
m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast<BYTE**>(&pVertex), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK);
for (UINT unLeaf = 0; unLeaf < pLeaf->m_usLeafCount; ++unLeaf)
{
D3DXVECTOR3 vecCenter(&(pLeaf->m_pCenterCoords[unLeaf * 3]));
SMVector3 vecCenter(&(pLeaf->m_pCenterCoords[unLeaf * 3]));
(pVertex++)->m_vPosition = vecCenter; // vertex 0
(pVertex++)->m_vPosition = vecCenter; // vertex 1
(pVertex++)->m_vPosition = vecCenter; // vertex 2
@@ -1084,7 +1078,7 @@ void CSpeedTreeWrapper::RenderLeaves(void) const
return;
D3DXVECTOR3 akPosition[VERTEX_NUM];
D3DXVECTOR3*pkPosition=akPosition;
D3DXVECTOR3* pkPosition = akPosition;
const float* center=pLeaf->m_pCenterCoords;
for (UINT unLeaf = 0; unLeaf < pLeaf->m_usLeafCount; ++unLeaf)
{
@@ -1107,48 +1101,13 @@ void CSpeedTreeWrapper::RenderLeaves(void) const
}
if (SUCCEEDED(
m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast<BYTE**>(&pVertex), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK)
m_pLeafVertexBuffer[unLod]->Lock(0, 0, reinterpret_cast<void**>(&pVertex), D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK)
))
{
UINT uVtxCount=pLeaf->m_usLeafCount*6;
for (UINT i = 0; i<uVtxCount; ++i)
pVertex[i].m_vPosition=akPosition[i];
/*
memcpy(vec0, pLeaf->m_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;
for (UINT i = 0; i < uVtxCount; ++i)
pVertex[i].m_vPosition = akPosition[i];
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();
}
}
@@ -1222,7 +1181,7 @@ void CSpeedTreeWrapper::RenderBillboards(void) const
{ pCoords[9], pCoords[10], pCoords[11], pTexCoords[6], pTexCoords[7] },
};
STATEMANAGER.SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1);
STATEMANAGER.SetFVF(D3DFVF_XYZ | D3DFVF_TEX1);
STATEMANAGER.SetRenderState(D3DRS_ALPHAREF, DWORD(m_pGeometryCache->m_sBillboard0.m_fAlphaTestValue));
ms_faceCount += 2;
@@ -1288,11 +1247,11 @@ void CSpeedTreeWrapper::PositionTree(void) const
D3DXMATRIX matTranslation;
D3DXMatrixIdentity(&matTranslation);
D3DXMatrixTranslation(&matTranslation, vecPosition.x, vecPosition.y, vecPosition.z);
// store translation for client-side transformation
STATEMANAGER.SetTransform(D3DTS_WORLD, &matTranslation);
// store translation for use in vertex shader
// store translation for use in vertex shader
D3DXVECTOR4 vecConstant(vecPosition[0], vecPosition[1], vecPosition[2], 0.0f);
STATEMANAGER.SetVertexShaderConstant(c_nVertexShader_TreePos, (float*)&vecConstant, 1);
}

View File

@@ -37,13 +37,13 @@
#include "SpeedTreeMaterial.h"
#include <SpeedTreeRT.h>
#include <d3d8.h>
#include <d3d8types.h>
#include <d3dx8.h>
#include <d3d9.h>
#include <d3d9types.h>
#include <d3dx9.h>
#include <vector>
#include "../eterLib/GrpObjectInstance.h"
#include "../eterLib/GrpImageInstance.h"
#include "EterLib/GrpObjectInstance.h"
#include "EterLib/GrpImageInstance.h"
#ifndef SAFE_DELETE
#define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } }
@@ -87,8 +87,8 @@ public:
virtual void SetPosition(float x, float y, float z);
virtual void CalculateBBox();
virtual void OnRender(); // Render 시에 메소드, 그러나 프리뷰나 특수한 경우에만 직접 Render 콜을 부르며
// 그 이외에는 RenderBranches, RenderFronds 등의 메소드를 CSpeedTreeForest에서 호출한다.
virtual void OnRender(); // Render 시에 메소드, 그러나 프리뷰나 특수한 경우에만 직접 Render 콜을 부르며
// 그 이외에는 RenderBranches, RenderFronds 등의 메소드를 CSpeedTreeForest에서 호출한다.
virtual void OnBlendRender() {}
virtual void OnRenderToShadowMap() {}
virtual void OnRenderShadow() {}
@@ -99,7 +99,7 @@ public:
virtual ~CSpeedTreeWrapper();
const float * GetPosition();
static void SetVertexShaders(DWORD dwBranchVertexShader, DWORD dwLeafVertexShader);
static void SetVertexShaders(LPDIRECT3DVERTEXDECLARATION9 dwBranchVertexShader, LPDIRECT3DVERTEXDECLARATION9 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);
@@ -141,7 +141,7 @@ public:
void Advance(void);
// utility
LPDIRECT3DTEXTURE8 GetBranchTexture(void) const;
LPDIRECT3DTEXTURE9 GetBranchTexture(void) const;
void CleanUpMemory(void);
private:
@@ -166,20 +166,20 @@ 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
LPDIRECT3DINDEXBUFFER9 m_pFrondIndexBuffer; // frond index buffer
unsigned short* m_pFrondIndexCounts; // number of indexes per frond LOD level
// 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 +196,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 LPDIRECT3DVERTEXDECLARATION9 ms_dwBranchVertexShader;
static LPDIRECT3DVERTEXDECLARATION9 ms_dwLeafVertexShader;
};
#pragma warning(pop)

View File

@@ -3,18 +3,8 @@
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <assert.h>
#include "../UserInterface/Locale_inc.h"
//#include <crtdbg.h>
//#include "Forest.h"
#include "SpeedTreeForestDirectX8.h"
// Armadillo nanomite protection
#ifndef NANOBEGIN
#ifdef __BORLANDC__
#define NANOBEGIN
#define NANOEND
#else
#define NANOBEGIN
#define NANOEND
#endif
#endif

View File

@@ -33,6 +33,7 @@
#include "SpeedTreeConfig.h"
#include <map>
#include <string>
#include <d3d9.h>
///////////////////////////////////////////////////////////////////////
// Branch & Frond Vertex Formats
@@ -126,54 +127,26 @@ static const char g_achSimpleVertexProgram[] =
///////////////////////////////////////////////////////////////////////
// LoadBranchShader
static DWORD LoadBranchShader(LPDIRECT3DDEVICE8 pDx)
static LPDIRECT3DVERTEXDECLARATION9 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( )
};
D3DVERTEXELEMENT9 pBranchShaderDecl[] = {
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
D3DDECL_END()
};
// assemble shader
DWORD dwShader;
LPD3DXBUFFER pCode, pError;
// assemble shader
LPDIRECT3DVERTEXDECLARATION9 dwShader = NULL;
if (D3DXAssembleShader(g_achSimpleVertexProgram, sizeof(g_achSimpleVertexProgram) - 1, 0, NULL, &pCode, &pError) == D3D_OK)
if (pDx->CreateVertexDeclaration(pBranchShaderDecl, &dwShader) != 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);
}
char szError[1024];
sprintf_s(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;
}
@@ -272,61 +245,27 @@ static const char g_achLeafVertexProgram[] =
///////////////////////////////////////////////////////////////////////
// LoadLeafShader
static DWORD LoadLeafShader(LPDIRECT3DDEVICE8 pDx)
static LPDIRECT3DVERTEXDECLARATION9 LoadLeafShader(LPDIRECT3DDEVICE9 pDx)
{
DWORD dwShader = D3DFVF_SPEEDTREE_LEAF_VERTEX;
// leaf shader declaration
D3DVERTEXELEMENT9 pLeafShaderDecl[] = {
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2 },
D3DDECL_END()
};
#if defined WRAPPER_USE_GPU_LEAF_PLACEMENT || defined WRAPPER_USE_GPU_WIND
// assemble shader
LPDIRECT3DVERTEXDECLARATION9 dwShader = NULL;
// 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( )
};
if (pDx->CreateVertexDeclaration(pLeafShaderDecl, &dwShader) != D3D_OK)
{
char szError[1024];
sprintf_s(szError, "Failed to create leaf vertex shader.");
MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP);
// 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;
}