[Bf-blender-cvs] [0f372f3966c] master: GPUContext: Update internal framebuffer size when activating context

Clément Foucault noreply at git.blender.org
Sun Aug 30 13:36:08 CEST 2020


Commit: 0f372f3966c434da5faa8e221f9da2aa48999a61
Author: Clément Foucault
Date:   Sat Aug 29 14:03:15 2020 +0200
Branches: master
https://developer.blender.org/rB0f372f3966c434da5faa8e221f9da2aa48999a61

GPUContext: Update internal framebuffer size when activating context

This is to ensure the FrameBuffer extents are always up to date.

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

M	source/blender/gpu/intern/gpu_context_private.hh
M	source/blender/gpu/intern/gpu_framebuffer_private.hh
M	source/blender/gpu/opengl/gl_context.cc
M	source/blender/gpu/opengl/gl_framebuffer.cc

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

diff --git a/source/blender/gpu/intern/gpu_context_private.hh b/source/blender/gpu/intern/gpu_context_private.hh
index 0374df9bbc5..04b347d1bff 100644
--- a/source/blender/gpu/intern/gpu_context_private.hh
+++ b/source/blender/gpu/intern/gpu_context_private.hh
@@ -65,6 +65,8 @@ struct GPUContext {
   /** Thread on which this context is active. */
   pthread_t thread_;
   bool is_active_;
+  /** Avoid including GHOST headers. Can be NULL for offscreen contexts. */
+  void *ghost_window_;
 
  public:
   GPUContext();
diff --git a/source/blender/gpu/intern/gpu_framebuffer_private.hh b/source/blender/gpu/intern/gpu_framebuffer_private.hh
index 93551b0ef8b..a34fe38a267 100644
--- a/source/blender/gpu/intern/gpu_framebuffer_private.hh
+++ b/source/blender/gpu/intern/gpu_framebuffer_private.hh
@@ -130,6 +130,12 @@ class FrameBuffer {
                             void (*callback)(void *userData, int level),
                             void *userData);
 
+  inline void size_set(int width, int height)
+  {
+    width_ = width;
+    height_ = height;
+  }
+
   inline GPUTexture *depth_tex(void) const
   {
     if (attachments_[GPU_FB_DEPTH_ATTACHMENT].tex) {
diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc
index 8c1022c8fd1..380b396f0cd 100644
--- a/source/blender/gpu/opengl/gl_context.cc
+++ b/source/blender/gpu/opengl/gl_context.cc
@@ -55,6 +55,7 @@ GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list
   glBindBuffer(GL_ARRAY_BUFFER, 0);
 
   state_manager = new GLStateManager();
+  ghost_window_ = ghost_window;
 
   if (ghost_window) {
     GLuint default_fbo = GHOST_GetDefaultOpenGLFramebuffer((GHOST_WindowHandle)ghost_window);
@@ -129,6 +130,27 @@ void GLContext::activate(void)
 
   /* Clear accumulated orphans. */
   orphans_clear();
+
+  if (ghost_window_) {
+    /* Get the correct framebuffer size for the internal framebuffers. */
+    GHOST_RectangleHandle bounds = GHOST_GetClientBounds((GHOST_WindowHandle)ghost_window_);
+    int w = GHOST_GetWidthRectangle(bounds);
+    int h = GHOST_GetHeightRectangle(bounds);
+    GHOST_DisposeRectangle(bounds);
+
+    if (front_left) {
+      front_left->size_set(w, h);
+    }
+    if (back_left) {
+      back_left->size_set(w, h);
+    }
+    if (front_right) {
+      front_right->size_set(w, h);
+    }
+    if (back_right) {
+      back_right->size_set(w, h);
+    }
+  }
 }
 
 void GLContext::deactivate(void)
diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc
index bf2a782b083..7e50d37928e 100644
--- a/source/blender/gpu/opengl/gl_framebuffer.cc
+++ b/source/blender/gpu/opengl/gl_framebuffer.cc
@@ -214,8 +214,7 @@ void GLFrameBuffer::update_attachments(void)
     GPUAttachment &attach = attachments_[first_attachment];
     int size[3];
     GPU_texture_get_mipmap_size(attach.tex, attach.mip, size);
-    width_ = size[0];
-    height_ = size[1];
+    this->size_set(size[0], size[1]);
     srgb_ = (GPU_texture_format(attach.tex) == GPU_SRGB8_A8);
   }



More information about the Bf-blender-cvs mailing list