From d2b6bc2d04d919699509d466b801e763d0692634 Mon Sep 17 00:00:00 2001
From: Alessandro Febretti <febret@gmail.com>
Date: Sun, 8 Nov 2015 20:40:57 -0600
Subject: [PATCH 1/3] VERSION: 10.1

---
 include/version.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/version.h b/include/version.h
index 23310ff1..ec6eb78c 100644
--- a/include/version.h
+++ b/include/version.h
@@ -2,7 +2,7 @@
 #define __OMEGA_VERSION_
 
 #define OMEGA_VERSION_MAJOR 10
-#define OMEGA_VERSION_MINOR 0
+#define OMEGA_VERSION_MINOR 1
 #define OMEGA_VERSION_REVISION 0
 
 #define _VSTH(v) #v

From f0221428fd086171f80eb4601a9c0d5e33c5373f Mon Sep 17 00:00:00 2001
From: Alessandro Febretti <febret@gmail.com>
Date: Sun, 8 Nov 2015 20:42:03 -0600
Subject: [PATCH 2/3] FIX: GLEW Context initialization and use in Equalizer
 caused crash GLEW and Gpu context initialization now happen inside Window
 instead of Pipe and work correctly with equalizer internal implementation
 (and GLFW)

---
 include/omega/GpuResource.h                 | 94 ++++++++-------------
 src/displaySystems/Equalizer/CMakeLists.txt |  1 -
 src/displaySystems/Equalizer/PipeImpl.cpp   | 53 ------------
 src/displaySystems/Equalizer/WindowImpl.cpp | 18 ++--
 src/displaySystems/Equalizer/eqinternal.h   | 21 +----
 src/omega/GpuResource.cpp                   | 21 +++--
 6 files changed, 60 insertions(+), 148 deletions(-)
 delete mode 100644 src/displaySystems/Equalizer/PipeImpl.cpp

diff --git a/include/omega/GpuResource.h b/include/omega/GpuResource.h
index b8263f15..208b26ed 100644
--- a/include/omega/GpuResource.h
+++ b/include/omega/GpuResource.h
@@ -1,29 +1,3 @@
-/**************************************************************************************************
- * THE OMEGA LIB PROJECT
- *-------------------------------------------------------------------------------------------------
- * Copyright 2010-2015		Electronic Visualization Laboratory, University of Illinois at Chicago
- * Authors:										
- *  Alessandro Febretti		febret@gmail.com
- *-------------------------------------------------------------------------------------------------
- * Copyright (c) 2010-2015, Electronic Visualization Laboratory, University of Illinois at Chicago
- * All rights reserved.
- * Redistribution and use in source and binary forms, with or without modification, are permitted 
- * provided that the following conditions are met:
- * 
- * Redistributions of source code must retain the above copyright notice, this list of conditions 
- * and the following disclaimer. Redistributions in binary form must reproduce the above copyright 
- * notice, this list of conditions and the following disclaimer in the documentation and/or other 
- * materials provided with the distribution. 
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE  GOODS OR SERVICES; LOSS OF 
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *************************************************************************************************/
 /******************************************************************************
 * THE OMEGA LIB PROJECT
 *-----------------------------------------------------------------------------
@@ -82,44 +56,50 @@ typedef struct GLEWContextStruct GLEWContext;
 
 namespace omega
 {
-	///////////////////////////////////////////////////////////////////////////////////////////////
-	class OMEGA_API GpuContext: public ReferenceType
-	{
-	public:
-		static const unsigned int MaxContexts = 64;
-		enum TextureUnit {
-			TextureUnitInvalid = 0,
-			TextureUnit0 = GL_TEXTURE0, 
-			TextureUnit1 = GL_TEXTURE1,
-			TextureUnit2 = GL_TEXTURE2,
-			TextureUnit3 = GL_TEXTURE3 };
+    ///////////////////////////////////////////////////////////////////////////
+    class OMEGA_API GpuContext: public ReferenceType
+    {
+    public:
+        static const unsigned int MaxContexts = 64;
+        enum TextureUnit {
+            TextureUnitInvalid = 0,
+            TextureUnit0 = GL_TEXTURE0, 
+            TextureUnit1 = GL_TEXTURE1,
+            TextureUnit2 = GL_TEXTURE2,
+            TextureUnit3 = GL_TEXTURE3 };
 
-		GpuContext(bool initializeGlew = true);
-		~GpuContext();
+        //! Initializes a GPU context. If the passed GLEW context is null, 
+        //! a glew context will be created internally and GLEW will be 
+        //! initialized by this contstructor.
+        //! @remarks This method needs to be called from within a valid OpenGL
+        //! context.
+        GpuContext(GLEWContext* ctx = NULL);
+        ~GpuContext();
 
-		uint getId() { return myId; }
-		GLEWContext* getGlewContext() { return myGlewContext; }
+        uint getId() { return myId; }
+        GLEWContext* getGlewContext() { return myGlewContext; }
         void makeCurrent();
         //void setGlewContext(GLEWContext* ctx) { myGlewContext = ctx; }
 
-	private:
-		static uint mysNumContexts;
-		static Lock mysContextLock;
+    private:
+        static uint mysNumContexts;
+        static Lock mysContextLock;
 
-		uint myId;
-		GLEWContext* myGlewContext;
-	};
+        uint myId;
+        GLEWContext* myGlewContext;
+        bool myOwnGlewContext;
+    };
 
-	///////////////////////////////////////////////////////////////////////////////////////////////
-	class OMEGA_API GpuResource: public ReferenceType
-	{
-	public:
-		GpuResource(GpuContext* ctx): myContext(ctx) { }
-		GpuContext* getContext() { return myContext; }
-		virtual void dispose() = 0;
-	private:
-		GpuContext* myContext;
-	};
+    ///////////////////////////////////////////////////////////////////////////////////////////////
+    class OMEGA_API GpuResource: public ReferenceType
+    {
+    public:
+        GpuResource(GpuContext* ctx): myContext(ctx) { }
+        GpuContext* getContext() { return myContext; }
+        virtual void dispose() = 0;
+    private:
+        GpuContext* myContext;
+    };
 }; // namespace omega
 
 #endif
diff --git a/src/displaySystems/Equalizer/CMakeLists.txt b/src/displaySystems/Equalizer/CMakeLists.txt
index 4ea01519..15c47b2f 100644
--- a/src/displaySystems/Equalizer/CMakeLists.txt
+++ b/src/displaySystems/Equalizer/CMakeLists.txt
@@ -16,7 +16,6 @@ add_library(displaySystem_Equalizer SHARED
     ChannelImpl.cpp
     ConfigImpl.cpp
     NodeImpl.cpp
-    PipeImpl.cpp
     WindowImpl.cpp)
 
 target_link_libraries(displaySystem_Equalizer ${EQUALIZER_LIBS} omega)
diff --git a/src/displaySystems/Equalizer/PipeImpl.cpp b/src/displaySystems/Equalizer/PipeImpl.cpp
deleted file mode 100644
index e471cfdd..00000000
--- a/src/displaySystems/Equalizer/PipeImpl.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/**************************************************************************************************
- * THE OMEGA LIB PROJECT
- *-------------------------------------------------------------------------------------------------
- * Copyright 2010-2015		Electronic Visualization Laboratory, University of Illinois at Chicago
- * Authors:										
- *  Alessandro Febretti		febret@gmail.com
- *-------------------------------------------------------------------------------------------------
- * Copyright (c) 2010-2015, Electronic Visualization Laboratory, University of Illinois at Chicago
- * All rights reserved.
- * Redistribution and use in source and binary forms, with or without modification, are permitted 
- * provided that the following conditions are met:
- * 
- * Redistributions of source code must retain the above copyright notice, this list of conditions 
- * and the following disclaimer. Redistributions in binary form must reproduce the above copyright 
- * notice, this list of conditions and the following disclaimer in the documentation and/or other 
- * materials provided with the distribution. 
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE  GOODS OR SERVICES; LOSS OF 
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *************************************************************************************************/
-#include "eqinternal.h"
-
-using namespace omega;
-using namespace co::base;
-using namespace std;
-
-// Uncomment to print debug messages about client flow.
-//#define OMEGA_DEBUG_FLOW
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-PipeImpl::PipeImpl(eq::Node* parent): 
-	eq::Pipe(parent), myNode((NodeImpl*)parent)
-{
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-PipeImpl::~PipeImpl() 
-{
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-bool PipeImpl::configInit(const uint128_t& initID)
-{
-    // false = do not initialize GLEW in GpuContext. Equalizer takes care of Glew initialization.
-	myGpuContext = new GpuContext(false);
-	return Pipe::configInit(initID);
-}
diff --git a/src/displaySystems/Equalizer/WindowImpl.cpp b/src/displaySystems/Equalizer/WindowImpl.cpp
index c343c3e6..b5425bd6 100644
--- a/src/displaySystems/Equalizer/WindowImpl.cpp
+++ b/src/displaySystems/Equalizer/WindowImpl.cpp
@@ -61,6 +61,11 @@ omicron::Lock sInitLock;
 ///////////////////////////////////////////////////////////////////////////////
 bool WindowImpl::configInit(const uint128_t& initID)
 {
+    // Serialize window init execution since we are tinkering with x cursors on linux inside there.
+    sInitLock.lock();
+    bool res = Window::configInit(initID);
+    sInitLock.unlock();
+
     // Get the tile index from the window name.
     String name = getName();
     
@@ -78,15 +83,12 @@ bool WindowImpl::configInit(const uint128_t& initID)
     if(app)
     {
         myRenderer = new Renderer(Engine::instance());
-        myRenderer->setGpuContext(myPipe->getGpuContext());
+        myGpuContext = new GpuContext(const_cast<GLEWContext*>(this->glewGetContext()));
+        myRenderer->setGpuContext(myGpuContext);
         myRenderer->initialize();
     }
     else return false;
 
-    // Serialize window init execution since we are tinkering with x cursors on linux inside there.
-    sInitLock.lock();
-    bool res = Window::configInit(initID);
-    sInitLock.unlock();
     oflog(Debug, "[WindowImpl::configInit] <%1%> done", %initID);
     return res;
 }
@@ -208,10 +210,10 @@ void WindowImpl::frameStart(const uint128_t& frameID, const uint32_t frameNumber
     // NOTE: getting the glew context from the first window is correct since all
     // windows attached to the same pape share the same Glew (and OpenGL) contexts.
     // NOTE2: do NOT remove these two lines. rendering explodes if you do.
-    const GLEWContext* glewc = myRenderer->getGpuContext()->getGlewContext();
-    myRenderer->getGpuContext()->makeCurrent();
-    oassert(glewc != NULL);
+    const GLEWContext* glewc = myGpuContext->getGlewContext();
     //myRenderer->getGpuContext()->setGlewContext(glewc);
+    myGpuContext->makeCurrent();
+    oassert(glewc != NULL);
     glewSetContext(glewc);
 }
 
diff --git a/src/displaySystems/Equalizer/eqinternal.h b/src/displaySystems/Equalizer/eqinternal.h
index f3c0eaf3..c92bf82a 100644
--- a/src/displaySystems/Equalizer/eqinternal.h
+++ b/src/displaySystems/Equalizer/eqinternal.h
@@ -168,24 +168,6 @@ class NodeImpl: public eq::Node
     //FrameData myFrameData;
 };
 
-///////////////////////////////////////////////////////////////////////////////
-//! @internal
-class PipeImpl: public eq::Pipe
-{
-public:
-    //EIGEN_MAKE_ALIGNED_OPERATOR_NEW
-public:
-    PipeImpl(eq::Node* parent);
-    GpuContext* getGpuContext() { return myGpuContext.get(); }
-
-protected:
-    virtual ~PipeImpl();
-    virtual bool configInit(const uint128_t& initID);
-private:
-    NodeImpl* myNode;
-    omicron::Ref<GpuContext> myGpuContext;
-};
-
 ///////////////////////////////////////////////////////////////////////////////
 //! @internal
 //! A Window represents an on-screen or off-screen drawable. A drawable is a 2D rendering surface, 
@@ -213,6 +195,7 @@ class WindowImpl: public eq::Window
 private:
     PipeImpl* myPipe;
     omicron::Ref<Renderer> myRenderer;
+    omicron::Ref<GpuContext> myGpuContext;
     DisplayTileConfig* myTile;
     bool myVisible;
     Rect myCurrentRect;
@@ -262,8 +245,6 @@ class EqualizerNodeFactory: public eq::NodeFactory
         { return new ChannelImpl( parent ); }
     virtual eq::Window* createWindow(eq::Pipe* parent)
         { return new WindowImpl(parent); }
-    virtual eq::Pipe* createPipe(eq::Node* parent)
-        { return new PipeImpl(parent); }
     virtual eq::Node* createNode( eq::Config* parent )
        { return new NodeImpl( parent ); }
 };
diff --git a/src/omega/GpuResource.cpp b/src/omega/GpuResource.cpp
index 00acad6b..e95c8450 100644
--- a/src/omega/GpuResource.cpp
+++ b/src/omega/GpuResource.cpp
@@ -32,21 +32,24 @@ uint GpuContext::mysNumContexts = 0;
 Lock GpuContext::mysContextLock = Lock();
 
 ///////////////////////////////////////////////////////////////////////////////
-GpuContext::GpuContext(bool initializeGlew)
+GpuContext::GpuContext(GLEWContext* ctx)
 {
-	mysContextLock.lock();
-	myId = mysNumContexts++;
+    myOwnGlewContext = false;
+    mysContextLock.lock();
+    myId = mysNumContexts++;
 
-	// Initialize Glew
-	myGlewContext = new GLEWContext();
-    glewSetContext(myGlewContext);
-    if(initializeGlew)
+    // Initialize Glew
+    myGlewContext = ctx;
+    if(myGlewContext == NULL)
     {
+        myGlewContext = new GLEWContext();
+        myOwnGlewContext = true;
+        glewSetContext(myGlewContext);
         oflog(Debug, "[GpuContext::GpuContext] <%1%> Glew init", %myId);
         glewInit();
     }
 
-	mysContextLock.unlock();
+    mysContextLock.unlock();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -59,6 +62,6 @@ void GpuContext::makeCurrent()
 ///////////////////////////////////////////////////////////////////////////////
 GpuContext::~GpuContext()
 {
-    delete myGlewContext;
+    if(myOwnGlewContext) delete myGlewContext;
     myGlewContext = NULL;
 }

From 7ca101356ea779dbf2028f44fb157dc28a6b3f6f Mon Sep 17 00:00:00 2001
From: Alessandro Febretti <febret@gmail.com>
Date: Sun, 8 Nov 2015 20:48:57 -0600
Subject: [PATCH 3/3] FIX: build

---
 src/displaySystems/Equalizer/WindowImpl.cpp | 2 +-
 src/displaySystems/Equalizer/eqinternal.h   | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/displaySystems/Equalizer/WindowImpl.cpp b/src/displaySystems/Equalizer/WindowImpl.cpp
index b5425bd6..0a5da1ce 100644
--- a/src/displaySystems/Equalizer/WindowImpl.cpp
+++ b/src/displaySystems/Equalizer/WindowImpl.cpp
@@ -47,7 +47,7 @@ using namespace std;
     
 ///////////////////////////////////////////////////////////////////////////////
 WindowImpl::WindowImpl(eq::Pipe* parent): 
-    eq::Window(parent), myPipe((PipeImpl*)parent),
+    eq::Window(parent),
     myVisible(false), mySkipResize(false)
     //myIndex(Vector2i::Zero())
 {
diff --git a/src/displaySystems/Equalizer/eqinternal.h b/src/displaySystems/Equalizer/eqinternal.h
index c92bf82a..9c8b1122 100644
--- a/src/displaySystems/Equalizer/eqinternal.h
+++ b/src/displaySystems/Equalizer/eqinternal.h
@@ -193,7 +193,6 @@ class WindowImpl: public eq::Window
     bool processEvent(const eq::Event& event);
 
 private:
-    PipeImpl* myPipe;
     omicron::Ref<Renderer> myRenderer;
     omicron::Ref<GpuContext> myGpuContext;
     DisplayTileConfig* myTile;