Add a FILAMENT_SUPPORTS_OPENGL CMake option (#3966)

This commit is contained in:
Ben Doherty
2021-05-15 14:40:06 -07:00
committed by GitHub
parent c1347e55cb
commit bd8ea711fd
4 changed files with 49 additions and 32 deletions

View File

@@ -84,6 +84,7 @@ The following CMake options are boolean options specific to Filament:
- `FILAMENT_ENABLE_JAVA`: Compile Java projects: requires a JDK and the JAVA_HOME env var
- `FILAMENT_ENABLE_LTO`: Enable link-time optimizations if supported by the compiler
- `FILAMENT_BUILD_FILAMAT`: Build filamat and JNI buildings
- `FILAMENT_SUPPORTS_OPENGL`: Include the OpenGL backend
- `FILAMENT_SUPPORTS_METAL`: Include the Metal backend
- `FILAMENT_SUPPORTS_VULKAN`: Include the Vulkan backend
- `FILAMENT_INSTALL_BACKEND_TEST`: Install the backend test library so it can be consumed on iOS

View File

@@ -369,6 +369,12 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebIn
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTNT_DEV")
endif()
# By default, build with support for OpenGL on all platforms.
option(FILAMENT_SUPPORTS_OPENGL "Include the OpenGL backend" ON)
if (FILAMENT_SUPPORTS_OPENGL)
add_definitions(-DFILAMENT_SUPPORTS_OPENGL)
endif()
# By default, build with Vulkan support on desktop platforms, although clients must request to use
# it at run time.
if (WIN32 OR WEBGL OR IOS)
@@ -424,9 +430,9 @@ endif()
set(MATC_API_FLAGS )
# TODO: Add a flag to build Filament without support for OpenGL.
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a opengl)
if (FILAMENT_SUPPORTS_OPENGL)
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a opengl)
endif()
if (FILAMENT_SUPPORTS_VULKAN)
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a vulkan)
endif()
@@ -643,7 +649,9 @@ if (WEBGL)
endif()
if (IS_HOST_PLATFORM)
add_subdirectory(${LIBRARIES}/bluegl)
if (FILAMENT_SUPPORTS_OPENGL)
add_subdirectory(${LIBRARIES}/bluegl)
endif()
add_subdirectory(${LIBRARIES}/filamentapp)
add_subdirectory(${LIBRARIES}/imageio)

View File

@@ -55,7 +55,7 @@ set(PRIVATE_HDRS
# OpenGL / OpenGL ES Sources
# ==================================================================================================
if (NOT FILAMENT_USE_EXTERNAL_GLES3 AND NOT FILAMENT_USE_SWIFTSHADER)
if (FILAMENT_SUPPORTS_OPENGL AND NOT FILAMENT_USE_EXTERNAL_GLES3 AND NOT FILAMENT_USE_SWIFTSHADER)
list(APPEND SRCS
src/opengl/gl_headers.cpp
src/opengl/gl_headers.h
@@ -255,7 +255,10 @@ add_library(vkshaders STATIC ${DUMMY_SRC} ${RESGEN_SOURCE})
# ==================================================================================================
if (ANDROID)
target_link_libraries(${TARGET} PUBLIC GLESv3 EGL android)
if (FILAMENT_SUPPORTS_OPENGL)
target_link_libraries(${TARGET} PUBLIC GLESv3 EGL)
endif()
target_link_libraries(${TARGET} PUBLIC android)
endif()
if (FILAMENT_USE_SWIFTSHADER)
@@ -270,7 +273,7 @@ target_link_libraries(${TARGET} PUBLIC math)
target_link_libraries(${TARGET} PUBLIC utils)
# Android, iOS, and WebGL do not use bluegl.
if(NOT IOS AND NOT ANDROID AND NOT WEBGL)
if(FILAMENT_SUPPORTS_OPENGL AND NOT IOS AND NOT ANDROID AND NOT WEBGL)
target_link_libraries(${TARGET} PRIVATE bluegl)
endif()

View File

@@ -20,44 +20,44 @@
#include <utils/debug.h>
#if defined(ANDROID)
#ifndef FILAMENT_USE_EXTERNAL_GLES3
#if defined(FILAMENT_SUPPORTS_OPENGL) && !defined(FILAMENT_USE_EXTERNAL_GLES3)
#include "opengl/PlatformEGLAndroid.h"
#endif
#if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN)
#if defined(FILAMENT_DRIVER_SUPPORTS_VULKAN)
#include "vulkan/PlatformVkAndroid.h"
#endif
#elif defined(IOS)
#ifndef FILAMENT_USE_EXTERNAL_GLES3
#if defined(FILAMENT_SUPPORTS_OPENGL) && !defined(FILAMENT_USE_EXTERNAL_GLES3)
#include "opengl/PlatformCocoaTouchGL.h"
#endif
#if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN)
#if defined(FILAMENT_DRIVER_SUPPORTS_VULKAN)
#include "vulkan/PlatformVkCocoaTouch.h"
#endif
#elif defined(__APPLE__)
#if !defined(FILAMENT_USE_EXTERNAL_GLES3) && !defined(FILAMENT_USE_SWIFTSHADER)
#if defined(FILAMENT_SUPPORTS_OPENGL) && !defined(FILAMENT_USE_EXTERNAL_GLES3) && !defined(FILAMENT_USE_SWIFTSHADER)
#include "opengl/PlatformCocoaGL.h"
#endif
#if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN)
#if defined(FILAMENT_DRIVER_SUPPORTS_VULKAN)
#include "vulkan/PlatformVkCocoa.h"
#endif
#elif defined(__linux__)
#if !defined(FILAMENT_USE_EXTERNAL_GLES3) && !defined(FILAMENT_USE_SWIFTSHADER)
#if defined(FILAMENT_SUPPORTS_OPENGL) && !defined(FILAMENT_USE_EXTERNAL_GLES3) && !defined(FILAMENT_USE_SWIFTSHADER)
#include "opengl/PlatformGLX.h"
#endif
#if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN)
#include "vulkan/PlatformVkLinux.h"
#endif
#elif defined(WIN32)
#if !defined(FILAMENT_USE_EXTERNAL_GLES3) && !defined(FILAMENT_USE_SWIFTSHADER)
#if defined(FILAMENT_SUPPORTS_OPENGL) && !defined(FILAMENT_USE_EXTERNAL_GLES3) && !defined(FILAMENT_USE_SWIFTSHADER)
#include "opengl/PlatformWGL.h"
#endif
#if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN)
#if defined(FILAMENT_DRIVER_SUPPORTS_VULKAN)
#include "vulkan/PlatformVkWindows.h"
#endif
#elif defined(__EMSCRIPTEN__)
#include "opengl/PlatformWebGL.h"
#else
#ifndef FILAMENT_USE_EXTERNAL_GLES3
#if defined(FILAMENT_SUPPORTS_OPENGL) && !defined(FILAMENT_USE_EXTERNAL_GLES3)
#include "opengl/PlatformDummyGL.h"
#endif
#endif
@@ -112,22 +112,27 @@ DefaultPlatform* DefaultPlatform::create(Backend* backend) noexcept {
return nullptr;
#endif
}
#if defined(FILAMENT_USE_EXTERNAL_GLES3) || defined(FILAMENT_USE_SWIFTSHADER)
return nullptr;
#elif defined(ANDROID)
return new PlatformEGLAndroid();
#elif defined(IOS)
return new PlatformCocoaTouchGL();
#elif defined(__APPLE__)
return new PlatformCocoaGL();
#elif defined(__linux__)
return new PlatformGLX();
#elif defined(WIN32)
return new PlatformWGL();
#elif defined(__EMSCRIPTEN__)
return new PlatformWebGL();
assert_invariant(*backend == Backend::OPENGL);
#if defined(FILAMENT_SUPPORTS_OPENGL)
#if defined(FILAMENT_USE_EXTERNAL_GLES3) || defined(FILAMENT_USE_SWIFTSHADER)
return nullptr;
#elif defined(ANDROID)
return new PlatformEGLAndroid();
#elif defined(IOS)
return new PlatformCocoaTouchGL();
#elif defined(__APPLE__)
return new PlatformCocoaGL();
#elif defined(__linux__)
return new PlatformGLX();
#elif defined(WIN32)
return new PlatformWGL();
#elif defined(__EMSCRIPTEN__)
return new PlatformWebGL();
#else
return new PlatformDummyGL();
#endif
#else
return new PlatformDummyGL();
return nullptr;
#endif
}