mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
Fixed SDL_GL_GetAttribute queries for framebuffer component sizes in Core Profile OpenGL contexts.
Fixes bugzilla #2060.
This commit is contained in:
parent
c4fe8c80c8
commit
ac27b511bf
@ -2798,14 +2798,32 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
|
|||||||
GLenum attrib = 0;
|
GLenum attrib = 0;
|
||||||
GLenum error = 0;
|
GLenum error = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Some queries in Core Profile desktop OpenGL 3+ contexts require
|
||||||
|
* glGetFramebufferAttachmentParameteriv instead of glGetIntegerv. Note that
|
||||||
|
* the enums we use for the former function don't exist in OpenGL ES 2, and
|
||||||
|
* the function itself doesn't exist prior to OpenGL 3 and OpenGL ES 2.
|
||||||
|
*/
|
||||||
|
#if SDL_VIDEO_OPENGL
|
||||||
|
const GLubyte *(APIENTRY *glGetStringFunc) (GLenum name);
|
||||||
|
void (APIENTRY *glGetFramebufferAttachmentParameterivFunc) (GLenum target, GLenum attachment, GLenum pname, GLint* params);
|
||||||
|
GLenum attachment = GL_BACK_LEFT;
|
||||||
|
GLenum attachmentattrib = 0;
|
||||||
|
|
||||||
|
glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
|
||||||
|
if (!glGetStringFunc) {
|
||||||
|
return SDL_SetError("Failed getting OpenGL glGetString entry point");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
|
glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
|
||||||
if (!glGetIntegervFunc) {
|
if (!glGetIntegervFunc) {
|
||||||
return -1;
|
return SDL_SetError("Failed getting OpenGL glGetIntegerv entry point");
|
||||||
}
|
}
|
||||||
|
|
||||||
glGetErrorFunc = SDL_GL_GetProcAddress("glGetError");
|
glGetErrorFunc = SDL_GL_GetProcAddress("glGetError");
|
||||||
if (!glGetErrorFunc) {
|
if (!glGetErrorFunc) {
|
||||||
return -1;
|
return SDL_SetError("Failed getting OpenGL glGetError entry point");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear value in any case */
|
/* Clear value in any case */
|
||||||
@ -2813,15 +2831,27 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
|
|||||||
|
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
case SDL_GL_RED_SIZE:
|
case SDL_GL_RED_SIZE:
|
||||||
|
#if SDL_VIDEO_OPENGL
|
||||||
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE;
|
||||||
|
#endif
|
||||||
attrib = GL_RED_BITS;
|
attrib = GL_RED_BITS;
|
||||||
break;
|
break;
|
||||||
case SDL_GL_BLUE_SIZE:
|
case SDL_GL_BLUE_SIZE:
|
||||||
|
#if SDL_VIDEO_OPENGL
|
||||||
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE;
|
||||||
|
#endif
|
||||||
attrib = GL_BLUE_BITS;
|
attrib = GL_BLUE_BITS;
|
||||||
break;
|
break;
|
||||||
case SDL_GL_GREEN_SIZE:
|
case SDL_GL_GREEN_SIZE:
|
||||||
|
#if SDL_VIDEO_OPENGL
|
||||||
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE;
|
||||||
|
#endif
|
||||||
attrib = GL_GREEN_BITS;
|
attrib = GL_GREEN_BITS;
|
||||||
break;
|
break;
|
||||||
case SDL_GL_ALPHA_SIZE:
|
case SDL_GL_ALPHA_SIZE:
|
||||||
|
#if SDL_VIDEO_OPENGL
|
||||||
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE;
|
||||||
|
#endif
|
||||||
attrib = GL_ALPHA_BITS;
|
attrib = GL_ALPHA_BITS;
|
||||||
break;
|
break;
|
||||||
case SDL_GL_DOUBLEBUFFER:
|
case SDL_GL_DOUBLEBUFFER:
|
||||||
@ -2836,9 +2866,17 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
|
|||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
case SDL_GL_DEPTH_SIZE:
|
case SDL_GL_DEPTH_SIZE:
|
||||||
|
#if SDL_VIDEO_OPENGL
|
||||||
|
attachment = GL_DEPTH;
|
||||||
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE;
|
||||||
|
#endif
|
||||||
attrib = GL_DEPTH_BITS;
|
attrib = GL_DEPTH_BITS;
|
||||||
break;
|
break;
|
||||||
case SDL_GL_STENCIL_SIZE:
|
case SDL_GL_STENCIL_SIZE:
|
||||||
|
#if SDL_VIDEO_OPENGL
|
||||||
|
attachment = GL_STENCIL;
|
||||||
|
attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE;
|
||||||
|
#endif
|
||||||
attrib = GL_STENCIL_BITS;
|
attrib = GL_STENCIL_BITS;
|
||||||
break;
|
break;
|
||||||
#if SDL_VIDEO_OPENGL
|
#if SDL_VIDEO_OPENGL
|
||||||
@ -2868,18 +2906,10 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
|
|||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
case SDL_GL_MULTISAMPLEBUFFERS:
|
case SDL_GL_MULTISAMPLEBUFFERS:
|
||||||
#if SDL_VIDEO_OPENGL
|
|
||||||
attrib = GL_SAMPLE_BUFFERS_ARB;
|
|
||||||
#else
|
|
||||||
attrib = GL_SAMPLE_BUFFERS;
|
attrib = GL_SAMPLE_BUFFERS;
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case SDL_GL_MULTISAMPLESAMPLES:
|
case SDL_GL_MULTISAMPLESAMPLES:
|
||||||
#if SDL_VIDEO_OPENGL
|
|
||||||
attrib = GL_SAMPLES_ARB;
|
|
||||||
#else
|
|
||||||
attrib = GL_SAMPLES;
|
attrib = GL_SAMPLES;
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
|
case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
|
||||||
#if SDL_VIDEO_OPENGL
|
#if SDL_VIDEO_OPENGL
|
||||||
@ -2890,23 +2920,23 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
|
|||||||
break;
|
break;
|
||||||
case SDL_GL_BUFFER_SIZE:
|
case SDL_GL_BUFFER_SIZE:
|
||||||
{
|
{
|
||||||
GLint bits = 0;
|
int rsize = 0, gsize = 0, bsize = 0, asize = 0;
|
||||||
GLint component;
|
|
||||||
|
|
||||||
/*
|
/* There doesn't seem to be a single flag in OpenGL for this! */
|
||||||
* there doesn't seem to be a single flag in OpenGL
|
if (SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &rsize) < 0) {
|
||||||
* for this!
|
return -1;
|
||||||
*/
|
}
|
||||||
glGetIntegervFunc(GL_RED_BITS, &component);
|
if (SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &gsize) < 0) {
|
||||||
bits += component;
|
return -1;
|
||||||
glGetIntegervFunc(GL_GREEN_BITS, &component);
|
}
|
||||||
bits += component;
|
if (SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &bsize) < 0) {
|
||||||
glGetIntegervFunc(GL_BLUE_BITS, &component);
|
return -1;
|
||||||
bits += component;
|
}
|
||||||
glGetIntegervFunc(GL_ALPHA_BITS, &component);
|
if (SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &asize) < 0) {
|
||||||
bits += component;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
*value = bits;
|
*value = rsize + gsize + bsize + asize;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case SDL_GL_ACCELERATED_VISUAL:
|
case SDL_GL_ACCELERATED_VISUAL:
|
||||||
@ -2965,7 +2995,21 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
|
|||||||
return SDL_SetError("Unknown OpenGL attribute");
|
return SDL_SetError("Unknown OpenGL attribute");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SDL_VIDEO_OPENGL
|
||||||
|
if (attachmentattrib && isAtLeastGL3((const char *) glGetStringFunc(GL_VERSION))) {
|
||||||
|
glGetFramebufferAttachmentParameterivFunc = SDL_GL_GetProcAddress("glGetFramebufferAttachmentParameteriv");
|
||||||
|
|
||||||
|
if (glGetFramebufferAttachmentParameterivFunc) {
|
||||||
|
glGetFramebufferAttachmentParameterivFunc(GL_FRAMEBUFFER, attachment, attachmentattrib, (GLint *) value);
|
||||||
|
} else {
|
||||||
|
return SDL_SetError("Failed getting OpenGL glGetFramebufferAttachmentParameteriv entry point");
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
glGetIntegervFunc(attrib, (GLint *) value);
|
glGetIntegervFunc(attrib, (GLint *) value);
|
||||||
|
}
|
||||||
|
|
||||||
error = glGetErrorFunc();
|
error = glGetErrorFunc();
|
||||||
if (error != GL_NO_ERROR) {
|
if (error != GL_NO_ERROR) {
|
||||||
if (error == GL_INVALID_ENUM) {
|
if (error == GL_INVALID_ENUM) {
|
||||||
|
Loading…
Reference in New Issue
Block a user