From 74488bec67c288462b6d3bae1fbd05b38e4f31e8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 9 Sep 2012 19:17:46 +0200 Subject: [PATCH] Further isolated X11-specific parts of EGL code. --- src/x11_egl_opengl.c | 98 ++++++++++++++++++++---------------------- src/x11_egl_platform.h | 3 ++ src/x11_glx_opengl.c | 10 ----- src/x11_platform.h | 3 +- src/x11_window.c | 2 +- 5 files changed, 53 insertions(+), 63 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 937c6d5e..0b0033e3 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -163,12 +163,10 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, EGLint fbconfigID) { - int attribs[40], visMask; - EGLint count, index, visualID = 0; - EGLint redBits, greenBits, blueBits, alphaBits; + int attribs[40]; + EGLint count, index; EGLConfig config; EGLContext share = NULL; - XVisualInfo visTemplate; if (wndconfig->share) share = wndconfig->share->EGL.context; @@ -192,45 +190,53 @@ static int createContext(_GLFWwindow* window, // Retrieve the corresponding visual // NOTE: This is the only non-portable code in this file. // Maybe it would not hurt too much to add #ifdefs for different platforms? - eglGetConfigAttrib(_glfwLibrary.EGL.display, config, EGL_NATIVE_VISUAL_ID, &visualID); - - // Init visual template - visTemplate.screen = _glfwLibrary.X11.screen; - visMask = VisualScreenMask; - - if (visualID) +#if defined(_GLFW_X11_EGL) { - // The X window visual must match the EGL config - visTemplate.visualid = visualID; - visMask |= VisualIDMask; - } - else - { - // some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID - // attribute, so attempt to find the closest match. - - eglGetConfigAttrib(_glfwLibrary.EGL.display, config, - EGL_RED_SIZE, &redBits); - eglGetConfigAttrib(_glfwLibrary.EGL.display, config, - EGL_GREEN_SIZE, &greenBits); - eglGetConfigAttrib(_glfwLibrary.EGL.display, config, - EGL_BLUE_SIZE, &blueBits); - eglGetConfigAttrib(_glfwLibrary.EGL.display, config, - EGL_ALPHA_SIZE, &alphaBits); - - visTemplate.depth = redBits + greenBits + blueBits + alphaBits; - visMask |= VisualDepthMask; - } - - window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display, - visMask, &visTemplate, &count); - - if (window->EGL.visual == NULL) - { - _glfwSetError(GLFW_PLATFORM_ERROR, - "EGL: Failed to retrieve visual for EGLConfig"); - return GL_FALSE; + int mask; + EGLint redBits, greenBits, blueBits, alphaBits, visualID = 0; + XVisualInfo info; + + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, + EGL_NATIVE_VISUAL_ID, &visualID); + + info.screen = _glfwLibrary.X11.screen; + mask = VisualScreenMask; + + if (visualID) + { + // The X window visual must match the EGL config + info.visualid = visualID; + mask |= VisualIDMask; + } + else + { + // some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID + // attribute, so attempt to find the closest match. + + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, + EGL_RED_SIZE, &redBits); + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, + EGL_GREEN_SIZE, &greenBits); + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, + EGL_BLUE_SIZE, &blueBits); + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, + EGL_ALPHA_SIZE, &alphaBits); + + info.depth = redBits + greenBits + blueBits + alphaBits; + mask |= VisualDepthMask; + } + + window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display, + mask, &info, &count); + + if (window->EGL.visual == NULL) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "EGL: Failed to retrieve visual for EGLConfig"); + return GL_FALSE; + } } +#endif if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) { @@ -471,16 +477,6 @@ void _glfwDestroyContext(_GLFWwindow* window) } -//======================================================================== -// Return the X visual associated with the specified context -//======================================================================== - -XVisualInfo* _glfwGetContextVisual(_GLFWwindow* window) -{ - return window->EGL.visual; -} - - //======================================================================== // Make the OpenGL context associated with the specified window current //======================================================================== diff --git a/src/x11_egl_platform.h b/src/x11_egl_platform.h index b0b2c810..8fa4841e 100644 --- a/src/x11_egl_platform.h +++ b/src/x11_egl_platform.h @@ -70,7 +70,10 @@ typedef struct _GLFWcontextEGL EGLConfig config; EGLContext context; EGLSurface surface; + +#if defined(_GLFW_X11_EGL) XVisualInfo* visual; +#endif } _GLFWcontextEGL; diff --git a/src/x11_glx_opengl.c b/src/x11_glx_opengl.c index ac5dd12c..c13cac60 100644 --- a/src/x11_glx_opengl.c +++ b/src/x11_glx_opengl.c @@ -611,16 +611,6 @@ void _glfwDestroyContext(_GLFWwindow* window) } -//======================================================================== -// Return the X visual associated with the specified context -//======================================================================== - -XVisualInfo* _glfwGetContextVisual(_GLFWwindow* window) -{ - return window->GLX.visual; -} - - //======================================================================== // Make the OpenGL context associated with the specified window current //======================================================================== diff --git a/src/x11_platform.h b/src/x11_platform.h index ede4abc0..edb58315 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -54,8 +54,10 @@ #endif #if defined(_GLFW_X11_GLX) + #define _GLFW_X11_CONTEXT_VISUAL window->GLX.visual #include "x11_glx_platform.h" #elif defined(_GLFW_X11_EGL) + #define _GLFW_X11_CONTEXT_VISUAL window->EGL.visual #define _GLFW_EGL_NATIVE_WINDOW window->X11.handle #define _GLFW_EGL_NATIVE_DISPLAY _glfwLibrary.X11.display #include "x11_egl_platform.h" @@ -225,7 +227,6 @@ int _glfwCreateContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig); void _glfwDestroyContext(_GLFWwindow* window); -XVisualInfo* _glfwGetContextVisual(_GLFWwindow* window); // Fullscreen support int _glfwGetClosestVideoMode(int* width, int* height, int* rate); diff --git a/src/x11_window.c b/src/x11_window.c index 3c8d39e9..f5573084 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -83,7 +83,7 @@ static GLboolean createWindow(_GLFWwindow* window, { unsigned long wamask; XSetWindowAttributes wa; - XVisualInfo* visual = _glfwGetContextVisual(window); + XVisualInfo* visual = _GLFW_X11_CONTEXT_VISUAL; // Every window needs a colormap // Create one based on the visual used by the current context