From a56924b22f4a73a25010f0f76f5286046dba8dc7 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 9 Apr 2023 16:49:52 +0900 Subject: [PATCH] internal/graphicsdriver/directx: refactoring --- .../graphicsdriver/directx/graphics11_windows.go | 16 +++++++--------- .../graphicsdriver/directx/graphics12_windows.go | 9 ++++----- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/internal/graphicsdriver/directx/graphics11_windows.go b/internal/graphicsdriver/directx/graphics11_windows.go index 4d4f9cbf9..a8ccb3679 100644 --- a/internal/graphicsdriver/directx/graphics11_windows.go +++ b/internal/graphicsdriver/directx/graphics11_windows.go @@ -385,19 +385,17 @@ func (g *graphics11) NewImage(width, height int) (graphicsdriver.Image, error) { } func (g *graphics11) NewScreenFramebufferImage(width, height int) (graphicsdriver.Image, error) { - var origWidth, origHeight int + imageWidth := width + imageHeight := height if g.screenImage != nil { - origWidth, origHeight = g.screenImage.width, g.screenImage.height + imageWidth = g.screenImage.width + imageHeight = g.screenImage.height g.screenImage.Dispose() g.screenImage = nil } if g.graphicsInfra.isSwapChainInited() { - // For a new image11 instance, use the original image size now. - // Use the new image size when a swap chain is actually resized. - newWidth, newHeight := width, height - width, height = origWidth, origHeight - g.newScreenWidth, g.newScreenHeight = newWidth, newHeight + g.newScreenWidth, g.newScreenHeight = width, height } else { if err := g.graphicsInfra.initSwapChain(width, height, unsafe.Pointer(g.device), g.window); err != nil { return nil, err @@ -412,8 +410,8 @@ func (g *graphics11) NewScreenFramebufferImage(width, height int) (graphicsdrive i := &image11{ graphics: g, id: g.genNextImageID(), - width: width, - height: height, + width: imageWidth, + height: imageHeight, screen: true, texture: (*_ID3D11Texture2D)(t), } diff --git a/internal/graphicsdriver/directx/graphics12_windows.go b/internal/graphicsdriver/directx/graphics12_windows.go index 506e29e62..b8ea7b838 100644 --- a/internal/graphicsdriver/directx/graphics12_windows.go +++ b/internal/graphicsdriver/directx/graphics12_windows.go @@ -990,14 +990,13 @@ func (g *graphics12) NewImage(width, height int) (graphicsdriver.Image, error) { } func (g *graphics12) NewScreenFramebufferImage(width, height int) (graphicsdriver.Image, error) { - var imageWidth, imageHeight int + imageWidth := width + imageHeight := height if g.screenImage != nil { - imageWidth, imageHeight = g.screenImage.width, g.screenImage.height + imageWidth = g.screenImage.width + imageHeight = g.screenImage.height g.screenImage.Dispose() g.screenImage = nil - } else { - imageWidth = width - imageHeight = height } if err := g.updateSwapChain(width, height); err != nil {