From df27ce9a441e65e36a22b0bb815f1397f9e7ac93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 14 Jan 2018 09:57:27 -0500 Subject: [PATCH 1/1] gamnit: don't touch the dynamic_resolution FBO if it is not used MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/gamnit/dynamic_resolution.nit | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/gamnit/dynamic_resolution.nit b/lib/gamnit/dynamic_resolution.nit index c0a2081..c783e97 100644 --- a/lib/gamnit/dynamic_resolution.nit +++ b/lib/gamnit/dynamic_resolution.nit @@ -54,6 +54,20 @@ redef class App private var perf_clock_dynamic_resolution = new Clock is lazy + # Real screen framebuffer + private var screen_framebuffer_cache: Int = -1 + + # Real screen framebuffer name + fun screen_framebuffer: Int + do + var cache = screen_framebuffer_cache + if cache != -1 then return cache + + cache = glGetIntegerv(gl_FRAMEBUFFER_BINDING, 0) + self.screen_framebuffer_cache = cache + return cache + end + redef fun create_gamnit do super @@ -68,7 +82,7 @@ redef class App redef fun on_resize(display) do - dynamic_context.resize(display, max_dynamic_resolution_ratio) + if dynamic_context_cache != null then dynamic_context.resize(display, max_dynamic_resolution_ratio) super end @@ -79,7 +93,7 @@ redef class App if dynamic_resolution_ratio == 1.0 then # Draw directly to the screen framebuffer - glBindFramebuffer(gl_FRAMEBUFFER, dynamic_context.screen_framebuffer) + glBindFramebuffer(gl_FRAMEBUFFER, screen_framebuffer) glViewport(0, 0, display.width, display.height) glClear gl_COLOR_BUFFER_BIT | gl_DEPTH_BUFFER_BIT @@ -111,7 +125,7 @@ redef class App var ratio = dynamic_resolution_ratio ratio = ratio.clamp(min_dynamic_resolution_ratio, max_dynamic_resolution_ratio) - glBindFramebuffer(gl_FRAMEBUFFER, dynamic_context.screen_framebuffer) + glBindFramebuffer(gl_FRAMEBUFFER, screen_framebuffer) glBindBuffer(gl_ARRAY_BUFFER, dynamic_context.buffer_array) glViewport(0, 0, display.width, display.height) glClear gl_COLOR_BUFFER_BIT | gl_DEPTH_BUFFER_BIT @@ -178,9 +192,6 @@ end # Handles to reused GL buffers and texture private class DynamicContext - # Real screen framebuffer - var screen_framebuffer: Int = -1 - # Dynamic screen framebuffer var dynamic_framebuffer: Int = -1 @@ -198,10 +209,6 @@ private class DynamicContext do # TODO enable antialiasing. - # Set aside the real screen framebuffer name - var screen_framebuffer = glGetIntegerv(gl_FRAMEBUFFER_BINDING, 0) - self.screen_framebuffer = screen_framebuffer - # Framebuffer var framebuffer = glGenFramebuffers(1).first glBindFramebuffer(gl_FRAMEBUFFER, framebuffer) -- 1.7.9.5