SDL2 Opengl ES 3.0?


#1

So, I’m including #include <SDL_opengles2.h> and setting:

#ifdef HAVE_OPENGLES
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#endif
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

however, I am getting:

Version : OpenGL ES 2.0 APPLE-15.0.48

When running on an iOS simulator. Is there anything I can do with SDL2 to get an OpenGL ES 3.0 instance? I have quite a few shaders which rely on #version 330 and I would love to be able to just switch to #version 300 es

Primary things I rely on are “layout” and “smooth” I think I can re-write these without too much effort, but I was hoping for some news about running at head.


#2

Try asking for:

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

It works for me at least.


#3

It returns an Opengl2 context for me regardless.

I noticed I’m using “SDL_opengles2.h” though, I don’t see an “SDL_opengles3.h” header, maybe I’m doing something goofy or confused, relevant includes here:

#include <SDL.h>
#ifdef HAVE_OPENGLES
#include <SDL_opengl.h>
#include <SDL_opengles2.h>
typedef GLfloat GLdouble; //opengles has no GLdouble

inline int gl3wInit(){
    return 0;
}

#else
#include <gl3w/include/GL/gl3w.h>
#include <SDL_opengl.h>
#endif


#4

I don’t think the header files should affect the context you are getting. The only thing I can think of is to make sure you are setting those attributes before creating the context, but that seems rather obvious. Also, maybe it can depend on which xcode version / which ios simulator you are using as at least some of the actual old devices don’t support ES 3.

For me the the emulator gives these versions respectively:
OpenGL ES 2.0 APPLE-12.0.41
OpenGL ES 3.0 APPLE-12.0.41

I wonder why I’m getting an older version number for ES2. I’m using the latest Xcode. Maybe it’s the quite old simulator I was using to test (iPhone 4s).

For headers I’m personally using the platforms own header files directly with some if-defs. You can look into SDL_opengles2.h and see what it could look like.

for ios use
#include <OpenGLES/ES3/gl.h>

for android and others use:
#include <GLES3/gl3.h>

Still, as SDL is providing a header for ES 2 it should probably add, headers for 3.0, 3.1 and 3.2 too.


#5

In addition I did a quick test and if I call these (on the same 4s simulator):

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

my call to SDL_GL_CreateContext fails (i.e. returns NULL)