GHOST: Guard GL context creation behind WITH_OPENGL_BACKEND

Even if not currently needed, it should be possible to compile
without OpenGL.

Also make sure the logic is similar for all GHOST implementations.

Pull Request: https://projects.blender.org/blender/blender/pulls/110165
This commit is contained in:
Clément Foucault 2023-07-16 19:58:10 +02:00 committed by Clément Foucault
parent 95367f732f
commit 8191b152ec
9 changed files with 379 additions and 427 deletions

View File

@ -23,7 +23,9 @@
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
#include "GHOST_ContextCGL.hh"
#if defined(WITH_OPENGL_BACKEND) || defined(WITH_METAL_BACKEND)
# include "GHOST_ContextCGL.hh"
#endif
#ifdef WITH_VULKAN_BACKEND
# include "GHOST_ContextVK.hh"
@ -761,25 +763,42 @@ GHOST_IWindow *GHOST_SystemCocoa::createWindow(const char *title,
*/
GHOST_IContext *GHOST_SystemCocoa::createOffscreenContext(GHOST_GPUSettings gpuSettings)
{
const bool debug_context = (gpuSettings.flags & GHOST_gpuDebugContext) != 0;
switch (gpuSettings.context_type) {
#ifdef WITH_VULKAN_BACKEND
if (gpuSettings.context_type == GHOST_kDrawingContextTypeVulkan) {
const bool debug_context = (gpuSettings.flags & GHOST_gpuDebugContext) != 0;
GHOST_Context *context = new GHOST_ContextVK(false, NULL, 1, 2, debug_context);
if (!context->initializeDrawingContext()) {
case GHOST_kDrawingContextTypeVulkan: {
GHOST_Context *context = new GHOST_ContextVK(false, NULL, 1, 2, debug_context);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
return NULL;
return nullptr;
}
#endif
#ifdef WITH_OPENGL_BACKEND
case GHOST_kDrawingContextTypeOpenGL:
#endif
#ifdef WITH_METAL_BACKEND
case GHOST_kDrawingContextTypeMetal:
#endif
#if defined(WITH_OPENGL_BACKEND) || defined(WITH_METAL_BACKEND)
{
/* TODO(fclem): Remove OpenGL support and rename context to ContextMTL */
GHOST_Context *context = new GHOST_ContextCGL(
false, NULL, NULL, NULL, gpuSettings.context_type);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
return nullptr;
}
return context;
}
#endif
GHOST_Context *context = new GHOST_ContextCGL(false, NULL, NULL, NULL, gpuSettings.context_type);
if (context->initializeDrawingContext())
return context;
else
delete context;
return NULL;
default:
/* Unsupported backend. */
return nullptr;
}
}
/**

View File

@ -127,29 +127,34 @@ uint8_t GHOST_SystemSDL::getNumDisplays() const
return SDL_GetNumVideoDisplays();
}
GHOST_IContext *GHOST_SystemSDL::createOffscreenContext(GHOST_GPUSettings /*gpuSettings*/)
GHOST_IContext *GHOST_SystemSDL::createOffscreenContext(GHOST_GPUSettings gpuSettings)
{
for (int minor = 6; minor >= 3; --minor) {
GHOST_Context *context = new GHOST_ContextSDL(false,
nullptr,
0, /* Profile bit. */
4,
minor,
GHOST_OPENGL_SDL_CONTEXT_FLAGS,
GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY);
switch (gpuSettings.context_type) {
#ifdef WITH_OPENGL_BACKEND
case GHOST_kDrawingContextTypeOpenGL: {
for (int minor = 6; minor >= 3; --minor) {
GHOST_Context *context = new GHOST_ContextSDL(
false,
nullptr,
0, /* Profile bit. */
4,
minor,
GHOST_OPENGL_SDL_CONTEXT_FLAGS,
GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY);
if (context->initializeDrawingContext()) {
return context;
if (context->initializeDrawingContext()) {
return context;
}
delete context;
}
return nullptr;
}
delete context;
context = nullptr;
}
#endif
if (context && context->initializeDrawingContext()) {
return context;
default:
/* Unsupported backend. */
return nullptr;
}
delete context;
return nullptr;
}
GHOST_TSuccess GHOST_SystemSDL::disposeContext(GHOST_IContext *context)

View File

@ -20,7 +20,9 @@
#include "GHOST_WindowManager.hh"
#include "GHOST_utildefines.hh"
#include "GHOST_ContextEGL.hh"
#ifdef WITH_OPENGL_BACKEND
# include "GHOST_ContextEGL.hh"
#endif
#ifdef WITH_VULKAN_BACKEND
# include "GHOST_ContextVK.hh"
@ -6243,86 +6245,85 @@ void GHOST_SystemWayland::getAllDisplayDimensions(uint32_t &width, uint32_t &hei
height = xy_max[1] - xy_min[1];
}
static GHOST_Context *createOffscreenContext_impl(GHOST_SystemWayland *system,
wl_display *wl_display,
wl_egl_window *egl_window)
{
/* Caller must lock `system->server_mutex`. */
GHOST_Context *context;
for (int minor = 6; minor >= 3; --minor) {
context = new GHOST_ContextEGL(system,
false,
EGLNativeWindowType(egl_window),
EGLNativeDisplayType(wl_display),
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
4,
minor,
GHOST_OPENGL_EGL_CONTEXT_FLAGS,
GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
EGL_OPENGL_API);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
}
return nullptr;
}
GHOST_IContext *GHOST_SystemWayland::createOffscreenContext(GHOST_GPUSettings gpuSettings)
{
#ifdef USE_EVENT_BACKGROUND_THREAD
std::lock_guard lock_server_guard{*server_mutex};
#endif
/* Create new off-screen window. */
wl_surface *wl_surface = wl_compositor_create_surface(wl_compositor());
#ifdef WITH_VULKAN_BACKEND
const bool debug_context = (gpuSettings.flags & GHOST_gpuDebugContext) != 0;
if (gpuSettings.context_type == GHOST_kDrawingContextTypeVulkan) {
GHOST_Context *context = new GHOST_ContextVK(false,
GHOST_kVulkanPlatformWayland,
0,
NULL,
wl_surface,
display_->wl_display,
1,
2,
debug_context);
switch (gpuSettings.context_type) {
if (!context->initializeDrawingContext()) {
#ifdef WITH_VULKAN_BACKEND
case GHOST_kDrawingContextTypeVulkan: {
/* Create new off-screen surface only for vulkan. */
wl_surface *wl_surface = wl_compositor_create_surface(wl_compositor());
GHOST_Context *context = new GHOST_ContextVK(false,
GHOST_kVulkanPlatformWayland,
0,
NULL,
wl_surface,
display_->wl_display,
1,
2,
debug_context);
if (context->initializeDrawingContext()) {
context->setUserData(wl_surface);
return context;
}
delete context;
if (wl_surface) {
wl_surface_destroy(wl_surface);
}
return nullptr;
}
context->setUserData(wl_surface);
return context;
}
#else
(void)gpuSettings;
#endif
wl_egl_window *egl_window = wl_surface ? wl_egl_window_create(wl_surface, 1, 1) : nullptr;
#ifdef WITH_OPENGL_BACKEND
case GHOST_kDrawingContextTypeOpenGL: {
/* Create new off-screen window. */
wl_surface *wl_surface = wl_compositor_create_surface(wl_compositor());
wl_egl_window *egl_window = wl_surface ? wl_egl_window_create(wl_surface, 1, 1) : nullptr;
GHOST_Context *context = createOffscreenContext_impl(this, display_->wl_display, egl_window);
for (int minor = 6; minor >= 3; --minor) {
/* Caller must lock `system->server_mutex`. */
GHOST_Context *context = new GHOST_ContextEGL(this,
false,
EGLNativeWindowType(egl_window),
EGLNativeDisplayType(display_->wl_display),
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
4,
minor,
GHOST_OPENGL_EGL_CONTEXT_FLAGS,
GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
EGL_OPENGL_API);
if (!context) {
GHOST_PRINT("Cannot create off-screen EGL context" << std::endl);
if (wl_surface) {
wl_surface_destroy(wl_surface);
if (context->initializeDrawingContext()) {
wl_surface_set_user_data(wl_surface, egl_window);
context->setUserData(wl_surface);
return context;
}
delete context;
}
GHOST_PRINT("Cannot create off-screen EGL context" << std::endl);
if (wl_surface) {
wl_surface_destroy(wl_surface);
}
if (egl_window) {
wl_egl_window_destroy(egl_window);
}
return nullptr;
}
if (egl_window) {
wl_egl_window_destroy(egl_window);
}
return nullptr;
#endif
default:
/* Unsupported backend. */
return nullptr;
}
wl_surface_set_user_data(wl_surface, egl_window);
context->setUserData(wl_surface);
return context;
}
GHOST_TSuccess GHOST_SystemWayland::disposeContext(GHOST_IContext *context)

View File

@ -7,7 +7,6 @@
*/
#include "GHOST_SystemWin32.hh"
#include "GHOST_ContextD3D.hh"
#include "GHOST_EventDragnDrop.hh"
#include "GHOST_EventTrackpad.hh"
@ -40,7 +39,10 @@
#include "GHOST_WindowManager.hh"
#include "GHOST_WindowWin32.hh"
#include "GHOST_ContextWGL.hh"
#include "GHOST_ContextD3D.hh"
#ifdef WITH_OPENGL_BACKEND
# include "GHOST_ContextWGL.hh"
#endif
#ifdef WITH_VULKAN_BACKEND
# include "GHOST_ContextVK.hh"
#endif
@ -268,61 +270,64 @@ GHOST_IContext *GHOST_SystemWin32::createOffscreenContext(GHOST_GPUSettings gpuS
{
const bool debug_context = (gpuSettings.flags & GHOST_gpuDebugContext) != 0;
GHOST_Context *context = nullptr;
switch (gpuSettings.context_type) {
#ifdef WITH_VULKAN_BACKEND
/* Vulkan does not need a window. */
if (gpuSettings.context_type == GHOST_kDrawingContextTypeVulkan) {
context = new GHOST_ContextVK(false, (HWND)0, 1, 2, debug_context);
if (!context->initializeDrawingContext()) {
case GHOST_kDrawingContextTypeVulkan: {
GHOST_Context *context = new GHOST_ContextVK(false, (HWND)0, 1, 2, debug_context);
if (context->initializeDrawingContext()) {
return nullptr;
}
delete context;
return nullptr;
}
return context;
}
#endif
HWND wnd = CreateWindowA("STATIC",
"BlenderGLEW",
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
0,
0,
64,
64,
NULL,
NULL,
GetModuleHandle(NULL),
NULL);
#ifdef WITH_OPENGL_BACKEND
case GHOST_kDrawingContextTypeOpenGL: {
HDC mHDC = GetDC(wnd);
HDC prev_hdc = wglGetCurrentDC();
HGLRC prev_context = wglGetCurrentContext();
/* OpenGL needs a dummy window to create a context on windows. */
HWND wnd = CreateWindowA("STATIC",
"BlenderGLEW",
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
0,
0,
64,
64,
NULL,
NULL,
GetModuleHandle(NULL),
NULL);
for (int minor = 6; minor >= 3; --minor) {
context = new GHOST_ContextWGL(false,
true,
wnd,
mHDC,
WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
4,
minor,
(debug_context ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY);
HDC mHDC = GetDC(wnd);
HDC prev_hdc = wglGetCurrentDC();
HGLRC prev_context = wglGetCurrentContext();
if (context->initializeDrawingContext()) {
for (int minor = 6; minor >= 3; --minor) {
GHOST_Context *context = new GHOST_ContextWGL(
false,
true,
wnd,
mHDC,
WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
4,
minor,
(debug_context ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY);
if (context->initializeDrawingContext()) {
wglMakeCurrent(prev_hdc, prev_context);
return context;
}
delete context;
}
wglMakeCurrent(prev_hdc, prev_context);
return context;
}
else {
delete context;
context = nullptr;
return nullptr;
}
#endif
default:
/* Unsupported backend. */
return nullptr;
}
finished:
wglMakeCurrent(prev_hdc, prev_context);
return context;
}
/**
@ -344,8 +349,6 @@ GHOST_TSuccess GHOST_SystemWin32::disposeContext(GHOST_IContext *context)
*/
GHOST_ContextD3D *GHOST_SystemWin32::createOffscreenContextD3D()
{
GHOST_ContextD3D *context;
HWND wnd = CreateWindowA("STATIC",
"Blender XR",
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
@ -358,13 +361,12 @@ GHOST_ContextD3D *GHOST_SystemWin32::createOffscreenContextD3D()
GetModuleHandle(NULL),
NULL);
context = new GHOST_ContextD3D(false, wnd);
if (context->initializeDrawingContext() == GHOST_kFailure) {
delete context;
context = nullptr;
GHOST_ContextD3D *context = new GHOST_ContextD3D(false, wnd);
if (context->initializeDrawingContext()) {
return context;
}
return context;
delete context;
return nullptr;
}
GHOST_TSuccess GHOST_SystemWin32::disposeContextD3D(GHOST_ContextD3D *context)

View File

@ -35,8 +35,10 @@
#include "GHOST_Debug.hh"
#include "GHOST_ContextEGL.hh"
#include "GHOST_ContextGLX.hh"
#ifdef WITH_OPENGL_BACKEND
# include "GHOST_ContextEGL.hh"
# include "GHOST_ContextGLX.hh"
#endif
#ifdef WITH_VULKAN_BACKEND
# include "GHOST_ContextVK.hh"
@ -350,94 +352,48 @@ GHOST_IWindow *GHOST_SystemX11::createWindow(const char *title,
return window;
}
#ifdef USE_EGL
static GHOST_Context *create_egl_context(
GHOST_SystemX11 *system, Display *display, bool debug_context, int ver_major, int ver_minor)
{
GHOST_Context *context;
context = new GHOST_ContextEGL(system,
false,
EGLNativeWindowType(nullptr),
EGLNativeDisplayType(display),
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
ver_major,
ver_minor,
GHOST_OPENGL_EGL_CONTEXT_FLAGS |
(debug_context ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0),
GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
EGL_OPENGL_API);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
return nullptr;
}
#endif
static GHOST_Context *create_glx_context(Display *display,
bool debug_context,
int ver_major,
int ver_minor)
{
GHOST_Context *context;
context = new GHOST_ContextGLX(false,
(Window) nullptr,
display,
(GLXFBConfig) nullptr,
GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
ver_major,
ver_minor,
GHOST_OPENGL_GLX_CONTEXT_FLAGS |
(debug_context ? GLX_CONTEXT_DEBUG_BIT_ARB : 0),
GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
return nullptr;
}
GHOST_IContext *GHOST_SystemX11::createOffscreenContext(GHOST_GPUSettings gpuSettings)
{
const bool debug_context = (gpuSettings.flags & GHOST_gpuDebugContext) != 0;
GHOST_Context *context = nullptr;
switch (gpuSettings.context_type) {
#ifdef WITH_VULKAN_BACKEND
if (gpuSettings.context_type == GHOST_kDrawingContextTypeVulkan) {
context = new GHOST_ContextVK(
false, GHOST_kVulkanPlatformX11, 0, m_display, NULL, NULL, 1, 2, debug_context);
if (!context->initializeDrawingContext()) {
case GHOST_kDrawingContextTypeVulkan: {
GHOST_Context *context = new GHOST_ContextVK(
false, GHOST_kVulkanPlatformX11, 0, m_display, NULL, NULL, 1, 2, debug_context);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
return nullptr;
}
return context;
}
#endif
#ifdef USE_EGL
/* Try to initialize an EGL context. */
for (int minor = 6; minor >= 3; --minor) {
context = create_egl_context(this, m_display, debug_context, 4, minor);
if (context != nullptr) {
return context;
#ifdef WITH_OPENGL_BACKEND
case GHOST_kDrawingContextTypeOpenGL: {
for (int minor = 6; minor >= 3; --minor) {
GHOST_Context *context = new GHOST_ContextGLX(
false,
(Window) nullptr,
m_display,
(GLXFBConfig) nullptr,
GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
4,
minor,
GHOST_OPENGL_GLX_CONTEXT_FLAGS | (debug_context ? GLX_CONTEXT_DEBUG_BIT_ARB : 0),
GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
}
return nullptr;
}
}
/* EGL initialization failed, try to fallback to a GLX context. */
#endif
for (int minor = 6; minor >= 3; --minor) {
context = create_glx_context(m_display, debug_context, 4, minor);
if (context != nullptr) {
return context;
}
}
return nullptr;
default:
/* Unsupported backend. */
return nullptr;
}
}
GHOST_TSuccess GHOST_SystemX11::disposeContext(GHOST_IContext *context)

View File

@ -65,22 +65,32 @@ GHOST_WindowSDL::~GHOST_WindowSDL()
GHOST_Context *GHOST_WindowSDL::newDrawingContext(GHOST_TDrawingContextType type)
{
if (type == GHOST_kDrawingContextTypeOpenGL) {
GHOST_Context *context = new GHOST_ContextSDL(m_wantStereoVisual,
m_sdl_win,
0, // profile bit
3,
3,
GHOST_OPENGL_SDL_CONTEXT_FLAGS,
GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY);
switch (type) {
#ifdef WITH_OPENGL_BACKEND
case GHOST_kDrawingContextTypeOpenGL: {
for (int minor = 6; minor >= 3; --minor) {
GHOST_Context *context = new GHOST_ContextSDL(
m_wantStereoVisual,
m_sdl_win,
0, /* Profile bit. */
4,
minor,
GHOST_OPENGL_SDL_CONTEXT_FLAGS,
GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY);
if (context->initializeDrawingContext()) {
return context;
if (context->initializeDrawingContext()) {
return context;
}
delete context;
}
return nullptr;
}
delete context;
}
#endif
return nullptr;
default:
/* Unsupported backend. */
return nullptr;
}
}
GHOST_TSuccess GHOST_WindowSDL::invalidate()

View File

@ -14,8 +14,10 @@
#include "GHOST_Event.hh"
#include "GHOST_ContextEGL.hh"
#include "GHOST_ContextNone.hh"
#ifdef WITH_OPENGL_BACKEND
# include "GHOST_ContextEGL.hh"
#endif
#ifdef WITH_VULKAN_BACKEND
# include "GHOST_ContextVK.hh"
#endif
@ -1749,53 +1751,58 @@ void GHOST_WindowWayland::setOpaque() const
GHOST_Context *GHOST_WindowWayland::newDrawingContext(GHOST_TDrawingContextType type)
{
GHOST_Context *context;
switch (type) {
case GHOST_kDrawingContextTypeNone:
context = new GHOST_ContextNone(m_wantStereoVisual);
break;
case GHOST_kDrawingContextTypeNone: {
GHOST_Context *context = new GHOST_ContextNone(m_wantStereoVisual);
return context;
}
#ifdef WITH_VULKAN_BACKEND
case GHOST_kDrawingContextTypeVulkan:
context = new GHOST_ContextVK(m_wantStereoVisual,
GHOST_kVulkanPlatformWayland,
0,
NULL,
window_->wl_surface,
system_->wl_display(),
1,
2,
true);
break;
case GHOST_kDrawingContextTypeVulkan: {
GHOST_Context *context = new GHOST_ContextVK(m_wantStereoVisual,
GHOST_kVulkanPlatformWayland,
0,
NULL,
window_->wl_surface,
system_->wl_display(),
1,
2,
true);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
return nullptr;
}
#endif
case GHOST_kDrawingContextTypeOpenGL:
#ifdef WITH_OPENGL_BACKEND
case GHOST_kDrawingContextTypeOpenGL: {
for (int minor = 6; minor >= 3; --minor) {
context = new GHOST_ContextEGL(system_,
m_wantStereoVisual,
EGLNativeWindowType(window_->egl_window),
EGLNativeDisplayType(system_->wl_display()),
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
4,
minor,
GHOST_OPENGL_EGL_CONTEXT_FLAGS,
GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
EGL_OPENGL_API);
GHOST_Context *context = new GHOST_ContextEGL(system_,
m_wantStereoVisual,
EGLNativeWindowType(window_->egl_window),
EGLNativeDisplayType(system_->wl_display()),
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
4,
minor,
GHOST_OPENGL_EGL_CONTEXT_FLAGS,
GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
EGL_OPENGL_API);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
context = nullptr;
}
}
return nullptr;
}
#endif
if (context && context->initializeDrawingContext()) {
return context;
default:
/* Unsupported backend. */
return nullptr;
}
delete context;
return nullptr;
}
/** \} */

View File

@ -15,7 +15,9 @@
#include "utf_winfunc.h"
#include "utfconv.h"
#include "GHOST_ContextWGL.hh"
#ifdef WITH_OPENGL_BACKEND
# include "GHOST_ContextWGL.hh"
#endif
#ifdef WITH_VULKAN_BACKEND
# include "GHOST_ContextVK.hh"
#endif
@ -592,56 +594,55 @@ GHOST_TSuccess GHOST_WindowWin32::invalidate()
GHOST_Context *GHOST_WindowWin32::newDrawingContext(GHOST_TDrawingContextType type)
{
if (type == GHOST_kDrawingContextTypeOpenGL) {
GHOST_Context *context;
switch (type) {
#ifdef WITH_VULKAN_BACKEND
case GHOST_kDrawingContextTypeVulkan: {
GHOST_Context *context = new GHOST_ContextVK(false, m_hWnd, 1, 2, m_debug_context);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
return nullptr;
}
#endif
for (int minor = 6; minor >= 3; --minor) {
context = new GHOST_ContextWGL(m_wantStereoVisual,
m_wantAlphaBackground,
m_hWnd,
m_hDC,
WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
4,
minor,
(m_debug_context ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY);
#ifdef WITH_OPENGL_BACKEND
case GHOST_kDrawingContextTypeOpenGL: {
for (int minor = 6; minor >= 3; --minor) {
GHOST_Context *context = new GHOST_ContextWGL(
m_wantStereoVisual,
m_wantAlphaBackground,
m_hWnd,
m_hDC,
WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
4,
minor,
(m_debug_context ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
}
return nullptr;
}
#endif
case GHOST_kDrawingContextTypeD3D: {
GHOST_Context *context = new GHOST_ContextD3D(false, m_hWnd);
if (context->initializeDrawingContext()) {
return context;
}
else {
delete context;
context = nullptr;
}
}
return context;
}
else if (type == GHOST_kDrawingContextTypeD3D) {
GHOST_Context *context;
context = new GHOST_ContextD3D(false, m_hWnd);
if (!context->initializeDrawingContext()) {
delete context;
context = nullptr;
return nullptr;
}
return context;
default:
/* Unsupported backend. */
return nullptr;
}
#ifdef WITH_VULKAN_BACKEND
else if (type == GHOST_kDrawingContextTypeVulkan) {
GHOST_Context *context = new GHOST_ContextVK(false, m_hWnd, 1, 2, m_debug_context);
if (context->initializeDrawingContext()) {
return context;
}
else {
delete context;
}
}
#endif
return NULL;
}
void GHOST_WindowWin32::lostMouseCapture()

View File

@ -23,8 +23,10 @@
# include "GHOST_DropTargetX11.hh"
#endif
#include "GHOST_ContextEGL.hh"
#include "GHOST_ContextGLX.hh"
#ifdef WITH_OPENGL_BACKEND
# include "GHOST_ContextEGL.hh"
# include "GHOST_ContextGLX.hh"
#endif
#ifdef WITH_VULKAN_BACKEND
# include "GHOST_ContextVK.hh"
#endif
@ -1171,128 +1173,77 @@ GHOST_WindowX11::~GHOST_WindowX11()
}
}
#ifdef USE_EGL
static GHOST_Context *create_egl_context(GHOST_SystemX11 *system,
Window window,
Display *display,
bool want_stereo,
bool debug_context,
int ver_major,
int ver_minor)
{
GHOST_Context *context;
context = new GHOST_ContextEGL(system,
want_stereo,
EGLNativeWindowType(window),
EGLNativeDisplayType(display),
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
ver_major,
ver_minor,
GHOST_OPENGL_EGL_CONTEXT_FLAGS |
(debug_context ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0),
GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
EGL_OPENGL_API);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
return nullptr;
}
#endif
#ifdef WITH_OPENGL_BACKEND
static GHOST_Context *create_glx_context(Window window,
Display *display,
GLXFBConfig fbconfig,
bool want_stereo,
bool debug_context,
int ver_major,
int ver_minor)
{
GHOST_Context *context;
context = new GHOST_ContextGLX(want_stereo,
window,
display,
fbconfig,
GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
ver_major,
ver_minor,
GHOST_OPENGL_GLX_CONTEXT_FLAGS |
(debug_context ? GLX_CONTEXT_DEBUG_BIT_ARB : 0),
GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
return nullptr;
}
#endif
GHOST_Context *GHOST_WindowX11::newDrawingContext(GHOST_TDrawingContextType type)
{
#if defined(WITH_VULKAN_BACKEND)
if (type == GHOST_kDrawingContextTypeVulkan) {
GHOST_Context *context = new GHOST_ContextVK(m_wantStereoVisual,
GHOST_kVulkanPlatformX11,
m_window,
m_display,
NULL,
NULL,
1,
2,
m_is_debug_context);
if (!context->initializeDrawingContext()) {
switch (type) {
#ifdef WITH_VULKAN_BACKEND
case GHOST_kDrawingContextTypeVulkan: {
GHOST_Context *context = new GHOST_ContextVK(m_wantStereoVisual,
GHOST_kVulkanPlatformX11,
m_window,
m_display,
NULL,
NULL,
1,
2,
m_is_debug_context);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
return nullptr;
}
return context;
}
#endif
#ifdef WITH_OPENGL_BACKEND
if (type == GHOST_kDrawingContextTypeOpenGL) {
GHOST_Context *context;
case GHOST_kDrawingContextTypeOpenGL: {
# ifdef USE_EGL
/* Try to initialize an EGL context. */
for (int minor = 6; minor >= 3; --minor) {
context = create_egl_context(
this->m_system, m_window, m_display, m_wantStereoVisual, m_is_debug_context, 4, minor);
if (context != nullptr) {
return context;
/* Try to initialize an EGL context. */
for (int minor = 6; minor >= 3; --minor) {
GHOST_Context *context = GHOST_ContextEGL(
this->m_system,
m_wantStereoVisual,
EGLNativeWindowType(m_window),
EGLNativeDisplayType(m_display),
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
4,
minor,
GHOST_OPENGL_EGL_CONTEXT_FLAGS |
(m_is_debug_context ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0),
GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
EGL_OPENGL_API);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
}
}
/* EGL initialization failed, try to fallback to a GLX context. */
/* EGL initialization failed, try to fallback to a GLX context. */
# endif
for (int minor = 6; minor >= 3; --minor) {
context = create_glx_context(m_window,
m_display,
(GLXFBConfig)m_fbconfig,
m_wantStereoVisual,
m_is_debug_context,
4,
minor);
if (context != nullptr) {
return context;
}
}
/* Ugly, but we get crashes unless a whole bunch of systems are patched. */
fprintf(stderr, "Error! Unsupported graphics card or driver.\n");
fprintf(stderr,
"A graphics card and driver with support for OpenGL 3.3 or higher is required.\n");
fprintf(stderr, "The program will now close.\n");
fflush(stderr);
exit(1);
}
for (int minor = 6; minor >= 3; --minor) {
GHOST_Context *context = new GHOST_ContextGLX(
m_wantStereoVisual,
m_window,
m_display,
(GLXFBConfig)m_fbconfig,
GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
4,
minor,
GHOST_OPENGL_GLX_CONTEXT_FLAGS | (m_is_debug_context ? GLX_CONTEXT_DEBUG_BIT_ARB : 0),
GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY);
if (context->initializeDrawingContext()) {
return context;
}
delete context;
}
return nullptr;
}
#endif
return nullptr;
default:
/* Unsupported backend. */
return nullptr;
}
}
GHOST_TSuccess GHOST_WindowX11::getStandardCursor(GHOST_TStandardCursor g_cursor, Cursor &xcursor)