1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-15 00:24:19 +00:00

Changed OpenGLContext to take a native context handle as its sharing context.

This commit is contained in:
jules 2012-05-05 18:33:20 +01:00
parent a5a4e69f37
commit 68024fb8aa
7 changed files with 20 additions and 26 deletions

View file

@ -38,7 +38,7 @@ class OpenGLContext::NativeContext
public:
NativeContext (Component& component_,
const OpenGLPixelFormat& pixelFormat,
const NativeContext* contextToShareWith)
void* /*contextToShareWith*/)
: component (component_),
isInsideGLCallback (false)
{

View file

@ -46,7 +46,7 @@ class OpenGLContext::NativeContext
public:
NativeContext (Component& component,
const OpenGLPixelFormat& pixelFormat,
const NativeContext* const contextToShareWith)
void* contextToShareWith)
: frameBufferHandle (0), colorBufferHandle (0), depthBufferHandle (0),
lastWidth (0), lastHeight (0), needToRebuildBuffers (false),
swapFrames (0), useDepthBuffer (pixelFormat.depthBufferBits > 0)
@ -73,7 +73,7 @@ public:
const NSUInteger type = kEAGLRenderingAPIOpenGLES2;
if (contextToShareWith != nullptr)
[context initWithAPI: type sharegroup: [contextToShareWith->context sharegroup]];
[context initWithAPI: type sharegroup: [(EAGLContext*) contextToShareWith sharegroup]];
else
[context initWithAPI: type];
@ -103,7 +103,7 @@ public:
}
bool createdOk() const noexcept { return getRawContext() != nullptr; }
void* getRawContext() const noexcept { return glLayer; }
void* getRawContext() const noexcept { return context; }
GLuint getFrameBufferID() const noexcept { return frameBufferHandle; }
bool makeActive() const noexcept

View file

@ -32,7 +32,7 @@ class OpenGLContext::NativeContext
public:
NativeContext (Component& component,
const OpenGLPixelFormat& pixelFormat,
const NativeContext* contextToShareWith_)
void* contextToShareWith_)
: renderContext (0), embeddedWindow (0), swapFrames (0), bestVisual (0),
contextToShareWith (contextToShareWith_)
{
@ -106,9 +106,7 @@ public:
void initialiseOnRenderThread()
{
ScopedXLock xlock;
renderContext = glXCreateContext (display, bestVisual,
contextToShareWith != nullptr ? contextToShareWith->renderContext : 0,
GL_TRUE);
renderContext = glXCreateContext (display, bestVisual, contextToShareWith, GL_TRUE);
makeActive();
}
@ -183,7 +181,7 @@ private:
int swapFrames;
Rectangle<int> bounds;
XVisualInfo* bestVisual;
const NativeContext* contextToShareWith;
void* contextToShareWith;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeContext);
};

View file

@ -116,7 +116,7 @@ class OpenGLContext::NativeContext
public:
NativeContext (Component& component,
const OpenGLPixelFormat& pixelFormat,
const NativeContext* contextToShareWith)
void* contextToShareWith)
{
NSOpenGLPixelFormatAttribute attribs[] =
{
@ -140,11 +140,8 @@ public:
view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
pixelFormat: format];
NSOpenGLContext* const sharedContext
= contextToShareWith != nullptr ? contextToShareWith->renderContext : nil;
renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
shareContext: sharedContext] autorelease];
shareContext: (NSOpenGLContext*) contextToShareWith] autorelease];
setSwapInterval (1);

View file

@ -31,7 +31,7 @@ class OpenGLContext::NativeContext
public:
NativeContext (Component& component,
const OpenGLPixelFormat& pixelFormat,
const NativeContext* contextToShareWith)
void* contextToShareWith)
{
createNativeWindow (component);
@ -68,7 +68,7 @@ public:
}
if (contextToShareWith != nullptr)
wglShareLists (contextToShareWith->renderContext, renderContext);
wglShareLists (contextToShareWith, renderContext);
component.getTopLevelComponent()->repaint();
component.repaint();

View file

@ -30,7 +30,7 @@ public:
CachedImage (OpenGLContext& context_,
Component& component_,
const OpenGLPixelFormat& pixelFormat,
const OpenGLContext* contextToShareWith)
void* contextToShareWith)
: Thread ("OpenGL Rendering"),
context (context_), component (component_),
#if JUCE_OPENGL_ES
@ -40,9 +40,7 @@ public:
#endif
needsUpdate (true)
{
nativeContext = new NativeContext (component, pixelFormat,
contextToShareWith != nullptr ? contextToShareWith->nativeContext
: nullptr);
nativeContext = new NativeContext (component, pixelFormat, contextToShareWith);
if (nativeContext->createdOk())
{
@ -487,13 +485,13 @@ void OpenGLContext::setPixelFormat (const OpenGLPixelFormat& preferredPixelForma
pixelFormat = preferredPixelFormat;
}
void OpenGLContext::setContextToShareWith (const OpenGLContext* context) noexcept
void OpenGLContext::setNativeSharedContext (void* nativeContextToShareWith) noexcept
{
// This method must not be called when the context has already been attached!
// Call it before attaching your context, or use detach() first, before calling this!
jassert (nativeContext == nullptr);
contextToShareWith = context;
contextToShareWith = nativeContextToShareWith;
}
void OpenGLContext::attachTo (Component& component)

View file

@ -86,11 +86,12 @@ public:
void setPixelFormat (const OpenGLPixelFormat& preferredPixelFormat) noexcept;
/** Provides a context with which you'd like this context's resources to be shared.
The object passed-in here must not be deleted while the context may still be
using it! To turn off sharing, you can call this method with a null pointer.
The object passed-in here is a platform-dependent native context object, and
must not be deleted while this context may still be using it! To turn off sharing,
you can call this method with a null pointer.
Note: This must be called BEFORE attaching your context to a target component!
*/
void setContextToShareWith (const OpenGLContext* contextToShareWith) noexcept;
void setNativeSharedContext (void* nativeContextToShareWith) noexcept;
//==============================================================================
/** Attaches the context to a target component.
@ -243,7 +244,7 @@ private:
OpenGLRenderer* renderer;
ScopedPointer<Attachment> attachment;
OpenGLPixelFormat pixelFormat;
const OpenGLContext* contextToShareWith;
void* contextToShareWith;
int width, height;
bool renderComponents;