| @@ -58,8 +58,13 @@ | |||||
| #elif JUCE_IOS | #elif JUCE_IOS | ||||
| #include <OpenGLES/ES2/gl.h> | #include <OpenGLES/ES2/gl.h> | ||||
| #elif JUCE_MAC | #elif JUCE_MAC | ||||
| #include <OpenGL/gl.h> | |||||
| #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 <OpenGL/gl3.h> | |||||
| #include <OpenGL/gl3ext.h> | |||||
| #else | |||||
| #include <OpenGL/gl.h> | |||||
| #include "OpenGL/glext.h" | |||||
| #endif | |||||
| #elif JUCE_ANDROID | #elif JUCE_ANDROID | ||||
| #include <GLES2/gl2.h> | #include <GLES2/gl2.h> | ||||
| #endif | #endif | ||||
| @@ -98,23 +98,28 @@ struct OpenGLExtensionFunctions | |||||
| typedef pointer_sized_int GLintptr; | typedef pointer_sized_int GLintptr; | ||||
| #endif | #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) | 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 | #elif JUCE_OPENGL_ES | ||||
| #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) static returnType name params; | #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) | JUCE_GL_EXTENSION_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION, JUCE_DECLARE_GL_FUNCTION) | ||||
| //============================================================================== | |||||
| #else | #else | ||||
| #define JUCE_DECLARE_GL_FUNCTION(name, returnType, params, callparams) inline static returnType name params { return ::name callparams; } | #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 | #endif | ||||
| #undef JUCE_DECLARE_GL_FUNCTION | #undef JUCE_DECLARE_GL_FUNCTION | ||||
| @@ -38,7 +38,8 @@ public: | |||||
| NativeContext (Component& comp, | NativeContext (Component& comp, | ||||
| const OpenGLPixelFormat& pixelFormat, | const OpenGLPixelFormat& pixelFormat, | ||||
| void* /*contextToShareWith*/, | void* /*contextToShareWith*/, | ||||
| bool /*useMultisampling*/) | |||||
| bool /*useMultisampling*/, | |||||
| OpenGLVersion) | |||||
| : component (comp), | : component (comp), | ||||
| isInsideGLCallback (false) | isInsideGLCallback (false) | ||||
| { | { | ||||
| @@ -46,7 +46,8 @@ public: | |||||
| NativeContext (Component& component, | NativeContext (Component& component, | ||||
| const OpenGLPixelFormat& pixFormat, | const OpenGLPixelFormat& pixFormat, | ||||
| void* contextToShare, | void* contextToShare, | ||||
| bool multisampling) | |||||
| bool multisampling, | |||||
| OpenGLVersion) | |||||
| : frameBufferHandle (0), colorBufferHandle (0), depthBufferHandle (0), | : frameBufferHandle (0), colorBufferHandle (0), depthBufferHandle (0), | ||||
| msaaColorHandle (0), msaaBufferHandle (0), | msaaColorHandle (0), msaaBufferHandle (0), | ||||
| lastWidth (0), lastHeight (0), needToRebuildBuffers (false), | lastWidth (0), lastHeight (0), needToRebuildBuffers (false), | ||||
| @@ -32,7 +32,8 @@ public: | |||||
| NativeContext (Component& component, | NativeContext (Component& component, | ||||
| const OpenGLPixelFormat& pixelFormat, | const OpenGLPixelFormat& pixelFormat, | ||||
| void* shareContext, | void* shareContext, | ||||
| bool /*useMultisampling*/) | |||||
| bool /*useMultisampling*/, | |||||
| OpenGLVersion) | |||||
| : renderContext (0), embeddedWindow (0), swapFrames (0), bestVisual (0), | : renderContext (0), embeddedWindow (0), swapFrames (0), bestVisual (0), | ||||
| contextToShareWith (shareContext) | contextToShareWith (shareContext) | ||||
| { | { | ||||
| @@ -28,11 +28,13 @@ public: | |||||
| NativeContext (Component& component, | NativeContext (Component& component, | ||||
| const OpenGLPixelFormat& pixFormat, | const OpenGLPixelFormat& pixFormat, | ||||
| void* contextToShare, | void* contextToShare, | ||||
| bool /*useMultisampling*/) | |||||
| bool /*useMultisampling*/, | |||||
| OpenGLVersion version) | |||||
| : lastSwapTime (0), minSwapTimeMs (0), underrunCounter (0) | : lastSwapTime (0), minSwapTimeMs (0), underrunCounter (0) | ||||
| { | { | ||||
| NSOpenGLPixelFormatAttribute attribs[] = | NSOpenGLPixelFormatAttribute attribs[] = | ||||
| { | { | ||||
| NSOpenGLPFAOpenGLProfile, version >= openGL3_2 ? NSOpenGLProfileVersion3_2Core : NSOpenGLProfileVersionLegacy, | |||||
| NSOpenGLPFADoubleBuffer, | NSOpenGLPFADoubleBuffer, | ||||
| NSOpenGLPFAMPSafe, | NSOpenGLPFAMPSafe, | ||||
| NSOpenGLPFAClosestPolicy, | NSOpenGLPFAClosestPolicy, | ||||
| @@ -31,7 +31,8 @@ public: | |||||
| NativeContext (Component& component, | NativeContext (Component& component, | ||||
| const OpenGLPixelFormat& pixelFormat, | const OpenGLPixelFormat& pixelFormat, | ||||
| void* contextToShareWith, | void* contextToShareWith, | ||||
| bool /*useMultisampling*/) | |||||
| bool /*useMultisampling*/, | |||||
| OpenGLVersion) | |||||
| { | { | ||||
| createNativeWindow (component); | createNativeWindow (component); | ||||
| @@ -39,7 +39,8 @@ public: | |||||
| hasInitialised (false), | hasInitialised (false), | ||||
| needsUpdate (1), lastMMLockReleaseTime (0) | 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()) | if (nativeContext->createdOk()) | ||||
| context.nativeContext = nativeContext; | context.nativeContext = nativeContext; | ||||
| @@ -553,8 +554,8 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| OpenGLContext::OpenGLContext() | OpenGLContext::OpenGLContext() | ||||
| : nativeContext (nullptr), renderer (nullptr), currentRenderScale (1.0), | : 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; | useMultisampling = b; | ||||
| } | } | ||||
| void OpenGLContext::setOpenGLVersionRequired (OpenGLVersion v) noexcept | |||||
| { | |||||
| versionRequired = v; | |||||
| } | |||||
| void OpenGLContext::attachTo (Component& component) | void OpenGLContext::attachTo (Component& component) | ||||
| { | { | ||||
| component.repaint(); | component.repaint(); | ||||
| @@ -109,6 +109,18 @@ public: | |||||
| /** Returns true if shaders can be used in this context. */ | /** Returns true if shaders can be used in this context. */ | ||||
| bool areShadersAvailable() const; | 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 | /** Enables or disables the use of the GL context to perform 2D rendering | ||||
| of the component to which it is attached. | of the component to which it is attached. | ||||
| If this is false, then only your OpenGLRenderer will be used to perform | If this is false, then only your OpenGLRenderer will be used to perform | ||||
| @@ -264,6 +276,7 @@ private: | |||||
| ScopedPointer<Attachment> attachment; | ScopedPointer<Attachment> attachment; | ||||
| OpenGLPixelFormat pixelFormat; | OpenGLPixelFormat pixelFormat; | ||||
| void* contextToShareWith; | void* contextToShareWith; | ||||
| OpenGLVersion versionRequired; | |||||
| bool renderComponents, useMultisampling, continuousRepaint; | bool renderComponents, useMultisampling, continuousRepaint; | ||||
| CachedImage* getCachedImage() const noexcept; | CachedImage* getCachedImage() const noexcept; | ||||