video: SDL_GL_GetAttribute needs to operate on FBO 0.

If a different FBO is bound, this would return incorrect results.

Fixes #5082.
This commit is contained in:
Ryan C. Gordon 2021-12-31 10:30:51 -05:00
parent 2363ddc330
commit e4000c0284
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 14 additions and 1 deletions

View File

@ -3842,10 +3842,23 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
}
if (attachmentattrib && isAtLeastGL3((const char *) glGetStringFunc(GL_VERSION))) {
glGetFramebufferAttachmentParameterivFunc = SDL_GL_GetProcAddress("glGetFramebufferAttachmentParameteriv");
/* glGetFramebufferAttachmentParameteriv needs to operate on the window framebuffer for this, so bind FBO 0 if necessary. */
GLint current_fbo = 0;
void (APIENTRY *glGetIntegervFunc) (GLenum pname, GLint * params) = SDL_GL_GetProcAddress("glGetIntegerv");
void (APIENTRY *glBindFramebufferFunc) (GLenum target, GLuint fbo) = SDL_GL_GetProcAddress("glBindFramebuffer");
if (glGetIntegervFunc && glBindFramebufferFunc) {
glGetIntegervFunc(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
}
glGetFramebufferAttachmentParameterivFunc = SDL_GL_GetProcAddress("glGetFramebufferAttachmentParameteriv");
if (glGetFramebufferAttachmentParameterivFunc) {
if (glBindFramebufferFunc && (current_fbo != 0)) {
glBindFramebufferFunc(GL_DRAW_FRAMEBUFFER, 0);
}
glGetFramebufferAttachmentParameterivFunc(GL_FRAMEBUFFER, attachment, attachmentattrib, (GLint *) value);
if (glBindFramebufferFunc && (current_fbo != 0)) {
glBindFramebufferFunc(GL_DRAW_FRAMEBUFFER, current_fbo);
}
} else {
return -1;
}