Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_GL_GetAttribute(SDL_GL_RED_SIZE) fails for core profiles #1044

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

SDL_GL_GetAttribute(SDL_GL_RED_SIZE) fails for core profiles #1044

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.0
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2013-08-24 05:20:57 +0000, Stephan T. Lavavej wrote:

Created attachment 1304
Self-contained test case.

SDL_GL_GetAttribute(SDL_GL_RED_SIZE) etc. fails for core profiles because it's using deprecated/removed OpenGL functionality. Here's a self-contained repro (I'm using mingw-w64 on Win7 x64, but the problem is universal):

C:\Temp\gcc>type meow.cpp
// g++ -DUSE_CORE_PROFILE -Wall -Wextra -mwindows meow.cpp -o meow.exe -lopengl32 -lSDL2 -limm32 -lole32 -loleaut32 -luuid -lversion -lwinmm -lmingw32 -lSDL2main

#include <stddef.h>
#include
#include <GL/gl.h>
#include <SDL2/SDL.h>

struct Attribute {
SDL_GLattr attr;
int value;
const char * name;
};

int main(int, char * []) {
std::ofstream f("output.txt");

#ifdef USE_CORE_PROFILE
f << "Using core profile.\n";
#else
f << "Using compatibility profile.\n";
#endif

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    f << "SDL_Init() failed!\n";
}

#define ATTRIB(ATTR, VALUE) { ATTR, VALUE, #ATTR }

const Attribute attrs[] = {
    ATTRIB(  SDL_GL_RED_SIZE, 8),
    ATTRIB(SDL_GL_GREEN_SIZE, 8),
    ATTRIB( SDL_GL_BLUE_SIZE, 8),
    ATTRIB(SDL_GL_ALPHA_SIZE, 8),
    ATTRIB(SDL_GL_DEPTH_SIZE, 0),
    ATTRIB(SDL_GL_DOUBLEBUFFER, 1),
    ATTRIB(SDL_GL_ACCELERATED_VISUAL, 1),
    ATTRIB(SDL_GL_CONTEXT_MAJOR_VERSION, 4),
    ATTRIB(SDL_GL_CONTEXT_MINOR_VERSION, 3),

#ifdef USE_CORE_PROFILE
ATTRIB(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE)
#else
ATTRIB(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY)
#endif
};

const size_t N = sizeof(attrs) / sizeof(attrs[0]);

for (size_t i = 0; i < N; ++i) {
    if (SDL_GL_SetAttribute(attrs[i].attr, attrs[i].value) != 0) {
        f << "SDL_GL_SetAttribute() failed!\n";
    }
}

SDL_Window * window = SDL_CreateWindow("Meow", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1200, SDL_WINDOW_OPENGL);

if (!window) {
    f << "SDL_CreateWindow() failed!\n";
}

SDL_GLContext context = SDL_GL_CreateContext(window);

if (!context) {
    f << "SDL_GL_CreateContext() failed!\n";
}

for (size_t i = 0; i < N; ++i) {
    int val = 0;

    if (SDL_GL_GetAttribute(attrs[i].attr, &val) != 0) {
        f << "SDL_GL_GetAttribute(" << attrs[i].name << ") failed!\n";
        continue;
    }

    if (val != attrs[i].value) {
        f << "Unexpected attribute value!\n";
    }
}

if (glGetError() == GL_NO_ERROR) {
    f << "Done!\n";
} else {
    f << "glGetError() recorded failure!\n";
}

SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;

}

C:\Temp\gcc>g++ -Wall -Wextra -mwindows meow.cpp -o meow.exe -lopengl32 -lSDL2 -limm32 -lole32 -loleaut32 -luuid -lversion -lwinmm -lmingw32 -lSDL2main

C:\Temp\gcc>meow

C:\Temp\gcc>type output.txt
Using compatibility profile.
Done!

C:\Temp\gcc>g++ -DUSE_CORE_PROFILE -Wall -Wextra -mwindows meow.cpp -o meow.exe -lopengl32 -lSDL2 -limm32 -lole32 -loleaut32 -luuid -lversion -lwinmm -lmingw32 -lSDL2main

C:\Temp\gcc>meow

C:\Temp\gcc>type output.txt
Using core profile.
SDL_GL_GetAttribute(SDL_GL_RED_SIZE) failed!
SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE) failed!
SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE) failed!
SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE) failed!
SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE) failed!
Done!

The problem is in SDL_video.c, where SDL_GL_GetAttribute() calls glGetIntegerv() with GL_RED_BITS. As http://www.opengl.org/registry/doc/glspec43.compatibility.20130214.pdf explains in D.2.2 "Removed Features", page 790, this enum was removed:

"Context framebuffer size queries - RED_BITS, GREEN_BITS, BLUE_BITS, ALPHA_BITS, DEPTH_BITS, and STENCIL_BITS."

(STENCIL doesn't appear in my test because I'm not using it, but it is clearly also affected.)

The core-friendly way to query this information appears to be glGetFramebufferAttachmentParameteriv(), available since OpenGL 3.0: http://www.opengl.org/wiki/GLAPI/glGetFramebufferAttachmentParameter

On 2015-02-19 05:22:17 +0000, Ryan C. Gordon wrote:

Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!

On 2015-04-07 04:57:58 +0000, Ryan C. Gordon wrote:

(sorry if you get a lot of copies of this email, I'm marking several bugs at once)

Marking bugs for the (mostly) final 2.0.4 TODO list. This means we're hoping to resolve this bug before 2.0.4 ships if possible. In a perfect world, the open bug count with the target-2.0.4 keyword is zero when we ship.

(Note that closing a bug report as WONTFIX, INVALID or WORKSFORME might still happen.)

--ryan.

On 2015-04-14 20:28:10 +0000, Alex Szpakowski wrote:

Created attachment 2124
Patch to fix SDL_GL_GetAttribute in Core Profile contexts

Here's a patch that makes SDL_GL_GetAttribute use glGetFramebufferAttachmentParameteriv when appropriate.

On 2015-05-06 15:56:03 +0000, Alex Szpakowski wrote:

This should be fixed as of this commit: https://hg.libsdl.org/SDL/rev/a583c42c51d7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant