[Bf-blender-cvs] [1be1c5f55f9] tmp-gldebuglayer: Force bind the default framebuffer when creating the context

Clément Foucault noreply at git.blender.org
Wed Sep 9 15:50:23 CEST 2020


Commit: 1be1c5f55f9f1c248316f7d1501d3de11cd169ef
Author: Clément Foucault
Date:   Wed Sep 9 04:18:34 2020 +0200
Branches: tmp-gldebuglayer
https://developer.blender.org/rB1be1c5f55f9f1c248316f7d1501d3de11cd169ef

Force bind the  default framebuffer when creating the context

===================================================================

M	source/blender/gpu/opengl/gl_backend.cc
M	source/blender/gpu/opengl/gl_context.cc
M	source/blender/gpu/opengl/gl_debug.cc
M	source/blender/gpu/opengl/gl_debug.hh
M	source/blender/gpu/opengl/gl_debug_layer.cc
M	source/blender/gpu/opengl/gl_framebuffer.cc
M	source/blender/gpu/opengl/gl_state.cc
M	source/blender/gpu/opengl/gl_state.hh

===================================================================

diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc
index c8d57a20a38..d1ebe9c2123 100644
--- a/source/blender/gpu/opengl/gl_backend.cc
+++ b/source/blender/gpu/opengl/gl_backend.cc
@@ -178,7 +178,7 @@ static bool detect_mip_render_workaround(void)
   glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
   glClear(GL_COLOR_BUFFER_BIT);
   glBindFramebuffer(GL_FRAMEBUFFER, 0);
-  glDrawBuffer(GL_BACK);
+
   /* Read mip 1. If color is not the same as the clear_color, the rendering failed. */
   glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA, GL_FLOAT, source_pix);
   bool enable_workaround = !equals_v4v4(clear_color, source_pix);
diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc
index 6b3b06ef12b..9c98953f469 100644
--- a/source/blender/gpu/opengl/gl_context.cc
+++ b/source/blender/gpu/opengl/gl_context.cc
@@ -74,6 +74,9 @@ GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list
     GHOST_DisposeRectangle(bounds);
 
     if (default_fbo != 0) {
+      /* Bind default framebuffer, otherwise state might be undefined because of
+       * detect_mip_render_workaround(). */
+      glBindFramebuffer(GL_FRAMEBUFFER, default_fbo);
       front_left = new GLFrameBuffer("front_left", this, GL_COLOR_ATTACHMENT0, default_fbo, w, h);
       back_left = new GLFrameBuffer("back_left", this, GL_COLOR_ATTACHMENT0, default_fbo, w, h);
     }
@@ -81,6 +84,7 @@ GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list
       front_left = new GLFrameBuffer("front_left", this, GL_FRONT_LEFT, 0, w, h);
       back_left = new GLFrameBuffer("back_left", this, GL_BACK_LEFT, 0, w, h);
     }
+
     GLboolean supports_stereo_quad_buffer = GL_FALSE;
     glGetBooleanv(GL_STEREO, &supports_stereo_quad_buffer);
     if (supports_stereo_quad_buffer) {
@@ -95,7 +99,7 @@ GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list
 
   active_fb = back_left;
   static_cast<GLStateManager *>(state_manager)->active_fb = static_cast<GLFrameBuffer *>(
-      back_left);
+      active_fb);
 }
 
 GLContext::~GLContext()
diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc
index 168ac508758..11bd093bdce 100644
--- a/source/blender/gpu/opengl/gl_debug.cc
+++ b/source/blender/gpu/opengl/gl_debug.cc
@@ -116,8 +116,7 @@ void init_gl_callbacks(void)
 {
   char msg[256] = "";
   const char format[] = "Successfully hooked OpenGL debug callback using %s";
-
-  if (GLContext::debug_layer_support) {
+  if (GLEW_VERSION_4_3 || GLEW_KHR_debug) {
     SNPRINTF(msg, format, GLEW_VERSION_4_3 ? "OpenGL 4.3" : "KHR_debug extension");
     glEnable(GL_DEBUG_OUTPUT);
     glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
diff --git a/source/blender/gpu/opengl/gl_debug.hh b/source/blender/gpu/opengl/gl_debug.hh
index c651d0981fb..2015a49bb07 100644
--- a/source/blender/gpu/opengl/gl_debug.hh
+++ b/source/blender/gpu/opengl/gl_debug.hh
@@ -115,6 +115,7 @@ DEBUG_FUNC_OVERRIDE(glDeleteTextures, GLsizei, n, const GLuint *, textures);
 DEBUG_FUNC_OVERRIDE(glDrawArrays, GLenum, mode, GLint, first, GLsizei, count);
 DEBUG_FUNC_OVERRIDE(glFinish, void);
 DEBUG_FUNC_OVERRIDE(glFlush, void);
+DEBUG_FUNC_OVERRIDE(glGenTextures, GLsizei, n, GLuint *, textures);
 DEBUG_FUNC_OVERRIDE(glGetTexImage, GLenum, target, GLint, level, GLenum, format, GLenum, type, void *, pixels);
 DEBUG_FUNC_OVERRIDE(glReadBuffer, GLenum, mode);
 DEBUG_FUNC_OVERRIDE(glReadPixels, GLint, x, GLint, y, GLsizei, width, GLsizei, height, GLenum, format, GLenum, type, void *, pixels);
diff --git a/source/blender/gpu/opengl/gl_debug_layer.cc b/source/blender/gpu/opengl/gl_debug_layer.cc
index 9bb47dbf1e2..737fd58e2df 100644
--- a/source/blender/gpu/opengl/gl_debug_layer.cc
+++ b/source/blender/gpu/opengl/gl_debug_layer.cc
@@ -115,8 +115,8 @@ void init_debug_layer(void)
 {
 #define DEBUG_WRAP(function) \
   do { \
-    real_##function = function; \
-    function = &debug_##function; \
+    real_##function = ::function; \
+    ::function = &debug_##function; \
   } while (0)
 
   DEBUG_WRAP(glBeginQuery);
diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc
index bfc8a2f74eb..563feacde51 100644
--- a/source/blender/gpu/opengl/gl_framebuffer.cc
+++ b/source/blender/gpu/opengl/gl_framebuffer.cc
@@ -26,10 +26,12 @@
 #include "GPU_capabilities.h"
 
 #include "gl_backend.hh"
-#include "gl_framebuffer.hh"
+#include "gl_debug.hh"
 #include "gl_state.hh"
 #include "gl_texture.hh"
 
+#include "gl_framebuffer.hh"
+
 namespace blender::gpu {
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/gpu/opengl/gl_state.cc b/source/blender/gpu/opengl/gl_state.cc
index 6dcb56288e8..970a4d45a88 100644
--- a/source/blender/gpu/opengl/gl_state.cc
+++ b/source/blender/gpu/opengl/gl_state.cc
@@ -30,6 +30,7 @@
 #include "glew-mx.h"
 
 #include "gl_context.hh"
+#include "gl_debug.hh"
 #include "gl_framebuffer.hh"
 #include "gl_texture.hh"
 
diff --git a/source/blender/gpu/opengl/gl_state.hh b/source/blender/gpu/opengl/gl_state.hh
index db9b9721ad5..fb2ed3403f7 100644
--- a/source/blender/gpu/opengl/gl_state.hh
+++ b/source/blender/gpu/opengl/gl_state.hh
@@ -42,8 +42,8 @@ class GLTexture;
  **/
 class GLStateManager : public GPUStateManager {
  public:
-  /** Anothter reference to tje active framebuffer. */
-  GLFrameBuffer *active_fb;
+  /** Anothter reference to the active framebuffer. */
+  GLFrameBuffer *active_fb = nullptr;
 
  private:
   /** Current state of the GL implementation. Avoids resetting the whole state for every change. */



More information about the Bf-blender-cvs mailing list