GHOST: Replace WITH_OPENGL build option

Replaces it by WITH_OPENGL_BACKEND and cleanup its usage.
Limits visibility of opengl enums and cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/109947
This commit is contained in:
Clément Foucault 2023-07-11 09:17:31 +02:00 committed by Clément Foucault
parent 232d763af4
commit 1978b4fc92
16 changed files with 89 additions and 54 deletions

@ -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

@ -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

@ -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

@ -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);

@ -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,

@ -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);

@ -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)

@ -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"

@ -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:

@ -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()

@ -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;

@ -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}; \

@ -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()

@ -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;

@ -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()

@ -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;