From 272bcbcaab6e89e11b58b6a52e43e52be8bd7550 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 11 Mar 2014 10:24:31 +0000 Subject: [PATCH] Added a method OpenGLContext::setOpenGLVersionRequired, which can be used to request a v3.2 context. --- modules/juce_opengl/juce_opengl.h | 9 +++++-- .../native/juce_OpenGLExtensions.h | 27 +++++++++++-------- .../juce_opengl/native/juce_OpenGL_android.h | 3 ++- modules/juce_opengl/native/juce_OpenGL_ios.h | 3 ++- .../juce_opengl/native/juce_OpenGL_linux.h | 3 ++- modules/juce_opengl/native/juce_OpenGL_osx.h | 4 ++- .../juce_opengl/native/juce_OpenGL_win32.h | 3 ++- .../juce_opengl/opengl/juce_OpenGLContext.cpp | 12 ++++++--- .../juce_opengl/opengl/juce_OpenGLContext.h | 13 +++++++++ 9 files changed, 56 insertions(+), 21 deletions(-) diff --git a/modules/juce_opengl/juce_opengl.h b/modules/juce_opengl/juce_opengl.h index d4f675024c..a869506d7f 100644 --- a/modules/juce_opengl/juce_opengl.h +++ b/modules/juce_opengl/juce_opengl.h @@ -58,8 +58,13 @@ #elif JUCE_IOS #include #elif JUCE_MAC - #include - #include "OpenGL/glext.h" + #if defined (MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MIN_ALLOWED >= MAC_OS_X_VERSION_10_7) + #include + #include + #else + #include + #include "OpenGL/glext.h" + #endif #elif JUCE_ANDROID #include #endif diff --git a/modules/juce_opengl/native/juce_OpenGLExtensions.h b/modules/juce_opengl/native/juce_OpenGLExtensions.h index 5494bbe6ea..52e65500d1 100644 --- a/modules/juce_opengl/native/juce_OpenGLExtensions.h +++ b/modules/juce_opengl/native/juce_OpenGLExtensions.h @@ -98,23 +98,28 @@ struct OpenGLExtensionFunctions typedef pointer_sized_int GLintptr; #endif - #if JUCE_WINDOWS || JUCE_LINUX - #if JUCE_WINDOWS - #define JUCE_GL_STDCALL __stdcall - #else - #define JUCE_GL_STDCALL - #endif - - #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) typedef returnType (JUCE_GL_STDCALL *type_ ## name) params; type_ ## name name; + //============================================================================== + #if JUCE_WINDOWS + #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) typedef returnType (__stdcall *type_ ## name) params; type_ ## name name; JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION, JUCE_DECLARE_GL_FUNCTION) + //============================================================================== + #elif JUCE_LINUX + #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) typedef returnType (*type_ ## name) params; type_ ## name name; + JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION, JUCE_DECLARE_GL_FUNCTION) + //============================================================================== #elif JUCE_OPENGL_ES #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) static returnType name params; JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION, JUCE_DECLARE_GL_FUNCTION) + //============================================================================== #else #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) inline static returnType name params { return ::name callparams; } - #define JUCE_DECLARE_GL_FUNCTION_EXT(name, returnType, params, callparams) inline static returnType name params { return ::name ## EXT callparams; } - JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION, JUCE_DECLARE_GL_FUNCTION_EXT) - #undef JUCE_DECLARE_GL_FUNCTION_EXT + #if defined (MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MIN_ALLOWED >= MAC_OS_X_VERSION_10_7) + JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION, JUCE_DECLARE_GL_FUNCTION) + #else + #define JUCE_DECLARE_GL_FUNCTION_EXT(name, returnType, params, callparams) inline static returnType name params { return ::name ## EXT callparams; } + JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION, JUCE_DECLARE_GL_FUNCTION_EXT) + #undef JUCE_DECLARE_GL_FUNCTION_EXT + #endif #endif #undef JUCE_DECLARE_GL_FUNCTION diff --git a/modules/juce_opengl/native/juce_OpenGL_android.h b/modules/juce_opengl/native/juce_OpenGL_android.h index f7c35e1489..18daad223d 100644 --- a/modules/juce_opengl/native/juce_OpenGL_android.h +++ b/modules/juce_opengl/native/juce_OpenGL_android.h @@ -38,7 +38,8 @@ public: NativeContext (Component& comp, const OpenGLPixelFormat& pixelFormat, void* /*contextToShareWith*/, - bool /*useMultisampling*/) + bool /*useMultisampling*/, + OpenGLVersion) : component (comp), isInsideGLCallback (false) { diff --git a/modules/juce_opengl/native/juce_OpenGL_ios.h b/modules/juce_opengl/native/juce_OpenGL_ios.h index 21f9fc241d..9715f6b14c 100644 --- a/modules/juce_opengl/native/juce_OpenGL_ios.h +++ b/modules/juce_opengl/native/juce_OpenGL_ios.h @@ -46,7 +46,8 @@ public: NativeContext (Component& component, const OpenGLPixelFormat& pixFormat, void* contextToShare, - bool multisampling) + bool multisampling, + OpenGLVersion) : frameBufferHandle (0), colorBufferHandle (0), depthBufferHandle (0), msaaColorHandle (0), msaaBufferHandle (0), lastWidth (0), lastHeight (0), needToRebuildBuffers (false), diff --git a/modules/juce_opengl/native/juce_OpenGL_linux.h b/modules/juce_opengl/native/juce_OpenGL_linux.h index 0d47e8175b..1b3d97457b 100644 --- a/modules/juce_opengl/native/juce_OpenGL_linux.h +++ b/modules/juce_opengl/native/juce_OpenGL_linux.h @@ -32,7 +32,8 @@ public: NativeContext (Component& component, const OpenGLPixelFormat& pixelFormat, void* shareContext, - bool /*useMultisampling*/) + bool /*useMultisampling*/, + OpenGLVersion) : renderContext (0), embeddedWindow (0), swapFrames (0), bestVisual (0), contextToShareWith (shareContext) { diff --git a/modules/juce_opengl/native/juce_OpenGL_osx.h b/modules/juce_opengl/native/juce_OpenGL_osx.h index ab7b789d6a..566db25578 100644 --- a/modules/juce_opengl/native/juce_OpenGL_osx.h +++ b/modules/juce_opengl/native/juce_OpenGL_osx.h @@ -28,11 +28,13 @@ public: NativeContext (Component& component, const OpenGLPixelFormat& pixFormat, void* contextToShare, - bool /*useMultisampling*/) + bool /*useMultisampling*/, + OpenGLVersion version) : lastSwapTime (0), minSwapTimeMs (0), underrunCounter (0) { NSOpenGLPixelFormatAttribute attribs[] = { + NSOpenGLPFAOpenGLProfile, version >= openGL3_2 ? NSOpenGLProfileVersion3_2Core : NSOpenGLProfileVersionLegacy, NSOpenGLPFADoubleBuffer, NSOpenGLPFAMPSafe, NSOpenGLPFAClosestPolicy, diff --git a/modules/juce_opengl/native/juce_OpenGL_win32.h b/modules/juce_opengl/native/juce_OpenGL_win32.h index 1bf5bd9e8d..c0999d02f0 100644 --- a/modules/juce_opengl/native/juce_OpenGL_win32.h +++ b/modules/juce_opengl/native/juce_OpenGL_win32.h @@ -31,7 +31,8 @@ public: NativeContext (Component& component, const OpenGLPixelFormat& pixelFormat, void* contextToShareWith, - bool /*useMultisampling*/) + bool /*useMultisampling*/, + OpenGLVersion) { createNativeWindow (component); diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index 98b52df451..5045fb6d2a 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -39,7 +39,8 @@ public: hasInitialised (false), needsUpdate (1), lastMMLockReleaseTime (0) { - nativeContext = new NativeContext (component, pixFormat, contextToShare, c.useMultisampling); + nativeContext = new NativeContext (component, pixFormat, contextToShare, + c.useMultisampling, c.versionRequired); if (nativeContext->createdOk()) context.nativeContext = nativeContext; @@ -553,8 +554,8 @@ private: //============================================================================== OpenGLContext::OpenGLContext() : nativeContext (nullptr), renderer (nullptr), currentRenderScale (1.0), - contextToShareWith (nullptr), renderComponents (true), - useMultisampling (false), continuousRepaint (false) + contextToShareWith (nullptr), versionRequired (OpenGLContext::defaultGLVersion), + renderComponents (true), useMultisampling (false), continuousRepaint (false) { } @@ -613,6 +614,11 @@ void OpenGLContext::setMultisamplingEnabled (bool b) noexcept useMultisampling = b; } +void OpenGLContext::setOpenGLVersionRequired (OpenGLVersion v) noexcept +{ + versionRequired = v; +} + void OpenGLContext::attachTo (Component& component) { component.repaint(); diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.h b/modules/juce_opengl/opengl/juce_OpenGLContext.h index e0abbb44b5..c72e47c00b 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.h +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.h @@ -109,6 +109,18 @@ public: /** Returns true if shaders can be used in this context. */ bool areShadersAvailable() const; + /** OpenGL versions, used by setOpenGLVersionRequired(). */ + enum OpenGLVersion + { + defaultGLVersion = 0, + openGL3_2 + }; + + /** Sets a preference for the version of GL that this context should use, if possible. + Some platforms may ignore this value. + */ + void setOpenGLVersionRequired (OpenGLVersion) noexcept; + /** Enables or disables the use of the GL context to perform 2D rendering of the component to which it is attached. If this is false, then only your OpenGLRenderer will be used to perform @@ -264,6 +276,7 @@ private: ScopedPointer attachment; OpenGLPixelFormat pixelFormat; void* contextToShareWith; + OpenGLVersion versionRequired; bool renderComponents, useMultisampling, continuousRepaint; CachedImage* getCachedImage() const noexcept;