GHOST: Fix SDL backend.

We use a hidden window for each offscreen context we need.

On X11 (linux) it does not show any other windows in the OS task bar
but it might be the case on other operating systems (untested).
This commit is contained in:
Clément Foucault 2018-07-27 16:28:44 +02:00
parent 70966af513
commit 60499ff25d
Notes: blender-bot 2023-02-14 11:42:40 +01:00
Referenced by issue #55468, GHOST_SDL broke in 0940e89e60
6 changed files with 58 additions and 4 deletions

View File

@ -55,6 +55,7 @@ GHOST_ContextSDL::GHOST_ContextSDL(
int contextResetNotificationStrategy)
: GHOST_Context(stereoVisual, numOfAASamples),
m_window(window),
m_hidden_window(NULL),
m_contextProfileMask(contextProfileMask),
m_contextMajorVersion(contextMajorVersion),
m_contextMinorVersion(contextMinorVersion),
@ -62,7 +63,7 @@ GHOST_ContextSDL::GHOST_ContextSDL(
m_contextResetNotificationStrategy(contextResetNotificationStrategy),
m_context(NULL)
{
assert(m_window != NULL);
// assert(m_window != NULL);
}
@ -70,7 +71,7 @@ GHOST_ContextSDL::~GHOST_ContextSDL()
{
if (m_context != NULL) {
if (m_window != NULL && m_context == SDL_GL_GetCurrentContext())
SDL_GL_MakeCurrent(m_window, m_context);
SDL_GL_MakeCurrent(m_window, NULL);
if (m_context != s_sharedContext || s_sharedCount == 1) {
assert(s_sharedCount > 0);
@ -82,6 +83,9 @@ GHOST_ContextSDL::~GHOST_ContextSDL()
SDL_GL_DeleteContext(m_context);
}
if (m_hidden_window != NULL)
SDL_DestroyWindow(m_hidden_window);
}
}
@ -160,6 +164,18 @@ GHOST_TSuccess GHOST_ContextSDL::initializeDrawingContext()
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, m_numOfAASamples);
}
if (m_window == NULL) {
m_hidden_window = SDL_CreateWindow(
"Offscreen Context Windows",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
1, 1,
SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_HIDDEN
);
m_window = m_hidden_window;
}
m_context = SDL_GL_CreateContext(m_window);
GHOST_TSuccess success;

View File

@ -120,6 +120,7 @@ public:
private:
SDL_Window *m_window;
SDL_Window *m_hidden_window;
const int m_contextProfileMask;
const int m_contextMajorVersion;

View File

@ -297,7 +297,9 @@ GHOST_TSuccess GHOST_System::getButtonState(GHOST_TButtonMask mask, bool& isDown
#ifdef WITH_INPUT_NDOF
void GHOST_System::setNDOFDeadZone(float deadzone)
{
this->m_ndofManager->setDeadZone(deadzone);
if (this->m_ndofManager) {
this->m_ndofManager->setDeadZone(deadzone);
}
}
#endif

View File

@ -26,6 +26,7 @@
#include <assert.h>
#include "GHOST_ContextSDL.h"
#include "GHOST_SystemSDL.h"
#include "GHOST_WindowSDL.h"
@ -149,6 +150,34 @@ GHOST_SystemSDL::getNumDisplays() const
return SDL_GetNumVideoDisplays();
}
GHOST_IContext *
GHOST_SystemSDL::createOffscreenContext()
{
GHOST_Context *context = new GHOST_ContextSDL(
0,
0,
NULL,
0, // profile bit
3, 3,
GHOST_OPENGL_SDL_CONTEXT_FLAGS,
GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY);
if (context->initializeDrawingContext())
return context;
else
delete context;
return NULL;
}
GHOST_TSuccess
GHOST_SystemSDL::disposeContext(GHOST_IContext *context)
{
delete context;
return GHOST_kSuccess;
}
GHOST_TSuccess
GHOST_SystemSDL::getModifierKeys(GHOST_ModifierKeys& keys) const
{

View File

@ -95,6 +95,12 @@ public:
getMainDisplayDimensions(GHOST_TUns32& width,
GHOST_TUns32& height) const;
GHOST_IContext *
createOffscreenContext();
GHOST_TSuccess
disposeContext(GHOST_IContext *context);
/**
* Informs if the system provides native dialogs (eg. confirm quit)
*/

View File

@ -93,7 +93,7 @@ GHOST_WindowSDL::newDrawingContext(GHOST_TDrawingContextType type)
m_wantNumOfAASamples,
m_sdl_win,
0, // profile bit
0, 0,
3, 3,
GHOST_OPENGL_SDL_CONTEXT_FLAGS,
GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY);