diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-08-29 15:03:15 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-08-30 14:11:03 +0300 |
commit | 0f372f3966c434da5faa8e221f9da2aa48999a61 (patch) | |
tree | 08ed30ca3f78cf767691c7b3575703ce25cfb9ee /source | |
parent | bb530a77b638d1ccab779e1f43675030597f995e (diff) |
GPUContext: Update internal framebuffer size when activating context
This is to ensure the FrameBuffer extents are always up to date.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/gpu/intern/gpu_context_private.hh | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_framebuffer_private.hh | 6 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_context.cc | 22 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_framebuffer.cc | 3 |
4 files changed, 31 insertions, 2 deletions
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); } |