From 0517a824675d55e8126b2de2fd46e1dea59c80c1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 15 Jan 2013 04:26:11 +0100 Subject: [PATCH] Added support for GLESv1_CM and GLESv2 client libraries. --- CMake/modules/FindGLESv1.cmake | 16 ++++++++++ CMake/modules/FindGLESv2.cmake | 16 ++++++++++ CMakeLists.txt | 58 +++++++++++++++++++++++++++------- src/config.h.in | 7 ++++ src/context.c | 4 +++ src/internal.h | 18 ++++++++--- 6 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 CMake/modules/FindGLESv1.cmake create mode 100644 CMake/modules/FindGLESv2.cmake diff --git a/CMake/modules/FindGLESv1.cmake b/CMake/modules/FindGLESv1.cmake new file mode 100644 index 00000000..3c779295 --- /dev/null +++ b/CMake/modules/FindGLESv1.cmake @@ -0,0 +1,16 @@ +# Find GLESv1 +# +# GLESv1_INCLUDE_DIR +# GLESv1_LIBRARY +# GLESv1_FOUND + +find_path(GLESv1_INCLUDE_DIR NAMES GLES/gl.h) + +set(GLESv1_NAMES ${GLESv1_NAMES} GLESv1_CM) +find_library(GLESv1_LIBRARY NAMES ${GLESv1_NAMES}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GLESv1 DEFAULT_MSG GLESv1_LIBRARY GLESv1_INCLUDE_DIR) + +mark_as_advanced(GLESv1_INCLUDE_DIR GLESv1_LIBRARY) + diff --git a/CMake/modules/FindGLESv2.cmake b/CMake/modules/FindGLESv2.cmake new file mode 100644 index 00000000..0a2f810a --- /dev/null +++ b/CMake/modules/FindGLESv2.cmake @@ -0,0 +1,16 @@ +# Find GLESv2 +# +# GLESv2_INCLUDE_DIR +# GLESv2_LIBRARY +# GLESv2_FOUND + +find_path(GLESv2_INCLUDE_DIR NAMES GLES2/gl2.h) + +set(GLESv2_NAMES ${GLESv2_NAMES} GLESv2) +find_library(GLESv2_LIBRARY NAMES ${GLESv2_NAMES}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GLESv2 DEFAULT_MSG GLESv2_LIBRARY GLESv2_INCLUDE_DIR) + +mark_as_advanced(GLESv2_INCLUDE_DIR GLESv2_LIBRARY) + diff --git a/CMakeLists.txt b/CMakeLists.txt index ba98d78a..778d9dbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,19 @@ if (NOT APPLE) endif() if (GLFW_USE_EGL) + set(GLFW_CLIENT_LIBRARY "opengl" CACHE STRING + "The client library to use; one of: opengl, glesv1 or glesv2") + + if (${GLFW_CLIENT_LIBRARY} STREQUAL "opengl") + set(_GLFW_USE_OPENGL 1) + elseif (${GLFW_CLIENT_LIBRARY} STREQUAL "glesv1") + set(_GLFW_USE_GLESV1 1) + elseif (${GLFW_CLIENT_LIBRARY} STREQUAL "glesv2") + set(_GLFW_USE_GLESV2 1) + else() + message(FATAL_ERROR "Unsupported client library") + endif() + set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake/modules) find_package(EGL REQUIRED) @@ -27,7 +40,15 @@ if (GLFW_USE_EGL) set(GLFW_BUILD_TESTS OFF) message(STATUS "NOTE: Examples and tests are disabled for EGL") else() + set(_GLFW_USE_OPENGL 1) +endif() + +if (_GLFW_USE_OPENGL) find_package(OpenGL REQUIRED) +elseif (_GLFW_USE_GLESV1) + find_package(GLESv1 REQUIRED) +elseif (_GLFW_USE_GLESV2) + find_package(GLESv2 REQUIRED) endif() find_package(Threads REQUIRED) @@ -86,14 +107,10 @@ else() endif() #-------------------------------------------------------------------- -# Set up GLFW for Win32 and WGL on Windows +# Set up GLFW for Win32 #-------------------------------------------------------------------- if (_GLFW_WIN32) - # Set up library and include paths - list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) - list(APPEND glfw_LIBRARIES ${OPENGL_gl_LIBRARY}) - if (MSVC) option(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC runtime library DLL" ON) @@ -116,6 +133,14 @@ if (_GLFW_WIN32) endif() endif() +#-------------------------------------------------------------------- +# Set up GLFW for WGL +#-------------------------------------------------------------------- +if (_GLFW_WGL) + list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) + list(APPEND glfw_LIBRARIES ${OPENGL_gl_LIBRARY}) +endif() + #-------------------------------------------------------------------- # Set up GLFW for Xlib and GLX or EGL on Unix-like systems with X Windows #-------------------------------------------------------------------- @@ -123,8 +148,7 @@ if (_GLFW_X11) find_package(X11 REQUIRED) - set(GLFW_PKG_LIBS "") - set(GLFW_PKG_DEPS "x11") + set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} x11") # Set up library and include paths list(APPEND glfw_INCLUDE_DIRS ${X11_X11_INCLUDE_PATH}) @@ -183,7 +207,6 @@ endif() #-------------------------------------------------------------------- if (_GLFW_GLX) - # Set up library and include paths list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) list(APPEND glfw_LIBRARIES ${OPENGL_gl_LIBRARY}) @@ -233,11 +256,10 @@ if (_GLFW_GLX) endif() #-------------------------------------------------------------------- -# EGL Context +# Use EGL for context creation #-------------------------------------------------------------------- if (_GLFW_EGL) - # Set up library and include paths list(APPEND glfw_INCLUDE_DIRS ${EGL_INCLUDE_DIR}) list(APPEND glfw_LIBRARIES ${EGL_LIBRARY}) @@ -247,10 +269,24 @@ if (_GLFW_EGL) set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} egl") endif() + if (_GLFW_USE_OPENGL) + list(APPEND glfw_LIBRARIES ${OPENGL_gl_LIBRARY}) + list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) + set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} gl") + elseif (_GLFW_USE_GLESV1) + list(APPEND glfw_LIBRARIES ${GLESv1_LIBRARY}) + list(APPEND glfw_INCLUDE_DIRS ${GLESv1_INCLUDE_DIR}) + set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} glesv1_cm") + elseif (_GLFW_USE_GLESV2) + list(APPEND glfw_LIBRARIES ${GLESv2_LIBRARY}) + list(APPEND glfw_INCLUDE_DIRS ${GLESv2_INCLUDE_DIR}) + set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} glesv2") + endif() + endif() #-------------------------------------------------------------------- -# Set up GLFW for Cocoa and NSOpenGL on Mac OS X +# Use Cocoa for window creation and NSOpenGL for context creation #-------------------------------------------------------------------- if (_GLFW_COCOA AND _GLFW_NSGL) diff --git a/src/config.h.in b/src/config.h.in index b289520b..760ace43 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -64,6 +64,13 @@ // Define this to 1 if glXGetProcAddressEXT is available #cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT +// Define this to 1 if using OpenGL as the client library +#cmakedefine _GLFW_USE_OPENGL +// Define this to 1 if using OpenGL ES 1.1 as the client library +#cmakedefine _GLFW_USE_GLESV1 +// Define this to 1 if using OpenGL ES 2.0 as the client library +#cmakedefine _GLFW_USE_GLESV2 + // The GLFW version as used by glfwGetVersionString #define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@" diff --git a/src/context.c b/src/context.c index 7c3d0780..d8f1a46f 100644 --- a/src/context.c +++ b/src/context.c @@ -390,6 +390,7 @@ GLboolean _glfwRefreshContextParams(void) return GL_FALSE; } +#if defined(_GLFW_USE_OPENGL) if (window->glMajor > 2) { // OpenGL 3.0+ uses a different function for extension string retrieval @@ -472,6 +473,7 @@ GLboolean _glfwRefreshContextParams(void) window->glRobustness = GLFW_NO_RESET_NOTIFICATION; } } +#endif // _GLFW_USE_OPENGL return GL_TRUE; } @@ -659,6 +661,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension) return GL_TRUE; } } +#if defined(_GLFW_USE_OPENGL) else { int i; @@ -677,6 +680,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension) } } } +#endif // _GLFW_USE_OPENGL // Check if extension is in the platform-specific string return _glfwPlatformExtensionSupported(extension); diff --git a/src/internal.h b/src/internal.h index 0cc3a6bd..a69b1ee0 100644 --- a/src/internal.h +++ b/src/internal.h @@ -81,16 +81,24 @@ typedef struct _GLFWmonitor _GLFWmonitor; #include "config.h" +#if defined(_GLFW_USE_GLESV1) + #define GLFW_INCLUDE_ES1 +#elif defined(_GLFW_USE_GLESV2) + #define GLFW_INCLUDE_ES2 +#endif + // Disable the inclusion of the platform glext.h by gl.h to allow proper // inclusion of our own, newer glext.h below #define GL_GLEXT_LEGACY #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_USE_OPENGL) + // This path may need to be changed if you build GLFW using your own setup + // GLFW comes with its own copy of glext.h since it uses fairly new extensions + // and not all development environments come with an up-to-date version + #include "../support/GL/glext.h" +#endif #if defined(_GLFW_COCOA) #include "cocoa_platform.h" @@ -227,7 +235,9 @@ struct _GLFWwindow GLboolean glForward, glDebug; int glProfile; int glRobustness; +#if defined(_GLFW_USE_OPENGL) PFNGLGETSTRINGIPROC GetStringi; +#endif GLFWwindowposfun windowPosCallback; GLFWwindowsizefun windowSizeCallback;