Browse Source

Added sharedContextSupport for CGL and WGL windowlessApplication

pull/433/head
Stéphane Brard 6 years ago
parent
commit
47021d2cdc
  1. 4
      src/Magnum/Platform/WindowlessCglApplication.cpp
  2. 22
      src/Magnum/Platform/WindowlessCglApplication.h
  3. 6
      src/Magnum/Platform/WindowlessWglApplication.cpp
  4. 20
      src/Magnum/Platform/WindowlessWglApplication.h

4
src/Magnum/Platform/WindowlessCglApplication.cpp

@ -35,7 +35,7 @@
namespace Magnum { namespace Platform { namespace Magnum { namespace Platform {
WindowlessCglContext::WindowlessCglContext(const Configuration&, GLContext*) { WindowlessCglContext::WindowlessCglContext(const Configuration & configuration, GLContext*) {
int formatCount; int formatCount;
CGLPixelFormatAttribute attributes32[] = { CGLPixelFormatAttribute attributes32[] = {
kCGLPFAAccelerated, kCGLPFAAccelerated,
@ -68,7 +68,7 @@ WindowlessCglContext::WindowlessCglContext(const Configuration&, GLContext*) {
} }
} }
if(CGLCreateContext(_pixelFormat, nullptr, &_context) != kCGLNoError) if(CGLCreateContext(_pixelFormat, configuration.sharedContext(), &_context) != kCGLNoError)
Error() << "Platform::WindowlessCglContext: cannot create context"; Error() << "Platform::WindowlessCglContext: cannot create context";
} }

22
src/Magnum/Platform/WindowlessCglApplication.h

@ -142,6 +142,28 @@ class WindowlessCglContext {
class WindowlessCglContext::Configuration { class WindowlessCglContext::Configuration {
public: public:
constexpr /*implicit*/ Configuration() {} constexpr /*implicit*/ Configuration() {}
/**
* @brief Creates an OpenGL shared context with @param ctx instead
* of creating a brand new one.
*/
Configuration& setSharedcontext(CGLContextObj 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
*/
CGLContextObj sharedContext() const {
return _sharedContext;
}
private:
CGLContextObj _context{};
CGLContextObj _sharedContext{};
}; };
/** /**

6
src/Magnum/Platform/WindowlessWglApplication.cpp

@ -145,7 +145,7 @@ WindowlessWglContext::WindowlessWglContext(const Configuration& configuration, G
#endif #endif
0 0
}; };
_context = wglCreateContextAttribsARB(_deviceContext, nullptr, contextAttributes); _context = wglCreateContextAttribsARB(_deviceContext, configuration.sharedContext(), contextAttributes);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
/* Fall back to (forward compatible) GL 2.1 if core context creation fails */ /* Fall back to (forward compatible) GL 2.1 if core context creation fails */
@ -157,7 +157,7 @@ WindowlessWglContext::WindowlessWglContext(const Configuration& configuration, G
WGL_CONTEXT_FLAGS_ARB, GLint(flags & ~Configuration::Flag::ForwardCompatible), WGL_CONTEXT_FLAGS_ARB, GLint(flags & ~Configuration::Flag::ForwardCompatible),
0 0
}; };
_context = wglCreateContextAttribsARB(_deviceContext, nullptr, fallbackContextAttributes); _context = wglCreateContextAttribsARB(_deviceContext, configuration.sharedContext(), fallbackContextAttributes);
/* Fall back to (forward compatible) GL 2.1 if we are on binary /* Fall back to (forward compatible) GL 2.1 if we are on binary
NVidia/AMD/Intel drivers on Windows. Instead of creating forward-compatible NVidia/AMD/Intel drivers on Windows. Instead of creating forward-compatible
@ -196,7 +196,7 @@ WindowlessWglContext::WindowlessWglContext(const Configuration& configuration, G
WGL_CONTEXT_FLAGS_ARB, GLint(flags & ~Configuration::Flag::ForwardCompatible), WGL_CONTEXT_FLAGS_ARB, GLint(flags & ~Configuration::Flag::ForwardCompatible),
0 0
}; };
_context = wglCreateContextAttribsARB(_deviceContext, nullptr, fallbackContextAttributes); _context = wglCreateContextAttribsARB(_deviceContext, configuration.sharedContext(), fallbackContextAttributes);
} }
} }
#endif #endif

20
src/Magnum/Platform/WindowlessWglApplication.h

@ -232,9 +232,29 @@ class WindowlessWglContext::Configuration {
_flags &= ~flags; _flags &= ~flags;
return *this; return *this;
} }
/**
* @brief Creates an OpenGL shared context with @param ctx instead
* of creating a brand new one.
*/
Configuration& setSharedcontext(HGLRC 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
*/
HGLRC sharedContext() const {
return _sharedContext;
}
private: private:
HGLRC _sharedContext;
Flags _flags; Flags _flags;
}; };
CORRADE_ENUMSET_OPERATORS(WindowlessWglContext::Configuration::Flags) CORRADE_ENUMSET_OPERATORS(WindowlessWglContext::Configuration::Flags)

Loading…
Cancel
Save