gamnit: don't touch the dynamic_resolution FBO if it is not used
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 14 Jan 2018 14:57:27 +0000 (09:57 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sun, 14 Jan 2018 15:22:47 +0000 (10:22 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/gamnit/dynamic_resolution.nit

index c0a2081..c783e97 100644 (file)
@@ -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)