add egl3test
authorRalf Jung <post@ralfj.de>
Mon, 30 Sep 2013 19:39:32 +0000 (21:39 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 30 Sep 2013 19:39:32 +0000 (21:39 +0200)
.gitignore
Makefile
eglbackend.cpp
eglbackend.h
glxbackend.cpp

index 8c21785704c693d6aa7088330abcbc5283632598..85392314598fcfaebbb7fa27323200dfc69465fa 100644 (file)
@@ -3,5 +3,6 @@ glx2test
 egltest
 egl2test
 glx3test
+egl3test
 gles2test
 eglinfo
index 2fa9312d0c33c0721dd45c1b2eb961297af13373..a6df6dcce982821668dab306253fc780d63a3c8b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,9 @@ egl2test: $(COMMON_SRC) $(COMMON_HDR) glutil_gl2.cpp eglbackend.cpp eglbackend.h
 glx3test: $(COMMON_SRC) $(COMMON_HDR) glutil_gl2.cpp glxbackend.cpp glxbackend.h
        g++ $(CFLAGS) -DWIN_GLX -DCON_GL3 $^ -lGL $(COMMON_LD) -o $@
 
+egl3test: $(COMMON_SRC) $(COMMON_HDR) glutil_gl2.cpp eglbackend.cpp eglbackend.h
+       g++ $(CFLAGS) -DWIN_EGL -DCON_GL3 $^ -lEGL -lGL $(COMMON_LD) -o $@
+
 gles2test: $(COMMON_SRC) $(COMMON_HDR) glutil_gl2.cpp eglbackend.cpp eglbackend.h
        g++ $(CFLAGS) -DWIN_EGL -DCON_GLES2 $^ -lEGL -lGLESv2 $(COMMON_LD) -o $@
 
index 2717b8648e648d1a270b85d889aa6f04fd4172b2..47e03844d0462497bcd1949c5d1f2f3bd8a6d56a 100644 (file)
@@ -24,8 +24,8 @@
 
 #include <EGL/eglext.h>
 
-#if !defined(CON_GL1) && !defined(CON_GLES2)
-#error "Valid GL contexts for EGL are: GL1, GLES2"
+#if !defined(CON_GL1) && !defined(CON_GL3) && !defined(CON_GLES2)
+#error "Valid GL contexts for EGL are: GL1, GL3, GLES2"
 #endif
 
 static const char *eglErrorToString(EGLint e)
@@ -66,6 +66,10 @@ static const EGLint configAttribs[] = {
 static const EGLint contextAttribs[] = {
 #ifdef CON_GLES2
        EGL_CONTEXT_CLIENT_VERSION, 2,
+#elif CON_GL3
+       EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
+       EGL_CONTEXT_MINOR_VERSION_KHR, 0,
+       EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
 #endif
        EGL_NONE
 };
@@ -81,9 +85,9 @@ VisualID EGLBackend::initialize(Display *xDisplay)
                if (eglInitialize(display, &eglMajor, &eglMinor) == EGL_FALSE)
                        dieEgl("Failed to initialize EGL");
                printf("Using EGL version: %d.%d\n", eglMajor, eglMinor);
-               if (eglMajor == 1 && eglMinor < 3) {
-                       // Choosing the GL context version requires EGL 1.3
-                       die("Need at least EGL 1.3 to function properly\n");
+               if (eglMajor == 1 && eglMinor < 4) {
+                       // Choosing the GL context version requires EGL 1.3, creating an OpenGL 3 context requires EGL 1.4
+                       die("Need at least EGL 1.4 to function properly\n");
                }
 #ifdef CON_GLES2
                if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE)
@@ -91,6 +95,12 @@ VisualID EGLBackend::initialize(Display *xDisplay)
                if (eglBindAPI(EGL_OPENGL_API) == EGL_FALSE)
 #endif
                        dieEgl("Failed to bind API");
+               // check for the extension we need
+#ifdef CON_GL3
+               if (!haveEGLExtension("EGL_KHR_create_context")) {
+                       die("Required EGL extension EGL_KHR_create_context is not supported\n");
+               }
+#endif
                // get an appropriate config
                EGLConfig configs[1];
                EGLint count;
@@ -108,6 +118,13 @@ VisualID EGLBackend::initialize(Display *xDisplay)
        return (VisualID)val;
 }
 
+bool EGLBackend::haveEGLExtension(const std::string &name)
+{
+       assert(display != EGL_NO_DISPLAY);
+       std::string extensions = eglQueryString(display, EGL_EXTENSIONS);
+       return (std::string(" "+extensions+" ").find(" "+name+" ") != std::string::npos);
+}
+
 void EGLBackend::createContext(Window window)
 {
        assert(display != EGL_NO_DISPLAY && context == EGL_NO_CONTEXT);
index acd8b677bddd2ad53b0c2e2e18afc17aaa361e76..918f6f903c50aabae47efd8e661d0b6df3dc4625 100644 (file)
@@ -19,6 +19,7 @@
 #include "glwindow.h"
 
 #include <EGL/egl.h>
+#include <string>
 
 
 /** Make an X window fit for GL. You have to manage the X window yourself! */
@@ -45,4 +46,6 @@ private:
        EGLConfig  config;
        EGLSurface surface;
        EGLContext context;
+       
+       bool haveEGLExtension(const std::string &name);
 };
index 2023954b242feb0c1dd786637619d28a748c17fd..f556a64ac3a4868daafc9ea5beed5b3dc562bb58 100644 (file)
@@ -58,7 +58,7 @@ VisualID GLXBackend::initialize(Display *display)
                int glxMajor, glxMinor;
                glXQueryVersion(display, &glxMajor, &glxMinor);
                printf("Using GLX version: %d.%d\n", glxMajor, glxMinor);
-               if (glxMajor < 1 || (glxMajor == 1 && glxMinor < 3)) {
+               if (glxMajor == 1 && glxMinor < 3) {
                        // glXChooseFBConfig and glXCreateNewContext require GLX 1.3
                        die("Need at least GLX 1.3 to function properly\n");
                }