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

Can't create OpenGL window if opengle was enabled #555

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

Can't create OpenGL window if opengle was enabled #555

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: HG 2.0
Reported for operating system, platform: Linux, x86

Comments on the original bug report:

On 2012-02-23 00:16:34 +0000, wrote:

Environment

Mesa on my linux box compiled with built-in gles1 and gles2.
Both opengl and opengles were enabled in SDL (rev 6302) by default.

BUGS

  1. SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL) return NULL and can't get any error message from SDL_GetError().

  2. Window can be created with window = SDL_CreateWindow(title, x,y, w, h, SDL_WINDOW_SHOWN), but SDL_CreateRender(window, -1, SDL_RENDERER_ACCELERATED) return NULL. SDL_GetError() return "Couldn't find matching render driver".

Workaround

Compile SDL with --enable-video-opengles=no.

A rough analysis of bug1

Those bugs may be due to this(not sure):

src/video/SDL_video.c
SDL_Window *
SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
{
...
#if (SDL_VIDEO_OPENGL && MACOSX) || IPHONEOS || ANDROID
flags |= SDL_WINDOW_OPENGL;
#endif
if (flags & SDL_WINDOW_OPENGL) {
if (!_this->GL_CreateContext) {
SDL_SetError("No OpenGL support in video driver");
return NULL;
}
SDL_GL_LoadLibrary(NULL);
}
...
if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) {
SDL_DestroyWindow(window);
return NULL;
}
...

src/video/x11/SDL_x11video.c:

static SDL_VideoDevice *
X11_CreateDevice(int devindex)
...
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
device->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData));
if (!device->gles_data) {
SDL_OutOfMemory();
return NULL;
}
#endif
...
#if SDL_VIDEO_OPENGL_GLX
device->GL_LoadLibrary = X11_GL_LoadLibrary;
...
#endif
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
device->GL_LoadLibrary = X11_GLES_LoadLibrary;
...
#endif

So X11_GLES_LoadLibrary will be called and gl_data will be NULL if both gles and glx are enabled.

src/video/x11/SDL_x11window.c:
int
X11_CreateWindow(_THIS, SDL_Window * window)
...
#if SDL_VIDEO_OPENGL_GLX
if (window->flags & SDL_WINDOW_OPENGL) {
XVisualInfo *vinfo;

    vinfo = X11_GL_GetVisual(_this, display, screen);
    if (!vinfo) {
        return -1;
    }
    visual = vinfo->visual;
    depth = vinfo->depth;
    XFree(vinfo);
} else

#endif
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
if (window->flags & SDL_WINDOW_OPENGL) {
XVisualInfo *vinfo;

    vinfo = X11_GLES_GetVisual(_this, display, screen);
    if (!vinfo) {
        return -1;
    }
    visual = vinfo->visual;
    depth = vinfo->depth;
    XFree(vinfo);
} else

#endif

If X11_GL_GetVisual return NULL, X11_GLES_GetVisual will not be called.

src/video/x11/SDL_x11opengl.c:
XVisualInfo *
X11_GL_GetVisual(_THIS, Display * display, int screen)
{
...
if (!_this->gl_data) {
/* The OpenGL library wasn't loaded, SDL_GetError() should have info */
return NULL;
}
...

Since X11_GL_LoadLibrary was not called, _this->gl_data was NULL. So X11_GL_GetVisual return NULL. Then SDL_CreateWindow return NULL.

On 2012-06-20 13:57:14 +0000, Gabriel Jacobo wrote:

I think I was bitten by this today, after installing the MESA EGL stuff, I lost the OpenGL functionality. If you can figure out a patch I'll test it.

On 2012-07-15 08:41:26 +0000, David Gow wrote:

Created attachment 900
Trial patch to add SDL_VIDEO_X11_USEEGL env var

I've coded up a quick patch which adds the environment variable SDL_VIDEO_X11_USEEGL. When set to 0, glx is used (with desktop OpenGL), when nonzero egl (with whatever API is supported, be it GLES1.1 or GLES2) is used. If not set, it will default to GLX (as it is more popular) if it is available.

The discussion on the list about whether or not using an environment variable is a good idea at all is important. Personally, I think that adding a SDL_WINDOW_OPENGLES flag is probably the right solution, as that would actually create a distinction between the two at an API level. It would, of course, also be a lot of work, and would probably break a lot of existing code.

Thoughts?

-- David

On 2012-07-18 14:06:59 +0000, Andre Heider wrote:

Created attachment 902
0001-Fix-memleaks-in-X11_CreateDevice-error-paths

On 2012-07-18 14:07:14 +0000, Andre Heider wrote:

Created attachment 903
0002-Rename-envvar-to-overwrite-X11-EGL-library-name.patch

On 2012-07-18 14:07:26 +0000, Andre Heider wrote:

Created attachment 904
0003-Fix-OpenGL-initialization-when-OpenGL-and-OpenGLES-i.patch

On 2012-07-18 15:19:09 +0000, Sam Lantinga wrote:

I went ahead and incorporated the changes from Scott Percival. Please let me know how this works.

On 2013-07-12 22:15:23 +0000, Ryan C. Gordon wrote:

(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.0, Priority 2.

This means we're in the final stretch for an official SDL 2.0.0 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.0 release, and generally be organized about what we're aiming to ship.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.

On 2013-07-12 22:18:02 +0000, Gabriel Jacobo wrote:

This one is fixed.

./testrendercopyex --info render
Built-in render drivers:
Renderer opengl:
Flags: 0x0000000E (Accelerated | PresentVSync | 0x00000008)
Texture formats (1): ARGB8888
Renderer opengles2:
Flags: 0x0000000E (Accelerated | PresentVSync | 0x00000008)
Texture formats (4): ABGR8888, ARGB8888, RGB888, BGR888
Renderer opengles:
Flags: 0x0000000E (Accelerated | PresentVSync | 0x00000008)
Texture formats (1): ABGR8888
Renderer software:
Flags: 0x00000009 (0x00000001 | 0x00000008)
Texture formats (8): RGB555, RGB565, RGB888, BGR888, ARGB8888, RGBA8888, ABGR8888, BGRA8888
Current renderer:
Renderer opengl:
Flags: 0x0000000A (Accelerated | 0x00000008)
Texture formats (3): ARGB8888, YV12, IYUV
Max Texture Size: 16384x16384

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