Browse Source

Added shared context support

pull/433/head
Stéphane Brard 6 years ago
parent
commit
af11780c59
  1. 15
      src/Magnum/Platform/WindowlessGlxApplication.cpp
  2. 26
      src/Magnum/Platform/WindowlessGlxApplication.h

15
src/Magnum/Platform/WindowlessGlxApplication.cpp

@ -40,6 +40,15 @@ namespace Magnum { namespace Platform {
WindowlessGlxContext::WindowlessGlxContext(const WindowlessGlxContext::Configuration& configuration, GLContext* const magnumContext) {
_display = XOpenDisplay(nullptr);
/**
* The user can choose to create a windowless application with a dedicated OpenGL context
* or give an OpenGL context to create a shared Context instead.
*
* Here, we ask the configuration whether a context has been specified by the user
* (!= nullptr) or not.
*/
GLXContext ctx = configuration.sharedContext();
/* Check version */
int major, minor;
glXQueryVersion(_display, &major, &minor);
@ -94,7 +103,7 @@ WindowlessGlxContext::WindowlessGlxContext(const WindowlessGlxContext::Configura
#endif
0
};
_context = glXCreateContextAttribsARB(_display, configs[0], nullptr, True, contextAttributes);
_context = glXCreateContextAttribsARB(_display, configs[0], ctx, True, contextAttributes);
#ifndef MAGNUM_TARGET_GLES
/* Fall back to (forward compatible) GL 2.1 if core context creation fails */
@ -105,7 +114,7 @@ WindowlessGlxContext::WindowlessGlxContext(const WindowlessGlxContext::Configura
GLX_CONTEXT_FLAGS_ARB, GLint(flags),
0
};
_context = glXCreateContextAttribsARB(_display, configs[0], nullptr, True, fallbackContextAttributes);
_context = glXCreateContextAttribsARB(_display, configs[0], ctx, True, fallbackContextAttributes);
/* Fall back to (forward compatible) GL 2.1 if we are on binary NVidia/AMD
drivers on Linux. Instead of creating forward-compatible context with
@ -142,7 +151,7 @@ WindowlessGlxContext::WindowlessGlxContext(const WindowlessGlxContext::Configura
GLX_CONTEXT_FLAGS_ARB, GLint(flags & ~Configuration::Flag::ForwardCompatible),
0
};
_context = glXCreateContextAttribsARB(_display, configs[0], nullptr, True, fallbackContextAttributes);
_context = glXCreateContextAttribsARB(_display, configs[0], ctx, True, fallbackContextAttributes);
}
/* Revert back the old context */

26
src/Magnum/Platform/WindowlessGlxApplication.h

@ -238,8 +238,34 @@ class WindowlessGlxContext::Configuration {
_flags &= ~flags;
return *this;
}
/**
* @brief Creates an OpenGL shared context with @param ctx instead
* of creating a brand new one.
*/
Configuration& setSharedcontext(GLXContext ctx) {
_sharedContext = ctx;
return *this;
}
/**
* @brief Returns the configuration shared context.
* If this has not been specified, (meaning the configuration uses a new opengl context),
* then returns nullptr
*/
GLXContext sharedContext() const {
return _sharedContext;
}
private:
/**
* If the @ref Configuration opengl context
* is shared with another context, then _sharedContext points to
* this context.
*
* Otherwise = nullptr;
*/
GLXContext _sharedContext{nullptr};
Flags _flags;
};

Loading…
Cancel
Save