GUI: DirectX 11 render backend, part 2

This commit is contained in:
tildearrow 2023-06-12 19:43:26 -05:00
parent 2c912da89a
commit cf144f4fe9
5 changed files with 33 additions and 5 deletions

View file

@ -3420,6 +3420,7 @@ bool FurnaceGUI::loop() {
logV("portrait: %d (%dx%d)",portrait,scrW,scrH);
logD("window resized to %dx%d",scrW,scrH);
updateWindow=true;
rend->resized(ev);
break;
case SDL_WINDOWEVENT_MOVED:
scrX=ev.window.data1;
@ -5824,8 +5825,8 @@ bool FurnaceGUI::loop() {
}
}
}
rend->present();
drawTimeEnd=SDL_GetPerformanceCounter();
rend->present();
if (settings.renderClearPos) {
rend->clear(uiColors[GUI_COLOR_BACKGROUND]);
}

View file

@ -1248,6 +1248,7 @@ class FurnaceGUIRender {
virtual bool destroyTexture(void* which);
virtual void setTextureBlendMode(void* which, FurnaceGUIBlendMode mode);
virtual void setBlendMode(FurnaceGUIBlendMode mode);
virtual void resized(const SDL_Event& ev);
virtual void clear(ImVec4 color);
virtual bool newFrame();
virtual void createFontsTexture();

View file

@ -49,6 +49,9 @@ void FurnaceGUIRender::setTextureBlendMode(void* which, FurnaceGUIBlendMode mode
void FurnaceGUIRender::setBlendMode(FurnaceGUIBlendMode mode) {
}
void FurnaceGUIRender::resized(const SDL_Event& ev) {
}
void FurnaceGUIRender::clear(ImVec4 color) {
}
@ -97,4 +100,4 @@ void FurnaceGUIRender::quitGUI() {
}
FurnaceGUIRender::~FurnaceGUIRender() {
}
}

View file

@ -48,6 +48,15 @@ bool FurnaceGUIRenderDX11::createRenderTarget() {
return false;
}
DXGI_SWAP_CHAIN_DESC chainDesc;
memset(&chainDesc,0,sizeof(chainDesc));
if (swapchain->GetDesc(&chainDesc)!=S_OK) {
logW("createRenderTarget: could not get swapchain desc!");
} else {
outW=chainDesc.BufferDesc.Width;
outH=chainDesc.BufferDesc.Height;
}
result=swapchain->GetBuffer(0,IID_PPV_ARGS(&screen));
if (result!=S_OK) {
logW("createRenderTarget: could not get buffer! %.8x",result);
@ -103,6 +112,15 @@ void FurnaceGUIRenderDX11::setTextureBlendMode(void* which, FurnaceGUIBlendMode
void FurnaceGUIRenderDX11::setBlendMode(FurnaceGUIBlendMode mode) {
}
void FurnaceGUIRenderDX11::resized(const SDL_Event& ev) {
destroyRenderTarget();
swapchain->ResizeBuffers(0,0,0,DXGI_FORMAT_UNKNOWN,0);
createRenderTarget();
}
void FurnaceGUIRenderDX11::clear(ImVec4 color) {
float floatColor[4]={
color.x*color.w,
@ -141,7 +159,9 @@ void FurnaceGUIRenderDX11::present() {
}
bool FurnaceGUIRenderDX11::getOutputSize(int& w, int& h) {
return false;
w=outW;
h=outH;
return true;
}
int FurnaceGUIRenderDX11::getWindowFlags() {

View file

@ -31,8 +31,8 @@ class FurnaceGUIRenderDX11: public FurnaceGUIRender {
ID3D11DeviceContext* context;
ID3D11RenderTargetView* renderTarget;
IDXGISwapChain* swapchain;
int outW, outH;
float quadVertex[4][3];
unsigned int quadBuf;
bool destroyRenderTarget();
bool createRenderTarget();
@ -46,6 +46,7 @@ class FurnaceGUIRenderDX11: public FurnaceGUIRender {
bool destroyTexture(void* which);
void setTextureBlendMode(void* which, FurnaceGUIBlendMode mode);
void setBlendMode(FurnaceGUIBlendMode mode);
void resized(const SDL_Event& ev);
void clear(ImVec4 color);
bool newFrame();
void createFontsTexture();
@ -64,7 +65,9 @@ class FurnaceGUIRenderDX11: public FurnaceGUIRender {
device(NULL),
context(NULL),
renderTarget(NULL),
swapchain(NULL) {
swapchain(NULL),
outW(0),
outH(0) {
memset(quadVertex,0,4*3*sizeof(float));
}
};