summaryrefslogtreecommitdiff
path: root/slideshow
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <emmanuel.peyrot@collabora.com>2015-11-19 17:18:56 +0000
committerTor Lillqvist <tml@collabora.com>2015-11-19 19:21:54 +0200
commitcda5c7ab237fa839aa931556ec66ac37e6f6a955 (patch)
treee376951dc5553489957969a5b7cf5fdadfbd9432 /slideshow
parente18da092ef9a81202c9ec941bcb9876f257eed5b (diff)
slideshow: Port all matrix operations from GL to glm
We are still using glPushMatrix/glMultMatrix/glPopMatrix until everything is moved to shaders, at which point we will upload it with glUniformMatrix instead. Change-Id: I1684700eb9ed5867c5a2ae2b4e8cf2f1805f4d70
Diffstat (limited to 'slideshow')
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx87
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx14
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx26
3 files changed, 71 insertions, 56 deletions
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
index a7fa892decd1..2a13ca134b75 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -27,6 +27,7 @@
************************************************************************/
#include <GL/glew.h>
+#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <vcl/opengl/OpenGLHelper.hxx>
@@ -188,8 +189,12 @@ void OGLTransitionImpl::display( double nTime, sal_Int32 glLeavingSlideTex, sal_
void OGLTransitionImpl::applyOverallOperations( double nTime, double SlideWidthScale, double SlideHeightScale )
{
const Operations_t& rOverallOperations(maScene.getOperations());
+ glm::mat4 matrix;
for(size_t i(0); i != rOverallOperations.size(); ++i)
- rOverallOperations[i]->interpolate(nTime,SlideWidthScale,SlideHeightScale);
+ rOverallOperations[i]->interpolate(matrix, nTime, SlideWidthScale, SlideHeightScale);
+ CHECK_GL_ERROR();
+ glMultMatrixf(glm::value_ptr(matrix));
+ CHECK_GL_ERROR();
}
static void display_primitives(const Primitives_t& primitives, double nTime, double WidthScale, double HeightScale)
@@ -264,8 +269,10 @@ OGLTransitionImpl::displaySlide(
/* reflected slides */
glPushMatrix();
- glScaled( 1, -1, 1 );
- glTranslated( 0, 2 - surfaceLevel, 0 );
+ glm::mat4 matrix;
+ matrix = glm::scale(matrix, glm::vec3(1, -1, 1));
+ matrix = glm::translate(matrix, glm::vec3(0, 2 - surfaceLevel, 0));
+ glMultMatrixf(glm::value_ptr(matrix));
glCullFace(GL_FRONT);
display_primitives(primitives, nTime, SlideWidthScale, SlideHeightScale);
@@ -308,10 +315,13 @@ void Primitive::display(double nTime, double WidthScale, double HeightScale, int
void Primitive::applyOperations(double nTime, double WidthScale, double HeightScale) const
{
- CHECK_GL_ERROR();
+ glm::mat4 matrix;
for(size_t i(0); i < Operations.size(); ++i)
- Operations[i]->interpolate( nTime ,WidthScale,HeightScale);
- glScaled(WidthScale,HeightScale,1);
+ 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();
}
@@ -322,10 +332,12 @@ void SceneObject::display(double nTime, double /* SlideWidth */, double /* Slide
CHECK_GL_ERROR();
glPushMatrix();
CHECK_GL_ERROR();
+ glm::mat4 matrix;
if (DispHeight > DispWidth)
- glScaled(DispHeight/DispWidth, 1, 1);
+ matrix = glm::scale(matrix, glm::vec3(DispHeight/DispWidth, 1, 1));
else
- glScaled(1, DispWidth/DispHeight, 1);
+ matrix = glm::scale(matrix, glm::vec3(1, DispWidth/DispHeight, 1));
+ glMultMatrixf(glm::value_ptr(matrix));
CHECK_GL_ERROR();
display_primitives(maPrimitives, nTime, 1, 1);
CHECK_GL_ERROR();
@@ -992,74 +1004,69 @@ inline double intervalInter(double t, double T0, double T1)
return ( t - T0 ) / ( T1 - T0 );
}
-void STranslate::interpolate(double t,double SlideWidthScale,double SlideHeightScale) const
+void STranslate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
{
- CHECK_GL_ERROR();
if(t <= mnT0)
return;
if(!mbInterpolate || t > mnT1)
t = mnT1;
t = intervalInter(t,mnT0,mnT1);
- glTranslated(SlideWidthScale*t*vector.x,SlideHeightScale*t*vector.y,t*vector.z);
- CHECK_GL_ERROR();
+ matrix = glm::translate(matrix, glm::vec3(SlideWidthScale*t*vector.x, SlideHeightScale*t*vector.y, t*vector.z));
}
-void SRotate::interpolate(double t,double SlideWidthScale,double SlideHeightScale) const
+void SRotate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
{
- CHECK_GL_ERROR();
if(t <= mnT0)
return;
if(!mbInterpolate || t > mnT1)
t = mnT1;
t = intervalInter(t,mnT0,mnT1);
- glTranslated(SlideWidthScale*origin.x,SlideHeightScale*origin.y,origin.z);
- glScaled(SlideWidthScale,SlideHeightScale,1);
- glRotated(t*angle,axis.x,axis.y,axis.z);
- glScaled(1/SlideWidthScale,1/SlideHeightScale,1);
- glTranslated(-SlideWidthScale*origin.x,-SlideHeightScale*origin.y,-origin.z);
- CHECK_GL_ERROR();
+ glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, origin.z);
+ glm::vec3 scale_vector(SlideWidthScale, SlideHeightScale, 1);
+ matrix = glm::translate(matrix, translation_vector);
+ matrix = glm::scale(matrix, scale_vector);
+ matrix = glm::rotate(matrix, static_cast<float>(t*angle), axis);
+ matrix = glm::scale(matrix, 1.f / scale_vector);
+ matrix = glm::translate(matrix, -translation_vector);
}
-void SScale::interpolate(double t,double SlideWidthScale,double SlideHeightScale) const
+void SScale::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
{
- CHECK_GL_ERROR();
if(t <= mnT0)
return;
if(!mbInterpolate || t > mnT1)
t = mnT1;
t = intervalInter(t,mnT0,mnT1);
- glTranslated(SlideWidthScale*origin.x,SlideHeightScale*origin.y,origin.z);
- glScaled((1-t) + t*scale.x,(1-t) + t*scale.y,(1-t) + t*scale.z);
- glTranslated(-SlideWidthScale*origin.x,-SlideHeightScale*origin.y,-origin.z);
- CHECK_GL_ERROR();
+ glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, origin.z);
+ matrix = glm::translate(matrix, translation_vector);
+ matrix = glm::scale(matrix, static_cast<float>(1 - t) + static_cast<float>(t) * scale);
+ matrix = glm::translate(matrix, -translation_vector);
}
-void RotateAndScaleDepthByWidth::interpolate(double t,double SlideWidthScale,double SlideHeightScale) const
+void RotateAndScaleDepthByWidth::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
{
- CHECK_GL_ERROR();
if(t <= mnT0)
return;
if(!mbInterpolate || t > mnT1)
t = mnT1;
t = intervalInter(t,mnT0,mnT1);
- glTranslated(SlideWidthScale*origin.x,SlideHeightScale*origin.y,SlideWidthScale*origin.z);
- glRotated(t*angle,axis.x,axis.y,axis.z);
- glTranslated(-SlideWidthScale*origin.x,-SlideHeightScale*origin.y,-SlideWidthScale*origin.z);
- CHECK_GL_ERROR();
+ glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, SlideWidthScale*origin.z);
+ matrix = glm::translate(matrix, translation_vector);
+ matrix = glm::rotate(matrix, static_cast<float>(t*angle), axis);
+ matrix = glm::translate(matrix, -translation_vector);
}
-void RotateAndScaleDepthByHeight::interpolate(double t,double SlideWidthScale,double SlideHeightScale) const
+void RotateAndScaleDepthByHeight::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
{
- CHECK_GL_ERROR();
if(t <= mnT0)
return;
if(!mbInterpolate || t > mnT1)
t = mnT1;
t = intervalInter(t,mnT0,mnT1);
- glTranslated(SlideWidthScale*origin.x,SlideHeightScale*origin.y,SlideHeightScale*origin.z);
- glRotated(t*angle,axis.x,axis.y,axis.z);
- glTranslated(-SlideWidthScale*origin.x,-SlideHeightScale*origin.y,-SlideHeightScale*origin.z);
- CHECK_GL_ERROR();
+ glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, SlideHeightScale*origin.z);
+ matrix = glm::translate(matrix, translation_vector);
+ matrix = glm::rotate(matrix, static_cast<float>(t*angle), axis);
+ matrix = glm::translate(matrix, -translation_vector);
}
SEllipseTranslate::SEllipseTranslate(double dWidth, double dHeight, double dStartPosition,
@@ -1072,7 +1079,7 @@ SEllipseTranslate::SEllipseTranslate(double dWidth, double dHeight, double dStar
endPosition = dEndPosition;
}
-void SEllipseTranslate::interpolate(double t,double /* SlideWidthScale */,double /* SlideHeightScale */) const
+void SEllipseTranslate::interpolate(glm::mat4& matrix, double t, double /* SlideWidthScale */, double /* SlideHeightScale */) const
{
if(t <= mnT0)
return;
@@ -1086,7 +1093,7 @@ void SEllipseTranslate::interpolate(double t,double /* SlideWidthScale */,double
x = width*(cos (a2) - cos (a1))/2;
y = height*(sin (a2) - sin (a1))/2;
- glTranslated(x, 0, y);
+ matrix = glm::translate(matrix, glm::vec3(x, 0, y));
}
Primitive& Primitive::operator=(const Primitive& rvalue)
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
index 972cb83a61e5..41e32cadb8aa 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
@@ -384,7 +384,7 @@ public:
height of slide divided by height of window
*/
- virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const = 0;
+ virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const = 0;
protected:
Operation(bool bInterpolate, double nT0, double nT1):
@@ -396,7 +396,7 @@ protected:
class SRotate: public Operation
{
public:
- virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const override;
+ virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override;
/** Constructor
@@ -445,7 +445,7 @@ makeSRotate(const glm::vec3& Axis, const glm::vec3& Origin, double Angle,
class SScale: public Operation
{
public:
- virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const override;
+ virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override;
/** Constructor
@@ -480,7 +480,7 @@ makeSScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T
class STranslate: public Operation
{
public:
- virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const override;
+ virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override;
/** Constructor
@@ -513,7 +513,7 @@ makeSTranslate(const glm::vec3& Vector,bool bInter, double T0, double T1);
class SEllipseTranslate: public Operation
{
public:
- virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const override;
+ virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override;
/** Constructor
@@ -551,7 +551,7 @@ makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, doub
class RotateAndScaleDepthByWidth: public Operation
{
public:
- virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const override;
+ virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override;
RotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1);
virtual ~RotateAndScaleDepthByWidth(){}
@@ -569,7 +569,7 @@ makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,dou
class RotateAndScaleDepthByHeight: public Operation
{
public:
- virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const override;
+ virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override;
RotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1);
virtual ~RotateAndScaleDepthByHeight(){}
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
index 7be1acfc3507..4244d9c0b1ca 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx
@@ -27,6 +27,8 @@
************************************************************************/
#include <sal/types.h>
+#include <glm/gtc/matrix_transform.hpp>
+#include <glm/gtc/type_ptr.hpp>
#include <memory>
@@ -1021,9 +1023,6 @@ void OGLTransitionerImpl::impl_createTexture(
void OGLTransitionerImpl::prepareEnvironment()
{
- CHECK_GL_ERROR();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
double EyePos(10.0);
double RealF(1.0);
double RealN(-1.0);
@@ -1037,14 +1036,23 @@ void OGLTransitionerImpl::prepareEnvironment()
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.
- glScaled( 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 );
- glFrustum(ClipL,ClipR,ClipB,ClipT,ClipN,ClipF);
+ 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);
- glLoadIdentity();
- glTranslated(0,0,-EyePos);
+ glm::mat4 modelview = glm::translate(glm::mat4(), glm::vec3(0, 0, -EyePos));
+ CHECK_GL_ERROR();
+ glLoadMatrixf(glm::value_ptr(modelview));
CHECK_GL_ERROR();
}