From 63345a3098e05e0d0692bc46852dfbfccfdcfae2 Mon Sep 17 00:00:00 2001 From: gdk Date: Thu, 31 Oct 2019 21:32:43 -0300 Subject: [PATCH] Support window resizing --- Ryujinx.Graphics.GAL/IWindow.cs | 4 +- Ryujinx.Graphics.OpenGL/Window.cs | 98 +++++++++++++++++++++++-------- Ryujinx/Ui/GLScreen.cs | 2 +- 3 files changed, 78 insertions(+), 26 deletions(-) diff --git a/Ryujinx.Graphics.GAL/IWindow.cs b/Ryujinx.Graphics.GAL/IWindow.cs index a0e5f196c..3d5130c29 100644 --- a/Ryujinx.Graphics.GAL/IWindow.cs +++ b/Ryujinx.Graphics.GAL/IWindow.cs @@ -1,5 +1,3 @@ -using System; - namespace Ryujinx.Graphics.GAL { public interface IWindow @@ -9,5 +7,7 @@ namespace Ryujinx.Graphics.GAL void QueueTexture(ITexture texture, ImageCrop crop, object context); void RegisterTextureReleaseCallback(TextureReleaseCallback callback); + + void SetSize(int width, int height); } } diff --git a/Ryujinx.Graphics.OpenGL/Window.cs b/Ryujinx.Graphics.OpenGL/Window.cs index a05eb1c0b..3fe83dd1c 100644 --- a/Ryujinx.Graphics.OpenGL/Window.cs +++ b/Ryujinx.Graphics.OpenGL/Window.cs @@ -10,8 +10,15 @@ namespace Ryujinx.Graphics.OpenGL private const int NativeWidth = 1280; private const int NativeHeight = 720; - private int _width = 1280; - private int _height = 720; + private int _width; + private int _height; + + private int _resizeWidth; + private int _resizeHeight; + + private bool _sizeChanged; + + private object _resizeLocker; private int _blitFramebufferHandle; private int _copyFramebufferHandle; @@ -40,6 +47,11 @@ namespace Ryujinx.Graphics.OpenGL public Window() { + _width = NativeWidth; + _height = NativeHeight; + + _resizeLocker = new object(); + _textures = new Queue(); } @@ -59,15 +71,18 @@ namespace Ryujinx.Graphics.OpenGL GL.Clear(ClearBufferMask.ColorBufferBit); + int windowWidth = _width; + int windowHeight = _height; + GL.BlitFramebuffer( 0, 0, - 1280, - 720, + windowWidth, + windowHeight, 0, 0, - 1280, - 720, + windowWidth, + windowHeight, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear); @@ -184,6 +199,17 @@ namespace Ryujinx.Graphics.OpenGL _release = callback; } + public void SetSize(int width, int height) + { + lock (_resizeLocker) + { + _resizeWidth = width; + _resizeHeight = height; + + _sizeChanged = true; + } + } + private void Release(object context) { if (_release != null) @@ -210,24 +236,9 @@ namespace Ryujinx.Graphics.OpenGL { int handle = _copyFramebufferHandle; - if (handle == 0) + void GenerateAndBindTexture() { - int textureHandle = GL.GenTexture(); - - GL.BindTexture(TextureTarget.Texture2D, textureHandle); - - GL.TexImage2D( - TextureTarget.Texture2D, - 0, - PixelInternalFormat.Rgba8, - 1280, - 720, - 0, - PixelFormat.Rgba, - PixelType.UnsignedByte, - IntPtr.Zero); - - handle = GL.GenFramebuffer(); + int textureHandle = GenerateWindowTexture(); GL.BindFramebuffer(FramebufferTarget.Framebuffer, handle); @@ -238,9 +249,50 @@ namespace Ryujinx.Graphics.OpenGL 0); _screenTextureHandle = textureHandle; + } + + if (handle == 0) + { + handle = GL.GenFramebuffer(); _copyFramebufferHandle = handle; + + GenerateAndBindTexture(); } + else if (_sizeChanged) + { + GL.DeleteTexture(_screenTextureHandle); + + lock (_resizeLocker) + { + _width = _resizeWidth; + _height = _resizeHeight; + + _sizeChanged = false; + } + + GenerateAndBindTexture(); + } + + return handle; + } + + private int GenerateWindowTexture() + { + int handle = GL.GenTexture(); + + GL.BindTexture(TextureTarget.Texture2D, handle); + + GL.TexImage2D( + TextureTarget.Texture2D, + 0, + PixelInternalFormat.Rgba8, + _width, + _height, + 0, + PixelFormat.Rgba, + PixelType.UnsignedByte, + IntPtr.Zero); return handle; } diff --git a/Ryujinx/Ui/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs index dc887534b..6d1060ee6 100644 --- a/Ryujinx/Ui/GLScreen.cs +++ b/Ryujinx/Ui/GLScreen.cs @@ -91,7 +91,7 @@ namespace Ryujinx.Ui { _resizeEvent = false; - // TODO: Resize + _renderer.Window.SetSize(Width, Height); } ticks += chrono.ElapsedTicks;