Android: cannot create OpenGL ES 1.1 context

I am trying to construct an OpenGL ES 1.1 context with SDL hg
8679:dd52820b7f5c on Android 4.3 (Samsung Galaxy Nexus):

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_ES);
SDL_GL_CreateContext(window); // fails

This code fails with “Could not create EGL context”. If I specify v2.0
instead, then context construction succeeds and I get a 2.0 context. I also
get a valid 2.0 context if I remove the version attributes completely.

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_ES);
SDL_GL_CreateContext(window); // succeeds with a 2.0 context

What is the correct way to create an OpenGL ES 1.1 context on Android using
SDL2?

2014-03-25 20:19 GMT-03:00 Stefanos A. :

I am trying to construct an OpenGL ES 1.1 context with SDL hg
8679:dd52820b7f5c on Android 4.3 (Samsung Galaxy Nexus):

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_ES);
SDL_GL_CreateContext(window); // fails

This code fails with “Could not create EGL context”. If I specify v2.0
instead, then context construction succeeds and I get a 2.0 context. I also
get a valid 2.0 context if I remove the version attributes completely.

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_ES);

SDL_GL_CreateContext(window); // succeeds with a 2.0 context

What is the correct way to create an OpenGL ES 1.1 context on Android
using SDL2?

Try setting the attributes before creating the window.–
Gabriel.

This appears to work, but why is this terrible hack necessary? Is this
requirement documented somewhere?

More importantly, is there a way to workaround this inside SDL to avoid
breaking encapsulation on the application side?

2014-03-26 0:30 GMT+01:00 Gabriel Jacobo :>

2014-03-25 20:19 GMT-03:00 Stefanos A. <@Stefanos_A>:

I am trying to construct an OpenGL ES 1.1 context with SDL hg

8679:dd52820b7f5c on Android 4.3 (Samsung Galaxy Nexus):

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_ES);
SDL_GL_CreateContext(window); // fails

This code fails with “Could not create EGL context”. If I specify v2.0
instead, then context construction succeeds and I get a 2.0 context. I also
get a valid 2.0 context if I remove the version attributes completely.

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_ES);

SDL_GL_CreateContext(window); // succeeds with a 2.0 context

What is the correct way to create an OpenGL ES 1.1 context on Android
using SDL2?

Try setting the attributes before creating the window.


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

It?s not really a hack, most GL attributes on most operating systems need to be set before the SDL window is created.On Mar 25, 2014, at 8:51 PM, Stefanos A. wrote:

This appears to work, but why is this terrible hack necessary? Is this requirement documented somewhere?

More importantly, is there a way to workaround this inside SDL to avoid breaking encapsulation on the application side?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I can personally vouch that they don’t need to be set beforehand on Win32,
Win32/ANGLE, X11, Cocoa and Carbon, either directly or through SDL2, which
is why I was surprised at this requirement.

However, this is documented in SDL_GL_SetAttribute, so I guess all is fine

  • I’ve shuffled my window creation code to account for this.

2014-03-26 0:54 GMT+01:00 Alex Szpakowski :> It’s not really a hack, most GL attributes on most operating systems need

to be set before the SDL window is created.

On Mar 25, 2014, at 8:51 PM, Stefanos A. <@Stefanos_A> wrote:

This appears to work, but why is this terrible hack necessary? Is this
requirement documented somewhere?

More importantly, is there a way to workaround this inside SDL to avoid
breaking encapsulation on the application side?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

If you tried setting multisampling you would find your statement is incorrect, it must always be set before creating the Window. The same for the red/green/blue/alpha/depth/stencil sizes. This is
innate in the underlying windowing systems.On 03/25/2014 05:11 PM, Stefanos A. wrote:

I can personally vouch that they don’t need to be set beforehand on Win32, Win32/ANGLE, X11, Cocoa and Carbon, either directly or through SDL2, which is why I was surprised at this requirement.

However, this is documented in SDL_GL_SetAttribute, so I guess all is fine - I’ve shuffled my window creation code to account for this.

2014-03-26 0:54 GMT+01:00 Alex Szpakowski <aszpakowski at gmail.com <mailto:aszpakowski at gmail.com>>:

It?s not really a hack, most GL attributes on most operating systems need to be set before the SDL window is created.

On Mar 25, 2014, at 8:51 PM, Stefanos A. <stapostol at gmail.com <mailto:stapostol at gmail.com>> wrote:

> This appears to work, but why is this terrible hack necessary? Is this requirement documented somewhere?
>
> More importantly, is there a way to workaround this inside SDL to avoid breaking encapsulation on the application side?
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

My statement includes multisampling and I have working code to prove it,
both native and with SDL2. :slight_smile:

Feel free to contact me off-list for a link and/or explanation.

2014-03-26 1:16 GMT+01:00 Forest Hale :> If you tried setting multisampling you would find your statement is

incorrect, it must always be set before creating the Window. The same for
the red/green/blue/alpha/depth/stencil sizes. This is
innate in the underlying windowing systems.

On 03/25/2014 05:11 PM, Stefanos A. wrote:

I can personally vouch that they don’t need to be set beforehand on
Win32, Win32/ANGLE, X11, Cocoa and Carbon, either directly or through SDL2,
which is why I was surprised at this requirement.

However, this is documented in SDL_GL_SetAttribute, so I guess all is
fine - I’ve shuffled my window creation code to account for this.

2014-03-26 0:54 GMT+01:00 Alex Szpakowski <aszpakowski at gmail.com<mailto:
aszpakowski at gmail.com>>:

It's not really a hack, most GL attributes on most operating systems

need to be set before the SDL window is created.

On Mar 25, 2014, at 8:51 PM, Stefanos A. <@Stefanos_A<mailto: @Stefanos_A>> wrote:

> This appears to work, but why is this terrible hack necessary? Is

this requirement documented somewhere?

>
> More importantly, is there a way to workaround this inside SDL to

avoid breaking encapsulation on the application side?

>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list
SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


LordHavoc
Author of DarkPlaces Quake1 engine -
http://icculus.org/twilight/darkplaces
Co-designer http://icculus.org/twilight/darkplacesCo-designer of Nexuiz

  • http://alientrap.org/nexuiz
    "War does not prove who is right, it proves who is left." - Unknown
    "Any sufficiently advanced technology is indistinguishable from a rigged
    demo." - James Klass
    "A game is a series of interesting choices." - Sid Meier

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Forest Hale is quite correct. The only exceptions I know of are Mac OS X and iOS, where the native backend APIs allow the OpenGL context creation to be a little more independent from the window creation than other platforms.

You can check out the WIN_CreateWindow and WIN_GL_SetupWindow in the Windows backend for an example.On Mar 25, 2014, at 9:30 PM, Stefanos A. wrote:

My statement includes multisampling and I have working code to prove it, both native and with SDL2. :slight_smile:

Feel free to contact me off-list for a link and/or explanation.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Anything that uses EGL needs to follow this rule, because EGL supports 3
types of OpenGL contexts (desktop, ES1 and ES2), and each need a different
bit set in the associated EGL surface that’s created along with the window,
as well as a different API binding. If anyone has a way to get rid of this
limitation that works across all platforms, by all means let’s try it (I
did try setting the EGL_RENDERABLE_TYPE setting to an or’ed combination of
all valid bitmasks, but that didn’t fly with the Linux nVidia driver at the
time, maybe it works or doesn’t with others).

Otherwise, you’ll have to live with this 'horrible hack" :wink: of having to
set the GL attributes before creating the window.
Non EGL based backends probably don’t require this, but you never know what
you are gonna get.

2014-03-25 21:35 GMT-03:00 Alex Szpakowski :> Forest Hale is quite correct. The only exceptions I know of are Mac OS X

and iOS, where the native backend APIs allow the OpenGL context creation to
be a little more independent from the window creation than other platforms.

You can check out the WIN_CreateWindow and WIN_GL_SetupWindow in the
Windows backend for an example.

On Mar 25, 2014, at 9:30 PM, Stefanos A. wrote:

My statement includes multisampling and I have working code to prove it,
both native and with SDL2. :slight_smile:

Feel free to contact me off-list for a link and/or explanation.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.

I have already added the suggested modification to my codebase, so the
following is now an academic exercise.

If you check the Khronos specification of
WGL_ARB_create_contexthttp://www.opengl.org/registry/specs/ARB/wgl_create_context.txt,
GLX_ARB_create_contexthttps://www.opengl.org/registry/specs/ARB/glx_create_context.txt,
aglChoosePixelFormathttps://developer.apple.com/library/mac/documentation/graphicsimaging/reference/agl_opengl/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/c/func/aglChoosePixelFormat
/aglCreateContexthttps://developer.apple.com/library/mac/documentation/graphicsimaging/reference/agl_opengl/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/c/func/aglCreateContextand
eglChooseConfighttp://www.khronos.org/registry/egl/sdk/docs/man/xhtml/eglChooseConfig.html
/eglCreateContexthttp://www.khronos.org/registry/egl/sdk/docs/man/xhtml/eglCreateContext.html,
you will see that there is no requirement that for specific attributes to
be set before a window is constructed. In other words, you can call
(pseudocode):

  1. win = CreateWindow()
  2. pf = ChoosePixelFormat(attribs)
  3. ctx = CreateContext(pf)
  4. MakeCurrent(ctx, win) (*)

in that order, and have a working OpenGL / OpenGL ES setup. This works on
native WGL, GLX, AGL and EGL. This also works on SDL2 / desktop on its
WGL, GLX, NSOpenGL and EGL/ANGLE codepaths. It fails on SDL2 / android +
EGL.

If you doubt the validity of the above, I invite you to run the
multisampling example from https://github.com/opentk/opentk on your
favorite operating system.

Do not misunderstand: I have already made the necessary modifications to
get my codebase working on SDL2 / android. The reason why I call this a
"terrible hack" is that it forces tight coupling between window and context
construction, in a way that was - so far - not required by non-android
platforms.

I don’t doubt that there are good technical reasons for this requirement on
android. If you know these reasons and care to share them, I would be
really interested in hearing the explanation. But, please, don’t handwave
this away with “every operating system requires this” - because this is
simply not true.

(*) Win32 has an additional requirement of calling SetPixelFormat before
calling MakeCurrent() for the first time. This is a one-off statement
between steps 3 and 4.

2014-03-26 1:47 GMT+01:00 Gabriel Jacobo :> Anything that uses EGL needs to follow this rule, because EGL supports 3

types of OpenGL contexts (desktop, ES1 and ES2), and each need a different
bit set in the associated EGL surface that’s created along with the window,
as well as a different API binding. If anyone has a way to get rid of this
limitation that works across all platforms, by all means let’s try it (I
did try setting the EGL_RENDERABLE_TYPE setting to an or’ed combination of
all valid bitmasks, but that didn’t fly with the Linux nVidia driver at the
time, maybe it works or doesn’t with others).

Otherwise, you’ll have to live with this 'horrible hack" :wink: of having to
set the GL attributes before creating the window.
Non EGL based backends probably don’t require this, but you never know
what you are gonna get.

2014-03-25 21:35 GMT-03:00 Alex Szpakowski :

Forest Hale is quite correct. The only exceptions I know of are Mac OS X

and iOS, where the native backend APIs allow the OpenGL context creation to
be a little more independent from the window creation than other platforms.

You can check out the WIN_CreateWindow and WIN_GL_SetupWindow in the
Windows backend for an example.

On Mar 25, 2014, at 9:30 PM, Stefanos A. <@Stefanos_A> wrote:

My statement includes multisampling and I have working code to prove
it, both native and with SDL2. :slight_smile:

Feel free to contact me off-list for a link and/or explanation.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

2014-03-25 23:17 GMT-03:00 Stefanos A. :

I don’t doubt that there are good technical reasons for this requirement
on android. If you know these reasons and care to share them, I would be
really interested in hearing the explanation. But, please, don’t handwave
this away with “every operating system requires this” - because this is
simply not true.

You should re read my previous message. The issue has nothing to do with
Android in particular, it’s related to the way we handle EGL surfaces. In
theory, you can create an EGL surface that supports more than one GL
context type, but in practice I found it problematic, though anyone
bothered enough by this is welcome to re visit it (it’s not hard to test)
and then if you figure it out we could remove the limitation that requires
you to set the GL attributes before creating the window. Though as far as
limitations go, it’s not that bad IMO.

Gabriel.

I appreciate your explanation. I never disputed your previous message, I
merely pointed out that the underlying APIs do not have a “universal
requirement” to specify context attributes before creating a window. This
is something particular to SDL2.

If you will, consider my previous post as an empirical confirmation of your
explanation: ANGLE, which only supports ES2, appears to work without
specifying context attributes before window creation; Android, which
supports both ES and ES2, requires context attributes to be set before
window creation. I have not yet tested with Mir or Wayland, but I would
expect them to behave similar to Android.

Cheers,
Stefanos

2014-03-26 13:18 GMT+01:00 Gabriel Jacobo :>

2014-03-25 23:17 GMT-03:00 Stefanos A. <@Stefanos_A>:

I don’t doubt that there are good technical reasons for this requirement
on android. If you know these reasons and care to share them, I would be
really interested in hearing the explanation. But, please, don’t handwave
this away with “every operating system requires this” - because this is
simply not true.

You should re read my previous message. The issue has nothing to do with
Android in particular, it’s related to the way we handle EGL surfaces. In
theory, you can create an EGL surface that supports more than one GL
context type, but in practice I found it problematic, though anyone
bothered enough by this is welcome to re visit it (it’s not hard to test)
and then if you figure it out we could remove the limitation that requires
you to set the GL attributes before creating the window. Though as far as
limitations go, it’s not that bad IMO.

Gabriel.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org