summaryrefslogtreecommitdiff
path: root/slideshow
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <emmanuel.peyrot@collabora.com>2015-12-09 21:39:24 +0000
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-12-12 09:30:20 +0100
commit793c0050e0da1c196381a019250333e889cbc68d (patch)
tree2276628ea478c57e6537fdf0c6d3753403664ab5 /slideshow
parent63f8cb0117d45f523de5b5e06b698327521cc89c (diff)
slideshow: Upload the projection and modelview matrices as uniforms
Change-Id: I9d6c3ad0d2cc2f691afb2c8622471286f8a5e1c7 (cherry picked from commit 7d1c123a55d222868e27673685c25d62b1e96cd5)
Diffstat (limited to 'slideshow')
-rw-r--r--slideshow/opengl/basicVertexShader.glsl6
-rw-r--r--slideshow/opengl/reflectionVertexShader.glsl6
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx39
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx4
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx37
5 files changed, 51 insertions, 41 deletions
diff --git a/slideshow/opengl/basicVertexShader.glsl b/slideshow/opengl/basicVertexShader.glsl
index a4b258c69043..ebd5dbcc6585 100644
--- a/slideshow/opengl/basicVertexShader.glsl
+++ b/slideshow/opengl/basicVertexShader.glsl
@@ -28,6 +28,8 @@
#version 120
+uniform mat4 u_projectionMatrix;
+uniform mat4 u_modelViewMatrix;
uniform mat4 u_sceneTransformMatrix;
uniform mat4 u_primitiveTransformMatrix;
uniform mat4 u_operationsTransformMatrix;
@@ -37,9 +39,9 @@ varying vec3 v_normal;
void main( void )
{
- mat4 modelViewMatrix = gl_ModelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
+ mat4 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
mat3 normalMatrix = mat3(transpose(inverse(modelViewMatrix)));
- gl_Position = gl_ProjectionMatrix * modelViewMatrix * gl_Vertex;
+ gl_Position = u_projectionMatrix * modelViewMatrix * gl_Vertex;
v_texturePosition = gl_MultiTexCoord0.xy;
v_normal = normalize(normalMatrix * gl_Normal);
}
diff --git a/slideshow/opengl/reflectionVertexShader.glsl b/slideshow/opengl/reflectionVertexShader.glsl
index ad9b0330322d..566eafa7590b 100644
--- a/slideshow/opengl/reflectionVertexShader.glsl
+++ b/slideshow/opengl/reflectionVertexShader.glsl
@@ -28,6 +28,8 @@
#version 130
+uniform mat4 u_projectionMatrix;
+uniform mat4 u_modelViewMatrix;
uniform mat4 u_sceneTransformMatrix;
uniform mat4 u_primitiveTransformMatrix;
uniform mat4 u_operationsTransformMatrix;
@@ -38,9 +40,9 @@ varying float v_isShadow;
void main( void )
{
- mat4 modelViewMatrix = gl_ModelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
+ mat4 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
mat3 normalMatrix = mat3(transpose(inverse(modelViewMatrix)));
- gl_Position = gl_ProjectionMatrix * modelViewMatrix * gl_Vertex;
+ gl_Position = u_projectionMatrix * modelViewMatrix * gl_Vertex;
v_texturePosition = gl_MultiTexCoord0.xy;
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 aab8508bc5e9..025c9805672f 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -74,6 +74,43 @@ void OGLTransitionImpl::setScene(TransitionScene const& rScene)
maScene = rScene;
}
+void OGLTransitionImpl::uploadModelViewProjectionMatrices()
+{
+ double EyePos(10.0);
+ double RealF(1.0);
+ double RealN(-1.0);
+ double RealL(-1.0);
+ double RealR(1.0);
+ double RealB(-1.0);
+ double RealT(1.0);
+ double ClipN(EyePos+5.0*RealN);
+ double ClipF(EyePos+15.0*RealF);
+ double ClipL(RealL*8.0);
+ double ClipR(RealR*8.0);
+ double ClipB(RealB*8.0);
+ double ClipT(RealT*8.0);
+
+ glm::mat4 projection = glm::frustum<float>(ClipL, ClipR, ClipB, ClipT, ClipN, ClipF);
+ //This scaling is to take the plane with BottomLeftCorner(-1,-1,0) and TopRightCorner(1,1,0) and map it to the screen after the perspective division.
+ glm::vec3 scale(1.0 / (((RealR * 2.0 * ClipN) / (EyePos * (ClipR - ClipL))) - ((ClipR + ClipL) / (ClipR - ClipL))),
+ 1.0 / (((RealT * 2.0 * ClipN) / (EyePos * (ClipT - ClipB))) - ((ClipT + ClipB) / (ClipT - ClipB))),
+ 1.0);
+ projection = glm::scale(projection, scale);
+ glm::mat4 modelview = glm::translate(glm::mat4(), glm::vec3(0, 0, -EyePos));
+
+ GLint location = glGetUniformLocation( m_nProgramObject, "u_projectionMatrix" );
+ if( location != -1 ) {
+ glUniformMatrix4fv(location, 1, false, glm::value_ptr(projection));
+ CHECK_GL_ERROR();
+ }
+
+ location = glGetUniformLocation( m_nProgramObject, "u_modelViewMatrix" );
+ if( location != -1 ) {
+ glUniformMatrix4fv(location, 1, false, glm::value_ptr(modelview));
+ CHECK_GL_ERROR();
+ }
+}
+
void OGLTransitionImpl::prepare( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex )
{
const SceneObjects_t& rSceneObjects(maScene.getSceneObjects());
@@ -100,6 +137,8 @@ void OGLTransitionImpl::prepare( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteri
CHECK_GL_ERROR();
}
+ uploadModelViewProjectionMatrices();
+
m_nPrimitiveTransformLocation = glGetUniformLocation( m_nProgramObject, "u_primitiveTransformMatrix" );
m_nSceneTransformLocation = glGetUniformLocation( m_nProgramObject, "u_sceneTransformMatrix" );
m_nOperationsTransformLocation = glGetUniformLocation( m_nProgramObject, "u_operationsTransformMatrix" );
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
index 61aed6d05e67..c972ff37f587 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
@@ -212,6 +212,10 @@ private:
TransitionScene maScene;
const TransitionSettings maSettings;
+ /** Calculates the projection and model/view matrices, and upload them.
+ */
+ void uploadModelViewProjectionMatrices();
+
/** Uniform location for primitive transform
*/
GLint m_nPrimitiveTransformLocation = -1;
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
index f808a1f5fa35..5d6a8553726b 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
@@ -207,7 +207,6 @@ protected:
bool useMipmap,
uno::Sequence<sal_Int8>& data,
const OGLFormat* pFormat );
- static void prepareEnvironment();
const OGLFormat* chooseFormats();
private:
@@ -532,7 +531,6 @@ void OGLTransitionerImpl::impl_prepareSlides()
void OGLTransitionerImpl::impl_prepareTransition()
{
- prepareEnvironment();
if( mpTransition && mpTransition->getSettings().mnRequiredGLVersion <= mnGLVersion )
mpTransition->prepare( maLeavingSlideGL, maEnteringSlideGL );
}
@@ -1014,41 +1012,6 @@ void OGLTransitionerImpl::impl_createTexture(
CHECK_GL_ERROR();
}
-void OGLTransitionerImpl::prepareEnvironment()
-{
- double EyePos(10.0);
- double RealF(1.0);
- double RealN(-1.0);
- double RealL(-1.0);
- double RealR(1.0);
- double RealB(-1.0);
- double RealT(1.0);
- double ClipN(EyePos+5.0*RealN);
- double ClipF(EyePos+15.0*RealF);
- double ClipL(RealL*8.0);
- double ClipR(RealR*8.0);
- double ClipB(RealB*8.0);
- double ClipT(RealT*8.0);
-
- CHECK_GL_ERROR();
- glMatrixMode(GL_PROJECTION);
- glm::mat4 projection = glm::frustum<float>(ClipL, ClipR, ClipB, ClipT, ClipN, ClipF);
- //This scaling is to take the plane with BottomLeftCorner(-1,-1,0) and TopRightCorner(1,1,0) and map it to the screen after the perspective division.
- glm::vec3 scale(1.0 / (((RealR * 2.0 * ClipN) / (EyePos * (ClipR - ClipL))) - ((ClipR + ClipL) / (ClipR - ClipL))),
- 1.0 / (((RealT * 2.0 * ClipN) / (EyePos * (ClipT - ClipB))) - ((ClipT + ClipB) / (ClipT - ClipB))),
- 1.0);
- projection = glm::scale(projection, scale);
- CHECK_GL_ERROR();
- glLoadMatrixf(glm::value_ptr(projection));
-
- CHECK_GL_ERROR();
- glMatrixMode(GL_MODELVIEW);
- glm::mat4 modelview = glm::translate(glm::mat4(), glm::vec3(0, 0, -EyePos));
- CHECK_GL_ERROR();
- glLoadMatrixf(glm::value_ptr(modelview));
- CHECK_GL_ERROR();
-}
-
const OGLFormat* OGLTransitionerImpl::chooseFormats()
{
const OGLFormat* pDetectedFormat=nullptr;