check GL version in the GL2.1 backend; check GLEW errors

This commit is contained in:
fgsfds 2020-06-09 23:28:26 +03:00
parent 180db16da8
commit 8d05d2b7e2
2 changed files with 29 additions and 7 deletions

View file

@ -479,14 +479,34 @@ static void gfx_opengl_draw_triangles(float buf_vbo[], size_t buf_vbo_len, size_
glDrawArrays(GL_TRIANGLES, 0, 3 * buf_vbo_num_tris); glDrawArrays(GL_TRIANGLES, 0, 3 * buf_vbo_num_tris);
} }
static inline bool gl_get_version(int *major, int *minor, bool *is_es) {
const char *vstr = (const char *)glGetString(GL_VERSION);
if (!vstr || !vstr[0]) return false;
if (!strncmp(vstr, "OpenGL ES ", 10)) {
vstr += 10;
*is_es = true;
} else if (!strncmp(vstr, "OpenGL ES-CM ", 13)) {
vstr += 13;
*is_es = true;
}
return (sscanf(vstr, "%d.%d", major, minor) == 2);
}
static void gfx_opengl_init(void) { static void gfx_opengl_init(void) {
#if FOR_WINDOWS #if FOR_WINDOWS || defined(OSX_BUILD)
glewInit(); GLenum err;
if ((err = glewInit()) != GLEW_OK)
sys_fatal("could not init GLEW:\n%s", glewGetErrorString(err));
#endif #endif
#ifdef OSX_BUILD // check GL version
glewInit(); int vmajor, vminor;
#endif bool is_es = false;
gl_get_version(&vmajor, &vminor, &is_es);
if (vmajor < 2 && vminor < 1 && !is_es)
sys_fatal("OpenGL 2.1+ is required.\nReported version: %s%d.%d", is_es ? "ES" : "", vmajor, vminor);
glGenBuffers(1, &opengl_vbo); glGenBuffers(1, &opengl_vbo);

View file

@ -510,7 +510,9 @@ static inline bool gl_get_version(int *major, int *minor, bool *is_es) {
static void gfx_opengl_init(void) { static void gfx_opengl_init(void) {
#if FOR_WINDOWS || defined(OSX_BUILD) #if FOR_WINDOWS || defined(OSX_BUILD)
glewInit(); GLenum err;
if ((err = glewInit()) != GLEW_OK)
sys_fatal("could not init GLEW:\n%s", glewGetErrorString(err));
#endif #endif
// check GL version // check GL version
@ -518,7 +520,7 @@ static void gfx_opengl_init(void) {
bool is_es = false; bool is_es = false;
gl_get_version(&vmajor, &vminor, &is_es); gl_get_version(&vmajor, &vminor, &is_es);
if (vmajor < 2 && vminor < 2 && !is_es) if (vmajor < 2 && vminor < 2 && !is_es)
sys_fatal("OpenGL 1.2+ is required. Reported version: %s%d.%d\n", is_es ? "ES" : "", vmajor, vminor); sys_fatal("OpenGL 1.2+ is required.\nReported version: %s%d.%d", is_es ? "ES" : "", vmajor, vminor);
// check extensions that we need // check extensions that we need
const bool supported = const bool supported =