We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1428 - Can't create OpenGL window if opengle was enabled
Summary: Can't create OpenGL window if opengle was enabled
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: x86 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.0
Depends on:
Blocks:
 
Reported: 2012-02-23 00:16 UTC by sparkaround
Modified: 2013-07-12 22:18 UTC (History)
2 users (show)

See Also:


Attachments
Trial patch to add SDL_VIDEO_X11_USEEGL env var (5.72 KB, patch)
2012-07-15 08:41 UTC, David Gow
Details | Diff
0001-Fix-memleaks-in-X11_CreateDevice-error-paths (1.11 KB, patch)
2012-07-18 14:06 UTC, Andre Heider
Details | Diff
0002-Rename-envvar-to-overwrite-X11-EGL-library-name.patch (1005 bytes, patch)
2012-07-18 14:07 UTC, Andre Heider
Details | Diff
0003-Fix-OpenGL-initialization-when-OpenGL-and-OpenGLES-i.patch (6.25 KB, patch)
2012-07-18 14:07 UTC, Andre Heider
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description sparkaround 2012-02-23 00:16:34 UTC
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.
Comment 1 Gabriel Jacobo 2012-06-20 13:57:14 UTC
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.
Comment 2 David Gow 2012-07-15 08:41:26 UTC
Created attachment 900 [details]
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
Comment 3 Andre Heider 2012-07-18 14:06:59 UTC
Created attachment 902 [details]
0001-Fix-memleaks-in-X11_CreateDevice-error-paths
Comment 4 Andre Heider 2012-07-18 14:07:14 UTC
Created attachment 903 [details]
0002-Rename-envvar-to-overwrite-X11-EGL-library-name.patch
Comment 5 Andre Heider 2012-07-18 14:07:26 UTC
Created attachment 904 [details]
0003-Fix-OpenGL-initialization-when-OpenGL-and-OpenGLES-i.patch
Comment 6 Sam Lantinga 2012-07-18 15:19:09 UTC
I went ahead and incorporated the changes from Scott Percival.  Please let me know how this works.
Comment 7 Ryan C. Gordon 2013-07-12 22:15:23 UTC
(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.
Comment 8 Gabriel Jacobo 2013-07-12 22:18:02 UTC
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