// 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 #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(); } auto CGraphicDevice::Reset() -> bool { MT_PLATFORM_STUB(); return mt_platform_stub_return(); } 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(); } auto CGraphicDevice::__WarningMessage(HWND, UINT) -> void { MT_PLATFORM_STUB(); } void CGraphicDevice::__InitializeDefaultIndexBufferList() { for (UINT i=0; ibytes.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; ibytes.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(); } // 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; }