From 1457cdae16f966864c34c126a2eac136ca5beb1f Mon Sep 17 00:00:00 2001 From: Nusan Date: Fri, 24 Mar 2023 10:10:13 +0100 Subject: [PATCH] Fix GLFW issue with texPreviousFrame not working after a lot of window resizing --- README.md | 1 + src/platform_glfw/Renderer.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eccbb30..cb39703 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,7 @@ As you can see you're gonna need [CMAKE](https://cmake.org/) for this, but don't ### Windows Use at least [Visual C++ 2010](https://support.microsoft.com/ru-ru/help/2977003/the-latest-supported-visual-c-downloads). For the DX9/DX11 builds, obviously you'll be needing a [DirectX SDK](https://www.microsoft.com/en-us/download/details.aspx?id=6812), though a lot of it is already in the Windows 8.1 SDK as well. +You will need to install NDI SDK and install Visual Studio with components ATL and MFC Then: mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release ../ diff --git a/src/platform_glfw/Renderer.cpp b/src/platform_glfw/Renderer.cpp index 6e8af51..c5fe780 100644 --- a/src/platform_glfw/Renderer.cpp +++ b/src/platform_glfw/Renderer.cpp @@ -735,6 +735,7 @@ namespace Renderer }; int textureUnit = 0; + int RGBA8_textureUnit = -1; Texture * CreateRGBA8Texture() { @@ -752,12 +753,19 @@ namespace Renderer glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + if (RGBA8_textureUnit < 0) + { + // Reuse the same textureUnit instead of using a new one each time + // this solve the issue with recreating the previous frame buffer each time you resize the screen + RGBA8_textureUnit = textureUnit++; + } + GLTexture * tex = new GLTexture(); tex->width = nWidth; tex->height = nHeight; tex->ID = glTexId; tex->type = TEXTURETYPE_2D; - tex->unit = textureUnit++; + tex->unit = RGBA8_textureUnit; return tex; }