[wpigui] Handle Direct3D framebuffer resize

This commit is contained in:
Peter Johnson
2020-08-29 22:32:32 -07:00
parent 4cf6947af7
commit 183b7c85a1
5 changed files with 19 additions and 0 deletions

View File

@@ -38,6 +38,10 @@ static void WindowSizeCallback(GLFWwindow* window, int width, int height) {
}
}
static void FramebufferSizeCallback(GLFWwindow* window, int width, int height) {
PlatformFramebufferSizeChanged(width, height);
}
static void WindowMaximizeCallback(GLFWwindow* window, int maximized) {
gContext->maximized = maximized;
}
@@ -197,6 +201,7 @@ bool gui::Initialize(const char* title, int width, int height) {
// Set window callbacks
glfwGetWindowSize(gContext->window, &gContext->width, &gContext->height);
glfwSetWindowSizeCallback(gContext->window, WindowSizeCallback);
glfwSetFramebufferSizeCallback(gContext->window, FramebufferSizeCallback);
glfwSetWindowMaximizeCallback(gContext->window, WindowMaximizeCallback);
glfwSetWindowPosCallback(gContext->window, WindowPosCallback);

View File

@@ -152,6 +152,15 @@ void gui::PlatformShutdown() {
ImGui_ImplDX11_Shutdown();
}
void gui::PlatformFramebufferSizeChanged(int width, int height) {
if (gPlatformContext && gPlatformContext->pd3dDevice) {
CleanupRenderTarget();
gPlatformContext->pSwapChain->ResizeBuffers(0, width, height,
DXGI_FORMAT_UNKNOWN, 0);
CreateRenderTarget();
}
}
static inline DXGI_FORMAT DXPixelFormat(PixelFormat format) {
switch (format) {
case kPixelRGBA:

View File

@@ -67,6 +67,7 @@ void PlatformGlfwWindowHints();
bool PlatformInitRenderer();
void PlatformRenderFrame();
void PlatformShutdown();
void PlatformFramebufferSizeChanged(int width, int height);
void CommonRenderFrame();

View File

@@ -107,6 +107,8 @@ void gui::PlatformShutdown() {
gPlatformValid = false;
}
void gui::PlatformFramebufferSizeChanged(int, int) {}
static inline MTLPixelFormat MetalPixelFormat(PixelFormat format) {
switch (format) {
case kPixelRGBA:

View File

@@ -99,6 +99,8 @@ void gui::PlatformShutdown() {
ImGui_ImplOpenGL3_Shutdown();
}
void gui::PlatformFramebufferSizeChanged(int width, int height) {}
static inline GLenum GLPixelFormat(PixelFormat format) {
switch (format) {
case kPixelRGBA: