[Bf-blender-cvs] [0940e89e604] blender2.8: GHOST: Add new interface to manage offscreen contexts.

Clément Foucault noreply at git.blender.org
Mon Feb 26 20:10:13 CET 2018


Commit: 0940e89e604d85d717f792b73e30e5e96a42e7c6
Author: Clément Foucault
Date:   Mon Feb 26 19:10:15 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB0940e89e604d85d717f792b73e30e5e96a42e7c6

GHOST: Add new interface to manage offscreen contexts.

Offscreen contexts are not attached to a window and can only be used for rendering to frambuffer objects.

CGL implementation : Brecht Van Lommel (brecht)
GLX implementation : Clément Foucault (fclem)
WGL implementation : Germano Cavalcante (mano-wii)

Other implementation are just place holder for now.

===================================================================

M	intern/ghost/CMakeLists.txt
M	intern/ghost/GHOST_C-api.h
A	intern/ghost/GHOST_IContext.h
M	intern/ghost/GHOST_ISystem.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_Context.h
M	intern/ghost/intern/GHOST_ContextCGL.h
M	intern/ghost/intern/GHOST_ContextCGL.mm
M	intern/ghost/intern/GHOST_ContextEGL.cpp
M	intern/ghost/intern/GHOST_ContextEGL.h
M	intern/ghost/intern/GHOST_ContextGLX.cpp
M	intern/ghost/intern/GHOST_ContextGLX.h
M	intern/ghost/intern/GHOST_ContextNone.cpp
M	intern/ghost/intern/GHOST_ContextNone.h
M	intern/ghost/intern/GHOST_ContextSDL.cpp
M	intern/ghost/intern/GHOST_ContextSDL.h
M	intern/ghost/intern/GHOST_ContextWGL.cpp
M	intern/ghost/intern/GHOST_ContextWGL.h
M	intern/ghost/intern/GHOST_SystemCocoa.h
M	intern/ghost/intern/GHOST_SystemCocoa.mm
M	intern/ghost/intern/GHOST_SystemWin32.cpp
M	intern/ghost/intern/GHOST_SystemWin32.h
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	intern/ghost/intern/GHOST_SystemX11.h
M	intern/ghost/intern/GHOST_WindowCocoa.mm

===================================================================

diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index 5a97da28d17..7771af93d4f 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -54,6 +54,7 @@ set(SRC
 	intern/GHOST_WindowManager.cpp
 
 	GHOST_C-api.h
+	GHOST_IContext.h
 	GHOST_IEvent.h
 	GHOST_IEventConsumer.h
 	GHOST_ISystem.h
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 967d3f58143..d5d8be7db8e 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -52,6 +52,7 @@ GHOST_DECLARE_HANDLE(GHOST_WindowHandle);
 GHOST_DECLARE_HANDLE(GHOST_EventHandle);
 GHOST_DECLARE_HANDLE(GHOST_RectangleHandle);
 GHOST_DECLARE_HANDLE(GHOST_EventConsumerHandle);
+GHOST_DECLARE_HANDLE(GHOST_ContextHandle);
 
 
 /**
@@ -188,6 +189,23 @@ extern GHOST_WindowHandle GHOST_CreateWindow(
         GHOST_TDrawingContextType type,
         GHOST_GLSettings glSettings);
 
+/**
+ * Create a new offscreen context.
+ * Never explicitly delete the context, use disposeContext() instead.
+ * \param systemhandle The handle to the system
+ * \return A handle to the new context ( == NULL if creation failed).
+ */
+extern GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle);
+
+/**
+ * Dispose of a context.
+ * \param systemhandle The handle to the system
+ * \param contexthandle Handle to the context to be disposed.
+ * \return Indication of success.
+ */
+extern GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle,
+                                                    GHOST_ContextHandle contexthandle);
+
 /**
  * Returns the window user data.
  * \param windowhandle The handle to the window
@@ -710,6 +728,20 @@ extern GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle wind
  */
 extern GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle);
 
+/**
+ * Activates the drawing context of this context.
+ * \param contexthandle The handle to the context
+ * \return A success indicator.
+ */
+extern GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthandle);
+
+/**
+ * Release the drawing context bound to this thread.
+ * \param contexthandle The handle to the context
+ * \return A success indicator.
+ */
+extern GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle);
+
 /**
  * Returns the status of the tablet
  * \param windowhandle The handle to the window
diff --git a/intern/ghost/GHOST_IContext.h b/intern/ghost/GHOST_IContext.h
new file mode 100644
index 00000000000..5b027a614ab
--- /dev/null
+++ b/intern/ghost/GHOST_IContext.h
@@ -0,0 +1,78 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file ghost/GHOST_IContext.h
+ *  \ingroup GHOST
+ * Declaration of GHOST_IContext interface class.
+ */
+
+#ifndef __GHOST_IContext_H__
+#define __GHOST_IContext_H__
+
+#include "STR_String.h"
+#include "GHOST_Types.h"
+
+
+/**
+ * Interface for GHOST context.
+ *
+ * You can create a offscreen context (windowless) with the system's
+ * GHOST_ISystem::createOffscreenContext method.
+ * \see GHOST_ISystem#createOffscreenContext
+ *
+ * \author  Clément Foucault
+ * \date    Feb 9, 2018
+ */
+class GHOST_IContext
+{
+public:
+	/**
+	 * Destructor.
+	 */
+	virtual ~GHOST_IContext()
+	{
+	}
+
+	/**
+	 * Activates the drawing context.
+	 * \return  A boolean success indicator.
+	 */
+	virtual GHOST_TSuccess activateDrawingContext() = 0;
+
+	/**
+	 * Release the drawing context of the calling thread.
+	 * \return  A boolean success indicator.
+	 */
+	virtual GHOST_TSuccess releaseDrawingContext() = 0;
+
+#ifdef WITH_CXX_GUARDEDALLOC
+	MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_IContext")
+#endif
+};
+
+#endif // __GHOST_IContext_H__
+
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index 03193d6e1da..5c5590ef069 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -36,6 +36,7 @@
 #define __GHOST_ISYSTEM_H__
 
 #include "GHOST_Types.h"
+#include "GHOST_IContext.h"
 #include "GHOST_ITimerTask.h"
 #include "GHOST_IWindow.h"
 
@@ -261,6 +262,20 @@ public:
 	 */
 	virtual GHOST_TSuccess disposeWindow(GHOST_IWindow *window) = 0;
 
+	/**
+	 * Create a new offscreen context.
+	 * Never explicitly delete the context, use disposeContext() instead.
+	 * \return  The new context (or 0 if creation failed).
+	 */
+	virtual GHOST_IContext *createOffscreenContext() = 0;
+
+	/**
+	 * Dispose of a context.
+	 * \param   context Pointer to the context to be disposed.
+	 * \return  Indication of success.
+	 */
+	virtual GHOST_TSuccess disposeContext(GHOST_IContext *context) = 0;
+
 	/**
 	 * Returns whether a window is valid.
 	 * \param   window Pointer to the window to be checked.
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index ce653188760..2fe94171cf8 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -132,6 +132,22 @@ void GHOST_GetAllDisplayDimensions(GHOST_SystemHandle systemhandle,
 	system->getAllDisplayDimensions(*width, *height);
 }
 
+GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle)
+{
+	GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
+
+	return (GHOST_ContextHandle) system->createOffscreenContext();
+}
+
+GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle,
+                                             GHOST_ContextHandle contexthandle)
+{
+	GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
+	GHOST_IContext *context = (GHOST_IContext *) contexthandle;
+
+	return system->disposeContext(context);
+}
+
 GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
                                       const char *title,
                                       GHOST_TInt32 left,
@@ -713,7 +729,19 @@ GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandl
 	return window->activateDrawingContext();
 }
 
+GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthandle)
+{
+	GHOST_IContext *context = (GHOST_IContext *) contexthandle;
+
+	return context->activateDrawingContext();
+}
+
+GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle)
+{
+	GHOST_IContext *context = (GHOST_IContext *) contexthandle;
 
+	return context->releaseDrawingContext();
+}
 
 GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle)
 {
diff --git a/intern/ghost/intern/GHOST_Context.h b/intern/ghost/intern/GHOST_Context.h
index 8776fa4764f..670b86d456f 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -33,6 +33,7 @@
 #ifndef __GHOST_CONTEXT_H__
 #define __GHOST_CONTEXT_H__
 
+#include "GHOST_IContext.h"
 #include "GHOST_Types.h"
 
 #include "glew-mx.h"
@@ -40,7 +41,7 @@
 #include <cstdlib> // for NULL
 
 
-class GHOST_Context
+class GHOST_Context : public GHOST_IContext
 {
 public:
 	/**
@@ -71,6 +72,12 @@ public:
 	 */
 	virtual GHOST_TSuccess activateDrawingContext() = 0;
 
+	/**
+	 * Release the drawing context of the calling thread.
+	 * \return  A boolean success indicator.
+	 */
+	virtual GHOST_TSuccess releaseDrawingContext()= 0;
+
 	/**
 	 * Call immediately after new to initialize.  If this fails then immediately delete the object.
 	 * \return Indication as to whether initialization has succeeded.
diff --git a/intern/ghost/intern/GHOST_ContextCGL.h b/intern/ghost/intern/GHOST_ContextCGL.h
index 6dcc4da0f0a..ea6eb485ce2 100644
--- a/intern/ghost/intern/GHOST_ContextCGL.h
+++ b/intern/ghost/intern/GHOST_ContextCGL.h
@@ -82,6 +82,12 @@ public:
 	 */
 	GHOST_TSuccess activateDrawingContext();
 
+	/**
+	 * Release the drawing context of the calling thread.
+	 * \return  A boolean success indicator.
+	 */
+	GHOST_TSuccess releaseDrawingContext();
+
 	/**
 	 * Call immediately after new to initialize.  If this fails then immediately delete the object.
 	 * \return Indication as to whether initialization has succeeded.
diff --git a/intern/ghost/intern/GHOST_ContextCGL.mm b/intern/ghost/intern/GHOST_ContextCGL.mm
index 03af3cc497e..46993a1cd1d 100644
--- a/intern/ghost/intern/GHOST_ContextCGL.mm
+++ b/intern/ghost/intern/GHOST_ContextCGL.mm
@@ -35,6 +35,8 @@
 
 #include <Cocoa/Cocoa.h>
 
+//#define GHOST_MULTITHREADED_OPENGL
+
 #ifdef GHOST_MULTITHREADED_OPENGL
 #include <OpenGL/OpenGL.h>
 #endif
@@ -62,8 +64,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:
@@ -73,7 +73,7 @@ GHOST_ContextCGL::GHOST_ContextCGL(
 			break;
 		case 3:
 			// Apple didn't implement 3.0 or 3.1
-			assert(contextMinorVersion == 2);
+			assert(contextMinorVersion == 3);
 			assert(contextProfileMask == GL_CONTEXT_CORE_PROFILE_BIT);
 			m_coreProfile = true;
 			break;
@@ -88,7 +88,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) {
@@ -16

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list