| Summary: | Please allow desktop OpenGL contexts under EGL | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Steinar H. Gunderson <steinar+sdl> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED WONTFIX | QA Contact: | Sam Lantinga <slouken> |
| Severity: | enhancement | ||
| Priority: | P2 | CC: | amaranth72 |
| Version: | 2.0.3 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
|
Description
Steinar H. Gunderson
2015-09-15 11:59:50 UTC
SDL 2.0.4's EGL code has this capability. I tried this, but SDL_GL_CreateContext returns NULL:
#include <epoxy/egl.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_error.h>
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_video.h>
#include <assert.h>
int main(int argc, char **argv)
{
if (SDL_Init(SDL_INIT_VIDEO) == -1) {
fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
exit(1);
}
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
// SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
SDL_Window *window = SDL_CreateWindow("OpenGL window",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
1280, 720,
SDL_WINDOW_OPENGL);
SDL_GLContext context = SDL_GL_CreateContext(surface);
assert(context != NULL);
printf("%p\n", eglGetCurrentContext());
}
So, the assert fails.
This was with SDL from hg, by the way. Well, your code is requesting an OpenGL ES context (since the deprecated SDL_GL_CONTEXT_EGL flag does that.) SDL chooses an appropriate context creation API based on the windowing backend and the requested OpenGL version and profile. It's not possible to force it to always choose EGL for desktop OpenGL contexts when the X11 windowing backend is used, for example. (Nor is it possible to force it to always use GLX no matter what.) Be sure to set the appropriate SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_MAJOR_VERSION, and SDL_GL_MINOR_VERSION flags to what you want. Also check SDL_GetError after a SDL function call returns NULL or -1, to better understand what caused it to fail. If so, count this bug as a feature request to always force EGL :-) I could always compile without GLX, but a distribution is unlikely to. It's also worth mentioning that some linux video drivers don't support EGL at all (e.g. older nvidia drivers). EGL is also not available at all in OS X or iOS, and on Windows it's generally not provided with a regular video driver install. Yes, I'm fully aware that getting an EGL context might fail. But it's a good point. I'm going to close this for now, but feel free to reopen it with a patch that adds an SDL hint to force EGL usage. |