feat(d3d): clean up hardware cursor stuff

This commit is contained in:
phaneron 2025-04-01 12:43:55 -04:00
parent f4e9f86ca6
commit 8adf3a0061
2 changed files with 37 additions and 26 deletions

View file

@ -336,7 +336,7 @@ LRESULT CGxDeviceD3d::WindowProcD3d(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
if (device) { if (device) {
if (device->m_d3dDevice && LOWORD(lParam) == HTCLIENT) { if (device->m_d3dDevice && LOWORD(lParam) == HTCLIENT) {
SetCursor(nullptr); SetCursor(nullptr);
BOOL show = device->m_cursorVisible && device->m_hardwareCursor ? TRUE : FALSE; BOOL show = device->m_cursorVisible && device->m_hwCursor ? TRUE : FALSE;
device->m_d3dDevice->ShowCursor(show); device->m_d3dDevice->ShowCursor(show);
return 1; return 1;
} }
@ -487,15 +487,7 @@ int32_t CGxDeviceD3d::DeviceSetFormat(const CGxFormat& format) {
CGxFormat createFormat = format; CGxFormat createFormat = format;
if (this->ICreateWindow(createFormat) && this->ICreateD3dDevice(createFormat) && this->CGxDevice::DeviceSetFormat(format)) { if (this->ICreateWindow(createFormat) && this->ICreateD3dDevice(createFormat) && this->CGxDevice::DeviceSetFormat(format)) {
this->intF64 = 1; this->ICursorClip(1);
this->m_hwCursorNeedsUpdate = 1;
if (this->m_format.window == 0) {
RECT windowRect;
GetWindowRect(this->m_hwnd, &windowRect);
ClipCursor(&windowRect);
}
return 1; return 1;
} else { } else {
CGxDevice::Log("CGxDeviceD3d::DeviceSetFormat(): unable to set format!"); CGxDevice::Log("CGxDeviceD3d::DeviceSetFormat(): unable to set format!");
@ -1015,6 +1007,20 @@ bool CGxDeviceD3d::ICreateWindow(CGxFormat& format) {
return this->m_hwnd != nullptr; return this->m_hwnd != nullptr;
} }
void CGxDeviceD3d::ICursorClip(int32_t a1) {
this->intF64 = a1;
if (a1) {
this->m_hwCursorNeedsUpdate = 1;
if (this->m_format.window) {
RECT windowRect;
GetWindowRect(this->m_hwnd, &windowRect);
ClipCursor(&windowRect);
}
}
}
void CGxDeviceD3d::IDestroyD3d() { void CGxDeviceD3d::IDestroyD3d() {
this->IDestroyD3dDevice(); this->IDestroyD3dDevice();
CGxDeviceD3d::IUnloadD3dLib(this->m_d3dLib, this->m_d3d); CGxDeviceD3d::IUnloadD3dLib(this->m_d3dLib, this->m_d3d);
@ -1220,7 +1226,7 @@ void CGxDeviceD3d::IRsSendToHw(EGxRenderState which) {
void CGxDeviceD3d::ICursorCreate(const CGxFormat& format) { void CGxDeviceD3d::ICursorCreate(const CGxFormat& format) {
CGxDevice::ICursorCreate(format); CGxDevice::ICursorCreate(format);
if (this->m_hardwareCursor && this->m_hwCursorTexture == nullptr) { if (this->m_hwCursor && this->m_hwCursorTexture == nullptr) {
this->m_d3dDevice->CreateTexture( this->m_d3dDevice->CreateTexture(
32, 32,
32, 32,
@ -1257,7 +1263,7 @@ void CGxDeviceD3d::ICursorDestroy() {
void CGxDeviceD3d::CursorSetVisible(int32_t visible) { void CGxDeviceD3d::CursorSetVisible(int32_t visible) {
CGxDevice::CursorSetVisible(visible); CGxDevice::CursorSetVisible(visible);
if (this->m_hardwareCursor && this->m_context) { if (this->m_hwCursor && this->m_context) {
POINT point; POINT point;
RECT rect; RECT rect;
GetCursorPos(&point); GetCursorPos(&point);
@ -1276,15 +1282,15 @@ void CGxDeviceD3d::CursorUnlock(uint32_t x, uint32_t y) {
} }
void CGxDeviceD3d::ICursorDraw() { void CGxDeviceD3d::ICursorDraw() {
if (!this->m_hardwareCursor) { if (!this->m_hwCursor) {
this->ISceneBegin(); this->ISceneBegin();
} }
CGxDevice::ICursorDraw(); CGxDevice::ICursorDraw();
if (!this->m_hardwareCursor) { if (!this->m_hwCursor) {
this->ISceneEnd(); this->ISceneEnd();
if (!this->m_hardwareCursor) { if (!this->m_hwCursor) {
return; return;
} }
} }
@ -1312,16 +1318,19 @@ void CGxDeviceD3d::ICursorDraw() {
void CGxDeviceD3d::ISceneBegin() { void CGxDeviceD3d::ISceneBegin() {
if (!this->m_context) { if (!this->m_context) {
auto result = this->m_d3dDevice->TestCooperativeLevel(); if (this->m_d3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) {
if (result == D3DERR_DEVICENOTRESET) {
this->IReleaseD3dResources(0);
D3DPRESENT_PARAMETERS d3dpp; D3DPRESENT_PARAMETERS d3dpp;
this->IReleaseD3dResources(0);
this->ISetPresentParms(d3dpp, this->m_format); this->ISetPresentParms(d3dpp, this->m_format);
result = this->m_d3dDevice->Reset(&d3dpp); if (this->m_d3dDevice->Reset(&d3dpp) == D3D_OK) {
if (result == D3D_OK) {
this->IStateSetD3dDefaults(); this->IStateSetD3dDefaults();
// TODO: CGxDeviceD3d::ICursorClip this->ICursorClip(1);
// TODO: this->NotifyOnDeviceRestored() this->m_context = 1;
// TODO
// this->intF5C = 0;
// this->unk3ACC = 1;
// this->NotifyOnDeviceRestored();
} }
} }
} }
@ -1427,7 +1436,7 @@ void CGxDeviceD3d::ISetCaps(const CGxFormat& format) {
// Detect hardware cursor // Detect hardware cursor
this->m_caps.m_hardwareCursor = this->m_d3dCaps.CursorCaps & D3DCURSORCAPS_COLOR; this->m_caps.m_hwCursor = this->m_d3dCaps.CursorCaps & D3DCURSORCAPS_COLOR;
// Texture formats // Texture formats
@ -2191,8 +2200,9 @@ void CGxDeviceD3d::ShaderCreate(CGxShader* shaders[], EGxShTarget target, const
} }
int32_t CGxDeviceD3d::StereoEnabled() { int32_t CGxDeviceD3d::StereoEnabled() {
// TODO CGxDevice::CursorUnlock(x, y);
return 0; this->m_hwCursorNeedsUpdate = 1;
} }
void CGxDeviceD3d::XformSetProjection(const C44Matrix& matrix) { void CGxDeviceD3d::XformSetProjection(const C44Matrix& matrix) {

View file

@ -252,7 +252,6 @@ class CGxDeviceD3d : public CGxDevice {
virtual void ICursorDestroy(); virtual void ICursorDestroy();
virtual void ICursorDraw(); virtual void ICursorDraw();
virtual void CursorSetVisible(int32_t visible); virtual void CursorSetVisible(int32_t visible);
virtual void CursorUnlock(uint32_t x, uint32_t y);
virtual int32_t DeviceCreate(int32_t (*windowProc)(void* window, uint32_t message, uintptr_t wparam, intptr_t lparam), const CGxFormat& format); virtual int32_t DeviceCreate(int32_t (*windowProc)(void* window, uint32_t message, uintptr_t wparam, intptr_t lparam), const CGxFormat& format);
virtual int32_t DeviceSetFormat(const CGxFormat& format); virtual int32_t DeviceSetFormat(const CGxFormat& format);
virtual void* DeviceWindow(); virtual void* DeviceWindow();
@ -270,6 +269,7 @@ class CGxDeviceD3d : public CGxDevice {
virtual void IShaderCreate(CGxShader* shader); virtual void IShaderCreate(CGxShader* shader);
virtual void ShaderCreate(CGxShader* shaders[], EGxShTarget target, const char* a4, const char* a5, int32_t permutations); virtual void ShaderCreate(CGxShader* shaders[], EGxShTarget target, const char* a4, const char* a5, int32_t permutations);
virtual int32_t StereoEnabled(); virtual int32_t StereoEnabled();
virtual void CursorUnlock(uint32_t x, uint32_t y);
// Member functions // Member functions
CGxDeviceD3d(); CGxDeviceD3d();
@ -283,6 +283,7 @@ class CGxDeviceD3d : public CGxDevice {
LPDIRECT3DVERTEXBUFFER9 ICreateD3dVB(EGxPoolUsage usage, uint32_t size); LPDIRECT3DVERTEXBUFFER9 ICreateD3dVB(EGxPoolUsage usage, uint32_t size);
LPDIRECT3DVERTEXDECLARATION9 ICreateD3dVertexDecl(D3DVERTEXELEMENT9 elements[], uint32_t count); LPDIRECT3DVERTEXDECLARATION9 ICreateD3dVertexDecl(D3DVERTEXELEMENT9 elements[], uint32_t count);
bool ICreateWindow(CGxFormat& format); bool ICreateWindow(CGxFormat& format);
void ICursorClip(int32_t a1);
void ISetPresentParms(D3DPRESENT_PARAMETERS& d3dpp, const CGxFormat& format); void ISetPresentParms(D3DPRESENT_PARAMETERS& d3dpp, const CGxFormat& format);
void IDestroyD3d(); void IDestroyD3d();
void IDestroyD3dDevice(); void IDestroyD3dDevice();