2V2-e.1: 3D draw-command channel — recording D3D8 device, StateManager, GrpBase, camera
EterLib/StateManager.cpp and GrpBase.cpp ported verbatim. CGraphicDevice::Create builds a platform IDirect3DDevice8 that keeps the device state and records every Draw* call as a Render3DDraw (vertices decoded by FVF, strips/fans expanded, textures, world/view/proj, blend/depth/light state). The 40250 camera (__UpdateCamera, SetCenterPosition, ...) and the Process order (__UpdateCamera -> OnCameraUpdate -> OnUIUpdate -> Begin/SetInterfaceRenderState/OnUIRender/End) are in place; CScreen Begin/End, CPythonGraphic render states and CCullingManager::Process matrix updates are verbatim. port.login_flow asserts a textured, lit character draw under the RH perspective with every vertex on screen; offline and live pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
668f48d6ec
commit
5bfa13c5cc
@@ -0,0 +1,512 @@
|
||||
#include "StdAfx.h"
|
||||
#include "../EterBase/Utils.h"
|
||||
#include "../EterBase/Timer.h"
|
||||
#include "GrpBase.h"
|
||||
#include "Camera.h"
|
||||
#include "StateManager.h"
|
||||
|
||||
void PixelPositionToD3DXVECTOR3(const D3DXVECTOR3& c_rkPPosSrc, D3DXVECTOR3* pv3Dst)
|
||||
{
|
||||
pv3Dst->x=+c_rkPPosSrc.x;
|
||||
pv3Dst->y=-c_rkPPosSrc.y;
|
||||
pv3Dst->z=+c_rkPPosSrc.z;
|
||||
}
|
||||
|
||||
void D3DXVECTOR3ToPixelPosition(const D3DXVECTOR3& c_rv3Src, D3DXVECTOR3* pv3Dst)
|
||||
{
|
||||
pv3Dst->x=+c_rv3Src.x;
|
||||
pv3Dst->y=-c_rv3Src.y;
|
||||
pv3Dst->z=+c_rv3Src.z;
|
||||
}
|
||||
|
||||
UINT CGraphicBase::ms_iD3DAdapterInfo=0;
|
||||
UINT CGraphicBase::ms_iD3DDevInfo=0;
|
||||
UINT CGraphicBase::ms_iD3DModeInfo=0;
|
||||
D3D_CDisplayModeAutoDetector CGraphicBase::ms_kD3DDetector;
|
||||
|
||||
HWND CGraphicBase::ms_hWnd;
|
||||
HDC CGraphicBase::ms_hDC;
|
||||
|
||||
LPDIRECT3D8 CGraphicBase::ms_lpd3d = NULL;
|
||||
LPDIRECT3DDEVICE8 CGraphicBase::ms_lpd3dDevice = NULL;
|
||||
ID3DXMatrixStack * CGraphicBase::ms_lpd3dMatStack = NULL;
|
||||
D3DPRESENT_PARAMETERS CGraphicBase::ms_d3dPresentParameter;
|
||||
D3DVIEWPORT8 CGraphicBase::ms_Viewport;
|
||||
|
||||
HRESULT CGraphicBase::ms_hLastResult = NULL;
|
||||
|
||||
int CGraphicBase::ms_iWidth;
|
||||
int CGraphicBase::ms_iHeight;
|
||||
|
||||
DWORD CGraphicBase::ms_faceCount = 0;
|
||||
|
||||
D3DCAPS8 CGraphicBase::ms_d3dCaps;
|
||||
|
||||
DWORD CGraphicBase::ms_dwD3DBehavior = 0;
|
||||
|
||||
DWORD CGraphicBase::ms_ptVS = 0;
|
||||
DWORD CGraphicBase::ms_pntVS = 0;
|
||||
DWORD CGraphicBase::ms_pnt2VS = 0;
|
||||
|
||||
D3DXMATRIX CGraphicBase::ms_matIdentity;
|
||||
|
||||
D3DXMATRIX CGraphicBase::ms_matView;
|
||||
D3DXMATRIX CGraphicBase::ms_matProj;
|
||||
D3DXMATRIX CGraphicBase::ms_matInverseView;
|
||||
D3DXMATRIX CGraphicBase::ms_matInverseViewYAxis;
|
||||
|
||||
D3DXMATRIX CGraphicBase::ms_matWorld;
|
||||
D3DXMATRIX CGraphicBase::ms_matWorldView;
|
||||
|
||||
D3DXMATRIX CGraphicBase::ms_matScreen0;
|
||||
D3DXMATRIX CGraphicBase::ms_matScreen1;
|
||||
D3DXMATRIX CGraphicBase::ms_matScreen2;
|
||||
|
||||
D3DXVECTOR3 CGraphicBase::ms_vtPickRayOrig;
|
||||
D3DXVECTOR3 CGraphicBase::ms_vtPickRayDir;
|
||||
|
||||
float CGraphicBase::ms_fFieldOfView;
|
||||
float CGraphicBase::ms_fNearY;
|
||||
float CGraphicBase::ms_fFarY;
|
||||
float CGraphicBase::ms_fAspect;
|
||||
|
||||
DWORD CGraphicBase::ms_dwWavingEndTime;
|
||||
int CGraphicBase::ms_iWavingPower;
|
||||
DWORD CGraphicBase::ms_dwFlashingEndTime;
|
||||
D3DXCOLOR CGraphicBase::ms_FlashingColor;
|
||||
|
||||
// Terrain picking용 Ray... CCamera 이용하는 버전.. 기존의 Ray와 통합 필요...
|
||||
CRay CGraphicBase::ms_Ray;
|
||||
bool CGraphicBase::ms_bSupportDXT = true;
|
||||
bool CGraphicBase::ms_isLowTextureMemory = false;
|
||||
bool CGraphicBase::ms_isHighTextureMemory = false;
|
||||
|
||||
// 2004.11.18.myevan.DynamicVertexBuffer로 교체
|
||||
/*
|
||||
std::vector<TIndex> CGraphicBase::ms_lineIdxVector;
|
||||
std::vector<TIndex> CGraphicBase::ms_lineTriIdxVector;
|
||||
std::vector<TIndex> CGraphicBase::ms_lineRectIdxVector;
|
||||
std::vector<TIndex> CGraphicBase::ms_lineCubeIdxVector;
|
||||
|
||||
std::vector<TIndex> CGraphicBase::ms_fillTriIdxVector;
|
||||
std::vector<TIndex> CGraphicBase::ms_fillRectIdxVector;
|
||||
std::vector<TIndex> CGraphicBase::ms_fillCubeIdxVector;
|
||||
*/
|
||||
|
||||
LPD3DXMESH CGraphicBase::ms_lpSphereMesh = NULL;
|
||||
LPD3DXMESH CGraphicBase::ms_lpCylinderMesh = NULL;
|
||||
|
||||
LPDIRECT3DVERTEXBUFFER8 CGraphicBase::ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM];
|
||||
|
||||
LPDIRECT3DINDEXBUFFER8 CGraphicBase::ms_alpd3dDefIB[DEFAULT_IB_NUM];
|
||||
|
||||
bool CGraphicBase::IsLowTextureMemory()
|
||||
{
|
||||
return ms_isLowTextureMemory;
|
||||
}
|
||||
|
||||
bool CGraphicBase::IsHighTextureMemory()
|
||||
{
|
||||
return ms_isHighTextureMemory;
|
||||
}
|
||||
|
||||
bool CGraphicBase::IsFastTNL()
|
||||
{
|
||||
if (ms_dwD3DBehavior & D3DCREATE_HARDWARE_VERTEXPROCESSING ||
|
||||
ms_dwD3DBehavior & D3DCREATE_MIXED_VERTEXPROCESSING)
|
||||
{
|
||||
if (ms_d3dCaps.VertexShaderVersion>D3DVS_VERSION(1,0))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CGraphicBase::IsTLVertexClipping()
|
||||
{
|
||||
if (ms_d3dCaps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CGraphicBase::GetBackBufferSize(UINT* puWidth, UINT* puHeight)
|
||||
{
|
||||
*puWidth=ms_d3dPresentParameter.BackBufferWidth;
|
||||
*puHeight=ms_d3dPresentParameter.BackBufferHeight;
|
||||
}
|
||||
|
||||
void CGraphicBase::SetDefaultIndexBuffer(UINT eDefIB)
|
||||
{
|
||||
if (eDefIB>=DEFAULT_IB_NUM)
|
||||
return;
|
||||
|
||||
STATEMANAGER.SetIndices(ms_alpd3dDefIB[eDefIB], 0);
|
||||
}
|
||||
|
||||
bool CGraphicBase::SetPDTStream(SPDTVertex* pVertices, UINT uVtxCount)
|
||||
{
|
||||
return SetPDTStream((SPDTVertexRaw*)pVertices, uVtxCount);
|
||||
}
|
||||
|
||||
bool CGraphicBase::SetPDTStream(SPDTVertexRaw* pSrcVertices, UINT uVtxCount)
|
||||
{
|
||||
if (!uVtxCount)
|
||||
return false;
|
||||
|
||||
static DWORD s_dwVBPos=0;
|
||||
|
||||
if (s_dwVBPos>=PDT_VERTEXBUFFER_NUM)
|
||||
s_dwVBPos=0;
|
||||
|
||||
IDirect3DVertexBuffer8* plpd3dFillRectVB=ms_alpd3dPDTVB[s_dwVBPos];
|
||||
++s_dwVBPos;
|
||||
|
||||
assert(PDT_VERTEX_NUM>=uVtxCount);
|
||||
if (uVtxCount >= PDT_VERTEX_NUM)
|
||||
return false;
|
||||
|
||||
TPDTVertex* pDstVertices;
|
||||
if (FAILED(
|
||||
plpd3dFillRectVB->Lock(0, sizeof(TPDTVertex)*uVtxCount, (BYTE**)&pDstVertices, D3DLOCK_DISCARD)
|
||||
))
|
||||
{
|
||||
STATEMANAGER.SetStreamSource(0, NULL, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
memcpy(pDstVertices, pSrcVertices, sizeof(TPDTVertex)*uVtxCount);
|
||||
|
||||
plpd3dFillRectVB->Unlock();
|
||||
|
||||
STATEMANAGER.SetStreamSource(0, plpd3dFillRectVB, sizeof(TPDTVertex));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DWORD CGraphicBase::GetAvailableTextureMemory()
|
||||
{
|
||||
assert(ms_lpd3dDevice!=NULL && "CGraphicBase::GetAvailableTextureMemory - D3DDevice is EMPTY");
|
||||
|
||||
static DWORD s_dwNextUpdateTime=0;
|
||||
static DWORD s_dwTexMemSize=0;//ms_lpd3dDevice->GetAvailableTextureMem();
|
||||
|
||||
DWORD dwCurTime=ELTimer_GetMSec();
|
||||
if (s_dwNextUpdateTime<dwCurTime)
|
||||
{
|
||||
s_dwNextUpdateTime=dwCurTime+5000;
|
||||
s_dwTexMemSize=ms_lpd3dDevice->GetAvailableTextureMem();
|
||||
}
|
||||
|
||||
return s_dwTexMemSize;
|
||||
}
|
||||
|
||||
const D3DXMATRIX& CGraphicBase::GetViewMatrix()
|
||||
{
|
||||
return ms_matView;
|
||||
}
|
||||
|
||||
const D3DXMATRIX & CGraphicBase::GetIdentityMatrix()
|
||||
{
|
||||
return ms_matIdentity;
|
||||
}
|
||||
|
||||
void CGraphicBase::SetEyeCamera(float xEye, float yEye, float zEye,
|
||||
float xCenter, float yCenter, float zCenter,
|
||||
float xUp, float yUp, float zUp)
|
||||
{
|
||||
D3DXVECTOR3 vectorEye(xEye, yEye, zEye);
|
||||
D3DXVECTOR3 vectorCenter(xCenter, yCenter, zCenter);
|
||||
D3DXVECTOR3 vectorUp(xUp, yUp, zUp);
|
||||
|
||||
// CCameraManager::Instance().SetCurrentCamera(CCameraManager::DEFAULT_PERSPECTIVE_CAMERA);
|
||||
CCameraManager::Instance().GetCurrentCamera()->SetViewParams(vectorEye, vectorCenter, vectorUp);
|
||||
UpdateViewMatrix();
|
||||
}
|
||||
|
||||
void CGraphicBase::SetSimpleCamera(float x, float y, float z, float pitch, float roll)
|
||||
{
|
||||
CCamera * pCamera = CCameraManager::Instance().GetCurrentCamera();
|
||||
D3DXVECTOR3 vectorEye(x, y, z);
|
||||
|
||||
pCamera->SetViewParams(D3DXVECTOR3(0.0f, y, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f));
|
||||
pCamera->RotateEyeAroundTarget(pitch, roll);
|
||||
pCamera->Move(vectorEye);
|
||||
|
||||
UpdateViewMatrix();
|
||||
|
||||
// This is levites's virtual(?) code which you should not trust.
|
||||
ms_lpd3dDevice->GetTransform(D3DTS_WORLD, &ms_matWorld);
|
||||
D3DXMatrixMultiply(&ms_matWorldView, &ms_matWorld, &ms_matView);
|
||||
}
|
||||
|
||||
void CGraphicBase::SetAroundCamera(float distance, float pitch, float roll, float lookAtZ)
|
||||
{
|
||||
CCamera * pCamera = CCameraManager::Instance().GetCurrentCamera();
|
||||
pCamera->SetViewParams(D3DXVECTOR3(0.0f, -distance, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f));
|
||||
pCamera->RotateEyeAroundTarget(pitch, roll);
|
||||
D3DXVECTOR3 v3Target = pCamera->GetTarget();
|
||||
v3Target.z = lookAtZ;
|
||||
pCamera->SetTarget(v3Target);
|
||||
// pCamera->Move(v3Target);
|
||||
|
||||
UpdateViewMatrix();
|
||||
|
||||
// This is levites's virtual(?) code which you should not trust.
|
||||
ms_lpd3dDevice->GetTransform(D3DTS_WORLD, &ms_matWorld);
|
||||
D3DXMatrixMultiply(&ms_matWorldView, &ms_matWorld, &ms_matView);
|
||||
}
|
||||
|
||||
void CGraphicBase::SetPositionCamera(float fx, float fy, float fz, float distance, float pitch, float roll)
|
||||
{
|
||||
// I wanna downward this code to the game control level. - [levites]
|
||||
if (ms_dwWavingEndTime > CTimer::Instance().GetCurrentMillisecond())
|
||||
{
|
||||
if (ms_iWavingPower>0)
|
||||
{
|
||||
fx += float(rand() % ms_iWavingPower) / 10.0f;
|
||||
fy += float(rand() % ms_iWavingPower) / 10.0f;
|
||||
fz += float(rand() % ms_iWavingPower) / 10.0f;
|
||||
}
|
||||
}
|
||||
|
||||
CCamera * pCamera = CCameraManager::Instance().GetCurrentCamera();
|
||||
if (!pCamera)
|
||||
return;
|
||||
|
||||
pCamera->SetViewParams(D3DXVECTOR3(0.0f, -distance, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f));
|
||||
pitch = fMIN(80.0f, fMAX(-80.0f, pitch) );
|
||||
// Tracef("SetPosition Camera : %f, %f\n", pitch, roll);
|
||||
pCamera->RotateEyeAroundTarget(pitch, roll);
|
||||
pCamera->Move(D3DXVECTOR3(fx, fy, fz));
|
||||
|
||||
UpdateViewMatrix();
|
||||
|
||||
// This is levites's virtual(?) code which you should not trust.
|
||||
STATEMANAGER.GetTransform(D3DTS_WORLD, &ms_matWorld);
|
||||
D3DXMatrixMultiply(&ms_matWorldView, &ms_matWorld, &ms_matView);
|
||||
}
|
||||
|
||||
void CGraphicBase::SetOrtho2D(float hres, float vres, float zres)
|
||||
{
|
||||
//CCameraManager::Instance().SetCurrentCamera(CCameraManager::DEFAULT_ORTHO_CAMERA);
|
||||
D3DXMatrixOrthoOffCenterRH(&ms_matProj, 0, hres, vres, 0, 0, zres);
|
||||
//UpdatePipeLineMatrix();
|
||||
UpdateProjMatrix();
|
||||
}
|
||||
|
||||
void CGraphicBase::SetOrtho3D(float hres, float vres, float zmin, float zmax)
|
||||
{
|
||||
//CCameraManager::Instance().SetCurrentCamera(CCameraManager::DEFAULT_PERSPECTIVE_CAMERA);
|
||||
D3DXMatrixOrthoRH(&ms_matProj, hres, vres, zmin, zmax);
|
||||
//UpdatePipeLineMatrix();
|
||||
UpdateProjMatrix();
|
||||
}
|
||||
|
||||
void CGraphicBase::SetPerspective(float fov, float aspect, float nearz, float farz)
|
||||
{
|
||||
ms_fFieldOfView = fov;
|
||||
|
||||
|
||||
//if (ms_d3dPresentParameter.BackBufferWidth>0 && ms_d3dPresentParameter.BackBufferHeight>0)
|
||||
// ms_fAspect = float(ms_d3dPresentParameter.BackBufferWidth)/float(ms_d3dPresentParameter.BackBufferHeight);
|
||||
//else
|
||||
ms_fAspect = aspect;
|
||||
|
||||
ms_fNearY = nearz;
|
||||
ms_fFarY = farz;
|
||||
|
||||
//CCameraManager::Instance().SetCurrentCamera(CCameraManager::DEFAULT_PERSPECTIVE_CAMERA);
|
||||
D3DXMatrixPerspectiveFovRH(&ms_matProj, D3DXToRadian(fov), ms_fAspect, nearz, farz);
|
||||
//UpdatePipeLineMatrix();
|
||||
UpdateProjMatrix();
|
||||
}
|
||||
|
||||
void CGraphicBase::UpdateProjMatrix()
|
||||
{
|
||||
STATEMANAGER.SetTransform(D3DTS_PROJECTION, &ms_matProj);
|
||||
}
|
||||
|
||||
void CGraphicBase::UpdateViewMatrix()
|
||||
{
|
||||
CCamera* pkCamera=CCameraManager::Instance().GetCurrentCamera();
|
||||
if (!pkCamera)
|
||||
return;
|
||||
|
||||
ms_matView = pkCamera->GetViewMatrix();
|
||||
STATEMANAGER.SetTransform(D3DTS_VIEW, &ms_matView);
|
||||
|
||||
D3DXMatrixInverse(&ms_matInverseView, NULL, &ms_matView);
|
||||
ms_matInverseViewYAxis._11 = ms_matInverseView._11;
|
||||
ms_matInverseViewYAxis._12 = ms_matInverseView._12;
|
||||
ms_matInverseViewYAxis._21 = ms_matInverseView._21;
|
||||
ms_matInverseViewYAxis._22 = ms_matInverseView._22;
|
||||
}
|
||||
|
||||
void CGraphicBase::UpdatePipeLineMatrix()
|
||||
{
|
||||
UpdateProjMatrix();
|
||||
UpdateViewMatrix();
|
||||
}
|
||||
|
||||
void CGraphicBase::SetViewport(DWORD dwX, DWORD dwY, DWORD dwWidth, DWORD dwHeight, float fMinZ, float fMaxZ)
|
||||
{
|
||||
ms_Viewport.X = dwX;
|
||||
ms_Viewport.Y = dwY;
|
||||
ms_Viewport.Width = dwWidth;
|
||||
ms_Viewport.Height = dwHeight;
|
||||
ms_Viewport.MinZ = fMinZ;
|
||||
ms_Viewport.MaxZ = fMaxZ;
|
||||
}
|
||||
|
||||
void CGraphicBase::GetTargetPosition(float * px, float * py, float * pz)
|
||||
{
|
||||
*px = CCameraManager::Instance().GetCurrentCamera()->GetTarget().x;
|
||||
*py = CCameraManager::Instance().GetCurrentCamera()->GetTarget().y;
|
||||
*pz = CCameraManager::Instance().GetCurrentCamera()->GetTarget().z;
|
||||
}
|
||||
|
||||
void CGraphicBase::GetCameraPosition(float * px, float * py, float * pz)
|
||||
{
|
||||
*px = CCameraManager::Instance().GetCurrentCamera()->GetEye().x;
|
||||
*py = CCameraManager::Instance().GetCurrentCamera()->GetEye().y;
|
||||
*pz = CCameraManager::Instance().GetCurrentCamera()->GetEye().z;
|
||||
}
|
||||
|
||||
void CGraphicBase::GetMatrix(D3DXMATRIX* pRetMatrix) const
|
||||
{
|
||||
assert(ms_lpd3dMatStack != NULL);
|
||||
*pRetMatrix = *ms_lpd3dMatStack->GetTop();
|
||||
}
|
||||
|
||||
const D3DXMATRIX* CGraphicBase::GetMatrixPointer() const
|
||||
{
|
||||
assert(ms_lpd3dMatStack!=NULL);
|
||||
return ms_lpd3dMatStack->GetTop();
|
||||
}
|
||||
|
||||
void CGraphicBase::GetSphereMatrix(D3DXMATRIX * pMatrix, float fValue)
|
||||
{
|
||||
D3DXMatrixIdentity(pMatrix);
|
||||
pMatrix->_11 = fValue * ms_matWorldView._11;
|
||||
pMatrix->_21 = fValue * ms_matWorldView._21;
|
||||
pMatrix->_31 = fValue * ms_matWorldView._31;
|
||||
pMatrix->_41 = fValue;
|
||||
pMatrix->_12 = -fValue * ms_matWorldView._12;
|
||||
pMatrix->_22 = -fValue * ms_matWorldView._22;
|
||||
pMatrix->_32 = -fValue * ms_matWorldView._32;
|
||||
pMatrix->_42 = -fValue;
|
||||
}
|
||||
|
||||
float CGraphicBase::GetFOV()
|
||||
{
|
||||
return ms_fFieldOfView;
|
||||
}
|
||||
|
||||
void CGraphicBase::PushMatrix()
|
||||
{
|
||||
ms_lpd3dMatStack->Push();
|
||||
}
|
||||
|
||||
void CGraphicBase::Scale(float x, float y, float z)
|
||||
{
|
||||
ms_lpd3dMatStack->Scale(x, y, z);
|
||||
}
|
||||
|
||||
void CGraphicBase::Rotate(float degree, float x, float y, float z)
|
||||
{
|
||||
D3DXVECTOR3 vec(x, y, z);
|
||||
ms_lpd3dMatStack->RotateAxis(&vec, D3DXToRadian(degree));
|
||||
}
|
||||
|
||||
void CGraphicBase::RotateLocal(float degree, float x, float y, float z)
|
||||
{
|
||||
D3DXVECTOR3 vec(x, y, z);
|
||||
ms_lpd3dMatStack->RotateAxisLocal(&vec, D3DXToRadian(degree));
|
||||
}
|
||||
|
||||
void CGraphicBase::MultMatrix( const D3DXMATRIX* pMat)
|
||||
{
|
||||
ms_lpd3dMatStack->MultMatrix(pMat);
|
||||
}
|
||||
|
||||
void CGraphicBase::MultMatrixLocal( const D3DXMATRIX* pMat)
|
||||
{
|
||||
ms_lpd3dMatStack->MultMatrixLocal(pMat);
|
||||
}
|
||||
|
||||
void CGraphicBase::RotateYawPitchRollLocal(float fYaw, float fPitch, float fRoll)
|
||||
{
|
||||
ms_lpd3dMatStack->RotateYawPitchRollLocal(D3DXToRadian(fYaw), D3DXToRadian(fPitch), D3DXToRadian(fRoll));
|
||||
}
|
||||
|
||||
void CGraphicBase::Translate(float x, float y, float z)
|
||||
{
|
||||
ms_lpd3dMatStack->Translate(x, y, z);
|
||||
}
|
||||
|
||||
void CGraphicBase::LoadMatrix(const D3DXMATRIX& c_rSrcMatrix)
|
||||
{
|
||||
ms_lpd3dMatStack->LoadMatrix(&c_rSrcMatrix);
|
||||
}
|
||||
|
||||
void CGraphicBase::PopMatrix()
|
||||
{
|
||||
ms_lpd3dMatStack->Pop();
|
||||
}
|
||||
|
||||
DWORD CGraphicBase::GetColor(float r, float g, float b, float a)
|
||||
{
|
||||
BYTE argb[4] =
|
||||
{
|
||||
(BYTE) (255.0f * b),
|
||||
(BYTE) (255.0f * g),
|
||||
(BYTE) (255.0f * r),
|
||||
(BYTE) (255.0f * a)
|
||||
};
|
||||
|
||||
return *((DWORD *) argb);
|
||||
}
|
||||
|
||||
void CGraphicBase::InitScreenEffect()
|
||||
{
|
||||
ms_dwWavingEndTime = 0;
|
||||
ms_dwFlashingEndTime = 0;
|
||||
ms_iWavingPower = 0;
|
||||
ms_FlashingColor = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
void CGraphicBase::SetScreenEffectWaving(float fDuringTime, int iPower)
|
||||
{
|
||||
ms_dwWavingEndTime = CTimer::Instance().GetCurrentMillisecond() + long(fDuringTime * 1000.0f);
|
||||
ms_iWavingPower = iPower;
|
||||
}
|
||||
|
||||
void CGraphicBase::SetScreenEffectFlashing(float fDuringTime, const D3DXCOLOR & c_rColor)
|
||||
{
|
||||
ms_dwFlashingEndTime = CTimer::Instance().GetCurrentMillisecond() + long(fDuringTime * 1000.0f);
|
||||
ms_FlashingColor = c_rColor;
|
||||
}
|
||||
|
||||
DWORD CGraphicBase::GetFaceCount()
|
||||
{
|
||||
return ms_faceCount;
|
||||
}
|
||||
|
||||
void CGraphicBase::ResetFaceCount()
|
||||
{
|
||||
ms_faceCount = 0;
|
||||
}
|
||||
|
||||
HRESULT CGraphicBase::GetLastResult()
|
||||
{
|
||||
return ms_hLastResult;
|
||||
}
|
||||
|
||||
CGraphicBase::CGraphicBase()
|
||||
{
|
||||
}
|
||||
|
||||
CGraphicBase::~CGraphicBase()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,769 @@
|
||||
#include "StdAfx.h"
|
||||
#include "StateManager.h"
|
||||
|
||||
//#define StateManager_Assert(a) if (!(a)) puts("assert"#a)
|
||||
#define StateManager_Assert(a) assert(a)
|
||||
|
||||
struct SLightData
|
||||
{
|
||||
enum
|
||||
{
|
||||
LIGHT_NUM = 8,
|
||||
};
|
||||
D3DLIGHT8 m_akD3DLight[LIGHT_NUM];
|
||||
} m_kLightData;
|
||||
|
||||
|
||||
|
||||
void CStateManager::SetLight(DWORD index, CONST D3DLIGHT8* pLight)
|
||||
{
|
||||
assert(index<SLightData::LIGHT_NUM);
|
||||
m_kLightData.m_akD3DLight[index]=*pLight;
|
||||
|
||||
m_lpD3DDev->SetLight(index, pLight);
|
||||
}
|
||||
|
||||
void CStateManager::GetLight(DWORD index, D3DLIGHT8* pLight)
|
||||
{
|
||||
assert(index<8);
|
||||
*pLight=m_kLightData.m_akD3DLight[index];
|
||||
}
|
||||
|
||||
bool CStateManager::BeginScene()
|
||||
{
|
||||
m_bScene=true;
|
||||
|
||||
D3DXMATRIX m4Proj;
|
||||
D3DXMATRIX m4View;
|
||||
D3DXMATRIX m4World;
|
||||
GetTransform(D3DTS_WORLD, &m4World);
|
||||
GetTransform(D3DTS_PROJECTION, &m4Proj);
|
||||
GetTransform(D3DTS_VIEW, &m4View);
|
||||
SetTransform(D3DTS_WORLD, &m4World);
|
||||
SetTransform(D3DTS_PROJECTION, &m4Proj);
|
||||
SetTransform(D3DTS_VIEW, &m4View);
|
||||
|
||||
if (FAILED(m_lpD3DDev->BeginScene()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CStateManager::EndScene()
|
||||
{
|
||||
m_lpD3DDev->EndScene();
|
||||
m_bScene=false;
|
||||
}
|
||||
|
||||
CStateManager::CStateManager(LPDIRECT3DDEVICE8 lpDevice) : m_lpD3DDev(NULL)
|
||||
{
|
||||
m_bScene = false;
|
||||
m_dwBestMinFilter = D3DTEXF_LINEAR;
|
||||
m_dwBestMagFilter = D3DTEXF_LINEAR;
|
||||
SetDevice(lpDevice);
|
||||
}
|
||||
|
||||
CStateManager::~CStateManager()
|
||||
{
|
||||
if (m_lpD3DDev)
|
||||
{
|
||||
m_lpD3DDev->Release();
|
||||
m_lpD3DDev = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void CStateManager::SetDevice(LPDIRECT3DDEVICE8 lpDevice)
|
||||
{
|
||||
StateManager_Assert(lpDevice);
|
||||
lpDevice->AddRef();
|
||||
|
||||
if (m_lpD3DDev)
|
||||
{
|
||||
m_lpD3DDev->Release();
|
||||
m_lpD3DDev = NULL;
|
||||
}
|
||||
|
||||
m_lpD3DDev = lpDevice;
|
||||
|
||||
D3DCAPS8 d3dCaps;
|
||||
m_lpD3DDev->GetDeviceCaps(&d3dCaps);
|
||||
|
||||
if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC)
|
||||
m_dwBestMagFilter = D3DTEXF_ANISOTROPIC;
|
||||
else
|
||||
m_dwBestMagFilter = D3DTEXF_LINEAR;
|
||||
|
||||
if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC)
|
||||
m_dwBestMinFilter = D3DTEXF_ANISOTROPIC;
|
||||
else
|
||||
m_dwBestMinFilter = D3DTEXF_LINEAR;
|
||||
|
||||
DWORD dwMax = d3dCaps.MaxAnisotropy;
|
||||
dwMax = dwMax < 4 ? dwMax : 4;
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
m_lpD3DDev->SetTextureStageState(i, D3DTSS_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);
|
||||
}
|
||||
|
||||
void CStateManager::Restore()
|
||||
{
|
||||
int i, j;
|
||||
|
||||
m_bForce = true;
|
||||
|
||||
for (i = 0; i < STATEMANAGER_MAX_RENDERSTATES; ++i)
|
||||
SetRenderState(D3DRENDERSTATETYPE(i), m_CurrentState.m_RenderStates[i]);
|
||||
|
||||
for (i = 0; i < STATEMANAGER_MAX_STAGES; ++i)
|
||||
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)
|
||||
SetTexture(i, m_CurrentState.m_Textures[i]);
|
||||
|
||||
m_bForce = false;
|
||||
}
|
||||
|
||||
void CStateManager::SetDefaultState()
|
||||
{
|
||||
m_CurrentState.ResetState();
|
||||
m_CopyState.ResetState();
|
||||
m_ChipState.ResetState();
|
||||
|
||||
m_bScene = false;
|
||||
m_bForce = true;
|
||||
|
||||
D3DXMATRIX Identity;
|
||||
D3DXMatrixIdentity(&Identity);
|
||||
|
||||
SetTransform(D3DTS_WORLD, &Identity);
|
||||
SetTransform(D3DTS_VIEW, &Identity);
|
||||
SetTransform(D3DTS_PROJECTION, &Identity);
|
||||
|
||||
D3DMATERIAL8 DefaultMat;
|
||||
ZeroMemory(&DefaultMat, sizeof(D3DMATERIAL8));
|
||||
|
||||
DefaultMat.Diffuse.r = 1.0f;
|
||||
DefaultMat.Diffuse.g = 1.0f;
|
||||
DefaultMat.Diffuse.b = 1.0f;
|
||||
DefaultMat.Diffuse.a = 1.0f;
|
||||
DefaultMat.Ambient.r = 1.0f;
|
||||
DefaultMat.Ambient.g = 1.0f;
|
||||
DefaultMat.Ambient.b = 1.0f;
|
||||
DefaultMat.Ambient.a = 1.0f;
|
||||
DefaultMat.Emissive.r = 0.0f;
|
||||
DefaultMat.Emissive.g = 0.0f;
|
||||
DefaultMat.Emissive.b = 0.0f;
|
||||
DefaultMat.Emissive.a = 0.0f;
|
||||
DefaultMat.Specular.r = 0.0f;
|
||||
DefaultMat.Specular.g = 0.0f;
|
||||
DefaultMat.Specular.b = 0.0f;
|
||||
DefaultMat.Specular.a = 0.0f;
|
||||
DefaultMat.Power = 0.0f;
|
||||
|
||||
SetMaterial(&DefaultMat);
|
||||
|
||||
SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
|
||||
SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
|
||||
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);
|
||||
SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
|
||||
SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
|
||||
SetRenderState(D3DRS_COLORWRITEENABLE, 0xFFFFFFFF);
|
||||
SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
|
||||
SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
|
||||
SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
|
||||
SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
|
||||
SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
|
||||
SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||
SetRenderState(D3DRS_FOGENABLE, FALSE);
|
||||
SetRenderState(D3DRS_FOGCOLOR, 0xFF000000);
|
||||
SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_NONE);
|
||||
SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
|
||||
SetRenderState(D3DRS_RANGEFOGENABLE, FALSE);
|
||||
SetRenderState(D3DRS_ZENABLE, TRUE);
|
||||
SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
|
||||
SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
|
||||
SetRenderState(D3DRS_DITHERENABLE, TRUE);
|
||||
SetRenderState(D3DRS_STENCILENABLE, FALSE);
|
||||
SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
|
||||
SetRenderState(D3DRS_CLIPPING, TRUE);
|
||||
SetRenderState(D3DRS_LIGHTING, FALSE);
|
||||
SetRenderState(D3DRS_SPECULARENABLE, FALSE);
|
||||
SetRenderState(D3DRS_COLORVERTEX, FALSE);
|
||||
SetRenderState(D3DRS_WRAP0, 0);
|
||||
SetRenderState(D3DRS_WRAP1, 0);
|
||||
SetRenderState(D3DRS_WRAP2, 0);
|
||||
SetRenderState(D3DRS_WRAP3, 0);
|
||||
SetRenderState(D3DRS_WRAP4, 0);
|
||||
SetRenderState(D3DRS_WRAP5, 0);
|
||||
SetRenderState(D3DRS_WRAP6, 0);
|
||||
SetRenderState(D3DRS_WRAP7, 0);
|
||||
|
||||
SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);
|
||||
SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
|
||||
SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
|
||||
|
||||
SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
||||
|
||||
SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(2, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(2, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(2, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(2, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
||||
|
||||
SetTextureStageState(3, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(3, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(3, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
SetTextureStageState(3, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(3, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(3, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
||||
|
||||
SetTextureStageState(4, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(4, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(4, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
SetTextureStageState(4, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(4, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(4, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
||||
|
||||
SetTextureStageState(5, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(5, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(5, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
SetTextureStageState(5, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(5, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(5, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
||||
|
||||
SetTextureStageState(6, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(6, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(6, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
SetTextureStageState(6, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(6, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(6, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
||||
|
||||
SetTextureStageState(7, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(7, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(7, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
SetTextureStageState(7, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
SetTextureStageState(7, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
SetTextureStageState(7, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
||||
|
||||
SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
|
||||
SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
|
||||
SetTextureStageState(2, D3DTSS_TEXCOORDINDEX, 2);
|
||||
SetTextureStageState(3, D3DTSS_TEXCOORDINDEX, 3);
|
||||
SetTextureStageState(4, D3DTSS_TEXCOORDINDEX, 4);
|
||||
SetTextureStageState(5, D3DTSS_TEXCOORDINDEX, 5);
|
||||
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);
|
||||
|
||||
SetPixelShader(0);
|
||||
SetVertexShader(D3DFVF_XYZ);
|
||||
|
||||
D3DXVECTOR4 av4Null[STATEMANAGER_MAX_VCONSTANTS];
|
||||
memset(av4Null, 0, sizeof(av4Null));
|
||||
SetVertexShaderConstant(0, av4Null, STATEMANAGER_MAX_VCONSTANTS);
|
||||
SetPixelShaderConstant(0, av4Null, STATEMANAGER_MAX_PCONSTANTS);
|
||||
|
||||
m_bForce = false;
|
||||
|
||||
#ifdef _DEBUG
|
||||
int i, j;
|
||||
for (i = 0; i < STATEMANAGER_MAX_RENDERSTATES; i++)
|
||||
m_bRenderStateSavingFlag[i] = FALSE;
|
||||
|
||||
for (j = 0; j < STATEMANAGER_MAX_TRANSFORMSTATES; j++)
|
||||
m_bTransformSavingFlag[j] = FALSE;
|
||||
|
||||
for (j = 0; j < STATEMANAGER_MAX_STAGES; ++j)
|
||||
for (i = 0; i < STATEMANAGER_MAX_TEXTURESTATES; ++i)
|
||||
m_bTextureStageStateSavingFlag[j][i] = FALSE;
|
||||
#endif _DEBUG
|
||||
}
|
||||
|
||||
// Material
|
||||
void CStateManager::SaveMaterial()
|
||||
{
|
||||
m_CopyState.m_D3DMaterial = m_CurrentState.m_D3DMaterial;
|
||||
}
|
||||
|
||||
void CStateManager::SaveMaterial(const D3DMATERIAL8 * pMaterial)
|
||||
{
|
||||
// Check that we have set this up before, if not, the default is this.
|
||||
m_CopyState.m_D3DMaterial = m_CurrentState.m_D3DMaterial;
|
||||
SetMaterial(pMaterial);
|
||||
}
|
||||
|
||||
void CStateManager::RestoreMaterial()
|
||||
{
|
||||
SetMaterial(&m_CopyState.m_D3DMaterial);
|
||||
}
|
||||
|
||||
void CStateManager::SetMaterial(const D3DMATERIAL8 * pMaterial)
|
||||
{
|
||||
m_lpD3DDev->SetMaterial(pMaterial);
|
||||
m_CurrentState.m_D3DMaterial = *pMaterial;
|
||||
}
|
||||
|
||||
void CStateManager::GetMaterial(D3DMATERIAL8 * pMaterial)
|
||||
{
|
||||
// Set the renderstate and remember it.
|
||||
*pMaterial = m_CurrentState.m_D3DMaterial;
|
||||
}
|
||||
|
||||
// Renderstates
|
||||
DWORD CStateManager::GetRenderState(D3DRENDERSTATETYPE Type)
|
||||
{
|
||||
return m_CurrentState.m_RenderStates[Type];
|
||||
}
|
||||
|
||||
void CStateManager::SaveRenderState(D3DRENDERSTATETYPE Type, DWORD dwValue)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (m_bRenderStateSavingFlag[Type])
|
||||
{
|
||||
Tracef(" CStateManager::SaveRenderState - This render state is already saved [%d, %d]\n", Type, dwValue);
|
||||
StateManager_Assert(!" This render state is already saved!");
|
||||
}
|
||||
m_bRenderStateSavingFlag[Type] = TRUE;
|
||||
#endif _DEBUG
|
||||
|
||||
// Check that we have set this up before, if not, the default is this.
|
||||
m_CopyState.m_RenderStates[Type] = m_CurrentState.m_RenderStates[Type];
|
||||
SetRenderState(Type, dwValue);
|
||||
}
|
||||
|
||||
void CStateManager::RestoreRenderState(D3DRENDERSTATETYPE Type)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (!m_bRenderStateSavingFlag[Type])
|
||||
{
|
||||
Tracef(" CStateManager::SaveRenderState - This render state was not saved [%d, %d]\n", Type);
|
||||
StateManager_Assert(!" This render state was not saved!");
|
||||
}
|
||||
m_bRenderStateSavingFlag[Type] = FALSE;
|
||||
#endif _DEBUG
|
||||
|
||||
SetRenderState(Type, m_CopyState.m_RenderStates[Type]);
|
||||
}
|
||||
|
||||
void CStateManager::SetRenderState(D3DRENDERSTATETYPE Type, DWORD Value)
|
||||
{
|
||||
if (m_CurrentState.m_RenderStates[Type] == Value)
|
||||
return;
|
||||
|
||||
m_lpD3DDev->SetRenderState(Type, Value);
|
||||
m_CurrentState.m_RenderStates[Type] = Value;
|
||||
}
|
||||
|
||||
void CStateManager::GetRenderState(D3DRENDERSTATETYPE Type, DWORD * pdwValue)
|
||||
{
|
||||
*pdwValue = m_CurrentState.m_RenderStates[Type];
|
||||
}
|
||||
|
||||
// Textures
|
||||
void CStateManager::SaveTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 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];
|
||||
SetTexture(dwStage, pTexture);
|
||||
}
|
||||
|
||||
void CStateManager::RestoreTexture(DWORD dwStage)
|
||||
{
|
||||
SetTexture(dwStage, m_CopyState.m_Textures[dwStage]);
|
||||
}
|
||||
|
||||
void CStateManager::SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture)
|
||||
{
|
||||
if (pTexture == m_CurrentState.m_Textures[dwStage])
|
||||
return;
|
||||
|
||||
m_lpD3DDev->SetTexture(dwStage, pTexture);
|
||||
m_CurrentState.m_Textures[dwStage] = pTexture;
|
||||
}
|
||||
|
||||
void CStateManager::GetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 * ppTexture)
|
||||
{
|
||||
*ppTexture = m_CurrentState.m_Textures[dwStage];
|
||||
}
|
||||
|
||||
// Texture stage states
|
||||
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
|
||||
if (m_bTextureStageStateSavingFlag[dwStage][Type])
|
||||
{
|
||||
Tracef(" CStateManager::SaveTextureStageState - This texture stage state is already saved [%d, %d]\n", dwStage, Type);
|
||||
StateManager_Assert(!" This texture stage state is already saved!");
|
||||
}
|
||||
m_bTextureStageStateSavingFlag[dwStage][Type] = TRUE;
|
||||
#endif _DEBUG
|
||||
m_CopyState.m_TextureStates[dwStage][Type] = m_CurrentState.m_TextureStates[dwStage][Type];
|
||||
SetTextureStageState(dwStage, Type, dwValue);
|
||||
}
|
||||
|
||||
void CStateManager::RestoreTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (!m_bTextureStageStateSavingFlag[dwStage][Type])
|
||||
{
|
||||
Tracef(" CStateManager::RestoreTextureStageState - This texture stage state was not saved [%d, %d]\n", dwStage, Type);
|
||||
StateManager_Assert(!" This texture stage state was not saved!");
|
||||
}
|
||||
m_bTextureStageStateSavingFlag[dwStage][Type] = FALSE;
|
||||
#endif _DEBUG
|
||||
SetTextureStageState(dwStage, Type, m_CopyState.m_TextureStates[dwStage][Type]);
|
||||
}
|
||||
|
||||
void CStateManager::SetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue)
|
||||
{
|
||||
if (m_CurrentState.m_TextureStates[dwStage][Type] == dwValue)
|
||||
return;
|
||||
|
||||
m_lpD3DDev->SetTextureStageState(dwStage, Type, dwValue);
|
||||
m_CurrentState.m_TextureStates[dwStage][Type] = dwValue;
|
||||
}
|
||||
|
||||
void CStateManager::GetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD * pdwValue)
|
||||
{
|
||||
*pdwValue = m_CurrentState.m_TextureStates[dwStage][Type];
|
||||
}
|
||||
|
||||
// Vertex Shader
|
||||
void CStateManager::SaveVertexShader(DWORD dwShader)
|
||||
{
|
||||
m_CopyState.m_dwVertexShader = m_CurrentState.m_dwVertexShader;
|
||||
SetVertexShader(dwShader);
|
||||
}
|
||||
|
||||
void CStateManager::RestoreVertexShader()
|
||||
{
|
||||
SetVertexShader(m_CopyState.m_dwVertexShader);
|
||||
}
|
||||
|
||||
void CStateManager::SetVertexShader(DWORD dwShader)
|
||||
{
|
||||
if (m_CurrentState.m_dwVertexShader == dwShader)
|
||||
return;
|
||||
|
||||
m_lpD3DDev->SetVertexShader(dwShader);
|
||||
m_CurrentState.m_dwVertexShader = dwShader;
|
||||
}
|
||||
|
||||
void CStateManager::GetVertexShader(DWORD * pdwShader)
|
||||
{
|
||||
*pdwShader = m_CurrentState.m_dwVertexShader;
|
||||
}
|
||||
|
||||
// Pixel Shader
|
||||
void CStateManager::SavePixelShader(DWORD dwShader)
|
||||
{
|
||||
m_CopyState.m_dwPixelShader = m_CurrentState.m_dwPixelShader;
|
||||
SetPixelShader(dwShader);
|
||||
}
|
||||
|
||||
void CStateManager::RestorePixelShader()
|
||||
{
|
||||
SetPixelShader(m_CopyState.m_dwPixelShader);
|
||||
}
|
||||
|
||||
void CStateManager::SetPixelShader(DWORD dwShader)
|
||||
{
|
||||
if (m_CurrentState.m_dwPixelShader == dwShader)
|
||||
return;
|
||||
|
||||
m_lpD3DDev->SetPixelShader(dwShader);
|
||||
m_CurrentState.m_dwPixelShader = dwShader;
|
||||
}
|
||||
|
||||
void CStateManager::GetPixelShader(DWORD * pdwShader)
|
||||
{
|
||||
*pdwShader = m_CurrentState.m_dwPixelShader;
|
||||
}
|
||||
|
||||
// *** These states are cached, but not protected from multiple sends of the same value.
|
||||
// Transform
|
||||
void CStateManager::SaveTransform(D3DTRANSFORMSTATETYPE Type, const D3DMATRIX* pMatrix)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (m_bTransformSavingFlag[Type])
|
||||
{
|
||||
Tracef(" CStateManager::SaveTransform - This transform is already saved [%d]\n", Type);
|
||||
StateManager_Assert(!" This trasform is already saved!");
|
||||
}
|
||||
m_bTransformSavingFlag[Type] = TRUE;
|
||||
#endif _DEBUG
|
||||
|
||||
m_CopyState.m_Matrices[Type] = m_CurrentState.m_Matrices[Type];
|
||||
SetTransform(Type, (D3DXMATRIX *)pMatrix);
|
||||
}
|
||||
|
||||
void CStateManager::RestoreTransform(D3DTRANSFORMSTATETYPE Type)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (!m_bTransformSavingFlag[Type])
|
||||
{
|
||||
Tracef(" CStateManager::RestoreTransform - This transform was not saved [%d]\n", Type);
|
||||
StateManager_Assert(!" This render state was not saved!");
|
||||
}
|
||||
m_bTransformSavingFlag[Type] = FALSE;
|
||||
#endif _DEBUG
|
||||
|
||||
SetTransform(Type, &m_CopyState.m_Matrices[Type]);
|
||||
}
|
||||
|
||||
// Don't cache-check the transform. To much to do
|
||||
void CStateManager::SetTransform(D3DTRANSFORMSTATETYPE Type, const D3DMATRIX* pMatrix)
|
||||
{
|
||||
if (m_bScene)
|
||||
{
|
||||
m_lpD3DDev->SetTransform(Type, pMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(D3DTS_VIEW==Type || D3DTS_PROJECTION==Type || D3DTS_WORLD==Type);
|
||||
}
|
||||
|
||||
m_CurrentState.m_Matrices[Type] = *pMatrix;
|
||||
}
|
||||
|
||||
void CStateManager::GetTransform(D3DTRANSFORMSTATETYPE Type, D3DMATRIX * pMatrix)
|
||||
{
|
||||
*pMatrix = m_CurrentState.m_Matrices[Type];
|
||||
}
|
||||
|
||||
// SetVertexShaderConstant
|
||||
void CStateManager::SaveVertexShaderConstant(DWORD dwRegister,CONST void* pConstantData,DWORD dwConstantCount)
|
||||
{
|
||||
DWORD i;
|
||||
|
||||
for (i = 0; i < dwConstantCount; i++)
|
||||
{
|
||||
StateManager_Assert((dwRegister + i) < STATEMANAGER_MAX_VCONSTANTS);
|
||||
m_CopyState.m_VertexShaderConstants[dwRegister + i] = m_CurrentState.m_VertexShaderConstants[dwRegister + i];
|
||||
}
|
||||
|
||||
SetVertexShaderConstant(dwRegister, pConstantData, dwConstantCount);
|
||||
}
|
||||
|
||||
void CStateManager::RestoreVertexShaderConstant(DWORD dwRegister, DWORD 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);
|
||||
|
||||
// Set the renderstate and remember it.
|
||||
for (DWORD i = 0; i < dwConstantCount; i++)
|
||||
{
|
||||
StateManager_Assert((dwRegister + i) < STATEMANAGER_MAX_VCONSTANTS);
|
||||
m_CurrentState.m_VertexShaderConstants[dwRegister + i] = *(((D3DXVECTOR4*)pConstantData) + i);
|
||||
}
|
||||
}
|
||||
|
||||
// SetPixelShaderConstant
|
||||
void CStateManager::SavePixelShaderConstant(DWORD dwRegister,CONST void* pConstantData,DWORD dwConstantCount)
|
||||
{
|
||||
DWORD i;
|
||||
|
||||
for (i = 0; i < dwConstantCount; i++)
|
||||
{
|
||||
StateManager_Assert((dwRegister + i) < STATEMANAGER_MAX_VCONSTANTS);
|
||||
m_CopyState.m_PixelShaderConstants[dwRegister + i] = *(((D3DXVECTOR4*)pConstantData) + i);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// Set the renderstate and remember it.
|
||||
for (DWORD i = 0; i < dwConstantCount; i++)
|
||||
{
|
||||
StateManager_Assert((dwRegister + i) < STATEMANAGER_MAX_VCONSTANTS);
|
||||
m_CurrentState.m_PixelShaderConstants[dwRegister + i] = *(((D3DXVECTOR4*)pConstantData) + i);
|
||||
}
|
||||
}
|
||||
|
||||
void CStateManager::SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 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];
|
||||
SetStreamSource(StreamNumber, pStreamData, Stride);
|
||||
}
|
||||
|
||||
void CStateManager::RestoreStreamSource(UINT StreamNumber)
|
||||
{
|
||||
SetStreamSource(StreamNumber,
|
||||
m_CopyState.m_StreamData[StreamNumber].m_lpStreamData,
|
||||
m_CopyState.m_StreamData[StreamNumber].m_Stride);
|
||||
}
|
||||
|
||||
void CStateManager::SetStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData, UINT Stride)
|
||||
{
|
||||
CStreamData kStreamData(pStreamData, Stride);
|
||||
if (m_CurrentState.m_StreamData[StreamNumber] == kStreamData)
|
||||
return;
|
||||
|
||||
m_lpD3DDev->SetStreamSource(StreamNumber, pStreamData, Stride);
|
||||
m_CurrentState.m_StreamData[StreamNumber] = kStreamData;
|
||||
}
|
||||
|
||||
void CStateManager::SaveIndices(LPDIRECT3DINDEXBUFFER8 pIndexData, UINT BaseVertexIndex)
|
||||
{
|
||||
m_CopyState.m_IndexData = m_CurrentState.m_IndexData;
|
||||
SetIndices(pIndexData, BaseVertexIndex);
|
||||
}
|
||||
|
||||
void CStateManager::RestoreIndices()
|
||||
{
|
||||
SetIndices(m_CopyState.m_IndexData.m_lpIndexData, m_CopyState.m_IndexData.m_BaseVertexIndex);
|
||||
}
|
||||
|
||||
void CStateManager::SetIndices(LPDIRECT3DINDEXBUFFER8 pIndexData, UINT BaseVertexIndex)
|
||||
{
|
||||
CIndexData kIndexData(pIndexData, BaseVertexIndex);
|
||||
|
||||
if (m_CurrentState.m_IndexData == kIndexData)
|
||||
return;
|
||||
|
||||
m_lpD3DDev->SetIndices(pIndexData, BaseVertexIndex);
|
||||
m_CurrentState.m_IndexData = kIndexData;
|
||||
}
|
||||
|
||||
HRESULT CStateManager::DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
|
||||
{
|
||||
return (m_lpD3DDev->DrawPrimitive(PrimitiveType, StartVertex, PrimitiveCount));
|
||||
}
|
||||
|
||||
HRESULT CStateManager::DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride)
|
||||
{
|
||||
m_CurrentState.m_StreamData[0] = NULL;
|
||||
return (m_lpD3DDev->DrawPrimitiveUP(PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride));
|
||||
}
|
||||
|
||||
HRESULT CStateManager::DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT minIndex, UINT NumVertices, UINT startIndex, UINT primCount)
|
||||
{
|
||||
return (m_lpD3DDev->DrawIndexedPrimitive(PrimitiveType, 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)
|
||||
{
|
||||
m_CurrentState.m_IndexData = NULL;
|
||||
m_CurrentState.m_StreamData[0] = NULL;
|
||||
return (m_lpD3DDev->DrawIndexedPrimitiveUP(PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride));
|
||||
}
|
||||
@@ -408,6 +408,56 @@ typedef enum _D3DCULL {
|
||||
D3DCULL_FORCE_DWORD = 0x7fffffff,
|
||||
} D3DCULL;
|
||||
|
||||
typedef enum _D3DTEXTUREFILTERTYPE {
|
||||
D3DTEXF_NONE = 0,
|
||||
D3DTEXF_POINT = 1,
|
||||
D3DTEXF_LINEAR = 2,
|
||||
D3DTEXF_ANISOTROPIC = 3,
|
||||
D3DTEXF_FLATCUBIC = 4,
|
||||
D3DTEXF_GAUSSIANCUBIC = 5,
|
||||
D3DTEXF_FORCE_DWORD = 0x7fffffff
|
||||
} D3DTEXTUREFILTERTYPE;
|
||||
|
||||
typedef enum _D3DSHADEMODE {
|
||||
D3DSHADE_FLAT = 1,
|
||||
D3DSHADE_GOURAUD = 2,
|
||||
D3DSHADE_PHONG = 3,
|
||||
D3DSHADE_FORCE_DWORD = 0x7fffffff
|
||||
} D3DSHADEMODE;
|
||||
|
||||
typedef enum _D3DBLENDOP {
|
||||
D3DBLENDOP_ADD = 1,
|
||||
D3DBLENDOP_SUBTRACT = 2,
|
||||
D3DBLENDOP_REVSUBTRACT = 3,
|
||||
D3DBLENDOP_MIN = 4,
|
||||
D3DBLENDOP_MAX = 5,
|
||||
D3DBLENDOP_FORCE_DWORD = 0x7fffffff
|
||||
} D3DBLENDOP;
|
||||
|
||||
typedef enum _D3DFOGMODE {
|
||||
D3DFOG_NONE = 0,
|
||||
D3DFOG_EXP = 1,
|
||||
D3DFOG_EXP2 = 2,
|
||||
D3DFOG_LINEAR = 3,
|
||||
D3DFOG_FORCE_DWORD = 0x7fffffff
|
||||
} D3DFOGMODE;
|
||||
|
||||
typedef enum _D3DMATERIALCOLORSOURCE {
|
||||
D3DMCS_MATERIAL = 0,
|
||||
D3DMCS_COLOR1 = 1,
|
||||
D3DMCS_COLOR2 = 2,
|
||||
D3DMCS_FORCE_DWORD = 0x7fffffff
|
||||
} D3DMATERIALCOLORSOURCE;
|
||||
|
||||
typedef enum _D3DVERTEXBLENDFLAGS {
|
||||
D3DVBF_DISABLE = 0,
|
||||
D3DVBF_1WEIGHTS = 1,
|
||||
D3DVBF_2WEIGHTS = 2,
|
||||
D3DVBF_3WEIGHTS = 3,
|
||||
D3DVBF_TWEENING = 255,
|
||||
D3DVBF_0WEIGHTS = 256
|
||||
} D3DVERTEXBLENDFLAGS;
|
||||
|
||||
#define D3DTS_WORLDMATRIX(index) (D3DTRANSFORMSTATETYPE)(index + 256)
|
||||
#define D3DTS_WORLD D3DTS_WORLDMATRIX(0)
|
||||
#define D3DTS_WORLD1 D3DTS_WORLDMATRIX(1)
|
||||
@@ -593,16 +643,72 @@ typedef struct _D3DCAPS8
|
||||
float MaxPixelShaderValue;
|
||||
} D3DCAPS8;
|
||||
|
||||
// COM interfaces: no methods here; platform/ owns every instance. The resource hierarchy is kept
|
||||
// so the implicit upcasts 40250 relies on (texture -> base texture) compile.
|
||||
#define D3DDEVCAPS_HWTRANSFORMANDLIGHT 0x00010000L
|
||||
#define D3DPTFILTERCAPS_MINFANISOTROPIC 0x00000400L
|
||||
#define D3DPTFILTERCAPS_MAGFANISOTROPIC 0x04000000L
|
||||
#define D3DPTADDRESSCAPS_WRAP 0x00000001L
|
||||
#define D3DPTADDRESSCAPS_MIRROR 0x00000002L
|
||||
#define D3DPTADDRESSCAPS_CLAMP 0x00000004L
|
||||
#define D3DPTADDRESSCAPS_BORDER 0x00000008L
|
||||
|
||||
#define D3DADAPTER_DEFAULT 0
|
||||
#define D3DCREATE_SOFTWARE_VERTEXPROCESSING 0x00000020L
|
||||
#define D3DCREATE_HARDWARE_VERTEXPROCESSING 0x00000040L
|
||||
#define D3DCREATE_MIXED_VERTEXPROCESSING 0x00000080L
|
||||
#define D3DVS_VERSION(_Major, _Minor) (0xFFFE0000 | ((_Major) << 8) | (_Minor))
|
||||
#define D3DPMISCCAPS_CLIPTLVERTS 0x00000200L
|
||||
|
||||
// COM interfaces: platform/ owns every instance. The resource hierarchy is kept so the implicit
|
||||
// upcasts 40250 relies on (texture -> base texture) compile; of the resources only the buffers carry
|
||||
// methods (Lock/Unlock, platform/EterLib/CpuBuffer.h).
|
||||
struct IDirect3D8;
|
||||
struct IDirect3DDevice8;
|
||||
struct IDirect3DResource8 {};
|
||||
struct IDirect3DBaseTexture8 : IDirect3DResource8 {};
|
||||
struct IDirect3DTexture8 : IDirect3DBaseTexture8 {};
|
||||
struct IDirect3DSurface8 : IDirect3DResource8 {};
|
||||
struct IDirect3DVertexBuffer8 : IDirect3DResource8 {};
|
||||
struct IDirect3DIndexBuffer8 : IDirect3DResource8 {};
|
||||
struct IDirect3DVertexBuffer8 : IDirect3DResource8
|
||||
{
|
||||
virtual ~IDirect3DVertexBuffer8() = default;
|
||||
virtual HRESULT Lock(UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags) = 0;
|
||||
virtual HRESULT Unlock() = 0;
|
||||
};
|
||||
struct IDirect3DIndexBuffer8 : IDirect3DResource8
|
||||
{
|
||||
virtual ~IDirect3DIndexBuffer8() = default;
|
||||
virtual HRESULT Lock(UINT OffsetToLock, UINT SizeToLock, BYTE** ppbData, DWORD Flags) = 0;
|
||||
virtual HRESULT Unlock() = 0;
|
||||
};
|
||||
|
||||
// The device methods the ported code calls (CStateManager), with D3D8's signatures. The platform
|
||||
// implements it (platform/EterLib/RecordingDevice.h) as a device that records draw calls.
|
||||
struct IDirect3DDevice8
|
||||
{
|
||||
virtual ~IDirect3DDevice8() = default;
|
||||
virtual ULONG AddRef() = 0;
|
||||
virtual ULONG Release() = 0;
|
||||
virtual HRESULT GetDeviceCaps(D3DCAPS8* pCaps) = 0;
|
||||
virtual HRESULT GetViewport(D3DVIEWPORT8* pViewport) = 0;
|
||||
virtual UINT GetAvailableTextureMem() = 0;
|
||||
virtual HRESULT BeginScene() = 0;
|
||||
virtual HRESULT EndScene() = 0;
|
||||
virtual HRESULT SetTransform(D3DTRANSFORMSTATETYPE State, const D3DMATRIX* pMatrix) = 0;
|
||||
virtual HRESULT GetTransform(D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) = 0;
|
||||
virtual HRESULT SetMaterial(const D3DMATERIAL8* pMaterial) = 0;
|
||||
virtual HRESULT SetLight(DWORD Index, const D3DLIGHT8* pLight) = 0;
|
||||
virtual HRESULT SetRenderState(D3DRENDERSTATETYPE State, DWORD Value) = 0;
|
||||
virtual HRESULT SetTexture(DWORD Stage, IDirect3DBaseTexture8* pTexture) = 0;
|
||||
virtual HRESULT SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) = 0;
|
||||
virtual HRESULT SetVertexShader(DWORD Handle) = 0;
|
||||
virtual HRESULT SetPixelShader(DWORD Handle) = 0;
|
||||
virtual HRESULT SetVertexShaderConstant(DWORD Register, const void* pConstantData, DWORD ConstantCount) = 0;
|
||||
virtual HRESULT SetPixelShaderConstant(DWORD Register, const void* pConstantData, DWORD ConstantCount) = 0;
|
||||
virtual HRESULT SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer8* pStreamData, UINT Stride) = 0;
|
||||
virtual HRESULT SetIndices(IDirect3DIndexBuffer8* pIndexData, UINT BaseVertexIndex) = 0;
|
||||
virtual HRESULT DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) = 0;
|
||||
virtual HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount) = 0;
|
||||
virtual HRESULT DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride) = 0;
|
||||
virtual HRESULT DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, const void* pIndexData, D3DFORMAT IndexDataFormat, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride) = 0;
|
||||
};
|
||||
typedef IDirect3D8* LPDIRECT3D8;
|
||||
typedef IDirect3DDevice8* LPDIRECT3DDEVICE8;
|
||||
typedef IDirect3DResource8* LPDIRECT3DRESOURCE8;
|
||||
|
||||
@@ -341,3 +341,144 @@ D3DXQUATERNION* D3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION* pOut, FLOAT y
|
||||
pOut->w = cyaw * cpitch * croll + syaw * spitch * sroll;
|
||||
return pOut;
|
||||
}
|
||||
|
||||
D3DXMATRIX* D3DXMatrixPerspectiveFovRH(D3DXMATRIX* pOut, FLOAT fovy, FLOAT aspect, FLOAT zn, FLOAT zf)
|
||||
{
|
||||
const FLOAT yScale = 1.0f / tanf(fovy / 2.0f);
|
||||
*pOut = D3DXMATRIX(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
pOut->_11 = yScale / aspect;
|
||||
pOut->_22 = yScale;
|
||||
pOut->_33 = zf / (zn - zf);
|
||||
pOut->_34 = -1.0f;
|
||||
pOut->_43 = zn * zf / (zn - zf);
|
||||
return pOut;
|
||||
}
|
||||
|
||||
D3DXMATRIX* D3DXMatrixOrthoRH(D3DXMATRIX* pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf)
|
||||
{
|
||||
D3DXMatrixIdentity(pOut);
|
||||
pOut->_11 = 2.0f / w;
|
||||
pOut->_22 = 2.0f / h;
|
||||
pOut->_33 = 1.0f / (zn - zf);
|
||||
pOut->_43 = zn / (zn - zf);
|
||||
return pOut;
|
||||
}
|
||||
|
||||
D3DXMATRIX* D3DXMatrixOrthoOffCenterRH(D3DXMATRIX* pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, FLOAT zf)
|
||||
{
|
||||
D3DXMatrixIdentity(pOut);
|
||||
pOut->_11 = 2.0f / (r - l);
|
||||
pOut->_22 = 2.0f / (t - b);
|
||||
pOut->_33 = 1.0f / (zn - zf);
|
||||
pOut->_41 = (l + r) / (l - r);
|
||||
pOut->_42 = (t + b) / (b - t);
|
||||
pOut->_43 = zn / (zn - zf);
|
||||
return pOut;
|
||||
}
|
||||
|
||||
ID3DXMatrixStack::ID3DXMatrixStack() : m_stack(1)
|
||||
{
|
||||
D3DXMatrixIdentity(&m_stack.back());
|
||||
}
|
||||
|
||||
ULONG ID3DXMatrixStack::Release()
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::Pop()
|
||||
{
|
||||
if (m_stack.size() > 1)
|
||||
m_stack.pop_back();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::Push()
|
||||
{
|
||||
m_stack.push_back(m_stack.back());
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::LoadIdentity()
|
||||
{
|
||||
D3DXMatrixIdentity(&m_stack.back());
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::LoadMatrix(const D3DXMATRIX* pM)
|
||||
{
|
||||
m_stack.back() = *pM;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::MultMatrix(const D3DXMATRIX* pM)
|
||||
{
|
||||
D3DXMatrixMultiply(&m_stack.back(), &m_stack.back(), pM);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::MultMatrixLocal(const D3DXMATRIX* pM)
|
||||
{
|
||||
D3DXMatrixMultiply(&m_stack.back(), pM, &m_stack.back());
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::RotateAxis(const D3DXVECTOR3* pV, FLOAT angle)
|
||||
{
|
||||
D3DXMATRIX m;
|
||||
return MultMatrix(D3DXMatrixRotationAxis(&m, pV, angle));
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::RotateAxisLocal(const D3DXVECTOR3* pV, FLOAT angle)
|
||||
{
|
||||
D3DXMATRIX m;
|
||||
return MultMatrixLocal(D3DXMatrixRotationAxis(&m, pV, angle));
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::RotateYawPitchRoll(FLOAT yaw, FLOAT pitch, FLOAT roll)
|
||||
{
|
||||
D3DXMATRIX m;
|
||||
return MultMatrix(D3DXMatrixRotationYawPitchRoll(&m, yaw, pitch, roll));
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::RotateYawPitchRollLocal(FLOAT yaw, FLOAT pitch, FLOAT roll)
|
||||
{
|
||||
D3DXMATRIX m;
|
||||
return MultMatrixLocal(D3DXMatrixRotationYawPitchRoll(&m, yaw, pitch, roll));
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::Scale(FLOAT x, FLOAT y, FLOAT z)
|
||||
{
|
||||
D3DXMATRIX m;
|
||||
return MultMatrix(D3DXMatrixScaling(&m, x, y, z));
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::ScaleLocal(FLOAT x, FLOAT y, FLOAT z)
|
||||
{
|
||||
D3DXMATRIX m;
|
||||
return MultMatrixLocal(D3DXMatrixScaling(&m, x, y, z));
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::Translate(FLOAT x, FLOAT y, FLOAT z)
|
||||
{
|
||||
D3DXMATRIX m;
|
||||
return MultMatrix(D3DXMatrixTranslation(&m, x, y, z));
|
||||
}
|
||||
|
||||
HRESULT ID3DXMatrixStack::TranslateLocal(FLOAT x, FLOAT y, FLOAT z)
|
||||
{
|
||||
D3DXMATRIX m;
|
||||
return MultMatrixLocal(D3DXMatrixTranslation(&m, x, y, z));
|
||||
}
|
||||
|
||||
D3DXMATRIX* ID3DXMatrixStack::GetTop()
|
||||
{
|
||||
return &m_stack.back();
|
||||
}
|
||||
|
||||
HRESULT D3DXCreateMatrixStack(DWORD, ID3DXMatrixStack** ppStack)
|
||||
{
|
||||
*ppStack = new ID3DXMatrixStack;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "D3D8Types.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
|
||||
#define D3DX_PI ((FLOAT)3.141592654f)
|
||||
#define D3DX_1BYPI ((FLOAT)0.318309886f)
|
||||
@@ -368,6 +369,9 @@ D3DXMATRIX* D3DXMatrixRotationZ(D3DXMATRIX* pOut, FLOAT angle);
|
||||
D3DXMATRIX* D3DXMatrixRotationAxis(D3DXMATRIX* pOut, const D3DXVECTOR3* pV, FLOAT angle);
|
||||
D3DXMATRIX* D3DXMatrixRotationQuaternion(D3DXMATRIX* pOut, const D3DXQUATERNION* pQ);
|
||||
D3DXMATRIX* D3DXMatrixRotationYawPitchRoll(D3DXMATRIX* pOut, FLOAT yaw, FLOAT pitch, FLOAT roll);
|
||||
D3DXMATRIX* D3DXMatrixPerspectiveFovRH(D3DXMATRIX* pOut, FLOAT fovy, FLOAT aspect, FLOAT zn, FLOAT zf);
|
||||
D3DXMATRIX* D3DXMatrixOrthoRH(D3DXMATRIX* pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf);
|
||||
D3DXMATRIX* D3DXMatrixOrthoOffCenterRH(D3DXMATRIX* pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, FLOAT zf);
|
||||
|
||||
// --- D3DXQUATERNION ---
|
||||
inline D3DXQUATERNION* D3DXQuaternionIdentity(D3DXQUATERNION* pOut)
|
||||
@@ -386,3 +390,29 @@ inline FLOAT D3DXPlaneDotCoord(const D3DXPLANE* pP, const D3DXVECTOR3* pV)
|
||||
{
|
||||
return pP->a * pV->x + pP->b * pV->y + pP->c * pV->z + pP->d;
|
||||
}
|
||||
|
||||
// --- ID3DXMatrixStack --- (the D3DX8 interface, as a plain class: the Local variants pre-multiply)
|
||||
struct ID3DXMatrixStack
|
||||
{
|
||||
ID3DXMatrixStack();
|
||||
ULONG Release();
|
||||
HRESULT Pop();
|
||||
HRESULT Push();
|
||||
HRESULT LoadIdentity();
|
||||
HRESULT LoadMatrix(const D3DXMATRIX* pM);
|
||||
HRESULT MultMatrix(const D3DXMATRIX* pM);
|
||||
HRESULT MultMatrixLocal(const D3DXMATRIX* pM);
|
||||
HRESULT RotateAxis(const D3DXVECTOR3* pV, FLOAT angle);
|
||||
HRESULT RotateAxisLocal(const D3DXVECTOR3* pV, FLOAT angle);
|
||||
HRESULT RotateYawPitchRoll(FLOAT yaw, FLOAT pitch, FLOAT roll);
|
||||
HRESULT RotateYawPitchRollLocal(FLOAT yaw, FLOAT pitch, FLOAT roll);
|
||||
HRESULT Scale(FLOAT x, FLOAT y, FLOAT z);
|
||||
HRESULT ScaleLocal(FLOAT x, FLOAT y, FLOAT z);
|
||||
HRESULT Translate(FLOAT x, FLOAT y, FLOAT z);
|
||||
HRESULT TranslateLocal(FLOAT x, FLOAT y, FLOAT z);
|
||||
D3DXMATRIX* GetTop();
|
||||
|
||||
private:
|
||||
std::vector<D3DXMATRIX> m_stack;
|
||||
};
|
||||
HRESULT D3DXCreateMatrixStack(DWORD Flags, ID3DXMatrixStack** ppStack);
|
||||
|
||||
Reference in New Issue
Block a user