Commit: 6493ee6d566c9a8c2489bbfe78284d197cd0567c
Author: Clément Foucault
Date:   Fri Feb 9 19:07:56 2018 +0100
Branches: temp-drawcontext
https://developer.blender.org/rB6493ee6d566c9a8c2489bbfe78284d197cd0567c

GHOST: Add interface to manage offscreen opengl contexts.

Only the X11 backend is present in this commit.

This is needed for the multiwindow support.

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

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_ContextGLX.cpp
M       intern/ghost/intern/GHOST_SystemX11.cpp
M       intern/ghost/intern/GHOST_SystemX11.h

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

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..0d40b7217d9 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_CreateOffscreenContext(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_DisposeOffscreenContext(GHOST_SystemHandle 
systemhandle,
+                                                    GHOST_ContextHandle 
contexthandle);
+
 /**
  * Returns the window user data.
  * \param windowhandle The handle to the window
@@ -710,6 +728,13 @@ 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_ActivateOffscreenContext(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..33cbbe7bacd
--- /dev/null
+++ b/intern/ghost/GHOST_IContext.h
@@ -0,0 +1,72 @@
+/*
+ * ***** 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    Fev 9, 2012
+ */
+class GHOST_IContext
+{
+public:
+       /**
+        * Destructor.
+        */
+       virtual ~GHOST_IContext()
+       {
+       }
+
+       /**
+        * Activates the drawing context.
+        * \return  A boolean success indicator.
+        */
+       virtual GHOST_TSuccess activateDrawingContext() = 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..1306070ea01 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_CreateOffscreenContext(GHOST_SystemHandle 
systemhandle)
+{
+       GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
+
+       return (GHOST_ContextHandle) system->createOffscreenContext();
+}
+
+GHOST_TSuccess GHOST_DisposeOffscreenContext(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,12 @@ GHOST_TSuccess 
GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandl
        return window->activateDrawingContext();
 }
 
+GHOST_TSuccess GHOST_ActivateOffscreenContext(GHOST_ContextHandle 
contexthandle)
+{
+       GHOST_IContext *context = (GHOST_IContext *) contexthandle;
 
+       return context->activateDrawingContext();
+}
 
 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..632240e48f0 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:
        /**
diff --git a/intern/ghost/intern/GHOST_ContextGLX.cpp 
b/intern/ghost/intern/GHOST_ContextGLX.cpp
index 061ac29945b..65f285a64b0 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.cpp
+++ b/intern/ghost/intern/GHOST_ContextGLX.cpp
@@ -74,7 +74,6 @@ GHOST_ContextGLX::GHOST_ContextGLX(
       m_contextResetNotificationStrategy(contextResetNotificationStrategy),
       m_context(None)
 {
-       assert(m_window  != 0);
        assert(m_display != NULL);
 }
 
@@ -288,8 +287,10 @@ const bool GLXEW_ARB_create_context_robustness =
                // which means we cannot use glX extensions until after we 
create a context
                initContextGLXEW();
 
-               initClearGL();
-               ::glXSwapBuffers(m_display, m_window);
+               if (m_window) {
+                       initClearGL();
+                       ::glXSwapBuffers(m_display, m_window);
+               }
 
                /* re initialize to get the extensions properly */
                initContextGLXEW();
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp 
b/intern/ghost/intern/GHOST_SystemX11.cpp
index 9b617a34e1a..e04efdf74bf 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -57,6 +57,12 @@
 
 #include "GHOST_Debug.h"
 
+#if defined(WITH_GL_EGL)
+#  include "GHOST_ContextEGL.h"
+#else
+#  include "GHOST_ContextGLX.h"
+#endif
+
 #ifdef WITH_XF86KEYSYM
 #include <X11/XF86keysym.h>
 #endif
@@ -379,6 +385,98 @@ createWindow(const STR_String& title,
        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_SystemX11::
+createOffscreenContext()
+{
+       // During development:
+       //   try 4.x compatibility profile
+       //   try 3.3 compatibility profile
+       //   fall back to 3.0 if needed
+       //
+       // Final Blender 2.8:
+       //   try 4.x core profile
+       //   try 3.3 core profile
+       //   no fallbacks
+
+#if defined(WITH_GL_PROFILE_CORE)
+       {
+               const char *version_major = 
(char*)glewGetString(GLEW_VERSION_MAJOR);
+               if (version_major != NULL && version_major[0] == '1') {
+                       fprintf(stderr, "Error: GLEW version 2.0 and above is 
required.\n");
+                       abort();
+               }
+       }
+#endif
+
+       const int profile_mask =
+#if defined(WITH_GL_PROFILE_CORE)
+               GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
+#elif defined(WITH_GL_PROFILE_COMPAT)
+               GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
+#else
+#  error // must specify either core or compat at build time
+#endif
+
+       GHOST_Context *context;
+
+       for (int minor = 5; minor >= 0; --minor) {
+               context = new GHOST_ContextGLX(
+                       false,
+                       0,
+                       (Window)NULL,
+                       m_display,
+                       (GLXFBConfig)NULL,
+                       profile_mask,
+                       4, minor,
+                       GHOST_OPENGL_GLX_CONTEXT_FLAGS | (false ? 
GLX_CONTEXT_DEBUG_BIT_ARB : 0),
+                       GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY);
+
+               if (context->initializeDrawingContext())
+                       return context;
+               else
+                       delete context;
+       }
+
+       context = new GHOST_ContextGLX(
+               

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to