GPUContext: Update internal framebuffer size when activating context

This is to ensure the FrameBuffer extents are always up to date.
This commit is contained in:
Clément Foucault 2020-08-29 14:03:15 +02:00
parent bb530a77b6
commit 0f372f3966
4 changed files with 31 additions and 2 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -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)

View File

@ -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);
}