This commit is contained in:
tildearrow 2024-05-16 03:02:45 -05:00
parent 05fe5270cd
commit 7413a15369
3 changed files with 89 additions and 45 deletions

View file

@ -175,6 +175,7 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
} }
// Backup the DX9 state // Backup the DX9 state
/*
IDirect3DStateBlock9* d3d9_state_block = nullptr; IDirect3DStateBlock9* d3d9_state_block = nullptr;
if (bd->pd3dDevice->CreateStateBlock(D3DSBT_ALL, &d3d9_state_block) < 0) if (bd->pd3dDevice->CreateStateBlock(D3DSBT_ALL, &d3d9_state_block) < 0)
return; return;
@ -182,26 +183,28 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
{ {
d3d9_state_block->Release(); d3d9_state_block->Release();
return; return;
} }*/
// Backup the DX9 transform (DX9 documentation suggests that it is included in the StateBlock but it doesn't appear to) // 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; D3DMATRIX last_world, last_view, last_projection;
bd->pd3dDevice->GetTransform(D3DTS_WORLD, &last_world); bd->pd3dDevice->GetTransform(D3DTS_WORLD, &last_world);
bd->pd3dDevice->GetTransform(D3DTS_VIEW, &last_view); bd->pd3dDevice->GetTransform(D3DTS_VIEW, &last_view);
bd->pd3dDevice->GetTransform(D3DTS_PROJECTION, &last_projection); bd->pd3dDevice->GetTransform(D3DTS_PROJECTION, &last_projection);
*/
// Allocate buffers // Allocate buffers
CUSTOMVERTEX* vtx_dst; CUSTOMVERTEX* vtx_dst;
ImDrawIdx* idx_dst; ImDrawIdx* idx_dst;
if (bd->pVB->Lock(0, (UINT)(draw_data->TotalVtxCount * sizeof(CUSTOMVERTEX)), (void**)&vtx_dst, D3DLOCK_DISCARD) < 0) 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; return;
} }
if (bd->pIB->Lock(0, (UINT)(draw_data->TotalIdxCount * sizeof(ImDrawIdx)), (void**)&idx_dst, D3DLOCK_DISCARD) < 0) if (bd->pIB->Lock(0, (UINT)(draw_data->TotalIdxCount * sizeof(ImDrawIdx)), (void**)&idx_dst, D3DLOCK_DISCARD) < 0)
{ {
bd->pVB->Unlock(); bd->pVB->Unlock();
d3d9_state_block->Release(); //d3d9_state_block->Release();
return; return;
} }
@ -282,13 +285,18 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
bd->pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, 0); bd->pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, 0);
// Restore the DX9 transform // Restore the DX9 transform
// don't. I like this transform.
/*
bd->pd3dDevice->SetTransform(D3DTS_WORLD, &last_world); bd->pd3dDevice->SetTransform(D3DTS_WORLD, &last_world);
bd->pd3dDevice->SetTransform(D3DTS_VIEW, &last_view); bd->pd3dDevice->SetTransform(D3DTS_VIEW, &last_view);
bd->pd3dDevice->SetTransform(D3DTS_PROJECTION, &last_projection); bd->pd3dDevice->SetTransform(D3DTS_PROJECTION, &last_projection);
*/
// Restore the DX9 state // Restore the DX9 state
/*
d3d9_state_block->Apply(); d3d9_state_block->Apply();
d3d9_state_block->Release(); d3d9_state_block->Release();
*/
} }
bool ImGui_ImplDX9_Init(IDirect3DDevice9* device) bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)

View file

@ -271,10 +271,15 @@ void FurnaceGUIRenderDX9::clear(ImVec4 color) {
} }
void FurnaceGUIRenderDX9::present() { void FurnaceGUIRenderDX9::present() {
if (inScene) {
device->EndScene();
inScene=false;
}
if (device->Present(NULL,NULL,NULL,NULL)==D3DERR_DEVICEREMOVED) { if (device->Present(NULL,NULL,NULL,NULL)==D3DERR_DEVICEREMOVED) {
logI("device is gone"); logI("device is gone");
dead=true; dead=true;
return false; return;
} }
if (mustResize) { if (mustResize) {
@ -340,56 +345,86 @@ void FurnaceGUIRenderDX9::destroyFontsTexture() {
} }
void FurnaceGUIRenderDX9::renderGUI() { void FurnaceGUIRenderDX9::renderGUI() {
HRESULT result=device->BeginScene(); if (!inScene) {
if (result==D3D_OK) { HRESULT result=device->BeginScene();
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); if (result!=D3D_OK) {
device->EndScene(); logW("couldn't render GUI! %.8x",result);
} else { return;
logW("couldn't render GUI! %.8x",result); }
inScene=true;
} }
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
} }
void FurnaceGUIRenderDX9::wipe(float alpha) { void FurnaceGUIRenderDX9::wipe(float alpha) {
if (wipeBuf==NULL) return; if (wipeBuf==NULL) return;
/* logV("WIPE...");
HRESULT result=device->BeginScene(); if (!inScene) {
if (result==D3D_OK) { HRESULT result=device->BeginScene();
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 (result!=D3D_OK) { if (result!=D3D_OK) {
logW("could not set viewport! %.8x",result); logW("couldn't render GUI! %.8x",result);
return;
} }
inScene=true;
unsigned int color=alpha*255; }
void* lockedData; D3DVIEWPORT9 view;
WipeVertex vertex[4]; view.X=0;
vertex[0]=WipeVertex(0,0,0,color); view.Y=0;
vertex[1]=WipeVertex(outW,0,0,color); view.Width=outW;
vertex[2]=WipeVertex(outW,outH,0,color); view.Height=outH;
vertex[3]=WipeVertex(0,outH,0,color); view.MinZ=0.0f;
view.MaxZ=1.0f;
result=wipeBuf->Lock(0,0,&lockedData,D3DLOCK_DISCARD); HRESULT result=device->SetViewport(&view);
if (result==D3D_OK) { if (result!=D3D_OK) {
memcpy(lockedData,vertex,sizeof(WipeVertex)*4); logW("could not set viewport! %.8x",result);
wipeBuf->Unlock(); }
device->SetStreamSource(0,wipeBuf,0,sizeof(WipeVertex)); unsigned char alphaU=alpha*255.0f;
device->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE); unsigned int color=alphaU<<24;
device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,1);
} void* lockedData;
WipeVertex vertex[4];
device->EndScene(); 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) { bool FurnaceGUIRenderDX9::getOutputSize(int& w, int& h) {

View file

@ -35,7 +35,7 @@ class FurnaceGUIRenderDX9: public FurnaceGUIRender {
int outW, outH, swapInterval; int outW, outH, swapInterval;
bool dead, haveScene, supportsDynamicTex, supportsVSync, mustResize, squareTex; bool dead, haveScene, supportsDynamicTex, supportsVSync, mustResize, squareTex, inScene;
// SHADERS // // SHADERS //
@ -94,6 +94,7 @@ class FurnaceGUIRenderDX9: public FurnaceGUIRender {
supportsVSync(false), supportsVSync(false),
mustResize(false), mustResize(false),
squareTex(false), squareTex(false),
inScene(false),
maxWidth(8192), maxWidth(8192),
maxHeight(8192) { maxHeight(8192) {
} }