- Purged 66 obsolete GDScript UI components and mobile prototype UI from project/ui/ (retaining ui_assets.gd) - Purged deprecated GDScript game scene, flow state machines, and local gameplay controllers (app_flow, game_scene, player_controller, net_world, etc.) - Purged deprecated local system simulation scripts (consumable_system, chest_system, equip_rules, etc.) and project/fx/ - Purged legacy GDScript unit tests targeting obsolete classes - Unified viewport back buffer sizing in CGraphicBase/CGraphicDevice/PythonBoot - Cleaned up client_main.gd and python_host_check.gd for pure native port architecture - Verified all port tests passing: port_map.py check (0 errors), port_gate.sh macos PASS (19/19 suites), python_game_render_test PASS
362 lines
9.3 KiB
C++
362 lines
9.3 KiB
C++
// 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.
|
|
#include "EterLib/StdAfx.h"
|
|
#include "EterLib/GrpDevice.h"
|
|
#include "EterLib/StateManager.h"
|
|
#include "EterBase/Stl.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;
|
|
|
|
CGraphicDevice::CGraphicDevice()
|
|
: m_uBackBufferCount(0)
|
|
{
|
|
__Initialize();
|
|
}
|
|
|
|
CGraphicDevice::~CGraphicDevice()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
void CGraphicDevice::InitBackBufferCount(UINT uBackBufferCount)
|
|
{
|
|
m_uBackBufferCount=uBackBufferCount;
|
|
}
|
|
|
|
void CGraphicDevice::Destroy()
|
|
{
|
|
__DestroyPDTVertexBufferList();
|
|
__DestroyDefaultIndexBufferList();
|
|
|
|
// PORT: no DC, vertex shader objects or D3DX meshes; the stream "shaders" are FVF codes.
|
|
ms_ptVS = 0;
|
|
ms_pntVS = 0;
|
|
ms_pnt2VS = 0;
|
|
|
|
safe_release(ms_lpd3dMatStack);
|
|
safe_release(ms_lpd3dDevice);
|
|
|
|
if (m_pStateManager)
|
|
{
|
|
delete m_pStateManager;
|
|
m_pStateManager = NULL;
|
|
}
|
|
|
|
__Initialize();
|
|
}
|
|
|
|
int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /*iBit*/, int iReflashRate)
|
|
{
|
|
int iRet = CREATE_OK;
|
|
|
|
Destroy();
|
|
|
|
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;
|
|
ms_lpd3dDevice = MtCreateRecordingDevice(iHres, iVres);
|
|
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))))
|
|
{
|
|
Tracenf("IDirect3DDevice.GetDeviceCaps - ERROR %d", ms_hLastResult);
|
|
return CREATE_GET_DEVICE_CAPS2;
|
|
}
|
|
|
|
ms_lpd3dDevice->GetViewport(&ms_Viewport);
|
|
|
|
m_pStateManager = new CStateManager(ms_lpd3dDevice);
|
|
|
|
D3DXCreateMatrixStack(0, &ms_lpd3dMatStack);
|
|
ms_lpd3dMatStack->LoadIdentity();
|
|
|
|
ms_ptVS = CreatePTStreamVertexShader();
|
|
ms_pntVS = CreatePNTStreamVertexShader();
|
|
ms_pnt2VS = CreatePNT2StreamVertexShader();
|
|
|
|
D3DXMatrixIdentity(&ms_matIdentity);
|
|
D3DXMatrixIdentity(&ms_matView);
|
|
D3DXMatrixIdentity(&ms_matProj);
|
|
D3DXMatrixIdentity(&ms_matInverseView);
|
|
D3DXMatrixIdentity(&ms_matInverseViewYAxis);
|
|
D3DXMatrixIdentity(&ms_matScreen0);
|
|
D3DXMatrixIdentity(&ms_matScreen1);
|
|
D3DXMatrixIdentity(&ms_matScreen2);
|
|
|
|
ms_matScreen0._11 = 1;
|
|
ms_matScreen0._22 = -1;
|
|
|
|
ms_matScreen1._41 = 1;
|
|
ms_matScreen1._42 = 1;
|
|
|
|
ms_matScreen2._11 = (float) iHres / 2;
|
|
ms_matScreen2._22 = (float) iVres / 2;
|
|
|
|
// PORT: no D3DXCreateSphere/D3DXCreateCylinder (debug collision rendering) and no Clear.
|
|
|
|
if (!__CreateDefaultIndexBufferList())
|
|
return false;
|
|
|
|
if (!__CreatePDTVertexBufferList())
|
|
return false;
|
|
|
|
DWORD dwTexMemSize = GetAvailableTextureMemory();
|
|
|
|
if (dwTexMemSize < 64 * 1024 * 1024)
|
|
ms_isLowTextureMemory = true;
|
|
else
|
|
ms_isLowTextureMemory = false;
|
|
|
|
if (dwTexMemSize > 100 * 1024 * 1024)
|
|
ms_isHighTextureMemory = true;
|
|
else
|
|
ms_isHighTextureMemory = false;
|
|
|
|
if (ms_d3dCaps.TextureAddressCaps & D3DPTADDRESSCAPS_BORDER)
|
|
GRAPHICS_CAPS_CAN_NOT_TEXTURE_ADDRESS_BORDER=false;
|
|
else
|
|
GRAPHICS_CAPS_CAN_NOT_TEXTURE_ADDRESS_BORDER=true;
|
|
|
|
// PORT: the SIS/3dfx driver checks have no adapter identifier to test.
|
|
return (iRet);
|
|
}
|
|
|
|
auto CGraphicDevice::GetDeviceState() -> EDeviceState
|
|
{
|
|
MT_PLATFORM_STUB();
|
|
return mt_platform_stub_return<EDeviceState>();
|
|
}
|
|
|
|
auto CGraphicDevice::Reset() -> bool
|
|
{
|
|
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;
|
|
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)
|
|
ms_alpd3dDefIB[i]=NULL;
|
|
}
|
|
|
|
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]=NULL;
|
|
}
|
|
}
|
|
|
|
bool CGraphicDevice::__CreateDefaultIndexBufferList()
|
|
{
|
|
static const WORD c_awLineIndices[2] = { 0, 1, };
|
|
static const WORD c_awLineTriIndices[6] = { 0, 1, 0, 2, 1, 2, };
|
|
static const WORD c_awLineRectIndices[8] = { 0, 1, 0, 2, 1, 3, 2, 3,};
|
|
static const WORD c_awLineCubeIndices[24] = {
|
|
0, 1, 0, 2, 1, 3, 2, 3,
|
|
0, 4, 1, 5, 2, 6, 3, 7,
|
|
4, 5, 4, 6, 5, 7, 6, 7,
|
|
};
|
|
static const WORD c_awFillTriIndices[3]= { 0, 1, 2, };
|
|
static const WORD c_awFillRectIndices[6] = { 0, 2, 1, 2, 3, 1, };
|
|
static const WORD c_awFillCubeIndices[36] = {
|
|
0, 1, 2, 1, 3, 2,
|
|
2, 0, 6, 0, 4, 6,
|
|
0, 1, 4, 1, 5, 4,
|
|
1, 3, 5, 3, 7, 5,
|
|
3, 2, 7, 2, 6, 7,
|
|
4, 5, 6, 5, 7, 6,
|
|
};
|
|
|
|
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_LINE, 2, c_awLineIndices))
|
|
return false;
|
|
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_LINE_TRI, 6, c_awLineTriIndices))
|
|
return false;
|
|
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_LINE_RECT, 8, c_awLineRectIndices))
|
|
return false;
|
|
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_LINE_CUBE, 24, c_awLineCubeIndices))
|
|
return false;
|
|
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_FILL_TRI, 3, c_awFillTriIndices))
|
|
return false;
|
|
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_FILL_RECT, 6, c_awFillRectIndices))
|
|
return false;
|
|
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_FILL_CUBE, 36, c_awFillCubeIndices))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CGraphicDevice::__CreateDefaultIndexBuffer(UINT eDefIB, UINT uIdxCount, const WORD* c_awIndices)
|
|
{
|
|
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;
|
|
}
|
|
|
|
void CGraphicDevice::__InitializePDTVertexBufferList()
|
|
{
|
|
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])
|
|
{
|
|
delete ms_alpd3dPDTVB[i]; // PORT: CPU buffer, no Release
|
|
ms_alpd3dPDTVB[i]=NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool CGraphicDevice::__CreatePDTVertexBufferList()
|
|
{
|
|
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
|
|
{
|
|
// 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;
|
|
}
|
|
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;
|
|
}
|