[Bf-blender-cvs] [62fe7e9a9d0] master: GPU: support default framebuffer with ID not equal to 0

Tomoaki Kawada noreply at git.blender.org
Sun Jun 2 13:07:09 CEST 2019


Commit: 62fe7e9a9d0e211bc2ad4cdfedb2489c5f899133
Author: Tomoaki Kawada
Date:   Sat Jun 1 17:54:07 2019 +0200
Branches: master
https://developer.blender.org/rB62fe7e9a9d0e211bc2ad4cdfedb2489c5f899133

GPU: support default framebuffer with ID not equal to 0

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

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_IWindow.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_Context.h
M	intern/ghost/intern/GHOST_Window.cpp
M	intern/ghost/intern/GHOST_Window.h
M	source/blender/draw/engines/eevee/eevee_lightcache.c
M	source/blender/draw/intern/draw_manager.c
M	source/blender/gpu/GPU_context.h
M	source/blender/gpu/intern/gpu_context.cpp
M	source/blender/gpu/intern/gpu_context_private.h
M	source/blender/gpu/intern/gpu_extensions.c
M	source/blender/gpu/intern/gpu_framebuffer.c
M	source/blender/render/intern/source/pipeline.c
M	source/blender/windowmanager/intern/wm_playanim.c
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 3238be8fd87..ea9d6925e23 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -721,6 +721,11 @@ extern GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthan
  */
 extern GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle);
 
+/**
+ * Get the OpenGL framebuffer handle that serves as a default framebuffer.
+ */
+extern unsigned int GHOST_GetDefaultOpenGLFramebuffer(GHOST_WindowHandle windwHandle);
+
 /**
  * Set which tablet API to use. Only affects Windows, other platforms have a single API.
  * \param systemhandle The handle to the system
diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h
index 8042244c536..52894a7c38d 100644
--- a/intern/ghost/GHOST_IWindow.h
+++ b/intern/ghost/GHOST_IWindow.h
@@ -217,6 +217,12 @@ class GHOST_IWindow {
    */
   virtual GHOST_TSuccess activateDrawingContext() = 0;
 
+  /**
+   * Gets the OpenGL framebuffer associated with the window's contents.
+   * \return The name of an OpenGL framebuffer object.
+   */
+  virtual unsigned int getDefaultFramebuffer() = 0;
+
   /**
    * Invalidates the contents of this window.
    * \return Indication of success.
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 38ddf9819f9..ef653c114e8 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -633,6 +633,13 @@ GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle)
   return context->releaseDrawingContext();
 }
 
+unsigned int GHOST_GetDefaultOpenGLFramebuffer(GHOST_WindowHandle windowhandle)
+{
+  GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
+
+  return window->getDefaultFramebuffer();
+}
+
 GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle)
 {
   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
diff --git a/intern/ghost/intern/GHOST_Context.h b/intern/ghost/intern/GHOST_Context.h
index 7937fd1f7c7..bbf6d6a510d 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -119,6 +119,15 @@ class GHOST_Context : public GHOST_IContext {
     return m_stereoVisual;
   }
 
+  /**
+   * Gets the OpenGL framebuffer associated with the OpenGL context
+   * \return The ID of an OpenGL framebuffer object.
+   */
+  virtual unsigned int getDefaultFramebuffer()
+  {
+    return 0;
+  }
+
  protected:
   void initContextGLEW();
 
diff --git a/intern/ghost/intern/GHOST_Window.cpp b/intern/ghost/intern/GHOST_Window.cpp
index 5649386063d..76f2d2347db 100644
--- a/intern/ghost/intern/GHOST_Window.cpp
+++ b/intern/ghost/intern/GHOST_Window.cpp
@@ -109,6 +109,11 @@ GHOST_TSuccess GHOST_Window::getSwapInterval(int &intervalOut)
   return m_context->getSwapInterval(intervalOut);
 }
 
+unsigned int GHOST_Window::getDefaultFramebuffer()
+{
+  return (m_context) ? m_context->getDefaultFramebuffer() : 0;
+}
+
 GHOST_TSuccess GHOST_Window::activateDrawingContext()
 {
   return m_context->activateDrawingContext();
diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h
index acd0c93ff87..50a563453f6 100644
--- a/intern/ghost/intern/GHOST_Window.h
+++ b/intern/ghost/intern/GHOST_Window.h
@@ -261,6 +261,12 @@ class GHOST_Window : public GHOST_IWindow {
    */
   GHOST_TSuccess updateDrawingContext();
 
+  /**
+   * Gets the OpenGL framebuffer associated with the window's contents.
+   * \return The ID of an OpenGL framebuffer object.
+   */
+  virtual unsigned int getDefaultFramebuffer();
+
   /**
    * Returns the window user data.
    * \return The window user data.
diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c
index 149ebae1137..ebdc7813335 100644
--- a/source/blender/draw/engines/eevee/eevee_lightcache.c
+++ b/source/blender/draw/engines/eevee/eevee_lightcache.c
@@ -409,7 +409,7 @@ static void eevee_lightbake_context_enable(EEVEE_LightBake *lbake)
   if (lbake->gl_context) {
     DRW_opengl_render_context_enable(lbake->gl_context);
     if (lbake->gpu_context == NULL) {
-      lbake->gpu_context = GPU_context_create();
+      lbake->gpu_context = GPU_context_create(0);
     }
     DRW_gawain_render_context_enable(lbake->gpu_context);
   }
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 9e69cfa7ea4..08e8a8c001e 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -3158,7 +3158,7 @@ void DRW_opengl_context_create(void)
   DST.gl_context = WM_opengl_context_create();
   WM_opengl_context_activate(DST.gl_context);
   /* Be sure to create gawain.context too. */
-  DST.gpu_context = GPU_context_create();
+  DST.gpu_context = GPU_context_create(0);
   if (!G.background) {
     immActivate();
   }
diff --git a/source/blender/gpu/GPU_context.h b/source/blender/gpu/GPU_context.h
index 1f812129e29..ebeb104b7e8 100644
--- a/source/blender/gpu/GPU_context.h
+++ b/source/blender/gpu/GPU_context.h
@@ -36,7 +36,7 @@ extern "C" {
 
 typedef struct GPUContext GPUContext;
 
-GPUContext *GPU_context_create(void);
+GPUContext *GPU_context_create(GLuint default_framebuffer);
 void GPU_context_discard(GPUContext *);
 
 void GPU_context_active_set(GPUContext *);
diff --git a/source/blender/gpu/intern/gpu_context.cpp b/source/blender/gpu/intern/gpu_context.cpp
index 4bfc44327c2..a0e03e61d5d 100644
--- a/source/blender/gpu/intern/gpu_context.cpp
+++ b/source/blender/gpu/intern/gpu_context.cpp
@@ -64,6 +64,7 @@ static std::mutex orphans_mutex;
 
 struct GPUContext {
   GLuint default_vao;
+  GLuint default_framebuffer;
   GPUFrameBuffer *current_fbo;
   std::unordered_set<GPUBatch *> batches; /* Batches that have VAOs from this context */
 #ifdef DEBUG
@@ -137,11 +138,12 @@ static void orphans_clear(GPUContext *ctx)
   orphans_mutex.unlock();
 }
 
-GPUContext *GPU_context_create(void)
+GPUContext *GPU_context_create(GLuint default_framebuffer)
 {
   /* BLI_assert(thread_is_main()); */
   GPUContext *ctx = new GPUContext;
   glGenVertexArrays(1, &ctx->default_vao);
+  ctx->default_framebuffer = default_framebuffer;
   GPU_context_active_set(ctx);
   return ctx;
 }
@@ -201,6 +203,14 @@ GLuint GPU_vao_default(void)
   return active_ctx->default_vao;
 }
 
+GLuint GPU_framebuffer_default(void)
+{
+  BLI_assert(active_ctx); /* need at least an active context */
+  BLI_assert(pthread_equal(
+      pthread_self(), active_ctx->thread)); /* context has been activated by another thread! */
+  return active_ctx->default_framebuffer;
+}
+
 GLuint GPU_vao_alloc(void)
 {
   GLuint new_vao_id = 0;
diff --git a/source/blender/gpu/intern/gpu_context_private.h b/source/blender/gpu/intern/gpu_context_private.h
index 9c4cb30e40f..6825b67d2c8 100644
--- a/source/blender/gpu/intern/gpu_context_private.h
+++ b/source/blender/gpu/intern/gpu_context_private.h
@@ -35,6 +35,7 @@ extern "C" {
 struct GPUFrameBuffer;
 
 GLuint GPU_vao_default(void);
+GLuint GPU_framebuffer_default(void);
 
 /* These require a gl ctx bound. */
 GLuint GPU_buf_alloc(void);
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index 57734686b23..8cd554cc9d5 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -244,15 +244,6 @@ void gpu_extensions_init(void)
 
   glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, GG.line_width_range);
 
-#ifndef NDEBUG
-  GLint ret;
-  glBindFramebuffer(GL_FRAMEBUFFER, 0);
-  glGetFramebufferAttachmentParameteriv(
-      GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &ret);
-  /* We expect FRONT_LEFT to be the default buffer. */
-  BLI_assert(ret == GL_FRAMEBUFFER_DEFAULT);
-#endif
-
   glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &GG.samples_color_texture_max);
 
   const char *vendor = (const char *)glGetString(GL_VENDOR);
diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c
index 62fb02931ab..98ab6d96c0a 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.c
+++ b/source/blender/gpu/intern/gpu_framebuffer.c
@@ -539,7 +539,7 @@ void GPU_framebuffer_bind(GPUFrameBuffer *fb)
 void GPU_framebuffer_restore(void)
 {
   if (GPU_framebuffer_active_get() != NULL) {
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
+    glBindFramebuffer(GL_FRAMEBUFFER, GPU_framebuffer_default());
     gpu_framebuffer_current_set(NULL);
   }
 }
@@ -718,7 +718,7 @@ void GPU_framebuffer_blit(GPUFrameBuffer *fb_read,
     gpu_framebuffer_current_set(prev_fb);
   }
   else {
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
+    glBindFramebuffer(GL_FRAMEBUFFER, GPU_framebuffer_default());
     gpu_framebuffer_current_set(NULL);
   }
 }
@@ -909,7 +909,7 @@ void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y)
     gpu_print_framebuffer_error(status, NULL);
   }
 
-  glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
+  glBindFramebuffer(GL_READ_FRAMEBUFFER, GPU_framebuffer_default());
 }
 
 void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c
index 76767d0d1d8..6bde162f507 100644
--- a/source/blender/render/intern/source/pipeline.c
+++ b/source/blender/render/intern/source/pipeline.c
@@ -1116,7 +1116,7 @@ void *RE_gl_context_get(Render *re)
 void *RE_gpu_context_get(Render *re)
 {
   if (re->gpu_context == NULL) {
-    re->gpu_context = GPU_context_create();
+    re->gpu_context = GPU_context_create(0);
   }
   return re->gpu_context;
 }
diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c
index 7cc44bcad99..51dccf5bb8b 100644
--- a/source/blender/windowmanager/intern/wm_playanim.c
+++ b/source/blender/windowmanager/intern/wm_playanim.c
@@ -1287,7 +1287,8 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
   // GHOST_ActivateWindowDrawingContext(g_WS.ghost_window);
 
   /* initialize OpenGL immediate mode */
-  g_WS.gpu_context = GPU_context_create();
+  GLuint default_fb = GHOST_GetDefaultOpenGLFramebuffer(g_WS.ghost_w

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list