From 1327c124a4ed50d5572474aa11eb5e84bc0bc036 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 07:56:17 +0300 Subject: [PATCH 01/81] Seperate Context from Window in CMakeLists, add option to build for EGL --- CMakeLists.txt | 96 +++++++++++++++++++++++++++++++++++++++------- src/CMakeLists.txt | 5 +++ 2 files changed, 88 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44dcb4d4..dd5c35aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,14 @@ set(GLFW_VERSION_FULL "${GLFW_VERSION}.${GLFW_VERSION_PATCH}${GLFW_VERSION_EXTRA option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON) option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) +option(GLFW_USE_EGL "Build for EGL and OpenGL ES platform (Currently only X11)" OFF) -find_package(OpenGL REQUIRED) +if (GLFW_USE_EGL) + SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake/modules) + find_package(EGL REQUIRED) +else() + find_package(OpenGL REQUIRED) +endif() #-------------------------------------------------------------------- # Enable all warnings on GCC, regardless of OS @@ -39,8 +45,14 @@ elseif (UNIX AND APPLE) set(_GLFW_COCOA_NSGL 1) message(STATUS "Building GLFW for Cocoa and NSOpenGL on Mac OS X") elseif (UNIX AND NOT APPLE) - set(_GLFW_X11_GLX 1) - message(STATUS "Building GLFW for X11 and GLX on a Unix-like system") + set(_GLFW_X11 1) + if (GLFW_USE_EGL) + set(_GLFW_X11_EGL 1) + message(STATUS "Building GLFW for X11 and EGL on a Unix-like system") + else() + set(_GLFW_X11_GLX 1) + message(STATUS "Building GLFW for X11 and GLX on a Unix-like system") + endif() else() message(FATAL_ERROR "No supported platform was detected") endif() @@ -62,20 +74,18 @@ if (_GLFW_WIN32_WGL) endif() #-------------------------------------------------------------------- -# Set up GLFW for Xlib and GLX on Unix-like systems with X Windows +# Set up GLFW for Xlib and GLX or EGL on Unix-like systems with X Windows #-------------------------------------------------------------------- -if (_GLFW_X11_GLX) +if (_GLFW_X11) find_package(X11 REQUIRED) - # Set up library and include paths - list(APPEND glfw_INCLUDE_DIRS ${X11_X11_INCLUDE_PATH} ${OPENGL_INCLUDE_DIR}) - list(APPEND glfw_LIBRARIES ${X11_X11_LIB} ${OPENGL_gl_LIBRARY}) - - set(GLFW_PKG_DEPS "gl x11") set(GLFW_PKG_LIBS "") + set(GLFW_PKG_DEPS "x11") - include(CheckFunctionExists) + # Set up library and include paths + list(APPEND glfw_INCLUDE_DIRS ${X11_X11_INCLUDE_PATH}) + list(APPEND glfw_LIBRARIES ${X11_X11_LIB}) # Check for XRandR (modern resolution switching extension) if (X11_Xrandr_FOUND) @@ -121,6 +131,25 @@ if (_GLFW_X11_GLX) set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -lm") endif() + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(_GLFW_USE_LINUX_JOYSTICKS 1) + endif() + +endif() + +#-------------------------------------------------------------------- +# GLX Context +#-------------------------------------------------------------------- +if (_GLFW_X11_GLX) + + # Set up library and include paths + list(APPEND glfw_INCLUDE_DIRS${OPENGL_INCLUDE_DIR}) + list(APPEND glfw_LIBRARIES ${OPENGL_gl_LIBRARY}) + + set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} gl") + + include(CheckFunctionExists) + set(CMAKE_REQUIRED_LIBRARIES ${OPENGL_gl_LIBRARY}) check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS) @@ -160,9 +189,50 @@ if (_GLFW_X11_GLX) endif() endif() - if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - set(_GLFW_USE_LINUX_JOYSTICKS 1) +endif() + +#-------------------------------------------------------------------- +# EGL Context +#-------------------------------------------------------------------- +if (_GLFW_X11_EGL) + + # Set up library and include paths + list(APPEND glfw_INCLUDE_DIRS${EGL_INCLUDE_DIR}) + list(APPEND glfw_LIBRARIES ${EGL_LIBRARY}) + + set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} egl") + + include(CheckFunctionExists) + + set(CMAKE_REQUIRED_LIBRARIES ${EGL_LIBRARY}) + + check_function_exists(eglGetProcAddress _GLFW_HAS_EGLGETPROCADDRESS) + + if (NOT _GLFW_HAS_EGLGETPROCADDRESS) + message(WARNING "No eglGetProcAddress found") + + # Check for dlopen support as a fallback + + find_library(DL_LIBRARY dl) + mark_as_advanced(DL_LIBRARY) + if (DL_LIBRARY) + set(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARY}) + else() + set(CMAKE_REQUIRED_LIBRARIES "") + endif() + + check_function_exists(dlopen _GLFW_HAS_DLOPEN) + + if (NOT _GLFW_HAS_DLOPEN) + message(FATAL_ERROR "No entry point retrieval mechanism found") + endif() + + if (DL_LIBRARY) + list(APPEND glfw_LIBRARIES ${DL_LIBRARY}) + set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -ldl") + endif() endif() + endif() #-------------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index add05982..9a4fba68 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,11 @@ elseif (_GLFW_X11_GLX) set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c x11_gamma.c x11_init.c x11_input.c x11_joystick.c x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) +elseif (_GLFW_X11_EGL) + set(glfw_HEADERS ${common_HEADERS} x11_egl_platform.h) + set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c + x11_gamma.c x11_init.c x11_input.c x11_joystick.c + x11_keysym2unicode.c x11_egl_opengl.c x11_time.c x11_window.c) endif() add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) From 85067ede2e3f9c3beab04852e43b83fd580570b6 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 07:56:34 +0300 Subject: [PATCH 02/81] Add EGL related configurations --- src/config.h.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/config.h.in b/src/config.h.in index 01d541a2..ceb7e5a2 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -37,6 +37,8 @@ // Define this to 1 if building GLFW for X11/GLX #cmakedefine _GLFW_X11_GLX +// Define this to 1 if building GLFW for X11/EGL +#cmakedefine _GLFW_X11_EGL // Define this to 1 if building GLFW for Win32/WGL #cmakedefine _GLFW_WIN32_WGL // Define this to 1 if building GLFW for Cocoa/NSOpenGL @@ -63,6 +65,9 @@ // Define this to 1 if glXGetProcAddressEXT is available #cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT +// Define this to 1 if eglGetProcAddress is available +#cmakedefine _GLFW_HAS_EGLGETPROCADDRESS 1 + // Define this to 1 if the Linux joystick API is available #cmakedefine _GLFW_USE_LINUX_JOYSTICKS From 778a76683a38b49d2fcaa9f580841726ee122792 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 07:56:50 +0300 Subject: [PATCH 03/81] Add EGL X11 platform header --- src/internal.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/internal.h b/src/internal.h index 700b6c06..386d5858 100644 --- a/src/internal.h +++ b/src/internal.h @@ -82,6 +82,8 @@ typedef struct _GLFWlibrary _GLFWlibrary; #include "win32_platform.h" #elif defined(_GLFW_X11_GLX) #include "x11_platform.h" +#elif defined(_GLFW_X11_EGL) + #include "x11_egl_platform.h" #else #error "No supported platform selected" #endif From 27a7cc5aa8c0ae64c3ea3e8399583d353a7e4cb3 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 07:57:21 +0300 Subject: [PATCH 04/81] Add FindEGL.cmake module --- CMake/modules/FindEGL.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 CMake/modules/FindEGL.cmake diff --git a/CMake/modules/FindEGL.cmake b/CMake/modules/FindEGL.cmake new file mode 100644 index 00000000..0d5765ed --- /dev/null +++ b/CMake/modules/FindEGL.cmake @@ -0,0 +1,15 @@ +# Find EGL +# +# EGL_INCLUDE_DIR +# EGL_LIBRARY +# EGL_FOUND + +FIND_PATH(EGL_INCLUDE_DIR NAMES EGL/egl.h) + +SET(EGL_NAMES ${EGL_NAMES} egl EGL) +FIND_LIBRARY(EGL_LIBRARY NAMES ${EGL_NAMES}) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(EGL DEFAULT_MSG EGL_LIBRARY EGL_INCLUDE_DIR) + +MARK_AS_ADVANCED(EGL_INCLUDE_DIR EGL_LIBRARY) From 812ebe200d88843f674926fbb245239e6758cc64 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 07:58:07 +0300 Subject: [PATCH 05/81] Add EGL X11 platform header --- src/x11_egl_platform.h | 285 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 src/x11_egl_platform.h diff --git a/src/x11_egl_platform.h b/src/x11_egl_platform.h new file mode 100644 index 00000000..b1fb53cb --- /dev/null +++ b/src/x11_egl_platform.h @@ -0,0 +1,285 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: X11/EGL +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 2002-2006 Marcus Geelnard +// Copyright (c) 2006-2010 Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#ifndef _platform_h_ +#define _platform_h_ + +#include +#include +#include +#include +#include +#include +#include + +// Include EGL +#include + +// With XFree86, we can use the XF86VidMode extension +#if defined(_GLFW_HAS_XF86VIDMODE) + #include +#endif + +#if defined(_GLFW_HAS_XRANDR) + #include +#endif + +// Do we have support for dlopen/dlsym? +#if defined(_GLFW_HAS_DLOPEN) + #include +#endif + +// The Xkb extension provides improved keyboard support +#if defined(_GLFW_HAS_XKB) + #include +#endif + +// We support two different ways for getting addresses for EGL +// extension functions: eglGetProcAddress and dlsym +#if defined(_GLFW_HAS_EGLGETPROCADDRESS) + #define _glfw_eglGetProcAddress(x) eglGetProcAddress(x) +#elif defined(_GLFW_HAS_DLOPEN) + #define _glfw_eglGetProcAddress(x) dlsym(_glfwLibrary.EGL.libEGL, x) + #define _GLFW_DLOPEN_LIBEGL +#else + #error "No OpenGL entry point retrieval mechanism was enabled" +#endif + +#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 +#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL EGL +#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 X11 +#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL EGL + +// Clipboard format atom indices +#define _GLFW_CLIPBOARD_FORMAT_UTF8 0 +#define _GLFW_CLIPBOARD_FORMAT_COMPOUND 1 +#define _GLFW_CLIPBOARD_FORMAT_STRING 2 +#define _GLFW_CLIPBOARD_FORMAT_COUNT 3 + +// Clipboard conversion status tokens +#define _GLFW_CONVERSION_INACTIVE 0 +#define _GLFW_CONVERSION_SUCCEEDED 1 +#define _GLFW_CONVERSION_FAILED 2 + + +//======================================================================== +// GLFW platform specific types +//======================================================================== + +//------------------------------------------------------------------------ +// Pointer length integer +//------------------------------------------------------------------------ +typedef intptr_t GLFWintptr; + + +//------------------------------------------------------------------------ +// Platform-specific OpenGL context structure +//------------------------------------------------------------------------ +typedef struct _GLFWcontextEGL +{ + EGLConfig config; + EGLContext context; + EGLSurface surface; + XVisualInfo* visual; +} _GLFWcontextEGL; + + +//------------------------------------------------------------------------ +// Platform-specific window structure +//------------------------------------------------------------------------ +typedef struct _GLFWwindowX11 +{ + // Platform specific window resources + Colormap colormap; // Window colormap + Window handle; // Window handle + + // Various platform specific internal variables + GLboolean overrideRedirect; // True if window is OverrideRedirect + GLboolean keyboardGrabbed; // True if keyboard is currently grabbed + GLboolean cursorGrabbed; // True if cursor is currently grabbed + GLboolean cursorHidden; // True if cursor is currently hidden + GLboolean cursorCentered; // True if cursor was moved since last poll + int cursorPosX, cursorPosY; + +} _GLFWwindowX11; + +//------------------------------------------------------------------------ +// Platform-specific library global data for X11 +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryX11 +{ + Display* display; + int screen; + Window root; + Cursor cursor; // Invisible cursor for hidden cursor + + Atom wmDeleteWindow; // WM_DELETE_WINDOW atom + Atom wmName; // _NET_WM_NAME atom + Atom wmIconName; // _NET_WM_ICON_NAME atom + Atom wmPing; // _NET_WM_PING atom + Atom wmState; // _NET_WM_STATE atom + Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom + Atom wmActiveWindow; // _NET_ACTIVE_WINDOW atom + + // True if window manager supports EWMH + GLboolean hasEWMH; + + struct { + GLboolean available; + int eventBase; + int errorBase; + } VidMode; + + struct { + GLboolean available; + int eventBase; + int errorBase; + int majorVersion; + int minorVersion; + GLboolean gammaBroken; + } RandR; + + struct { + GLboolean available; + int majorOpcode; + int eventBase; + int errorBase; + int majorVersion; + int minorVersion; + } Xkb; + + // Key code LUT (mapping X11 key codes to GLFW key codes) + int keyCodeLUT[256]; + + // Screensaver data + struct { + GLboolean changed; + int timeout; + int interval; + int blanking; + int exposure; + } saver; + + // Fullscreen data + struct { + GLboolean modeChanged; +#if defined(_GLFW_HAS_XRANDR) + SizeID oldSizeID; + int oldWidth; + int oldHeight; + Rotation oldRotation; +#endif /*_GLFW_HAS_XRANDR*/ +#if defined(_GLFW_HAS_XF86VIDMODE) + XF86VidModeModeInfo oldMode; +#endif /*_GLFW_HAS_XF86VIDMODE*/ + } FS; + + // Timer data + struct { + GLboolean monotonic; + double resolution; + uint64_t base; + } timer; + + // Selection data + struct { + Atom atom; + Atom formats[_GLFW_CLIPBOARD_FORMAT_COUNT]; + char* string; + Atom target; + Atom targets; + Atom property; + int status; + } selection; + +} _GLFWlibraryX11; + +//------------------------------------------------------------------------ +// Platform-specific library global data for EGL +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryEGL +{ + EGLDisplay display; + EGLint majorVersion, minorVersion; + +#if defined(_GLFW_DLOPEN_LIBEGL) + void* libEGL; // dlopen handle for libEGL.so +#endif +} _GLFWlibraryEGL; + +//------------------------------------------------------------------------ +// Joystick information & state +//------------------------------------------------------------------------ +GLFWGLOBAL struct { + int Present; + int fd; + int NumAxes; + int NumButtons; + float* Axis; + unsigned char* Button; +} _glfwJoy[GLFW_JOYSTICK_LAST + 1]; + + +//======================================================================== +// Prototypes for platform specific internal functions +//======================================================================== + +// Time +void _glfwInitTimer(void); + +// OpenGL(|ES) support +int _glfwInitOpenGL(void); +void _glfwTerminateOpenGL(void); +int _glfwCreateContext(_GLFWwindow* window, + const _GLFWwndconfig* wndconfig, + const _GLFWfbconfig* fbconfig); +void _glfwDestroyContext(_GLFWwindow* window); + +// Fullscreen support +int _glfwGetClosestVideoMode(int* width, int* height, int* rate); +void _glfwSetVideoModeMODE(int mode, int rate); +void _glfwSetVideoMode(int* width, int* height, int* rate); +void _glfwRestoreVideoMode(void); + +// Joystick input +void _glfwInitJoysticks(void); +void _glfwTerminateJoysticks(void); + +// Unicode support +long _glfwKeySym2Unicode(KeySym keysym); + +// Clipboard handling +GLboolean _glfwReadSelection(XSelectionEvent* request); +Atom _glfwWriteSelection(XSelectionRequestEvent* request); + +// Event processing +void _glfwProcessPendingEvents(void); + +#endif // _platform_h_ From c878281487f1e2f3c1c4c0663d9bdd6c90bdcb4d Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 07:58:27 +0300 Subject: [PATCH 06/81] Add EGL platform opengl implentation --- src/x11_egl_opengl.c | 462 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 462 insertions(+) create mode 100644 src/x11_egl_opengl.c diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c new file mode 100644 index 00000000..efbadc06 --- /dev/null +++ b/src/x11_egl_opengl.c @@ -0,0 +1,462 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: X11/EGL/GLES +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 2002-2006 Marcus Geelnard +// Copyright (c) 2006-2010 Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#include "internal.h" + +#include +#include + +// Max number of EGL configuration we handle +#define _GLFW_EGL_CONFIG_IN 15 + +//======================================================================== +// Returns the specified attribute of the specified EGLConfig +//======================================================================== + +static int getFBConfigAttrib(_GLFWwindow* window, EGLConfig fbconfig, int attrib) +{ + int value; + eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, attrib, &value); + return value; +} + + +//======================================================================== +// Return a list of available and usable framebuffer configs +//======================================================================== + +static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) +{ + EGLConfig fbconfigs[_GLFW_EGL_CONFIG_IN]; + _GLFWfbconfig* result; + int i, count = 0; + + *found = 0; + + + eglGetConfigs(_glfwLibrary.EGL.display, fbconfigs, + _GLFW_EGL_CONFIG_IN, &count); + if (!count) + { + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, + "X11/EGL: No EGLConfigs returned"); + return NULL; + } + + result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); + if (!result) + { + _glfwSetError(GLFW_OUT_OF_MEMORY, + "X11/EGL: Failed to allocate _GLFWfbconfig array"); + return NULL; + } + + for (i = 0; i < count; i++) + { + if (!getFBConfigAttrib(window, fbconfigs[i], EGL_NATIVE_VISUAL_ID)) + { + // Only consider EGLConfigs with associated visuals + continue; + } + + if (!(getFBConfigAttrib(window, + fbconfigs[i], + EGL_COLOR_BUFFER_TYPE) & EGL_RGB_BUFFER)) + { + // Only consider RGB(A) EGLConfigs + continue; + } + + if (!(getFBConfigAttrib(window, fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_WINDOW_BIT)) + { + // Only consider window EGLConfigs + continue; + } + + result[*found].redBits = getFBConfigAttrib(window, fbconfigs[i], EGL_RED_SIZE); + result[*found].greenBits = getFBConfigAttrib(window, fbconfigs[i], EGL_GREEN_SIZE); + result[*found].blueBits = getFBConfigAttrib(window, fbconfigs[i], EGL_BLUE_SIZE); + + result[*found].alphaBits = getFBConfigAttrib(window, fbconfigs[i], EGL_ALPHA_SIZE); + result[*found].depthBits = getFBConfigAttrib(window, fbconfigs[i], EGL_DEPTH_SIZE); + result[*found].stencilBits = getFBConfigAttrib(window, fbconfigs[i], EGL_STENCIL_SIZE); + + result[*found].samples = getFBConfigAttrib(window, fbconfigs[i], EGL_SAMPLES); + + result[*found].platformID = (GLFWintptr) getFBConfigAttrib(window, fbconfigs[i], EGL_CONFIG_ID); + + (*found)++; + } + + return result; +} + +//======================================================================== +// Read back framebuffer parameters from the context +//======================================================================== + +static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID) +{ + EGLint dummy; + EGLConfig fbconfig[_GLFW_EGL_CONFIG_IN]; + + int attribs[] = { EGL_CONFIG_ID, fbconfigID, None }; + + eglChooseConfig(_glfwLibrary.EGL.display, + attribs, + fbconfig, + _GLFW_EGL_CONFIG_IN, + &dummy); + if (!dummy) + { + // This should never ever happen + // TODO: Flag this as an error and propagate up + _glfwSetError(GLFW_PLATFORM_ERROR, "X11/EGL: Cannot find known " + "EGLConfig by ID. This cannot " + "happen. Have a nice day.\n"); + abort(); + } + + // There is no clear definition of an "accelerated" context on X11/EGL, and + // true sounds better than false, so we hardcode true here + window->accelerated = GL_TRUE; + + window->redBits = getFBConfigAttrib(window, *fbconfig, EGL_RED_SIZE); + window->greenBits = getFBConfigAttrib(window, *fbconfig, EGL_GREEN_SIZE); + window->blueBits = getFBConfigAttrib(window, *fbconfig, EGL_BLUE_SIZE); + + window->alphaBits = getFBConfigAttrib(window, *fbconfig, EGL_ALPHA_SIZE); + window->depthBits = getFBConfigAttrib(window, *fbconfig, EGL_DEPTH_SIZE); + window->stencilBits = getFBConfigAttrib(window, *fbconfig, EGL_STENCIL_SIZE); + + // Get FSAA buffer sample count + window->samples = getFBConfigAttrib(window, *fbconfig, EGL_SAMPLES); +} + + +//======================================================================== +// Create the actual OpenGL(|ES) context +//======================================================================== + +#define setEGLattrib(attribs, index, attribName, attribValue) \ + attribs[index++] = attribName; \ + attribs[index++] = attribValue; + +static int createContext(_GLFWwindow* window, + const _GLFWwndconfig* wndconfig, + EGLint fbconfigID) +{ + int attribs[40]; + EGLint dummy, index, vid; + EGLConfig fbconfig[_GLFW_EGL_CONFIG_IN]; + EGLContext share = NULL; + XVisualInfo visTemplate; + + if (wndconfig->share) + share = wndconfig->share->EGL.context; + + // Retrieve the previously selected EGLConfig + { + index = 0; + + setEGLattrib(attribs, index, EGL_CONFIG_ID, fbconfigID); + setEGLattrib(attribs, index, None, None); + + eglChooseConfig(_glfwLibrary.EGL.display, + attribs, + fbconfig, + _GLFW_EGL_CONFIG_IN, + &dummy); + + if (!dummy) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: Failed to retrieve the selected EGLConfig"); + return GL_FALSE; + } + } + + // Retrieve the corresponding visual + if (!eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, EGL_NATIVE_VISUAL_ID, &vid)) { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: Failed to retrieve visual for EGLConfig"); + return GL_FALSE; + } + + // The X window visual must match the EGL config + visTemplate.visualid = vid; + window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display, VisualIDMask, &visTemplate, &dummy); + if (window->EGL.visual == NULL) { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: Failed to retrieve visual for EGLConfig"); + return GL_FALSE; + } + + if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE) + { + setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, 2); + } + else + { + setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, 1); + } + + setEGLattrib(attribs, index, EGL_NONE, EGL_NONE); + + eglBindAPI(EGL_OPENGL_ES_API); + + window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display, *fbconfig, share, attribs); + if (window->EGL.context == EGL_NO_CONTEXT) + { + // TODO: Handle all the various error codes here + + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: Failed to create OpenGL(|ES) context"); + return GL_FALSE; + } + + refreshContextParams(window, fbconfigID); + + return GL_TRUE; +} + +#undef setEGLattrib + + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Initialize EGL +//======================================================================== + +int _glfwInitOpenGL(void) +{ +#ifdef _GLFW_DLOPEN_LIBGL + int i; + char* libEGL_names[ ] = + { + "libEGL.so", + "libEGL.so.1", + "/usr/lib/libEGL.so", + "/usr/lib/libEGL.so.1", + NULL + }; + + for (i = 0; libEGL_names[i] != NULL; i++) + { + _glfwLibrary.EGL.libEGL = dlopen(libEGL_names[i], RTLD_LAZY | RTLD_GLOBAL); + if (_glfwLibrary.EGL.libEGL) + break; + } + + if (!_glfwLibrary.EGL.libEGL) + { + _glfwSetError(GLFW_PLATFORM_ERROR, "X11/EGL: Failed to find libEGL"); + return GL_FALSE; + } +#endif + + _glfwLibrary.EGL.display = eglGetDisplay((EGLNativeDisplayType)_glfwLibrary.X11.display); + if (_glfwLibrary.EGL.display == EGL_NO_DISPLAY) + { + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, + "X11/EGL: Failed to get EGL display"); + return GL_FALSE; + } + + if (!eglInitialize(_glfwLibrary.EGL.display, + &_glfwLibrary.EGL.majorVersion, + &_glfwLibrary.EGL.minorVersion)) + { + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, + "X11/EGL: Failed to initialize EGL"); + return GL_FALSE; + } + + return GL_TRUE; +} + + +//======================================================================== +// Terminate EGL +//======================================================================== + +void _glfwTerminateOpenGL(void) +{ + // Unload libEGL.so if necessary +#ifdef _GLFW_DLOPEN_LIBGL + if (_glfwLibrary.EGL.libEGL != NULL) + { + dlclose(_glfwLibrary.EGL.libEGL); + _glfwLibrary.EGL.libEGL = NULL; + } +#endif + eglTerminate(_glfwLibrary.EGL.display); +} + + +//======================================================================== +// Prepare for creation of the OpenGL context +//======================================================================== + +int _glfwCreateContext(_GLFWwindow* window, + const _GLFWwndconfig* wndconfig, + const _GLFWfbconfig* fbconfig) +{ + _GLFWfbconfig closest; + + // Choose the best available fbconfig + { + unsigned int fbcount; + _GLFWfbconfig* fbconfigs; + const _GLFWfbconfig* result; + + fbconfigs = getFBConfigs(window, &fbcount); + if (!fbconfigs) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: No usable EGLFBConfigs found"); + return GL_FALSE; + } + + result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); + if (!result) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: No EGLFBConfig matched the criteria"); + + free(fbconfigs); + return GL_FALSE; + } + + closest = *result; + free(fbconfigs); + } + + return createContext(window, wndconfig, closest.platformID); +} + + +//======================================================================== +// Destroy the OpenGL context +//======================================================================== + +void _glfwDestroyContext(_GLFWwindow* window) +{ + if (window->EGL.context) + { + // Release and destroy the context + eglMakeCurrent(_glfwLibrary.EGL.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + window->EGL.context = NULL; + } +} + + +//======================================================================== +// Make the OpenGL context associated with the specified window current +//======================================================================== + +void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) +{ + if (window) + { + eglMakeCurrent(_glfwLibrary.EGL.display, + window->EGL.surface, + window->EGL.surface, + window->EGL.context); + } + else + eglMakeCurrent(_glfwLibrary.EGL.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); +} + + +//======================================================================== +// Swap OpenGL buffers +//======================================================================== + +void _glfwPlatformSwapBuffers(void) +{ + eglSwapBuffers(_glfwLibrary.EGL.display, + _glfwLibrary.currentWindow->EGL.surface); +} + + +//======================================================================== +// Set double buffering swap interval +//======================================================================== + +void _glfwPlatformSwapInterval(int interval) +{ + eglSwapInterval(_glfwLibrary.EGL.display, interval); +} + + +//======================================================================== +// Check if an OpenGL extension is available at runtime +//======================================================================== + +int _glfwPlatformExtensionSupported(const char* extension) +{ + const char* extensions; + + // Get list of GLX extensions + extensions = eglQueryString(_glfwLibrary.EGL.display, + EGL_EXTENSIONS); + if (extensions != NULL) + { + if (_glfwStringInExtensionString(extension, (unsigned char*)extensions)) + return GL_TRUE; + } + + return GL_FALSE; +} + + +//======================================================================== +// Get the function pointer to an OpenGL function +//======================================================================== + +void* _glfwPlatformGetProcAddress(const char* procname) +{ + return (void*) _glfw_eglGetProcAddress(procname); +} + + +//======================================================================== +// Copies the specified OpenGL state categories from src to dst +//======================================================================== + +void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) +{ + // AFAIK, EGL doesn't have this +} + From 29b4ed4e9a6731a2ccda09020d65d84e1a5281a3 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 09:33:29 +0300 Subject: [PATCH 07/81] Don't build tests and examples when building with EGL --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd5c35aa..8680aec2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,10 @@ elseif (UNIX AND NOT APPLE) set(_GLFW_X11 1) if (GLFW_USE_EGL) set(_GLFW_X11_EGL 1) + set(GLFW_BUILD_EXAMPLES 0) + set(GLFW_BUILD_TESTS 0) message(STATUS "Building GLFW for X11 and EGL on a Unix-like system") + message(STATUS "NOTE: Examples and tests are disabled for EGL") else() set(_GLFW_X11_GLX 1) message(STATUS "Building GLFW for X11 and GLX on a Unix-like system") From d99e2385c12e41085cd9fc90c8be9c260f23e19a Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 09:34:00 +0300 Subject: [PATCH 08/81] Add temporary #ifdef in x11_fullscreen so EGL compiles --- src/x11_fullscreen.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index 7ad11ec5..a17acde4 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -357,6 +357,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) rgbarray = (int*) malloc(sizeof(int) * viscount); rgbcount = 0; + // Temporary solution +#if !defined(_GLFW_X11_EGL) // Build RGB array for (k = 0; k < viscount; k++) { @@ -386,6 +388,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) } } } +#endif XFree(vislist); From 28db982d0ab3565bd1817b7bacf686140b6a8b47 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 09:34:42 +0300 Subject: [PATCH 09/81] Add x11_fullscreen.c to the source list --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a4fba68..3ba760f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,7 +27,7 @@ elseif (_GLFW_X11_GLX) x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) elseif (_GLFW_X11_EGL) set(glfw_HEADERS ${common_HEADERS} x11_egl_platform.h) - set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c + set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c x11_gamma.c x11_init.c x11_input.c x11_joystick.c x11_keysym2unicode.c x11_egl_opengl.c x11_time.c x11_window.c) endif() From e06515eaa09f2baf73532cc678c0f51c0039d581 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 09:35:02 +0300 Subject: [PATCH 10/81] Improve OpenGL version parsing from string --- src/opengl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/opengl.c b/src/opengl.c index 67b5e728..957e4d24 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -32,6 +32,7 @@ #include #include +#include //======================================================================== @@ -42,13 +43,16 @@ static void parseGLVersion(int* major, int* minor, int* rev) { GLuint _major, _minor = 0, _rev = 0; const GLubyte* version; - const GLubyte* ptr; - const char* glesPrefix = "OpenGL ES "; version = glGetString(GL_VERSION); if (!version) return; +#if 0 + // Old version detection code. This doesn't work very well + const GLubyte* ptr; + const char* glesPrefix = "OpenGL ES "; + if (strncmp((const char*) version, glesPrefix, strlen(glesPrefix)) == 0) { // The version string on OpenGL ES has a prefix before the version @@ -76,6 +80,12 @@ static void parseGLVersion(int* major, int* minor, int* rev) _rev = 10 * _rev + (*ptr - '0'); } } +#endif + + // Find version from OpenGL string + for (; version && + !sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev); + ++version); // Store result *major = _major; From 478eac2fe0a5101f42adb945badb52be6976fad1 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 09:35:47 +0300 Subject: [PATCH 11/81] Create window surface and add fallback for visual info retival --- src/x11_egl_opengl.c | 110 ++++++++++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 32 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index efbadc06..12bf71f5 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -40,7 +40,7 @@ // Returns the specified attribute of the specified EGLConfig //======================================================================== -static int getFBConfigAttrib(_GLFWwindow* window, EGLConfig fbconfig, int attrib) +static int getFBConfigAttrib(EGLConfig fbconfig, int attrib) { int value; eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, attrib, &value); @@ -80,37 +80,36 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) for (i = 0; i < count; i++) { - if (!getFBConfigAttrib(window, fbconfigs[i], EGL_NATIVE_VISUAL_ID)) + if (!getFBConfigAttrib(fbconfigs[i], EGL_NATIVE_VISUAL_ID)) { // Only consider EGLConfigs with associated visuals continue; } - if (!(getFBConfigAttrib(window, - fbconfigs[i], + if (!(getFBConfigAttrib(fbconfigs[i], EGL_COLOR_BUFFER_TYPE) & EGL_RGB_BUFFER)) { // Only consider RGB(A) EGLConfigs continue; } - if (!(getFBConfigAttrib(window, fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_WINDOW_BIT)) + if (!(getFBConfigAttrib(fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_WINDOW_BIT)) { // Only consider window EGLConfigs continue; } - result[*found].redBits = getFBConfigAttrib(window, fbconfigs[i], EGL_RED_SIZE); - result[*found].greenBits = getFBConfigAttrib(window, fbconfigs[i], EGL_GREEN_SIZE); - result[*found].blueBits = getFBConfigAttrib(window, fbconfigs[i], EGL_BLUE_SIZE); + result[*found].redBits = getFBConfigAttrib(fbconfigs[i], EGL_RED_SIZE); + result[*found].greenBits = getFBConfigAttrib(fbconfigs[i], EGL_GREEN_SIZE); + result[*found].blueBits = getFBConfigAttrib(fbconfigs[i], EGL_BLUE_SIZE); - result[*found].alphaBits = getFBConfigAttrib(window, fbconfigs[i], EGL_ALPHA_SIZE); - result[*found].depthBits = getFBConfigAttrib(window, fbconfigs[i], EGL_DEPTH_SIZE); - result[*found].stencilBits = getFBConfigAttrib(window, fbconfigs[i], EGL_STENCIL_SIZE); + result[*found].alphaBits = getFBConfigAttrib(fbconfigs[i], EGL_ALPHA_SIZE); + result[*found].depthBits = getFBConfigAttrib(fbconfigs[i], EGL_DEPTH_SIZE); + result[*found].stencilBits = getFBConfigAttrib(fbconfigs[i], EGL_STENCIL_SIZE); - result[*found].samples = getFBConfigAttrib(window, fbconfigs[i], EGL_SAMPLES); + result[*found].samples = getFBConfigAttrib(fbconfigs[i], EGL_SAMPLES); - result[*found].platformID = (GLFWintptr) getFBConfigAttrib(window, fbconfigs[i], EGL_CONFIG_ID); + result[*found].platformID = (GLFWintptr) getFBConfigAttrib(fbconfigs[i], EGL_CONFIG_ID); (*found)++; } @@ -148,16 +147,16 @@ static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID) // true sounds better than false, so we hardcode true here window->accelerated = GL_TRUE; - window->redBits = getFBConfigAttrib(window, *fbconfig, EGL_RED_SIZE); - window->greenBits = getFBConfigAttrib(window, *fbconfig, EGL_GREEN_SIZE); - window->blueBits = getFBConfigAttrib(window, *fbconfig, EGL_BLUE_SIZE); + window->redBits = getFBConfigAttrib(*fbconfig, EGL_RED_SIZE); + window->greenBits = getFBConfigAttrib(*fbconfig, EGL_GREEN_SIZE); + window->blueBits = getFBConfigAttrib(*fbconfig, EGL_BLUE_SIZE); - window->alphaBits = getFBConfigAttrib(window, *fbconfig, EGL_ALPHA_SIZE); - window->depthBits = getFBConfigAttrib(window, *fbconfig, EGL_DEPTH_SIZE); - window->stencilBits = getFBConfigAttrib(window, *fbconfig, EGL_STENCIL_SIZE); + window->alphaBits = getFBConfigAttrib(*fbconfig, EGL_ALPHA_SIZE); + window->depthBits = getFBConfigAttrib(*fbconfig, EGL_DEPTH_SIZE); + window->stencilBits = getFBConfigAttrib(*fbconfig, EGL_STENCIL_SIZE); // Get FSAA buffer sample count - window->samples = getFBConfigAttrib(window, *fbconfig, EGL_SAMPLES); + window->samples = getFBConfigAttrib(*fbconfig, EGL_SAMPLES); } @@ -173,8 +172,9 @@ static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, EGLint fbconfigID) { - int attribs[40]; - EGLint dummy, index, vid; + int attribs[40], visMask; + EGLint dummy, index, vid = 0; + EGLint red_size, green_size, blue_size, alpha_size; EGLConfig fbconfig[_GLFW_EGL_CONFIG_IN]; EGLContext share = NULL; XVisualInfo visTemplate; @@ -187,7 +187,7 @@ static int createContext(_GLFWwindow* window, index = 0; setEGLattrib(attribs, index, EGL_CONFIG_ID, fbconfigID); - setEGLattrib(attribs, index, None, None); + setEGLattrib(attribs, index, EGL_NONE, EGL_NONE); eglChooseConfig(_glfwLibrary.EGL.display, attribs, @@ -204,21 +204,47 @@ static int createContext(_GLFWwindow* window, } // Retrieve the corresponding visual - if (!eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, EGL_NATIVE_VISUAL_ID, &vid)) { - _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: Failed to retrieve visual for EGLConfig"); - return GL_FALSE; + // 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, *fbconfig, EGL_NATIVE_VISUAL_ID, &vid); + + // Init visual template + visTemplate.screen = _glfwLibrary.X11.screen; + visMask = VisualScreenMask; + + if (vid != 0) + { + // The X window visual must match the EGL config + visTemplate.visualid = vid; + 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, *fbconfig, + EGL_RED_SIZE, &red_size); + eglGetConfigAttrib (_glfwLibrary.EGL.display, *fbconfig, + EGL_GREEN_SIZE, &green_size); + eglGetConfigAttrib (_glfwLibrary.EGL.display, *fbconfig, + EGL_BLUE_SIZE, &blue_size); + eglGetConfigAttrib (_glfwLibrary.EGL.display, *fbconfig, + EGL_ALPHA_SIZE, &alpha_size); + + visTemplate.depth = red_size + green_size + blue_size + alpha_size; + visMask |= VisualDepthMask; } - // The X window visual must match the EGL config - visTemplate.visualid = vid; - window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display, VisualIDMask, &visTemplate, &dummy); + // Get X Visual + window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display, visMask, &visTemplate, &dummy); if (window->EGL.visual == NULL) { _glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to retrieve visual for EGLConfig"); return GL_FALSE; } + index = 0; if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE) { setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, 2); @@ -242,6 +268,9 @@ static int createContext(_GLFWwindow* window, return GL_FALSE; } + // store configuraion + window->EGL.config = *fbconfig; + refreshContextParams(window, fbconfigID); return GL_TRUE; @@ -372,11 +401,18 @@ int _glfwCreateContext(_GLFWwindow* window, void _glfwDestroyContext(_GLFWwindow* window) { + if (window->EGL.surface) + { + // Release and destroy the surface + eglDestroySurface(_glfwLibrary.EGL.display, window->EGL.surface); + window->EGL.surface = EGL_NO_SURFACE; + } + if (window->EGL.context) { // Release and destroy the context - eglMakeCurrent(_glfwLibrary.EGL.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - window->EGL.context = NULL; + eglDestroyContext(_glfwLibrary.EGL.display, window->EGL.context); + window->EGL.context = EGL_NO_CONTEXT; } } @@ -389,6 +425,16 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) { if (window) { + if (window->EGL.surface == EGL_NO_SURFACE) + { + window->EGL.surface = eglCreateWindowSurface(_glfwLibrary.EGL.display, + window->EGL.config, (EGLNativeWindowType)window->X11.handle, NULL); + if (window->EGL.surface == EGL_NO_SURFACE) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: Failed to create window surface"); + } + } eglMakeCurrent(_glfwLibrary.EGL.display, window->EGL.surface, window->EGL.surface, From 819b09d479dc1eac5adad7718fb934117ea584a3 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Wed, 25 Apr 2012 09:36:38 +0300 Subject: [PATCH 12/81] Add member struct defines for window's context members so code can be shared --- src/x11_egl_platform.h | 1 + src/x11_platform.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/x11_egl_platform.h b/src/x11_egl_platform.h index b1fb53cb..f2fe4092 100644 --- a/src/x11_egl_platform.h +++ b/src/x11_egl_platform.h @@ -76,6 +76,7 @@ #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL EGL #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL EGL +#define _GLFW_CTX EGL // Clipboard format atom indices #define _GLFW_CLIPBOARD_FORMAT_UTF8 0 diff --git a/src/x11_platform.h b/src/x11_platform.h index 39593655..28e749fe 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -85,6 +85,7 @@ #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryGLX GLX +#define _GLFW_CTX GLX // Clipboard format atom indices #define _GLFW_CLIPBOARD_FORMAT_UTF8 0 From 2815630688ce777f9bd34408ee7365ef04e74b0e Mon Sep 17 00:00:00 2001 From: Cloudef Date: Thu, 26 Apr 2012 02:26:01 +0300 Subject: [PATCH 13/81] Reflect X visual changes to EGL code --- src/x11_egl_opengl.c | 14 ++++++++++++++ src/x11_egl_platform.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 12bf71f5..923e3e22 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -401,6 +401,12 @@ int _glfwCreateContext(_GLFWwindow* window, void _glfwDestroyContext(_GLFWwindow* window) { + if (window->EGL.visual) + { + XFree(window->EGL.visual); + window->EGL.visual = NULL; + } + if (window->EGL.surface) { // Release and destroy the surface @@ -416,6 +422,14 @@ 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 f2fe4092..87ba39a0 100644 --- a/src/x11_egl_platform.h +++ b/src/x11_egl_platform.h @@ -262,6 +262,7 @@ 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); From 5cf8b8d3fa949e400a6b30b94630eb415a040177 Mon Sep 17 00:00:00 2001 From: Cloudef Date: Fri, 11 May 2012 23:02:38 +0300 Subject: [PATCH 14/81] Remove useless define --- src/x11_egl_platform.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/x11_egl_platform.h b/src/x11_egl_platform.h index 87ba39a0..9e0e21b4 100644 --- a/src/x11_egl_platform.h +++ b/src/x11_egl_platform.h @@ -76,7 +76,6 @@ #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL EGL #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL EGL -#define _GLFW_CTX EGL // Clipboard format atom indices #define _GLFW_CLIPBOARD_FORMAT_UTF8 0 From 2e7d91ea5a3c25f0cc8b7547461eb40f580f9219 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sat, 30 Jun 2012 22:25:26 +0300 Subject: [PATCH 15/81] Only consider OpenGL ES contexes EGL_WINDOW_BIT is compared agaist wrong attribute --- src/x11_egl_opengl.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 923e3e22..7df15963 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -93,12 +93,19 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) continue; } - if (!(getFBConfigAttrib(fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_WINDOW_BIT)) + if (!(getFBConfigAttrib(fbconfigs[i], EGL_SURFACE_TYPE) & EGL_WINDOW_BIT)) { // Only consider window EGLConfigs continue; } + if (!(getFBConfigAttrib(fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES_BIT) && + !(getFBConfigAttrib(fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) + { + // Only consider OpenGL ES context + continue; + } + result[*found].redBits = getFBConfigAttrib(fbconfigs[i], EGL_RED_SIZE); result[*found].greenBits = getFBConfigAttrib(fbconfigs[i], EGL_GREEN_SIZE); result[*found].blueBits = getFBConfigAttrib(fbconfigs[i], EGL_BLUE_SIZE); From 739be03373aea279e0bb6c7566e1af094fac247e Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sat, 30 Jun 2012 22:35:26 +0300 Subject: [PATCH 16/81] Obey the OPENGL_ES2_PROFILE hint --- src/x11_egl_opengl.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 7df15963..90507f86 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -52,7 +52,7 @@ static int getFBConfigAttrib(EGLConfig fbconfig, int attrib) // Return a list of available and usable framebuffer configs //======================================================================== -static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) +static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, unsigned int* found) { EGLConfig fbconfigs[_GLFW_EGL_CONFIG_IN]; _GLFWfbconfig* result; @@ -106,6 +106,13 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) continue; } + if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE && + !(getFBConfigAttrib(fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) + { + // User requested only OpenGL ES 2.0 context + continue; + } + result[*found].redBits = getFBConfigAttrib(fbconfigs[i], EGL_RED_SIZE); result[*found].greenBits = getFBConfigAttrib(fbconfigs[i], EGL_GREEN_SIZE); result[*found].blueBits = getFBConfigAttrib(fbconfigs[i], EGL_BLUE_SIZE); @@ -376,7 +383,7 @@ int _glfwCreateContext(_GLFWwindow* window, _GLFWfbconfig* fbconfigs; const _GLFWfbconfig* result; - fbconfigs = getFBConfigs(window, &fbcount); + fbconfigs = getFBConfigs(window, wndconfig, &fbcount); if (!fbconfigs) { _glfwSetError(GLFW_PLATFORM_ERROR, From db0a4b599d6275c832f2a2cfa540f2f7eaa071fa Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Tue, 17 Jul 2012 22:29:09 +0300 Subject: [PATCH 17/81] Fix GLubyte warning, by casting to (char*) --- src/opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opengl.c b/src/opengl.c index 957e4d24..59097e1e 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -84,7 +84,7 @@ static void parseGLVersion(int* major, int* minor, int* rev) // Find version from OpenGL string for (; version && - !sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev); + !sscanf((char*)version, "%d.%d.%d", &_major, &_minor, &_rev); ++version); // Store result From 6b1344af3cb283f751edba3a036f6aeccb98b6a4 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Tue, 17 Jul 2012 23:06:30 +0300 Subject: [PATCH 18/81] Use GLFWglproc return type --- src/x11_egl_opengl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 90507f86..e1eed5cd 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -519,9 +519,9 @@ int _glfwPlatformExtensionSupported(const char* extension) // Get the function pointer to an OpenGL function //======================================================================== -void* _glfwPlatformGetProcAddress(const char* procname) +GLFWglproc _glfwPlatformGetProcAddress(const char* procname) { - return (void*) _glfw_eglGetProcAddress(procname); + return _glfw_eglGetProcAddress(procname); } From 311b9df1021b0327cb13be33e428e46bd89b6cf2 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 19 Jul 2012 22:11:45 +0200 Subject: [PATCH 19/81] Added error for unsupported call. --- src/x11_egl_opengl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index e1eed5cd..52d00b97 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -531,6 +531,7 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname) void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) { - // AFAIK, EGL doesn't have this + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: Context copying not supported by EGL"); } From f004aa0f8259c27dd92f51264268fa5ebfe73a9b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 19 Jul 2012 22:14:08 +0200 Subject: [PATCH 20/81] Formatting. --- CMake/modules/FindEGL.cmake | 13 +++++++------ CMakeLists.txt | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CMake/modules/FindEGL.cmake b/CMake/modules/FindEGL.cmake index 0d5765ed..0929c920 100644 --- a/CMake/modules/FindEGL.cmake +++ b/CMake/modules/FindEGL.cmake @@ -4,12 +4,13 @@ # EGL_LIBRARY # EGL_FOUND -FIND_PATH(EGL_INCLUDE_DIR NAMES EGL/egl.h) +find_path(EGL_INCLUDE_DIR NAMES EGL/egl.h) -SET(EGL_NAMES ${EGL_NAMES} egl EGL) -FIND_LIBRARY(EGL_LIBRARY NAMES ${EGL_NAMES}) +set(EGL_NAMES ${EGL_NAMES} egl EGL) +find_library(EGL_LIBRARY NAMES ${EGL_NAMES}) -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(EGL DEFAULT_MSG EGL_LIBRARY EGL_INCLUDE_DIR) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(EGL DEFAULT_MSG EGL_LIBRARY EGL_INCLUDE_DIR) + +mark_as_advanced(EGL_INCLUDE_DIR EGL_LIBRARY) -MARK_AS_ADVANCED(EGL_INCLUDE_DIR EGL_LIBRARY) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8680aec2..bd3e944c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(GLFW_USE_EGL "Build for EGL and OpenGL ES platform (Currently only X11)" OFF) if (GLFW_USE_EGL) - SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake/modules) + set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake/modules) find_package(EGL REQUIRED) else() find_package(OpenGL REQUIRED) @@ -200,7 +200,7 @@ endif() if (_GLFW_X11_EGL) # Set up library and include paths - list(APPEND glfw_INCLUDE_DIRS${EGL_INCLUDE_DIR}) + list(APPEND glfw_INCLUDE_DIRS ${EGL_INCLUDE_DIR}) list(APPEND glfw_LIBRARIES ${EGL_LIBRARY}) set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} egl") From be12cbca152e211587ab53dcc1cbef6bec09f3b3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 19 Jul 2012 23:01:51 +0200 Subject: [PATCH 21/81] Added separate platform headers for EGL and GLX. --- src/cocoa_platform.h | 4 + src/internal.h | 9 +- src/win32_platform.h | 5 + src/x11_egl_platform.h | 206 +---------------------------------------- src/x11_glx_platform.h | 125 +++++++++++++++++++++++++ src/x11_platform.h | 84 +---------------- 6 files changed, 143 insertions(+), 290 deletions(-) create mode 100644 src/x11_glx_platform.h diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 97e903d7..b3fe0491 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -41,6 +41,10 @@ typedef void* id; #endif +// This path may need to be changed if you build GLFW using your own setup +// We ship and use our own copy of glext.h since GLFW uses fairly new +// extensions and not all operating systems come with an up-to-date version +#include "../support/GL/glext.h" #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL diff --git a/src/internal.h b/src/internal.h index 386d5858..37813c6f 100644 --- a/src/internal.h +++ b/src/internal.h @@ -71,19 +71,12 @@ typedef struct _GLFWlibrary _GLFWlibrary; #include "../include/GL/glfw3.h" -// This path may need to be changed if you build GLFW using your own setup -// We ship and use our own copy of glext.h since GLFW uses fairly new -// extensions and not all operating systems come with an up-to-date version -#include "../support/GL/glext.h" - #if defined(_GLFW_COCOA_NSGL) #include "cocoa_platform.h" #elif defined(_GLFW_WIN32_WGL) #include "win32_platform.h" -#elif defined(_GLFW_X11_GLX) +#elif defined(_GLFW_X11_GLX) || defined(_GLFW_X11_EGL) #include "x11_platform.h" -#elif defined(_GLFW_X11_EGL) - #include "x11_egl_platform.h" #else #error "No supported platform selected" #endif diff --git a/src/win32_platform.h b/src/win32_platform.h index eeadbf22..849dd337 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -63,6 +63,11 @@ #include #include +// This path may need to be changed if you build GLFW using your own setup +// We ship and use our own copy of glext.h since GLFW uses fairly new +// extensions and not all operating systems come with an up-to-date version +#include "../support/GL/glext.h" + // This path may need to be changed if you build GLFW using your own setup // We ship and use our own copy of wglext.h since GLFW uses fairly new // extensions and not all operating systems come with an up-to-date version diff --git a/src/x11_egl_platform.h b/src/x11_egl_platform.h index 9e0e21b4..769323c4 100644 --- a/src/x11_egl_platform.h +++ b/src/x11_egl_platform.h @@ -28,39 +28,16 @@ // //======================================================================== -#ifndef _platform_h_ -#define _platform_h_ +#ifndef _x11_egl_platform_h_ +#define _x11_egl_platform_h_ -#include -#include -#include -#include -#include -#include -#include - -// Include EGL #include -// With XFree86, we can use the XF86VidMode extension -#if defined(_GLFW_HAS_XF86VIDMODE) - #include -#endif - -#if defined(_GLFW_HAS_XRANDR) - #include -#endif - // Do we have support for dlopen/dlsym? #if defined(_GLFW_HAS_DLOPEN) #include #endif -// The Xkb extension provides improved keyboard support -#if defined(_GLFW_HAS_XKB) - #include -#endif - // We support two different ways for getting addresses for EGL // extension functions: eglGetProcAddress and dlsym #if defined(_GLFW_HAS_EGLGETPROCADDRESS) @@ -72,33 +49,14 @@ #error "No OpenGL entry point retrieval mechanism was enabled" #endif -#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL EGL -#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL EGL -// Clipboard format atom indices -#define _GLFW_CLIPBOARD_FORMAT_UTF8 0 -#define _GLFW_CLIPBOARD_FORMAT_COMPOUND 1 -#define _GLFW_CLIPBOARD_FORMAT_STRING 2 -#define _GLFW_CLIPBOARD_FORMAT_COUNT 3 - -// Clipboard conversion status tokens -#define _GLFW_CONVERSION_INACTIVE 0 -#define _GLFW_CONVERSION_SUCCEEDED 1 -#define _GLFW_CONVERSION_FAILED 2 - //======================================================================== // GLFW platform specific types //======================================================================== -//------------------------------------------------------------------------ -// Pointer length integer -//------------------------------------------------------------------------ -typedef intptr_t GLFWintptr; - - //------------------------------------------------------------------------ // Platform-specific OpenGL context structure //------------------------------------------------------------------------ @@ -111,116 +69,6 @@ typedef struct _GLFWcontextEGL } _GLFWcontextEGL; -//------------------------------------------------------------------------ -// Platform-specific window structure -//------------------------------------------------------------------------ -typedef struct _GLFWwindowX11 -{ - // Platform specific window resources - Colormap colormap; // Window colormap - Window handle; // Window handle - - // Various platform specific internal variables - GLboolean overrideRedirect; // True if window is OverrideRedirect - GLboolean keyboardGrabbed; // True if keyboard is currently grabbed - GLboolean cursorGrabbed; // True if cursor is currently grabbed - GLboolean cursorHidden; // True if cursor is currently hidden - GLboolean cursorCentered; // True if cursor was moved since last poll - int cursorPosX, cursorPosY; - -} _GLFWwindowX11; - -//------------------------------------------------------------------------ -// Platform-specific library global data for X11 -//------------------------------------------------------------------------ -typedef struct _GLFWlibraryX11 -{ - Display* display; - int screen; - Window root; - Cursor cursor; // Invisible cursor for hidden cursor - - Atom wmDeleteWindow; // WM_DELETE_WINDOW atom - Atom wmName; // _NET_WM_NAME atom - Atom wmIconName; // _NET_WM_ICON_NAME atom - Atom wmPing; // _NET_WM_PING atom - Atom wmState; // _NET_WM_STATE atom - Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom - Atom wmActiveWindow; // _NET_ACTIVE_WINDOW atom - - // True if window manager supports EWMH - GLboolean hasEWMH; - - struct { - GLboolean available; - int eventBase; - int errorBase; - } VidMode; - - struct { - GLboolean available; - int eventBase; - int errorBase; - int majorVersion; - int minorVersion; - GLboolean gammaBroken; - } RandR; - - struct { - GLboolean available; - int majorOpcode; - int eventBase; - int errorBase; - int majorVersion; - int minorVersion; - } Xkb; - - // Key code LUT (mapping X11 key codes to GLFW key codes) - int keyCodeLUT[256]; - - // Screensaver data - struct { - GLboolean changed; - int timeout; - int interval; - int blanking; - int exposure; - } saver; - - // Fullscreen data - struct { - GLboolean modeChanged; -#if defined(_GLFW_HAS_XRANDR) - SizeID oldSizeID; - int oldWidth; - int oldHeight; - Rotation oldRotation; -#endif /*_GLFW_HAS_XRANDR*/ -#if defined(_GLFW_HAS_XF86VIDMODE) - XF86VidModeModeInfo oldMode; -#endif /*_GLFW_HAS_XF86VIDMODE*/ - } FS; - - // Timer data - struct { - GLboolean monotonic; - double resolution; - uint64_t base; - } timer; - - // Selection data - struct { - Atom atom; - Atom formats[_GLFW_CLIPBOARD_FORMAT_COUNT]; - char* string; - Atom target; - Atom targets; - Atom property; - int status; - } selection; - -} _GLFWlibraryX11; - //------------------------------------------------------------------------ // Platform-specific library global data for EGL //------------------------------------------------------------------------ @@ -234,53 +82,5 @@ typedef struct _GLFWlibraryEGL #endif } _GLFWlibraryEGL; -//------------------------------------------------------------------------ -// Joystick information & state -//------------------------------------------------------------------------ -GLFWGLOBAL struct { - int Present; - int fd; - int NumAxes; - int NumButtons; - float* Axis; - unsigned char* Button; -} _glfwJoy[GLFW_JOYSTICK_LAST + 1]; - -//======================================================================== -// Prototypes for platform specific internal functions -//======================================================================== - -// Time -void _glfwInitTimer(void); - -// OpenGL(|ES) support -int _glfwInitOpenGL(void); -void _glfwTerminateOpenGL(void); -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); -void _glfwSetVideoModeMODE(int mode, int rate); -void _glfwSetVideoMode(int* width, int* height, int* rate); -void _glfwRestoreVideoMode(void); - -// Joystick input -void _glfwInitJoysticks(void); -void _glfwTerminateJoysticks(void); - -// Unicode support -long _glfwKeySym2Unicode(KeySym keysym); - -// Clipboard handling -GLboolean _glfwReadSelection(XSelectionEvent* request); -Atom _glfwWriteSelection(XSelectionRequestEvent* request); - -// Event processing -void _glfwProcessPendingEvents(void); - -#endif // _platform_h_ +#endif // _x11_egl_platform_h_ diff --git a/src/x11_glx_platform.h b/src/x11_glx_platform.h new file mode 100644 index 00000000..b5397d06 --- /dev/null +++ b/src/x11_glx_platform.h @@ -0,0 +1,125 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: X11/GLX +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 2002-2006 Marcus Geelnard +// Copyright (c) 2006-2010 Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#ifndef _x11_glx_platform_h_ +#define _x11_glx_platform_h_ + +#define GLX_GLXEXT_LEGACY +#include + +// This path may need to be changed if you build GLFW using your own setup +// We ship and use our own copy of glext.h since GLFW uses fairly new +// extensions and not all operating systems come with an up-to-date version +#include "../support/GL/glext.h" + +// This path may need to be changed if you build GLFW using your own setup +// We ship and use our own copy of glxext.h since GLFW uses fairly new +// extensions and not all operating systems come with an up-to-date version +#include "../support/GL/glxext.h" + +// Do we have support for dlopen/dlsym? +#if defined(_GLFW_HAS_DLOPEN) + #include +#endif + +// We support four different ways for getting addresses for GL/GLX +// extension functions: glXGetProcAddress, glXGetProcAddressARB, +// glXGetProcAddressEXT, and dlsym +#if defined(_GLFW_HAS_GLXGETPROCADDRESSARB) + #define _glfw_glXGetProcAddress(x) glXGetProcAddressARB(x) +#elif defined(_GLFW_HAS_GLXGETPROCADDRESS) + #define _glfw_glXGetProcAddress(x) glXGetProcAddress(x) +#elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT) + #define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x) +#elif defined(_GLFW_HAS_DLOPEN) + #define _glfw_glXGetProcAddress(x) dlsym(_glfwLibrary.GLX.libGL, x) + #define _GLFW_DLOPEN_LIBGL +#else + #error "No OpenGL entry point retrieval mechanism was enabled" +#endif + +#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX +#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryGLX GLX +#define _GLFW_CTX GLX + +#ifndef GLX_MESA_swap_control +typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); +#endif + + +//======================================================================== +// GLFW platform specific types +//======================================================================== + +//------------------------------------------------------------------------ +// Platform-specific OpenGL context structure +//------------------------------------------------------------------------ +typedef struct _GLFWcontextGLX +{ + GLXContext context; // OpenGL rendering context + XVisualInfo* visual; // Visual for selected GLXFBConfig + +} _GLFWcontextGLX; + + +//------------------------------------------------------------------------ +// Platform-specific library global data for GLX +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryGLX +{ + // Server-side GLX version + int majorVersion, minorVersion; + + // GLX extensions + PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; + PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; + PFNGLXSWAPINTERVALMESAPROC SwapIntervalMESA; + PFNGLXGETFBCONFIGATTRIBSGIXPROC GetFBConfigAttribSGIX; + PFNGLXCHOOSEFBCONFIGSGIXPROC ChooseFBConfigSGIX; + PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC CreateContextWithConfigSGIX; + PFNGLXGETVISUALFROMFBCONFIGSGIXPROC GetVisualFromFBConfigSGIX; + PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; + GLboolean SGIX_fbconfig; + GLboolean SGI_swap_control; + GLboolean EXT_swap_control; + GLboolean MESA_swap_control; + GLboolean ARB_multisample; + GLboolean ARB_create_context; + GLboolean ARB_create_context_profile; + GLboolean ARB_create_context_robustness; + GLboolean EXT_create_context_es2_profile; + +#if defined(_GLFW_DLOPEN_LIBGL) + void* libGL; // dlopen handle for libGL.so +#endif +} _GLFWlibraryGLX; + + +#endif // _x11_glx_platform_h_ diff --git a/src/x11_platform.h b/src/x11_platform.h index 28e749fe..6089f4cb 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -38,14 +38,6 @@ #include #include -#define GLX_GLXEXT_LEGACY -#include - -// This path may need to be changed if you build GLFW using your own setup -// We ship and use our own copy of glxext.h since GLFW uses fairly new -// extensions and not all operating systems come with an up-to-date version -#include "../support/GL/glxext.h" - // With XFree86, we can use the XF86VidMode extension #if defined(_GLFW_HAS_XF86VIDMODE) #include @@ -55,37 +47,19 @@ #include #endif -// Do we have support for dlopen/dlsym? -#if defined(_GLFW_HAS_DLOPEN) - #include -#endif - // The Xkb extension provides improved keyboard support #if defined(_GLFW_HAS_XKB) #include #endif -// We support four different ways for getting addresses for GL/GLX -// extension functions: glXGetProcAddress, glXGetProcAddressARB, -// glXGetProcAddressEXT, and dlsym -#if defined(_GLFW_HAS_GLXGETPROCADDRESSARB) - #define _glfw_glXGetProcAddress(x) glXGetProcAddressARB(x) -#elif defined(_GLFW_HAS_GLXGETPROCADDRESS) - #define _glfw_glXGetProcAddress(x) glXGetProcAddress(x) -#elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT) - #define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x) -#elif defined(_GLFW_HAS_DLOPEN) - #define _glfw_glXGetProcAddress(x) dlsym(_glfwLibrary.GLX.libGL, x) - #define _GLFW_DLOPEN_LIBGL -#else - #error "No OpenGL entry point retrieval mechanism was enabled" +#if defined(_GLFW_X11_GLX) + #include "x11_glx_platform.h" +#elif defined(_GLFW_X11_EGL) + #include "x11_egl_platform.h" #endif #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 -#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 X11 -#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryGLX GLX -#define _GLFW_CTX GLX // Clipboard format atom indices #define _GLFW_CLIPBOARD_FORMAT_UTF8 0 @@ -98,10 +72,6 @@ #define _GLFW_CONVERSION_SUCCEEDED 1 #define _GLFW_CONVERSION_FAILED 2 -#ifndef GLX_MESA_swap_control -typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); -#endif - //======================================================================== // GLFW platform specific types @@ -113,17 +83,6 @@ typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); typedef intptr_t GLFWintptr; -//------------------------------------------------------------------------ -// Platform-specific OpenGL context structure -//------------------------------------------------------------------------ -typedef struct _GLFWcontextGLX -{ - GLXContext context; // OpenGL rendering context - XVisualInfo* visual; // Visual for selected GLXFBConfig - -} _GLFWcontextGLX; - - //------------------------------------------------------------------------ // Platform-specific window structure //------------------------------------------------------------------------ @@ -236,39 +195,6 @@ typedef struct _GLFWlibraryX11 } _GLFWlibraryX11; -//------------------------------------------------------------------------ -// Platform-specific library global data for GLX -//------------------------------------------------------------------------ -typedef struct _GLFWlibraryGLX -{ - // Server-side GLX version - int majorVersion, minorVersion; - - // GLX extensions - PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; - PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; - PFNGLXSWAPINTERVALMESAPROC SwapIntervalMESA; - PFNGLXGETFBCONFIGATTRIBSGIXPROC GetFBConfigAttribSGIX; - PFNGLXCHOOSEFBCONFIGSGIXPROC ChooseFBConfigSGIX; - PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC CreateContextWithConfigSGIX; - PFNGLXGETVISUALFROMFBCONFIGSGIXPROC GetVisualFromFBConfigSGIX; - PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; - GLboolean SGIX_fbconfig; - GLboolean SGI_swap_control; - GLboolean EXT_swap_control; - GLboolean MESA_swap_control; - GLboolean ARB_multisample; - GLboolean ARB_create_context; - GLboolean ARB_create_context_profile; - GLboolean ARB_create_context_robustness; - GLboolean EXT_create_context_es2_profile; - -#if defined(_GLFW_DLOPEN_LIBGL) - void* libGL; // dlopen handle for libGL.so -#endif -} _GLFWlibraryGLX; - - //------------------------------------------------------------------------ // Joystick information & state //------------------------------------------------------------------------ From 3fd17741bc0de05feb9699250bacb1e75c88a4f3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 19 Jul 2012 23:20:47 +0200 Subject: [PATCH 22/81] Added macro for including the GLES2 header. --- include/GL/glfw3.h | 2 ++ readme.html | 1 + 2 files changed, 3 insertions(+) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 28e38bd1..2ff67627 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -161,6 +161,8 @@ extern "C" { #else #if defined(GLFW_INCLUDE_GL3) #include + #elif defined(GLFW_INCLUDE_ES2) + #include #else #include #endif diff --git a/readme.html b/readme.html index b854a59c..cdbb9885 100644 --- a/readme.html +++ b/readme.html @@ -284,6 +284,7 @@ version of GLFW.

  • Added GLFW_OPENGL_ROBUSTNESS window hint and associated strategy tokens for GL_ARB_robustness support
  • Added GLFW_OPENGL_REVISION window parameter to make up for removal of glfwGetGLVersion
  • Added GLFW_INCLUDE_GL3 macro for telling the GLFW header to include gl3.h header instead of gl.h
  • +
  • Added GLFW_INCLUDE_ES2 macro for telling the GLFW header to include the OpenGL ES 2.0 header instead of gl.h
  • Added windows simple multi-window test program
  • Added sharing simple OpenGL object sharing test program
  • Added modes video mode enumeration and setting test program
  • From 26a843043cca03d4a8e2bf4fd516dbea0274bdb4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 19 Jul 2012 23:51:51 +0200 Subject: [PATCH 23/81] Formatting, removed trivial comments. --- src/x11_egl_opengl.c | 76 +++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 52d00b97..3390dbd7 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -36,6 +36,7 @@ // Max number of EGL configuration we handle #define _GLFW_EGL_CONFIG_IN 15 + //======================================================================== // Returns the specified attribute of the specified EGLConfig //======================================================================== @@ -52,7 +53,9 @@ static int getFBConfigAttrib(EGLConfig fbconfig, int attrib) // Return a list of available and usable framebuffer configs //======================================================================== -static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, unsigned int* found) +static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, + const _GLFWwndconfig* wndconfig, + unsigned int* found) { EGLConfig fbconfigs[_GLFW_EGL_CONFIG_IN]; _GLFWfbconfig* result; @@ -60,9 +63,8 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, const _GLFWwndconfig* wn *found = 0; - eglGetConfigs(_glfwLibrary.EGL.display, fbconfigs, - _GLFW_EGL_CONFIG_IN, &count); + _GLFW_EGL_CONFIG_IN, &count); if (!count) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, @@ -131,6 +133,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, const _GLFWwndconfig* wn return result; } + //======================================================================== // Read back framebuffer parameters from the context //======================================================================== @@ -143,10 +146,11 @@ static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID) int attribs[] = { EGL_CONFIG_ID, fbconfigID, None }; eglChooseConfig(_glfwLibrary.EGL.display, - attribs, - fbconfig, - _GLFW_EGL_CONFIG_IN, - &dummy); + attribs, + fbconfig, + _GLFW_EGL_CONFIG_IN, + &dummy); + if (!dummy) { // This should never ever happen @@ -169,7 +173,6 @@ static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID) window->depthBits = getFBConfigAttrib(*fbconfig, EGL_DEPTH_SIZE); window->stencilBits = getFBConfigAttrib(*fbconfig, EGL_STENCIL_SIZE); - // Get FSAA buffer sample count window->samples = getFBConfigAttrib(*fbconfig, EGL_SAMPLES); } @@ -204,10 +207,10 @@ static int createContext(_GLFWwindow* window, setEGLattrib(attribs, index, EGL_NONE, EGL_NONE); eglChooseConfig(_glfwLibrary.EGL.display, - attribs, - fbconfig, - _GLFW_EGL_CONFIG_IN, - &dummy); + attribs, + fbconfig, + _GLFW_EGL_CONFIG_IN, + &dummy); if (!dummy) { @@ -238,21 +241,23 @@ static int createContext(_GLFWwindow* window, // attribute, so attempt to find the closest match. eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, - EGL_RED_SIZE, &red_size); - eglGetConfigAttrib (_glfwLibrary.EGL.display, *fbconfig, - EGL_GREEN_SIZE, &green_size); - eglGetConfigAttrib (_glfwLibrary.EGL.display, *fbconfig, - EGL_BLUE_SIZE, &blue_size); - eglGetConfigAttrib (_glfwLibrary.EGL.display, *fbconfig, - EGL_ALPHA_SIZE, &alpha_size); + EGL_RED_SIZE, &red_size); + eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, + EGL_GREEN_SIZE, &green_size); + eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, + EGL_BLUE_SIZE, &blue_size); + eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, + EGL_ALPHA_SIZE, &alpha_size); visTemplate.depth = red_size + green_size + blue_size + alpha_size; visMask |= VisualDepthMask; } - // Get X Visual - window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display, visMask, &visTemplate, &dummy); - if (window->EGL.visual == NULL) { + window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display, + visMask, &visTemplate, &dummy); + + if (window->EGL.visual == NULL) + { _glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to retrieve visual for EGLConfig"); return GL_FALSE; @@ -272,7 +277,9 @@ static int createContext(_GLFWwindow* window, eglBindAPI(EGL_OPENGL_ES_API); - window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display, *fbconfig, share, attribs); + window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display, + *fbconfig, share, attribs); + if (window->EGL.context == EGL_NO_CONTEXT) { // TODO: Handle all the various error codes here @@ -282,7 +289,6 @@ static int createContext(_GLFWwindow* window, return GL_FALSE; } - // store configuraion window->EGL.config = *fbconfig; refreshContextParams(window, fbconfigID); @@ -328,7 +334,7 @@ int _glfwInitOpenGL(void) } #endif - _glfwLibrary.EGL.display = eglGetDisplay((EGLNativeDisplayType)_glfwLibrary.X11.display); + _glfwLibrary.EGL.display = eglGetDisplay((EGLNativeDisplayType) _glfwLibrary.X11.display); if (_glfwLibrary.EGL.display == EGL_NO_DISPLAY) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, @@ -337,8 +343,8 @@ int _glfwInitOpenGL(void) } if (!eglInitialize(_glfwLibrary.EGL.display, - &_glfwLibrary.EGL.majorVersion, - &_glfwLibrary.EGL.minorVersion)) + &_glfwLibrary.EGL.majorVersion, + &_glfwLibrary.EGL.minorVersion)) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/EGL: Failed to initialize EGL"); @@ -423,19 +429,18 @@ void _glfwDestroyContext(_GLFWwindow* window) if (window->EGL.surface) { - // Release and destroy the surface eglDestroySurface(_glfwLibrary.EGL.display, window->EGL.surface); window->EGL.surface = EGL_NO_SURFACE; } if (window->EGL.context) { - // Release and destroy the context eglDestroyContext(_glfwLibrary.EGL.display, window->EGL.context); window->EGL.context = EGL_NO_CONTEXT; } } + //======================================================================== // Return the X visual associated with the specified context //======================================================================== @@ -445,6 +450,7 @@ XVisualInfo* _glfwGetContextVisual(_GLFWwindow* window) return window->EGL.visual; } + //======================================================================== // Make the OpenGL context associated with the specified window current //======================================================================== @@ -456,20 +462,26 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) if (window->EGL.surface == EGL_NO_SURFACE) { window->EGL.surface = eglCreateWindowSurface(_glfwLibrary.EGL.display, - window->EGL.config, (EGLNativeWindowType)window->X11.handle, NULL); + window->EGL.config, + (EGLNativeWindowType) window->X11.handle, + NULL); if (window->EGL.surface == EGL_NO_SURFACE) { _glfwSetError(GLFW_PLATFORM_ERROR, "X11/EGL: Failed to create window surface"); } } + eglMakeCurrent(_glfwLibrary.EGL.display, window->EGL.surface, window->EGL.surface, window->EGL.context); } else - eglMakeCurrent(_glfwLibrary.EGL.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + { + eglMakeCurrent(_glfwLibrary.EGL.display, + EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + } } @@ -507,7 +519,7 @@ int _glfwPlatformExtensionSupported(const char* extension) EGL_EXTENSIONS); if (extensions != NULL) { - if (_glfwStringInExtensionString(extension, (unsigned char*)extensions)) + if (_glfwStringInExtensionString(extension, (unsigned char*) extensions)) return GL_TRUE; } From 251964f84f7f81784426370fc5aa05dafab7578e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 00:14:52 +0200 Subject: [PATCH 24/81] Began decoupling EGL code from X11. --- src/x11_egl_opengl.c | 4 ++-- src/x11_egl_platform.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 3390dbd7..eaefd640 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -334,7 +334,7 @@ int _glfwInitOpenGL(void) } #endif - _glfwLibrary.EGL.display = eglGetDisplay((EGLNativeDisplayType) _glfwLibrary.X11.display); + _glfwLibrary.EGL.display = eglGetDisplay(_GLFW_EGL_NATIVE_DISPLAY); if (_glfwLibrary.EGL.display == EGL_NO_DISPLAY) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, @@ -463,7 +463,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) { window->EGL.surface = eglCreateWindowSurface(_glfwLibrary.EGL.display, window->EGL.config, - (EGLNativeWindowType) window->X11.handle, + _GLFW_EGL_NATIVE_WINDOW, NULL); if (window->EGL.surface == EGL_NO_SURFACE) { diff --git a/src/x11_egl_platform.h b/src/x11_egl_platform.h index 769323c4..1ab83f89 100644 --- a/src/x11_egl_platform.h +++ b/src/x11_egl_platform.h @@ -52,6 +52,9 @@ #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL EGL #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL EGL +#define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->X11.handle) +#define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfwLibrary.X11.display) + //======================================================================== // GLFW platform specific types From d3d972aa9ddf622a7a64b1eb0bd827add15a6752 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 00:15:36 +0200 Subject: [PATCH 25/81] Fixed typo in dlopen macro. --- src/x11_egl_opengl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index eaefd640..0367ef40 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -309,7 +309,7 @@ static int createContext(_GLFWwindow* window, int _glfwInitOpenGL(void) { -#ifdef _GLFW_DLOPEN_LIBGL +#ifdef _GLFW_DLOPEN_LIBEGL int i; char* libEGL_names[ ] = { @@ -362,7 +362,7 @@ int _glfwInitOpenGL(void) void _glfwTerminateOpenGL(void) { // Unload libEGL.so if necessary -#ifdef _GLFW_DLOPEN_LIBGL +#ifdef _GLFW_DLOPEN_LIBEGL if (_glfwLibrary.EGL.libEGL != NULL) { dlclose(_glfwLibrary.EGL.libEGL); From fd4967b01a373607ca8174bf6fd778edd41d3c93 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 00:17:58 +0200 Subject: [PATCH 26/81] Removed superfluous casts. --- src/x11_egl_platform.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/x11_egl_platform.h b/src/x11_egl_platform.h index 1ab83f89..149bdf2f 100644 --- a/src/x11_egl_platform.h +++ b/src/x11_egl_platform.h @@ -52,8 +52,8 @@ #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL EGL #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL EGL -#define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->X11.handle) -#define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfwLibrary.X11.display) +#define _GLFW_EGL_NATIVE_WINDOW window->X11.handle +#define _GLFW_EGL_NATIVE_DISPLAY _glfwLibrary.X11.display //======================================================================== From fd688e033212bdb59181871ddfdf7e369b2e4c97 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 00:19:58 +0200 Subject: [PATCH 27/81] Formatting. --- src/x11_egl_opengl.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 0367ef40..a0479183 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -190,7 +190,7 @@ static int createContext(_GLFWwindow* window, EGLint fbconfigID) { int attribs[40], visMask; - EGLint dummy, index, vid = 0; + EGLint dummy, index, visualID = 0; EGLint red_size, green_size, blue_size, alpha_size; EGLConfig fbconfig[_GLFW_EGL_CONFIG_IN]; EGLContext share = NULL; @@ -223,16 +223,16 @@ 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, *fbconfig, EGL_NATIVE_VISUAL_ID, &vid); + eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, EGL_NATIVE_VISUAL_ID, &visualID); // Init visual template visTemplate.screen = _glfwLibrary.X11.screen; visMask = VisualScreenMask; - if (vid != 0) + if (visualID) { // The X window visual must match the EGL config - visTemplate.visualid = vid; + visTemplate.visualid = visualID; visMask |= VisualIDMask; } else @@ -285,7 +285,7 @@ static int createContext(_GLFWwindow* window, // TODO: Handle all the various error codes here _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: Failed to create OpenGL(|ES) context"); + "X11/EGL: Failed to create OpenGL ES context"); return GL_FALSE; } @@ -361,7 +361,6 @@ int _glfwInitOpenGL(void) void _glfwTerminateOpenGL(void) { - // Unload libEGL.so if necessary #ifdef _GLFW_DLOPEN_LIBEGL if (_glfwLibrary.EGL.libEGL != NULL) { @@ -369,6 +368,7 @@ void _glfwTerminateOpenGL(void) _glfwLibrary.EGL.libEGL = NULL; } #endif + eglTerminate(_glfwLibrary.EGL.display); } @@ -468,7 +468,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) if (window->EGL.surface == EGL_NO_SURFACE) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: Failed to create window surface"); + "X11/EGL: Failed to create window surface"); } } From ddb497c5d5198498951da394fdebadd1cc6922c1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 02:02:20 +0200 Subject: [PATCH 28/81] Removed hard-coded EGL config limit. --- src/x11_egl_opengl.c | 81 ++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index a0479183..c82adabe 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -33,9 +33,6 @@ #include #include -// Max number of EGL configuration we handle -#define _GLFW_EGL_CONFIG_IN 15 - //======================================================================== // Returns the specified attribute of the specified EGLConfig @@ -57,16 +54,26 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, unsigned int* found) { - EGLConfig fbconfigs[_GLFW_EGL_CONFIG_IN]; + EGLConfig* fbconfigs; _GLFWfbconfig* result; int i, count = 0; *found = 0; - eglGetConfigs(_glfwLibrary.EGL.display, fbconfigs, - _GLFW_EGL_CONFIG_IN, &count); + eglGetConfigs(_glfwLibrary.EGL.display, NULL, 0, &count); + + fbconfigs = (EGLConfig*) malloc(sizeof(EGLConfig) * count); + if (!fbconfigs) + { + _glfwSetError(GLFW_OUT_OF_MEMORY, NULL); + return NULL; + } + + eglGetConfigs(_glfwLibrary.EGL.display, fbconfigs, count, &count); if (!count) { + free(fbconfigs); + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/EGL: No EGLConfigs returned"); return NULL; @@ -75,8 +82,9 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); if (!result) { - _glfwSetError(GLFW_OUT_OF_MEMORY, - "X11/EGL: Failed to allocate _GLFWfbconfig array"); + free(fbconfigs); + + _glfwSetError(GLFW_OUT_OF_MEMORY, NULL); return NULL; } @@ -130,6 +138,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, (*found)++; } + free(fbconfigs); return result; } @@ -140,18 +149,13 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID) { - EGLint dummy; - EGLConfig fbconfig[_GLFW_EGL_CONFIG_IN]; + EGLint count; + EGLConfig fbconfig; int attribs[] = { EGL_CONFIG_ID, fbconfigID, None }; - eglChooseConfig(_glfwLibrary.EGL.display, - attribs, - fbconfig, - _GLFW_EGL_CONFIG_IN, - &dummy); - - if (!dummy) + eglChooseConfig(_glfwLibrary.EGL.display, attribs, &fbconfig, 1, &count); + if (!count) { // This should never ever happen // TODO: Flag this as an error and propagate up @@ -165,15 +169,15 @@ static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID) // true sounds better than false, so we hardcode true here window->accelerated = GL_TRUE; - window->redBits = getFBConfigAttrib(*fbconfig, EGL_RED_SIZE); - window->greenBits = getFBConfigAttrib(*fbconfig, EGL_GREEN_SIZE); - window->blueBits = getFBConfigAttrib(*fbconfig, EGL_BLUE_SIZE); + window->redBits = getFBConfigAttrib(fbconfig, EGL_RED_SIZE); + window->greenBits = getFBConfigAttrib(fbconfig, EGL_GREEN_SIZE); + window->blueBits = getFBConfigAttrib(fbconfig, EGL_BLUE_SIZE); - window->alphaBits = getFBConfigAttrib(*fbconfig, EGL_ALPHA_SIZE); - window->depthBits = getFBConfigAttrib(*fbconfig, EGL_DEPTH_SIZE); - window->stencilBits = getFBConfigAttrib(*fbconfig, EGL_STENCIL_SIZE); + window->alphaBits = getFBConfigAttrib(fbconfig, EGL_ALPHA_SIZE); + window->depthBits = getFBConfigAttrib(fbconfig, EGL_DEPTH_SIZE); + window->stencilBits = getFBConfigAttrib(fbconfig, EGL_STENCIL_SIZE); - window->samples = getFBConfigAttrib(*fbconfig, EGL_SAMPLES); + window->samples = getFBConfigAttrib(fbconfig, EGL_SAMPLES); } @@ -190,9 +194,9 @@ static int createContext(_GLFWwindow* window, EGLint fbconfigID) { int attribs[40], visMask; - EGLint dummy, index, visualID = 0; + EGLint count, index, visualID = 0; EGLint red_size, green_size, blue_size, alpha_size; - EGLConfig fbconfig[_GLFW_EGL_CONFIG_IN]; + EGLConfig fbconfig; EGLContext share = NULL; XVisualInfo visTemplate; @@ -206,13 +210,8 @@ static int createContext(_GLFWwindow* window, setEGLattrib(attribs, index, EGL_CONFIG_ID, fbconfigID); setEGLattrib(attribs, index, EGL_NONE, EGL_NONE); - eglChooseConfig(_glfwLibrary.EGL.display, - attribs, - fbconfig, - _GLFW_EGL_CONFIG_IN, - &dummy); - - if (!dummy) + eglChooseConfig(_glfwLibrary.EGL.display, attribs, &fbconfig, 1, &count); + if (!count) { _glfwSetError(GLFW_PLATFORM_ERROR, "X11/EGL: Failed to retrieve the selected EGLConfig"); @@ -223,7 +222,7 @@ 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, *fbconfig, EGL_NATIVE_VISUAL_ID, &visualID); + eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, EGL_NATIVE_VISUAL_ID, &visualID); // Init visual template visTemplate.screen = _glfwLibrary.X11.screen; @@ -240,13 +239,13 @@ static int createContext(_GLFWwindow* window, // some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID // attribute, so attempt to find the closest match. - eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, + eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, EGL_RED_SIZE, &red_size); - eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, + eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, EGL_GREEN_SIZE, &green_size); - eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, + eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, EGL_BLUE_SIZE, &blue_size); - eglGetConfigAttrib(_glfwLibrary.EGL.display, *fbconfig, + eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, EGL_ALPHA_SIZE, &alpha_size); visTemplate.depth = red_size + green_size + blue_size + alpha_size; @@ -254,7 +253,7 @@ static int createContext(_GLFWwindow* window, } window->EGL.visual = XGetVisualInfo(_glfwLibrary.X11.display, - visMask, &visTemplate, &dummy); + visMask, &visTemplate, &count); if (window->EGL.visual == NULL) { @@ -278,7 +277,7 @@ static int createContext(_GLFWwindow* window, eglBindAPI(EGL_OPENGL_ES_API); window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display, - *fbconfig, share, attribs); + fbconfig, share, attribs); if (window->EGL.context == EGL_NO_CONTEXT) { @@ -289,7 +288,7 @@ static int createContext(_GLFWwindow* window, return GL_FALSE; } - window->EGL.config = *fbconfig; + window->EGL.config = fbconfig; refreshContextParams(window, fbconfigID); From c9c94e44d217e9777cac199298502bc1d05ce3f1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 02:08:01 +0200 Subject: [PATCH 29/81] Formatting. --- src/x11_egl_opengl.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index c82adabe..a6582aa7 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -90,6 +90,8 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, for (i = 0; i < count; i++) { + _GLFWfbconfig* f = result + *found; + if (!getFBConfigAttrib(fbconfigs[i], EGL_NATIVE_VISUAL_ID)) { // Only consider EGLConfigs with associated visuals @@ -117,23 +119,23 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, } if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE && - !(getFBConfigAttrib(fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) + !(getFBConfigAttrib(fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) { // User requested only OpenGL ES 2.0 context continue; } - result[*found].redBits = getFBConfigAttrib(fbconfigs[i], EGL_RED_SIZE); - result[*found].greenBits = getFBConfigAttrib(fbconfigs[i], EGL_GREEN_SIZE); - result[*found].blueBits = getFBConfigAttrib(fbconfigs[i], EGL_BLUE_SIZE); + f->redBits = getFBConfigAttrib(fbconfigs[i], EGL_RED_SIZE); + f->greenBits = getFBConfigAttrib(fbconfigs[i], EGL_GREEN_SIZE); + f->blueBits = getFBConfigAttrib(fbconfigs[i], EGL_BLUE_SIZE); - result[*found].alphaBits = getFBConfigAttrib(fbconfigs[i], EGL_ALPHA_SIZE); - result[*found].depthBits = getFBConfigAttrib(fbconfigs[i], EGL_DEPTH_SIZE); - result[*found].stencilBits = getFBConfigAttrib(fbconfigs[i], EGL_STENCIL_SIZE); + f->alphaBits = getFBConfigAttrib(fbconfigs[i], EGL_ALPHA_SIZE); + f->depthBits = getFBConfigAttrib(fbconfigs[i], EGL_DEPTH_SIZE); + f->stencilBits = getFBConfigAttrib(fbconfigs[i], EGL_STENCIL_SIZE); - result[*found].samples = getFBConfigAttrib(fbconfigs[i], EGL_SAMPLES); + f->samples = getFBConfigAttrib(fbconfigs[i], EGL_SAMPLES); - result[*found].platformID = (GLFWintptr) getFBConfigAttrib(fbconfigs[i], EGL_CONFIG_ID); + f->platformID = (GLFWintptr) getFBConfigAttrib(fbconfigs[i], EGL_CONFIG_ID); (*found)++; } From 1a05d6db70f3d6202c6affccac405be31eb7fa92 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 02:10:39 +0200 Subject: [PATCH 30/81] Renamed GLX implementation file. --- src/CMakeLists.txt | 8 +++++--- src/{x11_opengl.c => x11_glx_opengl.c} | 0 2 files changed, 5 insertions(+), 3 deletions(-) rename src/{x11_opengl.c => x11_glx_opengl.c} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3ba760f9..680cb241 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,13 +23,15 @@ elseif (_GLFW_WIN32_WGL) elseif (_GLFW_X11_GLX) set(glfw_HEADERS ${common_HEADERS} x11_platform.h) set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c - x11_gamma.c x11_init.c x11_input.c x11_joystick.c - x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) + x11_gamma.c x11_glx_opengl.c x11_init.c x11_input.c + x11_joystick.c x11_keysym2unicode.c x11_time.c + x11_window.c) elseif (_GLFW_X11_EGL) set(glfw_HEADERS ${common_HEADERS} x11_egl_platform.h) set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c x11_gamma.c x11_init.c x11_input.c x11_joystick.c - x11_keysym2unicode.c x11_egl_opengl.c x11_time.c x11_window.c) + x11_keysym2unicode.c x11_egl_opengl.c x11_time.c + x11_window.c) endif() add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) diff --git a/src/x11_opengl.c b/src/x11_glx_opengl.c similarity index 100% rename from src/x11_opengl.c rename to src/x11_glx_opengl.c From 546124f1fb14e2f7ebb917015c5a406b24b6617f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 02:10:59 +0200 Subject: [PATCH 31/81] Fixed invalid file mode. --- src/win32_window.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/win32_window.c diff --git a/src/win32_window.c b/src/win32_window.c old mode 100755 new mode 100644 From 5417130f96075650a1142f14b6507d3cef15651a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 03:03:33 +0200 Subject: [PATCH 32/81] Added new options to version string. --- src/x11_init.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/x11_init.c b/src/x11_init.c index 372fc2dd..3ad323f4 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -690,6 +690,11 @@ int _glfwPlatformTerminate(void) const char* _glfwPlatformGetVersionString(void) { const char* version = _GLFW_VERSION_FULL +#if defined(_GLFW_X11_GLX) + " GLX" +#elif defined(_GLFW_X11_EGL) + " EGL" +#endif #if defined(_GLFW_HAS_XRANDR) " XRandR" #endif @@ -708,8 +713,12 @@ const char* _glfwPlatformGetVersionString(void) " glXGetProcAddressARB" #elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT) " glXGetProcAddressEXT" +#elif defined(_GLFW_HAS_EGLGETPROCADDRESS) + " eglGetProcAddress" #elif defined(_GLFW_DLOPEN_LIBGL) " dlsym(libGL)" +#elif defined(_GLFW_DLOPEN_LIBEGL) + " dlsym(libEGL)" #else " no-extension-support" #endif From 2796ecb5566a5a87f3a1479c1d746f0557062fb1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 03:28:03 +0200 Subject: [PATCH 33/81] Updated platform API tags. --- src/x11_clipboard.c | 4 ++-- src/x11_egl_opengl.c | 2 +- src/x11_fullscreen.c | 4 ++-- src/x11_gamma.c | 6 +++--- src/x11_init.c | 4 ++-- src/x11_input.c | 2 +- src/x11_joystick.c | 2 +- src/x11_keysym2unicode.c | 2 +- src/x11_time.c | 2 +- src/x11_window.c | 8 ++++---- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index a833ed1f..5bc92d44 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -182,7 +182,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) if (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_FAILED) { _glfwSetError(GLFW_FORMAT_UNAVAILABLE, - "X11/GLX: Failed to convert selection to string"); + "X11: Failed to convert selection to string"); return NULL; } diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index a6582aa7..82880c93 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/EGL/GLES +// Platform: X11/EGL // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index a17acde4..e718951f 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -350,7 +350,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) if (vislist == NULL) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to retrieve the available visuals"); + "X11: Failed to retrieve the available visuals"); return 0; } diff --git a/src/x11_gamma.c b/src/x11_gamma.c index 44cd1139..148ae740 100644 --- a/src/x11_gamma.c +++ b/src/x11_gamma.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -115,7 +115,7 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp) if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to get gamma ramp due to size " + "X11: Failed to get gamma ramp due to size " "incompatibility"); return; } @@ -166,7 +166,7 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp) if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to set gamma ramp due to size " + "X11: Failed to set gamma ramp due to size " "incompatibility"); return; } diff --git a/src/x11_init.c b/src/x11_init.c index 3ad323f4..75aa6c59 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -491,7 +491,7 @@ static GLboolean initDisplay(void) _glfwLibrary.X11.display = XOpenDisplay(NULL); if (!_glfwLibrary.X11.display) { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: Failed to open X display"); + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11: Failed to open X display"); return GL_FALSE; } @@ -525,7 +525,7 @@ static GLboolean initDisplay(void) &_glfwLibrary.X11.RandR.minorVersion)) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to query RandR version"); + "X11: Failed to query RandR version"); return GL_FALSE; } } diff --git a/src/x11_input.c b/src/x11_input.c index 49961395..2ea8b8c4 100644 --- a/src/x11_input.c +++ b/src/x11_input.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11 (Unix) +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/x11_joystick.c b/src/x11_joystick.c index 444c479f..35dad02b 100644 --- a/src/x11_joystick.c +++ b/src/x11_joystick.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/x11_keysym2unicode.c b/src/x11_keysym2unicode.c index 1f610fdd..c0d10c6e 100644 --- a/src/x11_keysym2unicode.c +++ b/src/x11_keysym2unicode.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/x11_time.c b/src/x11_time.c index f1445233..bf3335d3 100644 --- a/src/x11_time.c +++ b/src/x11_time.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/x11_window.c b/src/x11_window.c index 84b6f7d6..9eca8fd1 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/GLX +// Platform: X11 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -146,7 +146,7 @@ static GLboolean createWindow(_GLFWwindow* window, // TODO: Handle all the various error codes here _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to create window"); + "X11: Failed to create window"); return GL_FALSE; } } @@ -205,7 +205,7 @@ static GLboolean createWindow(_GLFWwindow* window, if (!hints) { _glfwSetError(GLFW_OUT_OF_MEMORY, - "X11/GLX: Failed to allocate WM hints"); + "X11: Failed to allocate WM hints"); return GL_FALSE; } @@ -222,7 +222,7 @@ static GLboolean createWindow(_GLFWwindow* window, if (!hints) { _glfwSetError(GLFW_OUT_OF_MEMORY, - "X11/GLX: Failed to allocate size hints"); + "X11: Failed to allocate size hints"); return GL_FALSE; } From 0f4cdd5194b75817941902104d565d7c353e4498 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 17:40:20 +0200 Subject: [PATCH 34/81] Fixed invalid attribute list terminator. --- src/x11_egl_opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 82880c93..06490e1a 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -154,7 +154,7 @@ static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID) EGLint count; EGLConfig fbconfig; - int attribs[] = { EGL_CONFIG_ID, fbconfigID, None }; + int attribs[] = { EGL_CONFIG_ID, fbconfigID, EGL_NONE, EGL_NONE }; eglChooseConfig(_glfwLibrary.EGL.display, attribs, &fbconfig, 1, &count); if (!count) From ea1506ba67a4023b159bcc6745403e8fd81e2bc1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 18:04:43 +0200 Subject: [PATCH 35/81] Fixed EGLConfig nomenclature, simplified refresh. --- src/x11_egl_opengl.c | 100 ++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 59 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 06490e1a..23271ac2 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -38,10 +38,10 @@ // Returns the specified attribute of the specified EGLConfig //======================================================================== -static int getFBConfigAttrib(EGLConfig fbconfig, int attrib) +static int getConfigAttrib(EGLConfig config, int attrib) { int value; - eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, attrib, &value); + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, attrib, &value); return value; } @@ -54,7 +54,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, unsigned int* found) { - EGLConfig* fbconfigs; + EGLConfig* configs; _GLFWfbconfig* result; int i, count = 0; @@ -62,17 +62,17 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, eglGetConfigs(_glfwLibrary.EGL.display, NULL, 0, &count); - fbconfigs = (EGLConfig*) malloc(sizeof(EGLConfig) * count); - if (!fbconfigs) + configs = (EGLConfig*) malloc(sizeof(EGLConfig) * count); + if (!configs) { _glfwSetError(GLFW_OUT_OF_MEMORY, NULL); return NULL; } - eglGetConfigs(_glfwLibrary.EGL.display, fbconfigs, count, &count); + eglGetConfigs(_glfwLibrary.EGL.display, configs, count, &count); if (!count) { - free(fbconfigs); + free(configs); _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/EGL: No EGLConfigs returned"); @@ -82,7 +82,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); if (!result) { - free(fbconfigs); + free(configs); _glfwSetError(GLFW_OUT_OF_MEMORY, NULL); return NULL; @@ -92,55 +92,54 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, { _GLFWfbconfig* f = result + *found; - if (!getFBConfigAttrib(fbconfigs[i], EGL_NATIVE_VISUAL_ID)) + if (!getConfigAttrib(configs[i], EGL_NATIVE_VISUAL_ID)) { // Only consider EGLConfigs with associated visuals continue; } - if (!(getFBConfigAttrib(fbconfigs[i], - EGL_COLOR_BUFFER_TYPE) & EGL_RGB_BUFFER)) + if (!(getConfigAttrib(configs[i], EGL_COLOR_BUFFER_TYPE) & EGL_RGB_BUFFER)) { // Only consider RGB(A) EGLConfigs continue; } - if (!(getFBConfigAttrib(fbconfigs[i], EGL_SURFACE_TYPE) & EGL_WINDOW_BIT)) + if (!(getConfigAttrib(configs[i], EGL_SURFACE_TYPE) & EGL_WINDOW_BIT)) { // Only consider window EGLConfigs continue; } - if (!(getFBConfigAttrib(fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES_BIT) && - !(getFBConfigAttrib(fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) + if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES_BIT) && + !(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) { // Only consider OpenGL ES context continue; } if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE && - !(getFBConfigAttrib(fbconfigs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) + !(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) { // User requested only OpenGL ES 2.0 context continue; } - f->redBits = getFBConfigAttrib(fbconfigs[i], EGL_RED_SIZE); - f->greenBits = getFBConfigAttrib(fbconfigs[i], EGL_GREEN_SIZE); - f->blueBits = getFBConfigAttrib(fbconfigs[i], EGL_BLUE_SIZE); + f->redBits = getConfigAttrib(configs[i], EGL_RED_SIZE); + f->greenBits = getConfigAttrib(configs[i], EGL_GREEN_SIZE); + f->blueBits = getConfigAttrib(configs[i], EGL_BLUE_SIZE); - f->alphaBits = getFBConfigAttrib(fbconfigs[i], EGL_ALPHA_SIZE); - f->depthBits = getFBConfigAttrib(fbconfigs[i], EGL_DEPTH_SIZE); - f->stencilBits = getFBConfigAttrib(fbconfigs[i], EGL_STENCIL_SIZE); + f->alphaBits = getConfigAttrib(configs[i], EGL_ALPHA_SIZE); + f->depthBits = getConfigAttrib(configs[i], EGL_DEPTH_SIZE); + f->stencilBits = getConfigAttrib(configs[i], EGL_STENCIL_SIZE); - f->samples = getFBConfigAttrib(fbconfigs[i], EGL_SAMPLES); + f->samples = getConfigAttrib(configs[i], EGL_SAMPLES); - f->platformID = (GLFWintptr) getFBConfigAttrib(fbconfigs[i], EGL_CONFIG_ID); + f->platformID = (GLFWintptr) getConfigAttrib(configs[i], EGL_CONFIG_ID); (*found)++; } - free(fbconfigs); + free(configs); return result; } @@ -149,37 +148,21 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, // Read back framebuffer parameters from the context //======================================================================== -static void refreshContextParams(_GLFWwindow* window, EGLint fbconfigID) +static void refreshContextParams(_GLFWwindow* window) { - EGLint count; - EGLConfig fbconfig; - - int attribs[] = { EGL_CONFIG_ID, fbconfigID, EGL_NONE, EGL_NONE }; - - eglChooseConfig(_glfwLibrary.EGL.display, attribs, &fbconfig, 1, &count); - if (!count) - { - // This should never ever happen - // TODO: Flag this as an error and propagate up - _glfwSetError(GLFW_PLATFORM_ERROR, "X11/EGL: Cannot find known " - "EGLConfig by ID. This cannot " - "happen. Have a nice day.\n"); - abort(); - } - // There is no clear definition of an "accelerated" context on X11/EGL, and // true sounds better than false, so we hardcode true here window->accelerated = GL_TRUE; - window->redBits = getFBConfigAttrib(fbconfig, EGL_RED_SIZE); - window->greenBits = getFBConfigAttrib(fbconfig, EGL_GREEN_SIZE); - window->blueBits = getFBConfigAttrib(fbconfig, EGL_BLUE_SIZE); + window->redBits = getConfigAttrib(window->EGL.config, EGL_RED_SIZE); + window->greenBits = getConfigAttrib(window->EGL.config, EGL_GREEN_SIZE); + window->blueBits = getConfigAttrib(window->EGL.config, EGL_BLUE_SIZE); - window->alphaBits = getFBConfigAttrib(fbconfig, EGL_ALPHA_SIZE); - window->depthBits = getFBConfigAttrib(fbconfig, EGL_DEPTH_SIZE); - window->stencilBits = getFBConfigAttrib(fbconfig, EGL_STENCIL_SIZE); + window->alphaBits = getConfigAttrib(window->EGL.config, EGL_ALPHA_SIZE); + window->depthBits = getConfigAttrib(window->EGL.config, EGL_DEPTH_SIZE); + window->stencilBits = getConfigAttrib(window->EGL.config, EGL_STENCIL_SIZE); - window->samples = getFBConfigAttrib(fbconfig, EGL_SAMPLES); + window->samples = getConfigAttrib(window->EGL.config, EGL_SAMPLES); } @@ -198,7 +181,7 @@ static int createContext(_GLFWwindow* window, int attribs[40], visMask; EGLint count, index, visualID = 0; EGLint red_size, green_size, blue_size, alpha_size; - EGLConfig fbconfig; + EGLConfig config; EGLContext share = NULL; XVisualInfo visTemplate; @@ -212,7 +195,7 @@ static int createContext(_GLFWwindow* window, setEGLattrib(attribs, index, EGL_CONFIG_ID, fbconfigID); setEGLattrib(attribs, index, EGL_NONE, EGL_NONE); - eglChooseConfig(_glfwLibrary.EGL.display, attribs, &fbconfig, 1, &count); + eglChooseConfig(_glfwLibrary.EGL.display, attribs, &config, 1, &count); if (!count) { _glfwSetError(GLFW_PLATFORM_ERROR, @@ -224,7 +207,7 @@ 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, fbconfig, EGL_NATIVE_VISUAL_ID, &visualID); + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, EGL_NATIVE_VISUAL_ID, &visualID); // Init visual template visTemplate.screen = _glfwLibrary.X11.screen; @@ -241,13 +224,13 @@ static int createContext(_GLFWwindow* window, // some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID // attribute, so attempt to find the closest match. - eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, EGL_RED_SIZE, &red_size); - eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, EGL_GREEN_SIZE, &green_size); - eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, EGL_BLUE_SIZE, &blue_size); - eglGetConfigAttrib(_glfwLibrary.EGL.display, fbconfig, + eglGetConfigAttrib(_glfwLibrary.EGL.display, config, EGL_ALPHA_SIZE, &alpha_size); visTemplate.depth = red_size + green_size + blue_size + alpha_size; @@ -279,7 +262,7 @@ static int createContext(_GLFWwindow* window, eglBindAPI(EGL_OPENGL_ES_API); window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display, - fbconfig, share, attribs); + config, share, attribs); if (window->EGL.context == EGL_NO_CONTEXT) { @@ -290,9 +273,8 @@ static int createContext(_GLFWwindow* window, return GL_FALSE; } - window->EGL.config = fbconfig; - - refreshContextParams(window, fbconfigID); + window->EGL.config = config; + refreshContextParams(window); return GL_TRUE; } From bd179634dc6212f7df6ef5bce060e6dd0d217844 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 20 Jul 2012 18:11:26 +0200 Subject: [PATCH 36/81] Formatting. --- src/x11_egl_opengl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 23271ac2..f52b962c 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -498,8 +498,7 @@ int _glfwPlatformExtensionSupported(const char* extension) const char* extensions; // Get list of GLX extensions - extensions = eglQueryString(_glfwLibrary.EGL.display, - EGL_EXTENSIONS); + extensions = eglQueryString(_glfwLibrary.EGL.display, EGL_EXTENSIONS); if (extensions != NULL) { if (_glfwStringInExtensionString(extension, (unsigned char*) extensions)) From b78fd85e116063312734e2b41d9cbdc24492ac50 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 21 Jul 2012 23:51:08 +0200 Subject: [PATCH 37/81] Moved glext.h inclusion back. --- src/cocoa_platform.h | 5 ----- src/internal.h | 5 +++++ src/win32_platform.h | 5 ----- src/x11_glx_platform.h | 5 ----- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index b3fe0491..026d40ad 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -41,11 +41,6 @@ typedef void* id; #endif -// This path may need to be changed if you build GLFW using your own setup -// We ship and use our own copy of glext.h since GLFW uses fairly new -// extensions and not all operating systems come with an up-to-date version -#include "../support/GL/glext.h" - #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS NS diff --git a/src/internal.h b/src/internal.h index 37813c6f..4f34bd21 100644 --- a/src/internal.h +++ b/src/internal.h @@ -71,6 +71,11 @@ typedef struct _GLFWlibrary _GLFWlibrary; #include "../include/GL/glfw3.h" +// This path may need to be changed if you build GLFW using your own setup +// We ship and use our own copy of glext.h since GLFW uses fairly new +// extensions and not all operating systems come with an up-to-date version +#include "../support/GL/glext.h" + #if defined(_GLFW_COCOA_NSGL) #include "cocoa_platform.h" #elif defined(_GLFW_WIN32_WGL) diff --git a/src/win32_platform.h b/src/win32_platform.h index 849dd337..eeadbf22 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -63,11 +63,6 @@ #include #include -// This path may need to be changed if you build GLFW using your own setup -// We ship and use our own copy of glext.h since GLFW uses fairly new -// extensions and not all operating systems come with an up-to-date version -#include "../support/GL/glext.h" - // This path may need to be changed if you build GLFW using your own setup // We ship and use our own copy of wglext.h since GLFW uses fairly new // extensions and not all operating systems come with an up-to-date version diff --git a/src/x11_glx_platform.h b/src/x11_glx_platform.h index b5397d06..2882a197 100644 --- a/src/x11_glx_platform.h +++ b/src/x11_glx_platform.h @@ -34,11 +34,6 @@ #define GLX_GLXEXT_LEGACY #include -// This path may need to be changed if you build GLFW using your own setup -// We ship and use our own copy of glext.h since GLFW uses fairly new -// extensions and not all operating systems come with an up-to-date version -#include "../support/GL/glext.h" - // This path may need to be changed if you build GLFW using your own setup // We ship and use our own copy of glxext.h since GLFW uses fairly new // extensions and not all operating systems come with an up-to-date version From e9c82a82b2c63cbbf98d4de06902dbdcdea71105 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 21 Jul 2012 23:51:44 +0200 Subject: [PATCH 38/81] Added eglext.h header. --- src/x11_egl_platform.h | 5 + support/GL/eglext.h | 444 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 449 insertions(+) create mode 100644 support/GL/eglext.h diff --git a/src/x11_egl_platform.h b/src/x11_egl_platform.h index 149bdf2f..f3974676 100644 --- a/src/x11_egl_platform.h +++ b/src/x11_egl_platform.h @@ -33,6 +33,11 @@ #include +// This path may need to be changed if you build GLFW using your own setup +// We ship and use our own copy of eglext.h since GLFW uses fairly new +// extensions and not all operating systems come with an up-to-date version +#include "../support/GL/eglext.h" + // Do we have support for dlopen/dlsym? #if defined(_GLFW_HAS_DLOPEN) #include diff --git a/support/GL/eglext.h b/support/GL/eglext.h new file mode 100644 index 00000000..5516e7ad --- /dev/null +++ b/support/GL/eglext.h @@ -0,0 +1,444 @@ +#ifndef __eglext_h_ +#define __eglext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2007-2012 The Khronos Group Inc. +** +** Permission is hereby granted, free of charge, to any person obtaining a +** copy of this software and/or associated documentation files (the +** "Materials"), to deal in the Materials without restriction, including +** without limitation the rights to use, copy, modify, merge, publish, +** distribute, sublicense, and/or sell copies of the Materials, and to +** permit persons to whom the Materials are furnished to do so, subject to +** the following conditions: +** +** The above copyright notice and this permission notice shall be included +** in all copies or substantial portions of the Materials. +** +** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. +*/ + +#include + +/*************************************************************/ + +/* Header file version number */ +/* Current version at http://www.khronos.org/registry/egl/ */ +/* $Revision: 18175 $ on $Date: 2012-06-13 11:26:12 -0700 (Wed, 13 Jun 2012) $ */ +#define EGL_EGLEXT_VERSION 13 + +#ifndef EGL_KHR_config_attribs +#define EGL_KHR_config_attribs 1 +#define EGL_CONFORMANT_KHR 0x3042 /* EGLConfig attribute */ +#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040 /* EGL_SURFACE_TYPE bitfield */ +#endif + +#ifndef EGL_KHR_lock_surface +#define EGL_KHR_lock_surface 1 +#define EGL_READ_SURFACE_BIT_KHR 0x0001 /* EGL_LOCK_USAGE_HINT_KHR bitfield */ +#define EGL_WRITE_SURFACE_BIT_KHR 0x0002 /* EGL_LOCK_USAGE_HINT_KHR bitfield */ +#define EGL_LOCK_SURFACE_BIT_KHR 0x0080 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100 /* EGL_SURFACE_TYPE bitfield */ +#define EGL_MATCH_FORMAT_KHR 0x3043 /* EGLConfig attribute */ +#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGB_565_KHR 0x30C1 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_FORMAT_RGBA_8888_KHR 0x30C3 /* EGL_MATCH_FORMAT_KHR value */ +#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4 /* eglLockSurfaceKHR attribute */ +#define EGL_LOCK_USAGE_HINT_KHR 0x30C5 /* eglLockSurfaceKHR attribute */ +#define EGL_BITMAP_POINTER_KHR 0x30C6 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PITCH_KHR 0x30C7 /* eglQuerySurface attribute */ +#define EGL_BITMAP_ORIGIN_KHR 0x30C8 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9 /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC /* eglQuerySurface attribute */ +#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD /* eglQuerySurface attribute */ +#define EGL_LOWER_LEFT_KHR 0x30CE /* EGL_BITMAP_ORIGIN_KHR value */ +#define EGL_UPPER_LEFT_KHR 0x30CF /* EGL_BITMAP_ORIGIN_KHR value */ +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay display, EGLSurface surface); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface); +#endif + +#ifndef EGL_KHR_image +#define EGL_KHR_image 1 +#define EGL_NATIVE_PIXMAP_KHR 0x30B0 /* eglCreateImageKHR target */ +typedef void *EGLImageKHR; +#define EGL_NO_IMAGE_KHR ((EGLImageKHR)0) +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image); +#endif + +#ifndef EGL_KHR_vg_parent_image +#define EGL_KHR_vg_parent_image 1 +#define EGL_VG_PARENT_IMAGE_KHR 0x30BA /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_KHR_gl_texture_2D_image +#define EGL_KHR_gl_texture_2D_image 1 +#define EGL_GL_TEXTURE_2D_KHR 0x30B1 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_gl_texture_cubemap_image +#define EGL_KHR_gl_texture_cubemap_image 1 +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8 /* eglCreateImageKHR target */ +#endif + +#ifndef EGL_KHR_gl_texture_3D_image +#define EGL_KHR_gl_texture_3D_image 1 +#define EGL_GL_TEXTURE_3D_KHR 0x30B2 /* eglCreateImageKHR target */ +#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_gl_renderbuffer_image +#define EGL_KHR_gl_renderbuffer_image 1 +#define EGL_GL_RENDERBUFFER_KHR 0x30B9 /* eglCreateImageKHR target */ +#endif + +#if KHRONOS_SUPPORT_INT64 /* EGLTimeKHR requires 64-bit uint support */ +#ifndef EGL_KHR_reusable_sync +#define EGL_KHR_reusable_sync 1 + +typedef void* EGLSyncKHR; +typedef khronos_utime_nanoseconds_t EGLTimeKHR; + +#define EGL_SYNC_STATUS_KHR 0x30F1 +#define EGL_SIGNALED_KHR 0x30F2 +#define EGL_UNSIGNALED_KHR 0x30F3 +#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5 +#define EGL_CONDITION_SATISFIED_KHR 0x30F6 +#define EGL_SYNC_TYPE_KHR 0x30F7 +#define EGL_SYNC_REUSABLE_KHR 0x30FA +#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001 /* eglClientWaitSyncKHR bitfield */ +#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull +#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0) +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync); +EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); +EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync); +typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value); +#endif +#endif + +#ifndef EGL_KHR_image_base +#define EGL_KHR_image_base 1 +/* Most interfaces defined by EGL_KHR_image_pixmap above */ +#define EGL_IMAGE_PRESERVED_KHR 0x30D2 /* eglCreateImageKHR attribute */ +#endif + +#ifndef EGL_KHR_image_pixmap +#define EGL_KHR_image_pixmap 1 +/* Interfaces defined by EGL_KHR_image above */ +#endif + +#ifndef EGL_IMG_context_priority +#define EGL_IMG_context_priority 1 +#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100 +#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101 +#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102 +#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103 +#endif + +#ifndef EGL_KHR_lock_surface2 +#define EGL_KHR_lock_surface2 1 +#define EGL_BITMAP_PIXEL_SIZE_KHR 0x3110 +#endif + +#ifndef EGL_NV_coverage_sample +#define EGL_NV_coverage_sample 1 +#define EGL_COVERAGE_BUFFERS_NV 0x30E0 +#define EGL_COVERAGE_SAMPLES_NV 0x30E1 +#endif + +#ifndef EGL_NV_depth_nonlinear +#define EGL_NV_depth_nonlinear 1 +#define EGL_DEPTH_ENCODING_NV 0x30E2 +#define EGL_DEPTH_ENCODING_NONE_NV 0 +#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3 +#endif + +#if KHRONOS_SUPPORT_INT64 /* EGLTimeNV requires 64-bit uint support */ +#ifndef EGL_NV_sync +#define EGL_NV_sync 1 +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6 +#define EGL_SYNC_STATUS_NV 0x30E7 +#define EGL_SIGNALED_NV 0x30E8 +#define EGL_UNSIGNALED_NV 0x30E9 +#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001 +#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull +#define EGL_ALREADY_SIGNALED_NV 0x30EA +#define EGL_TIMEOUT_EXPIRED_NV 0x30EB +#define EGL_CONDITION_SATISFIED_NV 0x30EC +#define EGL_SYNC_TYPE_NV 0x30ED +#define EGL_SYNC_CONDITION_NV 0x30EE +#define EGL_SYNC_FENCE_NV 0x30EF +#define EGL_NO_SYNC_NV ((EGLSyncNV)0) +typedef void* EGLSyncNV; +typedef khronos_utime_nanoseconds_t EGLTimeNV; +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSyncNV EGLAPIENTRY eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncNV (EGLSyncNV sync); +EGLAPI EGLBoolean EGLAPIENTRY eglFenceNV (EGLSyncNV sync); +EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout); +EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncNV (EGLSyncNV sync, EGLenum mode); +EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync); +typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value); +#endif +#endif + +#if KHRONOS_SUPPORT_INT64 /* Dependent on EGL_KHR_reusable_sync which requires 64-bit uint support */ +#ifndef EGL_KHR_fence_sync +#define EGL_KHR_fence_sync 1 +/* Reuses most tokens and entry points from EGL_KHR_reusable_sync */ +#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0 +#define EGL_SYNC_CONDITION_KHR 0x30F8 +#define EGL_SYNC_FENCE_KHR 0x30F9 +#endif +#endif + +#ifndef EGL_HI_clientpixmap +#define EGL_HI_clientpixmap 1 + +/* Surface Attribute */ +#define EGL_CLIENT_PIXMAP_POINTER_HI 0x8F74 +/* + * Structure representing a client pixmap + * (pixmap's data is in client-space memory). + */ +struct EGLClientPixmapHI +{ + void* pData; + EGLint iWidth; + EGLint iHeight; + EGLint iStride; +}; + +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI(EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap); +#endif /* EGL_HI_clientpixmap */ + +#ifndef EGL_HI_colorformats +#define EGL_HI_colorformats 1 +/* Config Attribute */ +#define EGL_COLOR_FORMAT_HI 0x8F70 +/* Color Formats */ +#define EGL_COLOR_RGB_HI 0x8F71 +#define EGL_COLOR_RGBA_HI 0x8F72 +#define EGL_COLOR_ARGB_HI 0x8F73 +#endif /* EGL_HI_colorformats */ + +#ifndef EGL_MESA_drm_image +#define EGL_MESA_drm_image 1 +#define EGL_DRM_BUFFER_FORMAT_MESA 0x31D0 /* CreateDRMImageMESA attribute */ +#define EGL_DRM_BUFFER_USE_MESA 0x31D1 /* CreateDRMImageMESA attribute */ +#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2 /* EGL_IMAGE_FORMAT_MESA attribute value */ +#define EGL_DRM_BUFFER_MESA 0x31D3 /* eglCreateImageKHR target */ +#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4 +#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x00000001 /* EGL_DRM_BUFFER_USE_MESA bits */ +#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x00000002 /* EGL_DRM_BUFFER_USE_MESA bits */ +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLImageKHR EGLAPIENTRY eglCreateDRMImageMESA (EGLDisplay dpy, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglExportDRMImageMESA (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride); +#endif + +#ifndef EGL_NV_post_sub_buffer +#define EGL_NV_post_sub_buffer 1 +#define EGL_POST_SUB_BUFFER_SUPPORTED_NV 0x30BE +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglPostSubBufferNV (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLPOSTSUBBUFFERNVPROC) (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height); +#endif + +#ifndef EGL_ANGLE_query_surface_pointer +#define EGL_ANGLE_query_surface_pointer 1 +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean eglQuerySurfacePointerANGLE(EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value); +#endif +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACEPOINTERANGLEPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value); +#endif + +#ifndef EGL_ANGLE_surface_d3d_texture_2d_share_handle +#define EGL_ANGLE_surface_d3d_texture_2d_share_handle 1 +#define EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE 0x3200 +#endif + +#ifndef EGL_NV_coverage_sample_resolve +#define EGL_NV_coverage_sample_resolve 1 +#define EGL_COVERAGE_SAMPLE_RESOLVE_NV 0x3131 +#define EGL_COVERAGE_SAMPLE_RESOLVE_DEFAULT_NV 0x3132 +#define EGL_COVERAGE_SAMPLE_RESOLVE_NONE_NV 0x3133 +#endif + +#if KHRONOS_SUPPORT_INT64 /* EGLuint64NV requires 64-bit uint support */ +#ifndef EGL_NV_system_time +#define EGL_NV_system_time 1 + +typedef khronos_utime_nanoseconds_t EGLuint64NV; + +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeFrequencyNV(void); +EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeNV(void); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC) (void); +typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMENVPROC) (void); +#endif +#endif + +#if KHRONOS_SUPPORT_INT64 /* EGLuint64KHR requires 64-bit uint support */ +#ifndef EGL_KHR_stream +#define EGL_KHR_stream 1 +typedef void* EGLStreamKHR; +typedef khronos_uint64_t EGLuint64KHR; +#define EGL_NO_STREAM_KHR ((EGLStreamKHR)0) +#define EGL_CONSUMER_LATENCY_USEC_KHR 0x3210 +#define EGL_PRODUCER_FRAME_KHR 0x3212 +#define EGL_CONSUMER_FRAME_KHR 0x3213 +#define EGL_STREAM_STATE_KHR 0x3214 +#define EGL_STREAM_STATE_CREATED_KHR 0x3215 +#define EGL_STREAM_STATE_CONNECTING_KHR 0x3216 +#define EGL_STREAM_STATE_EMPTY_KHR 0x3217 +#define EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR 0x3218 +#define EGL_STREAM_STATE_OLD_FRAME_AVAILABLE_KHR 0x3219 +#define EGL_STREAM_STATE_DISCONNECTED_KHR 0x321A +#define EGL_BAD_STREAM_KHR 0x321B +#define EGL_BAD_STATE_KHR 0x321C +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamKHR(EGLDisplay dpy, const EGLint *attrib_list); +EGLAPI EGLBoolean EGLAPIENTRY eglDestroyStreamKHR(EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLBoolean EGLAPIENTRY eglStreamAttribKHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamKHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamu64KHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMKHRPROC)(EGLDisplay dpy, const EGLint *attrib_list); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSTREAMKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMATTRIBKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMU64KHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value); +#endif +#endif + +#ifdef EGL_KHR_stream /* Requires KHR_stream extension */ +#ifndef EGL_KHR_stream_consumer_gltexture +#define EGL_KHR_stream_consumer_gltexture 1 +#define EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR 0x321E +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerGLTextureExternalKHR(EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireKHR(EGLDisplay dpy, EGLStreamKHR stream); +EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseKHR(EGLDisplay dpy, EGLStreamKHR stream); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream); +#endif +#endif + +#ifdef EGL_KHR_stream /* Requires KHR_stream extension */ +#ifndef EGL_KHR_stream_producer_eglsurface +#define EGL_KHR_stream_producer_eglsurface 1 +#define EGL_STREAM_BIT_KHR 0x0800 +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLSurface EGLAPIENTRY eglCreateStreamProducerSurfaceKHR(EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC)(EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list); +#endif +#endif + +#ifdef EGL_KHR_stream /* Requires KHR_stream extension */ +#ifndef EGL_KHR_stream_producer_aldatalocator +#define EGL_KHR_stream_producer_aldatalocator 1 +#endif +#endif + +#ifdef EGL_KHR_stream /* Requires KHR_stream extension */ +#ifndef EGL_KHR_stream_fifo +#define EGL_KHR_stream_fifo 1 +/* reuse EGLTimeKHR */ +#define EGL_STREAM_FIFO_LENGTH_KHR 0x31FC +#define EGL_STREAM_TIME_NOW_KHR 0x31FD +#define EGL_STREAM_TIME_CONSUMER_KHR 0x31FE +#define EGL_STREAM_TIME_PRODUCER_KHR 0x31FF +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamTimeKHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value); +#endif /* EGL_EGLEXT_PROTOTYPES */ +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMTIMEKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value); +#endif +#endif + +#ifndef EGL_EXT_create_context_robustness +#define EGL_EXT_create_context_robustness 1 +#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT 0x30BF +#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT 0x3138 +#define EGL_NO_RESET_NOTIFICATION_EXT 0x31BE +#define EGL_LOSE_CONTEXT_ON_RESET_EXT 0x31BF +#endif + +#ifndef EGL_ANGLE_d3d_share_handle_client_buffer +#define EGL_ANGLE_d3d_share_handle_client_buffer 1 +/* reuse EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE */ +#endif + +#ifndef EGL_KHR_create_context +#define EGL_KHR_create_context 1 +#define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION +#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB +#define EGL_CONTEXT_FLAGS_KHR 0x30FC +#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD +#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31BD +#define EGL_NO_RESET_NOTIFICATION_KHR 0x31BE +#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31BF +#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001 +#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002 +#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004 +#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001 +#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002 +#endif + +#ifdef __cplusplus +} +#endif + +#endif From 3b6ec4e7758515c77f7d651ff31e540048a155fb Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Jul 2012 01:10:59 +0200 Subject: [PATCH 39/81] Added client API window hint. --- include/GL/glfw3.h | 18 +++-- readme.html | 2 +- src/cocoa_window.m | 7 ++ src/internal.h | 3 + src/opengl.c | 183 ++++++++++++++++++++++++++----------------- src/win32_window.c | 26 +++--- src/window.c | 9 ++- src/x11_egl_opengl.c | 35 +++++---- src/x11_glx_opengl.c | 27 ++++--- tests/glfwinfo.c | 127 +++++++++++++++++++----------- 10 files changed, 274 insertions(+), 163 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 2ff67627..4ff8e857 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -413,12 +413,17 @@ extern "C" { #define GLFW_STEREO 0x0002100C #define GLFW_WINDOW_RESIZABLE 0x0002100D #define GLFW_FSAA_SAMPLES 0x0002100E -#define GLFW_OPENGL_VERSION_MAJOR 0x0002100F -#define GLFW_OPENGL_VERSION_MINOR 0x00021010 -#define GLFW_OPENGL_FORWARD_COMPAT 0x00021011 -#define GLFW_OPENGL_DEBUG_CONTEXT 0x00021012 -#define GLFW_OPENGL_PROFILE 0x00021013 -#define GLFW_OPENGL_ROBUSTNESS 0x00021014 +#define GLFW_CLIENT_API 0x0002100F +#define GLFW_OPENGL_VERSION_MAJOR 0x00021010 +#define GLFW_OPENGL_VERSION_MINOR 0x00021011 +#define GLFW_OPENGL_FORWARD_COMPAT 0x00021012 +#define GLFW_OPENGL_DEBUG_CONTEXT 0x00021013 +#define GLFW_OPENGL_PROFILE 0x00021014 +#define GLFW_OPENGL_ROBUSTNESS 0x00021015 + +/* GLFW_OPENGL_API mode tokens */ +#define GLFW_OPENGL_API 0x00000001 +#define GLFW_OPENGL_ES_API 0x00000002 /* GLFW_OPENGL_ROBUSTNESS mode tokens */ #define GLFW_OPENGL_NO_ROBUSTNESS 0x00000000 @@ -429,7 +434,6 @@ extern "C" { #define GLFW_OPENGL_NO_PROFILE 0x00000000 #define GLFW_OPENGL_CORE_PROFILE 0x00000001 #define GLFW_OPENGL_COMPAT_PROFILE 0x00000002 -#define GLFW_OPENGL_ES2_PROFILE 0x00000004 /* glfwGetInputMode/glfwSetInputMode tokens */ #define GLFW_CURSOR_MODE 0x00030001 diff --git a/readme.html b/readme.html index cdbb9885..9873da27 100644 --- a/readme.html +++ b/readme.html @@ -280,7 +280,7 @@ version of GLFW.

  • Added glfwGetClipboardString and glfwSetClipboardString functions for interacting with the system clipboard
  • Added glfwGetCurrentContext function for retrieving the window whose OpenGL context is current
  • Added glfwCopyContext function for copying OpenGL state categories between contexts
  • -
  • Added GLFW_OPENGL_ES2_PROFILE profile for creating OpenGL ES 2.0 contexts using the GLX_EXT_create_context_es2_profile and WGL_EXT_create_context_es2_profile extensions
  • +
  • Added GLFW_CLIENT_API window hint for creating contexts for APIs other than desktop OpenGL
  • Added GLFW_OPENGL_ROBUSTNESS window hint and associated strategy tokens for GL_ARB_robustness support
  • Added GLFW_OPENGL_REVISION window parameter to make up for removal of glfwGetGLVersion
  • Added GLFW_INCLUDE_GL3 macro for telling the GLFW header to include gl3.h header instead of gl.h
  • diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 3523806a..8093c3c6 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -717,6 +717,13 @@ static GLboolean createContext(_GLFWwindow* window, else if (colorBits < 15) colorBits = 15; + if (wndconfig->clientAPI != GLFW_OPENGL_ES_API) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, + "Cocoa/NSOpenGL: NSOpenGL does not support OpenGL ES"); + return GL_FALSE; + } + #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 // Fail if any OpenGL version above 2.1 other than 3.2 was requested if (wndconfig->glMajor > 3 || diff --git a/src/internal.h b/src/internal.h index 4f34bd21..bda462a8 100644 --- a/src/internal.h +++ b/src/internal.h @@ -110,6 +110,7 @@ struct _GLFWhints GLboolean stereo; GLboolean resizable; int samples; + int clientAPI; int glMajor; int glMinor; GLboolean glForward; @@ -131,6 +132,7 @@ struct _GLFWwndconfig const char* title; int refreshRate; GLboolean resizable; + int clientAPI; int glMajor; int glMinor; GLboolean glForward; @@ -212,6 +214,7 @@ struct _GLFWwindow // OpenGL extensions and context attributes GLboolean accelerated; // GL_TRUE if OpenGL context is "accelerated" + int clientAPI; int glMajor, glMinor, glRevision; GLboolean glForward, glDebug; int glProfile; diff --git a/src/opengl.c b/src/opengl.c index 59097e1e..ff623ed3 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -36,7 +36,7 @@ //======================================================================== -// Parses the OpenGL version string and extracts the version number +// Parses the client API version string and extracts the version number //======================================================================== static void parseGLVersion(int* major, int* minor, int* rev) @@ -256,89 +256,125 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired, //======================================================================== -// Checks whether the OpenGL part of the window config is sane +// Checks whether the client API part of the window config is sane // It blames glfwOpenWindow because that's the only caller //======================================================================== GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) { - if (wndconfig->glMajor < 1 || wndconfig->glMinor < 0) + if (wndconfig->clientAPI != GLFW_OPENGL_API && + wndconfig->clientAPI != GLFW_OPENGL_ES_API) { - // OpenGL 1.0 is the smallest valid version - _glfwSetError(GLFW_INVALID_VALUE, - "glfwOpenWindow: Invalid OpenGL version requested"); + _glfwSetError(GLFW_INVALID_ENUM, + "glfwOpenWindow: Invalid client API requested"); return GL_FALSE; } - if (wndconfig->glMajor == 1 && wndconfig->glMinor > 5) - { - // OpenGL 1.x series ended with version 1.5 - _glfwSetError(GLFW_INVALID_VALUE, - "glfwOpenWindow: Invalid OpenGL version requested"); - return GL_FALSE; - } - else if (wndconfig->glMajor == 2 && wndconfig->glMinor > 1) - { - // OpenGL 2.x series ended with version 2.1 - _glfwSetError(GLFW_INVALID_VALUE, - "glfwOpenWindow: Invalid OpenGL version requested"); - return GL_FALSE; - } - else if (wndconfig->glMajor == 3 && wndconfig->glMinor > 3) - { - // OpenGL 3.x series ended with version 3.3 - _glfwSetError(GLFW_INVALID_VALUE, - "glfwOpenWindow: Invalid OpenGL version requested"); - return GL_FALSE; - } - else - { - // For now, let everything else through - } - if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE) + if (wndconfig->clientAPI == GLFW_OPENGL_API) { - if (wndconfig->glMajor != 2 || wndconfig->glMinor < 0) + if (wndconfig->glMajor < 1 || wndconfig->glMinor < 0) { - // The OpenGL ES 2.0 profile is currently only defined for version - // 2.0 (see {WGL|GLX}_EXT_create_context_es2_profile), but for - // compatibility with future updates to OpenGL ES, we allow - // everything 2.x and let the driver report invalid 2.x versions - + // OpenGL 1.0 is the smallest valid version _glfwSetError(GLFW_INVALID_VALUE, - "glfwOpenWindow: Invalid OpenGL ES 2.x version requested"); + "glfwOpenWindow: Invalid OpenGL version requested"); return GL_FALSE; } - } - else if (wndconfig->glProfile) - { - if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE && - wndconfig->glProfile != GLFW_OPENGL_COMPAT_PROFILE) + if (wndconfig->glMajor == 1 && wndconfig->glMinor > 5) { - _glfwSetError(GLFW_INVALID_ENUM, - "glfwOpenWindow: Invalid OpenGL profile requested"); - return GL_FALSE; - } - - if (wndconfig->glMajor < 3 || - (wndconfig->glMajor == 3 && wndconfig->glMinor < 2)) - { - // Desktop OpenGL context profiles are only defined for version 3.2 - // and above - + // OpenGL 1.x series ended with version 1.5 _glfwSetError(GLFW_INVALID_VALUE, - "glfwOpenWindow: Context profiles only exist for " - "OpenGL version 3.2 and above"); + "glfwOpenWindow: Invalid OpenGL version requested"); + return GL_FALSE; + } + else if (wndconfig->glMajor == 2 && wndconfig->glMinor > 1) + { + // OpenGL 2.x series ended with version 2.1 + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Invalid OpenGL version requested"); + return GL_FALSE; + } + else if (wndconfig->glMajor == 3 && wndconfig->glMinor > 3) + { + // OpenGL 3.x series ended with version 3.3 + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Invalid OpenGL version requested"); + return GL_FALSE; + } + else + { + // For now, let everything else through + } + + if (wndconfig->glProfile) + { + if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE && + wndconfig->glProfile != GLFW_OPENGL_COMPAT_PROFILE) + { + _glfwSetError(GLFW_INVALID_ENUM, + "glfwOpenWindow: Invalid OpenGL profile requested"); + return GL_FALSE; + } + + if (wndconfig->glMajor < 3 || + (wndconfig->glMajor == 3 && wndconfig->glMinor < 2)) + { + // Desktop OpenGL context profiles are only defined for version 3.2 + // and above + + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Context profiles only exist for " + "OpenGL version 3.2 and above"); + return GL_FALSE; + } + } + + if (wndconfig->glForward && wndconfig->glMajor < 3) + { + // Forward-compatible contexts are only defined for OpenGL version 3.0 and above + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Forward compatibility only exist for " + "OpenGL version 3.0 and above"); return GL_FALSE; } } - - if (wndconfig->glForward && wndconfig->glMajor < 3) + else if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) { - // Forward-compatible contexts are only defined for OpenGL version 3.0 and above - _glfwSetError(GLFW_INVALID_VALUE, - "glfwOpenWindow: Forward compatibility only exist for " - "OpenGL version 3.0 and above"); - return GL_FALSE; + if (wndconfig->glMajor < 1 || wndconfig->glMinor < 0) + { + // OpenGL ES 1.0 is the smallest valid version + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Invalid OpenGL ES version requested"); + return GL_FALSE; + } + if (wndconfig->glMajor == 1 && wndconfig->glMinor > 1) + { + // OpenGL ES 1.x series ended with version 1.1 + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Invalid OpenGL ES version requested"); + return GL_FALSE; + } + else + { + // For now, let everything else through + } + + if (wndconfig->glProfile) + { + // OpenGL ES does not support profiles + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Context profiles are not supported " + "by OpenGL ES"); + return GL_FALSE; + } + + if (wndconfig->glForward) + { + // OpenGL ES does not support Forward-compatibility + _glfwSetError(GLFW_INVALID_VALUE, + "glfwOpenWindow: Forward compatibility is not " + "supported by OpenGL ES"); + return GL_FALSE; + } } if (wndconfig->glRobustness) @@ -347,7 +383,8 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) wndconfig->glRobustness != GLFW_OPENGL_LOSE_CONTEXT_ON_RESET) { _glfwSetError(GLFW_INVALID_VALUE, - "glfwOpenWindow: Invalid OpenGL robustness mode requested"); + "glfwOpenWindow: Invalid OpenGL robustness mode " + "requested"); return GL_FALSE; } } @@ -363,6 +400,8 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig) { + window->clientAPI = wndconfig->clientAPI; + parseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision); // Read back forward-compatibility flag @@ -433,7 +472,7 @@ GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig) //======================================================================== -// Check if a string can be found in an OpenGL extension string +// Check if a string can be found in a client API extension string //======================================================================== int _glfwStringInExtensionString(const char* string, @@ -472,7 +511,7 @@ int _glfwStringInExtensionString(const char* string, ////////////////////////////////////////////////////////////////////////// //======================================================================== -// Make the OpenGL context associated with the specified window current +// Make the context associated with the specified window current //======================================================================== GLFWAPI void glfwMakeContextCurrent(GLFWwindow handle) @@ -494,7 +533,7 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow handle) //======================================================================== -// Returns the window whose OpenGL context is current +// Returns the window whose context is current //======================================================================== GLFWAPI GLFWwindow glfwGetCurrentContext(void) @@ -554,7 +593,7 @@ GLFWAPI void glfwSwapInterval(int interval) //======================================================================== -// Check if an OpenGL extension is available at runtime +// Check if a client API extension is available at runtime //======================================================================== GLFWAPI int glfwExtensionSupported(const char* extension) @@ -619,8 +658,8 @@ GLFWAPI int glfwExtensionSupported(const char* extension) //======================================================================== -// Get the function pointer to an OpenGL function. -// This function can be used to get access to extended OpenGL functions. +// Get the function pointer to a client API function +// This can be used to get access to client API extension functions //======================================================================== GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) @@ -642,7 +681,7 @@ GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) //======================================================================== -// Copies the specified OpenGL state categories from src to dst +// Copies the specified context state categories from src to dst //======================================================================== GLFWAPI void glfwCopyContext(GLFWwindow hsrc, GLFWwindow hdst, unsigned long mask) diff --git a/src/win32_window.c b/src/win32_window.c index 935767ce..c2870c4e 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -336,6 +336,21 @@ static GLboolean createContext(_GLFWwindow* window, attribs[i++] = wndconfig->glMinor; } + if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) + { + if (!window->WGL.ARB_create_context_profile || + !window->WGL.EXT_create_context_es2_profile) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, + "Win32/WGL: OpenGL ES 2.x requested but " + "WGL_EXT_create_context_es2_profile is unavailable"); + return GL_FALSE; + } + + attribs[i++] = WGL_CONTEXT_PROFILE_MASK_ARB; + attribs[i++] = WGL_CONTEXT_ES2_PROFILE_BIT_EXT; + } + if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) { int flags = 0; @@ -365,21 +380,10 @@ static GLboolean createContext(_GLFWwindow* window, return GL_FALSE; } - if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE && - !window->WGL.EXT_create_context_es2_profile) - { - _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "Win32/WGL: OpenGL ES 2.x profile requested but " - "WGL_EXT_create_context_es2_profile is unavailable"); - return GL_FALSE; - } - if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE) flags = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE) flags = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; - else if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE) - flags = WGL_CONTEXT_ES2_PROFILE_BIT_EXT; attribs[i++] = WGL_CONTEXT_PROFILE_MASK_ARB; attribs[i++] = flags; diff --git a/src/window.c b/src/window.c index f8939e37..41729a78 100644 --- a/src/window.c +++ b/src/window.c @@ -97,7 +97,8 @@ void _glfwSetDefaultWindowHints(void) { memset(&_glfwLibrary.hints, 0, sizeof(_glfwLibrary.hints)); - // The default minimum OpenGL version is 1.0 + // The default is OpenGL with minimum version 1.0 + _glfwLibrary.hints.clientAPI = GLFW_OPENGL_API; _glfwLibrary.hints.glMajor = 1; _glfwLibrary.hints.glMinor = 0; @@ -251,6 +252,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, wndconfig.title = title; wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0); wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE; + wndconfig.clientAPI = _glfwLibrary.hints.clientAPI; wndconfig.glMajor = _glfwLibrary.hints.glMajor; wndconfig.glMinor = _glfwLibrary.hints.glMinor; wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE; @@ -429,6 +431,9 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint) case GLFW_FSAA_SAMPLES: _glfwLibrary.hints.samples = hint; break; + case GLFW_CLIENT_API: + _glfwLibrary.hints.clientAPI = hint; + break; case GLFW_OPENGL_VERSION_MAJOR: _glfwLibrary.hints.glMajor = hint; break; @@ -714,6 +719,8 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param) return window->resizable; case GLFW_FSAA_SAMPLES: return window->samples; + case GLFW_CLIENT_API: + return window->clientAPI; case GLFW_OPENGL_VERSION_MAJOR: return window->glMajor; case GLFW_OPENGL_VERSION_MINOR: diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index f52b962c..4db794ba 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -110,18 +110,23 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, continue; } - if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES_BIT) && - !(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) + if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) { - // Only consider OpenGL ES context - continue; + if (wndconfig->glMajor == 1) + { + if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES_BIT)) + continue; + } + else + { + if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) + continue; + } } - - if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE && - !(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT)) + else if (wndconfig->clientAPI == GLFW_OPENGL_API) { - // User requested only OpenGL ES 2.0 context - continue; + if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_BIT)) + continue; } f->redBits = getConfigAttrib(configs[i], EGL_RED_SIZE); @@ -248,19 +253,17 @@ static int createContext(_GLFWwindow* window, } index = 0; - if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE) + + if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) { - setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, 2); + eglBindAPI(EGL_OPENGL_ES_API); + setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, wndconfig->glMajor); } else - { - setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, 1); - } + eglBindAPI(EGL_OPENGL_API); setEGLattrib(attribs, index, EGL_NONE, EGL_NONE); - eglBindAPI(EGL_OPENGL_ES_API); - window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display, config, share, attribs); diff --git a/src/x11_glx_opengl.c b/src/x11_glx_opengl.c index edcd69b6..da06d65f 100644 --- a/src/x11_glx_opengl.c +++ b/src/x11_glx_opengl.c @@ -346,6 +346,22 @@ static int createContext(_GLFWwindow* window, setGLXattrib(attribs, index, GLX_CONTEXT_MINOR_VERSION_ARB, wndconfig->glMinor); } + if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) + { + if (!_glfwLibrary.GLX.ARB_create_context_profile || + !_glfwLibrary.GLX.EXT_create_context_es2_profile) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, + "X11/GLX: OpenGL ES 2.x requested but " + "GLX_EXT_create_context_es2_profile is unavailable"); + return GL_FALSE; + } + + setGLXattrib(attribs, index, + GLX_CONTEXT_PROFILE_MASK_ARB, + GLX_CONTEXT_ES2_PROFILE_BIT_EXT); + } + if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) { int flags = 0; @@ -374,21 +390,10 @@ static int createContext(_GLFWwindow* window, return GL_FALSE; } - if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE && - !_glfwLibrary.GLX.EXT_create_context_es2_profile) - { - _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "X11/GLX: OpenGL ES 2.x profile requested but " - "GLX_EXT_create_context_es2_profile is unavailable"); - return GL_FALSE; - } - if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE) flags = GLX_CONTEXT_CORE_PROFILE_BIT_ARB; else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE) flags = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; - else if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE) - flags = GLX_CONTEXT_ES2_PROFILE_BIT_EXT; setGLXattrib(attribs, index, GLX_CONTEXT_PROFILE_MASK_ARB, flags); } diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index 45cb8616..28264179 100644 --- a/tests/glfwinfo.c +++ b/tests/glfwinfo.c @@ -42,17 +42,20 @@ #define strcasecmp(x, y) _stricmp(x, y) #endif +#define API_OPENGL "gl" +#define API_OPENGL_ES "es" + #define PROFILE_NAME_CORE "core" #define PROFILE_NAME_COMPAT "compat" -#define PROFILE_NAME_ES2 "es2" #define STRATEGY_NAME_NONE "none" #define STRATEGY_NAME_LOSE "lose" static void usage(void) { - printf("Usage: glfwinfo [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n"); - printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT " " PROFILE_NAME_ES2 "\n"); + printf("Usage: glfwinfo [-h] [-a API] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n"); + printf("available APIs: " API_OPENGL " " API_OPENGL_ES "\n"); + printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT "\n"); printf("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\n"); } @@ -61,14 +64,22 @@ static void error_callback(int error, const char* description) fprintf(stderr, "Error: %s in %s\n", glfwErrorString(error), description); } +static const char* get_client_api_name(int api) +{ + if (api == GLFW_OPENGL_API) + return "OpenGL"; + else if (api == GLFW_OPENGL_ES_API) + return "OpenGL ES"; + + return "Unknown API"; +} + static const char* get_glfw_profile_name(int profile) { if (profile == GLFW_OPENGL_COMPAT_PROFILE) - return PROFILE_NAME_COMPAT; + return "compatibility"; else if (profile == GLFW_OPENGL_CORE_PROFILE) - return PROFILE_NAME_CORE; - else if (profile == GLFW_OPENGL_ES2_PROFILE) - return PROFILE_NAME_ES2; + return "core"; return "unknown"; } @@ -76,22 +87,22 @@ static const char* get_glfw_profile_name(int profile) static const char* get_profile_name(GLint mask) { if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) - return PROFILE_NAME_COMPAT; + return "compatibility"; if (mask & GL_CONTEXT_CORE_PROFILE_BIT) - return PROFILE_NAME_CORE; + return "core"; return "unknown"; } -static void list_extensions(int major, int minor) +static void list_extensions(int api, int major, int minor) { int i; GLint count; const GLubyte* extensions; - printf("OpenGL context supported extensions:\n"); + printf("%s context supported extensions:\n", get_client_api_name(api)); - if (major > 2) + if (api == GLFW_OPENGL_API && major > 2) { PFNGLGETSTRINGIPROC glGetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi"); if (!glGetStringi) @@ -121,15 +132,25 @@ static void list_extensions(int major, int minor) int main(int argc, char** argv) { - int ch, profile = 0, strategy = 0, major = 1, minor = 0, revision; + int ch, api = 0, profile = 0, strategy = 0, major = 1, minor = 0, revision; GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE; GLint flags, mask; GLFWwindow window; - while ((ch = getopt(argc, argv, "dfhlm:n:p:r:")) != -1) + while ((ch = getopt(argc, argv, "a:dfhlm:n:p:r:")) != -1) { switch (ch) { + case 'a': + if (strcasecmp(optarg, API_OPENGL) == 0) + api = GLFW_OPENGL_API; + else if (strcasecmp(optarg, API_OPENGL_ES) == 0) + api = GLFW_OPENGL_ES_API; + else + { + usage(); + exit(EXIT_FAILURE); + } case 'd': debug = GL_TRUE; break; @@ -153,8 +174,6 @@ int main(int argc, char** argv) profile = GLFW_OPENGL_CORE_PROFILE; else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0) profile = GLFW_OPENGL_COMPAT_PROFILE; - else if (strcasecmp(optarg, PROFILE_NAME_ES2) == 0) - profile = GLFW_OPENGL_ES2_PROFILE; else { usage(); @@ -195,6 +214,9 @@ int main(int argc, char** argv) glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor); } + if (api != 0) + glfwOpenWindowHint(GLFW_CLIENT_API, api); + if (debug) glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); @@ -234,53 +256,70 @@ int main(int argc, char** argv) printf("GLFW library version string: \"%s\"\n", glfwGetVersionString()); - // Report OpenGL version - - printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION)); + // Report client API version + api = glfwGetWindowParam(window, GLFW_CLIENT_API); major = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MAJOR); minor = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MINOR); revision = glfwGetWindowParam(window, GLFW_OPENGL_REVISION); - printf("OpenGL context version parsed by GLFW: %u.%u.%u\n", major, minor, revision); + printf("%s context version string: \"%s\"\n", + get_client_api_name(api), + glGetString(GL_VERSION)); - // Report OpenGL context properties + printf("%s context version parsed by GLFW: %u.%u.%u\n", + get_client_api_name(api), + major, minor, revision); - if (major >= 3) + // Report client API context properties + + if (api == GLFW_OPENGL_API) { - glGetIntegerv(GL_CONTEXT_FLAGS, &flags); - printf("OpenGL context flags:"); + if (major >= 3) + { + glGetIntegerv(GL_CONTEXT_FLAGS, &flags); + printf("%s context flags:", get_client_api_name(api)); - if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) - puts(" forward-compatible"); - else - puts(" none"); + if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) + puts(" forward-compatible"); + else + puts(" none"); - printf("OpenGL forward-compatible flag parsed by GLFW: %s\n", - glfwGetWindowParam(window, GLFW_OPENGL_FORWARD_COMPAT) ? "true" : "false"); + printf("%s forward-compatible flag parsed by GLFW: %s\n", + get_client_api_name(api), + glfwGetWindowParam(window, GLFW_OPENGL_FORWARD_COMPAT) ? "true" : "false"); + } + + if (major > 3 || (major == 3 && minor >= 2)) + { + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); + printf("%s profile mask: %s (0x%08x)\n", + get_client_api_name(api), + get_profile_name(mask), mask); + + printf("%s profile parsed by GLFW: %s\n", + get_client_api_name(api), + get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE))); + } } - if (major > 3 || (major == 3 && minor >= 2)) - { - glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); - printf("OpenGL profile mask: %s (0x%08x)\n", get_profile_name(mask), mask); - - printf("OpenGL profile parsed by GLFW: %s\n", - get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE))); - } - - printf("OpenGL context renderer string: \"%s\"\n", glGetString(GL_RENDERER)); - printf("OpenGL context vendor string: \"%s\"\n", glGetString(GL_VENDOR)); + printf("%s context renderer string: \"%s\"\n", + get_client_api_name(api), + glGetString(GL_RENDERER)); + printf("%s context vendor string: \"%s\"\n", + get_client_api_name(api), + glGetString(GL_VENDOR)); if (major > 1) { - printf("OpenGL context shading language version: \"%s\"\n", + printf("%s context shading language version: \"%s\"\n", + get_client_api_name(api), glGetString(GL_SHADING_LANGUAGE_VERSION)); } - // Report OpenGL extensions + // Report client API extensions if (list) - list_extensions(major, minor); + list_extensions(api, major, minor); glfwTerminate(); exit(EXIT_SUCCESS); From edd554c115b9359c4d6967f6f07ce4b6972c0d03 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Jul 2012 01:33:42 +0200 Subject: [PATCH 40/81] Added support for EGL_KHR_create_context. --- src/x11_egl_opengl.c | 51 ++++++++++++++++++++++++++++++++++++++++++ src/x11_egl_platform.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 4db794ba..da92fb41 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -260,8 +260,56 @@ static int createContext(_GLFWwindow* window, setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, wndconfig->glMajor); } else + { eglBindAPI(EGL_OPENGL_API); + if (_glfwLibrary.EGL.KHR_create_context) + { + setEGLattrib(attribs, index, EGL_CONTEXT_MAJOR_VERSION_KHR, wndconfig->glMajor); + setEGLattrib(attribs, index, EGL_CONTEXT_MINOR_VERSION_KHR, wndconfig->glMinor); + + if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) + { + int flags = 0; + + if (wndconfig->glForward) + flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; + + if (wndconfig->glDebug) + flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; + + if (wndconfig->glRobustness) + flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR; + + setEGLattrib(attribs, index, EGL_CONTEXT_FLAGS_KHR, flags); + } + + if (wndconfig->glProfile) + { + int flags = 0; + + if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE) + flags = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR; + else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE) + flags = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; + + setEGLattrib(attribs, index, EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, flags); + } + + if (wndconfig->glRobustness) + { + int strategy; + + if (wndconfig->glRobustness == GLFW_OPENGL_NO_RESET_NOTIFICATION) + strategy = EGL_NO_RESET_NOTIFICATION_KHR; + else if (wndconfig->glRobustness == GLFW_OPENGL_LOSE_CONTEXT_ON_RESET) + strategy = EGL_LOSE_CONTEXT_ON_RESET_KHR; + + setEGLattrib(attribs, index, EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, strategy); + } + } + } + setEGLattrib(attribs, index, EGL_NONE, EGL_NONE); window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display, @@ -337,6 +385,9 @@ int _glfwInitOpenGL(void) return GL_FALSE; } + if (_glfwPlatformExtensionSupported("EGL_KHR_create_context")) + _glfwLibrary.EGL.KHR_create_context = GL_TRUE; + return GL_TRUE; } diff --git a/src/x11_egl_platform.h b/src/x11_egl_platform.h index f3974676..d3e70055 100644 --- a/src/x11_egl_platform.h +++ b/src/x11_egl_platform.h @@ -85,6 +85,8 @@ typedef struct _GLFWlibraryEGL EGLDisplay display; EGLint majorVersion, minorVersion; + GLboolean KHR_create_context; + #if defined(_GLFW_DLOPEN_LIBEGL) void* libEGL; // dlopen handle for libEGL.so #endif From bddc95c0176676ea646c2dfcd381465536e1676c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Jul 2012 01:38:15 +0200 Subject: [PATCH 41/81] Removed references to GLX in EGL port. --- src/x11_egl_opengl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index da92fb41..84f50bd4 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -248,7 +248,7 @@ static int createContext(_GLFWwindow* window, if (window->EGL.visual == NULL) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to retrieve visual for EGLConfig"); + "X11/EGL: Failed to retrieve visual for EGLConfig"); return GL_FALSE; } @@ -551,7 +551,6 @@ int _glfwPlatformExtensionSupported(const char* extension) { const char* extensions; - // Get list of GLX extensions extensions = eglQueryString(_glfwLibrary.EGL.display, EGL_EXTENSIONS); if (extensions != NULL) { From ccca5d71fe8e17f8deb8f443878c4fce1013f8fe Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Jul 2012 02:00:00 +0200 Subject: [PATCH 42/81] Use EGL_KHR_create_context with GLES as well. --- src/x11_egl_opengl.c | 100 +++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 84f50bd4..2484841b 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -252,62 +252,62 @@ static int createContext(_GLFWwindow* window, return GL_FALSE; } + if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) + eglBindAPI(EGL_OPENGL_ES_API); + else + eglBindAPI(EGL_OPENGL_API); + index = 0; - if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) + if (_glfwLibrary.EGL.KHR_create_context) { - eglBindAPI(EGL_OPENGL_ES_API); - setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, wndconfig->glMajor); + setEGLattrib(attribs, index, EGL_CONTEXT_MAJOR_VERSION_KHR, wndconfig->glMajor); + setEGLattrib(attribs, index, EGL_CONTEXT_MINOR_VERSION_KHR, wndconfig->glMinor); + + if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) + { + int flags = 0; + + if (wndconfig->glForward) + flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; + + if (wndconfig->glDebug) + flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; + + if (wndconfig->glRobustness) + flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR; + + setEGLattrib(attribs, index, EGL_CONTEXT_FLAGS_KHR, flags); + } + + if (wndconfig->glProfile) + { + int flags = 0; + + if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE) + flags = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR; + else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE) + flags = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; + + setEGLattrib(attribs, index, EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, flags); + } + + if (wndconfig->glRobustness) + { + int strategy; + + if (wndconfig->glRobustness == GLFW_OPENGL_NO_RESET_NOTIFICATION) + strategy = EGL_NO_RESET_NOTIFICATION_KHR; + else if (wndconfig->glRobustness == GLFW_OPENGL_LOSE_CONTEXT_ON_RESET) + strategy = EGL_LOSE_CONTEXT_ON_RESET_KHR; + + setEGLattrib(attribs, index, EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, strategy); + } } else { - eglBindAPI(EGL_OPENGL_API); - - if (_glfwLibrary.EGL.KHR_create_context) - { - setEGLattrib(attribs, index, EGL_CONTEXT_MAJOR_VERSION_KHR, wndconfig->glMajor); - setEGLattrib(attribs, index, EGL_CONTEXT_MINOR_VERSION_KHR, wndconfig->glMinor); - - if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) - { - int flags = 0; - - if (wndconfig->glForward) - flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; - - if (wndconfig->glDebug) - flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; - - if (wndconfig->glRobustness) - flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR; - - setEGLattrib(attribs, index, EGL_CONTEXT_FLAGS_KHR, flags); - } - - if (wndconfig->glProfile) - { - int flags = 0; - - if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE) - flags = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR; - else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE) - flags = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; - - setEGLattrib(attribs, index, EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, flags); - } - - if (wndconfig->glRobustness) - { - int strategy; - - if (wndconfig->glRobustness == GLFW_OPENGL_NO_RESET_NOTIFICATION) - strategy = EGL_NO_RESET_NOTIFICATION_KHR; - else if (wndconfig->glRobustness == GLFW_OPENGL_LOSE_CONTEXT_ON_RESET) - strategy = EGL_LOSE_CONTEXT_ON_RESET_KHR; - - setEGLattrib(attribs, index, EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, strategy); - } - } + if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) + setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, wndconfig->glMajor); } setEGLattrib(attribs, index, EGL_NONE, EGL_NONE); From b069391cc0834465ab0e3e0c2d2650fcc9e8e389 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Jul 2012 02:01:42 +0200 Subject: [PATCH 43/81] Formatting. --- src/x11_egl_opengl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 2484841b..c790b311 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -185,7 +185,7 @@ static int createContext(_GLFWwindow* window, { int attribs[40], visMask; EGLint count, index, visualID = 0; - EGLint red_size, green_size, blue_size, alpha_size; + EGLint redBits, greenBits, blueBits, alphaBits; EGLConfig config; EGLContext share = NULL; XVisualInfo visTemplate; @@ -230,15 +230,15 @@ static int createContext(_GLFWwindow* window, // attribute, so attempt to find the closest match. eglGetConfigAttrib(_glfwLibrary.EGL.display, config, - EGL_RED_SIZE, &red_size); + EGL_RED_SIZE, &redBits); eglGetConfigAttrib(_glfwLibrary.EGL.display, config, - EGL_GREEN_SIZE, &green_size); + EGL_GREEN_SIZE, &greenBits); eglGetConfigAttrib(_glfwLibrary.EGL.display, config, - EGL_BLUE_SIZE, &blue_size); + EGL_BLUE_SIZE, &blueBits); eglGetConfigAttrib(_glfwLibrary.EGL.display, config, - EGL_ALPHA_SIZE, &alpha_size); + EGL_ALPHA_SIZE, &alphaBits); - visTemplate.depth = red_size + green_size + blue_size + alpha_size; + visTemplate.depth = redBits + greenBits + blueBits + alphaBits; visMask |= VisualDepthMask; } From f457223bdf8d9b6f8c949e098ab9fd161ae2218b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Jul 2012 17:06:37 +0200 Subject: [PATCH 44/81] Minor context creation fixes. --- src/x11_egl_opengl.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index c790b311..ded3c612 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -176,8 +176,10 @@ static void refreshContextParams(_GLFWwindow* window) //======================================================================== #define setEGLattrib(attribs, index, attribName, attribValue) \ +{ \ attribs[index++] = attribName; \ - attribs[index++] = attribValue; + attribs[index++] = attribValue; \ +} static int createContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, @@ -253,9 +255,23 @@ static int createContext(_GLFWwindow* window, } if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) - eglBindAPI(EGL_OPENGL_ES_API); + { + if (!eglBindAPI(EGL_OPENGL_ES_API)) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: OpenGL ES is not supported"); + return GL_FALSE; + } + } else - eglBindAPI(EGL_OPENGL_API); + { + if (!eglBindAPI(EGL_OPENGL_API)) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: OpenGL is not supported"); + return GL_FALSE; + } + } index = 0; @@ -320,7 +336,7 @@ static int createContext(_GLFWwindow* window, // TODO: Handle all the various error codes here _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: Failed to create OpenGL ES context"); + "X11/EGL: Failed to create context"); return GL_FALSE; } From 03d526097d399eb540c63aa160a1c1ef310ae142 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 23 Jul 2012 00:48:18 +0200 Subject: [PATCH 45/81] Comment fix. --- include/GL/glfw3.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 4ff8e857..15bc9e5c 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -421,7 +421,7 @@ extern "C" { #define GLFW_OPENGL_PROFILE 0x00021014 #define GLFW_OPENGL_ROBUSTNESS 0x00021015 -/* GLFW_OPENGL_API mode tokens */ +/* GLFW_CLIENT_API tokens */ #define GLFW_OPENGL_API 0x00000001 #define GLFW_OPENGL_ES_API 0x00000002 From a3c4b96c91f30de1afd456586748d9342deed1b3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 23 Jul 2012 18:40:31 +0200 Subject: [PATCH 46/81] Removed commented-out code, added error reporting. --- src/opengl.c | 58 ++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/src/opengl.c b/src/opengl.c index ff623ed3..2195d3bd 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -39,58 +39,39 @@ // Parses the client API version string and extracts the version number //======================================================================== -static void parseGLVersion(int* major, int* minor, int* rev) +static GLboolean parseGLVersion(int* major, int* minor, int* rev) { GLuint _major, _minor = 0, _rev = 0; - const GLubyte* version; + const char* version; - version = glGetString(GL_VERSION); + version = (const char*) glGetString(GL_VERSION); if (!version) - return; - -#if 0 - // Old version detection code. This doesn't work very well - const GLubyte* ptr; - const char* glesPrefix = "OpenGL ES "; - - if (strncmp((const char*) version, glesPrefix, strlen(glesPrefix)) == 0) { - // The version string on OpenGL ES has a prefix before the version - // number, so we skip past it and then continue as normal - - version += strlen(glesPrefix); + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: No version string available"); + return GL_FALSE; } - // Parse version from string - - ptr = version; - for (_major = 0; *ptr >= '0' && *ptr <= '9'; ptr++) - _major = 10 * _major + (*ptr - '0'); - - if (*ptr == '.') + for (;;) { - ptr++; - for (_minor = 0; *ptr >= '0' && *ptr <= '9'; ptr++) - _minor = 10 * _minor + (*ptr - '0'); - - if (*ptr == '.') + if (*version != '\0') { - ptr++; - for (_rev = 0; *ptr >= '0' && *ptr <= '9'; ptr++) - _rev = 10 * _rev + (*ptr - '0'); + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: No version found in version string"); + return GL_FALSE; } + + if (sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev)) + break; + + version++; } -#endif - // Find version from OpenGL string - for (; version && - !sscanf((char*)version, "%d.%d.%d", &_major, &_minor, &_rev); - ++version); - - // Store result *major = _major; *minor = _minor; *rev = _rev; + + return GL_TRUE; } @@ -402,7 +383,8 @@ GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig) { window->clientAPI = wndconfig->clientAPI; - parseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision); + if (!parseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision)) + return GL_FALSE; // Read back forward-compatibility flag { From b1de4d6fedd92bdf06e3e125489660b716cbfc23 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 31 Jul 2012 19:06:48 +0200 Subject: [PATCH 47/81] Fixed client API version parsing. --- src/opengl.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/opengl.c b/src/opengl.c index 2195d3bd..a4157e69 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -41,8 +41,15 @@ static GLboolean parseGLVersion(int* major, int* minor, int* rev) { - GLuint _major, _minor = 0, _rev = 0; + int i, _major, _minor = 0, _rev = 0; const char* version; + const char* prefixes[] = + { + "OpenGL ES-CM ", + "OpenGL ES-CL ", + "OpenGL ES ", + NULL + }; version = (const char*) glGetString(GL_VERSION); if (!version) @@ -52,19 +59,22 @@ static GLboolean parseGLVersion(int* major, int* minor, int* rev) return GL_FALSE; } - for (;;) + for (i = 0; prefixes[i]; i++) { - if (*version != '\0') - { - _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: No version found in version string"); - return GL_FALSE; - } + const size_t length = strlen(prefixes[i]); - if (sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev)) - break; + if (strncmp(version, prefixes[i], length) == 0) + { + version += length; + break; + } + } - version++; + if (!sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev)) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/EGL: No version found in version string"); + return GL_FALSE; } *major = _major; From 331aa26503f5fbd1b40fdcb2927596590ab04433 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 31 Jul 2012 19:13:27 +0200 Subject: [PATCH 48/81] Formatting. --- src/opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opengl.c b/src/opengl.c index a4157e69..01dddbfe 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -360,7 +360,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig) if (wndconfig->glForward) { - // OpenGL ES does not support Forward-compatibility + // OpenGL ES does not support forward-compatibility _glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Forward compatibility is not " "supported by OpenGL ES"); From 0f1ab5317f44b12469c8b9362bd8a8841adf2f1b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 1 Aug 2012 01:05:57 +0200 Subject: [PATCH 49/81] Formatting. --- src/opengl.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/opengl.c b/src/opengl.c index 608bc4b3..ec6912b1 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -45,10 +45,10 @@ static GLboolean parseGLVersion(int* major, int* minor, int* rev) const char* version; const char* prefixes[] = { - "OpenGL ES-CM ", - "OpenGL ES-CL ", - "OpenGL ES ", - NULL + "OpenGL ES-CM ", + "OpenGL ES-CL ", + "OpenGL ES ", + NULL }; version = (const char*) glGetString(GL_VERSION); @@ -61,13 +61,13 @@ static GLboolean parseGLVersion(int* major, int* minor, int* rev) for (i = 0; prefixes[i]; i++) { - const size_t length = strlen(prefixes[i]); + const size_t length = strlen(prefixes[i]); - if (strncmp(version, prefixes[i], length) == 0) - { - version += length; - break; - } + if (strncmp(version, prefixes[i], length) == 0) + { + version += length; + break; + } } if (!sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev)) From a182acd5855bdce144b9ddbd1ccf82d00df7ade4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 2 Aug 2012 03:01:31 +0200 Subject: [PATCH 50/81] Removed EGL-specific context param refresh. --- src/x11_egl_opengl.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index ded3c612..f8d317db 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -149,28 +149,6 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, } -//======================================================================== -// Read back framebuffer parameters from the context -//======================================================================== - -static void refreshContextParams(_GLFWwindow* window) -{ - // There is no clear definition of an "accelerated" context on X11/EGL, and - // true sounds better than false, so we hardcode true here - window->accelerated = GL_TRUE; - - window->redBits = getConfigAttrib(window->EGL.config, EGL_RED_SIZE); - window->greenBits = getConfigAttrib(window->EGL.config, EGL_GREEN_SIZE); - window->blueBits = getConfigAttrib(window->EGL.config, EGL_BLUE_SIZE); - - window->alphaBits = getConfigAttrib(window->EGL.config, EGL_ALPHA_SIZE); - window->depthBits = getConfigAttrib(window->EGL.config, EGL_DEPTH_SIZE); - window->stencilBits = getConfigAttrib(window->EGL.config, EGL_STENCIL_SIZE); - - window->samples = getConfigAttrib(window->EGL.config, EGL_SAMPLES); -} - - //======================================================================== // Create the actual OpenGL(|ES) context //======================================================================== @@ -341,7 +319,6 @@ static int createContext(_GLFWwindow* window, } window->EGL.config = config; - refreshContextParams(window); return GL_TRUE; } From 93a1d1c226e0417931b8dd20bbc9aaead4bc777a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 7 Sep 2012 01:01:34 +0200 Subject: [PATCH 51/81] Added stubs, implemented on Linux and Cocoa. --- include/GL/glfw3.h | 1 + src/cocoa_joystick.m | 16 +++++++++++++--- src/internal.h | 1 + src/joystick.c | 22 ++++++++++++++++++++++ src/win32_joystick.c | 11 +++++++++++ src/x11_joystick.c | 18 ++++++++++++++++++ src/x11_platform.h | 1 + tests/joysticks.c | 13 +++++++++---- 8 files changed, 76 insertions(+), 7 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 1e90a5bc..295ff3ee 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -566,6 +566,7 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun); GLFWAPI int glfwGetJoystickParam(int joy, int param); GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes); GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); +GLFWAPI const char* glfwGetJoystickName(int joy); /* Clipboard */ GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* string); diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 7eac7f91..5728f12f 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -443,9 +443,9 @@ void _glfwInitJoysticks(void) if (refCF) { CFStringGetCString(refCF, - (char*) &(joystick->product), - 256, - CFStringGetSystemEncoding()); + joystick->product, + sizeof(joystick->product), + kCFStringEncodingUTF8); } joystick->numAxes = 0; @@ -625,3 +625,13 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, return button; } + +//======================================================================== +// Get joystick name +//======================================================================== + +const char* _glfwPlatformGetJoystickName(int joy) +{ + return _glfwJoysticks[joy].product; +} + diff --git a/src/internal.h b/src/internal.h index 39aeb4fa..509a0076 100644 --- a/src/internal.h +++ b/src/internal.h @@ -274,6 +274,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window); int _glfwPlatformGetJoystickParam(int joy, int param); int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes); int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); +const char* _glfwPlatformGetJoystickName(int joy); // Time input double _glfwPlatformGetTime(void); diff --git a/src/joystick.c b/src/joystick.c index 84763951..59107e31 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -126,3 +126,25 @@ GLFWAPI int glfwGetJoystickButtons(int joy, return _glfwPlatformGetJoystickButtons(joy, buttons, numbuttons); } + +//======================================================================== +// Get joystick name +//======================================================================== + +GLFWAPI const char* glfwGetJoystickName(int joy) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return 0; + } + + if (joy < 0 || joy > GLFW_JOYSTICK_LAST) + { + _glfwSetError(GLFW_INVALID_ENUM, NULL); + return 0; + } + + return _glfwPlatformGetJoystickName(joy); +} + diff --git a/src/win32_joystick.c b/src/win32_joystick.c index a51773d3..9ffb9aac 100644 --- a/src/win32_joystick.c +++ b/src/win32_joystick.c @@ -211,3 +211,14 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, return button; } + + +//======================================================================== +// Get joystick name +//======================================================================== + +const char* _glfwPlatformGetJoystickName(int joy) +{ + return ""; +} + diff --git a/src/x11_joystick.c b/src/x11_joystick.c index 1895dc6a..bf9a7bc1 100644 --- a/src/x11_joystick.c +++ b/src/x11_joystick.c @@ -40,6 +40,7 @@ #include #include +#include #endif // _GLFW_USE_LINUX_JOYSTICKS @@ -51,6 +52,7 @@ static int openJoystickDevice(int joy, const char* path) { #ifdef _GLFW_USE_LINUX_JOYSTICKS char numAxes, numButtons; + char name[256]; int fd, version; fd = open(path, O_RDONLY | O_NONBLOCK); @@ -68,6 +70,11 @@ static int openJoystickDevice(int joy, const char* path) return GL_FALSE; } + if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0) + strncpy(name, "Unknown", sizeof(name)); + + _glfwLibrary.X11.joystick[joy].name = strdup(name); + ioctl(fd, JSIOCGAXES, &numAxes); _glfwLibrary.X11.joystick[joy].numAxes = (int) numAxes; @@ -214,6 +221,7 @@ void _glfwTerminateJoysticks(void) close(_glfwLibrary.X11.joystick[i].fd); free(_glfwLibrary.X11.joystick[i].axis); free(_glfwLibrary.X11.joystick[i].button); + free(_glfwLibrary.X11.joystick[i].name); _glfwLibrary.X11.joystick[i].present = GL_FALSE; } @@ -302,3 +310,13 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, return numButtons; } + +//======================================================================== +// Get joystick name +//======================================================================== + +const char* _glfwPlatformGetJoystickName(int joy) +{ + return _glfwLibrary.X11.joystick[joy].name; +} + diff --git a/src/x11_platform.h b/src/x11_platform.h index 75beb745..4b154fc4 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -240,6 +240,7 @@ typedef struct _GLFWlibraryX11 int numButtons; float* axis; unsigned char* button; + char* name; } joystick[GLFW_JOYSTICK_LAST + 1]; } _GLFWlibraryX11; diff --git a/tests/joysticks.c b/tests/joysticks.c index 40202ce7..f2ba7452 100644 --- a/tests/joysticks.c +++ b/tests/joysticks.c @@ -37,6 +37,7 @@ typedef struct Joystick { GLboolean present; + char* name; float* axes; unsigned char* buttons; int axis_count; @@ -130,6 +131,9 @@ static void refresh_joysticks(void) { int axis_count, button_count; + free(j->name); + j->name = strdup(glfwGetJoystickName(GLFW_JOYSTICK_1 + i)); + axis_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_AXES); if (axis_count != j->axis_count) { @@ -150,8 +154,8 @@ static void refresh_joysticks(void) if (!j->present) { - printf("Found joystick %i with %i axes, %i buttons\n", - i + 1, j->axis_count, j->button_count); + printf("Found joystick %i named \'%s\' with %i axes, %i buttons\n", + i + 1, j->name, j->axis_count, j->button_count); joystick_count++; } @@ -162,12 +166,13 @@ static void refresh_joysticks(void) { if (j->present) { + printf("Lost joystick %i named \'%s\'\n", i + 1, j->name); + + free(j->name); free(j->axes); free(j->buttons); memset(j, 0, sizeof(Joystick)); - printf("Lost joystick %i\n", i + 1); - joystick_count--; } } From dd69985649586a54068885e36f586b33d79ad422 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 9 Sep 2012 19:01:48 +0200 Subject: [PATCH 52/81] Fixed API error tags. --- src/x11_egl_opengl.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/x11_egl_opengl.c b/src/x11_egl_opengl.c index 5e79a611..937c6d5e 100644 --- a/src/x11_egl_opengl.c +++ b/src/x11_egl_opengl.c @@ -75,7 +75,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, free(configs); _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/EGL: No EGLConfigs returned"); + "EGL: No EGLConfigs returned"); return NULL; } @@ -184,7 +184,7 @@ static int createContext(_GLFWwindow* window, if (!count) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: Failed to retrieve the selected EGLConfig"); + "EGL: Failed to retrieve the selected EGLConfig"); return GL_FALSE; } } @@ -228,7 +228,7 @@ static int createContext(_GLFWwindow* window, if (window->EGL.visual == NULL) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: Failed to retrieve visual for EGLConfig"); + "EGL: Failed to retrieve visual for EGLConfig"); return GL_FALSE; } @@ -237,7 +237,7 @@ static int createContext(_GLFWwindow* window, if (!eglBindAPI(EGL_OPENGL_ES_API)) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: OpenGL ES is not supported"); + "EGL: OpenGL ES is not supported"); return GL_FALSE; } } @@ -246,7 +246,7 @@ static int createContext(_GLFWwindow* window, if (!eglBindAPI(EGL_OPENGL_API)) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: OpenGL is not supported"); + "EGL: OpenGL is not supported"); return GL_FALSE; } } @@ -314,7 +314,7 @@ static int createContext(_GLFWwindow* window, // TODO: Handle all the various error codes here _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: Failed to create context"); + "EGL: Failed to create context"); return GL_FALSE; } @@ -356,7 +356,7 @@ int _glfwInitOpenGL(void) if (!_glfwLibrary.EGL.libEGL) { - _glfwSetError(GLFW_PLATFORM_ERROR, "X11/EGL: Failed to find libEGL"); + _glfwSetError(GLFW_PLATFORM_ERROR, "EGL: Failed to find libEGL"); return GL_FALSE; } #endif @@ -365,7 +365,7 @@ int _glfwInitOpenGL(void) if (_glfwLibrary.EGL.display == EGL_NO_DISPLAY) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/EGL: Failed to get EGL display"); + "EGL: Failed to get EGL display"); return GL_FALSE; } @@ -374,7 +374,7 @@ int _glfwInitOpenGL(void) &_glfwLibrary.EGL.minorVersion)) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/EGL: Failed to initialize EGL"); + "EGL: Failed to initialize EGL"); return GL_FALSE; } @@ -423,7 +423,7 @@ int _glfwCreateContext(_GLFWwindow* window, if (!fbconfigs) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: No usable EGLFBConfigs found"); + "EGL: No usable EGLFBConfigs found"); return GL_FALSE; } @@ -431,7 +431,7 @@ int _glfwCreateContext(_GLFWwindow* window, if (!result) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: No EGLFBConfig matched the criteria"); + "EGL: No EGLFBConfig matched the criteria"); free(fbconfigs); return GL_FALSE; @@ -498,7 +498,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) if (window->EGL.surface == EGL_NO_SURFACE) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: Failed to create window surface"); + "EGL: Failed to create window surface"); } } @@ -571,6 +571,6 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname) void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) { _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/EGL: Context copying not supported by EGL"); + "EGL: Context copying not supported by EGL"); } From 0ca1e67d7aa6389df1e49922b6b0f531f7991136 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 9 Sep 2012 19:03:17 +0200 Subject: [PATCH 53/81] Moved X11-specific defines to X11 header. --- src/x11_egl_platform.h | 3 --- src/x11_platform.h | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/x11_egl_platform.h b/src/x11_egl_platform.h index d3e70055..b0b2c810 100644 --- a/src/x11_egl_platform.h +++ b/src/x11_egl_platform.h @@ -57,9 +57,6 @@ #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL EGL #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL EGL -#define _GLFW_EGL_NATIVE_WINDOW window->X11.handle -#define _GLFW_EGL_NATIVE_DISPLAY _glfwLibrary.X11.display - //======================================================================== // GLFW platform specific types diff --git a/src/x11_platform.h b/src/x11_platform.h index 00ad40b8..ede4abc0 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -56,6 +56,8 @@ #if defined(_GLFW_X11_GLX) #include "x11_glx_platform.h" #elif defined(_GLFW_X11_EGL) + #define _GLFW_EGL_NATIVE_WINDOW window->X11.handle + #define _GLFW_EGL_NATIVE_DISPLAY _glfwLibrary.X11.display #include "x11_egl_platform.h" #endif From 74488bec67c288462b6d3bae1fbd05b38e4f31e8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 9 Sep 2012 19:17:46 +0200 Subject: [PATCH 54/81] 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 From 7493bbe0c81df30c8126b3e6abe3163fbad703b4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 9 Sep 2012 19:33:40 +0200 Subject: [PATCH 55/81] Removed X11 prefix from EGL and GLX files. --- src/CMakeLists.txt | 14 +++++++------- src/{x11_egl_opengl.c => egl_opengl.c} | 0 src/{x11_egl_platform.h => egl_platform.h} | 0 src/{x11_glx_opengl.c => glx_opengl.c} | 0 src/{x11_glx_platform.h => glx_platform.h} | 0 src/x11_platform.h | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) rename src/{x11_egl_opengl.c => egl_opengl.c} (100%) rename src/{x11_egl_platform.h => egl_platform.h} (100%) rename src/{x11_glx_opengl.c => glx_opengl.c} (100%) rename src/{x11_glx_platform.h => glx_platform.h} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4c31f39e..044ebbd3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,16 +21,16 @@ elseif (_GLFW_WIN32_WGL) win32_native.c win32_opengl.c win32_time.c win32_window.c win32_dllmain.c) elseif (_GLFW_X11_GLX) - set(glfw_HEADERS ${common_HEADERS} x11_platform.h) - set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c - x11_gamma.c x11_glx_opengl.c x11_init.c x11_input.c + set(glfw_HEADERS ${common_HEADERS} x11_platform.h glx_platform.h) + set(glfw_SOURCES ${common_SOURCES} glx_opengl.c x11_clipboard.c + x11_fullscreen.c x11_gamma.c x11_init.c x11_input.c x11_joystick.c x11_keysym2unicode.c x11_native.c x11_time.c x11_window.c) elseif (_GLFW_X11_EGL) - set(glfw_HEADERS ${common_HEADERS} x11_egl_platform.h) - set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c - x11_gamma.c x11_init.c x11_input.c x11_joystick.c - x11_keysym2unicode.c x11_egl_opengl.c x11_time.c + set(glfw_HEADERS ${common_HEADERS} x11_platform.h egl_platform.h) + set(glfw_SOURCES ${common_SOURCES} egl_opengl.c x11_clipboard.c + x11_fullscreen.c x11_gamma.c x11_init.c x11_input.c + x11_joystick.c x11_keysym2unicode.c x11_time.c x11_window.c) endif() diff --git a/src/x11_egl_opengl.c b/src/egl_opengl.c similarity index 100% rename from src/x11_egl_opengl.c rename to src/egl_opengl.c diff --git a/src/x11_egl_platform.h b/src/egl_platform.h similarity index 100% rename from src/x11_egl_platform.h rename to src/egl_platform.h diff --git a/src/x11_glx_opengl.c b/src/glx_opengl.c similarity index 100% rename from src/x11_glx_opengl.c rename to src/glx_opengl.c diff --git a/src/x11_glx_platform.h b/src/glx_platform.h similarity index 100% rename from src/x11_glx_platform.h rename to src/glx_platform.h diff --git a/src/x11_platform.h b/src/x11_platform.h index edb58315..ff21eaf5 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -55,12 +55,12 @@ #if defined(_GLFW_X11_GLX) #define _GLFW_X11_CONTEXT_VISUAL window->GLX.visual - #include "x11_glx_platform.h" + #include "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" + #include "egl_platform.h" #endif #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 From a4b3a18755c4236864603949fbd764122b6e122e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 8 Nov 2012 16:06:23 +0100 Subject: [PATCH 56/81] Formatting. --- src/win32_joystick.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/win32_joystick.c b/src/win32_joystick.c index 9ffb9aac..3e342168 100644 --- a/src/win32_joystick.c +++ b/src/win32_joystick.c @@ -199,13 +199,19 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, if (hats > 0) { - int j; - int value = ji.dwPOV / 100 / 45; - if (value < 0 || value > 8) value = 8; + int j, value = ji.dwPOV / 100 / 45; + + if (value < 0 || value > 8) + value = 8; for (j = 0; j < 4 && button < numbuttons; j++) { - buttons[button++] = directions[value] & (1 << j) ? GLFW_PRESS : GLFW_RELEASE; + if (directions[value] & (1 << j)) + buttons[button] = GLFW_PRESS; + else + buttons[button] = GLFW_RELEASE; + + button++; } } From 7eff6b1b1ebb0226b8f84156b473839b4a7c4d48 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 8 Nov 2012 16:26:15 +0100 Subject: [PATCH 57/81] Initial implementation of joystick name retrieval on Win32. --- src/win32_joystick.c | 13 ++++++++++++- src/win32_platform.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/win32_joystick.c b/src/win32_joystick.c index 3e342168..a9fe04b1 100644 --- a/src/win32_joystick.c +++ b/src/win32_joystick.c @@ -225,6 +225,17 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, const char* _glfwPlatformGetJoystickName(int joy) { - return ""; + JOYCAPS jc; + const int i = joy - GLFW_JOYSTICK_1; + + if (!isJoystickPresent(joy)) + return NULL; + + _glfw_joyGetDevCaps(i, &jc, sizeof(JOYCAPS)); + + free(_glfwLibrary.Win32.joyNames[i]); + _glfwLibrary.Win32.joyNames[i] = _glfwCreateUTF8FromWideString(jc.szPname); + + return _glfwLibrary.Win32.joyNames[i]; } diff --git a/src/win32_platform.h b/src/win32_platform.h index ba10039e..9ee8cc1a 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -208,6 +208,8 @@ typedef struct _GLFWlibraryWin32 } winmm; #endif // _GLFW_NO_DLOAD_WINMM + char* joyNames[GLFW_JOYSTICK_LAST + 1]; + } _GLFWlibraryWin32; From 875a1697924af99182412ff2f4748abfbd798dbf Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 8 Nov 2012 16:26:43 +0100 Subject: [PATCH 58/81] Added missing test for joystick presence. --- src/x11_joystick.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/x11_joystick.c b/src/x11_joystick.c index d9b0116b..230edcb4 100644 --- a/src/x11_joystick.c +++ b/src/x11_joystick.c @@ -340,6 +340,9 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, const char* _glfwPlatformGetJoystickName(int joy) { + if (!_glfwLibrary.X11.joystick[joy].present) + return NULL; + return _glfwLibrary.X11.joystick[joy].name; } From 38c4a8ef2df466097286293fbb0f294239788e1f Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sat, 10 Nov 2012 00:08:44 +0200 Subject: [PATCH 59/81] Make it possible to use GLESv1 --- include/GL/glfw3.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 31d76761..5b7fbfbb 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -153,6 +153,8 @@ extern "C" { #else #if defined(GLFW_INCLUDE_GL3) #include + #elif defined(GLFW_INCLUDE_ES1) + #include #elif defined(GLFW_INCLUDE_ES2) #include #else From b934cdf5739337f036767f40565e2caa0f5e5b10 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 27 Nov 2012 12:58:59 +0100 Subject: [PATCH 60/81] Begun preparations for Win32 EGL support. --- src/CMakeLists.txt | 6 +- src/egl_opengl.c | 2 +- src/egl_platform.h | 8 +-- src/glx_platform.h | 1 - src/{win32_opengl.c => wgl_opengl.c} | 0 src/wgl_platform.h | 83 ++++++++++++++++++++++++++++ src/win32_platform.h | 58 ++++--------------- 7 files changed, 103 insertions(+), 55 deletions(-) rename src/{win32_opengl.c => wgl_opengl.c} (100%) create mode 100644 src/wgl_platform.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e1fcc39..485f5c13 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,9 +24,9 @@ if (_GLFW_COCOA_NSGL) set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) elseif (_GLFW_WIN32_WGL) set(glfw_HEADERS ${common_HEADERS} win32_platform.h) - set(glfw_SOURCES ${common_SOURCES} win32_clipboard.c win32_fullscreen.c - win32_gamma.c win32_init.c win32_joystick.c - win32_opengl.c win32_time.c win32_window.c) + set(glfw_SOURCES ${common_SOURCES} wgl_opengl.c win32_clipboard.c + win32_fullscreen.c win32_gamma.c win32_init.c + win32_joystick.c win32_time.c win32_window.c) if (GLFW_NATIVE_API) list(APPEND glfw_SOURCES win32_native.c) diff --git a/src/egl_opengl.c b/src/egl_opengl.c index b3247873..054e01f1 100644 --- a/src/egl_opengl.c +++ b/src/egl_opengl.c @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/EGL +// Platform: EGL // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ diff --git a/src/egl_platform.h b/src/egl_platform.h index 8fa4841e..fcc4420a 100644 --- a/src/egl_platform.h +++ b/src/egl_platform.h @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: X11/EGL +// Platform: EGL // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -28,8 +28,8 @@ // //======================================================================== -#ifndef _x11_egl_platform_h_ -#define _x11_egl_platform_h_ +#ifndef _egl_platform_h_ +#define _egl_platform_h_ #include @@ -93,4 +93,4 @@ typedef struct _GLFWlibraryEGL } _GLFWlibraryEGL; -#endif // _x11_egl_platform_h_ +#endif // _egl_platform_h_ diff --git a/src/glx_platform.h b/src/glx_platform.h index 2882a197..a04d6f2e 100644 --- a/src/glx_platform.h +++ b/src/glx_platform.h @@ -62,7 +62,6 @@ #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryGLX GLX -#define _GLFW_CTX GLX #ifndef GLX_MESA_swap_control typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); diff --git a/src/win32_opengl.c b/src/wgl_opengl.c similarity index 100% rename from src/win32_opengl.c rename to src/wgl_opengl.c diff --git a/src/wgl_platform.h b/src/wgl_platform.h new file mode 100644 index 00000000..1bbd8e23 --- /dev/null +++ b/src/wgl_platform.h @@ -0,0 +1,83 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: WGL +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 2002-2006 Marcus Geelnard +// Copyright (c) 2006-2010 Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#ifndef _wgl_platform_h_ +#define _wgl_platform_h_ + +// This path may need to be changed if you build GLFW using your own setup +// We ship and use our own copy of wglext.h since GLFW uses fairly new +// extensions and not all operating systems come with an up-to-date version +#include "../support/GL/wglext.h" + + +#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL +#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryWGL WGL + + +//======================================================================== +// GLFW platform specific types +//======================================================================== + +//------------------------------------------------------------------------ +// Platform-specific OpenGL context structure +//------------------------------------------------------------------------ +typedef struct _GLFWcontextWGL +{ + // Platform specific window resources + HDC DC; // Private GDI device context + HGLRC context; // Permanent rendering context + + // Platform specific extensions (context specific) + PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; + PFNWGLGETPIXELFORMATATTRIBIVARBPROC GetPixelFormatAttribivARB; + PFNWGLGETEXTENSIONSSTRINGEXTPROC GetExtensionsStringEXT; + PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; + PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; + GLboolean EXT_swap_control; + GLboolean ARB_multisample; + GLboolean ARB_pixel_format; + GLboolean ARB_create_context; + GLboolean ARB_create_context_profile; + GLboolean EXT_create_context_es2_profile; + GLboolean ARB_create_context_robustness; +} _GLFWcontextWGL; + + +//------------------------------------------------------------------------ +// Platform-specific library global data for WGL +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryWGL +{ + int dummy; + +} _GLFWlibraryWGL; + + +#endif // _wgl_platform_h_ diff --git a/src/win32_platform.h b/src/win32_platform.h index 217fc2cf..142a7eae 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Win32/WGL +// Platform: Win32 // API version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -28,8 +28,8 @@ // //======================================================================== -#ifndef _platform_h_ -#define _platform_h_ +#ifndef _win32_platform_h_ +#define _win32_platform_h_ // We don't need all the fancy stuff @@ -63,11 +63,6 @@ #include #include -// This path may need to be changed if you build GLFW using your own setup -// We ship and use our own copy of wglext.h since GLFW uses fairly new -// extensions and not all operating systems come with an up-to-date version -#include "../support/GL/wglext.h" - //======================================================================== // Hack: Define things that some windows.h variants don't @@ -110,10 +105,16 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); #define _GLFW_WNDCLASSNAME L"GLFW30" +#if defined(_GLFW_WIN32_WGL) + #include "wgl_platform.h" +#elif defined(_GLFW_WIN32_EGL) + #define _GLFW_EGL_NATIVE_WINDOW window->Win32.handle + #define _GLFW_EGL_NATIVE_DISPLAY NULL + #include "egl_platform.h" +#endif + #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 -#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 Win32 -#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryWGL WGL //======================================================================== @@ -126,31 +127,6 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); typedef INT_PTR GLFWintptr; -//------------------------------------------------------------------------ -// Platform-specific OpenGL context structure -//------------------------------------------------------------------------ -typedef struct _GLFWcontextWGL -{ - // Platform specific window resources - HDC DC; // Private GDI device context - HGLRC context; // Permanent rendering context - - // Platform specific extensions (context specific) - PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; - PFNWGLGETPIXELFORMATATTRIBIVARBPROC GetPixelFormatAttribivARB; - PFNWGLGETEXTENSIONSSTRINGEXTPROC GetExtensionsStringEXT; - PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; - PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; - GLboolean EXT_swap_control; - GLboolean ARB_multisample; - GLboolean ARB_pixel_format; - GLboolean ARB_create_context; - GLboolean ARB_create_context_profile; - GLboolean EXT_create_context_es2_profile; - GLboolean ARB_create_context_robustness; -} _GLFWcontextWGL; - - //------------------------------------------------------------------------ // Platform-specific window structure //------------------------------------------------------------------------ @@ -210,16 +186,6 @@ typedef struct _GLFWlibraryWin32 } _GLFWlibraryWin32; -//------------------------------------------------------------------------ -// Platform-specific library global data for WGL -//------------------------------------------------------------------------ -typedef struct _GLFWlibraryWGL -{ - int dummy; - -} _GLFWlibraryWGL; - - //======================================================================== // Prototypes for platform specific internal functions //======================================================================== @@ -244,4 +210,4 @@ void _glfwSetVideoMode(int* width, int* height, void _glfwRestoreVideoMode(void); -#endif // _platform_h_ +#endif // _win32_platform_h_ From 7e9286c1fa15a5a1d94d8e41013e7e855a2cc46c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 27 Nov 2012 13:10:14 +0100 Subject: [PATCH 61/81] Removed unused stub. --- src/egl_opengl.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/egl_opengl.c b/src/egl_opengl.c index 054e01f1..0f10745d 100644 --- a/src/egl_opengl.c +++ b/src/egl_opengl.c @@ -589,14 +589,3 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname) return _glfw_eglGetProcAddress(procname); } - -//======================================================================== -// Copies the specified OpenGL state categories from src to dst -//======================================================================== - -void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask) -{ - _glfwSetError(GLFW_PLATFORM_ERROR, - "EGL: Context copying not supported by EGL"); -} - From 10cc85343a5c131861b9c20b96505e4a093ac300 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 27 Nov 2012 13:38:21 +0100 Subject: [PATCH 62/81] Formatting. --- include/GL/glfw3.h | 2 +- src/cocoa_platform.h | 5 +++-- src/egl_platform.h | 2 +- src/glx_platform.h | 2 +- src/wgl_platform.h | 2 +- src/win32_platform.h | 2 +- src/x11_platform.h | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index d37ee178..ecc8c28f 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -526,7 +526,7 @@ extern "C" { /*! @brief The @link clients client API @endlink to create a context for. */ #define GLFW_CLIENT_API 0x00022000 -#define GLFW_OPENGL_VERSION_MAJOR 0x00022001 +#define GLFW_CLIENT_VERSION_MAJOR 0x00022001 #define GLFW_OPENGL_VERSION_MINOR 0x00022002 #define GLFW_OPENGL_FORWARD_COMPAT 0x00022003 #define GLFW_OPENGL_DEBUG_CONTEXT 0x00022004 diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 06055a25..46957e53 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -41,9 +41,10 @@ typedef void* id; #endif -#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS -#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL +#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS NS + +#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryNSGL NSGL diff --git a/src/egl_platform.h b/src/egl_platform.h index fcc4420a..cb9114dd 100644 --- a/src/egl_platform.h +++ b/src/egl_platform.h @@ -54,7 +54,7 @@ #error "No OpenGL entry point retrieval mechanism was enabled" #endif -#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL EGL +#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextEGL EGL #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryEGL EGL diff --git a/src/glx_platform.h b/src/glx_platform.h index a04d6f2e..92a5ec65 100644 --- a/src/glx_platform.h +++ b/src/glx_platform.h @@ -60,7 +60,7 @@ #error "No OpenGL entry point retrieval mechanism was enabled" #endif -#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX +#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryGLX GLX #ifndef GLX_MESA_swap_control diff --git a/src/wgl_platform.h b/src/wgl_platform.h index 1bbd8e23..346176a3 100644 --- a/src/wgl_platform.h +++ b/src/wgl_platform.h @@ -37,7 +37,7 @@ #include "../support/GL/wglext.h" -#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL +#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL #define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryWGL WGL diff --git a/src/win32_platform.h b/src/win32_platform.h index 142a7eae..20126177 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -113,7 +113,7 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); #include "egl_platform.h" #endif -#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 +#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 Win32 diff --git a/src/x11_platform.h b/src/x11_platform.h index e2acc6e6..7c4ad4ce 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -63,7 +63,7 @@ #include "egl_platform.h" #endif -#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 +#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 X11 // Clipboard format atom indices From b49c78ed963e34679d56c5a068c25f792cba44d8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 27 Nov 2012 14:02:48 +0100 Subject: [PATCH 63/81] Added missing whitespace. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40c16ff9..b920fa30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,7 +172,7 @@ endif() if (_GLFW_X11_GLX) # Set up library and include paths - list(APPEND glfw_INCLUDE_DIRS${OPENGL_INCLUDE_DIR}) + list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) list(APPEND glfw_LIBRARIES ${OPENGL_gl_LIBRARY}) set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} gl") From 4ce92262f714a16036ef104ff4c0607201a07187 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 27 Nov 2012 14:31:10 +0100 Subject: [PATCH 64/81] Reverted bad edit. --- include/GL/glfw3.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index ecc8c28f..d37ee178 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -526,7 +526,7 @@ extern "C" { /*! @brief The @link clients client API @endlink to create a context for. */ #define GLFW_CLIENT_API 0x00022000 -#define GLFW_CLIENT_VERSION_MAJOR 0x00022001 +#define GLFW_OPENGL_VERSION_MAJOR 0x00022001 #define GLFW_OPENGL_VERSION_MINOR 0x00022002 #define GLFW_OPENGL_FORWARD_COMPAT 0x00022003 #define GLFW_OPENGL_DEBUG_CONTEXT 0x00022004 From 34d383399c222af661c6d408f3c583e455c2d2f1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 27 Nov 2012 15:02:26 +0100 Subject: [PATCH 65/81] Finished initial window/context backend split. --- CMakeLists.txt | 108 +++++++++++++++----------- src/CMakeLists.txt | 46 ++++++----- src/cocoa_platform.h | 36 ++------- src/config.h.in | 23 ++++-- src/egl_opengl.c | 2 +- src/egl_platform.h | 2 +- src/internal.h | 6 +- src/{cocoa_opengl.m => nsgl_opengl.m} | 0 src/nsgl_platform.h | 62 +++++++++++++++ src/win32_init.c | 5 ++ src/win32_platform.h | 4 +- src/x11_fullscreen.c | 2 +- src/x11_init.c | 4 +- src/x11_platform.h | 4 +- 14 files changed, 191 insertions(+), 113 deletions(-) rename src/{cocoa_opengl.m => nsgl_opengl.m} (100%) create mode 100644 src/nsgl_platform.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b920fa30..5797c99f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,10 @@ option(GLFW_USE_EGL "Build for EGL and OpenGL ES platform (Currently only X11)" if (GLFW_USE_EGL) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake/modules) find_package(EGL REQUIRED) + + set(GLFW_BUILD_EXAMPLES OFF) + set(GLFW_BUILD_TESTS OFF) + message(STATUS "NOTE: Examples and tests are disabled for EGL") else() find_package(OpenGL REQUIRED) endif() @@ -47,25 +51,39 @@ if (BUILD_SHARED_LIBS) endif() #-------------------------------------------------------------------- -# Detect and select target platform +# Detect and select target APIs #-------------------------------------------------------------------- if (WIN32) - set(_GLFW_WIN32_WGL 1) - message(STATUS "Building GLFW for WGL on a Win32 system") -elseif (UNIX AND APPLE) - set(_GLFW_COCOA_NSGL 1) - message(STATUS "Building GLFW for Cocoa and NSOpenGL on Mac OS X") -elseif (UNIX AND NOT APPLE) - set(_GLFW_X11 1) + set(_GLFW_WIN32 1) + message(STATUS "Using Win32 for window creation") + if (GLFW_USE_EGL) - set(_GLFW_X11_EGL 1) - set(GLFW_BUILD_EXAMPLES 0) - set(GLFW_BUILD_TESTS 0) - message(STATUS "Building GLFW for X11 and EGL on a Unix-like system") - message(STATUS "NOTE: Examples and tests are disabled for EGL") + set(_GLFW_EGL 1) + message(STATUS "Using EGL for context creation") else() - set(_GLFW_X11_GLX 1) - message(STATUS "Building GLFW for X11 and GLX on a Unix-like system") + set(_GLFW_WGL 1) + message(STATUS "Using WGL for context creation") + endif() +elseif (APPLE) + set(_GLFW_COCOA 1) + message(STATUS "Using Cocoa for window creation") + + if (GLFW_USE_EGL) + message(FATAL_ERROR "EGL not supported on Mac OS X") + else() + set(_GLFW_NSGL 1) + message(STATUS "Using NSGL for context creation") + endif() +elseif (UNIX) + set(_GLFW_X11 1) + message(STATUS "Using X11 for window creation") + + if (GLFW_USE_EGL) + set(_GLFW_EGL 1) + message(STATUS "Using EGL for context creation") + else() + set(_GLFW_GLX 1) + message(STATUS "Using GLX for context creation") endif() else() message(FATAL_ERROR "No supported platform was detected") @@ -74,7 +92,7 @@ endif() #-------------------------------------------------------------------- # Set up GLFW for Win32 and WGL on Windows #-------------------------------------------------------------------- -if (_GLFW_WIN32_WGL) +if (_GLFW_WIN32) # Set up library and include paths list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) @@ -160,16 +178,12 @@ if (_GLFW_X11) set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -lm") endif() - if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - set(_GLFW_USE_LINUX_JOYSTICKS 1) - endif() - endif() #-------------------------------------------------------------------- # GLX Context #-------------------------------------------------------------------- -if (_GLFW_X11_GLX) +if (_GLFW_GLX) # Set up library and include paths list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) @@ -223,42 +237,44 @@ endif() #-------------------------------------------------------------------- # EGL Context #-------------------------------------------------------------------- -if (_GLFW_X11_EGL) +if (_GLFW_EGL) # Set up library and include paths list(APPEND glfw_INCLUDE_DIRS ${EGL_INCLUDE_DIR}) list(APPEND glfw_LIBRARIES ${EGL_LIBRARY}) - set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} egl") - - include(CheckFunctionExists) - set(CMAKE_REQUIRED_LIBRARIES ${EGL_LIBRARY}) - check_function_exists(eglGetProcAddress _GLFW_HAS_EGLGETPROCADDRESS) + if (_GLFW_X11) + set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} egl") - if (NOT _GLFW_HAS_EGLGETPROCADDRESS) - message(WARNING "No eglGetProcAddress found") + include(CheckFunctionExists) - # Check for dlopen support as a fallback + check_function_exists(eglGetProcAddress _GLFW_HAS_EGLGETPROCADDRESS) - find_library(DL_LIBRARY dl) - mark_as_advanced(DL_LIBRARY) - if (DL_LIBRARY) - set(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARY}) - else() - set(CMAKE_REQUIRED_LIBRARIES "") - endif() + if (NOT _GLFW_HAS_EGLGETPROCADDRESS) + message(WARNING "No eglGetProcAddress found") - check_function_exists(dlopen _GLFW_HAS_DLOPEN) + # Check for dlopen support as a fallback - if (NOT _GLFW_HAS_DLOPEN) - message(FATAL_ERROR "No entry point retrieval mechanism found") - endif() + find_library(DL_LIBRARY dl) + mark_as_advanced(DL_LIBRARY) + if (DL_LIBRARY) + set(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARY}) + else() + set(CMAKE_REQUIRED_LIBRARIES "") + endif() - if (DL_LIBRARY) - list(APPEND glfw_LIBRARIES ${DL_LIBRARY}) - set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -ldl") + check_function_exists(dlopen _GLFW_HAS_DLOPEN) + + if (NOT _GLFW_HAS_DLOPEN) + message(FATAL_ERROR "No entry point retrieval mechanism found") + endif() + + if (DL_LIBRARY) + list(APPEND glfw_LIBRARIES ${DL_LIBRARY}) + set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -ldl") + endif() endif() endif() @@ -267,7 +283,7 @@ endif() #-------------------------------------------------------------------- # Set up GLFW for Cocoa and NSOpenGL on Mac OS X #-------------------------------------------------------------------- -if (_GLFW_COCOA_NSGL) +if (_GLFW_COCOA AND _GLFW_NSGL) option(GLFW_BUILD_UNIVERSAL "Build GLFW as a Universal Binary" OFF) @@ -349,7 +365,7 @@ install(FILES COPYING.txt readme.html #-------------------------------------------------------------------- # Create and install pkg-config file on supported platforms #-------------------------------------------------------------------- -if (_GLFW_X11_GLX OR _GLFW_COCOA_NSGL) +if (UNIX) configure_file(${GLFW_SOURCE_DIR}/src/glfw3.pc.in ${GLFW_BINARY_DIR}/src/glfw3.pc @ONLY) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 485f5c13..08602a9d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,11 +10,11 @@ set(common_HEADERS ${GLFW_SOURCE_DIR}/include/GL/glfw3.h internal.h) set(common_SOURCES clipboard.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) -if (_GLFW_COCOA_NSGL) +if (_GLFW_COCOA) set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h) set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_fullscreen.m - cocoa_gamma.c cocoa_init.m cocoa_joystick.m - cocoa_opengl.m cocoa_time.c cocoa_window.m) + cocoa_gamma.c cocoa_init.m cocoa_joystick.m cocoa_time.c + cocoa_window.m) if (GLFW_NATIVE_API) list(APPEND glfw_SOURCES cocoa_native.m) @@ -22,30 +22,38 @@ if (_GLFW_COCOA_NSGL) # For some reason, CMake doesn't know about .m set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) -elseif (_GLFW_WIN32_WGL) +elseif (_GLFW_WIN32) set(glfw_HEADERS ${common_HEADERS} win32_platform.h) - set(glfw_SOURCES ${common_SOURCES} wgl_opengl.c win32_clipboard.c - win32_fullscreen.c win32_gamma.c win32_init.c - win32_joystick.c win32_time.c win32_window.c) + set(glfw_SOURCES ${common_SOURCES} win32_clipboard.c win32_fullscreen.c + win32_gamma.c win32_init.c win32_joystick.c win32_time.c + win32_window.c) if (GLFW_NATIVE_API) list(APPEND glfw_SOURCES win32_native.c) endif() -elseif (_GLFW_X11_GLX) +elseif (_GLFW_X11) set(glfw_HEADERS ${common_HEADERS} x11_platform.h) - set(glfw_SOURCES ${common_SOURCES} glx_opengl.c x11_clipboard.c - x11_fullscreen.c x11_gamma.c x11_init.c x11_joystick.c - x11_keysym2unicode.c x11_time.c x11_window.c) + set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c + x11_gamma.c x11_init.c x11_joystick.c x11_keysym2unicode.c + x11_time.c x11_window.c) if (GLFW_NATIVE_API) list(APPEND glfw_SOURCES x11_native.c) endif() -elseif (_GLFW_X11_EGL) - set(glfw_HEADERS ${common_HEADERS} x11_platform.h egl_platform.h) - set(glfw_SOURCES ${common_SOURCES} egl_opengl.c x11_clipboard.c - x11_fullscreen.c x11_gamma.c x11_init.c - x11_joystick.c x11_keysym2unicode.c x11_time.c - x11_window.c) +endif() + +if (_GLFW_EGL) + list(APPEND glfw_HEADERS ${common_HEADERS} egl_platform.h) + list(APPEND glfw_SOURCES ${common_SOURCES} egl_opengl.c) +elseif (_GLFW_NSGL) + list(APPEND glfw_HEADERS ${common_HEADERS} nsgl_platform.h) + list(APPEND glfw_SOURCES ${common_SOURCES} nsgl_opengl.c) +elseif (_GLFW_WGL) + list(APPEND glfw_HEADERS ${common_HEADERS} wgl_platform.h) + list(APPEND glfw_SOURCES ${common_SOURCES} wgl_opengl.c) +elseif (_GLFW_X11) + list(APPEND glfw_HEADERS ${common_HEADERS} glx_platform.h) + list(APPEND glfw_SOURCES ${common_SOURCES} glx_opengl.c) endif() add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) @@ -58,7 +66,7 @@ if (BUILD_SHARED_LIBS) set_target_properties(glfw PROPERTIES SOVERSION ${GLFW_VERSION_MAJOR}) endif() - if (_GLFW_WIN32_WGL) + if (_GLFW_WIN32) # The GLFW DLL needs a special compile-time macro and import library name set_target_properties(glfw PROPERTIES PREFIX "" IMPORT_PREFIX "") @@ -67,7 +75,7 @@ if (BUILD_SHARED_LIBS) else() set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") endif() - elseif (_GLFW_COCOA_NSGL) + elseif (_GLFW_COCOA) # Append -fno-common to the compile flags to work around a bug in the Apple GCC get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS) if (NOT glfw_CFLAGS) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 46957e53..57a27487 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -1,6 +1,6 @@ //======================================================================== // GLFW - An OpenGL library -// Platform: Cocoa/NSOpenGL +// Platform: Cocoa // API Version: 3.0 // WWW: http://www.glfw.org/ //------------------------------------------------------------------------ @@ -27,13 +27,12 @@ // //======================================================================== -#ifndef _platform_h_ -#define _platform_h_ +#ifndef _cocoa_platform_h_ +#define _cocoa_platform_h_ #include - #if defined(__OBJC__) #import #else @@ -41,12 +40,13 @@ typedef void* id; #endif +#if defined(_GLFW_NSGL) + #include "nsgl_platform.h" +#endif + #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS NS -#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL -#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryNSGL NSGL - //======================================================================== // GLFW platform specific types @@ -58,16 +58,6 @@ typedef void* id; typedef intptr_t GLFWintptr; -//------------------------------------------------------------------------ -// Platform-specific OpenGL context structure -//------------------------------------------------------------------------ -typedef struct _GLFWcontextNSGL -{ - id pixelFormat; - id context; -} _GLFWcontextNSGL; - - //------------------------------------------------------------------------ // Platform-specific window structure //------------------------------------------------------------------------ @@ -99,16 +89,6 @@ typedef struct _GLFWlibraryNS } _GLFWlibraryNS; -//------------------------------------------------------------------------ -// Platform-specific library global data for NSGL -//------------------------------------------------------------------------ -typedef struct _GLFWlibraryNSGL -{ - // dlopen handle for dynamically loading OpenGL extension entry points - void* framework; -} _GLFWlibraryNSGL; - - //======================================================================== // Prototypes for platform specific internal functions //======================================================================== @@ -128,4 +108,4 @@ void _glfwRestoreVideoMode(void); int _glfwInitOpenGL(void); void _glfwTerminateOpenGL(void); -#endif // _platform_h_ +#endif // _cocoa_platform_h_ diff --git a/src/config.h.in b/src/config.h.in index f725f89f..d391fcdf 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -35,14 +35,21 @@ // it. Instead, you should modify the config.h.in file. //======================================================================== -// Define this to 1 if building GLFW for X11/GLX -#cmakedefine _GLFW_X11_GLX -// Define this to 1 if building GLFW for X11/EGL -#cmakedefine _GLFW_X11_EGL -// Define this to 1 if building GLFW for Win32/WGL -#cmakedefine _GLFW_WIN32_WGL -// Define this to 1 if building GLFW for Cocoa/NSOpenGL -#cmakedefine _GLFW_COCOA_NSGL +// Define this to 1 if building GLFW for X11 +#cmakedefine _GLFW_X11 +// Define this to 1 if building GLFW for Win32 +#cmakedefine _GLFW_WIN32 +// Define this to 1 if building GLFW for Cocoa +#cmakedefine _GLFW_COCOA + +// Define this to 1 if building GLFW for EGL +#cmakedefine _GLFW_EGL +// Define this to 1 if building GLFW for GLX +#cmakedefine _GLFW_GLX +// Define this to 1 if building GLFW for WGL +#cmakedefine _GLFW_WGL +// Define this to 1 if building GLFW for NSGL +#cmakedefine _GLFW_NSGL // Define this to 1 if building as a shared library / dynamic library / DLL #cmakedefine _GLFW_BUILD_DLL diff --git a/src/egl_opengl.c b/src/egl_opengl.c index 0f10745d..cf8ad77a 100644 --- a/src/egl_opengl.c +++ b/src/egl_opengl.c @@ -208,7 +208,7 @@ 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? -#if defined(_GLFW_X11_EGL) +#if defined(_GLFW_X11) { int mask; EGLint redBits, greenBits, blueBits, alphaBits, visualID = 0; diff --git a/src/egl_platform.h b/src/egl_platform.h index cb9114dd..e416871c 100644 --- a/src/egl_platform.h +++ b/src/egl_platform.h @@ -71,7 +71,7 @@ typedef struct _GLFWcontextEGL EGLContext context; EGLSurface surface; -#if defined(_GLFW_X11_EGL) +#if defined(_GLFW_X11) XVisualInfo* visual; #endif } _GLFWcontextEGL; diff --git a/src/internal.h b/src/internal.h index 436a63ad..36b586da 100644 --- a/src/internal.h +++ b/src/internal.h @@ -65,11 +65,11 @@ typedef struct _GLFWlibrary _GLFWlibrary; // extensions and not all operating systems come with an up-to-date version #include "../support/GL/glext.h" -#if defined(_GLFW_COCOA_NSGL) +#if defined(_GLFW_COCOA) #include "cocoa_platform.h" -#elif defined(_GLFW_WIN32_WGL) +#elif defined(_GLFW_WIN32) #include "win32_platform.h" -#elif defined(_GLFW_X11_GLX) || defined(_GLFW_X11_EGL) +#elif defined(_GLFW_X11) #include "x11_platform.h" #else #error "No supported platform selected" diff --git a/src/cocoa_opengl.m b/src/nsgl_opengl.m similarity index 100% rename from src/cocoa_opengl.m rename to src/nsgl_opengl.m diff --git a/src/nsgl_platform.h b/src/nsgl_platform.h new file mode 100644 index 00000000..34ea0fb6 --- /dev/null +++ b/src/nsgl_platform.h @@ -0,0 +1,62 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: NSOpenGL +// API Version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 2009-2010 Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== + +#ifndef _nsgl_platform_h_ +#define _nsgl_platform_h_ + + +#define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL +#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryNSGL NSGL + + +//======================================================================== +// GLFW platform specific types +//======================================================================== + +//------------------------------------------------------------------------ +// Platform-specific OpenGL context structure +//------------------------------------------------------------------------ +typedef struct _GLFWcontextNSGL +{ + id pixelFormat; + id context; +} _GLFWcontextNSGL; + + +//------------------------------------------------------------------------ +// Platform-specific library global data for NSGL +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryNSGL +{ + // dlopen handle for dynamically loading OpenGL extension entry points + void* framework; +} _GLFWlibraryNSGL; + + +#endif // _nsgl_platform_h_ diff --git a/src/win32_init.c b/src/win32_init.c index 21de415b..62d6c94b 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -232,6 +232,11 @@ int _glfwPlatformTerminate(void) const char* _glfwPlatformGetVersionString(void) { const char* version = _GLFW_VERSION_FULL +#if defined(_GLFW_WGL) + " WGL" +#elif defined(_GLFW_EGL) + " EGL" +#endif #if defined(__MINGW32__) " MinGW" #elif defined(_MSC_VER) diff --git a/src/win32_platform.h b/src/win32_platform.h index 20126177..758ada2c 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -105,9 +105,9 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); #define _GLFW_WNDCLASSNAME L"GLFW30" -#if defined(_GLFW_WIN32_WGL) +#if defined(_GLFW_WGL) #include "wgl_platform.h" -#elif defined(_GLFW_WIN32_EGL) +#elif defined(_GLFW_EGL) #define _GLFW_EGL_NATIVE_WINDOW window->Win32.handle #define _GLFW_EGL_NATIVE_DISPLAY NULL #include "egl_platform.h" diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index 06b161e4..9b1121fc 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -449,7 +449,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(int* found) rgbs = (int*) malloc(sizeof(int) * visualCount); rgbCount = 0; -#if !defined(_GLFW_X11_EGL) +#if defined(_GLFW_GLX) for (i = 0; i < visualCount; i++) { int gl, rgba, rgb, r, g, b; diff --git a/src/x11_init.c b/src/x11_init.c index b76d307e..b5631fba 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -693,9 +693,9 @@ int _glfwPlatformTerminate(void) const char* _glfwPlatformGetVersionString(void) { const char* version = _GLFW_VERSION_FULL -#if defined(_GLFW_X11_GLX) +#if defined(_GLFW_GLX) " GLX" -#elif defined(_GLFW_X11_EGL) +#elif defined(_GLFW_EGL) " EGL" #endif #if defined(_GLFW_HAS_XRANDR) diff --git a/src/x11_platform.h b/src/x11_platform.h index 7c4ad4ce..8c4740a0 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -53,10 +53,10 @@ #include #endif -#if defined(_GLFW_X11_GLX) +#if defined(_GLFW_GLX) #define _GLFW_X11_CONTEXT_VISUAL window->GLX.visual #include "glx_platform.h" -#elif defined(_GLFW_X11_EGL) +#elif defined(_GLFW_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 From 5ea359158650f61332373c088b4b424a29a2232b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 27 Nov 2012 15:17:24 +0100 Subject: [PATCH 66/81] Cocoa NSGL fixes. --- src/CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08602a9d..08ee9dad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,9 +19,6 @@ if (_GLFW_COCOA) if (GLFW_NATIVE_API) list(APPEND glfw_SOURCES cocoa_native.m) endif() - - # For some reason, CMake doesn't know about .m - set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) elseif (_GLFW_WIN32) set(glfw_HEADERS ${common_HEADERS} win32_platform.h) set(glfw_SOURCES ${common_SOURCES} win32_clipboard.c win32_fullscreen.c @@ -47,7 +44,7 @@ if (_GLFW_EGL) list(APPEND glfw_SOURCES ${common_SOURCES} egl_opengl.c) elseif (_GLFW_NSGL) list(APPEND glfw_HEADERS ${common_HEADERS} nsgl_platform.h) - list(APPEND glfw_SOURCES ${common_SOURCES} nsgl_opengl.c) + list(APPEND glfw_SOURCES ${common_SOURCES} nsgl_opengl.m) elseif (_GLFW_WGL) list(APPEND glfw_HEADERS ${common_HEADERS} wgl_platform.h) list(APPEND glfw_SOURCES ${common_SOURCES} wgl_opengl.c) @@ -56,6 +53,11 @@ elseif (_GLFW_X11) list(APPEND glfw_SOURCES ${common_SOURCES} glx_opengl.c) endif() +if (_GLFW_NSGL) + # For some reason, CMake doesn't know about .m + set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) +endif() + add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) set_target_properties(glfw PROPERTIES OUTPUT_NAME "${GLFW_LIB_NAME}") From 1eef0f08691134a37f239686a6916d21d2913e9a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 27 Nov 2012 15:21:49 +0100 Subject: [PATCH 67/81] Renamed context module files. --- src/CMakeLists.txt | 12 ++++++------ src/{opengl.c => context.c} | 0 src/{egl_opengl.c => egl_context.c} | 0 src/{glx_opengl.c => glx_context.c} | 0 src/{nsgl_opengl.m => nsgl_context.m} | 0 src/{wgl_opengl.c => wgl_context.c} | 0 6 files changed, 6 insertions(+), 6 deletions(-) rename src/{opengl.c => context.c} (100%) rename src/{egl_opengl.c => egl_context.c} (100%) rename src/{glx_opengl.c => glx_context.c} (100%) rename src/{nsgl_opengl.m => nsgl_context.m} (100%) rename src/{wgl_opengl.c => wgl_context.c} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08ee9dad..7f5be33b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,8 +7,8 @@ if (MSVC) endif() set(common_HEADERS ${GLFW_SOURCE_DIR}/include/GL/glfw3.h internal.h) -set(common_SOURCES clipboard.c fullscreen.c gamma.c init.c input.c - joystick.c opengl.c time.c window.c) +set(common_SOURCES clipboard.c context.c fullscreen.c gamma.c init.c input.c + joystick.c time.c window.c) if (_GLFW_COCOA) set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h) @@ -41,16 +41,16 @@ endif() if (_GLFW_EGL) list(APPEND glfw_HEADERS ${common_HEADERS} egl_platform.h) - list(APPEND glfw_SOURCES ${common_SOURCES} egl_opengl.c) + list(APPEND glfw_SOURCES ${common_SOURCES} egl_context.c) elseif (_GLFW_NSGL) list(APPEND glfw_HEADERS ${common_HEADERS} nsgl_platform.h) - list(APPEND glfw_SOURCES ${common_SOURCES} nsgl_opengl.m) + list(APPEND glfw_SOURCES ${common_SOURCES} nsgl_context.m) elseif (_GLFW_WGL) list(APPEND glfw_HEADERS ${common_HEADERS} wgl_platform.h) - list(APPEND glfw_SOURCES ${common_SOURCES} wgl_opengl.c) + list(APPEND glfw_SOURCES ${common_SOURCES} wgl_context.c) elseif (_GLFW_X11) list(APPEND glfw_HEADERS ${common_HEADERS} glx_platform.h) - list(APPEND glfw_SOURCES ${common_SOURCES} glx_opengl.c) + list(APPEND glfw_SOURCES ${common_SOURCES} glx_context.c) endif() if (_GLFW_NSGL) diff --git a/src/opengl.c b/src/context.c similarity index 100% rename from src/opengl.c rename to src/context.c diff --git a/src/egl_opengl.c b/src/egl_context.c similarity index 100% rename from src/egl_opengl.c rename to src/egl_context.c diff --git a/src/glx_opengl.c b/src/glx_context.c similarity index 100% rename from src/glx_opengl.c rename to src/glx_context.c diff --git a/src/nsgl_opengl.m b/src/nsgl_context.m similarity index 100% rename from src/nsgl_opengl.m rename to src/nsgl_context.m diff --git a/src/wgl_opengl.c b/src/wgl_context.c similarity index 100% rename from src/wgl_opengl.c rename to src/wgl_context.c From 1a3d47d06daa2004a4df629fdcf7676ca1a4e27a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 30 Nov 2012 13:56:42 +0100 Subject: [PATCH 68/81] Added window position callback. --- include/GL/glfw3.h | 18 ++++++++++++++++++ readme.html | 3 ++- src/internal.h | 1 + src/window.c | 24 ++++++++++++++++++++++++ tests/events.c | 10 ++++++++++ 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 8759ea79..e9cea004 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -706,6 +706,16 @@ typedef void* GLFWwindow; */ typedef void (* GLFWerrorfun)(int,const char*); +/*! @brief The function signature for window position callbacks. + * @param[in] window The window that the user moved. + * @param[in] x The new x-coordinate, in pixels, of the upper-left corner of + * the client area of the window. + * @param[in] y The new y-coordinate, in pixels, of the upper-left corner of + * the client area of the window. + * @ingroup window + */ +typedef void (* GLFWwindowposfun)(GLFWwindow,int,int); + /*! @brief The function signature for window resize callbacks. * @param[in] window The window that the user resized. * @param[in] width The new width, in pixels, of the window. @@ -1274,6 +1284,14 @@ GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer); */ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window); +/*! @brief Sets the position callback for the specified window. + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or @c NULL to remove the currently set + * callback. + * @ingroup window + */ +GLFWAPI void glfwSetWindowPosCallback(GLFWwindow window, GLFWwindowposfun cbfun); + /*! @brief Sets the size callback for the specified window. * @param[in] window The window whose callback to set. * @param[in] cbfun The new callback, or @c NULL to remove the currently set diff --git a/readme.html b/readme.html index 81100df6..1e629456 100644 --- a/readme.html +++ b/readme.html @@ -274,7 +274,7 @@ version of GLFW.

  • Added glfwSetErrorCallback function and GLFWerrorfun type for receiving more specific and/or nested errors
  • Added glfwSetWindowUserPointer and glfwGetWindowUserPointer functions for per-window user pointers
  • Added glfwGetVersionString function for determining which code paths were enabled at compile time
  • -
  • Added glfwGetWindowPos function for querying the position of the specified window
  • +
  • Added glfwSetWindowPosCallback function and GLFWwindowposfun type for reciving window position events
  • Added glfwSetWindowFocusCallback function and GLFWwindowfocusfun type for receiving window focus events
  • Added glfwSetWindowIconifyCallback function and GLFWwindowiconifyfun type for receiving window iconification events
  • Added glfwGetClipboardString and glfwSetClipboardString functions for interacting with the system clipboard
  • @@ -284,6 +284,7 @@ version of GLFW.

  • Added GLFW_OPENGL_REVISION window parameter to make up for removal of glfwGetGLVersion
  • Added GLFW_INCLUDE_GLCOREARB macro for including glcorearb.h instead of gl.h
  • Added GLFW_VISIBLE window hint and parameter for controlling and polling window visibility
  • +
  • Added GLFW_POSITION_X and GLFW_POSITION_Y window hints and parameter for controlling and polling window position
  • Added windows simple multi-window test program
  • Added sharing simple OpenGL object sharing test program
  • Added modes video mode enumeration and setting test program
  • diff --git a/src/internal.h b/src/internal.h index c5a40af3..2ef8f10c 100644 --- a/src/internal.h +++ b/src/internal.h @@ -199,6 +199,7 @@ struct _GLFWwindow int glRobustness; PFNGLGETSTRINGIPROC GetStringi; + GLFWwindowposfun windowPosCallback; GLFWwindowsizefun windowSizeCallback; GLFWwindowclosefun windowCloseCallback; GLFWwindowrefreshfun windowRefreshCallback; diff --git a/src/window.c b/src/window.c index 908a2a7c..ac0fd02f 100644 --- a/src/window.c +++ b/src/window.c @@ -119,8 +119,14 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused) void _glfwInputWindowPos(_GLFWwindow* window, int x, int y) { + if (window->positionX == x && window->positionY == y) + return; + window->positionX = x; window->positionY = y; + + if (window->windowPosCallback) + window->windowPosCallback(window, x, y); } @@ -764,6 +770,24 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow handle) } +//======================================================================== +// Set callback function for window position changes +//======================================================================== + +GLFWAPI void glfwSetWindowPosCallback(GLFWwindow handle, GLFWwindowposfun cbfun) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + window->windowPosCallback = cbfun; +} + + //======================================================================== // Set callback function for window size changes //======================================================================== diff --git a/tests/events.c b/tests/events.c index 3150a82e..46bde2ab 100644 --- a/tests/events.c +++ b/tests/events.c @@ -218,6 +218,15 @@ static const char* get_character_string(int character) return result; } +static void window_pos_callback(GLFWwindow window, int x, int y) +{ + printf("%08x at %0.3f: Window position: %i %i\n", + counter++, + glfwGetTime(), + x, + y); +} + static void window_size_callback(GLFWwindow window, int width, int height) { printf("%08x at %0.3f: Window size: %i %i\n", @@ -354,6 +363,7 @@ int main(void) printf("Window opened\n"); + glfwSetWindowPosCallback(window, window_pos_callback); glfwSetWindowSizeCallback(window, window_size_callback); glfwSetWindowCloseCallback(window, window_close_callback); glfwSetWindowRefreshCallback(window, window_refresh_callback); From a3ff29af36753272406e852f82dbe45df5c5584c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 15:47:10 +0100 Subject: [PATCH 69/81] Documentation updates. --- include/GL/glfw3.h | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index e9cea004..b5735a96 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -954,7 +954,7 @@ GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode); /*! @brief Sets the system gamma ramp to one generated from the specified * exponent. - * @param[in] The desired exponent. + * @param[in] gamma The desired exponent. * @ingroup gamma */ GLFWAPI void glfwSetGamma(float gamma); @@ -1048,7 +1048,8 @@ GLFWAPI void glfwDefaultWindowHints(void); * used by the OpenGL context. * * The @ref GLFW_RESIZABLE hint specifies whether the window will be resizable - * by the user. This hint is ignored for fullscreen windows. + * by the user. The window will still be resizable using the @ref + * glfwSetWindowSize function. This hint is ignored for fullscreen windows. * * The @ref GLFW_VISIBLE hint specifies whether the window will be initially * visible. This hint is ignored for fullscreen windows. @@ -1059,7 +1060,9 @@ GLFWAPI void glfwDefaultWindowHints(void); * Some window hints are hard constraints. These must match the available * capabilities @em exactly for window and context creation to succeed. Hints * that are not hard constraints are matched as closely as possible, but the - * resulting window and context may differ from what these hints requested. + * resulting window and context may differ from what these hints requested. To + * find out the actual properties of the created window and context, use the + * @ref glfwGetWindowParam function. * * The following window hints are hard constraints: * @arg @ref GLFW_STEREO @@ -1297,6 +1300,8 @@ GLFWAPI void glfwSetWindowPosCallback(GLFWwindow window, GLFWwindowposfun cbfun) * @param[in] cbfun The new callback, or @c NULL to remove the currently set * callback. * @ingroup window + * + * This callback is called when the window is resized. */ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun); @@ -1305,6 +1310,14 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfu * @param[in] cbfun The new callback, or @c NULL to remove the currently set * callback. * @ingroup window + * + * This callback is called when the user attempts to close the window, i.e. + * clicks the window's close widget or, on Mac OS X, selects @b Quit from the + * application menu. Calling @ref glfwDestroyWindow does not cause this + * callback to be called. + * + * The return value of the close callback becomes the new value of the @ref + * GLFW_CLOSE_REQUESTED window parameter. */ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun); @@ -1313,6 +1326,13 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cb * @param[in] cbfun The new callback, or @c NULL to remove the currently set * callback. * @ingroup window + * + * This callback is called when the client area of the window needs to be + * redrawn, for example if the window has been exposed after having been + * covered by another window. + * + * @note On compositing window systems such as Mac OS X, where the window + * contents are saved off-screen, this callback may never be called. */ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun); @@ -1321,6 +1341,8 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfu * @param[in] cbfun The new callback, or @c NULL to remove the currently set * callback. * @ingroup window + * + * This callback is called when the window gains or loses focus. */ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cbfun); @@ -1329,6 +1351,8 @@ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cb * @param[in] cbfun The new callback, or @c NULL to remove the currently set * callback. * @ingroup window + * + * This callback is called when the window is iconified or restored. */ GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow window, GLFWwindowiconifyfun cbfun); @@ -1427,7 +1451,7 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow window, double* xoffset, double* yof * set callback. * @ingroup input * - * @note The key callback deals with physical keys, with @link keys tokens + * @remarks The key callback deals with physical keys, with @link keys tokens * @endlink named after their use on the standard US keyboard layout. If you * want to input text, use the Unicode character callback instead. */ @@ -1438,8 +1462,8 @@ GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun); * the currently set callback. * @ingroup input * - * @note The Unicode character callback is for text input. If you want to know - * whether a specific key was pressed or released, use the key callback. + * @remarks The Unicode character callback is for text input. If you want to + * know whether a specific key was pressed or released, use the key callback. */ GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun); @@ -1454,6 +1478,9 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cb * @param[in] cbfun The new cursor position callback, or @c NULL to remove the * currently set callback. * @ingroup input + * + * @remarks The position is relative to the upper-left corner of the client + * area of the window. */ GLFWAPI void glfwSetCursorPosCallback(GLFWwindow window, GLFWcursorposfun cbfun); @@ -1506,6 +1533,8 @@ GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbutto * @param[in] string A UTF-8 encoded string. * @ingroup clipboard * + * @note This function may only be called from the main thread. + * * @sa glfwGetClipboardString */ GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* string); @@ -1516,6 +1545,8 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* string); * if that format was unavailable. * @ingroup clipboard * + * @note This function may only be called from the main thread. + * * @note The returned string is valid only until the next call to @ref * glfwGetClipboardString or @ref glfwSetClipboardString. * From 69a900592e0ce28278ee3c8224838b7e499af698 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 16:10:00 +0100 Subject: [PATCH 70/81] Added explicit support for sRGB framebuffers. --- include/GL/glfw3.h | 7 +++++++ src/cocoa_window.m | 3 +++ src/internal.h | 2 ++ src/opengl.c | 6 ++++++ src/win32_opengl.c | 12 ++++++++++++ src/win32_platform.h | 1 + src/window.c | 4 ++++ src/x11_opengl.c | 8 ++++++++ src/x11_platform.h | 1 + 9 files changed, 44 insertions(+) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index b5735a96..1954a0c1 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -518,6 +518,10 @@ extern "C" { /*! @brief The number of samples used for default framebuffer multisampling. */ #define GLFW_FSAA_SAMPLES 0x0002100E +/*! @brief @c GL_TRUE if the framebuffer should be sRGB capable, or @c GL_FALSE + * otherwise. + */ +#define GLFW_SRGB_CAPABLE 0x0002100F /*! @brief The @link clients client API @endlink to create a context for. */ @@ -1020,6 +1024,9 @@ GLFWAPI void glfwDefaultWindowHints(void); * The @ref GLFW_FSAA_SAMPLES hint specifies the desired number of samples to * use for multisampling. * + * The @ref GLFW_SRGB_CAPABLE hint specifies whether the framebuffer should be + * sRGB capable. + * * The @ref GLFW_CLIENT_API hint specifies which client API to create the * context for. Possible values are @ref GLFW_OPENGL_API and @ref * GLFW_OPENGL_ES_API. diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 24ba6628..040277a7 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -835,6 +835,9 @@ static GLboolean createContext(_GLFWwindow* window, ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples); } + // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB + // frambuffer, so there's no need (and no way) to request it + ADD_ATTR(0); #undef ADD_ATTR diff --git a/src/internal.h b/src/internal.h index 2ef8f10c..d3084ee9 100644 --- a/src/internal.h +++ b/src/internal.h @@ -100,6 +100,7 @@ struct _GLFWhints GLboolean resizable; GLboolean visible; int samples; + GLboolean sRGB; int clientAPI; int glMajor; int glMinor; @@ -160,6 +161,7 @@ struct _GLFWfbconfig int auxBuffers; GLboolean stereo; int samples; + GLboolean sRGB; GLFWintptr platformID; }; diff --git a/src/opengl.c b/src/opengl.c index 538bcdfb..931296ce 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -217,6 +217,12 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired, extraDiff += (desired->samples - current->samples) * (desired->samples - current->samples); } + + if (desired->sRGB) + { + if (!current->sRGB) + extraDiff++; + } } // Figure out if the current one is better than the best one found so far diff --git a/src/win32_opengl.c b/src/win32_opengl.c index f1e911f3..80d7470e 100644 --- a/src/win32_opengl.c +++ b/src/win32_opengl.c @@ -72,6 +72,7 @@ static void initWGLExtensions(_GLFWwindow* window) // This needs to include every extension used below except for // WGL_ARB_extensions_string and WGL_EXT_extensions_string window->WGL.ARB_multisample = GL_FALSE; + window->WGL.ARB_framebuffer_sRGB = GL_FALSE; window->WGL.ARB_create_context = GL_FALSE; window->WGL.ARB_create_context_profile = GL_FALSE; window->WGL.EXT_create_context_es2_profile = GL_FALSE; @@ -92,6 +93,9 @@ static void initWGLExtensions(_GLFWwindow* window) if (_glfwPlatformExtensionSupported("WGL_ARB_multisample")) window->WGL.ARB_multisample = GL_TRUE; + if (_glfwPlatformExtensionSupported("WGL_ARB_framebuffer_sRGB")) + window->WGL.ARB_framebuffer_sRGB = GL_TRUE; + if (_glfwPlatformExtensionSupported("WGL_ARB_create_context")) { window->WGL.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) @@ -246,6 +250,11 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) f->samples = getPixelFormatAttrib(window, i, WGL_SAMPLES_ARB); else f->samples = 0; + + if (window->WGL.ARB_framebuffer_sRGB) + f->sRGB = getPixelFormatAttrib(window, i, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB); + else + f->sRGB = GL_FALSE; } else { @@ -293,6 +302,9 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) // PFD pixel formats do not support FSAA f->samples = 0; + + // PFD pixel formats do not support sRGB + f->sRGB = GL_FALSE; } f->platformID = i; diff --git a/src/win32_platform.h b/src/win32_platform.h index 217fc2cf..ccabf595 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -144,6 +144,7 @@ typedef struct _GLFWcontextWGL GLboolean EXT_swap_control; GLboolean ARB_multisample; GLboolean ARB_pixel_format; + GLboolean ARB_framebuffer_sRGB; GLboolean ARB_create_context; GLboolean ARB_create_context_profile; GLboolean EXT_create_context_es2_profile; diff --git a/src/window.c b/src/window.c index ac0fd02f..d4026465 100644 --- a/src/window.c +++ b/src/window.c @@ -237,6 +237,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, fbconfig.auxBuffers = Max(_glfwLibrary.hints.auxBuffers, 0); fbconfig.stereo = _glfwLibrary.hints.stereo ? GL_TRUE : GL_FALSE; fbconfig.samples = Max(_glfwLibrary.hints.samples, 0); + fbconfig.sRGB = _glfwLibrary.hints.sRGB ? GL_TRUE : GL_FALSE; // Set up desired window config wndconfig.mode = mode; @@ -446,6 +447,9 @@ GLFWAPI void glfwWindowHint(int target, int hint) case GLFW_FSAA_SAMPLES: _glfwLibrary.hints.samples = hint; break; + case GLFW_SRGB_CAPABLE: + _glfwLibrary.hints.sRGB = hint; + break; case GLFW_CLIENT_API: _glfwLibrary.hints.clientAPI = hint; break; diff --git a/src/x11_opengl.c b/src/x11_opengl.c index ad77805a..845a1980 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -190,6 +190,11 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) else f->samples = 0; + if (_glfwLibrary.GLX.ARB_framebuffer_sRGB) + f->sRGB = getFBConfigAttrib(window, fbconfigs[i], GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB); + else + f->sRGB = GL_FALSE; + f->platformID = (GLFWintptr) getFBConfigAttrib(window, fbconfigs[i], GLX_FBCONFIG_ID); (*found)++; @@ -527,6 +532,9 @@ int _glfwInitOpenGL(void) if (_glfwPlatformExtensionSupported("GLX_ARB_multisample")) _glfwLibrary.GLX.ARB_multisample = GL_TRUE; + if (_glfwPlatformExtensionSupported("GLX_ARB_framebuffer_sRGB")) + _glfwLibrary.GLX.ARB_framebuffer_sRGB = GL_TRUE; + if (_glfwPlatformExtensionSupported("GLX_ARB_create_context")) { _glfwLibrary.GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) diff --git a/src/x11_platform.h b/src/x11_platform.h index e577c22f..84a2aa85 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -272,6 +272,7 @@ typedef struct _GLFWlibraryGLX GLboolean EXT_swap_control; GLboolean MESA_swap_control; GLboolean ARB_multisample; + GLboolean ARB_framebuffer_sRGB; GLboolean ARB_create_context; GLboolean ARB_create_context_profile; GLboolean ARB_create_context_robustness; From 8e5b2239d3d8c04ba0f00ae0adcc499ac658e5ed Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 16:14:49 +0100 Subject: [PATCH 71/81] Updated changelog. --- readme.html | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.html b/readme.html index 1e629456..3ad596c9 100644 --- a/readme.html +++ b/readme.html @@ -279,6 +279,7 @@ version of GLFW.

  • Added glfwSetWindowIconifyCallback function and GLFWwindowiconifyfun type for receiving window iconification events
  • Added glfwGetClipboardString and glfwSetClipboardString functions for interacting with the system clipboard
  • Added glfwGetCurrentContext function for retrieving the window whose OpenGL context is current
  • +
  • Added GLFW_SRGB_CAPABLE for requesting sRGB capable framebuffers
  • Added GLFW_CLIENT_API, GLFW_OPENGL_API and GLFW_OPENGL_ES_API for selecting client API
  • Added GLFW_OPENGL_ROBUSTNESS window hint and associated strategy tokens for GL_ARB_robustness support
  • Added GLFW_OPENGL_REVISION window parameter to make up for removal of glfwGetGLVersion
  • From 280782a2a5d66cccb2597e407015ec753afa71f2 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 16:29:56 +0100 Subject: [PATCH 72/81] Added explicit non-support for sRGB on EGL. --- src/egl_context.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/egl_context.c b/src/egl_context.c index cf8ad77a..3c164520 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -157,6 +157,10 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, f->samples = getConfigAttrib(configs[i], EGL_SAMPLES); + // NOTE: There does not appear to be any way to request sRGB + // framebuffers for OpenGL or GLES contexts; only for OpenVG ones + f->sRGB = GL_FALSE; + f->platformID = (GLFWintptr) getConfigAttrib(configs[i], EGL_CONFIG_ID); (*found)++; From 7be9e87ef18f9f7b91b72cfdffdf1de0de75fbb0 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 16:45:03 +0100 Subject: [PATCH 73/81] Removed bad use of glfwGetCurrentContext. --- tests/joysticks.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/joysticks.c b/tests/joysticks.c index c1abb5f8..9b03a3b7 100644 --- a/tests/joysticks.c +++ b/tests/joysticks.c @@ -94,11 +94,11 @@ static void draw_joystick(Joystick* j, int x, int y, int width, int height) } } -static void draw_joysticks(void) +static void draw_joysticks(GLFWwindow window) { int i, width, height; - glfwGetWindowSize(glfwGetCurrentContext(), &width, &height); + glfwGetWindowSize(window, &width, &height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -205,7 +205,7 @@ int main(void) glClear(GL_COLOR_BUFFER_BIT); refresh_joysticks(); - draw_joysticks(); + draw_joysticks(window); glfwSwapBuffers(window); glfwPollEvents(); From 3a773342e804c744f7fa9c5dd21c36944ee936c8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 16:52:02 +0100 Subject: [PATCH 74/81] Renamed struct member to match other platforms. --- src/cocoa_joystick.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 3979a2f1..e7d5cc81 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -68,7 +68,7 @@ typedef struct typedef struct { int present; - char product[256]; + char name[256]; IOHIDDeviceInterface** interface; @@ -443,8 +443,8 @@ void _glfwInitJoysticks(void) if (refCF) { CFStringGetCString(refCF, - joystick->product, - sizeof(joystick->product), + joystick->name, + sizeof(joystick->name), kCFStringEncodingUTF8); } @@ -632,6 +632,6 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, const char* _glfwPlatformGetJoystickName(int joy) { - return _glfwJoysticks[joy].product; + return _glfwJoysticks[joy].name; } From 0bac5795061cdac2d5e668ab97bec68bb0a169c5 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 16:53:28 +0100 Subject: [PATCH 75/81] Formatting. --- src/joystick.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/joystick.c b/src/joystick.c index 59107e31..9c20303d 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -136,13 +136,13 @@ GLFWAPI const char* glfwGetJoystickName(int joy) if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return 0; + return NULL; } if (joy < 0 || joy > GLFW_JOYSTICK_LAST) { _glfwSetError(GLFW_INVALID_ENUM, NULL); - return 0; + return NULL; } return _glfwPlatformGetJoystickName(joy); From 7d9b5c012702a53c55b40f89a950fb85eeb82a88 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 16:55:09 +0100 Subject: [PATCH 76/81] Added documentation for glfwGetJoystickName. --- include/GL/glfw3.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index ade6d9e5..966234d7 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -1534,6 +1534,13 @@ GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes); * @ingroup input */ GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); + +/*! @brief Returns the name of the specified joystick. + * @param[in] joy The joystick to query. + * @return The UTF-8 encoded name of the joystick, or @c NULL if the joystick + * is not present. + * @ingroup input + */ GLFWAPI const char* glfwGetJoystickName(int joy); /*! @brief Sets the clipboard to the specified string. From 20c891f56691799094095d177af07dbfa3e948c4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 17:10:41 +0100 Subject: [PATCH 77/81] Updated changelog. --- readme.html | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.html b/readme.html index 3ad596c9..8e155e79 100644 --- a/readme.html +++ b/readme.html @@ -278,6 +278,7 @@ version of GLFW.

  • Added glfwSetWindowFocusCallback function and GLFWwindowfocusfun type for receiving window focus events
  • Added glfwSetWindowIconifyCallback function and GLFWwindowiconifyfun type for receiving window iconification events
  • Added glfwGetClipboardString and glfwSetClipboardString functions for interacting with the system clipboard
  • +
  • Added glfwGetJoystickName for retrieving the name of a joystick
  • Added glfwGetCurrentContext function for retrieving the window whose OpenGL context is current
  • Added GLFW_SRGB_CAPABLE for requesting sRGB capable framebuffers
  • Added GLFW_CLIENT_API, GLFW_OPENGL_API and GLFW_OPENGL_ES_API for selecting client API
  • From d4a08b10fdf162e34e3e42b95cfbfab3327bf3b8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 17:13:41 +0100 Subject: [PATCH 78/81] Documented joystick name caveat. --- include/GL/glfw3.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 966234d7..23fcefa7 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -1540,6 +1540,9 @@ GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbutto * @return The UTF-8 encoded name of the joystick, or @c NULL if the joystick * is not present. * @ingroup input + * + * @note The returned string is valid only until the next call to @ref + * glfwGetJoystickName. */ GLFWAPI const char* glfwGetJoystickName(int joy); From 5da8ed250a12875cb0483e0958a84c955f8e723b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 19:01:20 +0100 Subject: [PATCH 79/81] Cleanup of backend option strings. --- CMakeLists.txt | 5 ++++- src/cocoa_platform.h | 2 ++ src/internal.h | 2 +- src/win32_platform.h | 2 ++ src/x11_platform.h | 2 ++ 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5797c99f..08542a60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,10 @@ option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON) option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) option(GLFW_NATIVE_API "Build the GLFW native API" OFF) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) -option(GLFW_USE_EGL "Build for EGL and OpenGL ES platform (Currently only X11)" OFF) + +if (NOT APPLE) + option(GLFW_USE_EGL "Use EGL for context creation" OFF) +endif() if (GLFW_USE_EGL) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake/modules) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 57a27487..21589a69 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -42,6 +42,8 @@ typedef void* id; #if defined(_GLFW_NSGL) #include "nsgl_platform.h" +#else + #error "No supported context creation API selected" #endif #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS diff --git a/src/internal.h b/src/internal.h index fa87e699..d2619e2e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -72,7 +72,7 @@ typedef struct _GLFWlibrary _GLFWlibrary; #elif defined(_GLFW_X11) #include "x11_platform.h" #else - #error "No supported platform selected" + #error "No supported window creation API selected" #endif diff --git a/src/win32_platform.h b/src/win32_platform.h index f5e94bb5..30d55347 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -111,6 +111,8 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); #define _GLFW_EGL_NATIVE_WINDOW window->Win32.handle #define _GLFW_EGL_NATIVE_DISPLAY NULL #include "egl_platform.h" +#else + #error "No supported context creation API selected" #endif #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 diff --git a/src/x11_platform.h b/src/x11_platform.h index 990487fc..87c46d85 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -61,6 +61,8 @@ #define _GLFW_EGL_NATIVE_WINDOW window->X11.handle #define _GLFW_EGL_NATIVE_DISPLAY _glfwLibrary.X11.display #include "egl_platform.h" +#else + #error "No supported context creation API selected" #endif #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 From 47c11b4ea665786993859720896fb33a5676adb1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 19:02:32 +0100 Subject: [PATCH 80/81] Tweaked comment. --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f5be33b..94fe11e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,7 +78,8 @@ if (BUILD_SHARED_LIBS) set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") endif() elseif (_GLFW_COCOA) - # Append -fno-common to the compile flags to work around a bug in the Apple GCC + # Append -fno-common to the compile flags to work around a bug in + # Apple's GCC get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS) if (NOT glfw_CFLAGS) set(glfw_CFLAGS "") From ccdb776cc34cc5bb368acc2c455ef4cb45e400ae Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 2 Dec 2012 19:13:01 +0100 Subject: [PATCH 81/81] Cleanup of configuration variable use. --- src/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 94fe11e2..3d11ef3b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,7 +53,7 @@ elseif (_GLFW_X11) list(APPEND glfw_SOURCES ${common_SOURCES} glx_context.c) endif() -if (_GLFW_NSGL) +if (APPLE) # For some reason, CMake doesn't know about .m set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) endif() @@ -68,7 +68,7 @@ if (BUILD_SHARED_LIBS) set_target_properties(glfw PROPERTIES SOVERSION ${GLFW_VERSION_MAJOR}) endif() - if (_GLFW_WIN32) + if (WIN32) # The GLFW DLL needs a special compile-time macro and import library name set_target_properties(glfw PROPERTIES PREFIX "" IMPORT_PREFIX "") @@ -77,7 +77,7 @@ if (BUILD_SHARED_LIBS) else() set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") endif() - elseif (_GLFW_COCOA) + elseif (APPLE) # Append -fno-common to the compile flags to work around a bug in # Apple's GCC get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS)