From c1ebe11f3a3cd6972a9ea153c2ff627f4364dfbb Mon Sep 17 00:00:00 2001 From: Adrian Perez Date: Mon, 20 Aug 2018 12:26:53 -0700 Subject: [PATCH] Add option USE_EXTERNAL_GLES3 (#116) Causes gl_headers to use GLES, even on desktop. Causes all ContextManagers to be elided; users are expected to provide their own. --- CMakeLists.txt | 6 ++++++ filament/CMakeLists.txt | 4 +++- filament/src/driver/ExternalContext.cpp | 24 +++++++++++++++++------ filament/src/driver/opengl/gl_headers.cpp | 2 +- filament/src/driver/opengl/gl_headers.h | 2 +- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9ba425bce..387d014b79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,8 @@ project(TNT) option(ENABLE_JAVA "Compile Java projects, requires a JDK and the JAVA_HOME env var" ON) +option(USE_EXTERNAL_GLES3 "Experimental: Compile filament against OpenGL ES 3" OFF) + # ================================================================================================== # OS specific # ================================================================================================== @@ -94,6 +96,10 @@ endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD} -fstrict-aliasing -Wno-unknown-pragmas -Wno-unused-function") +if (USE_EXTERNAL_GLES3) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_EXTERNAL_GLES3") +endif() + if (WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_USE_MATH_DEFINES=1") endif() diff --git a/filament/CMakeLists.txt b/filament/CMakeLists.txt index 11775be079..966d821eed 100644 --- a/filament/CMakeLists.txt +++ b/filament/CMakeLists.txt @@ -162,7 +162,9 @@ endif() # OS specific # ================================================================================================== # Here set the architecture specific sources -if (ANDROID) +if (USE_EXTERNAL_GLES3) + # Experimental feature; clients provide their own Context Manager. +elseif (ANDROID) list(APPEND SRCS src/driver/opengl/ContextManagerEGL.cpp) elseif (APPLE) list(APPEND SRCS src/driver/opengl/ContextManagerCocoa.mm) diff --git a/filament/src/driver/ExternalContext.cpp b/filament/src/driver/ExternalContext.cpp index 56c2cef971..a9029c4ef4 100644 --- a/filament/src/driver/ExternalContext.cpp +++ b/filament/src/driver/ExternalContext.cpp @@ -17,27 +17,37 @@ #include #if defined(ANDROID) - #include "driver/opengl/ContextManagerEGL.h" + #ifndef USE_EXTERNAL_GLES3 + #include "driver/opengl/ContextManagerEGL.h" + #endif #if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN) #include "driver/vulkan/ContextManagerVkAndroid.h" #endif #elif defined(__APPLE__) - #include "driver/opengl/ContextManagerCocoa.h" + #ifndef USE_EXTERNAL_GLES3 + #include "driver/opengl/ContextManagerCocoa.h" + #endif #if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN) #include "driver/vulkan/ContextManagerVkCocoa.h" #endif #elif defined(__linux__) - #include "driver/opengl/ContextManagerGLX.h" + #ifndef USE_EXTERNAL_GLES3 + #include "driver/opengl/ContextManagerGLX.h" + #endif #if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN) #include "driver/vulkan/ContextManagerVkLinux.h" #endif #elif defined(WIN32) - #include "driver/opengl/ContextManagerWGL.h" + #ifndef USE_EXTERNAL_GLES3 + #include "driver/opengl/ContextManagerWGL.h" + #endif #if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN) #include "driver/vulkan/ContextManagerVkWindows.h" #endif #else - #include "driver/opengl/ContextManagerDummy.h" + #ifndef USE_EXTERNAL_GLES3 + #include "driver/opengl/ContextManagerDummy.h" + #endif #endif namespace filament { @@ -72,7 +82,9 @@ ExternalContext* ExternalContext::create(Backend* backend) noexcept { return nullptr; #endif } - #if defined(ANDROID) + #if defined(USE_EXTERNAL_GLES3) + return nullptr; + #elif defined(ANDROID) return new ContextManagerEGL(); #elif defined(__APPLE__) return new ContextManagerCocoa(); diff --git a/filament/src/driver/opengl/gl_headers.cpp b/filament/src/driver/opengl/gl_headers.cpp index 409a21bca2..1200cbd9dd 100644 --- a/filament/src/driver/opengl/gl_headers.cpp +++ b/filament/src/driver/opengl/gl_headers.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#ifdef ANDROID +#if defined(ANDROID) || defined(USE_EXTERNAL_GLES3) #include #include diff --git a/filament/src/driver/opengl/gl_headers.h b/filament/src/driver/opengl/gl_headers.h index bfb6eb88fe..e30ae40280 100644 --- a/filament/src/driver/opengl/gl_headers.h +++ b/filament/src/driver/opengl/gl_headers.h @@ -17,7 +17,7 @@ #ifndef TNT_FILAMENT_DRIVER_GL_HEADERS_H #define TNT_FILAMENT_DRIVER_GL_HEADERS_H -#ifdef ANDROID +#if defined(ANDROID) || defined(USE_EXTERNAL_GLES3) #include #include