From e35e13036273c21c914b881b5f1efa4dbfc34dd0 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 18 Jul 2012 10:41:26 +0100 Subject: [PATCH] Added some matrix uniform setting methods to OpenGLShaderProgram. --- modules/juce_opengl/native/juce_OpenGLExtensions.h | 6 +++++- modules/juce_opengl/opengl/juce_OpenGLContext.cpp | 9 ++++----- modules/juce_opengl/opengl/juce_OpenGLShaderProgram.cpp | 4 ++++ modules/juce_opengl/opengl/juce_OpenGLShaderProgram.h | 6 ++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/modules/juce_opengl/native/juce_OpenGLExtensions.h b/modules/juce_opengl/native/juce_OpenGLExtensions.h index 858ea4f4b2..bd762a5dae 100644 --- a/modules/juce_opengl/native/juce_OpenGLExtensions.h +++ b/modules/juce_opengl/native/juce_OpenGLExtensions.h @@ -84,7 +84,11 @@ USE_FUNCTION (glUniform3f, void, (GLint p1, GLfloat p2, GLfloat p3, GLfloat p4), (p1, p2, p3, p4))\ USE_FUNCTION (glUniform4f, void, (GLint p1, GLfloat p2, GLfloat p3, GLfloat p4, GLfloat p5), (p1, p2, p3, p4, p5))\ USE_FUNCTION (glUniform4i, void, (GLint p1, GLint p2, GLint p3, GLint p4, GLint p5), (p1, p2, p3, p4, p5))\ - USE_FUNCTION (glUniform1fv, void, (GLint p1, GLsizei p2, const GLfloat* p3), (p1, p2, p3)) + USE_FUNCTION (glUniform1fv, void, (GLint p1, GLsizei p2, const GLfloat* p3), (p1, p2, p3))\ + USE_FUNCTION (glUniformMatrix2fv, void, (GLint p1, GLsizei p2, GLboolean p3, const GLfloat* p4), (p1, p2, p3, p4))\ + USE_FUNCTION (glUniformMatrix3fv, void, (GLint p1, GLsizei p2, GLboolean p3, const GLfloat* p4), (p1, p2, p3, p4))\ + USE_FUNCTION (glUniformMatrix4fv, void, (GLint p1, GLsizei p2, GLboolean p3, const GLfloat* p4), (p1, p2, p3, p4)) + #else #define JUCE_GL_EXTENSION_FUNCTIONS1(USE_FUNCTION) JUCE_GL_BASIC_EXTENSION_FUNCTIONS(USE_FUNCTION, EXT_FUNCTION) #endif diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index 606193300a..b09ba4e1b7 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -559,13 +559,12 @@ void OpenGLContext::deactivateCurrentContext() { NativeContext::deactivateC void OpenGLContext::triggerRepaint() { - CachedImage* const currentContext - = dynamic_cast (Thread::getCurrentThread()); + CachedImage* const cachedImage = getCachedImage(); - if (currentContext != nullptr) + if (cachedImage != nullptr) { - currentContext->triggerRepaint(); - currentContext->component.repaint(); + cachedImage->triggerRepaint(); + cachedImage->component.repaint(); } } diff --git a/modules/juce_opengl/opengl/juce_OpenGLShaderProgram.cpp b/modules/juce_opengl/opengl/juce_OpenGLShaderProgram.cpp index 52ef3ccfe1..2bb644bf3a 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLShaderProgram.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLShaderProgram.cpp @@ -129,4 +129,8 @@ void OpenGLShaderProgram::Uniform::set (GLfloat n1, GLfloat n2, GLfloat n3, floa void OpenGLShaderProgram::Uniform::set (GLint n1, GLint n2, GLint n3, GLint n4) const noexcept { context.extensions.glUniform4i (uniformID, n1, n2, n3, n4); } void OpenGLShaderProgram::Uniform::set (const GLfloat* values, GLsizei numValues) const noexcept { context.extensions.glUniform1fv (uniformID, numValues, values); } +void OpenGLShaderProgram::Uniform::setMatrix2 (const GLfloat* v, GLint num, GLboolean trns) const noexcept { context.extensions.glUniformMatrix2fv (uniformID, num, trns, v); } +void OpenGLShaderProgram::Uniform::setMatrix3 (const GLfloat* v, GLint num, GLboolean trns) const noexcept { context.extensions.glUniformMatrix3fv (uniformID, num, trns, v); } +void OpenGLShaderProgram::Uniform::setMatrix4 (const GLfloat* v, GLint num, GLboolean trns) const noexcept { context.extensions.glUniformMatrix4fv (uniformID, num, trns, v); } + #endif diff --git a/modules/juce_opengl/opengl/juce_OpenGLShaderProgram.h b/modules/juce_opengl/opengl/juce_OpenGLShaderProgram.h index 53a96218f6..aeafff7d98 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLShaderProgram.h +++ b/modules/juce_opengl/opengl/juce_OpenGLShaderProgram.h @@ -105,6 +105,12 @@ public: void set (GLint n1, GLint n2, GLint n3, GLint n4) const noexcept; /** Sets a vector float uniform. */ void set (const GLfloat* values, int numValues) const noexcept; + /** Sets a 2x2 matrix float uniform. */ + void setMatrix2 (const GLfloat* values, GLint count, GLboolean transpose) const noexcept; + /** Sets a 3x3 matrix float uniform. */ + void setMatrix3 (const GLfloat* values, GLint count, GLboolean transpose) const noexcept; + /** Sets a 4x4 matrix float uniform. */ + void setMatrix4 (const GLfloat* values, GLint count, GLboolean transpose) const noexcept; /** The uniform's ID number. If the uniform couldn't be found, this value will be < 0.