- Library code update
- project update (added Eigen) git-svn-id: http://moon:8086/svn/software/trunk/projects/mpsk_rx_gui@94 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "juce_opengl",
|
||||
"name": "JUCE OpenGL classes",
|
||||
"version": "3.0.5",
|
||||
"version": "3.0.8",
|
||||
"description": "Classes for rendering OpenGL in a JUCE window.",
|
||||
"website": "http://www.juce.com/juce",
|
||||
"license": "GPL/Commercial",
|
||||
|
||||
@@ -56,24 +56,42 @@
|
||||
#include <GL/gl.h>
|
||||
#undef KeyPress
|
||||
#elif JUCE_IOS
|
||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
|
||||
#if defined (__IPHONE_7_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
|
||||
#include <OpenGLES/ES3/gl.h>
|
||||
#else
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#endif
|
||||
#elif JUCE_MAC
|
||||
#if defined (MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7)
|
||||
#define JUCE_OPENGL3 1
|
||||
#define JUCE_OPENGL3 1
|
||||
#include <OpenGL/gl3.h>
|
||||
#include <OpenGL/gl3ext.h>
|
||||
#else
|
||||
#include <OpenGL/gl.h>
|
||||
#include "OpenGL/glext.h"
|
||||
#include <OpenGL/glext.h>
|
||||
#endif
|
||||
#elif JUCE_ANDROID
|
||||
#include <GLES2/gl2.h>
|
||||
#endif
|
||||
|
||||
#if GL_ES_VERSION_3_0
|
||||
#define JUCE_OPENGL3 1
|
||||
#endif
|
||||
|
||||
//=============================================================================
|
||||
/** This macro is a helper for use in GLSL shader code which needs to compile on both OpenGL 2.1 and OpenGL 3.0.
|
||||
It's mandatory in OpenGL 3.0 to specify the GLSL version.
|
||||
*/
|
||||
#if JUCE_OPENGL3
|
||||
#if JUCE_OPENGL_ES
|
||||
#define JUCE_GLSL_VERSION "#version 300 es"
|
||||
#else
|
||||
#define JUCE_GLSL_VERSION "#version 150"
|
||||
#endif
|
||||
#else
|
||||
#define JUCE_GLSL_VERSION ""
|
||||
#endif
|
||||
|
||||
//=============================================================================
|
||||
#if JUCE_OPENGL_ES || defined (DOXYGEN)
|
||||
/** This macro is a helper for use in GLSL shader code which needs to compile on both GLES and desktop GL.
|
||||
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
|
||||
[((UIView*) peer->getNativeHandle()) addSubview: view];
|
||||
|
||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
|
||||
#if defined (__IPHONE_7_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
|
||||
if (version == OpenGLContext::openGL3_2 && [[UIDevice currentDevice].systemVersion floatValue] >= 7.0)
|
||||
{
|
||||
if (! createContext (kEAGLRenderingAPIOpenGLES3, contextToShare))
|
||||
@@ -118,7 +118,7 @@ public:
|
||||
|
||||
bool createdOk() const noexcept { return getRawContext() != nullptr; }
|
||||
void* getRawContext() const noexcept { return context; }
|
||||
GLuint getFrameBufferID() const noexcept { return frameBufferHandle; }
|
||||
GLuint getFrameBufferID() const noexcept { return useMSAA ? msaaBufferHandle : frameBufferHandle; }
|
||||
|
||||
bool makeActive() const noexcept
|
||||
{
|
||||
@@ -142,6 +142,18 @@ public:
|
||||
|
||||
void swapBuffers()
|
||||
{
|
||||
if (useMSAA)
|
||||
{
|
||||
glBindFramebuffer (GL_DRAW_FRAMEBUFFER, frameBufferHandle);
|
||||
glBindFramebuffer (GL_READ_FRAMEBUFFER, msaaBufferHandle);
|
||||
|
||||
#if defined (__IPHONE_7_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
|
||||
glBlitFramebuffer (0, 0, lastWidth, lastHeight, 0, 0, lastWidth, lastHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
#else
|
||||
glResolveMultisampleFramebufferAPPLE();
|
||||
#endif
|
||||
}
|
||||
|
||||
glBindRenderbuffer (GL_RENDERBUFFER, colorBufferHandle);
|
||||
[context presentRenderbuffer: GL_RENDERBUFFER];
|
||||
|
||||
@@ -189,7 +201,7 @@ private:
|
||||
int swapFrames;
|
||||
bool useDepthBuffer, useMSAA;
|
||||
|
||||
bool createContext (NSUInteger type, void* contextToShare)
|
||||
bool createContext (EAGLRenderingAPI type, void* contextToShare)
|
||||
{
|
||||
jassert (context == nil);
|
||||
context = [EAGLContext alloc];
|
||||
@@ -233,7 +245,7 @@ private:
|
||||
glBindFramebuffer (GL_FRAMEBUFFER, msaaBufferHandle);
|
||||
glBindRenderbuffer (GL_RENDERBUFFER, msaaColorHandle);
|
||||
|
||||
glRenderbufferStorageMultisampleAPPLE (GL_RENDERBUFFER, 4, GL_RGBA8_OES, width, height);
|
||||
glRenderbufferStorageMultisample (GL_RENDERBUFFER, 4, GL_RGBA8, width, height);
|
||||
|
||||
glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, msaaColorHandle);
|
||||
}
|
||||
@@ -244,7 +256,7 @@ private:
|
||||
glBindRenderbuffer (GL_RENDERBUFFER, depthBufferHandle);
|
||||
|
||||
if (useMSAA)
|
||||
glRenderbufferStorageMultisampleAPPLE (GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT16, width, height);
|
||||
glRenderbufferStorageMultisample (GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT16, width, height);
|
||||
else
|
||||
glRenderbufferStorage (GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
extern ComponentPeer* createNonRepaintingEmbeddedWindowsPeer (Component*, void* parent);
|
||||
extern ComponentPeer* createNonRepaintingEmbeddedWindowsPeer (Component&, void* parent);
|
||||
|
||||
//==============================================================================
|
||||
class OpenGLContext::NativeContext
|
||||
@@ -33,7 +33,9 @@ public:
|
||||
void* contextToShareWith,
|
||||
bool /*useMultisampling*/,
|
||||
OpenGLVersion)
|
||||
: context (nullptr)
|
||||
{
|
||||
dummyComponent = new DummyComponent (*this);
|
||||
createNativeWindow (component);
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
@@ -82,8 +84,8 @@ public:
|
||||
releaseDC();
|
||||
}
|
||||
|
||||
void initialiseOnRenderThread (OpenGLContext&) {}
|
||||
void shutdownOnRenderThread() { deactivateCurrentContext(); }
|
||||
void initialiseOnRenderThread (OpenGLContext& c) { context = &c; }
|
||||
void shutdownOnRenderThread() { deactivateCurrentContext(); context = nullptr; }
|
||||
|
||||
static void deactivateCurrentContext() { wglMakeCurrent (0, 0); }
|
||||
bool makeActive() const noexcept { return isActive() || wglMakeCurrent (dc, renderContext) != FALSE; }
|
||||
@@ -114,13 +116,30 @@ public:
|
||||
void* getRawContext() const noexcept { return renderContext; }
|
||||
unsigned int getFrameBufferID() const noexcept { return 0; }
|
||||
|
||||
void triggerRepaint()
|
||||
{
|
||||
if (context != nullptr)
|
||||
context->triggerRepaint();
|
||||
}
|
||||
|
||||
struct Locker { Locker (NativeContext&) {} };
|
||||
|
||||
private:
|
||||
Component dummyComponent;
|
||||
struct DummyComponent : public Component
|
||||
{
|
||||
DummyComponent (NativeContext& c) : context (c) {}
|
||||
|
||||
// The windowing code will call this when a paint callback happens
|
||||
void handleCommandMessage (int) override { context.triggerRepaint(); }
|
||||
|
||||
NativeContext& context;
|
||||
};
|
||||
|
||||
ScopedPointer<DummyComponent> dummyComponent;
|
||||
ScopedPointer<ComponentPeer> nativeWindow;
|
||||
HGLRC renderContext;
|
||||
HDC dc;
|
||||
OpenGLContext* context;
|
||||
|
||||
#define JUCE_DECLARE_WGL_EXTENSION_FUNCTION(name, returnType, params) \
|
||||
typedef returnType (__stdcall *type_ ## name) params; type_ ## name name;
|
||||
@@ -142,7 +161,7 @@ private:
|
||||
void createNativeWindow (Component& component)
|
||||
{
|
||||
Component* topComp = component.getTopLevelComponent();
|
||||
nativeWindow = createNonRepaintingEmbeddedWindowsPeer (&dummyComponent, topComp->getWindowHandle());
|
||||
nativeWindow = createNonRepaintingEmbeddedWindowsPeer (*dummyComponent, topComp->getWindowHandle());
|
||||
|
||||
if (ComponentPeer* peer = topComp->getPeer())
|
||||
updateWindowPosition (peer->getAreaCoveredBy (component));
|
||||
|
||||
@@ -145,11 +145,6 @@ public:
|
||||
{
|
||||
ScopedPointer<MessageManagerLock> mmLock;
|
||||
|
||||
const Rectangle<int> screenBounds (component.getTopLevelComponent()->getScreenBounds());
|
||||
|
||||
if (lastScreenBounds != screenBounds)
|
||||
updateViewportSize (false);
|
||||
|
||||
const bool isUpdating = needsUpdate.compareAndSetBool (0, 1);
|
||||
|
||||
if (context.renderComponents && isUpdating)
|
||||
@@ -161,6 +156,8 @@ public:
|
||||
mmLock = new MessageManagerLock (this); // need to acquire this before locking the context.
|
||||
if (! mmLock->lockWasGained())
|
||||
return false;
|
||||
|
||||
updateViewportSize (false);
|
||||
}
|
||||
|
||||
if (! context.makeActive())
|
||||
@@ -219,13 +216,19 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void checkViewportBounds()
|
||||
{
|
||||
const Rectangle<int> screenBounds (component.getTopLevelComponent()->getScreenBounds());
|
||||
|
||||
if (lastScreenBounds != screenBounds)
|
||||
updateViewportSize (true);
|
||||
}
|
||||
|
||||
void paintComponent()
|
||||
{
|
||||
// you mustn't set your own cached image object when attaching a GL context!
|
||||
jassert (get (component) == this);
|
||||
|
||||
updateViewportSize (false);
|
||||
|
||||
if (! ensureFrameBufferSize())
|
||||
return;
|
||||
|
||||
@@ -463,7 +466,8 @@ void OpenGLContext::NativeContext::renderCallback()
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
class OpenGLContext::Attachment : public ComponentMovementWatcher
|
||||
class OpenGLContext::Attachment : public ComponentMovementWatcher,
|
||||
private Timer
|
||||
{
|
||||
public:
|
||||
Attachment (OpenGLContext& c, Component& comp)
|
||||
@@ -564,10 +568,14 @@ private:
|
||||
comp.setCachedComponentImage (newCachedImage);
|
||||
newCachedImage->start(); // (must wait until this is attached before starting its thread)
|
||||
newCachedImage->updateViewportSize (true);
|
||||
|
||||
startTimer (400);
|
||||
}
|
||||
|
||||
void detach()
|
||||
{
|
||||
stopTimer();
|
||||
|
||||
Component& comp = *getComponent();
|
||||
|
||||
#if JUCE_MAC
|
||||
@@ -580,6 +588,12 @@ private:
|
||||
comp.setCachedComponentImage (nullptr);
|
||||
context.nativeContext = nullptr;
|
||||
}
|
||||
|
||||
void timerCallback() override
|
||||
{
|
||||
if (CachedImage* const cachedImage = CachedImage::get (*getComponent()))
|
||||
cachedImage->checkViewportBounds();
|
||||
}
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
@@ -842,27 +856,27 @@ void OpenGLContext::copyTexture (const Rectangle<int>& targetClipArea,
|
||||
ProgramBuilder (OpenGLShaderProgram& prog)
|
||||
{
|
||||
prog.addVertexShader (OpenGLHelpers::translateVertexShaderToV3 (
|
||||
"attribute " JUCE_HIGHP " vec2 position;"
|
||||
"uniform " JUCE_HIGHP " vec2 screenSize;"
|
||||
"varying " JUCE_HIGHP " vec2 pixelPos;"
|
||||
"void main()"
|
||||
"{"
|
||||
"pixelPos = position;"
|
||||
JUCE_HIGHP " vec2 scaled = position / (0.5 * screenSize.xy);"
|
||||
"gl_Position = vec4 (scaled.x - 1.0, 1.0 - scaled.y, 0, 1.0);"
|
||||
"}"));
|
||||
"attribute " JUCE_HIGHP " vec2 position;"
|
||||
"uniform " JUCE_HIGHP " vec2 screenSize;"
|
||||
"uniform " JUCE_HIGHP " float textureBounds[4];"
|
||||
"uniform " JUCE_HIGHP " vec2 vOffsetAndScale;"
|
||||
"varying " JUCE_HIGHP " vec2 texturePos;"
|
||||
"void main()"
|
||||
"{"
|
||||
JUCE_HIGHP " vec2 scaled = position / (0.5 * screenSize.xy);"
|
||||
"gl_Position = vec4 (scaled.x - 1.0, 1.0 - scaled.y, 0, 1.0);"
|
||||
"texturePos = (position - vec2 (textureBounds[0], textureBounds[1])) / vec2 (textureBounds[2], textureBounds[3]);"
|
||||
"texturePos = vec2 (texturePos.x, vOffsetAndScale.x + vOffsetAndScale.y * texturePos.y);"
|
||||
"}"));
|
||||
|
||||
prog.addFragmentShader (OpenGLHelpers::translateFragmentShaderToV3 (
|
||||
"uniform sampler2D imageTexture;"
|
||||
"uniform " JUCE_HIGHP " float textureBounds[4];"
|
||||
"uniform " JUCE_HIGHP " vec2 vOffsetAndScale;"
|
||||
"varying " JUCE_HIGHP " vec2 pixelPos;"
|
||||
"void main()"
|
||||
"{"
|
||||
JUCE_HIGHP " vec2 texturePos = (pixelPos - vec2 (textureBounds[0], textureBounds[1]))"
|
||||
"/ vec2 (textureBounds[2], textureBounds[3]);"
|
||||
"gl_FragColor = texture2D (imageTexture, vec2 (texturePos.x, vOffsetAndScale.x + vOffsetAndScale.y * texturePos.y));"
|
||||
"}"));
|
||||
"uniform sampler2D imageTexture;"
|
||||
"varying " JUCE_HIGHP " vec2 texturePos;"
|
||||
"void main()"
|
||||
"{"
|
||||
"gl_FragColor = texture2D (imageTexture, texturePos);"
|
||||
"}"));
|
||||
|
||||
prog.link();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -90,7 +90,7 @@ struct CachedImageList : public ReferenceCountedObject,
|
||||
CachedImage (CachedImageList& list, ImagePixelData* im)
|
||||
: owner (list), pixelData (im),
|
||||
lastUsed (Time::getCurrentTime()),
|
||||
imageSize (im->width * im->height)
|
||||
imageSize ((size_t) (im->width * im->height))
|
||||
{
|
||||
pixelData->listeners.add (&owner);
|
||||
}
|
||||
@@ -336,30 +336,36 @@ public:
|
||||
//==============================================================================
|
||||
struct ShaderProgramHolder
|
||||
{
|
||||
ShaderProgramHolder (OpenGLContext& context, const char* fragmentShader)
|
||||
ShaderProgramHolder (OpenGLContext& context, const char* fragmentShader, const char* vertexShader)
|
||||
: program (context)
|
||||
{
|
||||
JUCE_CHECK_OPENGL_ERROR
|
||||
program.addVertexShader (OpenGLHelpers::translateVertexShaderToV3 (
|
||||
"attribute vec2 position;"
|
||||
"attribute vec4 colour;"
|
||||
"uniform vec4 screenBounds;"
|
||||
"varying " JUCE_MEDIUMP " vec4 frontColour;"
|
||||
"varying " JUCE_HIGHP " vec2 pixelPos;"
|
||||
"void main()"
|
||||
"{"
|
||||
" frontColour = colour;"
|
||||
" vec2 adjustedPos = position - screenBounds.xy;"
|
||||
" pixelPos = adjustedPos;"
|
||||
" vec2 scaledPos = adjustedPos / screenBounds.zw;"
|
||||
" gl_Position = vec4 (scaledPos.x - 1.0, 1.0 - scaledPos.y, 0, 1.0);"
|
||||
"}"));
|
||||
|
||||
if (! program.addFragmentShader (OpenGLHelpers::translateFragmentShaderToV3 (fragmentShader)))
|
||||
if (vertexShader == nullptr)
|
||||
vertexShader = "attribute vec2 position;"
|
||||
"attribute vec4 colour;"
|
||||
"uniform vec4 screenBounds;"
|
||||
"varying " JUCE_MEDIUMP " vec4 frontColour;"
|
||||
"varying " JUCE_HIGHP " vec2 pixelPos;"
|
||||
"void main()"
|
||||
"{"
|
||||
"frontColour = colour;"
|
||||
"vec2 adjustedPos = position - screenBounds.xy;"
|
||||
"pixelPos = adjustedPos;"
|
||||
"vec2 scaledPos = adjustedPos / screenBounds.zw;"
|
||||
"gl_Position = vec4 (scaledPos.x - 1.0, 1.0 - scaledPos.y, 0, 1.0);"
|
||||
"}";
|
||||
|
||||
if (program.addVertexShader (OpenGLHelpers::translateVertexShaderToV3 (vertexShader))
|
||||
&& program.addFragmentShader (OpenGLHelpers::translateFragmentShaderToV3 (fragmentShader))
|
||||
&& program.link())
|
||||
{
|
||||
JUCE_CHECK_OPENGL_ERROR
|
||||
}
|
||||
else
|
||||
{
|
||||
lastError = program.getLastError();
|
||||
|
||||
program.link();
|
||||
JUCE_CHECK_OPENGL_ERROR
|
||||
}
|
||||
}
|
||||
|
||||
OpenGLShaderProgram program;
|
||||
@@ -368,8 +374,8 @@ public:
|
||||
|
||||
struct ShaderBase : public ShaderProgramHolder
|
||||
{
|
||||
ShaderBase (OpenGLContext& context, const char* fragmentShader)
|
||||
: ShaderProgramHolder (context, fragmentShader),
|
||||
ShaderBase (OpenGLContext& context, const char* fragmentShader, const char* vertexShader = nullptr)
|
||||
: ShaderProgramHolder (context, fragmentShader, vertexShader),
|
||||
positionAttribute (program, "position"),
|
||||
colourAttribute (program, "colour"),
|
||||
screenBounds (program, "screenBounds")
|
||||
@@ -656,11 +662,28 @@ public:
|
||||
struct ImageProgram : public ShaderBase
|
||||
{
|
||||
ImageProgram (OpenGLContext& context)
|
||||
: ShaderBase (context, JUCE_DECLARE_IMAGE_UNIFORMS JUCE_DECLARE_SWIZZLE_FUNCTION
|
||||
: ShaderBase (context, JUCE_DECLARE_VARYING_COLOUR JUCE_DECLARE_SWIZZLE_FUNCTION
|
||||
"uniform sampler2D imageTexture;"
|
||||
"varying " JUCE_HIGHP " vec2 texturePos;"
|
||||
"void main()"
|
||||
"{"
|
||||
JUCE_CLAMP_TEXTURE_COORD
|
||||
"gl_FragColor = frontColour.a * " JUCE_GET_IMAGE_PIXEL ";"
|
||||
"}",
|
||||
"uniform " JUCE_MEDIUMP " vec2 imageLimits;"
|
||||
JUCE_DECLARE_MATRIX_UNIFORM
|
||||
"attribute vec2 position;"
|
||||
"attribute vec4 colour;"
|
||||
"uniform vec4 screenBounds;"
|
||||
"varying " JUCE_MEDIUMP " vec4 frontColour;"
|
||||
"varying " JUCE_HIGHP " vec2 texturePos;"
|
||||
"void main()"
|
||||
"{"
|
||||
"frontColour = colour;"
|
||||
"vec2 adjustedPos = position - screenBounds.xy;"
|
||||
"vec2 pixelPos = adjustedPos;"
|
||||
"texturePos = clamp (" JUCE_MATRIX_TIMES_FRAGCOORD ", vec2 (0, 0), imageLimits);"
|
||||
"vec2 scaledPos = adjustedPos / screenBounds.zw;"
|
||||
"gl_Position = vec4 (scaledPos.x - 1.0, 1.0 - scaledPos.y, 0, 1.0);"
|
||||
"}"),
|
||||
imageParams (program)
|
||||
{}
|
||||
|
||||
@@ -81,8 +81,8 @@ String OpenGLHelpers::translateVertexShaderToV3 (const String& code)
|
||||
{
|
||||
#if JUCE_OPENGL3
|
||||
if (OpenGLShaderProgram::getLanguageVersion() > 1.2)
|
||||
return "#version 150\n" + code.replace ("attribute", "in")
|
||||
.replace ("varying", "out");
|
||||
return JUCE_GLSL_VERSION "\n" + code.replace ("attribute", "in")
|
||||
.replace ("varying", "out");
|
||||
#endif
|
||||
|
||||
return code;
|
||||
@@ -92,7 +92,7 @@ String OpenGLHelpers::translateFragmentShaderToV3 (const String& code)
|
||||
{
|
||||
#if JUCE_OPENGL3
|
||||
if (OpenGLShaderProgram::getLanguageVersion() > 1.2)
|
||||
return "#version 150\n"
|
||||
return JUCE_GLSL_VERSION "\n"
|
||||
"out vec4 fragColor;\n"
|
||||
+ code.replace ("varying", "in")
|
||||
.replace ("texture2D", "texture")
|
||||
|
||||
Reference in New Issue
Block a user