port: GrpDevice verbatim 40250 (Create over the recording device, declaration vertex shaders -> stream-0 FVF)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b5d413afa6
commit
65c43a84cd
+436
-180
@@ -1,25 +1,22 @@
|
||||
// 40250 EterLib/GrpDevice.cpp over the platform's recording device (RecordingDevice.h): there is no
|
||||
// Direct3D object, adapter detection or window; Create makes the device, CStateManager, the matrix
|
||||
// stack and the default buffers as 40250 does. The remaining MT_PLATFORM_STUB() bodies (device reset,
|
||||
// web-browser mode, driver warnings) have no platform counterpart yet.
|
||||
// 40250 EterLib/GrpDevice.cpp, verbatim but for CGraphicDevice::Create, which makes the recording device
|
||||
// (RecordingDevice.h) in place of the Direct3D object, adapter detection and CreateDevice.
|
||||
#include "EterLib/StdAfx.h"
|
||||
#include "EterLib/GrpDevice.h"
|
||||
#include "EterLib/StateManager.h"
|
||||
#include "EterBase/Stl.h"
|
||||
#include "EterBase/Debug.h"
|
||||
|
||||
#include "CpuBuffer.h"
|
||||
#include "RecordingDevice.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "../PlatformStub.h"
|
||||
|
||||
bool GRAPHICS_CAPS_CAN_NOT_DRAW_LINE = false;
|
||||
bool GRAPHICS_CAPS_CAN_NOT_DRAW_SHADOW = false;
|
||||
bool GRAPHICS_CAPS_HALF_SIZE_IMAGE = false;
|
||||
bool GRAPHICS_CAPS_CAN_NOT_TEXTURE_ADDRESS_BORDER = false;
|
||||
bool GRAPHICS_CAPS_SOFTWARE_TILING = false;
|
||||
|
||||
D3DPRESENT_PARAMETERS g_kD3DPP;
|
||||
bool g_isBrowserMode=false;
|
||||
RECT g_rcBrowser;
|
||||
|
||||
CGraphicDevice::CGraphicDevice()
|
||||
: m_uBackBufferCount(0)
|
||||
{
|
||||
@@ -31,31 +28,325 @@ CGraphicDevice::~CGraphicDevice()
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void CGraphicDevice::InitBackBufferCount(UINT uBackBufferCount)
|
||||
void CGraphicDevice::__Initialize()
|
||||
{
|
||||
m_uBackBufferCount=uBackBufferCount;
|
||||
ms_iD3DAdapterInfo=D3DADAPTER_DEFAULT;
|
||||
ms_iD3DDevInfo=D3DADAPTER_DEFAULT;
|
||||
ms_iD3DModeInfo=D3DADAPTER_DEFAULT;
|
||||
|
||||
ms_lpd3d = NULL;
|
||||
ms_lpd3dDevice = NULL;
|
||||
ms_lpd3dMatStack = NULL;
|
||||
|
||||
ms_dwWavingEndTime = 0;
|
||||
ms_dwFlashingEndTime = 0;
|
||||
|
||||
m_pStateManager = NULL;
|
||||
|
||||
__InitializeDefaultIndexBufferList();
|
||||
__InitializePDTVertexBufferList();
|
||||
}
|
||||
|
||||
void CGraphicDevice::Destroy()
|
||||
void CGraphicDevice::RegisterWarningString(UINT uiMsg, const char * c_szString)
|
||||
{
|
||||
__DestroyPDTVertexBufferList();
|
||||
__DestroyDefaultIndexBufferList();
|
||||
m_kMap_strWarningMessage[uiMsg] = c_szString;
|
||||
}
|
||||
|
||||
// PORT: no DC, vertex shader objects or D3DX meshes; the stream "shaders" are FVF codes.
|
||||
ms_ptVS = 0;
|
||||
ms_pntVS = 0;
|
||||
ms_pnt2VS = 0;
|
||||
void CGraphicDevice::__WarningMessage(HWND hWnd, UINT uiMsg)
|
||||
{
|
||||
if (m_kMap_strWarningMessage.end() == m_kMap_strWarningMessage.find(uiMsg))
|
||||
return;
|
||||
MessageBox(hWnd, m_kMap_strWarningMessage[uiMsg].c_str(), "Warning", MB_OK|MB_TOPMOST);
|
||||
}
|
||||
|
||||
safe_release(ms_lpd3dMatStack);
|
||||
safe_release(ms_lpd3dDevice);
|
||||
void CGraphicDevice::MoveWebBrowserRect(const RECT& c_rcWebPage)
|
||||
{
|
||||
g_rcBrowser=c_rcWebPage;
|
||||
}
|
||||
|
||||
if (m_pStateManager)
|
||||
void CGraphicDevice::EnableWebBrowserMode(const RECT& c_rcWebPage)
|
||||
{
|
||||
if (!ms_lpd3dDevice)
|
||||
return;
|
||||
|
||||
D3DPRESENT_PARAMETERS& rkD3DPP=ms_d3dPresentParameter;
|
||||
|
||||
g_isBrowserMode=true;
|
||||
|
||||
if (D3DSWAPEFFECT_COPY==rkD3DPP.SwapEffect)
|
||||
return;
|
||||
|
||||
g_kD3DPP=rkD3DPP;
|
||||
g_rcBrowser=c_rcWebPage;
|
||||
|
||||
//rkD3DPP.Windowed=TRUE;
|
||||
rkD3DPP.SwapEffect=D3DSWAPEFFECT_COPY;
|
||||
rkD3DPP.BackBufferCount = 1;
|
||||
rkD3DPP.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
|
||||
IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice;
|
||||
HRESULT hr=rkD3DDev.Reset(&rkD3DPP);
|
||||
if (FAILED(hr))
|
||||
return;
|
||||
|
||||
STATEMANAGER.SetDefaultState();
|
||||
}
|
||||
|
||||
void CGraphicDevice::DisableWebBrowserMode()
|
||||
{
|
||||
if (!ms_lpd3dDevice)
|
||||
return;
|
||||
|
||||
D3DPRESENT_PARAMETERS& rkD3DPP=ms_d3dPresentParameter;
|
||||
|
||||
g_isBrowserMode=false;
|
||||
|
||||
rkD3DPP=g_kD3DPP;
|
||||
|
||||
IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice;
|
||||
HRESULT hr=rkD3DDev.Reset(&rkD3DPP);
|
||||
if (FAILED(hr))
|
||||
return;
|
||||
|
||||
STATEMANAGER.SetDefaultState();
|
||||
}
|
||||
|
||||
bool CGraphicDevice::ResizeBackBuffer(UINT uWidth, UINT uHeight)
|
||||
{
|
||||
if (!ms_lpd3dDevice)
|
||||
return false;
|
||||
|
||||
D3DPRESENT_PARAMETERS& rkD3DPP=ms_d3dPresentParameter;
|
||||
if (rkD3DPP.Windowed)
|
||||
{
|
||||
delete m_pStateManager;
|
||||
m_pStateManager = NULL;
|
||||
if (rkD3DPP.BackBufferWidth!=uWidth || rkD3DPP.BackBufferHeight!=uHeight)
|
||||
{
|
||||
rkD3DPP.BackBufferWidth=uWidth;
|
||||
rkD3DPP.BackBufferHeight=uHeight;
|
||||
|
||||
IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice;
|
||||
|
||||
HRESULT hr=rkD3DDev.Reset(&rkD3DPP);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
STATEMANAGER.SetDefaultState();
|
||||
}
|
||||
}
|
||||
|
||||
__Initialize();
|
||||
return true;
|
||||
}
|
||||
|
||||
DWORD CGraphicDevice::CreatePNTStreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
|
||||
DWORD declVector[] =
|
||||
{
|
||||
D3DVSD_STREAM(0),
|
||||
D3DVSD_REG(0, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(3, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(7, D3DVSDT_FLOAT2),
|
||||
D3DVSD_END()
|
||||
};
|
||||
|
||||
DWORD ret;
|
||||
|
||||
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
|
||||
return 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
DWORD CGraphicDevice::CreatePNT2StreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
|
||||
DWORD declVector[] =
|
||||
{
|
||||
D3DVSD_STREAM(0),
|
||||
D3DVSD_REG(0, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(3, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(7, D3DVSDT_FLOAT2),
|
||||
D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2),
|
||||
// D3DVSD_STREAM(1),
|
||||
D3DVSD_END()
|
||||
};
|
||||
|
||||
DWORD ret;
|
||||
|
||||
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
|
||||
return 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
DWORD CGraphicDevice::CreatePTStreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
|
||||
DWORD declVector[] =
|
||||
{
|
||||
D3DVSD_STREAM(0),
|
||||
D3DVSD_REG(0, D3DVSDT_FLOAT3),
|
||||
D3DVSD_STREAM(1),
|
||||
D3DVSD_REG(7, D3DVSDT_FLOAT2),
|
||||
D3DVSD_END()
|
||||
};
|
||||
|
||||
DWORD ret;
|
||||
|
||||
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
|
||||
return 0;
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
DWORD CGraphicDevice::CreateDoublePNTStreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
|
||||
DWORD declVector[] =
|
||||
{
|
||||
D3DVSD_STREAM(0),
|
||||
D3DVSD_REG(0, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(3, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(7, D3DVSDT_FLOAT2),
|
||||
D3DVSD_STREAM(1),
|
||||
D3DVSD_REG(D3DVSDE_POSITION2, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(D3DVSDE_NORMAL2, D3DVSDT_FLOAT3),
|
||||
D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2),
|
||||
D3DVSD_END()
|
||||
};
|
||||
|
||||
DWORD ret;
|
||||
|
||||
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
|
||||
return 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CGraphicDevice::EDeviceState CGraphicDevice::GetDeviceState()
|
||||
{
|
||||
if (!ms_lpd3dDevice)
|
||||
return DEVICESTATE_NULL;
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
if (FAILED(hr = ms_lpd3dDevice->TestCooperativeLevel()))
|
||||
{
|
||||
if (D3DERR_DEVICELOST == hr)
|
||||
return DEVICESTATE_BROKEN;
|
||||
|
||||
if (D3DERR_DEVICENOTRESET == hr)
|
||||
return DEVICESTATE_NEEDS_RESET;
|
||||
|
||||
return DEVICESTATE_BROKEN;
|
||||
}
|
||||
|
||||
return DEVICESTATE_OK;
|
||||
}
|
||||
|
||||
bool CGraphicDevice::Reset()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
if (FAILED(hr = ms_lpd3dDevice->Reset(&ms_d3dPresentParameter)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static LPDIRECT3DSURFACE8 s_lpStencil;
|
||||
static DWORD s_MaxTextureWidth, s_MaxTextureHeight;
|
||||
|
||||
BOOL EL3D_ConfirmDevice(D3DCAPS8& rkD3DCaps, UINT uBehavior, D3DFORMAT /*eD3DFmt*/)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
s_MaxTextureWidth = rkD3DCaps.MaxTextureWidth;
|
||||
s_MaxTextureHeight = rkD3DCaps.MaxTextureHeight;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
DWORD GetMaxTextureWidth()
|
||||
{
|
||||
return s_MaxTextureWidth;
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -67,14 +358,29 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /
|
||||
ms_iWidth = iHres;
|
||||
ms_iHeight = iVres;
|
||||
|
||||
// PORT: in place of Direct3DCreate8, the display-mode detection and CreateDevice: the recording
|
||||
// device renders through Godot, which supports DXT and has no refresh-rate or T&L failures.
|
||||
ms_hWnd = hWnd;
|
||||
// PORT: in place of GetDC, Direct3DCreate8, the D3D_CDisplayModeAutoDetector adapter/mode search, the
|
||||
// driver black list, CreateDevice with its refresh-rate retry, the DXT format checks and the full-screen
|
||||
// SetWindowPos: the recording device (RecordingDevice.h) renders through the host, which owns the window
|
||||
// and supports DXT and hardware T&L at any refresh rate.
|
||||
ms_lpd3dDevice = MtCreateRecordingDevice(iHres, iVres);
|
||||
|
||||
ZeroMemory(&ms_d3dPresentParameter, sizeof(ms_d3dPresentParameter));
|
||||
|
||||
ms_d3dPresentParameter.Windowed = Windowed;
|
||||
ms_d3dPresentParameter.BackBufferWidth = iHres;
|
||||
ms_d3dPresentParameter.BackBufferHeight = iVres;
|
||||
ms_d3dPresentParameter.hDeviceWindow = hWnd;
|
||||
ms_d3dPresentParameter.BackBufferCount = m_uBackBufferCount;
|
||||
ms_d3dPresentParameter.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
|
||||
if (!Windowed)
|
||||
ms_d3dPresentParameter.FullScreen_RefreshRateInHz = iReflashRate;
|
||||
|
||||
ms_d3dPresentParameter.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
|
||||
ms_d3dPresentParameter.EnableAutoDepthStencil = TRUE;
|
||||
|
||||
ms_dwD3DBehavior = D3DCREATE_HARDWARE_VERTEXPROCESSING;
|
||||
ms_d3dPresentParameter.BackBufferWidth = iHres;
|
||||
ms_d3dPresentParameter.BackBufferHeight = iVres;
|
||||
ms_d3dPresentParameter.Windowed = Windowed;
|
||||
|
||||
if (FAILED((ms_hLastResult = ms_lpd3dDevice->GetDeviceCaps(&ms_d3dCaps))))
|
||||
{
|
||||
@@ -82,6 +388,10 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /
|
||||
return CREATE_GET_DEVICE_CAPS2;
|
||||
}
|
||||
|
||||
// PORT: the detector runs EL3D_ConfirmDevice on each device's caps; here on the one device (max texture size).
|
||||
if (!EL3D_ConfirmDevice(ms_d3dCaps, ms_dwD3DBehavior, ms_d3dPresentParameter.BackBufferFormat))
|
||||
return CREATE_DETECT;
|
||||
|
||||
ms_lpd3dDevice->GetViewport(&ms_Viewport);
|
||||
|
||||
m_pStateManager = new CStateManager(ms_lpd3dDevice);
|
||||
@@ -98,8 +408,6 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /
|
||||
D3DXMatrixIdentity(&ms_matProj);
|
||||
D3DXMatrixIdentity(&ms_matInverseView);
|
||||
D3DXMatrixIdentity(&ms_matInverseViewYAxis);
|
||||
D3DXMatrixIdentity(&ms_matWorld);
|
||||
D3DXMatrixIdentity(&ms_matWorldView);
|
||||
D3DXMatrixIdentity(&ms_matScreen0);
|
||||
D3DXMatrixIdentity(&ms_matScreen1);
|
||||
D3DXMatrixIdentity(&ms_matScreen2);
|
||||
@@ -112,8 +420,10 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /
|
||||
|
||||
ms_matScreen2._11 = (float) iHres / 2;
|
||||
ms_matScreen2._22 = (float) iVres / 2;
|
||||
|
||||
// PORT: no D3DXCreateSphere/D3DXCreateCylinder; ms_lpSphereMesh/ms_lpCylinderMesh stay NULL (debug collision rendering).
|
||||
|
||||
// PORT: no D3DXCreateSphere/D3DXCreateCylinder (debug collision rendering) and no Clear.
|
||||
ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
|
||||
|
||||
if (!__CreateDefaultIndexBufferList())
|
||||
return false;
|
||||
@@ -138,81 +448,46 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /
|
||||
else
|
||||
GRAPHICS_CAPS_CAN_NOT_TEXTURE_ADDRESS_BORDER=true;
|
||||
|
||||
// PORT: the SIS/3dfx driver checks have no adapter identifier to test.
|
||||
// PORT: the SIS/3dfx driver caps have no adapter identifier to test.
|
||||
|
||||
return (iRet);
|
||||
}
|
||||
|
||||
auto CGraphicDevice::GetDeviceState() -> EDeviceState
|
||||
void CGraphicDevice::__InitializePDTVertexBufferList()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<EDeviceState>();
|
||||
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
|
||||
ms_alpd3dPDTVB[i]=NULL;
|
||||
}
|
||||
|
||||
void CGraphicDevice::__DestroyPDTVertexBufferList()
|
||||
{
|
||||
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
|
||||
{
|
||||
if (ms_alpd3dPDTVB[i])
|
||||
{
|
||||
ms_alpd3dPDTVB[i]->Release();
|
||||
ms_alpd3dPDTVB[i]=NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto CGraphicDevice::Reset() -> bool
|
||||
bool CGraphicDevice::__CreatePDTVertexBufferList()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CGraphicDevice::EnableWebBrowserMode(const RECT &) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CGraphicDevice::DisableWebBrowserMode() -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CGraphicDevice::MoveWebBrowserRect(const RECT &) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CGraphicDevice::ResizeBackBuffer(UINT uWidth, UINT uHeight) -> bool
|
||||
{
|
||||
ms_iWidth = uWidth;
|
||||
ms_iHeight = uHeight;
|
||||
ms_d3dPresentParameter.BackBufferWidth = uWidth;
|
||||
ms_d3dPresentParameter.BackBufferHeight = uHeight;
|
||||
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
|
||||
{
|
||||
if (FAILED(
|
||||
ms_lpd3dDevice->CreateVertexBuffer(
|
||||
sizeof(TPDTVertex)*PDT_VERTEX_NUM,
|
||||
D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
|
||||
D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1,
|
||||
D3DPOOL_SYSTEMMEM,
|
||||
&ms_alpd3dPDTVB[i])
|
||||
))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::RegisterWarningString(UINT, const char *) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
void CGraphicDevice::__Initialize()
|
||||
{
|
||||
ms_iD3DAdapterInfo=D3DADAPTER_DEFAULT;
|
||||
ms_iD3DDevInfo=D3DADAPTER_DEFAULT;
|
||||
ms_iD3DModeInfo=D3DADAPTER_DEFAULT;
|
||||
|
||||
ms_lpd3d = NULL;
|
||||
ms_lpd3dDevice = NULL;
|
||||
ms_lpd3dMatStack = NULL;
|
||||
|
||||
ms_dwWavingEndTime = 0;
|
||||
ms_dwFlashingEndTime = 0;
|
||||
|
||||
m_pStateManager = NULL;
|
||||
|
||||
__InitializeDefaultIndexBufferList();
|
||||
__InitializePDTVertexBufferList();
|
||||
}
|
||||
|
||||
auto CGraphicDevice::__IsInDriverBlackList(D3D_CAdapterInfo &) -> bool
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
}
|
||||
|
||||
auto CGraphicDevice::__WarningMessage(HWND, UINT) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
void CGraphicDevice::__InitializeDefaultIndexBufferList()
|
||||
{
|
||||
for (UINT i=0; i<DEFAULT_IB_NUM; ++i)
|
||||
@@ -224,11 +499,36 @@ void CGraphicDevice::__DestroyDefaultIndexBufferList()
|
||||
for (UINT i=0; i<DEFAULT_IB_NUM; ++i)
|
||||
if (ms_alpd3dDefIB[i])
|
||||
{
|
||||
delete ms_alpd3dDefIB[i]; // PORT: CPU buffer, no Release
|
||||
ms_alpd3dDefIB[i]->Release();
|
||||
ms_alpd3dDefIB[i]=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool CGraphicDevice::__CreateDefaultIndexBuffer(UINT eDefIB, UINT uIdxCount, const WORD* c_awIndices)
|
||||
{
|
||||
assert(ms_alpd3dDefIB[eDefIB]==NULL);
|
||||
|
||||
if (FAILED(
|
||||
ms_lpd3dDevice->CreateIndexBuffer(
|
||||
sizeof(WORD)*uIdxCount,
|
||||
D3DUSAGE_WRITEONLY,
|
||||
D3DFMT_INDEX16,
|
||||
D3DPOOL_MANAGED,
|
||||
&ms_alpd3dDefIB[eDefIB])
|
||||
)) return false;
|
||||
|
||||
WORD* dstIndices;
|
||||
if (FAILED(
|
||||
ms_alpd3dDefIB[eDefIB]->Lock(0, 0, (BYTE**)&dstIndices, 0)
|
||||
)) return false;
|
||||
|
||||
memcpy(dstIndices, c_awIndices, sizeof(WORD)*uIdxCount);
|
||||
|
||||
ms_alpd3dDefIB[eDefIB]->Unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGraphicDevice::__CreateDefaultIndexBufferList()
|
||||
{
|
||||
static const WORD c_awLineIndices[2] = { 0, 1, };
|
||||
@@ -268,96 +568,52 @@ bool CGraphicDevice::__CreateDefaultIndexBufferList()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGraphicDevice::__CreateDefaultIndexBuffer(UINT eDefIB, UINT uIdxCount, const WORD* c_awIndices)
|
||||
void CGraphicDevice::InitBackBufferCount(UINT uBackBufferCount)
|
||||
{
|
||||
assert(ms_alpd3dDefIB[eDefIB]==NULL);
|
||||
|
||||
// PORT: a CPU buffer in place of CreateIndexBuffer (CpuBuffer.h).
|
||||
MtCpuIndexBuffer* pIB = new MtCpuIndexBuffer;
|
||||
pIB->bytes.resize(sizeof(WORD)*uIdxCount);
|
||||
pIB->format = D3DFMT_INDEX16;
|
||||
ms_alpd3dDefIB[eDefIB] = pIB;
|
||||
|
||||
WORD* dstIndices;
|
||||
if (FAILED(
|
||||
ms_alpd3dDefIB[eDefIB]->Lock(0, 0, (BYTE**)&dstIndices, 0)
|
||||
)) return false;
|
||||
|
||||
memcpy(dstIndices, c_awIndices, sizeof(WORD)*uIdxCount);
|
||||
|
||||
ms_alpd3dDefIB[eDefIB]->Unlock();
|
||||
|
||||
return true;
|
||||
m_uBackBufferCount=uBackBufferCount;
|
||||
}
|
||||
|
||||
void CGraphicDevice::__InitializePDTVertexBufferList()
|
||||
void CGraphicDevice::Destroy()
|
||||
{
|
||||
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
|
||||
ms_alpd3dPDTVB[i]=NULL;
|
||||
}
|
||||
__DestroyPDTVertexBufferList();
|
||||
__DestroyDefaultIndexBufferList();
|
||||
|
||||
void CGraphicDevice::__DestroyPDTVertexBufferList()
|
||||
{
|
||||
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
|
||||
if (ms_hDC)
|
||||
{
|
||||
if (ms_alpd3dPDTVB[i])
|
||||
{
|
||||
delete ms_alpd3dPDTVB[i]; // PORT: CPU buffer, no Release
|
||||
ms_alpd3dPDTVB[i]=NULL;
|
||||
}
|
||||
ReleaseDC(ms_hWnd, ms_hDC);
|
||||
ms_hDC = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool CGraphicDevice::__CreatePDTVertexBufferList()
|
||||
{
|
||||
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
|
||||
if (ms_ptVS)
|
||||
{
|
||||
ms_lpd3dDevice->DeleteVertexShader(ms_ptVS);
|
||||
ms_ptVS = 0;;
|
||||
}
|
||||
|
||||
if (ms_pntVS)
|
||||
{
|
||||
ms_lpd3dDevice->DeleteVertexShader(ms_pntVS);
|
||||
ms_pntVS = 0;
|
||||
}
|
||||
|
||||
if (ms_pnt2VS)
|
||||
{
|
||||
ms_lpd3dDevice->DeleteVertexShader(ms_pnt2VS);
|
||||
ms_pnt2VS = 0;
|
||||
}
|
||||
|
||||
safe_release(ms_lpSphereMesh);
|
||||
safe_release(ms_lpCylinderMesh);
|
||||
|
||||
safe_release(ms_lpd3dMatStack);
|
||||
safe_release(ms_lpd3dDevice);
|
||||
safe_release(ms_lpd3d);
|
||||
|
||||
if (m_pStateManager)
|
||||
{
|
||||
// PORT: a CPU buffer in place of CreateVertexBuffer (CpuBuffer.h).
|
||||
MtCpuVertexBuffer* pVB = new MtCpuVertexBuffer;
|
||||
pVB->bytes.resize(sizeof(TPDTVertex)*PDT_VERTEX_NUM);
|
||||
pVB->fvf = D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1;
|
||||
ms_alpd3dPDTVB[i] = pVB;
|
||||
delete m_pStateManager;
|
||||
m_pStateManager = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// PORT: the stream vertex shaders are declarations for the fixed-function pipeline; the recording
|
||||
// device decodes vertices by FVF, so each returns the FVF matching its declaration. PT keeps its
|
||||
// texture coordinates in stream 1, which the device does not record: stream 0 is position only.
|
||||
DWORD CGraphicDevice::CreatePTStreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
return D3DFVF_XYZ;
|
||||
}
|
||||
|
||||
DWORD CGraphicDevice::CreatePNTStreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
return D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1;
|
||||
}
|
||||
|
||||
DWORD CGraphicDevice::CreatePNT2StreamVertexShader()
|
||||
{
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
return D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::CreateDoublePNTStreamVertexShader() -> DWORD
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<DWORD>();
|
||||
}
|
||||
|
||||
// 40250 GrpDevice.cpp:298-306; s_MaxTextureWidth/Height come from D3DCAPS8 in __CheckD3DCaps.
|
||||
// PORT: 4096 is the texture size every Godot renderer on the target GPUs supports.
|
||||
static DWORD s_MaxTextureWidth = 4096, s_MaxTextureHeight = 4096;
|
||||
|
||||
DWORD GetMaxTextureWidth()
|
||||
{
|
||||
return s_MaxTextureWidth;
|
||||
}
|
||||
|
||||
DWORD GetMaxTextureHeight()
|
||||
{
|
||||
return s_MaxTextureHeight;
|
||||
__Initialize();
|
||||
}
|
||||
|
||||
@@ -727,10 +727,8 @@ void CScreen::End()
|
||||
STATEMANAGER.EndScene();
|
||||
}
|
||||
|
||||
// PORT: 40250 declares these extern (UserInterface, the in-game web page); PythonApplicationWebPage is
|
||||
// DIVERGENT here, so the page is never open and Show presents the whole back buffer.
|
||||
static const bool g_isBrowserMode = false;
|
||||
static RECT g_rcBrowser = {};
|
||||
extern bool g_isBrowserMode;
|
||||
extern RECT g_rcBrowser;
|
||||
|
||||
void CScreen::Show(HWND hWnd)
|
||||
{
|
||||
|
||||
@@ -299,6 +299,7 @@ public:
|
||||
caps->DevCaps = D3DDEVCAPS_HWTRANSFORMANDLIGHT;
|
||||
caps->VertexShaderVersion = D3DVS_VERSION(1, 1);
|
||||
caps->PrimitiveMiscCaps = D3DPMISCCAPS_CLIPTLVERTS;
|
||||
caps->VertexProcessingCaps = D3DVTXPCAPS_TEXGEN | D3DVTXPCAPS_DIRECTIONALLIGHTS | D3DVTXPCAPS_POSITIONALLIGHTS;
|
||||
caps->MaxActiveLights = 8;
|
||||
caps->MaxTextureBlendStages = 4;
|
||||
caps->MaxSimultaneousTextures = 4;
|
||||
@@ -515,12 +516,38 @@ public:
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT SetPixelShader(DWORD) override { return S_OK; }
|
||||
// PORT: no programmable vertex shaders; 40250 falls back to its FVF when creation fails.
|
||||
HRESULT CreateVertexShader(const DWORD*, const DWORD*, DWORD* pHandle, DWORD) override
|
||||
// PORT: no programmable vertex shaders (a pFunction fails; 40250 falls back to its FVF). A declaration
|
||||
// alone describes fixed-function input, so its handle is the FVF of stream 0 (the vertices the device
|
||||
// records): CGraphicDevice's PT/PNT/PNT2 stream shaders.
|
||||
HRESULT CreateVertexShader(const DWORD* pDeclaration, const DWORD* pFunction, DWORD* pHandle, DWORD) override
|
||||
{
|
||||
if (pHandle)
|
||||
*pHandle = 0;
|
||||
return E_FAIL;
|
||||
if (pFunction || !pDeclaration || !pHandle)
|
||||
return E_FAIL;
|
||||
DWORD fvf = 0, texCount = 0, stream = 0;
|
||||
for (const DWORD* token = pDeclaration; *token != D3DVSD_END(); ++token)
|
||||
{
|
||||
const DWORD type = (*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT;
|
||||
if (type == D3DVSD_TOKEN_STREAM)
|
||||
stream = *token & 0xF;
|
||||
else if (type == D3DVSD_TOKEN_STREAMDATA && stream == 0)
|
||||
{
|
||||
const DWORD reg = *token & 0x1F;
|
||||
if (reg == D3DVSDE_POSITION)
|
||||
fvf |= D3DFVF_XYZ;
|
||||
else if (reg == D3DVSDE_NORMAL)
|
||||
fvf |= D3DFVF_NORMAL;
|
||||
else if (reg == D3DVSDE_DIFFUSE)
|
||||
fvf |= D3DFVF_DIFFUSE;
|
||||
else if (reg >= D3DVSDE_TEXCOORD0 && reg <= D3DVSDE_TEXCOORD3)
|
||||
texCount = std::max<DWORD>(texCount, reg - D3DVSDE_TEXCOORD0 + 1);
|
||||
else
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
*pHandle = fvf | (texCount << D3DFVF_TEXCOUNT_SHIFT);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT DeleteVertexShader(DWORD) override { return S_OK; }
|
||||
HRESULT SetVertexShaderConstant(DWORD, const void*, DWORD) override { return S_OK; }
|
||||
|
||||
Reference in New Issue
Block a user