ported to DX9
This commit is contained in:
@@ -93,7 +93,7 @@ void CBlockTexture::Render(int ix, int iy)
|
||||
|
||||
STATEMANAGER.SetTexture(0, m_lpd3dTexture);
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_DIFFUSE);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_DIFFUSE);
|
||||
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,7 @@ void CBlockTexture::InvalidateRect(const RECT & c_rsrcRect)
|
||||
|
||||
bool CBlockTexture::Create(CGraphicDib * pDIB, const RECT & c_rRect, DWORD dwWidth, DWORD dwHeight)
|
||||
{
|
||||
if (FAILED(ms_lpd3dDevice->CreateTexture(dwWidth, dwHeight, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_lpd3dTexture)))
|
||||
if (FAILED(ms_lpd3dDevice->CreateTexture(dwWidth, dwHeight, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_lpd3dTexture, nullptr)))
|
||||
{
|
||||
Tracef("Failed to create block texture %u, %u\n", dwWidth, dwHeight);
|
||||
return false;
|
||||
|
||||
@@ -22,5 +22,5 @@ class CBlockTexture : public CGraphicBase
|
||||
BOOL m_bClipEnable;
|
||||
DWORD m_dwWidth;
|
||||
DWORD m_dwHeight;
|
||||
LPDIRECT3DTEXTURE8 m_lpd3dTexture;
|
||||
LPDIRECT3DTEXTURE9 m_lpd3dTexture;
|
||||
};
|
||||
|
||||
@@ -279,7 +279,7 @@ void CCamera::SetViewMatrix()
|
||||
|
||||
D3DXMatrixLookAtRH(&m_matView, &m_v3Eye, &m_v3Target, &m_v3Up);
|
||||
|
||||
float fDeterminantD3DMatView = D3DXMatrixfDeterminant(&m_matView);
|
||||
float fDeterminantD3DMatView = D3DXMatrixDeterminant(&m_matView);
|
||||
D3DXMatrixInverse(&m_matInverseView, &fDeterminantD3DMatView, &m_matView);
|
||||
|
||||
m_matBillboard = m_matInverseView;
|
||||
|
||||
@@ -227,7 +227,7 @@ void CDecal::Render()
|
||||
D3DXMatrixIdentity(&matWorld);
|
||||
STATEMANAGER.SetTransform(D3DTS_WORLD, &matWorld);
|
||||
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
|
||||
for (DWORD dwi = 0; dwi < m_TriangleFanStructVector.size(); ++dwi)
|
||||
STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLEFAN,
|
||||
|
||||
@@ -19,19 +19,14 @@ void D3DXVECTOR3ToPixelPosition(const D3DXVECTOR3& c_rv3Src, D3DXVECTOR3* pv3Dst
|
||||
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;
|
||||
LPDIRECT3D9 CGraphicBase::ms_lpd3d = NULL;
|
||||
LPDIRECT3DDEVICE9 CGraphicBase::ms_lpd3dDevice = NULL;
|
||||
ID3DXMatrixStack * CGraphicBase::ms_lpd3dMatStack = NULL;
|
||||
D3DPRESENT_PARAMETERS CGraphicBase::ms_d3dPresentParameter;
|
||||
D3DVIEWPORT8 CGraphicBase::ms_Viewport;
|
||||
D3DVIEWPORT9 CGraphicBase::ms_Viewport;
|
||||
|
||||
HRESULT CGraphicBase::ms_hLastResult = NULL;
|
||||
|
||||
@@ -40,13 +35,13 @@ int CGraphicBase::ms_iHeight;
|
||||
|
||||
DWORD CGraphicBase::ms_faceCount = 0;
|
||||
|
||||
D3DCAPS8 CGraphicBase::ms_d3dCaps;
|
||||
D3DCAPS9 CGraphicBase::ms_d3dCaps;
|
||||
|
||||
DWORD CGraphicBase::ms_dwD3DBehavior = 0;
|
||||
|
||||
DWORD CGraphicBase::ms_ptVS = 0;
|
||||
DWORD CGraphicBase::ms_pntVS = 0;
|
||||
DWORD CGraphicBase::ms_pnt2VS = 0;
|
||||
LPDIRECT3DVERTEXDECLARATION9 CGraphicBase::ms_ptVS = 0;
|
||||
LPDIRECT3DVERTEXDECLARATION9 CGraphicBase::ms_pntVS = 0;
|
||||
LPDIRECT3DVERTEXDECLARATION9 CGraphicBase::ms_pnt2VS = 0;
|
||||
|
||||
D3DXMATRIX CGraphicBase::ms_matIdentity;
|
||||
|
||||
@@ -96,9 +91,9 @@ std::vector<TIndex> CGraphicBase::ms_fillCubeIdxVector;
|
||||
LPD3DXMESH CGraphicBase::ms_lpSphereMesh = NULL;
|
||||
LPD3DXMESH CGraphicBase::ms_lpCylinderMesh = NULL;
|
||||
|
||||
LPDIRECT3DVERTEXBUFFER8 CGraphicBase::ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM];
|
||||
LPDIRECT3DVERTEXBUFFER9 CGraphicBase::ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM];
|
||||
|
||||
LPDIRECT3DINDEXBUFFER8 CGraphicBase::ms_alpd3dDefIB[DEFAULT_IB_NUM];
|
||||
LPDIRECT3DINDEXBUFFER9 CGraphicBase::ms_alpd3dDefIB[DEFAULT_IB_NUM];
|
||||
|
||||
bool CGraphicBase::IsLowTextureMemory()
|
||||
{
|
||||
@@ -158,7 +153,7 @@ bool CGraphicBase::SetPDTStream(SPDTVertexRaw* pSrcVertices, UINT uVtxCount)
|
||||
if (s_dwVBPos>=PDT_VERTEXBUFFER_NUM)
|
||||
s_dwVBPos=0;
|
||||
|
||||
IDirect3DVertexBuffer8* plpd3dFillRectVB=ms_alpd3dPDTVB[s_dwVBPos];
|
||||
IDirect3DVertexBuffer9* plpd3dFillRectVB=ms_alpd3dPDTVB[s_dwVBPos];
|
||||
++s_dwVBPos;
|
||||
|
||||
assert(PDT_VERTEX_NUM>=uVtxCount);
|
||||
@@ -167,7 +162,7 @@ bool CGraphicBase::SetPDTStream(SPDTVertexRaw* pSrcVertices, UINT uVtxCount)
|
||||
|
||||
TPDTVertex* pDstVertices;
|
||||
if (FAILED(
|
||||
plpd3dFillRectVB->Lock(0, sizeof(TPDTVertex)*uVtxCount, (BYTE**)&pDstVertices, D3DLOCK_DISCARD)
|
||||
plpd3dFillRectVB->Lock(0, sizeof(TPDTVertex)*uVtxCount, (void**)&pDstVertices, D3DLOCK_DISCARD)
|
||||
))
|
||||
{
|
||||
STATEMANAGER.SetStreamSource(0, NULL, 0);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "GrpDetector.h"
|
||||
#include "Ray.h"
|
||||
#include <vector>
|
||||
|
||||
@@ -238,28 +237,23 @@ class CGraphicBase
|
||||
static HRESULT ms_hLastResult;
|
||||
|
||||
static int ms_iWidth;
|
||||
static int ms_iHeight;
|
||||
|
||||
static UINT ms_iD3DAdapterInfo;
|
||||
static UINT ms_iD3DDevInfo;
|
||||
static UINT ms_iD3DModeInfo;
|
||||
static D3D_CDisplayModeAutoDetector ms_kD3DDetector;
|
||||
static int ms_iHeight;
|
||||
|
||||
static HWND ms_hWnd;
|
||||
static HDC ms_hDC;
|
||||
static LPDIRECT3D8 ms_lpd3d;
|
||||
static LPDIRECT3DDEVICE8 ms_lpd3dDevice;
|
||||
static LPDIRECT3D9 ms_lpd3d;
|
||||
static LPDIRECT3DDEVICE9 ms_lpd3dDevice;
|
||||
static ID3DXMatrixStack* ms_lpd3dMatStack;
|
||||
static D3DVIEWPORT8 ms_Viewport;
|
||||
static D3DVIEWPORT9 ms_Viewport;
|
||||
|
||||
static DWORD ms_faceCount;
|
||||
static D3DCAPS8 ms_d3dCaps;
|
||||
static D3DCAPS9 ms_d3dCaps;
|
||||
static D3DPRESENT_PARAMETERS ms_d3dPresentParameter;
|
||||
|
||||
static DWORD ms_dwD3DBehavior;
|
||||
static DWORD ms_ptVS;
|
||||
static DWORD ms_pntVS;
|
||||
static DWORD ms_pnt2VS;
|
||||
static LPDIRECT3DVERTEXDECLARATION9 ms_ptVS;
|
||||
static LPDIRECT3DVERTEXDECLARATION9 ms_pntVS;
|
||||
static LPDIRECT3DVERTEXDECLARATION9 ms_pnt2VS;
|
||||
|
||||
static D3DXMATRIX ms_matScreen0;
|
||||
static D3DXMATRIX ms_matScreen1;
|
||||
@@ -307,6 +301,6 @@ class CGraphicBase
|
||||
};
|
||||
|
||||
|
||||
static LPDIRECT3DVERTEXBUFFER8 ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM];
|
||||
static LPDIRECT3DINDEXBUFFER8 ms_alpd3dDefIB[DEFAULT_IB_NUM];
|
||||
static LPDIRECT3DVERTEXBUFFER9 ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM];
|
||||
static LPDIRECT3DINDEXBUFFER9 ms_alpd3dDefIB[DEFAULT_IB_NUM];
|
||||
};
|
||||
|
||||
@@ -1,647 +0,0 @@
|
||||
#include "StdAfx.h"
|
||||
#include "../eterBase/Stl.h"
|
||||
#include "GrpDetector.h"
|
||||
|
||||
struct FIsEqualD3DDisplayMode
|
||||
{
|
||||
FIsEqualD3DDisplayMode(D3DDISPLAYMODE* pkD3DDMChk)
|
||||
{
|
||||
m_pkD3DDMChk=pkD3DDMChk;
|
||||
}
|
||||
BOOL operator() (D3DDISPLAYMODE& rkD3DDMTest)
|
||||
{
|
||||
if (rkD3DDMTest.Width!=m_pkD3DDMChk->Width)
|
||||
return FALSE;
|
||||
|
||||
if (rkD3DDMTest.Height!=m_pkD3DDMChk->Height)
|
||||
return FALSE;
|
||||
|
||||
if (rkD3DDMTest.Format!=m_pkD3DDMChk->Format)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
D3DDISPLAYMODE* m_pkD3DDMChk;
|
||||
};
|
||||
|
||||
static int CompareD3DDisplayModeOrder( const VOID* arg1, const VOID* arg2 )
|
||||
{
|
||||
D3DDISPLAYMODE* p1 = (D3DDISPLAYMODE*)arg1;
|
||||
D3DDISPLAYMODE* p2 = (D3DDISPLAYMODE*)arg2;
|
||||
|
||||
if( p1->Format > p2->Format ) return -1;
|
||||
if( p1->Format < p2->Format ) return +1;
|
||||
if( p1->Width < p2->Width ) return -1;
|
||||
if( p1->Width > p2->Width ) return +1;
|
||||
if( p1->Height < p2->Height ) return -1;
|
||||
if( p1->Height > p2->Height ) return +1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
UINT D3D_CAdapterDisplayModeList::GetDisplayModeNum()
|
||||
{
|
||||
return m_uD3DDMNum;
|
||||
}
|
||||
|
||||
UINT D3D_CAdapterDisplayModeList::GetPixelFormatNum()
|
||||
{
|
||||
return m_uD3DFmtNum;
|
||||
}
|
||||
|
||||
|
||||
const D3DDISPLAYMODE& D3D_CAdapterDisplayModeList::GetDisplayModer(UINT iD3DDM)
|
||||
{
|
||||
assert(iD3DDM<m_uD3DDMNum);
|
||||
return m_akD3DDM[iD3DDM];
|
||||
}
|
||||
|
||||
const D3DFORMAT& D3D_CAdapterDisplayModeList::GetPixelFormatr(UINT iD3DFmt)
|
||||
{
|
||||
assert(iD3DFmt<m_uD3DFmtNum);
|
||||
return m_aeD3DFmt[iD3DFmt];
|
||||
}
|
||||
|
||||
VOID D3D_CAdapterDisplayModeList::Build(IDirect3D8& rkD3D, D3DFORMAT eD3DFmtDefault, UINT iD3DAdapterInfo)
|
||||
{
|
||||
D3DDISPLAYMODE* akD3DDM=m_akD3DDM;
|
||||
D3DFORMAT* aeD3DFmt=m_aeD3DFmt;
|
||||
|
||||
UINT uD3DDMNum=0;
|
||||
UINT uD3DFmtNum=0;
|
||||
|
||||
aeD3DFmt[uD3DFmtNum++]=eD3DFmtDefault;
|
||||
|
||||
UINT uAdapterModeNum=rkD3D.GetAdapterModeCount(iD3DAdapterInfo);
|
||||
for (UINT iD3DAdapterInfoMode=0; iD3DAdapterInfoMode<uAdapterModeNum; iD3DAdapterInfoMode++)
|
||||
{
|
||||
D3DDISPLAYMODE kD3DDMCur;
|
||||
rkD3D.EnumAdapterModes(iD3DAdapterInfo, iD3DAdapterInfoMode, &kD3DDMCur);
|
||||
|
||||
// IsFilterOutLowResolutionMode
|
||||
if( kD3DDMCur.Width < FILTEROUT_LOWRESOLUTION_WIDTH || kD3DDMCur.Height < FILTEROUT_LOWRESOLUTION_HEIGHT )
|
||||
continue;
|
||||
|
||||
// FindDisplayMode
|
||||
D3DDISPLAYMODE* pkD3DDMEnd=akD3DDM+uD3DDMNum;
|
||||
D3DDISPLAYMODE* pkD3DDMFind=std::find_if(akD3DDM, pkD3DDMEnd, FIsEqualD3DDisplayMode(&kD3DDMCur));
|
||||
|
||||
// IsNewDisplayMode
|
||||
if (pkD3DDMFind==pkD3DDMEnd && uD3DDMNum<D3DDISPLAYMODE_MAX)
|
||||
{
|
||||
D3DDISPLAYMODE& rkD3DDMNew=akD3DDM[uD3DDMNum++];
|
||||
rkD3DDMNew.Width=kD3DDMCur.Width;
|
||||
rkD3DDMNew.Height=kD3DDMCur.Height;
|
||||
rkD3DDMNew.Format=kD3DDMCur.Format;
|
||||
|
||||
// FindFormat
|
||||
D3DFORMAT* peD3DFmtEnd=aeD3DFmt+uD3DFmtNum;
|
||||
D3DFORMAT* peD3DFmtFind=std::find(aeD3DFmt, peD3DFmtEnd, kD3DDMCur.Format);
|
||||
|
||||
// IsNewFormat
|
||||
if (peD3DFmtFind==peD3DFmtEnd && uD3DFmtNum<D3DFORMAT_MAX)
|
||||
{
|
||||
aeD3DFmt[uD3DFmtNum++]=kD3DDMCur.Format;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qsort(akD3DDM, uD3DDMNum, sizeof(D3DDISPLAYMODE), CompareD3DDisplayModeOrder);
|
||||
|
||||
m_uD3DFmtNum=uD3DFmtNum;
|
||||
m_uD3DDMNum=uD3DDMNum;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
VOID D3D_SModeInfo::GetString(std::string* pstEnumList)
|
||||
{
|
||||
UINT uScrDepthBits=16;
|
||||
switch (m_eD3DFmtPixel)
|
||||
{
|
||||
case D3DFMT_X8R8G8B8:
|
||||
case D3DFMT_A8R8G8B8:
|
||||
case D3DFMT_R8G8B8:
|
||||
uScrDepthBits=32;
|
||||
break;
|
||||
}
|
||||
|
||||
int iVP=0;
|
||||
|
||||
switch (m_dwD3DBehavior)
|
||||
{
|
||||
case D3DCREATE_HARDWARE_VERTEXPROCESSING:
|
||||
iVP=1;
|
||||
break;
|
||||
case D3DCREATE_MIXED_VERTEXPROCESSING:
|
||||
iVP=2;
|
||||
break;
|
||||
case D3DCREATE_SOFTWARE_VERTEXPROCESSING:
|
||||
iVP=3;
|
||||
break;
|
||||
}
|
||||
|
||||
static const char* szVP[4]=
|
||||
{
|
||||
"UNKNOWN",
|
||||
"HWVP",
|
||||
"MXVP",
|
||||
"SWVP",
|
||||
};
|
||||
|
||||
char szText[1024+1];
|
||||
_snprintf(szText, sizeof(szText), "%dx%dx%d %s\r\n", m_uScrWidth, m_uScrHeight, uScrDepthBits, szVP[iVP]);
|
||||
pstEnumList->append(szText);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const CHAR* D3D_CDeviceInfo::msc_aszD3DDevDesc[D3DDEVICETYPE_NUM] = {"HAL", "REF"};
|
||||
const D3DDEVTYPE D3D_CDeviceInfo::msc_aeD3DDevType[D3DDEVICETYPE_NUM]={D3DDEVTYPE_HAL, D3DDEVTYPE_REF};
|
||||
|
||||
|
||||
UINT D3D_CDeviceInfo::GetD3DModeInfoNum()
|
||||
{
|
||||
return m_uD3DModeInfoNum;
|
||||
}
|
||||
|
||||
D3D_SModeInfo* D3D_CDeviceInfo::GetD3DModeInfop(UINT iD3D_SModeInfo)
|
||||
{
|
||||
if (iD3D_SModeInfo >= m_uD3DModeInfoNum)
|
||||
return NULL;
|
||||
|
||||
return &m_akD3DModeInfo[iD3D_SModeInfo];
|
||||
}
|
||||
|
||||
BOOL D3D_CDeviceInfo::FindDepthStencilFormat(IDirect3D8& rkD3D, UINT iD3DAdapterInfo, D3DDEVTYPE DeviceType, D3DFORMAT TargetFormat, D3DFORMAT* pDepthStencilFormat )
|
||||
{
|
||||
UINT m_dwMinDepthBits = 16;
|
||||
UINT m_dwMinStencilBits = 0;
|
||||
|
||||
if( m_dwMinDepthBits <= 16 && m_dwMinStencilBits == 0 )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16 ) ) )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, TargetFormat, D3DFMT_D16 ) ) )
|
||||
{
|
||||
*pDepthStencilFormat = D3DFMT_D16;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( m_dwMinDepthBits <= 15 && m_dwMinStencilBits <= 1 )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D15S1 ) ) )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, TargetFormat, D3DFMT_D15S1 ) ) )
|
||||
{
|
||||
*pDepthStencilFormat = D3DFMT_D15S1;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( m_dwMinDepthBits <= 24 && m_dwMinStencilBits == 0 )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8 ) ) )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, TargetFormat, D3DFMT_D24X8 ) ) )
|
||||
{
|
||||
*pDepthStencilFormat = D3DFMT_D24X8;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( m_dwMinDepthBits <= 24 && m_dwMinStencilBits <= 8 )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8 ) ) )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, TargetFormat, D3DFMT_D24S8 ) ) )
|
||||
{
|
||||
*pDepthStencilFormat = D3DFMT_D24S8;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( m_dwMinDepthBits <= 24 && m_dwMinStencilBits <= 4 )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X4S4 ) ) )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, TargetFormat, D3DFMT_D24X4S4 ) ) )
|
||||
{
|
||||
*pDepthStencilFormat = D3DFMT_D24X4S4;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( m_dwMinDepthBits <= 32 && m_dwMinStencilBits == 0 )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32 ) ) )
|
||||
{
|
||||
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
|
||||
TargetFormat, TargetFormat, D3DFMT_D32 ) ) )
|
||||
{
|
||||
*pDepthStencilFormat = D3DFMT_D32;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL D3D_CDeviceInfo::Build(IDirect3D8& rkD3D, UINT iD3DAdapterInfo, UINT iDevType, D3D_CAdapterDisplayModeList& rkD3DADMList, BOOL (*pfnConfirmDevice)(D3DCAPS8& rkD3DCaps, UINT uBehavior, D3DFORMAT eD3DFmt))
|
||||
{
|
||||
assert(pfnConfirmDevice!=NULL && "D3D_CDeviceInfo::Build");
|
||||
|
||||
const D3DDEVTYPE c_eD3DDevType=msc_aeD3DDevType[iDevType];
|
||||
const TCHAR* c_szD3DDevDesc=msc_aszD3DDevDesc[iDevType];
|
||||
|
||||
m_eD3DDevType = c_eD3DDevType;
|
||||
rkD3D.GetDeviceCaps(iD3DAdapterInfo, c_eD3DDevType, &m_kD3DCaps);
|
||||
|
||||
m_szDevDesc = c_szD3DDevDesc;
|
||||
m_uD3DModeInfoNum=0;
|
||||
m_canDoWindowed = FALSE;
|
||||
m_isWindowed = FALSE;
|
||||
m_eD3DMSTFullscreen = D3DMULTISAMPLE_NONE;
|
||||
m_eD3DMSTWindowed = D3DMULTISAMPLE_NONE;
|
||||
|
||||
BOOL aisFormatConfirmed[20];
|
||||
DWORD adwD3DBehavior[20];
|
||||
D3DFORMAT aeD3DFmtDepthStencil[20];
|
||||
|
||||
BOOL isHALExists = FALSE;
|
||||
BOOL isHALWindowedCompatible = FALSE;
|
||||
BOOL isHALDesktopCompatible = FALSE;
|
||||
BOOL isHALSampleCompatible = FALSE;
|
||||
|
||||
// GetFlagInfo
|
||||
{
|
||||
UINT uD3DFmtNum=rkD3DADMList.GetPixelFormatNum();
|
||||
|
||||
for (DWORD iFmt=0; iFmt<uD3DFmtNum; ++iFmt)
|
||||
{
|
||||
D3DFORMAT eD3DFmtPixel=rkD3DADMList.GetPixelFormatr(iFmt);
|
||||
DWORD dwD3DBehavior=0;
|
||||
BOOL isFormatConfirmed=FALSE;
|
||||
|
||||
aeD3DFmtDepthStencil[iFmt] = D3DFMT_UNKNOWN;
|
||||
|
||||
// SkipNoRenderTargetFormat;
|
||||
if (FAILED(rkD3D.CheckDeviceType(iD3DAdapterInfo, m_eD3DDevType, eD3DFmtPixel, eD3DFmtPixel, FALSE)))
|
||||
continue;
|
||||
|
||||
if (D3DDEVTYPE_HAL==m_eD3DDevType)
|
||||
{
|
||||
isHALExists=TRUE;
|
||||
|
||||
if (m_kD3DCaps.Caps2 & D3DCAPS2_CANRENDERWINDOWED)
|
||||
{
|
||||
isHALWindowedCompatible=TRUE;
|
||||
|
||||
if (iFmt==0)
|
||||
isHALDesktopCompatible=TRUE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Confirm the device/format for HW vertex processing
|
||||
if (m_kD3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
|
||||
{
|
||||
if (m_kD3DCaps.DevCaps & D3DDEVCAPS_PUREDEVICE)
|
||||
{
|
||||
dwD3DBehavior=D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_PUREDEVICE;
|
||||
|
||||
if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))
|
||||
isFormatConfirmed = TRUE;
|
||||
}
|
||||
|
||||
if (FALSE == isFormatConfirmed)
|
||||
{
|
||||
dwD3DBehavior = D3DCREATE_HARDWARE_VERTEXPROCESSING;
|
||||
|
||||
if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))
|
||||
isFormatConfirmed = TRUE;
|
||||
}
|
||||
|
||||
if (FALSE == isFormatConfirmed)
|
||||
{
|
||||
dwD3DBehavior = D3DCREATE_MIXED_VERTEXPROCESSING;
|
||||
|
||||
if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))
|
||||
isFormatConfirmed = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Confirm the device/format for SW vertex processing
|
||||
if (FALSE == isFormatConfirmed)
|
||||
{
|
||||
dwD3DBehavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
|
||||
|
||||
if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))
|
||||
isFormatConfirmed = TRUE;
|
||||
}
|
||||
|
||||
if (isFormatConfirmed)
|
||||
{
|
||||
if (!FindDepthStencilFormat(rkD3D, iD3DAdapterInfo, c_eD3DDevType, eD3DFmtPixel, &aeD3DFmtDepthStencil[iFmt]))
|
||||
isFormatConfirmed = TRUE;
|
||||
|
||||
}
|
||||
|
||||
adwD3DBehavior[iFmt]=dwD3DBehavior;
|
||||
aisFormatConfirmed[iFmt]=isFormatConfirmed;
|
||||
}
|
||||
}
|
||||
|
||||
// BuildModeInfoList
|
||||
{
|
||||
UINT uD3DDMNum=rkD3DADMList.GetDisplayModeNum();
|
||||
UINT uD3DFmtNum=rkD3DADMList.GetPixelFormatNum();
|
||||
|
||||
|
||||
for (UINT iD3DDM=0; iD3DDM<uD3DDMNum; ++iD3DDM)
|
||||
{
|
||||
const D3DDISPLAYMODE& c_rkD3DDM=rkD3DADMList.GetDisplayModer(iD3DDM);
|
||||
for (DWORD iFmt=0; iFmt<uD3DFmtNum; ++iFmt)
|
||||
{
|
||||
if (rkD3DADMList.GetPixelFormatr(iFmt)==c_rkD3DDM.Format)
|
||||
{
|
||||
if (aisFormatConfirmed[iFmt] == TRUE )
|
||||
{
|
||||
D3D_SModeInfo& rkModeInfo=m_akD3DModeInfo[m_uD3DModeInfoNum++];
|
||||
rkModeInfo.m_uScrWidth=c_rkD3DDM.Width;
|
||||
rkModeInfo.m_uScrHeight=c_rkD3DDM.Height;
|
||||
rkModeInfo.m_eD3DFmtPixel=c_rkD3DDM.Format;
|
||||
rkModeInfo.m_dwD3DBehavior=adwD3DBehavior[iFmt];
|
||||
rkModeInfo.m_eD3DFmtDepthStencil=aeD3DFmtDepthStencil[iFmt];
|
||||
|
||||
if( m_eD3DDevType == D3DDEVTYPE_HAL )
|
||||
isHALSampleCompatible = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the device is compatible with the desktop display mode
|
||||
// (which was added initially as formats[0])
|
||||
if (aisFormatConfirmed[0] && (m_kD3DCaps.Caps2 & D3DCAPS2_CANRENDERWINDOWED) )
|
||||
{
|
||||
m_canDoWindowed=TRUE;
|
||||
m_isWindowed=TRUE;
|
||||
}
|
||||
|
||||
if (m_uD3DModeInfoNum>0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL D3D_CDeviceInfo::Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo)
|
||||
{
|
||||
if (isWindowed)
|
||||
if (!m_isWindowed)
|
||||
return FALSE;
|
||||
|
||||
for (UINT iD3D_SModeInfo=0; iD3D_SModeInfo<m_uD3DModeInfoNum; ++iD3D_SModeInfo)
|
||||
{
|
||||
D3D_SModeInfo& rkModeInfo=m_akD3DModeInfo[iD3D_SModeInfo];
|
||||
if (rkModeInfo.m_uScrWidth==uScrWidth && rkModeInfo.m_uScrHeight==uScrHeight)
|
||||
{
|
||||
if (uScrDepthBits==16)
|
||||
{
|
||||
switch (rkModeInfo.m_eD3DFmtPixel)
|
||||
{
|
||||
case D3DFMT_R5G6B5:
|
||||
case D3DFMT_X1R5G5B5:
|
||||
case D3DFMT_A1R5G5B5:
|
||||
*piD3DModeInfo=iD3D_SModeInfo;
|
||||
return TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (rkModeInfo.m_eD3DFmtPixel)
|
||||
{
|
||||
case D3DFMT_X8R8G8B8:
|
||||
case D3DFMT_A8R8G8B8:
|
||||
case D3DFMT_R8G8B8:
|
||||
*piD3DModeInfo=iD3D_SModeInfo;
|
||||
return TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
VOID D3D_CDeviceInfo::GetString(std::string* pstEnumList)
|
||||
{
|
||||
char szText[1024+1];
|
||||
_snprintf(szText, sizeof(szText), "%s\r\n========================================\r\n", m_szDevDesc);
|
||||
pstEnumList->append(szText);
|
||||
|
||||
for (UINT iD3D_SModeInfo=0; iD3D_SModeInfo<m_uD3DModeInfoNum; ++iD3D_SModeInfo)
|
||||
{
|
||||
_snprintf(szText, sizeof(szText), "%d. ", iD3D_SModeInfo);
|
||||
pstEnumList->append(szText);
|
||||
|
||||
D3D_SModeInfo& rkModeInfo=m_akD3DModeInfo[iD3D_SModeInfo];
|
||||
rkModeInfo.GetString(pstEnumList);
|
||||
}
|
||||
|
||||
pstEnumList->append("\r\n");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
D3DDISPLAYMODE& D3D_CAdapterInfo::GetDesktopD3DDisplayModer()
|
||||
{
|
||||
return m_kD3DDMDesktop;
|
||||
}
|
||||
|
||||
D3DDISPLAYMODE* D3D_CAdapterInfo::GetDesktopD3DDisplayModep()
|
||||
{
|
||||
return &m_kD3DDMDesktop;
|
||||
}
|
||||
|
||||
D3D_CDeviceInfo* D3D_CAdapterInfo::GetD3DDeviceInfop(UINT iD3DDevInfo)
|
||||
{
|
||||
if (iD3DDevInfo >= m_uD3DDevInfoNum)
|
||||
return NULL;
|
||||
|
||||
return &m_akD3DDevInfo[iD3DDevInfo];
|
||||
}
|
||||
|
||||
D3D_SModeInfo* D3D_CAdapterInfo::GetD3DModeInfop(UINT iD3DDevInfo, UINT iD3D_SModeInfo)
|
||||
{
|
||||
D3D_CDeviceInfo* pkD3DDevInfo=GetD3DDeviceInfop(iD3DDevInfo);
|
||||
if (pkD3DDevInfo)
|
||||
{
|
||||
D3D_SModeInfo* pkD3DModeInfo=pkD3DDevInfo->GetD3DModeInfop(iD3D_SModeInfo);
|
||||
if (pkD3DModeInfo)
|
||||
return pkD3DModeInfo;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BOOL D3D_CAdapterInfo::Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo)
|
||||
{
|
||||
for (UINT iDevInfo=0; iDevInfo<m_uD3DDevInfoNum; ++iDevInfo)
|
||||
{
|
||||
D3D_CDeviceInfo& rkD3DDevInfo=m_akD3DDevInfo[iDevInfo];
|
||||
if (rkD3DDevInfo.Find(uScrWidth, uScrHeight, uScrDepthBits, isWindowed, piD3DModeInfo))
|
||||
{
|
||||
*piD3DDevInfo=iDevInfo;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL D3D_CAdapterInfo::Build(IDirect3D8& rkD3D, UINT iD3DAdapterInfo, PFNCONFIRMDEVICE pfnConfirmDevice)
|
||||
{
|
||||
D3DDISPLAYMODE& rkD3DDMDesktop=m_kD3DDMDesktop;
|
||||
if (FAILED(rkD3D.GetAdapterDisplayMode(iD3DAdapterInfo, &rkD3DDMDesktop)))
|
||||
return FALSE;
|
||||
|
||||
rkD3D.GetAdapterIdentifier(iD3DAdapterInfo, D3DENUM_NO_WHQL_LEVEL, &m_kD3DAdapterIdentifier);
|
||||
|
||||
m_iCurD3DDevInfo=0;
|
||||
m_uD3DDevInfoNum=0;
|
||||
|
||||
D3D_CAdapterDisplayModeList kD3DADMList;
|
||||
kD3DADMList.Build(rkD3D, m_kD3DDMDesktop.Format, iD3DAdapterInfo);
|
||||
|
||||
D3D_CDeviceInfo* akD3DDevInfo=m_akD3DDevInfo;
|
||||
for (UINT iDevType=0; iDevType<D3DDEVICETYPE_NUM; ++iDevType)
|
||||
{
|
||||
D3D_CDeviceInfo& rkD3DDevInfo=akD3DDevInfo[m_uD3DDevInfoNum];
|
||||
if (rkD3DDevInfo.Build(rkD3D, iD3DAdapterInfo, iDevType, kD3DADMList, pfnConfirmDevice))
|
||||
++m_uD3DDevInfoNum;
|
||||
}
|
||||
|
||||
if (m_uD3DDevInfoNum>0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
VOID D3D_CAdapterInfo::GetString(std::string* pstEnumList)
|
||||
{
|
||||
for (UINT iDevInfo=0; iDevInfo<m_uD3DDevInfoNum; ++iDevInfo)
|
||||
{
|
||||
char szText[1024+1];
|
||||
_snprintf(szText, sizeof(szText), "Device %d\r\n", iDevInfo);
|
||||
pstEnumList->append(szText);
|
||||
|
||||
D3D_CDeviceInfo& rkD3DDevInfo=m_akD3DDevInfo[iDevInfo];
|
||||
rkD3DDevInfo.GetString(pstEnumList);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
D3D_CDisplayModeAutoDetector::D3D_CDisplayModeAutoDetector()
|
||||
{
|
||||
m_uD3DAdapterInfoCount=0;
|
||||
}
|
||||
|
||||
D3D_CDisplayModeAutoDetector::~D3D_CDisplayModeAutoDetector()
|
||||
{
|
||||
}
|
||||
|
||||
D3D_CAdapterInfo* D3D_CDisplayModeAutoDetector::GetD3DAdapterInfop(UINT iD3DAdapterInfo)
|
||||
{
|
||||
if (iD3DAdapterInfo >= m_uD3DAdapterInfoCount)
|
||||
return NULL;
|
||||
|
||||
return &m_akD3DAdapterInfo[iD3DAdapterInfo];
|
||||
}
|
||||
|
||||
D3D_SModeInfo* D3D_CDisplayModeAutoDetector::GetD3DModeInfop(UINT iD3DAdapterInfo, UINT iD3DDevInfo, UINT iD3D_SModeInfo)
|
||||
{
|
||||
D3D_CAdapterInfo* pkD3DAdapterInfo=GetD3DAdapterInfop(iD3DAdapterInfo);
|
||||
if (pkD3DAdapterInfo)
|
||||
{
|
||||
D3D_CDeviceInfo* pkD3DDevInfo=pkD3DAdapterInfo->GetD3DDeviceInfop(iD3DDevInfo);
|
||||
if (pkD3DDevInfo)
|
||||
{
|
||||
D3D_SModeInfo* pkD3D_SModeInfo=pkD3DDevInfo->GetD3DModeInfop(iD3D_SModeInfo);
|
||||
if (pkD3D_SModeInfo)
|
||||
return pkD3D_SModeInfo;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BOOL D3D_CDisplayModeAutoDetector::Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo, UINT* piD3DAdapterInfo)
|
||||
{
|
||||
for (UINT iD3DAdapterInfo=0; iD3DAdapterInfo<m_uD3DAdapterInfoCount; ++iD3DAdapterInfo)
|
||||
{
|
||||
D3D_CAdapterInfo& rkAdapterInfo=m_akD3DAdapterInfo[iD3DAdapterInfo];
|
||||
if (rkAdapterInfo.Find(uScrWidth, uScrHeight, uScrDepthBits, isWindowed, piD3DModeInfo, piD3DDevInfo))
|
||||
{
|
||||
*piD3DAdapterInfo=iD3DAdapterInfo;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL D3D_CDisplayModeAutoDetector::Build(IDirect3D8& rkD3D, PFNCONFIRMDEVICE pfnConfirmDevice)
|
||||
{
|
||||
m_uD3DAdapterInfoCount=0;
|
||||
|
||||
UINT uTotalAdapterCount=rkD3D.GetAdapterCount();
|
||||
uTotalAdapterCount=std::min(uTotalAdapterCount, (UINT)D3DADAPTERINFO_NUM);
|
||||
|
||||
for (UINT iD3DAdapterInfo=0; iD3DAdapterInfo<uTotalAdapterCount; ++iD3DAdapterInfo)
|
||||
{
|
||||
D3D_CAdapterInfo& rkAdapterInfo=m_akD3DAdapterInfo[m_uD3DAdapterInfoCount];
|
||||
if (rkAdapterInfo.Build(rkD3D, iD3DAdapterInfo, pfnConfirmDevice))
|
||||
++m_uD3DAdapterInfoCount;
|
||||
}
|
||||
|
||||
if (m_uD3DAdapterInfoCount>0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
VOID D3D_CDisplayModeAutoDetector::GetString(std::string* pstEnumList)
|
||||
{
|
||||
for (UINT iD3DAdapterInfo=0; iD3DAdapterInfo<m_uD3DAdapterInfoCount; ++iD3DAdapterInfo)
|
||||
{
|
||||
char szText[1024+1];
|
||||
_snprintf(szText, sizeof(szText), "Adapter %d\r\n", iD3DAdapterInfo);
|
||||
pstEnumList->append(szText);
|
||||
|
||||
D3D_CAdapterInfo& rkAdapterInfo=m_akD3DAdapterInfo[iD3DAdapterInfo];
|
||||
rkAdapterInfo.GetString(pstEnumList);
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d8.h>
|
||||
#include <string>
|
||||
typedef BOOL (*PFNCONFIRMDEVICE) (D3DCAPS8& rkD3DCaps, UINT uBehavior, D3DFORMAT eD3DFmt);
|
||||
|
||||
enum
|
||||
{
|
||||
D3DDEVICETYPE_HAL,
|
||||
D3DDEVICETYPE_REF,
|
||||
D3DDEVICETYPE_NUM,
|
||||
};
|
||||
|
||||
struct D3D_SModeInfo
|
||||
{
|
||||
UINT m_uScrWidth;
|
||||
UINT m_uScrHeight;
|
||||
UINT m_uScrDepthBit;
|
||||
UINT m_dwD3DBehavior;
|
||||
D3DFORMAT m_eD3DFmtPixel;
|
||||
D3DFORMAT m_eD3DFmtDepthStencil;
|
||||
|
||||
VOID GetString(std::string* pstEnumList);
|
||||
};
|
||||
|
||||
class D3D_CAdapterDisplayModeList
|
||||
{
|
||||
public:
|
||||
D3D_CAdapterDisplayModeList() {}
|
||||
~D3D_CAdapterDisplayModeList() {}
|
||||
VOID Build(IDirect3D8& rkD3D, D3DFORMAT eD3DFmtDefault, UINT iAdapter);
|
||||
|
||||
UINT GetDisplayModeNum();
|
||||
UINT GetPixelFormatNum();
|
||||
|
||||
const D3DDISPLAYMODE& GetDisplayModer(UINT iD3DDM);
|
||||
const D3DFORMAT& GetPixelFormatr(UINT iD3DFmt);
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
D3DDISPLAYMODE_MAX = 100,
|
||||
D3DFORMAT_MAX = 20,
|
||||
|
||||
FILTEROUT_LOWRESOLUTION_WIDTH = 640,
|
||||
FILTEROUT_LOWRESOLUTION_HEIGHT = 480,
|
||||
};
|
||||
|
||||
protected:
|
||||
D3DDISPLAYMODE m_akD3DDM[D3DDISPLAYMODE_MAX];
|
||||
D3DFORMAT m_aeD3DFmt[D3DFORMAT_MAX];
|
||||
|
||||
UINT m_uD3DDMNum;
|
||||
UINT m_uD3DFmtNum;
|
||||
|
||||
};
|
||||
|
||||
class D3D_CDeviceInfo
|
||||
{
|
||||
public:
|
||||
D3D_CDeviceInfo() {}
|
||||
~D3D_CDeviceInfo() {}
|
||||
BOOL Build(IDirect3D8& rkD3D, UINT iAdapter, UINT iDevType, D3D_CAdapterDisplayModeList& rkD3DADMList, PFNCONFIRMDEVICE pfnConfirmDevice);
|
||||
BOOL Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo);
|
||||
|
||||
UINT GetD3DModeInfoNum();
|
||||
|
||||
VOID GetString(std::string* pstEnumList);
|
||||
|
||||
BOOL FindDepthStencilFormat(IDirect3D8& rkD3D, UINT iAdapter, D3DDEVTYPE DeviceType, D3DFORMAT TargetFormat, D3DFORMAT* pDepthStencilFormat);
|
||||
|
||||
D3D_SModeInfo& GetD3DModeInfor(UINT iD3DModeInfo);
|
||||
D3D_SModeInfo* GetD3DModeInfop(UINT iD3DModeInfo);
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
D3DMODEINFO_NUM = 150,
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
const TCHAR* m_szDevDesc;
|
||||
|
||||
D3DDEVTYPE m_eD3DDevType;
|
||||
D3DCAPS8 m_kD3DCaps;
|
||||
BOOL m_canDoWindowed;
|
||||
|
||||
UINT m_iCurD3DModeInfo;
|
||||
UINT m_uD3DModeInfoNum;
|
||||
D3D_SModeInfo m_akD3DModeInfo[D3DMODEINFO_NUM];
|
||||
|
||||
|
||||
BOOL m_isWindowed;
|
||||
|
||||
D3DMULTISAMPLE_TYPE m_eD3DMSTWindowed;
|
||||
D3DMULTISAMPLE_TYPE m_eD3DMSTFullscreen;
|
||||
|
||||
|
||||
protected:
|
||||
static const CHAR* msc_aszD3DDevDesc[D3DDEVICETYPE_NUM];
|
||||
static const D3DDEVTYPE msc_aeD3DDevType[D3DDEVICETYPE_NUM];
|
||||
};
|
||||
|
||||
class D3D_CAdapterInfo
|
||||
{
|
||||
public:
|
||||
D3D_CAdapterInfo() {}
|
||||
~D3D_CAdapterInfo() {}
|
||||
BOOL Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo);
|
||||
|
||||
BOOL Build(IDirect3D8& rkD3D, UINT iAdapter, PFNCONFIRMDEVICE pfnConfirmDevice);
|
||||
VOID GetString(std::string* pstEnumList);
|
||||
|
||||
D3DADAPTER_IDENTIFIER8& GetIdentifier()
|
||||
{
|
||||
return m_kD3DAdapterIdentifier;
|
||||
}
|
||||
|
||||
D3DDISPLAYMODE& GetDesktopD3DDisplayModer();
|
||||
D3DDISPLAYMODE* GetDesktopD3DDisplayModep();
|
||||
|
||||
D3D_CDeviceInfo* GetD3DDeviceInfop(UINT iD3DDevInfo);
|
||||
D3D_SModeInfo* GetD3DModeInfop(UINT iD3DDevInfo, UINT iD3DModeInfo);
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
D3DDEVICEINFO_NUM = 5,
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
D3DADAPTER_IDENTIFIER8 m_kD3DAdapterIdentifier;
|
||||
D3DDISPLAYMODE m_kD3DDMDesktop;
|
||||
|
||||
UINT m_iCurD3DDevInfo;
|
||||
UINT m_uD3DDevInfoNum;
|
||||
D3D_CDeviceInfo m_akD3DDevInfo[D3DDEVICEINFO_NUM];
|
||||
|
||||
};
|
||||
|
||||
class D3D_CDisplayModeAutoDetector
|
||||
{
|
||||
public:
|
||||
D3D_CDisplayModeAutoDetector();
|
||||
~D3D_CDisplayModeAutoDetector();
|
||||
|
||||
BOOL Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo, UINT* piD3DAdapterInfo);
|
||||
BOOL Build(IDirect3D8& rkD3D, PFNCONFIRMDEVICE pfnConfirmDevice);
|
||||
|
||||
D3D_CAdapterInfo* GetD3DAdapterInfop(UINT iD3DAdapterInfo);
|
||||
D3D_SModeInfo* GetD3DModeInfop(UINT iD3DAdapterInfo, UINT iD3DDevInfo, UINT iD3DModeInfo);
|
||||
|
||||
VOID GetString(std::string* pstEnumList);
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
D3DADAPTERINFO_NUM = 10,
|
||||
};
|
||||
|
||||
protected:
|
||||
D3D_CAdapterInfo m_akD3DAdapterInfo[D3DADAPTERINFO_NUM];
|
||||
UINT m_uD3DAdapterInfoCount;
|
||||
};
|
||||
@@ -26,10 +26,6 @@ CGraphicDevice::~CGraphicDevice()
|
||||
|
||||
void CGraphicDevice::__Initialize()
|
||||
{
|
||||
ms_iD3DAdapterInfo=D3DADAPTER_DEFAULT;
|
||||
ms_iD3DDevInfo=D3DADAPTER_DEFAULT;
|
||||
ms_iD3DModeInfo=D3DADAPTER_DEFAULT;
|
||||
|
||||
ms_lpd3d = NULL;
|
||||
ms_lpd3dDevice = NULL;
|
||||
ms_lpd3dMatStack = NULL;
|
||||
@@ -78,9 +74,9 @@ void CGraphicDevice::EnableWebBrowserMode(const RECT& c_rcWebPage)
|
||||
//rkD3DPP.Windowed=TRUE;
|
||||
rkD3DPP.SwapEffect=D3DSWAPEFFECT_COPY;
|
||||
rkD3DPP.BackBufferCount = 1;
|
||||
rkD3DPP.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
rkD3DPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
|
||||
IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice;
|
||||
IDirect3DDevice9& rkD3DDev=*ms_lpd3dDevice;
|
||||
HRESULT hr=rkD3DDev.Reset(&rkD3DPP);
|
||||
if (FAILED(hr))
|
||||
return;
|
||||
@@ -99,7 +95,7 @@ void CGraphicDevice::DisableWebBrowserMode()
|
||||
|
||||
rkD3DPP=g_kD3DPP;
|
||||
|
||||
IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice;
|
||||
IDirect3DDevice9& rkD3DDev=*ms_lpd3dDevice;
|
||||
HRESULT hr=rkD3DDev.Reset(&rkD3DPP);
|
||||
if (FAILED(hr))
|
||||
return;
|
||||
@@ -120,7 +116,7 @@ bool CGraphicDevice::ResizeBackBuffer(UINT uWidth, UINT uHeight)
|
||||
rkD3DPP.BackBufferWidth=uWidth;
|
||||
rkD3DPP.BackBufferHeight=uHeight;
|
||||
|
||||
IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice;
|
||||
IDirect3DDevice9& rkD3DDev=*ms_lpd3dDevice;
|
||||
|
||||
HRESULT hr=rkD3DDev.Reset(&rkD3DPP);
|
||||
if (FAILED(hr))
|
||||
@@ -135,94 +131,100 @@ bool CGraphicDevice::ResizeBackBuffer(UINT uWidth, UINT uHeight)
|
||||
return true;
|
||||
}
|
||||
|
||||
DWORD CGraphicDevice::CreatePNTStreamVertexShader()
|
||||
LPDIRECT3DVERTEXDECLARATION9 CGraphicDevice::CreatePNTStreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
|
||||
DWORD declVector[] =
|
||||
{
|
||||
D3DVSD_STREAM(0),
|
||||
D3DVSD_REG(0, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(3, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(7, D3DVSDT_FLOAT2),
|
||||
D3DVSD_END()
|
||||
|
||||
LPDIRECT3DVERTEXDECLARATION9 dwShader = NULL;
|
||||
|
||||
D3DVERTEXELEMENT9 pShaderDecl[] = {
|
||||
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
|
||||
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
|
||||
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
DWORD ret;
|
||||
|
||||
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
|
||||
return 0;
|
||||
|
||||
return ret;
|
||||
|
||||
if (ms_lpd3dDevice->CreateVertexDeclaration(pShaderDecl, &dwShader) != D3D_OK)
|
||||
{
|
||||
char szError[1024];
|
||||
sprintf(szError, "Failed to create CreatePNTBTStreamVertexShader");
|
||||
MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP);
|
||||
}
|
||||
|
||||
return dwShader;
|
||||
}
|
||||
|
||||
DWORD CGraphicDevice::CreatePNT2StreamVertexShader()
|
||||
LPDIRECT3DVERTEXDECLARATION9 CGraphicDevice::CreatePNT2StreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
|
||||
DWORD declVector[] =
|
||||
{
|
||||
D3DVSD_STREAM(0),
|
||||
D3DVSD_REG(0, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(3, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(7, D3DVSDT_FLOAT2),
|
||||
D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2),
|
||||
// D3DVSD_STREAM(1),
|
||||
D3DVSD_END()
|
||||
LPDIRECT3DVERTEXDECLARATION9 dwShader = NULL;
|
||||
|
||||
D3DVERTEXELEMENT9 pShaderDecl[] = {
|
||||
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
|
||||
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
|
||||
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
|
||||
{ 0, 32, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
DWORD ret;
|
||||
if (ms_lpd3dDevice->CreateVertexDeclaration(pShaderDecl, &dwShader) != D3D_OK)
|
||||
{
|
||||
char szError[1024];
|
||||
sprintf(szError, "Failed to create CreatePNTBT2StreamVertexShader");
|
||||
MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP);
|
||||
}
|
||||
|
||||
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
|
||||
return 0;
|
||||
|
||||
return ret;
|
||||
return dwShader;
|
||||
}
|
||||
|
||||
DWORD CGraphicDevice::CreatePTStreamVertexShader()
|
||||
LPDIRECT3DVERTEXDECLARATION9 CGraphicDevice::CreatePTStreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
|
||||
DWORD declVector[] =
|
||||
{
|
||||
D3DVSD_STREAM(0),
|
||||
D3DVSD_REG(0, D3DVSDT_FLOAT3),
|
||||
D3DVSD_STREAM(1),
|
||||
D3DVSD_REG(7, D3DVSDT_FLOAT2),
|
||||
D3DVSD_END()
|
||||
LPDIRECT3DVERTEXDECLARATION9 dwShader = NULL;
|
||||
|
||||
D3DVERTEXELEMENT9 pShaderDecl[] = {
|
||||
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
|
||||
{ 1, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
DWORD ret;
|
||||
if (ms_lpd3dDevice->CreateVertexDeclaration(pShaderDecl, &dwShader) != D3D_OK)
|
||||
{
|
||||
char szError[1024];
|
||||
sprintf(szError, "Failed to create CreatePTStreamVertexShader");
|
||||
MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP);
|
||||
}
|
||||
|
||||
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
|
||||
return 0;
|
||||
|
||||
return (ret);
|
||||
return dwShader;
|
||||
}
|
||||
|
||||
DWORD CGraphicDevice::CreateDoublePNTStreamVertexShader()
|
||||
LPDIRECT3DVERTEXDECLARATION9 CGraphicDevice::CreateDoublePNTStreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
|
||||
DWORD declVector[] =
|
||||
{
|
||||
D3DVSD_STREAM(0),
|
||||
D3DVSD_REG(0, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(3, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(7, D3DVSDT_FLOAT2),
|
||||
D3DVSD_STREAM(1),
|
||||
D3DVSD_REG(D3DVSDE_POSITION2, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(D3DVSDE_NORMAL2, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2),
|
||||
D3DVSD_END()
|
||||
LPDIRECT3DVERTEXDECLARATION9 dwShader = NULL;
|
||||
|
||||
D3DVERTEXELEMENT9 pShaderDecl[] = {
|
||||
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
|
||||
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
|
||||
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
|
||||
|
||||
{ 1, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 1 },
|
||||
{ 1, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 1 },
|
||||
{ 1, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
|
||||
D3DDECL_END()
|
||||
};
|
||||
|
||||
DWORD ret;
|
||||
if (ms_lpd3dDevice->CreateVertexDeclaration(pShaderDecl, &dwShader) != D3D_OK)
|
||||
{
|
||||
char szError[1024];
|
||||
sprintf(szError, "Failed to create CreateDoublePNTBTStreamVertexShader");
|
||||
MessageBox(NULL, szError, "Vertex Shader Error", MB_ICONSTOP);
|
||||
}
|
||||
|
||||
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
|
||||
return 0;
|
||||
|
||||
return ret;
|
||||
return dwShader;
|
||||
}
|
||||
|
||||
CGraphicDevice::EDeviceState CGraphicDevice::GetDeviceState()
|
||||
@@ -256,42 +258,33 @@ bool CGraphicDevice::Reset()
|
||||
return true;
|
||||
}
|
||||
|
||||
static LPDIRECT3DSURFACE8 s_lpStencil;
|
||||
static LPDIRECT3DSURFACE9 s_lpStencil;
|
||||
static DWORD s_MaxTextureWidth, s_MaxTextureHeight;
|
||||
|
||||
BOOL EL3D_ConfirmDevice(D3DCAPS8& rkD3DCaps, UINT uBehavior, D3DFORMAT /*eD3DFmt*/)
|
||||
BOOL EL3D_ConfirmDevice(D3DCAPS9& rkD3DCaps, UINT uBehavior)
|
||||
{
|
||||
// PUREDEVICE는 GetTransform / GetViewport 등이 되지 않는다.
|
||||
if (uBehavior & D3DCREATE_PUREDEVICE)
|
||||
return FALSE;
|
||||
|
||||
if (uBehavior & D3DCREATE_HARDWARE_VERTEXPROCESSING)
|
||||
{
|
||||
// PUREDEVICE´Â GetTransform / GetViewport µîÀÌ µÇÁö ¾Ê´Â´Ù.
|
||||
if (uBehavior & D3DCREATE_PUREDEVICE)
|
||||
return FALSE;
|
||||
|
||||
if (uBehavior & D3DCREATE_HARDWARE_VERTEXPROCESSING)
|
||||
{
|
||||
// DirectionalLight
|
||||
if (!(rkD3DCaps.VertexProcessingCaps & D3DVTXPCAPS_DIRECTIONALLIGHTS))
|
||||
return FALSE;
|
||||
|
||||
|
||||
// PositionalLight
|
||||
if (!(rkD3DCaps.VertexProcessingCaps & D3DVTXPCAPS_POSITIONALLIGHTS))
|
||||
return FALSE;
|
||||
|
||||
// Software T&L Support - ATI NOT SUPPORT CLIP, USE DIRECTX SOFTWARE PROCESSING CLIPPING
|
||||
if (GRAPHICS_CAPS_SOFTWARE_TILING)
|
||||
{
|
||||
if (!(rkD3DCaps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Shadow/Terrain
|
||||
if (!(rkD3DCaps.VertexProcessingCaps & D3DVTXPCAPS_TEXGEN))
|
||||
return FALSE;
|
||||
}
|
||||
// Shadow/Terrain
|
||||
if (!(rkD3DCaps.VertexProcessingCaps & D3DVTXPCAPS_TEXGEN))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
s_MaxTextureWidth = rkD3DCaps.MaxTextureWidth;
|
||||
s_MaxTextureHeight = rkD3DCaps.MaxTextureHeight;
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -305,46 +298,6 @@ DWORD GetMaxTextureHeight()
|
||||
return s_MaxTextureHeight;
|
||||
}
|
||||
|
||||
bool CGraphicDevice::__IsInDriverBlackList(D3D_CAdapterInfo& rkD3DAdapterInfo)
|
||||
{
|
||||
D3DADAPTER_IDENTIFIER8& rkD3DAdapterIdentifier=rkD3DAdapterInfo.GetIdentifier();
|
||||
|
||||
char szSrcDriver[256];
|
||||
strncpy(szSrcDriver, rkD3DAdapterIdentifier.Driver, sizeof(szSrcDriver)-1);
|
||||
DWORD dwSrcHighVersion=rkD3DAdapterIdentifier.DriverVersion.QuadPart>>32;
|
||||
DWORD dwSrcLowVersion=rkD3DAdapterIdentifier.DriverVersion.QuadPart&0xffffffff;
|
||||
|
||||
bool ret=false;
|
||||
|
||||
FILE* fp=fopen("grpblk.txt", "r");
|
||||
if (fp)
|
||||
{
|
||||
DWORD dwChkHighVersion;
|
||||
DWORD dwChkLowVersion;
|
||||
|
||||
char szChkDriver[256];
|
||||
|
||||
char szLine[256];
|
||||
while (fgets(szLine, sizeof(szLine)-1, fp))
|
||||
{
|
||||
sscanf(szLine, "%s %x %x", szChkDriver, &dwChkHighVersion, &dwChkLowVersion);
|
||||
|
||||
if (strcmp(szSrcDriver, szChkDriver)==0)
|
||||
if (dwSrcHighVersion==dwChkHighVersion)
|
||||
if (dwSrcLowVersion==dwChkLowVersion)
|
||||
{
|
||||
ret=true;
|
||||
break;
|
||||
}
|
||||
|
||||
szLine[0]='\0';
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /*iBit*/, int iReflashRate)
|
||||
{
|
||||
int iRet = CREATE_OK;
|
||||
@@ -356,64 +309,55 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /
|
||||
|
||||
ms_hWnd = hWnd;
|
||||
ms_hDC = GetDC(hWnd);
|
||||
ms_lpd3d = Direct3DCreate8(D3D_SDK_VERSION);
|
||||
ms_lpd3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
|
||||
if (!ms_lpd3d)
|
||||
return CREATE_NO_DIRECTX;
|
||||
|
||||
if (!ms_kD3DDetector.Build(*ms_lpd3d, EL3D_ConfirmDevice))
|
||||
return CREATE_ENUM;
|
||||
D3DADAPTER_IDENTIFIER9 d3dAdapterId;
|
||||
ms_lpd3d->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &d3dAdapterId);
|
||||
|
||||
if (!ms_kD3DDetector.Find(800, 600, 32, TRUE, &ms_iD3DModeInfo, &ms_iD3DDevInfo, &ms_iD3DAdapterInfo))
|
||||
return CREATE_DETECT;
|
||||
D3DDISPLAYMODE d3dDisplayMode;
|
||||
ms_lpd3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3dDisplayMode);
|
||||
|
||||
std::string stDevList;
|
||||
ms_kD3DDetector.GetString(&stDevList);
|
||||
|
||||
//Tracen(stDevList.c_str());
|
||||
//Tracenf("adapter %d, device %d, mode %d", ms_iD3DAdapterInfo, ms_iD3DDevInfo, ms_iD3DModeInfo);
|
||||
|
||||
D3D_CAdapterInfo * pkD3DAdapterInfo = ms_kD3DDetector.GetD3DAdapterInfop(ms_iD3DAdapterInfo);
|
||||
if (!pkD3DAdapterInfo)
|
||||
{
|
||||
Tracenf("adapter %d is EMPTY", ms_iD3DAdapterInfo);
|
||||
return CREATE_DETECT;
|
||||
}
|
||||
|
||||
if (__IsInDriverBlackList(*pkD3DAdapterInfo))
|
||||
{
|
||||
iRet |= CREATE_BAD_DRIVER;
|
||||
__WarningMessage(hWnd, CREATE_BAD_DRIVER);
|
||||
}
|
||||
|
||||
D3D_SModeInfo * pkD3DModeInfo = pkD3DAdapterInfo->GetD3DModeInfop(ms_iD3DDevInfo, ms_iD3DModeInfo);
|
||||
if (!pkD3DModeInfo)
|
||||
{
|
||||
Tracenf("device %d, mode %d is EMPTY", ms_iD3DDevInfo, ms_iD3DModeInfo);
|
||||
return CREATE_DETECT;
|
||||
}
|
||||
|
||||
D3DADAPTER_IDENTIFIER8& rkD3DAdapterId=pkD3DAdapterInfo->GetIdentifier();
|
||||
if (Windowed &&
|
||||
strnicmp(rkD3DAdapterId.Driver, "3dfx", 4)==0 &&
|
||||
22 == pkD3DAdapterInfo->GetDesktopD3DDisplayModer().Format)
|
||||
strnicmp(d3dAdapterId.Driver, "3dfx", 4) == 0 &&
|
||||
D3DFMT_X8R8G8B8 == d3dDisplayMode.Format)
|
||||
{
|
||||
return CREATE_FORMAT;
|
||||
}
|
||||
|
||||
if (pkD3DModeInfo->m_dwD3DBehavior==D3DCREATE_SOFTWARE_VERTEXPROCESSING)
|
||||
{
|
||||
iRet |= CREATE_NO_TNL;
|
||||
D3DCAPS9 d3dCaps;
|
||||
ms_lpd3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps);
|
||||
|
||||
// DISABLE_NOTIFY_NOT_SUPPORT_TNL_MESSAGE
|
||||
//__WarningMessage(hWnd, CREATE_NO_TNL);
|
||||
// END_OF_DISABLE_NOTIFY_NOT_SUPPORT_TNL_MESSAGE
|
||||
BOOL isFormatConfirmed = FALSE;
|
||||
if (d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
|
||||
{
|
||||
if (d3dCaps.DevCaps & D3DDEVCAPS_PUREDEVICE)
|
||||
{
|
||||
ms_dwD3DBehavior = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE;
|
||||
isFormatConfirmed = EL3D_ConfirmDevice(d3dCaps, ms_dwD3DBehavior);
|
||||
}
|
||||
|
||||
if (!isFormatConfirmed)
|
||||
{
|
||||
ms_dwD3DBehavior = D3DCREATE_HARDWARE_VERTEXPROCESSING;
|
||||
isFormatConfirmed = EL3D_ConfirmDevice(d3dCaps, ms_dwD3DBehavior);
|
||||
}
|
||||
|
||||
if (!isFormatConfirmed)
|
||||
{
|
||||
ms_dwD3DBehavior = D3DCREATE_MIXED_VERTEXPROCESSING;
|
||||
isFormatConfirmed = EL3D_ConfirmDevice(d3dCaps, ms_dwD3DBehavior);
|
||||
}
|
||||
}
|
||||
|
||||
std::string stModeInfo;
|
||||
pkD3DModeInfo->GetString(&stModeInfo);
|
||||
|
||||
//Tracen(stModeInfo.c_str());
|
||||
if (!isFormatConfirmed)
|
||||
{
|
||||
ms_dwD3DBehavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
|
||||
isFormatConfirmed = EL3D_ConfirmDevice(d3dCaps, ms_dwD3DBehavior);
|
||||
iRet |= CREATE_NO_TNL;
|
||||
}
|
||||
|
||||
int ErrorCorrection = 0;
|
||||
|
||||
@@ -424,54 +368,76 @@ RETRY:
|
||||
ms_d3dPresentParameter.BackBufferWidth = iHres;
|
||||
ms_d3dPresentParameter.BackBufferHeight = iVres;
|
||||
ms_d3dPresentParameter.hDeviceWindow = hWnd;
|
||||
ms_d3dPresentParameter.BackBufferFormat = d3dDisplayMode.Format;
|
||||
ms_d3dPresentParameter.BackBufferCount = m_uBackBufferCount;
|
||||
ms_d3dPresentParameter.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_NONE;
|
||||
|
||||
if (Windowed)
|
||||
{
|
||||
ms_d3dPresentParameter.BackBufferFormat = pkD3DAdapterInfo->GetDesktopD3DDisplayModer().Format;
|
||||
ms_d3dPresentParameter.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
|
||||
ms_d3dPresentParameter.FullScreen_RefreshRateInHz = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ms_d3dPresentParameter.BackBufferFormat = pkD3DModeInfo->m_eD3DFmtPixel;
|
||||
ms_d3dPresentParameter.FullScreen_RefreshRateInHz = iReflashRate;
|
||||
ms_d3dPresentParameter.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
|
||||
ms_d3dPresentParameter.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
|
||||
}
|
||||
|
||||
ms_d3dPresentParameter.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
|
||||
ms_d3dPresentParameter.EnableAutoDepthStencil = TRUE;
|
||||
ms_d3dPresentParameter.AutoDepthStencilFormat = pkD3DModeInfo->m_eD3DFmtDepthStencil;
|
||||
ms_d3dPresentParameter.AutoDepthStencilFormat = D3DFMT_D24S8;
|
||||
|
||||
ms_dwD3DBehavior = pkD3DModeInfo->m_dwD3DBehavior;
|
||||
|
||||
if (SUCCEEDED(ms_lpd3d->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT,
|
||||
D3DDEVTYPE_HAL,
|
||||
D3DFMT_A8R8G8B8,
|
||||
TRUE,
|
||||
D3DMULTISAMPLE_2_SAMPLES,
|
||||
&ms_d3dPresentParameter.MultiSampleQuality)))
|
||||
{
|
||||
ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
|
||||
ms_d3dPresentParameter.MultiSampleQuality = 0;
|
||||
}
|
||||
|
||||
if (SUCCEEDED(ms_lpd3d->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT,
|
||||
D3DDEVTYPE_HAL,
|
||||
D3DFMT_A8R8G8B8,
|
||||
TRUE,
|
||||
D3DMULTISAMPLE_4_SAMPLES,
|
||||
&ms_d3dPresentParameter.MultiSampleQuality)))
|
||||
{
|
||||
ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_4_SAMPLES;
|
||||
ms_d3dPresentParameter.MultiSampleQuality = 0;
|
||||
}
|
||||
|
||||
if (FAILED(ms_hLastResult = ms_lpd3d->CreateDevice(
|
||||
ms_iD3DAdapterInfo,
|
||||
D3DDEVTYPE_HAL,
|
||||
hWnd,
|
||||
// 2004. 1. 9 myevan 버텍스 프로세싱 방식 자동 선택 추가
|
||||
pkD3DModeInfo->m_dwD3DBehavior,
|
||||
&ms_d3dPresentParameter,
|
||||
&ms_lpd3dDevice)))
|
||||
D3DADAPTER_DEFAULT,
|
||||
D3DDEVTYPE_HAL,
|
||||
hWnd,
|
||||
ms_dwD3DBehavior,
|
||||
&ms_d3dPresentParameter,
|
||||
&ms_lpd3dDevice)))
|
||||
{
|
||||
switch (ms_hLastResult)
|
||||
{
|
||||
case D3DERR_INVALIDCALL:
|
||||
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_INVALIDCALL\nThe method call is invalid. For example, a method's parameter may have an invalid value.");
|
||||
break;
|
||||
case D3DERR_NOTAVAILABLE:
|
||||
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_NOTAVAILABLE\nThis device does not support the queried technique. ");
|
||||
break;
|
||||
case D3DERR_OUTOFVIDEOMEMORY:
|
||||
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_OUTOFVIDEOMEMORY\nDirect3D does not have enough display memory to perform the operation");
|
||||
break;
|
||||
default:
|
||||
Tracenf("IDirect3DDevice.CreateDevice - ERROR %d", ms_hLastResult);
|
||||
break;
|
||||
case D3DERR_INVALIDCALL:
|
||||
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_INVALIDCALL\nThe method call is invalid. For example, a method's parameter may have an invalid value.");
|
||||
break;
|
||||
case D3DERR_NOTAVAILABLE:
|
||||
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_NOTAVAILABLE\nThis device does not support the queried technique. ");
|
||||
break;
|
||||
case D3DERR_OUTOFVIDEOMEMORY:
|
||||
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_OUTOFVIDEOMEMORY\nDirect3D does not have enough display memory to perform the operation");
|
||||
break;
|
||||
default:
|
||||
Tracenf("IDirect3DDevice.CreateDevice - ERROR %d", ms_hLastResult);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ErrorCorrection)
|
||||
return CREATE_DEVICE;
|
||||
|
||||
// 2004. 1. 9 myevan 큰의미 없는 코드인듯.. 에러나면 표시하고 종료하자
|
||||
|
||||
// 2004. 1. 9 myevan Å«ÀÇ¹Ì ¾ø´Â ÄÚµåÀεí.. ¿¡·¯³ª¸é Ç¥½ÃÇϰí Á¾·áÇÏÀÚ
|
||||
iReflashRate = 0;
|
||||
++ErrorCorrection;
|
||||
iRet = CREATE_REFRESHRATE;
|
||||
@@ -479,38 +445,38 @@ RETRY:
|
||||
}
|
||||
|
||||
// Check DXT Support Info
|
||||
if(ms_lpd3d->CheckDeviceFormat(
|
||||
ms_iD3DAdapterInfo,
|
||||
D3DDEVTYPE_HAL,
|
||||
ms_d3dPresentParameter.BackBufferFormat,
|
||||
0,
|
||||
D3DRTYPE_TEXTURE,
|
||||
D3DFMT_DXT1) == D3DERR_NOTAVAILABLE)
|
||||
if (ms_lpd3d->CheckDeviceFormat(
|
||||
D3DADAPTER_DEFAULT,
|
||||
D3DDEVTYPE_HAL,
|
||||
ms_d3dPresentParameter.BackBufferFormat,
|
||||
0,
|
||||
D3DRTYPE_TEXTURE,
|
||||
D3DFMT_DXT1) == D3DERR_NOTAVAILABLE)
|
||||
{
|
||||
ms_bSupportDXT = false;
|
||||
}
|
||||
|
||||
if(ms_lpd3d->CheckDeviceFormat(
|
||||
ms_iD3DAdapterInfo,
|
||||
D3DDEVTYPE_HAL,
|
||||
ms_d3dPresentParameter.BackBufferFormat,
|
||||
0,
|
||||
D3DRTYPE_TEXTURE,
|
||||
D3DFMT_DXT3) == D3DERR_NOTAVAILABLE)
|
||||
if (ms_lpd3d->CheckDeviceFormat(
|
||||
D3DADAPTER_DEFAULT,
|
||||
D3DDEVTYPE_HAL,
|
||||
ms_d3dPresentParameter.BackBufferFormat,
|
||||
0,
|
||||
D3DRTYPE_TEXTURE,
|
||||
D3DFMT_DXT3) == D3DERR_NOTAVAILABLE)
|
||||
{
|
||||
ms_bSupportDXT = false;
|
||||
}
|
||||
|
||||
if(ms_lpd3d->CheckDeviceFormat(
|
||||
ms_iD3DAdapterInfo,
|
||||
D3DDEVTYPE_HAL,
|
||||
ms_d3dPresentParameter.BackBufferFormat,
|
||||
0,
|
||||
D3DRTYPE_TEXTURE,
|
||||
D3DFMT_DXT5) == D3DERR_NOTAVAILABLE)
|
||||
if (ms_lpd3d->CheckDeviceFormat(
|
||||
D3DADAPTER_DEFAULT,
|
||||
D3DDEVTYPE_HAL,
|
||||
ms_d3dPresentParameter.BackBufferFormat,
|
||||
0,
|
||||
D3DRTYPE_TEXTURE,
|
||||
D3DFMT_DXT5) == D3DERR_NOTAVAILABLE)
|
||||
{
|
||||
ms_bSupportDXT = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (FAILED((ms_hLastResult = ms_lpd3dDevice->GetDeviceCaps(&ms_d3dCaps))))
|
||||
{
|
||||
@@ -580,15 +546,15 @@ RETRY:
|
||||
else
|
||||
GRAPHICS_CAPS_CAN_NOT_TEXTURE_ADDRESS_BORDER=true;
|
||||
|
||||
//D3DADAPTER_IDENTIFIER8& rkD3DAdapterId=pkD3DAdapterInfo->GetIdentifier();
|
||||
if (strnicmp(rkD3DAdapterId.Driver, "SIS", 3) == 0)
|
||||
//D3DADAPTER_IDENTIFIER9& rkD3DAdapterId=pkD3DAdapterInfo->GetIdentifier();
|
||||
if (strnicmp(d3dAdapterId.Driver, "SIS", 3) == 0)
|
||||
{
|
||||
GRAPHICS_CAPS_CAN_NOT_DRAW_LINE = true;
|
||||
GRAPHICS_CAPS_CAN_NOT_DRAW_SHADOW = true;
|
||||
GRAPHICS_CAPS_HALF_SIZE_IMAGE = true;
|
||||
ms_isLowTextureMemory = true;
|
||||
}
|
||||
else if (strnicmp(rkD3DAdapterId.Driver, "3dfx", 4) == 0)
|
||||
else if (strnicmp(d3dAdapterId.Driver, "3dfx", 4) == 0)
|
||||
{
|
||||
GRAPHICS_CAPS_CAN_NOT_DRAW_SHADOW = true;
|
||||
GRAPHICS_CAPS_HALF_SIZE_IMAGE = true;
|
||||
@@ -626,7 +592,7 @@ bool CGraphicDevice::__CreatePDTVertexBufferList()
|
||||
D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
|
||||
D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1,
|
||||
D3DPOOL_SYSTEMMEM,
|
||||
&ms_alpd3dPDTVB[i])
|
||||
&ms_alpd3dPDTVB[i], nullptr)
|
||||
))
|
||||
return false;
|
||||
}
|
||||
@@ -659,12 +625,12 @@ bool CGraphicDevice::__CreateDefaultIndexBuffer(UINT eDefIB, UINT uIdxCount, con
|
||||
D3DUSAGE_WRITEONLY,
|
||||
D3DFMT_INDEX16,
|
||||
D3DPOOL_MANAGED,
|
||||
&ms_alpd3dDefIB[eDefIB])
|
||||
&ms_alpd3dDefIB[eDefIB], nullptr)
|
||||
)) return false;
|
||||
|
||||
WORD* dstIndices;
|
||||
if (FAILED(
|
||||
ms_alpd3dDefIB[eDefIB]->Lock(0, 0, (BYTE**)&dstIndices, 0)
|
||||
ms_alpd3dDefIB[eDefIB]->Lock(0, 0, (void**)&dstIndices, 0)
|
||||
)) return false;
|
||||
|
||||
memcpy(dstIndices, c_awIndices, sizeof(WORD)*uIdxCount);
|
||||
@@ -731,20 +697,20 @@ void CGraphicDevice::Destroy()
|
||||
|
||||
if (ms_ptVS)
|
||||
{
|
||||
ms_lpd3dDevice->DeleteVertexShader(ms_ptVS);
|
||||
ms_ptVS = 0;;
|
||||
ms_ptVS->Release();
|
||||
ms_ptVS = nullptr;
|
||||
}
|
||||
|
||||
if (ms_pntVS)
|
||||
{
|
||||
ms_lpd3dDevice->DeleteVertexShader(ms_pntVS);
|
||||
ms_pntVS = 0;
|
||||
ms_pntVS->Release();
|
||||
ms_pntVS = nullptr;
|
||||
}
|
||||
|
||||
if (ms_pnt2VS)
|
||||
{
|
||||
ms_lpd3dDevice->DeleteVertexShader(ms_pnt2VS);
|
||||
ms_pnt2VS = 0;
|
||||
ms_pnt2VS->Release();
|
||||
ms_pnt2VS = nullptr;
|
||||
}
|
||||
|
||||
safe_release(ms_lpSphereMesh);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "GrpBase.h"
|
||||
#include "GrpDetector.h"
|
||||
#include "StateManager.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
class CGraphicDevice : public CGraphicBase
|
||||
{
|
||||
public:
|
||||
@@ -50,7 +51,6 @@ public:
|
||||
|
||||
protected:
|
||||
void __Initialize();
|
||||
bool __IsInDriverBlackList(D3D_CAdapterInfo& rkD3DAdapterInfo);
|
||||
void __WarningMessage(HWND hWnd, UINT uiMsg);
|
||||
|
||||
void __InitializeDefaultIndexBufferList();
|
||||
@@ -62,10 +62,10 @@ protected:
|
||||
void __DestroyPDTVertexBufferList();
|
||||
bool __CreatePDTVertexBufferList();
|
||||
|
||||
DWORD CreatePTStreamVertexShader();
|
||||
DWORD CreatePNTStreamVertexShader();
|
||||
DWORD CreatePNT2StreamVertexShader();
|
||||
DWORD CreateDoublePNTStreamVertexShader();
|
||||
LPDIRECT3DVERTEXDECLARATION9 CreatePTStreamVertexShader();
|
||||
LPDIRECT3DVERTEXDECLARATION9 CreatePNTStreamVertexShader();
|
||||
LPDIRECT3DVERTEXDECLARATION9 CreatePNT2StreamVertexShader();
|
||||
LPDIRECT3DVERTEXDECLARATION9 CreateDoublePNTStreamVertexShader();
|
||||
|
||||
protected:
|
||||
DWORD m_uBackBufferCount;
|
||||
|
||||
@@ -123,7 +123,7 @@ void CGraphicExpandedImageInstance::OnRender()
|
||||
|
||||
STATEMANAGER.SetTexture(0, pTexture->GetD3DTexture());
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
|
||||
}
|
||||
//STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, c_FillRectIndices, D3DFMT_INDEX16, vertices, sizeof(TPDTVertex));
|
||||
|
||||
@@ -90,7 +90,7 @@ void CGraphicImageInstance::OnRender()
|
||||
|
||||
STATEMANAGER.SetTexture(0, pTexture->GetD3DTexture());
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
|
||||
}
|
||||
//OLD: STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, c_FillRectIndices, D3DFMT_INDEX16, vertices, sizeof(TPDTVertex));
|
||||
|
||||
@@ -45,7 +45,7 @@ bool CGraphicImageTexture::CreateDeviceObjects()
|
||||
if (m_stFileName.empty())
|
||||
{
|
||||
// 폰트 텍스쳐
|
||||
if (FAILED(ms_lpd3dDevice->CreateTexture(m_width, m_height, 1, 0, m_d3dFmt, D3DPOOL_MANAGED, &m_lpd3dTexture)))
|
||||
if (FAILED(ms_lpd3dDevice->CreateTexture(m_width, m_height, 1, 0, m_d3dFmt, D3DPOOL_MANAGED, &m_lpd3dTexture, nullptr)))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -96,7 +96,7 @@ bool CGraphicImageTexture::CreateDDSTexture(CDXTCImage & image, const BYTE * /*c
|
||||
int mipmapCount = image.m_dwMipMapCount == 0 ? 1 : image.m_dwMipMapCount;
|
||||
|
||||
D3DFORMAT format;
|
||||
LPDIRECT3DTEXTURE8 lpd3dTexture;
|
||||
LPDIRECT3DTEXTURE9 lpd3dTexture;
|
||||
D3DPOOL pool = ms_bSupportDXT ? D3DPOOL_MANAGED : D3DPOOL_SCRATCH;;
|
||||
|
||||
if(image.m_CompFormat == PF_DXT5)
|
||||
@@ -173,13 +173,13 @@ bool CGraphicImageTexture::CreateDDSTexture(CDXTCImage & image, const BYTE * /*c
|
||||
return false;
|
||||
}
|
||||
|
||||
IDirect3DTexture8* pkTexSrc=lpd3dTexture;
|
||||
IDirect3DTexture8* pkTexDst=m_lpd3dTexture;
|
||||
IDirect3DTexture9* pkTexSrc=lpd3dTexture;
|
||||
IDirect3DTexture9* pkTexDst=m_lpd3dTexture;
|
||||
|
||||
for(int i=0; i<mipmapCount; ++i) {
|
||||
|
||||
IDirect3DSurface8* ppsSrc = NULL;
|
||||
IDirect3DSurface8* ppsDst = NULL;
|
||||
IDirect3DSurface9* ppsSrc = NULL;
|
||||
IDirect3DSurface9* ppsDst = NULL;
|
||||
|
||||
if (SUCCEEDED(pkTexSrc->GetSurfaceLevel(i, &ppsSrc)))
|
||||
{
|
||||
@@ -261,8 +261,8 @@ bool CGraphicImageTexture::CreateFromMemoryFile(UINT bufSize, const void * c_pvB
|
||||
if (IsLowTextureMemory())
|
||||
if (uTexBias || format!=imageInfo.Format)
|
||||
{
|
||||
IDirect3DTexture8* pkTexSrc=m_lpd3dTexture;
|
||||
IDirect3DTexture8* pkTexDst;
|
||||
IDirect3DTexture9* pkTexSrc=m_lpd3dTexture;
|
||||
IDirect3DTexture9* pkTexDst;
|
||||
|
||||
|
||||
if (SUCCEEDED(D3DXCreateTexture(
|
||||
@@ -279,8 +279,8 @@ bool CGraphicImageTexture::CreateFromMemoryFile(UINT bufSize, const void * c_pvB
|
||||
|
||||
for(int i=0; i<imageInfo.MipLevels; ++i) {
|
||||
|
||||
IDirect3DSurface8* ppsSrc = NULL;
|
||||
IDirect3DSurface8* ppsDst = NULL;
|
||||
IDirect3DSurface9* ppsSrc = NULL;
|
||||
IDirect3DSurface9* ppsDst = NULL;
|
||||
|
||||
if (SUCCEEDED(pkTexSrc->GetSurfaceLevel(i, &ppsSrc)))
|
||||
{
|
||||
|
||||
@@ -3,24 +3,27 @@
|
||||
#include "GrpIndexBuffer.h"
|
||||
#include "StateManager.h"
|
||||
|
||||
LPDIRECT3DINDEXBUFFER8 CGraphicIndexBuffer::GetD3DIndexBuffer() const
|
||||
LPDIRECT3DINDEXBUFFER9 CGraphicIndexBuffer::GetD3DIndexBuffer() const
|
||||
{
|
||||
assert(m_lpd3dIdxBuf!=NULL);
|
||||
assert(m_lpd3dIdxBuf != NULL);
|
||||
return m_lpd3dIdxBuf;
|
||||
}
|
||||
|
||||
void CGraphicIndexBuffer::SetIndices(int startIndex) const
|
||||
{
|
||||
assert(ms_lpd3dDevice!=NULL);
|
||||
STATEMANAGER.SetIndices(m_lpd3dIdxBuf, startIndex);
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
STATEMANAGER.SetIndices(m_lpd3dIdxBuf, startIndex);
|
||||
}
|
||||
|
||||
|
||||
bool CGraphicIndexBuffer::Lock(void** pretIndices) const
|
||||
{
|
||||
assert(m_lpd3dIdxBuf!=NULL);
|
||||
assert(m_lpd3dIdxBuf != NULL);
|
||||
|
||||
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (BYTE**)pretIndices, 0)))
|
||||
if (!m_lpd3dIdxBuf)
|
||||
return false;
|
||||
|
||||
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, pretIndices, 0)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -28,16 +31,22 @@ bool CGraphicIndexBuffer::Lock(void** pretIndices) const
|
||||
|
||||
void CGraphicIndexBuffer::Unlock() const
|
||||
{
|
||||
assert(m_lpd3dIdxBuf!=NULL);
|
||||
assert(m_lpd3dIdxBuf != NULL);
|
||||
|
||||
if (!m_lpd3dIdxBuf)
|
||||
return;
|
||||
|
||||
m_lpd3dIdxBuf->Unlock();
|
||||
}
|
||||
|
||||
bool CGraphicIndexBuffer::Lock(void** pretIndices)
|
||||
{
|
||||
assert(m_lpd3dIdxBuf!=NULL);
|
||||
assert(m_lpd3dIdxBuf != NULL);
|
||||
|
||||
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (BYTE**)pretIndices, 0)))
|
||||
if (!m_lpd3dIdxBuf)
|
||||
return false;
|
||||
|
||||
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, pretIndices, 0)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -45,17 +54,20 @@ bool CGraphicIndexBuffer::Lock(void** pretIndices)
|
||||
|
||||
void CGraphicIndexBuffer::Unlock()
|
||||
{
|
||||
assert(m_lpd3dIdxBuf!=NULL);
|
||||
assert(m_lpd3dIdxBuf != NULL);
|
||||
|
||||
if (!m_lpd3dIdxBuf)
|
||||
return;
|
||||
|
||||
m_lpd3dIdxBuf->Unlock();
|
||||
}
|
||||
|
||||
bool CGraphicIndexBuffer::Copy(int bufSize, const void* srcIndices)
|
||||
{
|
||||
assert(m_lpd3dIdxBuf!=NULL);
|
||||
assert(m_lpd3dIdxBuf != NULL);
|
||||
|
||||
BYTE* dstIndices;
|
||||
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, &dstIndices, 0)))
|
||||
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (void**)&dstIndices, 0)))
|
||||
return false;
|
||||
|
||||
memcpy(dstIndices, srcIndices, bufSize);
|
||||
@@ -73,15 +85,15 @@ bool CGraphicIndexBuffer::Create(int faceCount, TFace* faces)
|
||||
return false;
|
||||
|
||||
WORD* dstIndices;
|
||||
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (BYTE**)&dstIndices, 0)))
|
||||
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (void**)&dstIndices, 0)))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i<faceCount; ++i, dstIndices+=3)
|
||||
{
|
||||
TFace * curFace=faces+i;
|
||||
dstIndices[0]=curFace->indices[0];
|
||||
dstIndices[1]=curFace->indices[1];
|
||||
dstIndices[2]=curFace->indices[2];
|
||||
for (int i = 0; i < faceCount; ++i, dstIndices += 3)
|
||||
{
|
||||
TFace* curFace = faces + i;
|
||||
dstIndices[0] = curFace->indices[0];
|
||||
dstIndices[1] = curFace->indices[1];
|
||||
dstIndices[2] = curFace->indices[2];
|
||||
}
|
||||
|
||||
m_lpd3dIdxBuf->Unlock();
|
||||
@@ -91,12 +103,13 @@ bool CGraphicIndexBuffer::Create(int faceCount, TFace* faces)
|
||||
bool CGraphicIndexBuffer::CreateDeviceObjects()
|
||||
{
|
||||
if (FAILED(ms_lpd3dDevice->CreateIndexBuffer(
|
||||
m_dwBufferSize,
|
||||
D3DUSAGE_WRITEONLY,
|
||||
m_dwBufferSize,
|
||||
D3DUSAGE_WRITEONLY,
|
||||
m_d3dFmt,
|
||||
D3DPOOL_MANAGED,
|
||||
&m_lpd3dIdxBuf)
|
||||
))
|
||||
D3DPOOL_MANAGED,
|
||||
&m_lpd3dIdxBuf,
|
||||
NULL)
|
||||
))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -108,9 +121,9 @@ void CGraphicIndexBuffer::DestroyDeviceObjects()
|
||||
}
|
||||
|
||||
bool CGraphicIndexBuffer::Create(int idxCount, D3DFORMAT d3dFmt)
|
||||
{
|
||||
{
|
||||
Destroy();
|
||||
|
||||
|
||||
m_iidxCount = idxCount;
|
||||
m_dwBufferSize = sizeof(WORD) * idxCount;
|
||||
m_d3dFmt = d3dFmt;
|
||||
@@ -125,7 +138,7 @@ void CGraphicIndexBuffer::Destroy()
|
||||
|
||||
void CGraphicIndexBuffer::Initialize()
|
||||
{
|
||||
m_lpd3dIdxBuf=NULL;
|
||||
m_lpd3dIdxBuf = NULL;
|
||||
}
|
||||
|
||||
CGraphicIndexBuffer::CGraphicIndexBuffer()
|
||||
|
||||
@@ -4,37 +4,37 @@
|
||||
|
||||
class CGraphicIndexBuffer : public CGraphicBase
|
||||
{
|
||||
public:
|
||||
CGraphicIndexBuffer();
|
||||
virtual ~CGraphicIndexBuffer();
|
||||
public:
|
||||
CGraphicIndexBuffer();
|
||||
virtual ~CGraphicIndexBuffer();
|
||||
|
||||
void Destroy();
|
||||
bool Create(int idxCount, D3DFORMAT d3dFmt);
|
||||
bool Create(int faceCount, TFace* faces);
|
||||
void Destroy();
|
||||
bool Create(int idxCount, D3DFORMAT d3dFmt);
|
||||
bool Create(int faceCount, TFace* faces);
|
||||
|
||||
bool CreateDeviceObjects();
|
||||
void DestroyDeviceObjects();
|
||||
bool CreateDeviceObjects();
|
||||
void DestroyDeviceObjects();
|
||||
|
||||
bool Copy(int bufSize, const void* srcIndices);
|
||||
bool Copy(int bufSize, const void* srcIndices);
|
||||
|
||||
bool Lock(void** pretIndices) const;
|
||||
void Unlock() const;
|
||||
bool Lock(void** pretIndices) const;
|
||||
void Unlock() const;
|
||||
|
||||
bool Lock(void** pretIndices);
|
||||
void Unlock();
|
||||
bool Lock(void** pretIndices);
|
||||
void Unlock();
|
||||
|
||||
void SetIndices(int startIndex=0) const;
|
||||
void SetIndices(int startIndex = 0) const;
|
||||
|
||||
LPDIRECT3DINDEXBUFFER8 GetD3DIndexBuffer() const;
|
||||
LPDIRECT3DINDEXBUFFER9 GetD3DIndexBuffer() const;
|
||||
|
||||
int GetIndexCount() const {return m_iidxCount;}
|
||||
int GetIndexCount() const { return m_iidxCount; }
|
||||
|
||||
protected:
|
||||
void Initialize();
|
||||
protected:
|
||||
void Initialize();
|
||||
|
||||
protected:
|
||||
LPDIRECT3DINDEXBUFFER8 m_lpd3dIdxBuf;
|
||||
DWORD m_dwBufferSize;
|
||||
D3DFORMAT m_d3dFmt;
|
||||
int m_iidxCount;
|
||||
protected:
|
||||
LPDIRECT3DINDEXBUFFER9 m_lpd3dIdxBuf;
|
||||
DWORD m_dwBufferSize;
|
||||
D3DFORMAT m_d3dFmt;
|
||||
int m_iidxCount;
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ void CLightManager::Initialize()
|
||||
m_LightPool.FreeAll();
|
||||
}
|
||||
|
||||
void CLightManager::RegisterLight(ELightType /*LightType*/, TLightID * poutLightID, D3DLIGHT8 & LightData)
|
||||
void CLightManager::RegisterLight(ELightType /*LightType*/, TLightID * poutLightID, D3DLIGHT9 & LightData)
|
||||
{
|
||||
CLight * pLight = m_LightPool.Alloc();
|
||||
TLightID ID = NewLightID();
|
||||
@@ -212,7 +212,7 @@ void CLight::SetDeviceLight(BOOL bActive)
|
||||
}
|
||||
}
|
||||
|
||||
void CLight::SetParameter(TLightID id, const D3DLIGHT8 & c_rLight)
|
||||
void CLight::SetParameter(TLightID id, const D3DLIGHT9 & c_rLight)
|
||||
{
|
||||
m_LightID = id;
|
||||
m_d3dLight = c_rLight;
|
||||
|
||||
@@ -39,7 +39,7 @@ class CLight : public CGraphicBase, public CLightBase
|
||||
|
||||
void Update();
|
||||
|
||||
void SetParameter(TLightID id, const D3DLIGHT8 & c_rLight);
|
||||
void SetParameter(TLightID id, const D3DLIGHT9 & c_rLight);
|
||||
|
||||
void SetDistance(float fDistance);
|
||||
float GetDistance() const { return m_fDistance; }
|
||||
@@ -63,7 +63,7 @@ class CLight : public CGraphicBase, public CLightBase
|
||||
private:
|
||||
TLightID m_LightID; // Light ID. equal to D3D light index
|
||||
|
||||
D3DLIGHT8 m_d3dLight;
|
||||
D3DLIGHT9 m_d3dLight;
|
||||
BOOL m_isEdited;
|
||||
float m_fDistance;
|
||||
|
||||
@@ -100,7 +100,7 @@ class CLightManager : public CGraphicBase, public CLightBase, public CSingleton<
|
||||
void RestoreLight();
|
||||
|
||||
/////
|
||||
void RegisterLight(ELightType LightType, TLightID * poutLightID, D3DLIGHT8 & LightData);
|
||||
void RegisterLight(ELightType LightType, TLightID * poutLightID, D3DLIGHT9 & LightData);
|
||||
CLight * GetLight(TLightID LightID);
|
||||
void DeleteLight(TLightID LightID);
|
||||
/////
|
||||
|
||||
@@ -108,7 +108,7 @@ void CGraphicMarkInstance::OnRender()
|
||||
|
||||
STATEMANAGER.SetTexture(0, pTexture->GetD3DTexture());
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
|
||||
//OLD: STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, c_FillRectIndices, D3DFMT_INDEX16, vertices, sizeof(TPDTVertex));
|
||||
}
|
||||
|
||||
@@ -22,9 +22,8 @@ void CPixelShader::Destroy()
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
if (ms_lpd3dDevice)
|
||||
ms_lpd3dDevice->DeletePixelShader(m_handle);
|
||||
m_handle=0;
|
||||
m_handle->Release();
|
||||
m_handle=nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +35,7 @@ bool CPixelShader::CreateFromDiskFile(const char* c_szFileName)
|
||||
LPD3DXBUFFER lpd3dxErrorBuffer;
|
||||
|
||||
if (FAILED(
|
||||
D3DXAssembleShaderFromFile(c_szFileName, 0, NULL, &lpd3dxShaderBuffer, &lpd3dxErrorBuffer)
|
||||
D3DXAssembleShaderFromFile(c_szFileName, 0, NULL, 0, &lpd3dxShaderBuffer, &lpd3dxErrorBuffer)
|
||||
))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -17,5 +17,5 @@ class CPixelShader : public CGraphicBase
|
||||
void Initialize();
|
||||
|
||||
protected:
|
||||
DWORD m_handle;
|
||||
LPDIRECT3DPIXELSHADER9 m_handle;
|
||||
};
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "Camera.h"
|
||||
#include "StateManager.h"
|
||||
|
||||
#include <comdef.h>
|
||||
|
||||
DWORD CScreen::ms_diffuseColor = 0xffffffff;
|
||||
DWORD CScreen::ms_clearColor = 0L;
|
||||
DWORD CScreen::ms_clearStencil = 0L;
|
||||
@@ -29,7 +31,7 @@ void CScreen::RenderLine3d(float sx, float sy, float sz, float ex, float ey, flo
|
||||
{
|
||||
STATEMANAGER.SetTexture(0, NULL);
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.DrawPrimitive(D3DPT_LINELIST, 0, 1);
|
||||
}
|
||||
}
|
||||
@@ -61,7 +63,7 @@ void CScreen::RenderBox3d(float sx, float sy, float sz, float ex, float ey, floa
|
||||
{
|
||||
STATEMANAGER.SetTexture(0, NULL);
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.DrawPrimitive(D3DPT_LINELIST, 0, 4);
|
||||
}
|
||||
}
|
||||
@@ -84,7 +86,7 @@ void CScreen::RenderBar3d(float sx, float sy, float sz, float ex, float ey, floa
|
||||
{
|
||||
STATEMANAGER.SetTexture(0, NULL);
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
}
|
||||
}
|
||||
@@ -106,7 +108,7 @@ void CScreen::RenderBar3d(const D3DXVECTOR3 * c_pv3Positions)
|
||||
{
|
||||
STATEMANAGER.SetTexture(0, NULL);
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
}
|
||||
}
|
||||
@@ -129,7 +131,7 @@ void CScreen::RenderGradationBar3d(float sx, float sy, float sz, float ex, float
|
||||
{
|
||||
STATEMANAGER.SetTexture(0, NULL);
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
}
|
||||
}
|
||||
@@ -153,7 +155,7 @@ void CScreen::RenderLineCube(float sx, float sy, float sz, float ex, float ey, f
|
||||
{
|
||||
STATEMANAGER.SetTexture(0, NULL);
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop());
|
||||
SetDefaultIndexBuffer(DEFAULT_IB_LINE_CUBE);
|
||||
|
||||
@@ -180,7 +182,7 @@ void CScreen::RenderCube(float sx, float sy, float sz, float ex, float ey, float
|
||||
{
|
||||
STATEMANAGER.SetTexture(0, NULL);
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop());
|
||||
|
||||
SetDefaultIndexBuffer(DEFAULT_IB_FILL_CUBE);
|
||||
@@ -220,7 +222,7 @@ void CScreen::RenderCube(float sx, float sy, float sz, float ex, float ey, float
|
||||
{
|
||||
STATEMANAGER.SetTexture(0, NULL);
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop());
|
||||
|
||||
SetDefaultIndexBuffer(DEFAULT_IB_FILL_CUBE);
|
||||
@@ -315,7 +317,7 @@ public:
|
||||
|
||||
CD3DXMeshRenderingOption(D3DFILLMODE d3dFillMode, const D3DXMATRIX & c_rmatWorld)
|
||||
{
|
||||
ms_lpd3dDevice->GetVertexShader(&m_dwVS);
|
||||
ms_lpd3dDevice->GetFVF(&m_dwVS);
|
||||
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
|
||||
@@ -329,7 +331,7 @@ public:
|
||||
|
||||
virtual ~CD3DXMeshRenderingOption()
|
||||
{
|
||||
ms_lpd3dDevice->SetVertexShader(m_dwVS);
|
||||
ms_lpd3dDevice->SetFVF(m_dwVS);
|
||||
|
||||
STATEMANAGER.RestoreTransform(D3DTS_WORLD);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLORARG1);
|
||||
@@ -356,11 +358,11 @@ void CScreen::RenderD3DXMesh(LPD3DXMESH lpMesh, const D3DXMATRIX * c_pmatWorld,
|
||||
}
|
||||
|
||||
CD3DXMeshRenderingOption SetRenderingOption(d3dFillMode, matWorld);
|
||||
LPDIRECT3DINDEXBUFFER8 lpIndexBuffer;
|
||||
LPDIRECT3DVERTEXBUFFER8 lpVertexBuffer;
|
||||
LPDIRECT3DINDEXBUFFER9 lpIndexBuffer;
|
||||
LPDIRECT3DVERTEXBUFFER9 lpVertexBuffer;
|
||||
lpMesh->GetIndexBuffer(&lpIndexBuffer);
|
||||
lpMesh->GetVertexBuffer(&lpVertexBuffer);
|
||||
STATEMANAGER.SetVertexShader(lpMesh->GetFVF());
|
||||
STATEMANAGER.SetFVF(lpMesh->GetFVF());
|
||||
STATEMANAGER.SetIndices(lpIndexBuffer, 0);
|
||||
STATEMANAGER.SetStreamSource(0, lpVertexBuffer, 24);
|
||||
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, lpMesh->GetNumVertices(), 0, lpMesh->GetNumFaces());
|
||||
@@ -401,7 +403,7 @@ void CScreen::RenderTextureBox(float sx, float sy, float ex, float ey, float z,
|
||||
#ifdef WORLD_EDITOR
|
||||
STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop());
|
||||
#endif
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
|
||||
// 2004.11.18.myevan.DrawIndexPrimitiveUP -> DynamicVertexBuffer
|
||||
SetDefaultIndexBuffer(DEFAULT_IB_FILL_RECT);
|
||||
@@ -432,7 +434,7 @@ void CScreen::RenderBillboard(D3DXVECTOR3 * Position, D3DXCOLOR & Color)
|
||||
vertices[3].diffuse = Color;
|
||||
vertices[3].texCoord = TTextureCoordinate(1, 1);
|
||||
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
|
||||
// 2004.11.18.myevan.DrawIndexPrimitiveUP -> DynamicVertexBuffer
|
||||
SetDefaultIndexBuffer(DEFAULT_IB_FILL_RECT);
|
||||
@@ -631,7 +633,7 @@ BOOL CScreen::IsLostDevice()
|
||||
if (!ms_lpd3dDevice)
|
||||
return TRUE;
|
||||
|
||||
IDirect3DDevice8 & rkD3DDev = *ms_lpd3dDevice;
|
||||
IDirect3DDevice9 & rkD3DDev = *ms_lpd3dDevice;
|
||||
HRESULT hrTestCooperativeLevel = rkD3DDev.TestCooperativeLevel();
|
||||
if (FAILED(hrTestCooperativeLevel))
|
||||
return TRUE;
|
||||
@@ -644,11 +646,9 @@ BOOL CScreen::RestoreDevice()
|
||||
if (!ms_lpd3dDevice)
|
||||
return FALSE;
|
||||
|
||||
UINT iD3DAdapterInfo = ms_iD3DAdapterInfo;
|
||||
IDirect3D8 & rkD3D = *ms_lpd3d;
|
||||
IDirect3DDevice8 & rkD3DDev = *ms_lpd3dDevice;
|
||||
D3DPRESENT_PARAMETERS & rkD3DPP = ms_d3dPresentParameter;
|
||||
D3D_CDisplayModeAutoDetector & rkD3DDetector = ms_kD3DDetector;
|
||||
IDirect3D9& rkD3D = *ms_lpd3d;
|
||||
IDirect3DDevice9& rkD3DDev = *ms_lpd3dDevice;
|
||||
D3DPRESENT_PARAMETERS& rkD3DPP = ms_d3dPresentParameter;
|
||||
|
||||
HRESULT hrTestCooperativeLevel = rkD3DDev.TestCooperativeLevel();
|
||||
|
||||
@@ -661,22 +661,19 @@ BOOL CScreen::RestoreDevice()
|
||||
|
||||
if (D3DERR_DEVICENOTRESET == hrTestCooperativeLevel)
|
||||
{
|
||||
D3D_CAdapterInfo* pkD3DAdapterInfo = rkD3DDetector.GetD3DAdapterInfop(ms_iD3DAdapterInfo);
|
||||
|
||||
if (!pkD3DAdapterInfo)
|
||||
return FALSE;
|
||||
|
||||
D3DDISPLAYMODE & rkD3DDMDesktop = pkD3DAdapterInfo->GetDesktopD3DDisplayModer();
|
||||
|
||||
if (FAILED(rkD3D.GetAdapterDisplayMode(iD3DAdapterInfo, &rkD3DDMDesktop)))
|
||||
D3DDISPLAYMODE d3dDisplayMode;
|
||||
if (FAILED(rkD3D.GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3dDisplayMode)))
|
||||
return FALSE;
|
||||
|
||||
rkD3DPP.BackBufferFormat = rkD3DDMDesktop.Format;
|
||||
rkD3DPP.BackBufferFormat = d3dDisplayMode.Format;
|
||||
|
||||
HRESULT hrReset = rkD3DDev.Reset(&rkD3DPP);
|
||||
|
||||
if (FAILED(hrReset))
|
||||
{
|
||||
_com_error err(hrReset);
|
||||
LPCTSTR errMsg = err.ErrorMessage();
|
||||
TraceError(errMsg);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,13 +35,13 @@ bool CGraphicShadowTexture::Create(int width, int height)
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
if (FAILED(ms_lpd3dDevice->CreateTexture(m_width, m_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_lpd3dShadowTexture)))
|
||||
if (FAILED(ms_lpd3dDevice->CreateTexture(m_width, m_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_lpd3dShadowTexture, nullptr)))
|
||||
return false;
|
||||
|
||||
if (FAILED(m_lpd3dShadowTexture->GetSurfaceLevel(0, &m_lpd3dShadowSurface)))
|
||||
return false;
|
||||
|
||||
if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_width, m_height, D3DFMT_D16, D3DMULTISAMPLE_NONE, &m_lpd3dDepthSurface)))
|
||||
if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_width, m_height, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, TRUE, &m_lpd3dDepthSurface, nullptr)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -57,7 +57,7 @@ const D3DXMATRIX& CGraphicShadowTexture::GetLightVPMatrixReference() const
|
||||
return m_d3dLightVPMatrix;
|
||||
}
|
||||
|
||||
LPDIRECT3DTEXTURE8 CGraphicShadowTexture::GetD3DTexture() const
|
||||
LPDIRECT3DTEXTURE9 CGraphicShadowTexture::GetD3DTexture() const
|
||||
{
|
||||
return m_lpd3dShadowTexture;
|
||||
}
|
||||
@@ -66,13 +66,14 @@ void CGraphicShadowTexture::Begin()
|
||||
{
|
||||
D3DXMatrixMultiply(&m_d3dLightVPMatrix, &ms_matView, &ms_matProj);
|
||||
|
||||
ms_lpd3dDevice->GetRenderTarget(&m_lpd3dOldBackBufferSurface);
|
||||
ms_lpd3dDevice->GetRenderTarget(0, &m_lpd3dOldBackBufferSurface);
|
||||
ms_lpd3dDevice->GetDepthStencilSurface(&m_lpd3dOldDepthBufferSurface);
|
||||
ms_lpd3dDevice->GetViewport(&m_d3dOldViewport);
|
||||
|
||||
ms_lpd3dDevice->SetRenderTarget(m_lpd3dShadowSurface, m_lpd3dDepthSurface);
|
||||
ms_lpd3dDevice->SetDepthStencilSurface(m_lpd3dDepthSurface);
|
||||
ms_lpd3dDevice->SetRenderTarget(0, m_lpd3dShadowSurface);
|
||||
|
||||
D3DVIEWPORT8 d3dViewport;
|
||||
D3DVIEWPORT9 d3dViewport;
|
||||
d3dViewport.MinZ = 0.0f;
|
||||
d3dViewport.MaxZ = 1.0f;
|
||||
d3dViewport.X = 0;
|
||||
@@ -99,11 +100,11 @@ void CGraphicShadowTexture::Begin()
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
||||
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
|
||||
STATEMANAGER.SaveSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
|
||||
STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
|
||||
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SaveTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
|
||||
@@ -113,11 +114,11 @@ void CGraphicShadowTexture::Begin()
|
||||
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
|
||||
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
|
||||
|
||||
STATEMANAGER.SaveTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveTextureStageState(1, D3DTSS_MIPFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
|
||||
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
|
||||
STATEMANAGER.SaveSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
|
||||
STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
|
||||
STATEMANAGER.SaveSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
|
||||
}
|
||||
|
||||
void CGraphicShadowTexture::End()
|
||||
@@ -127,7 +128,8 @@ void CGraphicShadowTexture::End()
|
||||
|
||||
ms_lpd3dDevice->EndScene();
|
||||
|
||||
ms_lpd3dDevice->SetRenderTarget(m_lpd3dOldBackBufferSurface, m_lpd3dOldDepthBufferSurface);
|
||||
ms_lpd3dDevice->SetDepthStencilSurface(m_lpd3dOldDepthBufferSurface);
|
||||
ms_lpd3dDevice->SetRenderTarget(0, m_lpd3dOldBackBufferSurface);
|
||||
ms_lpd3dDevice->SetViewport(&m_d3dOldViewport);
|
||||
|
||||
m_lpd3dOldBackBufferSurface->Release();
|
||||
@@ -149,11 +151,11 @@ void CGraphicShadowTexture::End()
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ALPHAARG2);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ALPHAOP);
|
||||
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MINFILTER);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MAGFILTER);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MIPFILTER);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSU);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSV);
|
||||
STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MINFILTER);
|
||||
STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MAGFILTER);
|
||||
STATEMANAGER.RestoreSamplerState(0, D3DSAMP_MIPFILTER);
|
||||
STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSU);
|
||||
STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSV);
|
||||
|
||||
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_COLORARG1);
|
||||
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_COLORARG2);
|
||||
@@ -162,11 +164,11 @@ void CGraphicShadowTexture::End()
|
||||
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ALPHAARG2);
|
||||
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ALPHAOP);
|
||||
|
||||
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MINFILTER);
|
||||
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MAGFILTER);
|
||||
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MIPFILTER);
|
||||
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSU);
|
||||
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSV);
|
||||
STATEMANAGER.RestoreSamplerState(1, D3DSAMP_MINFILTER);
|
||||
STATEMANAGER.RestoreSamplerState(1, D3DSAMP_MAGFILTER);
|
||||
STATEMANAGER.RestoreSamplerState(1, D3DSAMP_MIPFILTER);
|
||||
STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSU);
|
||||
STATEMANAGER.RestoreSamplerState(1, D3DSAMP_ADDRESSV);
|
||||
}
|
||||
|
||||
void CGraphicShadowTexture::Initialize()
|
||||
|
||||
@@ -17,19 +17,19 @@ class CGraphicShadowTexture : public CGraphicTexture
|
||||
void Set(int stage = 0) const;
|
||||
|
||||
const D3DXMATRIX& GetLightVPMatrixReference() const;
|
||||
LPDIRECT3DTEXTURE8 GetD3DTexture() const;
|
||||
LPDIRECT3DTEXTURE9 GetD3DTexture() const;
|
||||
|
||||
protected:
|
||||
void Initialize();
|
||||
|
||||
protected:
|
||||
D3DXMATRIX m_d3dLightVPMatrix;
|
||||
D3DVIEWPORT8 m_d3dOldViewport;
|
||||
D3DVIEWPORT9 m_d3dOldViewport;
|
||||
|
||||
LPDIRECT3DTEXTURE8 m_lpd3dShadowTexture;
|
||||
LPDIRECT3DSURFACE8 m_lpd3dShadowSurface;
|
||||
LPDIRECT3DSURFACE8 m_lpd3dDepthSurface;
|
||||
LPDIRECT3DTEXTURE9 m_lpd3dShadowTexture;
|
||||
LPDIRECT3DSURFACE9 m_lpd3dShadowSurface;
|
||||
LPDIRECT3DSURFACE9 m_lpd3dDepthSurface;
|
||||
|
||||
LPDIRECT3DSURFACE8 m_lpd3dOldBackBufferSurface;
|
||||
LPDIRECT3DSURFACE8 m_lpd3dOldDepthBufferSurface;
|
||||
LPDIRECT3DSURFACE9 m_lpd3dOldBackBufferSurface;
|
||||
LPDIRECT3DSURFACE9 m_lpd3dOldDepthBufferSurface;
|
||||
};
|
||||
|
||||
@@ -539,7 +539,7 @@ void CGraphicTextInstance::Render(RECT * pClipRect)
|
||||
STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE);
|
||||
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE);
|
||||
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
|
||||
@@ -34,7 +34,7 @@ void CGraphicTexture::SetTextureStage(int stage) const
|
||||
STATEMANAGER.SetTexture(stage, m_lpd3dTexture);
|
||||
}
|
||||
|
||||
LPDIRECT3DTEXTURE8 CGraphicTexture::GetD3DTexture() const
|
||||
LPDIRECT3DTEXTURE9 CGraphicTexture::GetD3DTexture() const
|
||||
{
|
||||
return m_lpd3dTexture;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class CGraphicTexture : public CGraphicBase
|
||||
int GetHeight() const;
|
||||
|
||||
void SetTextureStage(int stage) const;
|
||||
LPDIRECT3DTEXTURE8 GetD3DTexture() const;
|
||||
LPDIRECT3DTEXTURE9 GetD3DTexture() const;
|
||||
|
||||
void DestroyDeviceObjects();
|
||||
|
||||
@@ -28,5 +28,5 @@ class CGraphicTexture : public CGraphicBase
|
||||
int m_width;
|
||||
int m_height;
|
||||
|
||||
LPDIRECT3DTEXTURE8 m_lpd3dTexture;
|
||||
LPDIRECT3DTEXTURE9 m_lpd3dTexture;
|
||||
};
|
||||
|
||||
@@ -31,7 +31,7 @@ bool CGraphicVertexBuffer::LockRange(unsigned count, void** pretVertices) const
|
||||
return false;
|
||||
|
||||
DWORD dwLockSize=GetVertexStride() * count;
|
||||
if (FAILED(m_lpd3dVB->Lock(0, dwLockSize, (BYTE **) pretVertices, m_dwLockFlag)))
|
||||
if (FAILED(m_lpd3dVB->Lock(0, dwLockSize, (void **) pretVertices, m_dwLockFlag)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -43,7 +43,7 @@ bool CGraphicVertexBuffer::Lock(void ** pretVertices) const
|
||||
return false;
|
||||
|
||||
DWORD dwLockSize=GetVertexStride()*GetVertexCount();
|
||||
if (FAILED(m_lpd3dVB->Lock(0, dwLockSize, (BYTE **) pretVertices, m_dwLockFlag)))
|
||||
if (FAILED(m_lpd3dVB->Lock(0, dwLockSize, (void **) pretVertices, m_dwLockFlag)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -72,7 +72,7 @@ bool CGraphicVertexBuffer::LockDynamic(void** pretVertices)
|
||||
if (!m_lpd3dVB)
|
||||
return false;
|
||||
|
||||
if (FAILED(m_lpd3dVB->Lock(0, 0, (BYTE**)pretVertices, 0)))
|
||||
if (FAILED(m_lpd3dVB->Lock(0, 0, (void**)pretVertices, 0)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -83,7 +83,7 @@ bool CGraphicVertexBuffer::Lock(void ** pretVertices)
|
||||
if (!m_lpd3dVB)
|
||||
return false;
|
||||
|
||||
if (FAILED(m_lpd3dVB->Lock(0, 0, (BYTE**)pretVertices, m_dwLockFlag)))
|
||||
if (FAILED(m_lpd3dVB->Lock(0, 0, (void**)pretVertices, m_dwLockFlag)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -123,7 +123,8 @@ bool CGraphicVertexBuffer::CreateDeviceObjects()
|
||||
m_dwUsage,
|
||||
m_dwFVF,
|
||||
m_d3dPool,
|
||||
&m_lpd3dVB)
|
||||
&m_lpd3dVB,
|
||||
nullptr)
|
||||
))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class CGraphicVertexBuffer : public CGraphicBase
|
||||
int GetVertexStride() const;
|
||||
DWORD GetFlexibleVertexFormat() const;
|
||||
|
||||
inline LPDIRECT3DVERTEXBUFFER8 GetD3DVertexBuffer() const { return m_lpd3dVB; }
|
||||
inline LPDIRECT3DVERTEXBUFFER9 GetD3DVertexBuffer() const { return m_lpd3dVB; }
|
||||
inline DWORD GetBufferSize() const { return m_dwBufferSize; }
|
||||
|
||||
bool IsEmpty() const;
|
||||
@@ -39,7 +39,7 @@ class CGraphicVertexBuffer : public CGraphicBase
|
||||
void Initialize();
|
||||
|
||||
protected:
|
||||
LPDIRECT3DVERTEXBUFFER8 m_lpd3dVB;
|
||||
LPDIRECT3DVERTEXBUFFER9 m_lpd3dVB;
|
||||
|
||||
DWORD m_dwBufferSize;
|
||||
DWORD m_dwFVF;
|
||||
|
||||
@@ -22,10 +22,8 @@ void CVertexShader::Destroy()
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
if (ms_lpd3dDevice)
|
||||
ms_lpd3dDevice->DeleteVertexShader(m_handle);
|
||||
|
||||
m_handle = 0;
|
||||
m_handle->Release();
|
||||
m_handle = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,14 +35,11 @@ bool CVertexShader::CreateFromDiskFile(const char* c_szFileName, const DWORD* c_
|
||||
LPD3DXBUFFER lpd3dxErrorBuffer;
|
||||
|
||||
if (FAILED(
|
||||
D3DXAssembleShaderFromFile(c_szFileName, 0, NULL, &lpd3dxShaderBuffer, &lpd3dxErrorBuffer)
|
||||
D3DXAssembleShaderFromFile(c_szFileName, 0, NULL, 0, &lpd3dxShaderBuffer, &lpd3dxErrorBuffer)
|
||||
)) return false;
|
||||
|
||||
CDirect3DXBuffer shaderBuffer(lpd3dxShaderBuffer);
|
||||
CDirect3DXBuffer errorBuffer(lpd3dxErrorBuffer);
|
||||
|
||||
if (FAILED(
|
||||
ms_lpd3dDevice->CreateVertexShader(c_pdwVertexDecl, (DWORD*)shaderBuffer.GetPointer(), &m_handle, 0 )
|
||||
ms_lpd3dDevice->CreateVertexShader((const DWORD*)lpd3dxShaderBuffer->GetBufferPointer(), &m_handle)
|
||||
))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -17,5 +17,5 @@ class CVertexShader : public CGraphicBase
|
||||
void Initialize();
|
||||
|
||||
protected:
|
||||
DWORD m_handle;
|
||||
LPDIRECT3DVERTEXSHADER9 m_handle;
|
||||
};
|
||||
|
||||
@@ -259,7 +259,7 @@ void CLensFlare::DrawBeforeFlare()
|
||||
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
|
||||
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(SVertex));
|
||||
|
||||
STATEMANAGER.RestoreRenderState(D3DRS_LIGHTING);
|
||||
@@ -445,7 +445,7 @@ void CLensFlare::AdjustBrightness()
|
||||
void CLensFlare::ReadDepthPixels(float * /*pPixels*/)
|
||||
{
|
||||
/*
|
||||
LPDIRECT3DSURFACE8 lpSurface;
|
||||
LPDIRECT3DSURFACE9 lpSurface;
|
||||
if (FAILED(ms_lpd3dDevice->GetDepthStencilSurface(&lpSurface)))
|
||||
assert(false);
|
||||
|
||||
@@ -540,7 +540,7 @@ void CFlare::Draw(float fBrightScale, int nWidth, int nHeight, int nX, int nY)
|
||||
float fDY = float(nY) - float(nHeight) / 2.0f;
|
||||
|
||||
STATEMANAGER.SetTexture(1, NULL);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
|
||||
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3dx8.h>
|
||||
#include <d3dx9.h>
|
||||
|
||||
class CRay
|
||||
{
|
||||
|
||||
@@ -820,7 +820,7 @@ void CSkyBox::Render()
|
||||
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
STATEMANAGER.SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
|
||||
|
||||
STATEMANAGER.SetTransform(D3DTS_WORLD, &m_matWorld);
|
||||
|
||||
@@ -828,8 +828,8 @@ void CSkyBox::Render()
|
||||
if( m_ucRenderMode == CSkyObject::SKY_RENDER_MODE_TEXTURE )
|
||||
{
|
||||
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
|
||||
STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
|
||||
STATEMANAGER.SaveSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
|
||||
|
||||
for (unsigned int i = 0; i < 6; ++i)
|
||||
{
|
||||
@@ -844,8 +844,8 @@ void CSkyBox::Render()
|
||||
|
||||
//STATEMANAGER.SetTexture( 0, NULL );
|
||||
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSU);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSV);
|
||||
STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSU);
|
||||
STATEMANAGER.RestoreSamplerState(0, D3DSAMP_ADDRESSV);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,37 +1,34 @@
|
||||
#include "StdAfx.h"
|
||||
#include "StateManager.h"
|
||||
#include "GrpLightManager.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];
|
||||
D3DLIGHT9 m_akD3DLight[8];
|
||||
} m_kLightData;
|
||||
|
||||
|
||||
|
||||
void CStateManager::SetLight(DWORD index, CONST D3DLIGHT8* pLight)
|
||||
void CStateManager::SetLight(DWORD index, CONST D3DLIGHT9* pLight)
|
||||
{
|
||||
assert(index<SLightData::LIGHT_NUM);
|
||||
m_kLightData.m_akD3DLight[index]=*pLight;
|
||||
assert(index < 8);
|
||||
m_kLightData.m_akD3DLight[index] = *pLight;
|
||||
|
||||
m_lpD3DDev->SetLight(index, pLight);
|
||||
}
|
||||
|
||||
void CStateManager::GetLight(DWORD index, D3DLIGHT8* pLight)
|
||||
void CStateManager::GetLight(DWORD index, D3DLIGHT9* pLight)
|
||||
{
|
||||
assert(index<8);
|
||||
*pLight=m_kLightData.m_akD3DLight[index];
|
||||
assert(index < 8);
|
||||
*pLight = m_kLightData.m_akD3DLight[index];
|
||||
}
|
||||
|
||||
bool CStateManager::BeginScene()
|
||||
{
|
||||
m_bScene=true;
|
||||
m_bScene = true;
|
||||
|
||||
D3DXMATRIX m4Proj;
|
||||
D3DXMATRIX m4View;
|
||||
@@ -51,15 +48,24 @@ bool CStateManager::BeginScene()
|
||||
void CStateManager::EndScene()
|
||||
{
|
||||
m_lpD3DDev->EndScene();
|
||||
m_bScene=false;
|
||||
m_bScene = false;
|
||||
}
|
||||
|
||||
CStateManager::CStateManager(LPDIRECT3DDEVICE8 lpDevice) : m_lpD3DDev(NULL)
|
||||
CStateManager::CStateManager(LPDIRECT3DDEVICE9 lpDevice) : m_lpD3DDev(NULL)
|
||||
{
|
||||
m_bScene = false;
|
||||
m_dwBestMinFilter = D3DTEXF_LINEAR;
|
||||
m_dwBestMagFilter = D3DTEXF_LINEAR;
|
||||
m_dwBestMinFilter = D3DTEXF_ANISOTROPIC;
|
||||
m_dwBestMagFilter = D3DTEXF_ANISOTROPIC;
|
||||
|
||||
for (int i = 0; i < STATEMANAGER_MAX_RENDERSTATES; i++)
|
||||
lpDevice->GetRenderState((D3DRENDERSTATETYPE)i, &gs_DefaultRenderStates[i]);
|
||||
|
||||
SetDevice(lpDevice);
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_iDrawCallCount = 0;
|
||||
m_iLastDrawCallCount = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
CStateManager::~CStateManager()
|
||||
@@ -71,7 +77,7 @@ CStateManager::~CStateManager()
|
||||
}
|
||||
}
|
||||
|
||||
void CStateManager::SetDevice(LPDIRECT3DDEVICE8 lpDevice)
|
||||
void CStateManager::SetDevice(LPDIRECT3DDEVICE9 lpDevice)
|
||||
{
|
||||
StateManager_Assert(lpDevice);
|
||||
lpDevice->AddRef();
|
||||
@@ -84,33 +90,14 @@ void CStateManager::SetDevice(LPDIRECT3DDEVICE8 lpDevice)
|
||||
|
||||
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);
|
||||
SetSamplerState(dwStage, D3DSAMP_MINFILTER, m_dwBestMinFilter);
|
||||
SetSamplerState(dwStage, D3DSAMP_MAGFILTER, m_dwBestMagFilter);
|
||||
SetSamplerState(dwStage, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
|
||||
}
|
||||
|
||||
void CStateManager::Restore()
|
||||
@@ -120,15 +107,24 @@ void CStateManager::Restore()
|
||||
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]);
|
||||
SetTextureStageState(i, D3DTEXTURESTAGESTATETYPE(j), m_CurrentState.m_SamplerStates[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < STATEMANAGER_MAX_STAGES; ++i)
|
||||
{
|
||||
SetTexture(i, m_CurrentState.m_Textures[i]);
|
||||
|
||||
}
|
||||
|
||||
m_bForce = false;
|
||||
}
|
||||
|
||||
@@ -141,15 +137,19 @@ void CStateManager::SetDefaultState()
|
||||
m_bScene = false;
|
||||
m_bForce = true;
|
||||
|
||||
D3DXMATRIX Identity;
|
||||
D3DXMatrixIdentity(&Identity);
|
||||
m_CurrentState_Copy = m_CurrentState;
|
||||
m_CopyState_Copy = m_CopyState;
|
||||
m_ChipState_Copy = m_ChipState;
|
||||
|
||||
SetTransform(D3DTS_WORLD, &Identity);
|
||||
SetTransform(D3DTS_VIEW, &Identity);
|
||||
SetTransform(D3DTS_PROJECTION, &Identity);
|
||||
D3DXMATRIX matIdentity;
|
||||
D3DXMatrixIdentity(&matIdentity);
|
||||
|
||||
D3DMATERIAL8 DefaultMat;
|
||||
ZeroMemory(&DefaultMat, sizeof(D3DMATERIAL8));
|
||||
SetTransform(D3DTS_WORLD, &matIdentity);
|
||||
SetTransform(D3DTS_VIEW, &matIdentity);
|
||||
SetTransform(D3DTS_PROJECTION, &matIdentity);
|
||||
|
||||
D3DMATERIAL9 DefaultMat;
|
||||
ZeroMemory(&DefaultMat, sizeof(D3DMATERIAL9));
|
||||
|
||||
DefaultMat.Diffuse.r = 1.0f;
|
||||
DefaultMat.Diffuse.g = 1.0f;
|
||||
@@ -176,25 +176,26 @@ void CStateManager::SetDefaultState()
|
||||
SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
|
||||
SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
|
||||
|
||||
SetRenderState(D3DRS_LINEPATTERN, 0xFFFFFFFF);
|
||||
SetRenderState(D3DRS_LASTPIXEL, FALSE);
|
||||
//SetRenderState(D3DRS_LINEPATTERN, 0xFFFFFFFF);
|
||||
SetRenderState(D3DRS_LASTPIXEL, TRUE);
|
||||
SetRenderState(D3DRS_ALPHAREF, 1);
|
||||
SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
|
||||
SetRenderState(D3DRS_ZVISIBLE, FALSE);
|
||||
//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_EDGEANTIALIAS, TRUE);
|
||||
//SetRenderState(D3DRS_ZBIAS, 0);
|
||||
SetRenderState(D3DRS_STENCILWRITEMASK, 0xFFFFFFFF);
|
||||
SetRenderState(D3DRS_AMBIENT, 0x00000000);
|
||||
SetRenderState(D3DRS_LOCALVIEWER, FALSE);
|
||||
SetRenderState(D3DRS_LOCALVIEWER, TRUE);
|
||||
SetRenderState(D3DRS_NORMALIZENORMALS, FALSE);
|
||||
SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_DISABLE);
|
||||
SetRenderState(D3DRS_CLIPPLANEENABLE, 0);
|
||||
SetRenderState(D3DRS_SOFTWAREVERTEXPROCESSING, FALSE);
|
||||
SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE);
|
||||
SaveVertexProcessing(FALSE);
|
||||
SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
|
||||
SetRenderState(D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF);
|
||||
SetRenderState(D3DRS_PATCHEDGESTYLE, D3DPATCHEDGE_CONTINUOUS);
|
||||
SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
|
||||
SetRenderState(D3DRS_COLORWRITEENABLE, 0xFFFFFFFF);
|
||||
SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
|
||||
@@ -206,7 +207,7 @@ void CStateManager::SetDefaultState()
|
||||
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||
SetRenderState(D3DRS_FOGENABLE, FALSE);
|
||||
SetRenderState(D3DRS_FOGCOLOR, 0xFF000000);
|
||||
SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_NONE);
|
||||
SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
|
||||
SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
|
||||
SetRenderState(D3DRS_RANGEFOGENABLE, FALSE);
|
||||
SetRenderState(D3DRS_ZENABLE, TRUE);
|
||||
@@ -293,54 +294,54 @@ void CStateManager::SetDefaultState()
|
||||
SetTextureStageState(6, D3DTSS_TEXCOORDINDEX, 6);
|
||||
SetTextureStageState(7, D3DTSS_TEXCOORDINDEX, 7);
|
||||
|
||||
SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
|
||||
|
||||
SetTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(1, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
|
||||
|
||||
SetTextureStageState(2, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(2, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(2, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(2, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
|
||||
|
||||
SetTextureStageState(3, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(3, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(3, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(3, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(3, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
|
||||
|
||||
SetTextureStageState(4, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(4, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(4, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(4, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(4, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(4, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
|
||||
|
||||
SetTextureStageState(5, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(5, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(5, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(5, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(5, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(5, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
|
||||
|
||||
SetTextureStageState(6, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(6, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(6, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(6, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(6, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(6, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
|
||||
|
||||
SetTextureStageState(7, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(7, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetTextureStageState(7, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(7, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(7, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||
SetSamplerState(7, D3DSAMP_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);
|
||||
SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(2, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(2, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(3, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(3, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(4, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(4, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(5, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(5, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(6, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(6, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(7, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
|
||||
SetSamplerState(7, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
|
||||
|
||||
SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, 0);
|
||||
SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, 0);
|
||||
@@ -361,7 +362,7 @@ void CStateManager::SetDefaultState()
|
||||
SetTexture(7, NULL);
|
||||
|
||||
SetPixelShader(0);
|
||||
SetVertexShader(D3DFVF_XYZ);
|
||||
SetFVF(D3DFVF_XYZ);
|
||||
|
||||
D3DXVECTOR4 av4Null[STATEMANAGER_MAX_VCONSTANTS];
|
||||
memset(av4Null, 0, sizeof(av4Null));
|
||||
@@ -373,14 +374,23 @@ void CStateManager::SetDefaultState()
|
||||
#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;
|
||||
m_bSamplerStateSavingFlag[j][i] = FALSE;
|
||||
}
|
||||
}
|
||||
#endif _DEBUG
|
||||
}
|
||||
|
||||
@@ -390,7 +400,7 @@ void CStateManager::SaveMaterial()
|
||||
m_CopyState.m_D3DMaterial = m_CurrentState.m_D3DMaterial;
|
||||
}
|
||||
|
||||
void CStateManager::SaveMaterial(const D3DMATERIAL8 * pMaterial)
|
||||
void CStateManager::SaveMaterial(const D3DMATERIAL9* pMaterial)
|
||||
{
|
||||
// Check that we have set this up before, if not, the default is this.
|
||||
m_CopyState.m_D3DMaterial = m_CurrentState.m_D3DMaterial;
|
||||
@@ -402,13 +412,13 @@ void CStateManager::RestoreMaterial()
|
||||
SetMaterial(&m_CopyState.m_D3DMaterial);
|
||||
}
|
||||
|
||||
void CStateManager::SetMaterial(const D3DMATERIAL8 * pMaterial)
|
||||
void CStateManager::SetMaterial(const D3DMATERIAL9* pMaterial)
|
||||
{
|
||||
m_lpD3DDev->SetMaterial(pMaterial);
|
||||
m_CurrentState.m_D3DMaterial = *pMaterial;
|
||||
}
|
||||
|
||||
void CStateManager::GetMaterial(D3DMATERIAL8 * pMaterial)
|
||||
void CStateManager::GetMaterial(D3DMATERIAL9* pMaterial)
|
||||
{
|
||||
// Set the renderstate and remember it.
|
||||
*pMaterial = m_CurrentState.m_D3DMaterial;
|
||||
@@ -420,6 +430,27 @@ DWORD CStateManager::GetRenderState(D3DRENDERSTATETYPE Type)
|
||||
return m_CurrentState.m_RenderStates[Type];
|
||||
}
|
||||
|
||||
void CStateManager::StateManager_Capture()
|
||||
{
|
||||
m_CurrentState_Copy = m_CurrentState;
|
||||
m_CopyState_Copy = m_CopyState;
|
||||
m_ChipState_Copy = m_ChipState;
|
||||
m_DirtyStates_Copy = m_DirtyStates;
|
||||
}
|
||||
|
||||
void CStateManager::StateManager_Apply()
|
||||
{
|
||||
m_CurrentState = m_CurrentState_Copy;
|
||||
m_CopyState = m_CopyState_Copy;
|
||||
m_ChipState = m_ChipState_Copy;
|
||||
m_DirtyStates = m_DirtyStates_Copy;
|
||||
}
|
||||
|
||||
LPDIRECT3DDEVICE9 CStateManager::GetDevice()
|
||||
{
|
||||
return m_lpD3DDev;
|
||||
}
|
||||
|
||||
void CStateManager::SaveRenderState(D3DRENDERSTATETYPE Type, DWORD dwValue)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
@@ -459,13 +490,13 @@ void CStateManager::SetRenderState(D3DRENDERSTATETYPE Type, DWORD Value)
|
||||
m_CurrentState.m_RenderStates[Type] = Value;
|
||||
}
|
||||
|
||||
void CStateManager::GetRenderState(D3DRENDERSTATETYPE Type, DWORD * pdwValue)
|
||||
void CStateManager::GetRenderState(D3DRENDERSTATETYPE Type, DWORD* pdwValue)
|
||||
{
|
||||
*pdwValue = m_CurrentState.m_RenderStates[Type];
|
||||
}
|
||||
|
||||
// Textures
|
||||
void CStateManager::SaveTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture)
|
||||
void CStateManager::SaveTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9 pTexture)
|
||||
{
|
||||
// Check that we have set this up before, if not, the default is this.
|
||||
m_CopyState.m_Textures[dwStage] = m_CurrentState.m_Textures[dwStage];
|
||||
@@ -477,7 +508,7 @@ void CStateManager::RestoreTexture(DWORD dwStage)
|
||||
SetTexture(dwStage, m_CopyState.m_Textures[dwStage]);
|
||||
}
|
||||
|
||||
void CStateManager::SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture)
|
||||
void CStateManager::SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9 pTexture)
|
||||
{
|
||||
if (pTexture == m_CurrentState.m_Textures[dwStage])
|
||||
return;
|
||||
@@ -486,13 +517,13 @@ void CStateManager::SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture)
|
||||
m_CurrentState.m_Textures[dwStage] = pTexture;
|
||||
}
|
||||
|
||||
void CStateManager::GetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 * ppTexture)
|
||||
void CStateManager::GetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9* ppTexture)
|
||||
{
|
||||
*ppTexture = m_CurrentState.m_Textures[dwStage];
|
||||
}
|
||||
|
||||
// Texture stage states
|
||||
void CStateManager::SaveTextureStageState(DWORD dwStage,D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue)
|
||||
void CStateManager::SaveTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue)
|
||||
{
|
||||
// Check that we have set this up before, if not, the default is this.
|
||||
#ifdef _DEBUG
|
||||
@@ -529,13 +560,51 @@ void CStateManager::SetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE
|
||||
m_CurrentState.m_TextureStates[dwStage][Type] = dwValue;
|
||||
}
|
||||
|
||||
void CStateManager::GetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD * pdwValue)
|
||||
void CStateManager::GetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pdwValue)
|
||||
{
|
||||
*pdwValue = m_CurrentState.m_TextureStates[dwStage][Type];
|
||||
}
|
||||
|
||||
// Sampler states
|
||||
void CStateManager::SaveSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD dwValue)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (m_bSamplerStateSavingFlag[dwStage][Type])
|
||||
{
|
||||
Tracenf(" CStateManager::SaveTextureStageState - This texture stage state is already saved [%d, %d]\n", dwStage, Type);
|
||||
StateManager_Assert(!" This texture stage state is already saved!");
|
||||
}
|
||||
m_bSamplerStateSavingFlag[dwStage][Type] = TRUE;
|
||||
#endif _DEBUG
|
||||
m_CopyState.m_SamplerStates[dwStage][Type] = m_CurrentState.m_SamplerStates[dwStage][Type];
|
||||
SetSamplerState(dwStage, Type, dwValue);
|
||||
}
|
||||
void CStateManager::RestoreSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (!m_bSamplerStateSavingFlag[dwStage][Type])
|
||||
{
|
||||
Tracenf(" CStateManager::RestoreTextureStageState - This texture stage state was not saved [%d, %d]\n", dwStage, Type);
|
||||
StateManager_Assert(!" This texture stage state was not saved!");
|
||||
}
|
||||
m_bSamplerStateSavingFlag[dwStage][Type] = FALSE;
|
||||
#endif _DEBUG
|
||||
SetSamplerState(dwStage, Type, m_CopyState.m_SamplerStates[dwStage][Type]);
|
||||
}
|
||||
void CStateManager::SetSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD dwValue)
|
||||
{
|
||||
if (m_CurrentState.m_SamplerStates[dwStage][Type] == dwValue)
|
||||
return;
|
||||
m_lpD3DDev->SetSamplerState(dwStage, Type, dwValue);
|
||||
m_CurrentState.m_SamplerStates[dwStage][Type] = dwValue;
|
||||
}
|
||||
void CStateManager::GetSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD* pdwValue)
|
||||
{
|
||||
*pdwValue = m_CurrentState.m_SamplerStates[dwStage][Type];
|
||||
}
|
||||
|
||||
// Vertex Shader
|
||||
void CStateManager::SaveVertexShader(DWORD dwShader)
|
||||
void CStateManager::SaveVertexShader(LPDIRECT3DVERTEXSHADER9 dwShader)
|
||||
{
|
||||
m_CopyState.m_dwVertexShader = m_CurrentState.m_dwVertexShader;
|
||||
SetVertexShader(dwShader);
|
||||
@@ -546,7 +615,7 @@ void CStateManager::RestoreVertexShader()
|
||||
SetVertexShader(m_CopyState.m_dwVertexShader);
|
||||
}
|
||||
|
||||
void CStateManager::SetVertexShader(DWORD dwShader)
|
||||
void CStateManager::SetVertexShader(LPDIRECT3DVERTEXSHADER9 dwShader)
|
||||
{
|
||||
if (m_CurrentState.m_dwVertexShader == dwShader)
|
||||
return;
|
||||
@@ -555,13 +624,71 @@ void CStateManager::SetVertexShader(DWORD dwShader)
|
||||
m_CurrentState.m_dwVertexShader = dwShader;
|
||||
}
|
||||
|
||||
void CStateManager::GetVertexShader(DWORD * pdwShader)
|
||||
void CStateManager::GetVertexShader(LPDIRECT3DVERTEXSHADER9* pdwShader)
|
||||
{
|
||||
*pdwShader = m_CurrentState.m_dwVertexShader;
|
||||
}
|
||||
|
||||
// Vertex Processing
|
||||
void CStateManager::SaveVertexProcessing(BOOL IsON)
|
||||
{
|
||||
if (m_CurrentState.m_bVertexProcessing = IsON)
|
||||
return;
|
||||
m_CopyState.m_bVertexProcessing = m_CurrentState.m_bVertexProcessing;
|
||||
m_lpD3DDev->SetSoftwareVertexProcessing(IsON);
|
||||
m_CurrentState.m_bVertexProcessing = IsON;
|
||||
}
|
||||
void CStateManager::RestoreVertexProcessing()
|
||||
{
|
||||
if (m_CopyState.m_bVertexProcessing = m_CurrentState.m_bVertexProcessing)
|
||||
return;
|
||||
m_lpD3DDev->SetSoftwareVertexProcessing(m_CopyState.m_bVertexProcessing);
|
||||
}
|
||||
// Vertex Declaration
|
||||
void CStateManager::SaveVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 dwShader)
|
||||
{
|
||||
m_CopyState.m_dwVertexDeclaration = m_CurrentState.m_dwVertexDeclaration;
|
||||
SetVertexDeclaration(dwShader);
|
||||
}
|
||||
void CStateManager::RestoreVertexDeclaration()
|
||||
{
|
||||
SetVertexDeclaration(m_CopyState.m_dwVertexDeclaration);
|
||||
}
|
||||
void CStateManager::SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 dwShader)
|
||||
{
|
||||
//if (m_CurrentState.m_dwVertexDeclaration == dwShader)
|
||||
// return;
|
||||
m_lpD3DDev->SetVertexDeclaration(dwShader);
|
||||
m_CurrentState.m_dwVertexDeclaration = dwShader;
|
||||
}
|
||||
void CStateManager::GetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9* pdwShader)
|
||||
{
|
||||
*pdwShader = m_CurrentState.m_dwVertexDeclaration;
|
||||
}
|
||||
// FVF
|
||||
void CStateManager::SaveFVF(DWORD dwShader)
|
||||
{
|
||||
m_CopyState.m_dwFVF = m_CurrentState.m_dwFVF;
|
||||
SetFVF(dwShader);
|
||||
}
|
||||
void CStateManager::RestoreFVF()
|
||||
{
|
||||
SetFVF(m_CopyState.m_dwFVF);
|
||||
}
|
||||
void CStateManager::SetFVF(DWORD dwShader)
|
||||
{
|
||||
//if (m_CurrentState.m_dwFVF == dwShader)
|
||||
// return;
|
||||
m_lpD3DDev->SetFVF(dwShader);
|
||||
m_CurrentState.m_dwFVF = dwShader;
|
||||
}
|
||||
void CStateManager::GetFVF(DWORD* pdwShader)
|
||||
{
|
||||
*pdwShader = m_CurrentState.m_dwFVF;
|
||||
}
|
||||
|
||||
// Pixel Shader
|
||||
void CStateManager::SavePixelShader(DWORD dwShader)
|
||||
void CStateManager::SavePixelShader(LPDIRECT3DPIXELSHADER9 dwShader)
|
||||
{
|
||||
m_CopyState.m_dwPixelShader = m_CurrentState.m_dwPixelShader;
|
||||
SetPixelShader(dwShader);
|
||||
@@ -572,7 +699,7 @@ void CStateManager::RestorePixelShader()
|
||||
SetPixelShader(m_CopyState.m_dwPixelShader);
|
||||
}
|
||||
|
||||
void CStateManager::SetPixelShader(DWORD dwShader)
|
||||
void CStateManager::SetPixelShader(LPDIRECT3DPIXELSHADER9 dwShader)
|
||||
{
|
||||
if (m_CurrentState.m_dwPixelShader == dwShader)
|
||||
return;
|
||||
@@ -581,14 +708,14 @@ void CStateManager::SetPixelShader(DWORD dwShader)
|
||||
m_CurrentState.m_dwPixelShader = dwShader;
|
||||
}
|
||||
|
||||
void CStateManager::GetPixelShader(DWORD * pdwShader)
|
||||
void CStateManager::GetPixelShader(LPDIRECT3DPIXELSHADER9* 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)
|
||||
void CStateManager::SaveTransform(D3DTRANSFORMSTATETYPE Type, const D3DXMATRIX* pMatrix)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (m_bTransformSavingFlag[Type])
|
||||
@@ -600,7 +727,7 @@ void CStateManager::SaveTransform(D3DTRANSFORMSTATETYPE Type, const D3DMATRIX* p
|
||||
#endif _DEBUG
|
||||
|
||||
m_CopyState.m_Matrices[Type] = m_CurrentState.m_Matrices[Type];
|
||||
SetTransform(Type, (D3DXMATRIX *)pMatrix);
|
||||
SetTransform(Type, pMatrix);
|
||||
}
|
||||
|
||||
void CStateManager::RestoreTransform(D3DTRANSFORMSTATETYPE Type)
|
||||
@@ -618,7 +745,7 @@ void CStateManager::RestoreTransform(D3DTRANSFORMSTATETYPE Type)
|
||||
}
|
||||
|
||||
// Don't cache-check the transform. To much to do
|
||||
void CStateManager::SetTransform(D3DTRANSFORMSTATETYPE Type, const D3DMATRIX* pMatrix)
|
||||
void CStateManager::SetTransform(D3DTRANSFORMSTATETYPE Type, const D3DXMATRIX* pMatrix)
|
||||
{
|
||||
if (m_bScene)
|
||||
{
|
||||
@@ -626,19 +753,19 @@ void CStateManager::SetTransform(D3DTRANSFORMSTATETYPE Type, const D3DMATRIX* pM
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(D3DTS_VIEW==Type || D3DTS_PROJECTION==Type || D3DTS_WORLD==Type);
|
||||
assert(D3DTS_VIEW == Type || D3DTS_PROJECTION == Type || D3DTS_WORLD == Type);
|
||||
}
|
||||
|
||||
m_CurrentState.m_Matrices[Type] = *pMatrix;
|
||||
}
|
||||
|
||||
void CStateManager::GetTransform(D3DTRANSFORMSTATETYPE Type, D3DMATRIX * pMatrix)
|
||||
void CStateManager::GetTransform(D3DTRANSFORMSTATETYPE Type, D3DXMATRIX* pMatrix)
|
||||
{
|
||||
*pMatrix = m_CurrentState.m_Matrices[Type];
|
||||
}
|
||||
|
||||
// SetVertexShaderConstant
|
||||
void CStateManager::SaveVertexShaderConstant(DWORD dwRegister,CONST void* pConstantData,DWORD dwConstantCount)
|
||||
void CStateManager::SaveVertexShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount)
|
||||
{
|
||||
DWORD i;
|
||||
|
||||
@@ -656,9 +783,9 @@ void CStateManager::RestoreVertexShaderConstant(DWORD dwRegister, DWORD dwConsta
|
||||
SetVertexShaderConstant(dwRegister, &m_CopyState.m_VertexShaderConstants[dwRegister], dwConstantCount);
|
||||
}
|
||||
|
||||
void CStateManager::SetVertexShaderConstant(DWORD dwRegister,CONST void* pConstantData,DWORD dwConstantCount)
|
||||
void CStateManager::SetVertexShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount)
|
||||
{
|
||||
m_lpD3DDev->SetVertexShaderConstant(dwRegister, pConstantData, dwConstantCount);
|
||||
m_lpD3DDev->SetVertexShaderConstantF(dwRegister, (const float*)pConstantData, dwConstantCount);
|
||||
|
||||
// Set the renderstate and remember it.
|
||||
for (DWORD i = 0; i < dwConstantCount; i++)
|
||||
@@ -669,7 +796,7 @@ void CStateManager::SetVertexShaderConstant(DWORD dwRegister,CONST void* pConsta
|
||||
}
|
||||
|
||||
// SetPixelShaderConstant
|
||||
void CStateManager::SavePixelShaderConstant(DWORD dwRegister,CONST void* pConstantData,DWORD dwConstantCount)
|
||||
void CStateManager::SavePixelShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount)
|
||||
{
|
||||
DWORD i;
|
||||
|
||||
@@ -687,9 +814,9 @@ void CStateManager::RestorePixelShaderConstant(DWORD dwRegister, DWORD dwConstan
|
||||
SetPixelShaderConstant(dwRegister, &m_CopyState.m_PixelShaderConstants[dwRegister], dwConstantCount);
|
||||
}
|
||||
|
||||
void CStateManager::SetPixelShaderConstant(DWORD dwRegister,CONST void* pConstantData,DWORD dwConstantCount)
|
||||
void CStateManager::SetPixelShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount)
|
||||
{
|
||||
m_lpD3DDev->SetPixelShaderConstant(dwRegister, pConstantData, dwConstantCount);
|
||||
m_lpD3DDev->SetVertexShaderConstantF(dwRegister, (const float*)pConstantData, dwConstantCount);
|
||||
|
||||
// Set the renderstate and remember it.
|
||||
for (DWORD i = 0; i < dwConstantCount; i++)
|
||||
@@ -699,7 +826,7 @@ void CStateManager::SetPixelShaderConstant(DWORD dwRegister,CONST void* pConstan
|
||||
}
|
||||
}
|
||||
|
||||
void CStateManager::SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData,UINT Stride)
|
||||
void CStateManager::SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER9 pStreamData, UINT Stride)
|
||||
{
|
||||
// Check that we have set this up before, if not, the default is this.
|
||||
m_CopyState.m_StreamData[StreamNumber] = m_CurrentState.m_StreamData[StreamNumber];
|
||||
@@ -708,22 +835,22 @@ void CStateManager::SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8
|
||||
|
||||
void CStateManager::RestoreStreamSource(UINT StreamNumber)
|
||||
{
|
||||
SetStreamSource(StreamNumber,
|
||||
m_CopyState.m_StreamData[StreamNumber].m_lpStreamData,
|
||||
m_CopyState.m_StreamData[StreamNumber].m_Stride);
|
||||
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)
|
||||
void CStateManager::SetStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER9 pStreamData, UINT Stride)
|
||||
{
|
||||
CStreamData kStreamData(pStreamData, Stride);
|
||||
if (m_CurrentState.m_StreamData[StreamNumber] == kStreamData)
|
||||
return;
|
||||
return;
|
||||
|
||||
m_lpD3DDev->SetStreamSource(StreamNumber, pStreamData, Stride);
|
||||
m_lpD3DDev->SetStreamSource(StreamNumber, pStreamData, 0, Stride);
|
||||
m_CurrentState.m_StreamData[StreamNumber] = kStreamData;
|
||||
}
|
||||
|
||||
void CStateManager::SaveIndices(LPDIRECT3DINDEXBUFFER8 pIndexData, UINT BaseVertexIndex)
|
||||
void CStateManager::SaveIndices(LPDIRECT3DINDEXBUFFER9 pIndexData, UINT BaseVertexIndex)
|
||||
{
|
||||
m_CopyState.m_IndexData = m_CurrentState.m_IndexData;
|
||||
SetIndices(pIndexData, BaseVertexIndex);
|
||||
@@ -734,36 +861,65 @@ void CStateManager::RestoreIndices()
|
||||
SetIndices(m_CopyState.m_IndexData.m_lpIndexData, m_CopyState.m_IndexData.m_BaseVertexIndex);
|
||||
}
|
||||
|
||||
void CStateManager::SetIndices(LPDIRECT3DINDEXBUFFER8 pIndexData, UINT BaseVertexIndex)
|
||||
void CStateManager::SetIndices(LPDIRECT3DINDEXBUFFER9 pIndexData, UINT BaseVertexIndex)
|
||||
{
|
||||
CIndexData kIndexData(pIndexData, BaseVertexIndex);
|
||||
|
||||
if (m_CurrentState.m_IndexData == kIndexData)
|
||||
return;
|
||||
|
||||
m_lpD3DDev->SetIndices(pIndexData, BaseVertexIndex);
|
||||
|
||||
m_lpD3DDev->SetIndices(pIndexData);
|
||||
m_CurrentState.m_IndexData = kIndexData;
|
||||
}
|
||||
|
||||
HRESULT CStateManager::DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
++m_iDrawCallCount;
|
||||
#endif
|
||||
|
||||
return (m_lpD3DDev->DrawPrimitive(PrimitiveType, StartVertex, PrimitiveCount));
|
||||
}
|
||||
|
||||
HRESULT CStateManager::DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
++m_iDrawCallCount;
|
||||
#endif
|
||||
|
||||
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));
|
||||
#ifdef _DEBUG
|
||||
++m_iDrawCallCount;
|
||||
#endif
|
||||
|
||||
return (m_lpD3DDev->DrawIndexedPrimitive(PrimitiveType, minIndex, 0, NumVertices, startIndex, primCount));
|
||||
}
|
||||
|
||||
HRESULT CStateManager::DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, CONST void * pIndexData, D3DFORMAT IndexDataFormat, CONST void * pVertexStreamZeroData, UINT VertexStreamZeroStride)
|
||||
HRESULT CStateManager::DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData, D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
++m_iDrawCallCount;
|
||||
#endif
|
||||
|
||||
m_CurrentState.m_IndexData = NULL;
|
||||
m_CurrentState.m_StreamData[0] = NULL;
|
||||
return (m_lpD3DDev->DrawIndexedPrimitiveUP(PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride));
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
void CStateManager::ResetDrawCallCounter()
|
||||
{
|
||||
m_iLastDrawCallCount = m_iDrawCallCount;
|
||||
m_iDrawCallCount = 0;
|
||||
}
|
||||
|
||||
int CStateManager::GetDrawCallCount() const
|
||||
{
|
||||
return m_iLastDrawCallCount;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
kind. NVIDIA makes no guarantee of its fitness for a particular purpose and is
|
||||
not liable under any circumstances for any damages or loss whatsoever arising
|
||||
from the use or inability to use this file or items derived from it.
|
||||
|
||||
Comments:
|
||||
|
||||
A simple class to manage rendering state. Created as a singleton.
|
||||
Create it as a static global, or with new. It doesn't matter as long as it is created
|
||||
|
||||
Comments:
|
||||
|
||||
A simple class to manage rendering state. Created as a singleton.
|
||||
Create it as a static global, or with new. It doesn't matter as long as it is created
|
||||
before you use the CStateManager::GetSingleton() API to get a reference to it.
|
||||
|
||||
Call it with STATEMANAGER.SetRenderState(...)
|
||||
@@ -22,7 +22,7 @@
|
||||
There are two levels of caching:
|
||||
- All Sets/Saves/Restores are tracked for redundancy. This reduces the size of the batch to
|
||||
be flushed
|
||||
- The flush function is called before rendering, and only copies state that is
|
||||
- The flush function is called before rendering, and only copies state that is
|
||||
different from the current chip state.
|
||||
|
||||
If you get an assert it is probably because an API call failed.
|
||||
@@ -35,14 +35,14 @@
|
||||
The state manager holds a reference to the d3d device.
|
||||
|
||||
- cmaughan@nvidia.com
|
||||
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CSTATEMANAGER_H
|
||||
#define __CSTATEMANAGER_H
|
||||
|
||||
#include <d3d8.h>
|
||||
#include <d3dx8.h>
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -64,38 +64,40 @@ static const DWORD STATEMANAGER_MAX_PCONSTANTS = 8;
|
||||
static const DWORD STATEMANAGER_MAX_TRANSFORMSTATES = 300; // World1 lives way up there...
|
||||
static const DWORD STATEMANAGER_MAX_STREAMS = 16;
|
||||
|
||||
static DWORD gs_DefaultRenderStates[STATEMANAGER_MAX_RENDERSTATES];
|
||||
|
||||
class CStreamData
|
||||
{
|
||||
public:
|
||||
CStreamData(LPDIRECT3DVERTEXBUFFER8 pStreamData = NULL, UINT Stride = 0) : m_lpStreamData(pStreamData), m_Stride(Stride)
|
||||
{
|
||||
}
|
||||
public:
|
||||
CStreamData(LPDIRECT3DVERTEXBUFFER9 pStreamData = NULL, UINT Stride = 0) : m_lpStreamData(pStreamData), m_Stride(Stride)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator == (const CStreamData& rhs) const
|
||||
{
|
||||
return ((m_lpStreamData == rhs.m_lpStreamData) && (m_Stride == rhs.m_Stride));
|
||||
}
|
||||
bool operator == (const CStreamData& rhs) const
|
||||
{
|
||||
return ((m_lpStreamData == rhs.m_lpStreamData) && (m_Stride == rhs.m_Stride));
|
||||
}
|
||||
|
||||
LPDIRECT3DVERTEXBUFFER8 m_lpStreamData;
|
||||
UINT m_Stride;
|
||||
LPDIRECT3DVERTEXBUFFER9 m_lpStreamData;
|
||||
UINT m_Stride;
|
||||
};
|
||||
|
||||
class CIndexData
|
||||
{
|
||||
public:
|
||||
CIndexData(LPDIRECT3DINDEXBUFFER8 pIndexData = NULL, UINT BaseVertexIndex = 0)
|
||||
: m_lpIndexData(pIndexData),
|
||||
public:
|
||||
CIndexData(LPDIRECT3DINDEXBUFFER9 pIndexData = NULL, UINT BaseVertexIndex = 0)
|
||||
: m_lpIndexData(pIndexData),
|
||||
m_BaseVertexIndex(BaseVertexIndex)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
bool operator == (const CIndexData& rhs) const
|
||||
{
|
||||
return ((m_lpIndexData == rhs.m_lpIndexData) && (m_BaseVertexIndex == rhs.m_BaseVertexIndex));
|
||||
}
|
||||
bool operator == (const CIndexData& rhs) const
|
||||
{
|
||||
return ((m_lpIndexData == rhs.m_lpIndexData) && (m_BaseVertexIndex == rhs.m_BaseVertexIndex));
|
||||
}
|
||||
|
||||
LPDIRECT3DINDEXBUFFER8 m_lpIndexData;
|
||||
UINT m_BaseVertexIndex;
|
||||
LPDIRECT3DINDEXBUFFER9 m_lpIndexData;
|
||||
UINT m_BaseVertexIndex;
|
||||
};
|
||||
|
||||
// State types managed by the class
|
||||
@@ -116,223 +118,271 @@ typedef enum eStateType
|
||||
|
||||
class CStateID
|
||||
{
|
||||
public:
|
||||
CStateID(eStateType Type, DWORD dwValue0 = 0, DWORD dwValue1 = 0)
|
||||
: m_Type(Type),
|
||||
public:
|
||||
CStateID(eStateType Type, DWORD dwValue0 = 0, DWORD dwValue1 = 0)
|
||||
: m_Type(Type),
|
||||
m_dwValue0(dwValue0),
|
||||
m_dwValue1(dwValue1)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
CStateID(eStateType Type, DWORD dwStage, D3DTEXTURESTAGESTATETYPE StageType)
|
||||
: m_Type(Type),
|
||||
CStateID(eStateType Type, DWORD dwStage, D3DTEXTURESTAGESTATETYPE StageType)
|
||||
: m_Type(Type),
|
||||
m_dwStage(dwStage),
|
||||
m_TextureStageStateType(StageType)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
CStateID(eStateType Type, D3DRENDERSTATETYPE RenderType)
|
||||
: m_Type(Type),
|
||||
CStateID(eStateType Type, D3DRENDERSTATETYPE RenderType)
|
||||
: m_Type(Type),
|
||||
m_RenderStateType(RenderType)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
eStateType m_Type;
|
||||
eStateType m_Type;
|
||||
|
||||
union
|
||||
{
|
||||
DWORD m_dwValue0;
|
||||
DWORD m_dwStage;
|
||||
D3DRENDERSTATETYPE m_RenderStateType;
|
||||
D3DTRANSFORMSTATETYPE m_TransformStateType;
|
||||
};
|
||||
union
|
||||
{
|
||||
DWORD m_dwValue0;
|
||||
DWORD m_dwStage;
|
||||
D3DRENDERSTATETYPE m_RenderStateType;
|
||||
D3DTRANSFORMSTATETYPE m_TransformStateType;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
DWORD m_dwValue1;
|
||||
D3DTEXTURESTAGESTATETYPE m_TextureStageStateType;
|
||||
};
|
||||
union
|
||||
{
|
||||
DWORD m_dwValue1;
|
||||
D3DTEXTURESTAGESTATETYPE m_TextureStageStateType;
|
||||
};
|
||||
};
|
||||
|
||||
typedef std::vector<CStateID> TStateID;
|
||||
|
||||
class CStateManagerState
|
||||
{
|
||||
public:
|
||||
CStateManagerState()
|
||||
{
|
||||
}
|
||||
public:
|
||||
CStateManagerState()
|
||||
{
|
||||
}
|
||||
|
||||
void ResetState()
|
||||
{
|
||||
DWORD i, y;
|
||||
void ResetState()
|
||||
{
|
||||
DWORD i, y;
|
||||
|
||||
for (i = 0; i < STATEMANAGER_MAX_RENDERSTATES; i++)
|
||||
m_RenderStates[i] = 0x7FFFFFFF;
|
||||
for (i = 0; i < STATEMANAGER_MAX_RENDERSTATES; i++)
|
||||
m_RenderStates[i] = gs_DefaultRenderStates[i];
|
||||
|
||||
for (i = 0; i < STATEMANAGER_MAX_STAGES; i++)
|
||||
for (y = 0; y < STATEMANAGER_MAX_TEXTURESTATES; y++)
|
||||
m_TextureStates[i][y] = 0x7FFFFFFF;
|
||||
for (i = 0; i < STATEMANAGER_MAX_STAGES; i++)
|
||||
for (y = 0; y < STATEMANAGER_MAX_TEXTURESTATES; y++)
|
||||
m_TextureStates[i][y] = 0x7FFFFFFF;
|
||||
|
||||
for (i = 0; i < STATEMANAGER_MAX_STREAMS; i++)
|
||||
m_StreamData[i] = CStreamData();
|
||||
for (i = 0; i < STATEMANAGER_MAX_STREAMS; i++)
|
||||
m_StreamData[i] = CStreamData();
|
||||
|
||||
m_IndexData = CIndexData();
|
||||
m_IndexData = CIndexData();
|
||||
|
||||
for (i = 0; i < STATEMANAGER_MAX_STAGES; i++)
|
||||
m_Textures[i] = NULL;
|
||||
for (i = 0; i < STATEMANAGER_MAX_STAGES; i++)
|
||||
m_Textures[i] = NULL;
|
||||
|
||||
// Matrices and constants are not cached, just restored. It's silly to check all the
|
||||
// data elements (by which time the driver could have been sent them).
|
||||
for (i = 0; i < STATEMANAGER_MAX_TRANSFORMSTATES; i++)
|
||||
D3DXMatrixIdentity(&m_Matrices[i]);
|
||||
// Matrices and constants are not cached, just restored. It's silly to check all the
|
||||
// data elements (by which time the driver could have been sent them).
|
||||
for (i = 0; i < STATEMANAGER_MAX_TRANSFORMSTATES; i++)
|
||||
D3DXMatrixIdentity(&m_Matrices[i]);
|
||||
|
||||
for (i = 0; i < STATEMANAGER_MAX_VCONSTANTS; i++)
|
||||
m_VertexShaderConstants[i] = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
for (i = 0; i < STATEMANAGER_MAX_VCONSTANTS; i++)
|
||||
m_VertexShaderConstants[i] = D3DXVECTOR4(0, 0, 0, 0);
|
||||
|
||||
for (i = 0; i < STATEMANAGER_MAX_PCONSTANTS; i++)
|
||||
m_PixelShaderConstants[i] = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
for (i = 0; i < STATEMANAGER_MAX_PCONSTANTS; i++)
|
||||
m_PixelShaderConstants[i] = D3DXVECTOR4(0, 0, 0, 0);
|
||||
|
||||
m_dwPixelShader = 0;
|
||||
m_dwVertexShader = D3DFVF_XYZ;
|
||||
m_dwPixelShader = 0;
|
||||
m_dwVertexShader = 0;
|
||||
m_dwVertexDeclaration = 0;
|
||||
m_dwFVF = D3DFVF_XYZ;
|
||||
m_bVertexProcessing = FALSE;
|
||||
}
|
||||
|
||||
ZeroMemory(&m_Matrices, sizeof(D3DXMATRIX) * STATEMANAGER_MAX_TRANSFORMSTATES);
|
||||
}
|
||||
// Renderstates
|
||||
DWORD m_RenderStates[STATEMANAGER_MAX_RENDERSTATES];
|
||||
|
||||
// Renderstates
|
||||
DWORD m_RenderStates[STATEMANAGER_MAX_RENDERSTATES];
|
||||
// Texture stage states
|
||||
DWORD m_TextureStates[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_TEXTURESTATES];
|
||||
DWORD m_SamplerStates[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_TEXTURESTATES];
|
||||
|
||||
// Texture stage states
|
||||
DWORD m_TextureStates[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_TEXTURESTATES];
|
||||
// Vertex shader constants
|
||||
D3DXVECTOR4 m_VertexShaderConstants[STATEMANAGER_MAX_VCONSTANTS];
|
||||
|
||||
// Vertex shader constants
|
||||
D3DXVECTOR4 m_VertexShaderConstants[STATEMANAGER_MAX_VCONSTANTS];
|
||||
// Pixel shader constants
|
||||
D3DXVECTOR4 m_PixelShaderConstants[STATEMANAGER_MAX_PCONSTANTS];
|
||||
|
||||
// Pixel shader constants
|
||||
D3DXVECTOR4 m_PixelShaderConstants[STATEMANAGER_MAX_PCONSTANTS];
|
||||
// Textures
|
||||
LPDIRECT3DBASETEXTURE9 m_Textures[STATEMANAGER_MAX_STAGES];
|
||||
|
||||
// Textures
|
||||
LPDIRECT3DBASETEXTURE8 m_Textures[STATEMANAGER_MAX_STAGES];
|
||||
// Shaders
|
||||
LPDIRECT3DPIXELSHADER9 m_dwPixelShader;
|
||||
LPDIRECT3DVERTEXSHADER9 m_dwVertexShader;
|
||||
LPDIRECT3DVERTEXDECLARATION9 m_dwVertexDeclaration;
|
||||
DWORD m_dwFVF;
|
||||
|
||||
// Shaders
|
||||
DWORD m_dwPixelShader;
|
||||
DWORD m_dwVertexShader;
|
||||
D3DXMATRIX m_Matrices[STATEMANAGER_MAX_TRANSFORMSTATES];
|
||||
|
||||
D3DXMATRIX m_Matrices[STATEMANAGER_MAX_TRANSFORMSTATES];
|
||||
D3DMATERIAL9 m_D3DMaterial;
|
||||
|
||||
D3DMATERIAL8 m_D3DMaterial;
|
||||
CStreamData m_StreamData[STATEMANAGER_MAX_STREAMS];
|
||||
CIndexData m_IndexData;
|
||||
|
||||
CStreamData m_StreamData[STATEMANAGER_MAX_STREAMS];
|
||||
CIndexData m_IndexData;
|
||||
BOOL m_bVertexProcessing;
|
||||
};
|
||||
|
||||
class CStateManager : public CSingleton<CStateManager>
|
||||
{
|
||||
public:
|
||||
CStateManager(LPDIRECT3DDEVICE8 lpDevice);
|
||||
virtual ~CStateManager();
|
||||
public:
|
||||
CStateManager(LPDIRECT3DDEVICE9 lpDevice);
|
||||
virtual ~CStateManager();
|
||||
|
||||
void SetDefaultState();
|
||||
void Restore();
|
||||
void SetDefaultState();
|
||||
void Restore();
|
||||
|
||||
bool BeginScene();
|
||||
void EndScene();
|
||||
|
||||
// Material
|
||||
void SaveMaterial();
|
||||
void SaveMaterial(const D3DMATERIAL8 * pMaterial);
|
||||
void RestoreMaterial();
|
||||
void SetMaterial(const D3DMATERIAL8 * pMaterial);
|
||||
void GetMaterial(D3DMATERIAL8 * pMaterial);
|
||||
bool BeginScene();
|
||||
void EndScene();
|
||||
|
||||
void SetLight(DWORD index, CONST D3DLIGHT8* pLight);
|
||||
void GetLight(DWORD index, D3DLIGHT8* pLight);
|
||||
// Material
|
||||
void SaveMaterial();
|
||||
void SaveMaterial(const D3DMATERIAL9* pMaterial);
|
||||
void RestoreMaterial();
|
||||
void SetMaterial(const D3DMATERIAL9* pMaterial);
|
||||
void GetMaterial(D3DMATERIAL9* pMaterial);
|
||||
|
||||
// Renderstates
|
||||
void SaveRenderState(D3DRENDERSTATETYPE Type, DWORD dwValue);
|
||||
void RestoreRenderState(D3DRENDERSTATETYPE Type);
|
||||
void SetRenderState(D3DRENDERSTATETYPE Type, DWORD Value);
|
||||
void GetRenderState(D3DRENDERSTATETYPE Type, DWORD * pdwValue);
|
||||
void SetLight(DWORD index, CONST D3DLIGHT9* pLight);
|
||||
void GetLight(DWORD index, D3DLIGHT9* pLight);
|
||||
|
||||
// Textures
|
||||
void SaveTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture);
|
||||
void RestoreTexture(DWORD dwStage);
|
||||
void SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 pTexture);
|
||||
void GetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE8 * ppTexture);
|
||||
// Renderstates
|
||||
void SaveRenderState(D3DRENDERSTATETYPE Type, DWORD dwValue);
|
||||
void RestoreRenderState(D3DRENDERSTATETYPE Type);
|
||||
void SetRenderState(D3DRENDERSTATETYPE Type, DWORD Value);
|
||||
void GetRenderState(D3DRENDERSTATETYPE Type, DWORD* pdwValue);
|
||||
|
||||
// Texture stage states
|
||||
void SaveTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue);
|
||||
void RestoreTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type);
|
||||
void SetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue);
|
||||
void GetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD * pdwValue);
|
||||
void SetBestFiltering(DWORD dwStage); // if possible set anisotropy filtering, or use trilinear
|
||||
// Textures
|
||||
void SaveTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9 pTexture);
|
||||
void RestoreTexture(DWORD dwStage);
|
||||
void SetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9 pTexture);
|
||||
void GetTexture(DWORD dwStage, LPDIRECT3DBASETEXTURE9* ppTexture);
|
||||
|
||||
// Vertex Shader
|
||||
void SaveVertexShader(DWORD dwShader);
|
||||
void RestoreVertexShader();
|
||||
void SetVertexShader(DWORD dwShader);
|
||||
void GetVertexShader(DWORD * pdwShader);
|
||||
// Texture stage states
|
||||
void SaveTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue);
|
||||
void RestoreTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type);
|
||||
void SetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD dwValue);
|
||||
void GetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pdwValue);
|
||||
void SetBestFiltering(DWORD dwStage); // if possible set anisotropy filtering, or use trilinear
|
||||
|
||||
// Pixel Shader
|
||||
void SavePixelShader(DWORD dwShader);
|
||||
void RestorePixelShader();
|
||||
void SetPixelShader(DWORD dwShader);
|
||||
void GetPixelShader(DWORD * pdwShader);
|
||||
// Sampler states
|
||||
void SaveSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD dwValue);
|
||||
void RestoreSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type);
|
||||
void SetSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD dwValue);
|
||||
void GetSamplerState(DWORD dwStage, D3DSAMPLERSTATETYPE Type, DWORD* pdwValue);
|
||||
|
||||
// *** These states are cached, but not protected from multiple sends of the same value.
|
||||
// Transform
|
||||
void SaveTransform(D3DTRANSFORMSTATETYPE Transform, const D3DMATRIX* pMatrix);
|
||||
void RestoreTransform(D3DTRANSFORMSTATETYPE Transform);
|
||||
// Vertex Shader
|
||||
void SaveVertexShader(LPDIRECT3DVERTEXSHADER9 dwShader);
|
||||
void RestoreVertexShader();
|
||||
void SetVertexShader(LPDIRECT3DVERTEXSHADER9 dwShader);
|
||||
void GetVertexShader(LPDIRECT3DVERTEXSHADER9* pdwShader);
|
||||
|
||||
// Don't cache-check the transform. To much to do
|
||||
void SetTransform(D3DTRANSFORMSTATETYPE Type, const D3DMATRIX* pMatrix);
|
||||
void GetTransform(D3DTRANSFORMSTATETYPE Type, D3DMATRIX * pMatrix);
|
||||
// Vertex Declaration
|
||||
void SaveVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 dwShader);
|
||||
void RestoreVertexDeclaration();
|
||||
void SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 dwShader);
|
||||
void GetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9* pdwShader);
|
||||
|
||||
// SetVertexShaderConstant
|
||||
void SaveVertexShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
|
||||
void RestoreVertexShaderConstant(DWORD dwRegister, DWORD dwConstantCount);
|
||||
void SetVertexShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
|
||||
// FVF
|
||||
void SaveFVF(DWORD dwShader);
|
||||
void RestoreFVF();
|
||||
void SetFVF(DWORD dwShader);
|
||||
void GetFVF(DWORD* pdwShader);
|
||||
|
||||
// SetPixelShaderConstant
|
||||
void SavePixelShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
|
||||
void RestorePixelShaderConstant(DWORD dwRegister, DWORD dwConstantCount);
|
||||
void SetPixelShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
|
||||
// Pixel Shader
|
||||
void SavePixelShader(LPDIRECT3DPIXELSHADER9 dwShader);
|
||||
void RestorePixelShader();
|
||||
void SetPixelShader(LPDIRECT3DPIXELSHADER9 dwShader);
|
||||
void GetPixelShader(LPDIRECT3DPIXELSHADER9* pdwShader);
|
||||
|
||||
void SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData, UINT Stride);
|
||||
void RestoreStreamSource(UINT StreamNumber);
|
||||
void SetStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER8 pStreamData, UINT Stride);
|
||||
// *** These states are cached, but not protected from multiple sends of the same value.
|
||||
// Transform
|
||||
void SaveTransform(D3DTRANSFORMSTATETYPE Transform, const D3DXMATRIX* pMatrix);
|
||||
void RestoreTransform(D3DTRANSFORMSTATETYPE Transform);
|
||||
|
||||
void SaveIndices(LPDIRECT3DINDEXBUFFER8 pIndexData, UINT BaseVertexIndex);
|
||||
void RestoreIndices();
|
||||
void SetIndices(LPDIRECT3DINDEXBUFFER8 pIndexData,UINT BaseVertexIndex);
|
||||
|
||||
HRESULT DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
|
||||
HRESULT DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
|
||||
HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT minIndex, UINT NumVertices, UINT startIndex, UINT primCount);
|
||||
HRESULT DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, CONST void * pIndexData, D3DFORMAT IndexDataFormat, CONST void * pVertexStreamZeroData, UINT VertexStreamZeroStride);
|
||||
// VertexProcessing
|
||||
void SaveVertexProcessing(BOOL IsON);
|
||||
void RestoreVertexProcessing();
|
||||
|
||||
// Codes For Debug
|
||||
DWORD GetRenderState(D3DRENDERSTATETYPE Type);
|
||||
// Don't cache-check the transform. To much to do
|
||||
void SetTransform(D3DTRANSFORMSTATETYPE Type, const D3DXMATRIX* pMatrix);
|
||||
void GetTransform(D3DTRANSFORMSTATETYPE Type, D3DXMATRIX* pMatrix);
|
||||
|
||||
private:
|
||||
void SetDevice(LPDIRECT3DDEVICE8 lpDevice);
|
||||
// SetVertexShaderConstant
|
||||
void SaveVertexShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
|
||||
void RestoreVertexShaderConstant(DWORD dwRegister, DWORD dwConstantCount);
|
||||
void SetVertexShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
|
||||
|
||||
private:
|
||||
CStateManagerState m_ChipState;
|
||||
CStateManagerState m_CurrentState;
|
||||
CStateManagerState m_CopyState;
|
||||
TStateID m_DirtyStates;
|
||||
bool m_bForce;
|
||||
bool m_bScene;
|
||||
DWORD m_dwBestMinFilter;
|
||||
DWORD m_dwBestMagFilter;
|
||||
LPDIRECT3DDEVICE8 m_lpD3DDev;
|
||||
// SetPixelShaderConstant
|
||||
void SavePixelShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
|
||||
void RestorePixelShaderConstant(DWORD dwRegister, DWORD dwConstantCount);
|
||||
void SetPixelShaderConstant(DWORD dwRegister, CONST void* pConstantData, DWORD dwConstantCount);
|
||||
|
||||
void SaveStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER9 pStreamData, UINT Stride);
|
||||
void RestoreStreamSource(UINT StreamNumber);
|
||||
void SetStreamSource(UINT StreamNumber, LPDIRECT3DVERTEXBUFFER9 pStreamData, UINT Stride);
|
||||
|
||||
void SaveIndices(LPDIRECT3DINDEXBUFFER9 pIndexData, UINT BaseVertexIndex);
|
||||
void RestoreIndices();
|
||||
void SetIndices(LPDIRECT3DINDEXBUFFER9 pIndexData, UINT BaseVertexIndex);
|
||||
|
||||
HRESULT DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
|
||||
HRESULT DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
|
||||
HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType, UINT minIndex, UINT NumVertices, UINT startIndex, UINT primCount);
|
||||
HRESULT DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData, D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
|
||||
|
||||
// Codes For Debug
|
||||
DWORD GetRenderState(D3DRENDERSTATETYPE Type);
|
||||
|
||||
void StateManager_Capture();
|
||||
void StateManager_Apply();
|
||||
|
||||
LPDIRECT3DDEVICE9 GetDevice();
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Saving Flag
|
||||
BOOL m_bRenderStateSavingFlag[STATEMANAGER_MAX_RENDERSTATES];
|
||||
BOOL m_bTextureStageStateSavingFlag[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_TEXTURESTATES];
|
||||
BOOL m_bTransformSavingFlag[STATEMANAGER_MAX_TRANSFORMSTATES];
|
||||
void ResetDrawCallCounter();
|
||||
int GetDrawCallCount() const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
void SetDevice(LPDIRECT3DDEVICE9 lpDevice);
|
||||
|
||||
private:
|
||||
CStateManagerState m_ChipState;
|
||||
CStateManagerState m_CurrentState;
|
||||
CStateManagerState m_CopyState;
|
||||
TStateID m_DirtyStates;
|
||||
|
||||
bool m_bForce;
|
||||
bool m_bScene;
|
||||
DWORD m_dwBestMinFilter;
|
||||
DWORD m_dwBestMagFilter;
|
||||
LPDIRECT3DDEVICE9 m_lpD3DDev;
|
||||
|
||||
CStateManagerState m_ChipState_Copy;
|
||||
CStateManagerState m_CurrentState_Copy;
|
||||
CStateManagerState m_CopyState_Copy;
|
||||
TStateID m_DirtyStates_Copy;
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Saving Flag
|
||||
BOOL m_bRenderStateSavingFlag[STATEMANAGER_MAX_RENDERSTATES];
|
||||
BOOL m_bTextureStageStateSavingFlag[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_TEXTURESTATES];
|
||||
BOOL m_bSamplerStateSavingFlag[STATEMANAGER_MAX_STAGES][STATEMANAGER_MAX_TEXTURESTATES];
|
||||
BOOL m_bTransformSavingFlag[STATEMANAGER_MAX_TRANSFORMSTATES];
|
||||
|
||||
int m_iDrawCallCount;
|
||||
int m_iLastDrawCallCount;
|
||||
#endif _DEBUG
|
||||
};
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#pragma warning(disable:4201 4512 4238 4239)
|
||||
#endif
|
||||
|
||||
#include <d3d8.h>
|
||||
#include <d3dx8.h>
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9.h>
|
||||
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
|
||||
@@ -37,13 +37,9 @@
|
||||
#include <direct.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
#pragma comment(lib, "d3d8.lib")
|
||||
#pragma comment(lib, "d3dx8.lib")
|
||||
|
||||
#include "../eterBase/StdAfx.h"
|
||||
#include "../eterBase/Debug.h"
|
||||
#include "../eterLocale/CodePageId.h"
|
||||
#include "EterBase/StdAfx.h"
|
||||
#include "EterBase/Debug.h"
|
||||
#include "EterLocale/CodePageId.h"
|
||||
|
||||
#ifndef VC_EXTRALEAN
|
||||
#include <winsock.h>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <d3dx8.h>
|
||||
#include <d3dx9.h>
|
||||
|
||||
template<typename T>
|
||||
class CTransitor
|
||||
|
||||
Reference in New Issue
Block a user