diff --git a/OpenJPOG/Source/Tasks/ARootTask.cpp b/OpenJPOG/Source/Tasks/ARootTask.cpp index 1cc8331..f430640 100644 --- a/OpenJPOG/Source/Tasks/ARootTask.cpp +++ b/OpenJPOG/Source/Tasks/ARootTask.cpp @@ -16,6 +16,9 @@ ARootTask::ARootTask() TBOOL ARootTask::OnCreate() { m_pMoviePlayer = new ABINKMoviePlayer(); + if (!CreateRenderInterface()) { + return TFALSE; + } return TTask::OnCreate(); } @@ -42,3 +45,84 @@ void ARootTask::AllocateInputSystem() m_pInputTask = pScheduler->CreateTask(TGetClass(ADummyTask), pInputTask); m_pVibrationTask = (AVibrationManager*)pScheduler->CreateTask(TGetClass(AVibrationManager), pInputTask); } + +TBOOL ARootTask::CreateRenderInterface() +{ + TRenderInterface::DisplayParams displayParams; + displayParams.uiWidth = 640; + displayParams.uiHeight = 480; + displayParams.bWindowed = TTRUE; + displayParams.uiColourDepth = 32; + displayParams.eDepthStencilFormat = 0; + CreateDisplayDevice(displayParams, TFALSE); + m_pRenderInterface->CreateDisplay(displayParams); + return TTRUE; +} + +const TRenderAdapter::Mode::Device* ARootTask::CreateDisplayDevice(TRenderInterface::DisplayParams& a_rDisplayParams, bool a_bReverseOrder) +{ + TRenderInterface* pRenderer = TRenderInterface::GetRenderer(); + const TRenderAdapter::Mode::Device* pDevice = TNULL; + + if (a_bReverseOrder) + { + a_rDisplayParams.eDepthStencilFormat = 4; + pDevice = pRenderer->FindDevice(&a_rDisplayParams); + + if (!pDevice) + { + a_rDisplayParams.eDepthStencilFormat = 2; + pDevice = pRenderer->FindDevice(&a_rDisplayParams); + + if (!pDevice) + { + a_rDisplayParams.eDepthStencilFormat = 3; + pDevice = pRenderer->FindDevice(&a_rDisplayParams); + + if (!pDevice) + { + a_rDisplayParams.eDepthStencilFormat = 0; + pDevice = pRenderer->FindDevice(&a_rDisplayParams); + + if (!pDevice) + { + a_rDisplayParams.eDepthStencilFormat = 1; + pDevice = pRenderer->FindDevice(&a_rDisplayParams); + } + } + } + } + } + else + { + pDevice = pRenderer->FindDevice(&a_rDisplayParams); + a_rDisplayParams.eDepthStencilFormat = 0; + + if (!pDevice) + { + a_rDisplayParams.eDepthStencilFormat = 1; + pDevice = pRenderer->FindDevice(&a_rDisplayParams); + + if (!pRenderer->FindDevice(&a_rDisplayParams)) + { + a_rDisplayParams.eDepthStencilFormat = 2; + pDevice = pRenderer->FindDevice(&a_rDisplayParams); + + if (!pRenderer->FindDevice(&a_rDisplayParams)) + { + a_rDisplayParams.eDepthStencilFormat = 4; + pDevice = pRenderer->FindDevice(&a_rDisplayParams); + + if (!pRenderer->FindDevice(&a_rDisplayParams)) + { + a_rDisplayParams.eDepthStencilFormat = 3; + pDevice = pRenderer->FindDevice(&a_rDisplayParams); + } + } + } + } + } + + return pDevice; + +} diff --git a/OpenJPOG/Source/Tasks/ARootTask.h b/OpenJPOG/Source/Tasks/ARootTask.h index 2e8bfa7..9fa8264 100644 --- a/OpenJPOG/Source/Tasks/ARootTask.h +++ b/OpenJPOG/Source/Tasks/ARootTask.h @@ -9,6 +9,7 @@ #include "GUI/AGUISystem.h" #include "ARootStateController.h" + class ARootTask : public Toshi::TTask { DECLARE_DYNAMIC(ARootTask); @@ -35,6 +36,9 @@ class ARootTask : public Toshi::TTask void AllocateRenderInterface(); void AllocateInputSystem(); + TBOOL CreateRenderInterface(); + const Toshi::TRenderAdapter::Mode::Device* CreateDisplayDevice(Toshi::TRenderInterface::DisplayParams& a_rDisplayParams, bool a_bReverseOrder); + private: Toshi::TCString m_szName; AGUISystem* m_pGUISystem; // 0x34 diff --git a/Toshi/Include/TRender/TRenderInterface.h b/Toshi/Include/TRender/TRenderInterface.h index e224d69..9492669 100644 --- a/Toshi/Include/TRender/TRenderInterface.h +++ b/Toshi/Include/TRender/TRenderInterface.h @@ -106,6 +106,10 @@ class TRENDERINTERFACE_EXPORTS TRenderInterface : public TObject TResource* CreateResource(const TClass* a_pClass, TPCCHAR a_szResName, TResource* a_pResource); + const TRenderAdapter::Mode::Device* FindDevice(const DisplayParams* a_pDisplayParams); + + void FlushDyingResources(); + TResource* GetSystemResource(SYSRESOURCES a_SystemResource) { TASSERT(a_SystemResource < TRenderInterface::SYSRESOURCES_NUMOF); @@ -121,13 +125,24 @@ class TRENDERINTERFACE_EXPORTS TRenderInterface : public TObject } TBOOL IsCreated() { return m_bIsCreated; } + TBOOL IsDisplayCreated() { return m_bIsDiplayCreated; } TNodeList* GetAdapterList() { return &m_pAdapterList; }; + static TRenderInterface* TOSHI_API GetRenderer() { return s_Interface; } + private: + void DestroyDyingResources(TResource* a_pResource); + void DeleteResource(TResource* a_pResource); + void DeleteResourceRecurse(TResource* a_pResource); + void DeleteResourceAtomic(TResource* a_pResource); + static TRenderInterface* s_Interface; +protected: + TBOOL m_bIsCreated; // 0x9 + TBOOL m_bIsDiplayCreated; // 0xA TRenderContext* m_pCurrentRenderContext; // 0x1C TRenderContext* m_pDefaultRenderContext; // 0x20 TKernelInterface* m_pKernel; // 0x24 @@ -135,6 +150,7 @@ class TRENDERINTERFACE_EXPORTS TRenderInterface : public TObject TNodeList m_pAdapterList; // 0xFC TINT m_iResourceCount; // 0x124 TNodeTree m_Resources; // 0x128 + TBOOL m_bHasDyingResources; // 0x12C }; TOSHI_NAMESPACE_END \ No newline at end of file diff --git a/Toshi/Include/TRenderD3D/TRenderContextD3D.h b/Toshi/Include/TRenderD3D/TRenderContextD3D.h new file mode 100644 index 0000000..bc1b02f --- /dev/null +++ b/Toshi/Include/TRenderD3D/TRenderContextD3D.h @@ -0,0 +1,12 @@ +#pragma once +#include "Defines.h" +#include "TRender/TRenderContext.h" + +TOSHI_NAMESPACE_BEGIN + +class TRENDERINTERFACED3D_EXPORTS TRenderContextD3D : public TRenderContext +{ + +}; + +TOSHI_NAMESPACE_END \ No newline at end of file diff --git a/Toshi/Include/TRenderD3D/TRenderD3DInterface.h b/Toshi/Include/TRenderD3D/TRenderD3DInterface.h index ec42945..6a094f0 100644 --- a/Toshi/Include/TRenderD3D/TRenderD3DInterface.h +++ b/Toshi/Include/TRenderD3D/TRenderD3DInterface.h @@ -42,6 +42,9 @@ class TRENDERINTERFACED3D_EXPORTS TRenderD3DInterface : public TRenderInterface virtual void ConnectDefaultViewportHandelrs(TViewport& a_pViewport) override; virtual TModel* CreateModel(TPCCHAR a_szName, TINT a_iUnk1) override; + virtual TBOOL IsCapableColourCorrection(); + virtual void EnableColourCorrection(TBOOL a_bEnable); + TBOOL IsTextureFormatSupported(D3DFORMAT a_eFormat); void Exit() { m_bIsExited = TTRUE; } @@ -51,24 +54,34 @@ class TRENDERINTERFACED3D_EXPORTS TRenderD3DInterface : public TRenderInterface void CreateAcceleratorTableA(); void DestroyAcceleratorTable(); + protected: TBOOL LoadShaders(); + void SetDefaultRenderStates(); public: IDirect3DDevice8* GetD3DDevice() { return m_pD3DDevice; } IDirect3D8* GetD3DInterface() { return m_pD3DInterface; } TMSWindow* GetMSWindow() { return &m_pMSWindow; } + HACCEL GetAcceleratorTable() { return m_hAccel; } private: - IDirect3D8* m_pD3DInterface; // 0x17C - IDirect3DDevice8* m_pD3DDevice; // 0x180 - D3DPRESENT_PARAMETERS m_oPresentParams; // 0x18C - HACCEL m_hAccel; // 0x1DC - TD3DAdapter::Mode::Device* m_pCurrentDevice; // 0x1E0 - TMSWindow m_pMSWindow; // 0x1F8 - TBOOL m_bIsExited; // 0x208 + TTextureResource* m_pInvalidTexture; // 0xF8 + IDirect3D8* m_pD3DInterface; // 0x17C + IDirect3DDevice8* m_pD3DDevice; // 0x180 + D3DPRESENT_PARAMETERS m_oPresentParams; // 0x18C + D3DSURFACE_DESC m_oSurfaceDesk; // 0x1B8 + HACCEL m_hAccel; // 0x1DC + TD3DAdapter::Mode::Device* m_pCurrentDevice; // 0x1E0 + TRenderInterface::DisplayParams m_oDisplayParams; // 0x1E4 + TMSWindow m_pMSWindow; // 0x1F8 + TBOOL m_bIsExited; // 0x208 + TBOOL m_bUsingColorCorrection; // 0x21C + TBOOL m_bCheckedCapableColourCorrection; // 0x21D + TBOOL m_bCapableColourCorrection; // 0x21E + TBOOL m_bEnableColourCorrection; // 0x21F }; TOSHI_NAMESPACE_END \ No newline at end of file diff --git a/Toshi/Source/TRender/TRenderInterface.cpp b/Toshi/Source/TRender/TRenderInterface.cpp index ca6c4fe..8b6ff54 100644 --- a/Toshi/Source/TRender/TRenderInterface.cpp +++ b/Toshi/Source/TRender/TRenderInterface.cpp @@ -12,6 +12,7 @@ TRenderInterface* TRenderInterface::s_Interface = TNULL; TRenderInterface::TRenderInterface() { m_bIsCreated = TFALSE; + m_bIsDiplayCreated = TFALSE; m_pDefaultRenderContext = TNULL; m_pCurrentRenderContext = TNULL; m_pKernel = TNULL; @@ -25,7 +26,10 @@ TRenderInterface::TRenderInterface() TBOOL TRenderInterface::CreateDisplay(const DisplayParams& a_rParams) { - return TBOOL(); + TASSERT(TTRUE == IsCreated()); + TASSERT(TFALSE == IsDisplayCreated()); + m_bIsDiplayCreated = 1; + return TTRUE; } TBOOL TRenderInterface::DestroyDisplay() @@ -35,7 +39,8 @@ TBOOL TRenderInterface::DestroyDisplay() TBOOL TRenderInterface::Update(float a_fDeltaTime) { - return TBOOL(); + FlushDyingResources(); + return TTRUE; } TBOOL TRenderInterface::BeginScene() @@ -58,14 +63,22 @@ TRenderInterface::DisplayParams* TRenderInterface::GetCurrentDisplayParams() return nullptr; } - TBOOL TRenderInterface::Create(TKernelInterface* pKernelInterface) { TASSERT(TFALSE == IsCreated()); - TVALIDADDRESS(pKernelInterface); + TVALIDADDRESS(pKernelInterface); m_pKernel = pKernelInterface; - return TTRUE; + + m_pDefaultRenderContext = CreateRenderContext(); + TVALIDADDRESS(m_pDefaultRenderContext); + + if (m_pDefaultRenderContext) { + SetCurrentRenderContext(m_pDefaultRenderContext); + m_bIsCreated = TTRUE; + return TTRUE; + } + return TFALSE; } TBOOL TRenderInterface::CreateSystemResources() @@ -133,6 +146,179 @@ TResource* TRenderInterface::CreateResource(const TClass* a_pClass, TPCCHAR a_sz return pResource; } +const TRenderAdapter::Mode::Device* TRenderInterface::FindDevice(const DisplayParams* a_pDisplayParams) +{ + auto pAdapter = GetAdapterList()->Begin(); + + while (TTRUE) + { + if (pAdapter == GetAdapterList()->End()) + { + TCString().Format("Unable to find the passed device!\n"); + return TNULL; + } + + for (auto pMode = pAdapter->GetModeList()->Begin(); pMode != pAdapter->GetModeList()->End(); pMode++) + { + auto uiNumSupportedDevices = pAdapter->GetNumSupportedDevices(); + + for (TUINT32 i = 0; i < uiNumSupportedDevices; i++) + { + auto pDevice = pMode->GetDevice(i); + + if (pDevice->IsSoftware()) continue; + + TBOOL bPassedColourDepth = TTRUE; + + if (a_pDisplayParams->uiColourDepth == 32) + { + if (!pDevice->GetMode()->Is32Bit()) + { + bPassedColourDepth = TFALSE; + } + } + else if (a_pDisplayParams->uiColourDepth == 16) + { + if (!pDevice->GetMode()->Is16Bit()) + { + bPassedColourDepth = TFALSE; + } + } + + TBOOL bPassedWindowed = TTRUE; + + if (a_pDisplayParams->bWindowed && !pDevice->CanRenderWindowed()) + { + bPassedWindowed = TFALSE; + } + + auto uiWidth = pDevice->GetMode()->GetWidth(); + auto uiHeight = pDevice->GetMode()->GetHeight(); + + if (uiHeight < uiWidth || !a_pDisplayParams->bWindowed || a_pDisplayParams->uiWidth <= a_pDisplayParams->uiHeight) + { + if (uiWidth == a_pDisplayParams->uiWidth && uiHeight == a_pDisplayParams->uiHeight) + { + if (pDevice->IsDepthStencilFormatSupported(a_pDisplayParams->eDepthStencilFormat) && + bPassedColourDepth && bPassedWindowed) + { + return pDevice; + } + } + } + else + { + if (a_pDisplayParams->uiWidth <= uiWidth) + { + if (uiHeight < a_pDisplayParams->uiHeight) continue; + + if (pDevice->IsDepthStencilFormatSupported(a_pDisplayParams->eDepthStencilFormat) && + bPassedColourDepth && bPassedWindowed) + { + return pDevice; + } + } + } + } + } + + pAdapter++; + } +} + +void TRenderInterface::FlushDyingResources() +{ + while (m_bHasDyingResources) + { + m_bHasDyingResources = TFALSE; + DestroyDyingResources(m_Resources.ChildOfRoot()); + } +} + +void TRenderInterface::DestroyDyingResources(TResource* a_pResource) +{ + // TODO: refactor + TResource* pTVar1; + TResource* next; + TResource* pRes1; + TResource* pRes2; + + pRes1 = a_pResource; + pRes2 = a_pResource; + if (a_pResource) { + do { + next = pRes2->Next(); + if (next == pRes1) { + next = (TResource*)0x0; + } + if ((pRes2->m_Flags & 4) == 0) { + pRes2 = pRes2->Child(); + if (pRes2 != (TResource*)0x0) { + DestroyDyingResources(pRes2); + } + } + else { + if (pRes2 == pRes1) { + pRes1 = next; + a_pResource = next; + } + pTVar1 = pRes2->Child(); + while (pTVar1 != (TResource*)0x0) { + pRes1 = pTVar1->Next(); + if (pRes1 == pTVar1) { + pRes1 = (TResource*)0x0; + } + DeleteResourceAtomic(pTVar1); + pTVar1 = pRes1; + pRes1 = a_pResource; + } + DeleteResourceAtomic(pRes2); + } + pRes2 = next; + } while (next); + } +} + +void TRenderInterface::DeleteResource(TResource* a_pResource) +{ + DeleteResourceRecurse(a_pResource->Child()); + DeleteResourceAtomic(a_pResource); +} + +void TRenderInterface::DeleteResourceRecurse(TResource* a_pResource) +{ + while (a_pResource) + { + auto next = a_pResource->Next(); + if (next == a_pResource) next = TNULL; + + DeleteResourceAtomic(a_pResource); + a_pResource = next; + } +} + +void TRenderInterface::DeleteResourceAtomic(TResource* a_pResource) +{ + if (a_pResource) { + DeleteResourceRecurse(a_pResource->Child()); + + TASSERT(TFALSE == a_pResource->IsValid()); + + if (a_pResource->IsCreated()) { + a_pResource->OnDestroy(); + } + + m_Resources.Remove(a_pResource, TFALSE); + + if (a_pResource->m_Flags & 8) { + a_pResource->~TResource(); + } + else { + delete a_pResource; + } + } +} + TBOOL TRenderInterface::Destroy() { return TBOOL(); @@ -171,12 +357,12 @@ TBOOL TRenderInterface::SetPixelAspectRatio(float a_fPixelAspectRatio) TRenderContext* TRenderInterface::CreateRenderContext() { - return nullptr; + return TNULL; } TRenderCapture* TRenderInterface::CreateCapture() { - return nullptr; + return TNULL; } void TRenderInterface::DestroyCapture(TRenderCapture* a_pRenderCapture) diff --git a/Toshi/Source/TRender/TTextureFactory.cpp b/Toshi/Source/TRender/TTextureFactory.cpp index 4bb760c..412e001 100644 --- a/Toshi/Source/TRender/TTextureFactory.cpp +++ b/Toshi/Source/TRender/TTextureFactory.cpp @@ -56,11 +56,11 @@ TUINT TTextureFactory::HashName(TPCCHAR a_szName) TTextureFactory::NameEntry* TTextureFactory::RegisterTexture(TPCCHAR a_szName, TTextureResource* a_pTexture) { - TNodeList* pList = &m_aLists[HashName(a_szName)]; - TTextureFactory::NameEntry* pEntry = new TTextureFactory::NameEntry(a_szName, a_pTexture); + auto pList = &m_aLists[HashName(a_szName)]; + auto pEntry = new TTextureFactory::NameEntry(a_szName, a_pTexture); - TVALIDADDRESS(a_pTexture->m_pNameEntry); a_pTexture->m_pNameEntry = pEntry; + TVALIDADDRESS(a_pTexture->m_pNameEntry); pList->InsertHead(*pEntry); return a_pTexture->m_pNameEntry; diff --git a/Toshi/Source/TRenderD3D/TRenderContextD3D.cpp b/Toshi/Source/TRenderD3D/TRenderContextD3D.cpp new file mode 100644 index 0000000..81fc41e --- /dev/null +++ b/Toshi/Source/TRenderD3D/TRenderContextD3D.cpp @@ -0,0 +1 @@ +#include "TRenderD3D/TRenderContextD3D.h" \ No newline at end of file diff --git a/Toshi/Source/TRenderD3D/TRenderD3DInterface.cpp b/Toshi/Source/TRenderD3D/TRenderD3DInterface.cpp index 8f86db6..530edf3 100644 --- a/Toshi/Source/TRenderD3D/TRenderD3DInterface.cpp +++ b/Toshi/Source/TRenderD3D/TRenderD3DInterface.cpp @@ -1,7 +1,9 @@ #include "TRenderD3D/TRenderD3DInterface.h" #include "TKernel/TWString.h" #include "TRenderD3D/TRenderD3DAdapter.h" +#include "TRenderD3D/TTextureFactoryD3D.h" #include +#include TOSHI_NAMESPACE_USING @@ -12,7 +14,16 @@ TRenderD3DInterface::TRenderD3DInterface() m_pD3DInterface = NULL; m_pD3DDevice = NULL; m_hAccel = NULL; + m_pCurrentDevice = TNULL; + m_oDisplayParams.uiWidth = 640; + m_oDisplayParams.uiHeight = 480; + m_oDisplayParams.uiColourDepth = 32; + m_oDisplayParams.bWindowed = TTRUE; m_bIsExited = TFALSE; + m_bUsingColorCorrection = TTRUE; + m_bCheckedCapableColourCorrection = TFALSE; + m_bCapableColourCorrection = TFALSE; + m_bEnableColourCorrection = TTRUE; } void TOSHI_API TRenderD3DInterface::TD3DAssert(HRESULT a_hr, TPCCHAR a_pError) @@ -30,6 +41,105 @@ void TOSHI_API TRenderD3DInterface::TD3DAssert(HRESULT a_hr, TPCCHAR a_pError) TBOOL TRenderD3DInterface::CreateDisplay(const TRenderInterface::DisplayParams& a_rParams) { + TASSERT(TTRUE == IsCreated()); + TASSERT(TFALSE == IsDisplayCreated()); + + if (!TRenderInterface::CreateDisplay(a_rParams)) { + return TFALSE; + } + + m_pCurrentDevice = (TD3DAdapter::Mode::Device*)FindDevice(&a_rParams); + m_oDisplayParams = a_rParams; + TASSERT(m_pCurrentDevice != TNULL); + + if (m_pCurrentDevice) { + + TRenderInterface::DisplayParams* pDisplayParams = GetCurrentDisplayParams(); + + RECT clientRect; + GetClientRect(GetDesktopWindow(), &clientRect); + + if (2000 < clientRect.right) { + clientRect.right /= 2; + } + + TUINT32 uiWindowPosX = 0; + TUINT32 uiWindowPosY = 0; + + if (pDisplayParams->bWindowed) { + TRenderAdapter::Mode* pMode = GetCurrentDevice()->GetMode(); + uiWindowPosX = (clientRect.right - pMode->GetWidth()) / 2; + uiWindowPosY = (clientRect.bottom - pMode->GetHeight()) / 2; + } + + TSystem::MemSet(&m_oPresentParams, 0, sizeof(m_oPresentParams)); + m_oPresentParams.Windowed = pDisplayParams->bWindowed; + m_oPresentParams.BackBufferCount = 1; + m_oPresentParams.MultiSampleType = D3DMULTISAMPLE_NONE; + m_oPresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD; + m_oPresentParams.EnableAutoDepthStencil = TRUE; + m_oPresentParams.hDeviceWindow = GetMSWindow()->GetHWND(); + m_oPresentParams.AutoDepthStencilFormat = TD3DAdapter::Mode::Device::DEPTHSTENCILFORMATS[pDisplayParams->eDepthStencilFormat]; + m_oPresentParams.BackBufferWidth = pDisplayParams->uiWidth; + m_oPresentParams.BackBufferHeight = pDisplayParams->uiHeight; + + auto pDevice = TSTATICCAST(TD3DAdapter::Mode::Device*, GetCurrentDevice()); + auto pMode = TSTATICCAST(TD3DAdapter::Mode*, pDevice->GetMode()); + auto pAdapter = TSTATICCAST(TD3DAdapter*, pMode->GetAdapter()); + auto uiAdapterIndex = pAdapter->GetAdapterIndex(); + + if (pDisplayParams->bWindowed) { + m_oPresentParams.BackBufferFormat = pMode->GetD3DDisplayMode().Format; + } + else { + m_oPresentParams.BackBufferFormat = pMode->GetBackBufferFormat(pDisplayParams->uiColourDepth); + } + + HRESULT hRes = GetD3DInterface()->CreateDevice( + uiAdapterIndex, + TD3DAdapter::Mode::Device::DEVICETYPES[pDevice->GetDeviceIndex()], + GetMSWindow()->GetHWND(), + pDevice->GetD3DDeviceFlags(), + &m_oPresentParams, + &m_pD3DDevice + ); + + if (FAILED(hRes)) { + TD3DAssert(hRes, "Failed to create D3D Device!"); + return TFALSE; + } + + SetDefaultRenderStates(); + + if (pDisplayParams->bWindowed) { + GetMSWindow()->SetWindowed(); + } + else { + GetMSWindow()->SetFullscreen(); + } + + GetMSWindow()->Position(uiWindowPosX, uiWindowPosY, pDisplayParams->uiWidth, pDisplayParams->uiHeight); + GetMSWindow()->Enable(); + + IDirect3DSurface8* pSurface; + GetD3DDevice()->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pSurface); + pSurface->GetDesc(&m_oSurfaceDesk); + pSurface->Release(); + GetD3DDevice()->ShowCursor(TRUE); + + TUINT invalidTextureData[64]; + for (int i = 0; i < 32; i++) { + invalidTextureData[i] = 0xff0fff0f; + } + + TTextureFactoryHAL* factory = (TTextureFactoryHAL*)GetSystemResource(SYSRESOURCE_TEXTUREFACTORY); + m_pInvalidTexture = factory->CreateTextureFromMemory(invalidTextureData, sizeof(invalidTextureData), 17, 8, 8); + TVALIDADDRESS(m_pInvalidTexture); + + EnableColourCorrection(TTRUE); + m_bIsDiplayCreated = TTRUE; + } + return TBOOL(); } @@ -40,7 +150,20 @@ TBOOL TRenderD3DInterface::DestroyDisplay() TBOOL TRenderD3DInterface::Update(float a_fDeltaTime) { - return TBOOL(); + TASSERT(TTRUE == IsCreated()); + if (TRenderInterface::Update(a_fDeltaTime)) { + MSG msg; + while (FALSE != PeekMessage(&msg, NULL, 0, 0, 1)) { + if (TranslateAccelerator(GetMSWindow()->GetHWND(), GetAcceleratorTable(), &msg) == 0) { + TranslateMessage(&msg); + DispatchMessageA(&msg); + } + } + } + if (!m_bIsExited) { + return TTRUE; + } + return TFALSE; } TBOOL TRenderD3DInterface::BeginScene() @@ -55,12 +178,12 @@ TBOOL TRenderD3DInterface::EndScene() TRenderAdapter::Mode::Device* TRenderD3DInterface::GetCurrentDevice() { - return nullptr; + return m_pCurrentDevice; } TRenderInterface::DisplayParams* TRenderD3DInterface::GetCurrentDisplayParams() { - return nullptr; + return &m_oDisplayParams; } TBOOL TRenderD3DInterface::Create(TKernelInterface* a_pKernel) @@ -114,7 +237,9 @@ TBOOL TRenderD3DInterface::SetPixelAspectRatio(float a_fPixelAspectRatio) TRenderContext* TRenderD3DInterface::CreateRenderContext() { - return nullptr; + TRenderContextD3D* pRenderContext = new TRenderContextD3D(); + TVALIDADDRESS(pRenderContext); + return pRenderContext; } TRenderCapture* TRenderD3DInterface::CreateCapture() @@ -135,6 +260,22 @@ TModel* TRenderD3DInterface::CreateModel(TPCCHAR a_szName, TINT a_iUnk1) return nullptr; } +TBOOL TRenderD3DInterface::IsCapableColourCorrection() +{ + if (!m_bCheckedCapableColourCorrection) { + D3DCAPS8 caps; + HRESULT hRes = GetD3DDevice()->GetDeviceCaps(&caps); + m_bCapableColourCorrection = SUCCEEDED(hRes) && HASFLAG(caps.AdapterOrdinal & 0x20000); + } + + return m_bCapableColourCorrection; +} + +void TRenderD3DInterface::EnableColourCorrection(TBOOL a_bEnable) +{ + m_bEnableColourCorrection = a_bEnable && IsCapableColourCorrection(); +} + TBOOL TRenderD3DInterface::IsTextureFormatSupported(TTEXTURERESOURCEFORMAT a_eTextureFormat) { switch (a_eTextureFormat) { @@ -225,3 +366,13 @@ TBOOL TRenderD3DInterface::LoadShaders() { return TBOOL(); } + +void TRenderD3DInterface::SetDefaultRenderStates() +{ + m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, 1); + m_pD3DDevice->SetRenderState(D3DRS_CULLMODE, 2); + m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, 0); + m_pD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, 2); + m_pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, 2); + m_pD3DDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, 2); +}