[Bf-blender-cvs] [9accd7e5808] temp-drawcontext: GHOST: offscreen context support for macOS.
Brecht Van Lommel
noreply at git.blender.org
Mon Feb 12 17:38:36 CET 2018
Commit: 9accd7e58086d26c1287c2e8876a381d1249180e
Author: Brecht Van Lommel
Date: Mon Feb 12 17:01:27 2018 +0100
Branches: temp-drawcontext
https://developer.blender.org/rB9accd7e58086d26c1287c2e8876a381d1249180e
GHOST: offscreen context support for macOS.
===================================================================
M intern/ghost/GHOST_IContext.h
M intern/ghost/intern/GHOST_ContextCGL.mm
M intern/ghost/intern/GHOST_SystemCocoa.h
M intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
diff --git a/intern/ghost/GHOST_IContext.h b/intern/ghost/GHOST_IContext.h
index 33cbbe7bacd..fd8647b6335 100644
--- a/intern/ghost/GHOST_IContext.h
+++ b/intern/ghost/GHOST_IContext.h
@@ -45,7 +45,7 @@
* \see GHOST_ISystem#createOffscreenContext
*
* \author Clément Foucault
- * \date Fev 9, 2012
+ * \date Feb 9, 2018
*/
class GHOST_IContext
{
diff --git a/intern/ghost/intern/GHOST_ContextCGL.mm b/intern/ghost/intern/GHOST_ContextCGL.mm
index 03af3cc497e..88aba680f91 100644
--- a/intern/ghost/intern/GHOST_ContextCGL.mm
+++ b/intern/ghost/intern/GHOST_ContextCGL.mm
@@ -62,8 +62,6 @@ GHOST_ContextCGL::GHOST_ContextCGL(
m_openGLContext(nil),
m_debug(contextFlags)
{
- assert(openGLView != nil);
-
// for now be very strict about OpenGL version requested
switch (contextMajorVersion) {
case 2:
@@ -88,7 +86,10 @@ GHOST_ContextCGL::~GHOST_ContextCGL()
if (m_openGLContext != nil) {
if (m_openGLContext == [NSOpenGLContext currentContext]) {
[NSOpenGLContext clearCurrentContext];
- [m_openGLView clearGLContext];
+
+ if(m_openGLView) {
+ [m_openGLView clearGLContext];
+ }
}
if (m_openGLContext != s_sharedOpenGLContext || s_sharedCount == 1) {
@@ -258,7 +259,7 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext()
std::vector<NSOpenGLPixelFormatAttribute> attribs;
attribs.reserve(40);
- NSOpenGLContext *prev_openGLContext = [m_openGLView openGLContext];
+ NSOpenGLContext *prev_openGLContext = (m_openGLView) ? [m_openGLView openGLContext] : NULL;
#ifdef GHOST_OPENGL_ALPHA
static const bool needAlpha = true;
@@ -362,8 +363,10 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext()
initContextGLEW();
- [m_openGLView setOpenGLContext:m_openGLContext];
- [m_openGLContext setView:m_openGLView];
+ if (m_openGLView) {
+ [m_openGLView setOpenGLContext:m_openGLContext];
+ [m_openGLContext setView:m_openGLView];
+ }
if (s_sharedCount == 0)
s_sharedOpenGLContext = m_openGLContext;
@@ -380,7 +383,10 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext()
error:
- [m_openGLView setOpenGLContext:prev_openGLContext];
+ if (m_openGLView) {
+ [m_openGLView setOpenGLContext:prev_openGLContext];
+ }
+
[pixelFormat release];
[pool drain];
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h
index 6802ad42c7b..62d9774d81d 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.h
+++ b/intern/ghost/intern/GHOST_SystemCocoa.h
@@ -123,6 +123,25 @@ public:
const GHOST_TEmbedderWindowID parentWindow = 0
);
+ /**
+ * Create a new offscreen context.
+ * Never explicitly delete the context, use disposeContext() instead.
+ * \return The new context (or 0 if creation failed).
+ */
+ GHOST_IContext *
+ createOffscreenContext(
+ );
+
+ /**
+ * Dispose of a context.
+ * \param context Pointer to the context to be disposed.
+ * \return Indication of success.
+ */
+ GHOST_TSuccess
+ disposeContext(
+ GHOST_IContext *context
+ );
+
/***************************************************************************************
* Event management functionality
***************************************************************************************/
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm
index e9fffb6f60b..16d9de396f6 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -27,15 +27,6 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#import <Cocoa/Cocoa.h>
-
-/*For the currently not ported to Cocoa keyboard layout functions (64bit & 10.6 compatible)*/
-#include <Carbon/Carbon.h>
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
-
#include "GHOST_SystemCocoa.h"
#include "GHOST_DisplayManagerCocoa.h"
@@ -51,12 +42,26 @@
#include "GHOST_WindowManager.h"
#include "GHOST_WindowCocoa.h"
+#if defined(WITH_GL_EGL)
+# include "GHOST_ContextEGL.h"
+#else
+# include "GHOST_ContextCGL.h"
+#endif
+
#ifdef WITH_INPUT_NDOF
#include "GHOST_NDOFManagerCocoa.h"
#endif
#include "AssertMacros.h"
+#import <Cocoa/Cocoa.h>
+
+/* For the currently not ported to Cocoa keyboard layout functions (64bit & 10.6 compatible) */
+#include <Carbon/Carbon.h>
+
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
#pragma mark KeyMap, mouse converters
@@ -580,6 +585,53 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
return window;
}
+/**
+ * Create a new offscreen context.
+ * Never explicitly delete the context, use disposeContext() instead.
+ * \return The new context (or 0 if creation failed).
+ */
+GHOST_IContext *
+GHOST_SystemCocoa::
+createOffscreenContext()
+{
+ GHOST_Context *context = new GHOST_ContextCGL(
+ false,
+ 0,
+ NULL,
+ NULL,
+
+#if defined(WITH_GL_PROFILE_CORE)
+ GL_CONTEXT_CORE_PROFILE_BIT,
+ 3, 2,
+#else
+ 0, // no profile bit
+ 2, 1,
+#endif
+ GHOST_OPENGL_CGL_CONTEXT_FLAGS,
+ GHOST_OPENGL_CGL_RESET_NOTIFICATION_STRATEGY);
+
+ if (context->initializeDrawingContext())
+ return context;
+ else
+ delete context;
+
+ return NULL;
+}
+
+/**
+ * Dispose of a context.
+ * \param context Pointer to the context to be disposed.
+ * \return Indication of success.
+ */
+GHOST_TSuccess
+GHOST_SystemCocoa::
+disposeContext(GHOST_IContext *context)
+{
+ delete context;
+
+ return GHOST_kSuccess;
+}
+
/**
* \note : returns coordinates in Cocoa screen coordinates
*/
More information about the Bf-blender-cvs
mailing list