summaryrefslogtreecommitdiff
path: root/slideshow
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <emmanuel.peyrot@collabora.com>2015-12-09 21:39:23 +0000
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-12-11 15:28:59 +0100
commit566eca14481ea70c83aef30824da911ccf834b41 (patch)
tree4a48f2867bf8e054bb7d58d3ae03a899a057fc50 /slideshow
parent4fcebe9f8a69f40bb8629da69df5974851515d2e (diff)
slideshow: upload the transform matrices as uniforms
Change-Id: I2380fc7f8462514e6c032b18b44df51fbaaccb9f
Diffstat (limited to 'slideshow')
-rw-r--r--slideshow/opengl/basicVertexShader.glsl10
-rw-r--r--slideshow/opengl/reflectionVertexShader.glsl10
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx54
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx20
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx2
5 files changed, 55 insertions, 41 deletions
diff --git a/slideshow/opengl/basicVertexShader.glsl b/slideshow/opengl/basicVertexShader.glsl
index 020616fff872..a4b258c69043 100644
--- a/slideshow/opengl/basicVertexShader.glsl
+++ b/slideshow/opengl/basicVertexShader.glsl
@@ -28,14 +28,20 @@
#version 120
+uniform mat4 u_sceneTransformMatrix;
+uniform mat4 u_primitiveTransformMatrix;
+uniform mat4 u_operationsTransformMatrix;
+
varying vec2 v_texturePosition;
varying vec3 v_normal;
void main( void )
{
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+ mat4 modelViewMatrix = gl_ModelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
+ mat3 normalMatrix = mat3(transpose(inverse(modelViewMatrix)));
+ gl_Position = gl_ProjectionMatrix * modelViewMatrix * gl_Vertex;
v_texturePosition = gl_MultiTexCoord0.xy;
- v_normal = normalize(gl_NormalMatrix * gl_Normal);
+ v_normal = normalize(normalMatrix * gl_Normal);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/opengl/reflectionVertexShader.glsl b/slideshow/opengl/reflectionVertexShader.glsl
index 5087b98c57b0..ad9b0330322d 100644
--- a/slideshow/opengl/reflectionVertexShader.glsl
+++ b/slideshow/opengl/reflectionVertexShader.glsl
@@ -28,15 +28,21 @@
#version 130
+uniform mat4 u_sceneTransformMatrix;
+uniform mat4 u_primitiveTransformMatrix;
+uniform mat4 u_operationsTransformMatrix;
+
varying vec2 v_texturePosition;
varying vec3 v_normal;
varying float v_isShadow;
void main( void )
{
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+ mat4 modelViewMatrix = gl_ModelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
+ mat3 normalMatrix = mat3(transpose(inverse(modelViewMatrix)));
+ gl_Position = gl_ProjectionMatrix * modelViewMatrix * gl_Vertex;
v_texturePosition = gl_MultiTexCoord0.xy;
- v_normal = normalize(gl_NormalMatrix * gl_Normal);
+ v_normal = normalize(normalMatrix * gl_Normal);
v_isShadow = float(gl_VertexID >= 6);
}
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
index 94ded57c0a3e..aab8508bc5e9 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -99,6 +99,10 @@ void OGLTransitionImpl::prepare( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteri
glUniform1i( location, 2 ); // texture unit 2
CHECK_GL_ERROR();
}
+
+ m_nPrimitiveTransformLocation = glGetUniformLocation( m_nProgramObject, "u_primitiveTransformMatrix" );
+ m_nSceneTransformLocation = glGetUniformLocation( m_nProgramObject, "u_sceneTransformMatrix" );
+ m_nOperationsTransformLocation = glGetUniformLocation( m_nProgramObject, "u_operationsTransformMatrix" );
}
CHECK_GL_ERROR();
@@ -169,14 +173,10 @@ void OGLTransitionImpl::display( double nTime, sal_Int32 glLeavingSlideTex, sal_
prepare( nTime, SlideWidth, SlideHeight, DispWidth, DispHeight );
CHECK_GL_ERROR();
- glPushMatrix();
- CHECK_GL_ERROR();
displaySlides_( nTime, glLeavingSlideTex, glEnteringSlideTex, SlideWidthScale, SlideHeightScale );
CHECK_GL_ERROR();
displayScene( nTime, SlideWidth, SlideHeight, DispWidth, DispHeight );
CHECK_GL_ERROR();
- glPopMatrix();
- CHECK_GL_ERROR();
}
void OGLTransitionImpl::applyOverallOperations( double nTime, double SlideWidthScale, double SlideHeightScale )
@@ -186,11 +186,11 @@ void OGLTransitionImpl::applyOverallOperations( double nTime, double SlideWidthS
for(size_t i(0); i != rOverallOperations.size(); ++i)
rOverallOperations[i]->interpolate(matrix, nTime, SlideWidthScale, SlideHeightScale);
CHECK_GL_ERROR();
- glMultMatrixf(glm::value_ptr(matrix));
+ glUniformMatrix4fv(m_nOperationsTransformLocation, 1, false, glm::value_ptr(matrix));
CHECK_GL_ERROR();
}
-static void display_primitives(const Primitives_t& primitives, double nTime, double WidthScale, double HeightScale)
+static void display_primitives(const Primitives_t& primitives, GLint primitiveTransformLocation, double nTime, double WidthScale, double HeightScale)
{
CHECK_GL_ERROR();
GLuint buffer;
@@ -236,7 +236,7 @@ static void display_primitives(const Primitives_t& primitives, double nTime, dou
glTexCoordPointer( 2, GL_FLOAT, sizeof(Vertex), reinterpret_cast<void*>(offsetof(Vertex, texcoord)) );
for (const Primitive& primitive: primitives)
- primitive.display(nTime, WidthScale, HeightScale, *first++);
+ primitive.display(primitiveTransformLocation, nTime, WidthScale, HeightScale, *first++);
CHECK_GL_ERROR();
glDeleteBuffers(1, &buffer);
@@ -251,7 +251,9 @@ OGLTransitionImpl::displaySlide(
CHECK_GL_ERROR();
glBindTexture(GL_TEXTURE_2D, glSlideTex);
CHECK_GL_ERROR();
- display_primitives(primitives, nTime, SlideWidthScale, SlideHeightScale);
+ glUniformMatrix4fv(m_nSceneTransformLocation, 1, false, glm::value_ptr(glm::mat4()));
+ CHECK_GL_ERROR();
+ display_primitives(primitives, m_nPrimitiveTransformLocation, nTime, SlideWidthScale, SlideHeightScale);
CHECK_GL_ERROR();
}
@@ -261,55 +263,43 @@ void OGLTransitionImpl::displayScene( double nTime, double SlideWidth, double Sl
const SceneObjects_t& rSceneObjects(maScene.getSceneObjects());
glEnable(GL_TEXTURE_2D);
for(size_t i(0); i != rSceneObjects.size(); ++i)
- rSceneObjects[i]->display(nTime, SlideWidth, SlideHeight, DispWidth, DispHeight);
+ rSceneObjects[i]->display(m_nSceneTransformLocation, m_nPrimitiveTransformLocation, nTime, SlideWidth, SlideHeight, DispWidth, DispHeight);
CHECK_GL_ERROR();
}
-void Primitive::display(double nTime, double WidthScale, double HeightScale, int first) const
+void Primitive::display(GLint primitiveTransformLocation, double nTime, double WidthScale, double HeightScale, int first) const
{
- CHECK_GL_ERROR();
- glPushMatrix();
+ glm::mat4 matrix;
+ applyOperations( matrix, nTime, WidthScale, HeightScale );
CHECK_GL_ERROR();
- applyOperations( nTime, WidthScale, HeightScale );
-
+ glUniformMatrix4fv(primitiveTransformLocation, 1, false, glm::value_ptr(matrix));
CHECK_GL_ERROR();
glDrawArrays( GL_TRIANGLES, first, Vertices.size() );
CHECK_GL_ERROR();
- glPopMatrix();
- CHECK_GL_ERROR();
}
-void Primitive::applyOperations(double nTime, double WidthScale, double HeightScale) const
+void Primitive::applyOperations(glm::mat4& matrix, double nTime, double WidthScale, double HeightScale) const
{
- glm::mat4 matrix;
for(size_t i(0); i < Operations.size(); ++i)
Operations[i]->interpolate(matrix, nTime, WidthScale, HeightScale);
matrix = glm::scale(matrix, glm::vec3(WidthScale, HeightScale, 1));
- CHECK_GL_ERROR();
- // TODO: replace that with an uniform upload instead.
- glMultMatrixf(glm::value_ptr(matrix));
- CHECK_GL_ERROR();
}
-void SceneObject::display(double nTime, double /* SlideWidth */, double /* SlideHeight */, double DispWidth, double DispHeight ) const
+void SceneObject::display(GLint sceneTransformLocation, GLint primitiveTransformLocation, double nTime, double /* SlideWidth */, double /* SlideHeight */, double DispWidth, double DispHeight ) const
{
// fixme: allow various model spaces, now we make it so that
// it is regular -1,-1 to 1,1, where the whole display fits in
- CHECK_GL_ERROR();
- glPushMatrix();
- CHECK_GL_ERROR();
glm::mat4 matrix;
if (DispHeight > DispWidth)
matrix = glm::scale(matrix, glm::vec3(DispHeight/DispWidth, 1, 1));
else
matrix = glm::scale(matrix, glm::vec3(1, DispWidth/DispHeight, 1));
- glMultMatrixf(glm::value_ptr(matrix));
CHECK_GL_ERROR();
- display_primitives(maPrimitives, nTime, 1, 1);
+ glUniformMatrix4fv(sceneTransformLocation, 1, false, glm::value_ptr(matrix));
CHECK_GL_ERROR();
- glPopMatrix();
+ display_primitives(maPrimitives, primitiveTransformLocation, nTime, 1, 1);
CHECK_GL_ERROR();
}
@@ -336,18 +326,18 @@ public:
Iris() = default;
virtual void prepare() override;
- virtual void display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight) const override;
+ virtual void display(GLint sceneTransformLocation, GLint primitiveTransformLocation, double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight) const override;
virtual void finish() override;
private:
GLuint maTexture = 0;
};
-void Iris::display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight ) const
+void Iris::display(GLint sceneTransformLocation, GLint primitiveTransformLocation, double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight ) const
{
glBindTexture(GL_TEXTURE_2D, maTexture);
CHECK_GL_ERROR();
- SceneObject::display(nTime, SlideWidth, SlideHeight, DispWidth, DispHeight);
+ SceneObject::display(sceneTransformLocation, primitiveTransformLocation, nTime, SlideWidth, SlideHeight, DispWidth, DispHeight);
}
void Iris::prepare()
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
index c56e9c95f2af..61aed6d05e67 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
@@ -166,7 +166,7 @@ protected:
void setScene(TransitionScene const& rScene);
- static void displaySlide( double nTime, sal_Int32 glSlideTex, const Primitives_t& primitives, double SlideWidthScale, double SlideHeightScale );
+ void displaySlide( double nTime, sal_Int32 glSlideTex, const Primitives_t& primitives, double SlideWidthScale, double SlideHeightScale );
void displayScene( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight);
void applyOverallOperations( double nTime, double SlideWidthScale, double SlideHeightScale );
@@ -212,6 +212,18 @@ private:
TransitionScene maScene;
const TransitionSettings maSettings;
+ /** Uniform location for primitive transform
+ */
+ GLint m_nPrimitiveTransformLocation = -1;
+
+ /** Uniform location for scene transform
+ */
+ GLint m_nSceneTransformLocation = -1;
+
+ /** Uniform location for operations transform
+ */
+ GLint m_nOperationsTransformLocation = -1;
+
protected:
/** GLSL program object
*/
@@ -252,7 +264,7 @@ public:
virtual ~SceneObject();
virtual void prepare() {}
- virtual void display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight) const;
+ virtual void display(GLint sceneTransformLocation, GLint primitiveTransformLocation, double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight ) const;
virtual void finish() {}
void pushPrimitive (const Primitive &p);
@@ -283,8 +295,8 @@ public:
void swap(Primitive& rOther);
- void applyOperations(double nTime, double SlideWidthScale, double SlideHeightScale) const;
- void display(double nTime, double SlideWidthScale, double SlideHeightScale, int first) const;
+ void applyOperations(glm::mat4& matrix, double nTime, double SlideWidthScale, double SlideHeightScale) const;
+ void display(GLint primitiveTransformLocation, double nTime, double WidthScale, double HeightScale, int first) const;
/** PushBack a vertex,normal, and tex coord. Each SlideLocation is where on the slide is mapped to this location ( from (0,0) to (1,1) ). This will make sure the correct aspect ratio is used, and helps to make slides begin and end at the correct position. (0,0) is the top left of the slide, and (1,1) is the bottom right.
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
index c7d55604b99d..f808a1f5fa35 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
@@ -532,6 +532,7 @@ void OGLTransitionerImpl::impl_prepareSlides()
void OGLTransitionerImpl::impl_prepareTransition()
{
+ prepareEnvironment();
if( mpTransition && mpTransition->getSettings().mnRequiredGLVersion <= mnGLVersion )
mpTransition->prepare( maLeavingSlideGL, maEnteringSlideGL );
}
@@ -1182,7 +1183,6 @@ void OGLTransitionerImpl::GLInitSlides()
#endif
mpContext->makeCurrent();
- prepareEnvironment();
const OGLFormat* pFormat = nullptr;
if( !mbUseLeavingPixmap || !mbUseEnteringPixmap )