2V2-e.1: 3D draw-command channel — recording D3D8 device, StateManager, GrpBase, camera
EterLib/StateManager.cpp and GrpBase.cpp ported verbatim. CGraphicDevice::Create builds a platform IDirect3DDevice8 that keeps the device state and records every Draw* call as a Render3DDraw (vertices decoded by FVF, strips/fans expanded, textures, world/view/proj, blend/depth/light state). The 40250 camera (__UpdateCamera, SetCenterPosition, ...) and the Process order (__UpdateCamera -> OnCameraUpdate -> OnUIUpdate -> Begin/SetInterfaceRenderState/OnUIRender/End) are in place; CScreen Begin/End, CPythonGraphic render states and CCullingManager::Process matrix updates are verbatim. port.login_flow asserts a textured, lit character draw under the RH perspective with every vertex on screen; offline and live pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
668f48d6ec
commit
5bfa13c5cc
@@ -1,34 +1,143 @@
|
||||
// Platform skeleton for EterLib/GrpDevice.h (40250 EterLib/GrpDevice.cpp), generated by platform_stub.py.
|
||||
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
|
||||
// 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)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
__Initialize();
|
||||
}
|
||||
|
||||
CGraphicDevice::~CGraphicDevice()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
auto CGraphicDevice::InitBackBufferCount(UINT) -> void
|
||||
void CGraphicDevice::InitBackBufferCount(UINT uBackBufferCount)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
m_uBackBufferCount=uBackBufferCount;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::Destroy() -> void
|
||||
void CGraphicDevice::Destroy()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
__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();
|
||||
}
|
||||
|
||||
auto CGraphicDevice::Create(HWND, int, int, bool, int, int) -> int
|
||||
int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /*iBit*/, int iReflashRate)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<int>();
|
||||
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
|
||||
@@ -69,9 +178,23 @@ auto CGraphicDevice::RegisterWarningString(UINT, const char *) -> void
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CGraphicDevice::__Initialize() -> void
|
||||
void CGraphicDevice::__Initialize()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
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
|
||||
@@ -85,60 +208,133 @@ auto CGraphicDevice::__WarningMessage(HWND, UINT) -> void
|
||||
MT_PLATFORM_STUB();
|
||||
}
|
||||
|
||||
auto CGraphicDevice::__InitializeDefaultIndexBufferList() -> void
|
||||
void CGraphicDevice::__InitializeDefaultIndexBufferList()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
for (UINT i=0; i<DEFAULT_IB_NUM; ++i)
|
||||
ms_alpd3dDefIB[i]=NULL;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::__DestroyDefaultIndexBufferList() -> void
|
||||
void CGraphicDevice::__DestroyDefaultIndexBufferList()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
auto CGraphicDevice::__CreateDefaultIndexBufferList() -> bool
|
||||
bool CGraphicDevice::__CreateDefaultIndexBufferList()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
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;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::__CreateDefaultIndexBuffer(UINT, UINT, const WORD *) -> bool
|
||||
bool CGraphicDevice::__CreateDefaultIndexBuffer(UINT eDefIB, UINT uIdxCount, const WORD* c_awIndices)
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
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;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::__InitializePDTVertexBufferList() -> void
|
||||
void CGraphicDevice::__InitializePDTVertexBufferList()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
|
||||
ms_alpd3dPDTVB[i]=NULL;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::__DestroyPDTVertexBufferList() -> void
|
||||
void CGraphicDevice::__DestroyPDTVertexBufferList()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto CGraphicDevice::__CreatePDTVertexBufferList() -> bool
|
||||
bool CGraphicDevice::__CreatePDTVertexBufferList()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<bool>();
|
||||
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;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::CreatePTStreamVertexShader() -> DWORD
|
||||
// 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()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<DWORD>();
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
return D3DFVF_XYZ;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::CreatePNTStreamVertexShader() -> DWORD
|
||||
DWORD CGraphicDevice::CreatePNTStreamVertexShader()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<DWORD>();
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
return D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::CreatePNT2StreamVertexShader() -> DWORD
|
||||
DWORD CGraphicDevice::CreatePNT2StreamVertexShader()
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
return mt_platform_stub_return<DWORD>();
|
||||
assert(ms_lpd3dDevice != NULL);
|
||||
return D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2;
|
||||
}
|
||||
|
||||
auto CGraphicDevice::CreateDoublePNTStreamVertexShader() -> DWORD
|
||||
|
||||
Reference in New Issue
Block a user