diff --git a/CMakeLists.txt b/CMakeLists.txt index 3453e68036d..113ec61655a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -640,18 +640,19 @@ if(UNIX AND NOT APPLE) endif() -# OpenGL - -option(WITH_OPENGL "When off limits visibility of the opengl headers to just bf_gpu and gawain (temporary option for development purposes)" ON) +# GPU Module option(WITH_GPU_BUILDTIME_SHADER_BUILDER "Shader builder is a developer option enabling linting on GLSL during compilation" OFF) option(WITH_RENDERDOC "Use Renderdoc API to capture frames" OFF) mark_as_advanced( - WITH_OPENGL WITH_GPU_BUILDTIME_SHADER_BUILDER WITH_RENDERDOC ) +# OpenGL +option(WITH_OPENGL_BACKEND "Enable OpenGL support as graphic backend" ON) +mark_as_advanced(WITH_OPENGL_BACKEND) + # Vulkan option(WITH_VULKAN_BACKEND "Enable Vulkan as graphics backend (only for development)" OFF) option(WITH_VULKAN_GUARDEDALLOC "Use guardedalloc for host allocations done inside Vulkan (development option)" OFF) @@ -661,7 +662,6 @@ mark_as_advanced( ) # Metal - if(APPLE) option(WITH_METAL_BACKEND "Use Metal for graphics instead of (or as well as) OpenGL on macOS." ON) mark_as_advanced(WITH_METAL_BACKEND) @@ -1249,14 +1249,6 @@ if(WITH_OPENVDB) list(APPEND OPENVDB_LIBRARIES ${BOOST_LIBRARIES} ${TBB_LIBRARIES}) endif() - -# ----------------------------------------------------------------------------- -# Configure OpenGL - -if(WITH_OPENGL) - add_definitions(-DWITH_OPENGL) -endif() - # ----------------------------------------------------------------------------- # Configure Metal diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt index f8706f88ea3..ae9e9d2d021 100644 --- a/intern/ghost/CMakeLists.txt +++ b/intern/ghost/CMakeLists.txt @@ -77,6 +77,10 @@ set(LIB PRIVATE bf::dna ) +if(WITH_OPENGL_BACKEND) + add_definitions(-DWITH_OPENGL_BACKEND) +endif() + if(WITH_VULKAN_BACKEND) list(APPEND SRC intern/GHOST_ContextVK.cc diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h index c81f7147a27..0bd7c72749a 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -193,11 +193,13 @@ typedef enum { GHOST_kWindowOrderTop = 0, GHOST_kWindowOrderBottom } GHOST_TWind typedef enum { GHOST_kDrawingContextTypeNone = 0, +#if defined(WITH_OPENGL_BACKEND) GHOST_kDrawingContextTypeOpenGL, +#endif #ifdef WIN32 GHOST_kDrawingContextTypeD3D, #endif -#ifdef __APPLE__ +#if defined(__APPLE__) && defined(WITH_METAL_BACKEND) GHOST_kDrawingContextTypeMetal, #endif #ifdef WITH_VULKAN_BACKEND diff --git a/intern/ghost/intern/GHOST_ContextCGL.mm b/intern/ghost/intern/GHOST_ContextCGL.mm index effde93fa81..2a4e6eb6d47 100644 --- a/intern/ghost/intern/GHOST_ContextCGL.mm +++ b/intern/ghost/intern/GHOST_ContextCGL.mm @@ -108,7 +108,7 @@ GHOST_ContextCGL::~GHOST_ContextCGL() metalFree(); if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND if (m_openGLContext != nil) { if (m_openGLContext == [NSOpenGLContext currentContext]) { [NSOpenGLContext clearCurrentContext]; @@ -145,7 +145,7 @@ GHOST_TSuccess GHOST_ContextCGL::swapBuffers() GHOST_TSuccess return_value = GHOST_kFailure; if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND if (m_openGLContext != nil) { if (m_metalView) { metalSwapBuffers(); @@ -175,7 +175,7 @@ GHOST_TSuccess GHOST_ContextCGL::setSwapInterval(int interval) { if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND if (m_openGLContext != nil) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [m_openGLContext setValues:&interval forParameter:NSOpenGLCPSwapInterval]; @@ -197,7 +197,7 @@ GHOST_TSuccess GHOST_ContextCGL::getSwapInterval(int &intervalOut) { if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND if (m_openGLContext != nil) { GLint interval; @@ -226,7 +226,7 @@ GHOST_TSuccess GHOST_ContextCGL::activateDrawingContext() { if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND if (m_openGLContext != nil) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [m_openGLContext makeCurrentContext]; @@ -247,7 +247,7 @@ GHOST_TSuccess GHOST_ContextCGL::releaseDrawingContext() { if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND if (m_openGLContext != nil) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [NSOpenGLContext clearCurrentContext]; @@ -278,7 +278,7 @@ GHOST_TSuccess GHOST_ContextCGL::updateDrawingContext() { if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND if (m_openGLContext != nil) { if (m_metalView) { metalUpdateFramebuffer(); @@ -385,7 +385,7 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext() /* Command-line argument would be better. */ if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND /* Command-line argument would be better. */ static bool softwareGL = getenv("BLENDER_SOFTWAREGL"); @@ -508,7 +508,7 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext() GHOST_TSuccess GHOST_ContextCGL::releaseNativeHandles() { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND m_openGLContext = nil; m_openGLView = nil; #endif @@ -635,14 +635,14 @@ void GHOST_ContextCGL::metalFree() void GHOST_ContextCGL::metalInitFramebuffer() { if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND glGenFramebuffers(1, &m_defaultFramebuffer); #endif } updateDrawingContext(); if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFramebuffer); #endif } @@ -651,7 +651,7 @@ void GHOST_ContextCGL::metalInitFramebuffer() void GHOST_ContextCGL::metalUpdateFramebuffer() { if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND assert(m_defaultFramebuffer != 0); #endif } @@ -661,7 +661,7 @@ void GHOST_ContextCGL::metalUpdateFramebuffer() size_t width = (size_t)backingSize.width; size_t height = (size_t)backingSize.height; -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND unsigned int glTex; CVPixelBufferRef cvPixelBuffer = nil; CVOpenGLTextureCacheRef cvGLTexCache = nil; @@ -671,7 +671,7 @@ void GHOST_ContextCGL::metalUpdateFramebuffer() #endif if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND /* OPENGL path */ { /* Test if there is anything to update */ @@ -809,7 +809,7 @@ void GHOST_ContextCGL::metalUpdateFramebuffer() } if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFramebuffer); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, glTex, 0); #endif @@ -817,7 +817,7 @@ void GHOST_ContextCGL::metalUpdateFramebuffer() [m_metalLayer setDrawableSize:CGSizeMake((CGFloat)width, (CGFloat)height)]; if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND CVPixelBufferRelease(cvPixelBuffer); CVOpenGLTextureCacheRelease(cvGLTexCache); CVOpenGLTextureRelease(cvGLTex); @@ -835,7 +835,7 @@ void GHOST_ContextCGL::metalSwapBuffers() updateDrawingContext(); if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND glFlush(); assert(m_defaultFramebufferMetalTexture[current_swapchain_index].texture != nil); #endif @@ -888,7 +888,7 @@ void GHOST_ContextCGL::initClear() { if (!m_useMetalForRendering) { -#if WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND glClearColor(0.294, 0.294, 0.294, 0.000); glClear(GL_COLOR_BUFFER_BIT); glClearColor(0.000, 0.000, 0.000, 0.000); diff --git a/intern/ghost/intern/GHOST_System.cc b/intern/ghost/intern/GHOST_System.cc index ace3b69fcb9..d14e71a9900 100644 --- a/intern/ghost/intern/GHOST_System.cc +++ b/intern/ghost/intern/GHOST_System.cc @@ -403,7 +403,13 @@ GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window **window, if (stereoVisual) { gpuSettings.flags |= GHOST_gpuStereoVisual; } +#if defined(WITH_OPENGL_BACKEND) gpuSettings.context_type = GHOST_kDrawingContextTypeOpenGL; +#elif defined(WITH_METAL_BACKEND) + gpuSettings.context_type = GHOST_kDrawingContextTypeMetal; +#else +# error +#endif /* NOTE: don't use #getCurrentDisplaySetting() because on X11 we may * be zoomed in and the desktop may be bigger than the viewport. */ GHOST_ASSERT(m_displayManager, diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm index c6841b50037..5d743a3e3f5 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.mm +++ b/intern/ghost/intern/GHOST_WindowCocoa.mm @@ -829,8 +829,14 @@ GHOST_Context *GHOST_WindowCocoa::newDrawingContext(GHOST_TDrawingContextType ty } #endif - if (type == GHOST_kDrawingContextTypeOpenGL || type == GHOST_kDrawingContextTypeMetal) { - + if (true +#if defined(WITH_OPENGL_BACKEND) + || type == GHOST_kDrawingContextTypeOpenGL +#elif defined(WITH_METAL_BACKEND) + || type == GHOST_kDrawingContextTypeMetal +#endif + ) + { GHOST_Context *context = new GHOST_ContextCGL( m_wantStereoVisual, m_metalView, m_metalLayer, m_openGLView, type); diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 4a8ade75bba..023ec02264c 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -2,14 +2,6 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -# WITH_OPENGL limits the visibility of the opengl headers to just GPU and bg_gpu, -# to more easily highlight code-paths in other libraries that need to be refactored, -# bf_gpu is allowed to have opengl regardless of this option. - -if(NOT WITH_OPENGL AND NOT WITH_METAL_BACKEND AND NOT WITH_HEADLESS) - add_definitions(-DWITH_OPENGL) -endif() - set(INC . intern @@ -331,8 +323,10 @@ set(LIB ) # Select Backend source based on availability -if(WITH_OPENGL) +if(WITH_OPENGL_BACKEND) list(APPEND SRC ${OPENGL_SRC}) + + add_definitions(-DWITH_OPENGL_BACKEND) endif() if(WITH_METAL_BACKEND) diff --git a/source/blender/gpu/intern/gpu_context.cc b/source/blender/gpu/intern/gpu_context.cc index 8a6a4a9f9d0..a3c39d61a19 100644 --- a/source/blender/gpu/intern/gpu_context.cc +++ b/source/blender/gpu/intern/gpu_context.cc @@ -13,11 +13,6 @@ * - free can be called from any thread */ -/* TODO: Create cmake option. */ -#if WITH_OPENGL -# define WITH_OPENGL_BACKEND 1 -#endif - #include "BLI_assert.h" #include "BLI_utildefines.h" diff --git a/source/blender/gpu/intern/gpu_shader_builder.cc b/source/blender/gpu/intern/gpu_shader_builder.cc index a0903a13fa3..e28b6adf90e 100644 --- a/source/blender/gpu/intern/gpu_shader_builder.cc +++ b/source/blender/gpu/intern/gpu_shader_builder.cc @@ -45,9 +45,11 @@ void ShaderBuilder::init() GHOST_GPUSettings gpuSettings = {0}; switch (GPU_backend_type_selection_get()) { +#ifdef WITH_METAL_BACKEND case GPU_BACKEND_OPENGL: gpuSettings.context_type = GHOST_kDrawingContextTypeOpenGL; break; +#endif #ifdef WITH_METAL_BACKEND case GPU_BACKEND_METAL: diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index eee9f0f0cdf..108c9289eef 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -406,6 +406,10 @@ if(WITH_XR_OPENXR) add_definitions(-DWITH_XR_OPENXR) endif() +if(WITH_OPENGL_BACKEND) + add_definitions(-DWITH_OPENGL_BACKEND) +endif() + if(WITH_METAL_BACKEND) add_definitions(-DWITH_METAL_BACKEND) endif() diff --git a/source/blender/makesrna/intern/rna_userdef.cc b/source/blender/makesrna/intern/rna_userdef.cc index 9673eb1d014..28e2afb0781 100644 --- a/source/blender/makesrna/intern/rna_userdef.cc +++ b/source/blender/makesrna/intern/rna_userdef.cc @@ -1113,6 +1113,11 @@ static const EnumPropertyItem *rna_preference_gpu_backend_itemf(bContext * /*C*/ EnumPropertyItem *result = nullptr; for (int i = 0; rna_enum_preference_gpu_backend_items[i].identifier != nullptr; i++) { const EnumPropertyItem *item = &rna_enum_preference_gpu_backend_items[i]; +# ifndef WITH_OPENGL_BACKEND + if (item->value == GPU_BACKEND_OPENGL) { + continue; + } +# endif # ifndef WITH_METAL_BACKEND if (item->value == GPU_BACKEND_METAL) { continue; diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 3f9a1aac5ea..c23ca0a3712 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -1121,7 +1121,7 @@ static PyObject *Buffer_repr(Buffer *self) /** \name OpenGL API Wrapping * \{ */ -#ifdef WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND # define BGL_Wrap(funcname, ret, arg_list) \ static PyObject *Method_##funcname(PyObject *UNUSED(self), PyObject *args) \ { \ @@ -1485,7 +1485,7 @@ static void py_module_dict_add_method(PyObject *submodule, # pragma GCC diagnostic ignored "-Waddress" #endif -#ifdef WITH_OPENGL +#ifdef WITH_OPENGL_BACKEND # define PY_MOD_ADD_METHOD(func) \ { \ static PyMethodDef method_def = {"gl" #func, Method_##func, METH_VARARGS}; \ diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index d6c4375bdcf..0c3f0eb6ea1 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -125,6 +125,10 @@ if(WITH_CYCLES) add_definitions(-DWITH_CYCLES) endif() +if(WITH_OPENGL_BACKEND) + add_definitions(-DWITH_OPENGL_BACKEND) +endif() + if(WITH_VULKAN_BACKEND) add_definitions(-DWITH_VULKAN_BACKEND) endif() diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 4ba578b28ca..ff2df8d858c 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -1756,7 +1756,10 @@ GHOST_TDrawingContextType wm_ghost_drawing_context_type(const eGPUBackendType gp return GHOST_kDrawingContextTypeNone; case GPU_BACKEND_ANY: case GPU_BACKEND_OPENGL: +#ifdef WITH_OPENGL_BACKEND return GHOST_kDrawingContextTypeOpenGL; +#endif + BLI_assert_unreachable(); case GPU_BACKEND_VULKAN: #ifdef WITH_VULKAN_BACKEND return GHOST_kDrawingContextTypeVulkan; diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 25bbaeb2a19..7f332fd509a 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -57,6 +57,10 @@ if(WITH_CYCLES) endif() endif() +if(WITH_OPENGL_BACKEND) + add_definitions(-DWITH_OPENGL_BACKEND) +endif() + if(WITH_VULKAN_BACKEND) add_definitions(-DWITH_VULKAN_BACKEND) endif() diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c index 9a8c34c01c7..aa3478196d2 100644 --- a/source/creator/creator_args.c +++ b/source/creator/creator_args.c @@ -1269,12 +1269,21 @@ static const char arg_handle_gpu_backend_set_doc[] = "\n" "\tForce to use a specific GPU backend. Valid options: " # ifdef WITH_VULKAN_BACKEND - "'vulkan', " + "'vulkan'" +# if defined(WITH_METAL_BACKEND) || defined(WITH_OPENGL_BACKEND) + ", " +# endif # endif # ifdef WITH_METAL_BACKEND - "'metal', " + "'metal'" +# if defined(WITH_OPENGL_BACKEND) + ", " +# endif # endif - "'opengl'."; +# ifdef WITH_OPENGL_BACKEND + "'opengl'" +# endif + "."; static int arg_handle_gpu_backend_set(int argc, const char **argv, void *UNUSED(data)) { if (argc == 0) { @@ -1287,9 +1296,14 @@ static int arg_handle_gpu_backend_set(int argc, const char **argv, void *UNUSED( eGPUBackendType gpu_backend = GPU_BACKEND_NONE; /* NOLINTBEGIN: bugprone-assignment-in-if-condition */ - if (STREQ(argv[1], (backends_supported[backends_supported_num++] = "opengl"))) { + if (false) { + /* Just a dummy if to make the following ifdef blocks work. */ + } +# ifdef WITH_OPENGL_BACKEND + else if (STREQ(argv[1], (backends_supported[backends_supported_num++] = "opengl"))) { gpu_backend = GPU_BACKEND_OPENGL; } +# endif # ifdef WITH_VULKAN_BACKEND else if (STREQ(argv[1], (backends_supported[backends_supported_num++] = "vulkan"))) { gpu_backend = GPU_BACKEND_VULKAN;