Skip to content

Commit f022142

Browse files
committed
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)
1 parent d2b6bc2 commit f022142

File tree

6 files changed

+60
-148
lines changed

6 files changed

+60
-148
lines changed

include/omega/GpuResource.h

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
/**************************************************************************************************
2-
* THE OMEGA LIB PROJECT
3-
*-------------------------------------------------------------------------------------------------
4-
* Copyright 2010-2015 Electronic Visualization Laboratory, University of Illinois at Chicago
5-
* Authors:
6-
* Alessandro Febretti [email protected]
7-
*-------------------------------------------------------------------------------------------------
8-
* Copyright (c) 2010-2015, Electronic Visualization Laboratory, University of Illinois at Chicago
9-
* All rights reserved.
10-
* Redistribution and use in source and binary forms, with or without modification, are permitted
11-
* provided that the following conditions are met:
12-
*
13-
* Redistributions of source code must retain the above copyright notice, this list of conditions
14-
* and the following disclaimer. Redistributions in binary form must reproduce the above copyright
15-
* notice, this list of conditions and the following disclaimer in the documentation and/or other
16-
* materials provided with the distribution.
17-
*
18-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19-
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20-
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21-
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23-
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24-
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25-
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26-
*************************************************************************************************/
271
/******************************************************************************
282
* THE OMEGA LIB PROJECT
293
*-----------------------------------------------------------------------------
@@ -82,44 +56,50 @@ typedef struct GLEWContextStruct GLEWContext;
8256

8357
namespace omega
8458
{
85-
///////////////////////////////////////////////////////////////////////////////////////////////
86-
class OMEGA_API GpuContext: public ReferenceType
87-
{
88-
public:
89-
static const unsigned int MaxContexts = 64;
90-
enum TextureUnit {
91-
TextureUnitInvalid = 0,
92-
TextureUnit0 = GL_TEXTURE0,
93-
TextureUnit1 = GL_TEXTURE1,
94-
TextureUnit2 = GL_TEXTURE2,
95-
TextureUnit3 = GL_TEXTURE3 };
59+
///////////////////////////////////////////////////////////////////////////
60+
class OMEGA_API GpuContext: public ReferenceType
61+
{
62+
public:
63+
static const unsigned int MaxContexts = 64;
64+
enum TextureUnit {
65+
TextureUnitInvalid = 0,
66+
TextureUnit0 = GL_TEXTURE0,
67+
TextureUnit1 = GL_TEXTURE1,
68+
TextureUnit2 = GL_TEXTURE2,
69+
TextureUnit3 = GL_TEXTURE3 };
9670

97-
GpuContext(bool initializeGlew = true);
98-
~GpuContext();
71+
//! Initializes a GPU context. If the passed GLEW context is null,
72+
//! a glew context will be created internally and GLEW will be
73+
//! initialized by this contstructor.
74+
//! @remarks This method needs to be called from within a valid OpenGL
75+
//! context.
76+
GpuContext(GLEWContext* ctx = NULL);
77+
~GpuContext();
9978

100-
uint getId() { return myId; }
101-
GLEWContext* getGlewContext() { return myGlewContext; }
79+
uint getId() { return myId; }
80+
GLEWContext* getGlewContext() { return myGlewContext; }
10281
void makeCurrent();
10382
//void setGlewContext(GLEWContext* ctx) { myGlewContext = ctx; }
10483

105-
private:
106-
static uint mysNumContexts;
107-
static Lock mysContextLock;
84+
private:
85+
static uint mysNumContexts;
86+
static Lock mysContextLock;
10887

109-
uint myId;
110-
GLEWContext* myGlewContext;
111-
};
88+
uint myId;
89+
GLEWContext* myGlewContext;
90+
bool myOwnGlewContext;
91+
};
11292

113-
///////////////////////////////////////////////////////////////////////////////////////////////
114-
class OMEGA_API GpuResource: public ReferenceType
115-
{
116-
public:
117-
GpuResource(GpuContext* ctx): myContext(ctx) { }
118-
GpuContext* getContext() { return myContext; }
119-
virtual void dispose() = 0;
120-
private:
121-
GpuContext* myContext;
122-
};
93+
///////////////////////////////////////////////////////////////////////////////////////////////
94+
class OMEGA_API GpuResource: public ReferenceType
95+
{
96+
public:
97+
GpuResource(GpuContext* ctx): myContext(ctx) { }
98+
GpuContext* getContext() { return myContext; }
99+
virtual void dispose() = 0;
100+
private:
101+
GpuContext* myContext;
102+
};
123103
}; // namespace omega
124104

125105
#endif

src/displaySystems/Equalizer/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ add_library(displaySystem_Equalizer SHARED
1616
ChannelImpl.cpp
1717
ConfigImpl.cpp
1818
NodeImpl.cpp
19-
PipeImpl.cpp
2019
WindowImpl.cpp)
2120

2221
target_link_libraries(displaySystem_Equalizer ${EQUALIZER_LIBS} omega)

src/displaySystems/Equalizer/PipeImpl.cpp

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/displaySystems/Equalizer/WindowImpl.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ omicron::Lock sInitLock;
6161
///////////////////////////////////////////////////////////////////////////////
6262
bool WindowImpl::configInit(const uint128_t& initID)
6363
{
64+
// Serialize window init execution since we are tinkering with x cursors on linux inside there.
65+
sInitLock.lock();
66+
bool res = Window::configInit(initID);
67+
sInitLock.unlock();
68+
6469
// Get the tile index from the window name.
6570
String name = getName();
6671

@@ -78,15 +83,12 @@ bool WindowImpl::configInit(const uint128_t& initID)
7883
if(app)
7984
{
8085
myRenderer = new Renderer(Engine::instance());
81-
myRenderer->setGpuContext(myPipe->getGpuContext());
86+
myGpuContext = new GpuContext(const_cast<GLEWContext*>(this->glewGetContext()));
87+
myRenderer->setGpuContext(myGpuContext);
8288
myRenderer->initialize();
8389
}
8490
else return false;
8591

86-
// Serialize window init execution since we are tinkering with x cursors on linux inside there.
87-
sInitLock.lock();
88-
bool res = Window::configInit(initID);
89-
sInitLock.unlock();
9092
oflog(Debug, "[WindowImpl::configInit] <%1%> done", %initID);
9193
return res;
9294
}
@@ -208,10 +210,10 @@ void WindowImpl::frameStart(const uint128_t& frameID, const uint32_t frameNumber
208210
// NOTE: getting the glew context from the first window is correct since all
209211
// windows attached to the same pape share the same Glew (and OpenGL) contexts.
210212
// NOTE2: do NOT remove these two lines. rendering explodes if you do.
211-
const GLEWContext* glewc = myRenderer->getGpuContext()->getGlewContext();
212-
myRenderer->getGpuContext()->makeCurrent();
213-
oassert(glewc != NULL);
213+
const GLEWContext* glewc = myGpuContext->getGlewContext();
214214
//myRenderer->getGpuContext()->setGlewContext(glewc);
215+
myGpuContext->makeCurrent();
216+
oassert(glewc != NULL);
215217
glewSetContext(glewc);
216218
}
217219

src/displaySystems/Equalizer/eqinternal.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,6 @@ class NodeImpl: public eq::Node
168168
//FrameData myFrameData;
169169
};
170170

171-
///////////////////////////////////////////////////////////////////////////////
172-
//! @internal
173-
class PipeImpl: public eq::Pipe
174-
{
175-
public:
176-
//EIGEN_MAKE_ALIGNED_OPERATOR_NEW
177-
public:
178-
PipeImpl(eq::Node* parent);
179-
GpuContext* getGpuContext() { return myGpuContext.get(); }
180-
181-
protected:
182-
virtual ~PipeImpl();
183-
virtual bool configInit(const uint128_t& initID);
184-
private:
185-
NodeImpl* myNode;
186-
omicron::Ref<GpuContext> myGpuContext;
187-
};
188-
189171
///////////////////////////////////////////////////////////////////////////////
190172
//! @internal
191173
//! 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
213195
private:
214196
PipeImpl* myPipe;
215197
omicron::Ref<Renderer> myRenderer;
198+
omicron::Ref<GpuContext> myGpuContext;
216199
DisplayTileConfig* myTile;
217200
bool myVisible;
218201
Rect myCurrentRect;
@@ -262,8 +245,6 @@ class EqualizerNodeFactory: public eq::NodeFactory
262245
{ return new ChannelImpl( parent ); }
263246
virtual eq::Window* createWindow(eq::Pipe* parent)
264247
{ return new WindowImpl(parent); }
265-
virtual eq::Pipe* createPipe(eq::Node* parent)
266-
{ return new PipeImpl(parent); }
267248
virtual eq::Node* createNode( eq::Config* parent )
268249
{ return new NodeImpl( parent ); }
269250
};

src/omega/GpuResource.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,24 @@ uint GpuContext::mysNumContexts = 0;
3232
Lock GpuContext::mysContextLock = Lock();
3333

3434
///////////////////////////////////////////////////////////////////////////////
35-
GpuContext::GpuContext(bool initializeGlew)
35+
GpuContext::GpuContext(GLEWContext* ctx)
3636
{
37-
mysContextLock.lock();
38-
myId = mysNumContexts++;
37+
myOwnGlewContext = false;
38+
mysContextLock.lock();
39+
myId = mysNumContexts++;
3940

40-
// Initialize Glew
41-
myGlewContext = new GLEWContext();
42-
glewSetContext(myGlewContext);
43-
if(initializeGlew)
41+
// Initialize Glew
42+
myGlewContext = ctx;
43+
if(myGlewContext == NULL)
4444
{
45+
myGlewContext = new GLEWContext();
46+
myOwnGlewContext = true;
47+
glewSetContext(myGlewContext);
4548
oflog(Debug, "[GpuContext::GpuContext] <%1%> Glew init", %myId);
4649
glewInit();
4750
}
4851

49-
mysContextLock.unlock();
52+
mysContextLock.unlock();
5053
}
5154

5255
///////////////////////////////////////////////////////////////////////////////
@@ -59,6 +62,6 @@ void GpuContext::makeCurrent()
5962
///////////////////////////////////////////////////////////////////////////////
6063
GpuContext::~GpuContext()
6164
{
62-
delete myGlewContext;
65+
if(myOwnGlewContext) delete myGlewContext;
6366
myGlewContext = NULL;
6467
}

0 commit comments

Comments
 (0)