From 7413a1536934b24a7232b33171999f439a8033c9 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 16 May 2024 03:02:45 -0500 Subject: [PATCH] WIPE! --- .../imgui_patched/backends/imgui_impl_dx9.cpp | 14 ++- src/gui/render/renderDX9.cpp | 117 ++++++++++++------ src/gui/render/renderDX9.h | 3 +- 3 files changed, 89 insertions(+), 45 deletions(-) diff --git a/extern/imgui_patched/backends/imgui_impl_dx9.cpp b/extern/imgui_patched/backends/imgui_impl_dx9.cpp index d39f2a22e..90dbd168a 100644 --- a/extern/imgui_patched/backends/imgui_impl_dx9.cpp +++ b/extern/imgui_patched/backends/imgui_impl_dx9.cpp @@ -175,6 +175,7 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data) } // Backup the DX9 state + /* IDirect3DStateBlock9* d3d9_state_block = nullptr; if (bd->pd3dDevice->CreateStateBlock(D3DSBT_ALL, &d3d9_state_block) < 0) return; @@ -182,26 +183,28 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data) { d3d9_state_block->Release(); return; - } + }*/ // Backup the DX9 transform (DX9 documentation suggests that it is included in the StateBlock but it doesn't appear to) + /* D3DMATRIX last_world, last_view, last_projection; bd->pd3dDevice->GetTransform(D3DTS_WORLD, &last_world); bd->pd3dDevice->GetTransform(D3DTS_VIEW, &last_view); bd->pd3dDevice->GetTransform(D3DTS_PROJECTION, &last_projection); + */ // Allocate buffers CUSTOMVERTEX* vtx_dst; ImDrawIdx* idx_dst; if (bd->pVB->Lock(0, (UINT)(draw_data->TotalVtxCount * sizeof(CUSTOMVERTEX)), (void**)&vtx_dst, D3DLOCK_DISCARD) < 0) { - d3d9_state_block->Release(); + //d3d9_state_block->Release(); return; } if (bd->pIB->Lock(0, (UINT)(draw_data->TotalIdxCount * sizeof(ImDrawIdx)), (void**)&idx_dst, D3DLOCK_DISCARD) < 0) { bd->pVB->Unlock(); - d3d9_state_block->Release(); + //d3d9_state_block->Release(); return; } @@ -282,13 +285,18 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data) bd->pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, 0); // Restore the DX9 transform + // don't. I like this transform. + /* bd->pd3dDevice->SetTransform(D3DTS_WORLD, &last_world); bd->pd3dDevice->SetTransform(D3DTS_VIEW, &last_view); bd->pd3dDevice->SetTransform(D3DTS_PROJECTION, &last_projection); + */ // Restore the DX9 state + /* d3d9_state_block->Apply(); d3d9_state_block->Release(); + */ } bool ImGui_ImplDX9_Init(IDirect3DDevice9* device) diff --git a/src/gui/render/renderDX9.cpp b/src/gui/render/renderDX9.cpp index 8642f15d4..cd09562ac 100644 --- a/src/gui/render/renderDX9.cpp +++ b/src/gui/render/renderDX9.cpp @@ -271,10 +271,15 @@ void FurnaceGUIRenderDX9::clear(ImVec4 color) { } void FurnaceGUIRenderDX9::present() { + if (inScene) { + device->EndScene(); + inScene=false; + } + if (device->Present(NULL,NULL,NULL,NULL)==D3DERR_DEVICEREMOVED) { logI("device is gone"); dead=true; - return false; + return; } if (mustResize) { @@ -340,56 +345,86 @@ void FurnaceGUIRenderDX9::destroyFontsTexture() { } void FurnaceGUIRenderDX9::renderGUI() { - HRESULT result=device->BeginScene(); - if (result==D3D_OK) { - ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); - device->EndScene(); - } else { - logW("couldn't render GUI! %.8x",result); + if (!inScene) { + HRESULT result=device->BeginScene(); + if (result!=D3D_OK) { + logW("couldn't render GUI! %.8x",result); + return; + } + inScene=true; } + + ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); } void FurnaceGUIRenderDX9::wipe(float alpha) { if (wipeBuf==NULL) return; - /* + logV("WIPE..."); - HRESULT result=device->BeginScene(); - if (result==D3D_OK) { - D3DVIEWPORT9 view; - view.X=0; - view.Y=0; - view.Width=outW; - view.Height=outH; - view.MinZ=0.0f; - view.MaxZ=1.0f; - result=device->SetViewport(&view); + if (!inScene) { + HRESULT result=device->BeginScene(); if (result!=D3D_OK) { - logW("could not set viewport! %.8x",result); + logW("couldn't render GUI! %.8x",result); + return; } - - unsigned int color=alpha*255; - - void* lockedData; - WipeVertex vertex[4]; - vertex[0]=WipeVertex(0,0,0,color); - vertex[1]=WipeVertex(outW,0,0,color); - vertex[2]=WipeVertex(outW,outH,0,color); - vertex[3]=WipeVertex(0,outH,0,color); - - result=wipeBuf->Lock(0,0,&lockedData,D3DLOCK_DISCARD); - if (result==D3D_OK) { - memcpy(lockedData,vertex,sizeof(WipeVertex)*4); - wipeBuf->Unlock(); - - device->SetStreamSource(0,wipeBuf,0,sizeof(WipeVertex)); - device->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE); - device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,1); - } - - device->EndScene(); + inScene=true; + } + + D3DVIEWPORT9 view; + view.X=0; + view.Y=0; + view.Width=outW; + view.Height=outH; + view.MinZ=0.0f; + view.MaxZ=1.0f; + HRESULT result=device->SetViewport(&view); + if (result!=D3D_OK) { + logW("could not set viewport! %.8x",result); + } + + unsigned char alphaU=alpha*255.0f; + unsigned int color=alphaU<<24; + + void* lockedData; + WipeVertex vertex[4]; + vertex[0]=WipeVertex(0,0,0,color); + vertex[1]=WipeVertex(outW,0,0,color); + vertex[2]=WipeVertex(outW,outH,0,color); + vertex[3]=WipeVertex(0,outH,0,color); + + result=wipeBuf->Lock(0,0,&lockedData,D3DLOCK_DISCARD); + if (result==D3D_OK) { + memcpy(lockedData,vertex,sizeof(WipeVertex)*4); + wipeBuf->Unlock(); + + result=device->SetRenderState(D3DRS_SCISSORTESTENABLE,FALSE); + if (result!=D3D_OK) { + logE("SHIT! scissor, %.8x",result); + } + result=device->SetTexture(0,NULL); + if (result!=D3D_OK) { + logE("SHIT! set texture, %.8x",result); + } + result=device->SetStreamSource(0,wipeBuf,0,sizeof(WipeVertex)); + if (result!=D3D_OK) { + logE("SHIT! set stream source, %.8x",result); + } + result=device->SetTexture(0,NULL); + if (result!=D3D_OK) { + logE("SHIT! set texture, %.8x",result); + } + result=device->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE); + if (result!=D3D_OK) { + logE("SHIT! set FVF, %.8x",result); + } + result=device->DrawPrimitive(D3DPT_TRIANGLEFAN,0,2); + if (result!=D3D_OK) { + logE("SHIT! draw primitive, %.8x",result); + } + } else { + logE("SHIT! lock, %.8x",result); } - */ } bool FurnaceGUIRenderDX9::getOutputSize(int& w, int& h) { diff --git a/src/gui/render/renderDX9.h b/src/gui/render/renderDX9.h index e9a8bef25..3d46326e8 100644 --- a/src/gui/render/renderDX9.h +++ b/src/gui/render/renderDX9.h @@ -35,7 +35,7 @@ class FurnaceGUIRenderDX9: public FurnaceGUIRender { int outW, outH, swapInterval; - bool dead, haveScene, supportsDynamicTex, supportsVSync, mustResize, squareTex; + bool dead, haveScene, supportsDynamicTex, supportsVSync, mustResize, squareTex, inScene; // SHADERS // @@ -94,6 +94,7 @@ class FurnaceGUIRenderDX9: public FurnaceGUIRender { supportsVSync(false), mustResize(false), squareTex(false), + inScene(false), maxWidth(8192), maxHeight(8192) { }