so we need to destroy textures

This commit is contained in:
tildearrow 2024-05-15 18:36:23 -05:00
parent 8905a48361
commit d00cdabe6e
2 changed files with 35 additions and 12 deletions

View file

@ -45,6 +45,11 @@ class FurnaceDX9Texture: public FurnaceGUITexture {
dynamic(false) {}
};
struct FurnaceGUIRenderDX9Private {
D3DPRESENT_PARAMETERS present;
std::vector<FurnaceDX9Texture*> texPool;
};
struct WipeVertex {
float x, y, z;
unsigned int color;
@ -223,13 +228,23 @@ FurnaceGUITexture* FurnaceGUIRenderDX9::createTexture(bool dynamic, int width, i
ret->texPre=texPre;
ret->dynamic=dynamic;
ret->format=format;
priv->texPool.push_back(ret);
return ret;
}
bool FurnaceGUIRenderDX9::destroyTexture(FurnaceGUITexture* which) {
FurnaceDX9Texture* t=(FurnaceDX9Texture*)which;
t->tex->Release();
if (t->texPre!=NULL) t->texPre->Release();
if (t->tex!=NULL) t->tex->Release();
delete t;
for (size_t i=0; i<priv->texPool.size(); i++) {
if (priv->texPool[i]==t) {
priv->texPool.erase(priv->texPool.begin()+i);
break;
}
}
return true;
}
@ -246,15 +261,32 @@ void FurnaceGUIRenderDX9::resized(const SDL_Event& ev) {
}
void FurnaceGUIRenderDX9::clear(ImVec4 color) {
device->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,ImGui::ColorConvertFloat4ToU32(color),0,0);
}
void FurnaceGUIRenderDX9::present() {
device->Present(NULL,NULL,NULL,NULL);
if (mustResize) {
logI("DX9: resizing buffers");
ImGui_ImplDX9_InvalidateDeviceObjects();
if (wipeBuf!=NULL) {
if (wipeBuf) {
wipeBuf->Release();
wipeBuf=NULL;
}
for (FurnaceDX9Texture* i: priv->texPool) {
if (i->tex) {
i->tex->Release();
i->tex=NULL;
}
if (i->texPre) {
i->texPre->Release();
i->texPre=NULL;
}
}
priv->present.BackBufferWidth=outW;
priv->present.BackBufferHeight=outH;
priv->present.BackBufferCount=1;
@ -276,12 +308,6 @@ void FurnaceGUIRenderDX9::clear(ImVec4 color) {
mustResize=false;
}
device->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,ImGui::ColorConvertFloat4ToU32(color),0,0);
}
void FurnaceGUIRenderDX9::present() {
device->Present(NULL,NULL,NULL,NULL);
}
bool FurnaceGUIRenderDX9::newFrame() {

View file

@ -20,10 +20,7 @@
#include "../gui.h"
#ifdef INCLUDE_D3D9
#include <d3d9.h>
struct FurnaceGUIRenderDX9Private {
D3DPRESENT_PARAMETERS present;
};
struct FurnaceGUIRenderDX9Private;
#else
typedef void IDirect3D9;
typedef void IDirect3DVertexBuffer9;