[Libreoffice-commits] core.git: 6 commits - slideshow/opengl slideshow/source

Emmanuel Gil Peyrot emmanuel.peyrot at collabora.com
Thu Nov 19 09:23:40 PST 2015


 slideshow/opengl/basicVertexShader.glsl                                |    2 
 slideshow/opengl/vortexVertexShader.glsl                               |    2 
 slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx   |  234 +++++-----
 slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx   |   53 +-
 slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx |   26 -
 5 files changed, 184 insertions(+), 133 deletions(-)

New commits:
commit cda5c7ab237fa839aa931556ec66ac37e6f6a955
Author: Emmanuel Gil Peyrot <emmanuel.peyrot at collabora.com>
Date:   Thu Nov 19 17:18:56 2015 +0000

    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

diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
index a7fa892..2a13ca1 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 972cb83..41e32ca 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 7be1acf..4244d9c 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();
 }
 
commit e18da092ef9a81202c9ec941bcb9876f257eed5b
Author: Emmanuel Gil Peyrot <emmanuel.peyrot at collabora.com>
Date:   Thu Nov 19 17:18:55 2015 +0000

    slideshow: Batch primitive display as much as possible
    
    We now set the state and upload all vertices data at once, before each
    batch, in order to minimize GL calls during drawing.
    
    The next step will be to move to shaders, in order to use per-primitive
    uniforms instead of changing the global modelview matrix and issuing
    another draw call.
    
    Change-Id: I8c7cf29047047b9cad575cc6264485ae77d6ba10

diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
index 11e6c4e..a7fa892 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -192,6 +192,58 @@ void OGLTransitionImpl::applyOverallOperations( double nTime, double SlideWidthS
         rOverallOperations[i]->interpolate(nTime,SlideWidthScale,SlideHeightScale);
 }
 
+static void display_primitives(const Primitives_t& primitives, double nTime, double WidthScale, double HeightScale)
+{
+    CHECK_GL_ERROR();
+    GLuint buffer;
+    glGenBuffers(1, &buffer);
+    CHECK_GL_ERROR();
+    glBindBuffer(GL_ARRAY_BUFFER, buffer);
+
+    int size = 0;
+    for (const Primitive& primitive: primitives)
+        size += primitive.getVerticesSize();
+
+    CHECK_GL_ERROR();
+    glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_STREAM_DRAW);
+    CHECK_GL_ERROR();
+    Vertex *buf = reinterpret_cast<Vertex*>(glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY));
+
+    std::vector<int> first_elements;
+    int last_pos = 0;
+    for (const Primitive& primitive: primitives) {
+        first_elements.push_back(last_pos);
+        int num = primitive.writeVertices(buf);
+        buf += num;
+        last_pos += num;
+    }
+    auto first = first_elements.begin();
+
+    CHECK_GL_ERROR();
+    glUnmapBuffer(GL_ARRAY_BUFFER);
+
+    // State initialization
+    // TODO: move that elsewhere.
+    CHECK_GL_ERROR();
+    glEnableClientState( GL_VERTEX_ARRAY );
+    CHECK_GL_ERROR();
+    glVertexPointer( 3, GL_FLOAT, sizeof(Vertex), reinterpret_cast<void*>(offsetof(Vertex, position)) );
+    CHECK_GL_ERROR();
+    glEnableClientState( GL_NORMAL_ARRAY );
+    CHECK_GL_ERROR();
+    glNormalPointer( GL_FLOAT , sizeof(Vertex) , reinterpret_cast<void*>(offsetof(Vertex, normal)) );
+    CHECK_GL_ERROR();
+    glEnableClientState( GL_TEXTURE_COORD_ARRAY );
+    CHECK_GL_ERROR();
+    glTexCoordPointer( 2, GL_FLOAT, sizeof(Vertex), reinterpret_cast<void*>(offsetof(Vertex, texcoord)) );
+
+    for (const Primitive& primitive: primitives)
+        primitive.display(nTime, WidthScale, HeightScale, *first++);
+
+    CHECK_GL_ERROR();
+    glDeleteBuffers(1, &buffer);
+}
+
 void
 OGLTransitionImpl::displaySlide(
         const double nTime,
@@ -216,8 +268,7 @@ OGLTransitionImpl::displaySlide(
         glTranslated( 0, 2 - surfaceLevel, 0 );
 
         glCullFace(GL_FRONT);
-        for(size_t i(0); i < primitives.size(); ++i)
-            primitives[i].display(nTime, SlideWidthScale, SlideHeightScale);
+        display_primitives(primitives, nTime, SlideWidthScale, SlideHeightScale);
         glCullFace(GL_BACK);
 
         slideShadow( nTime, primitives[0], SlideWidthScale, SlideHeightScale );
@@ -225,8 +276,7 @@ OGLTransitionImpl::displaySlide(
         glPopMatrix();
     }
 
-    for(size_t i(0); i < primitives.size(); ++i)
-        primitives[i].display(nTime, SlideWidthScale, SlideHeightScale);
+    display_primitives(primitives, nTime, SlideWidthScale, SlideHeightScale);
     CHECK_GL_ERROR();
 }
 
@@ -240,7 +290,7 @@ void OGLTransitionImpl::displayScene( double nTime, double SlideWidth, double Sl
     CHECK_GL_ERROR();
 }
 
-void Primitive::display(double nTime, double WidthScale, double HeightScale) const
+void Primitive::display(double nTime, double WidthScale, double HeightScale, int first) const
 {
     CHECK_GL_ERROR();
     glPushMatrix();
@@ -249,19 +299,8 @@ void Primitive::display(double nTime, double WidthScale, double HeightScale) con
     applyOperations( nTime, WidthScale, HeightScale );
 
     CHECK_GL_ERROR();
-    glEnableClientState( GL_VERTEX_ARRAY );
-    CHECK_GL_ERROR();
-    glNormalPointer( GL_FLOAT , 0 , &Normals[0] );
-    CHECK_GL_ERROR();
-    glEnableClientState( GL_NORMAL_ARRAY );
-    CHECK_GL_ERROR();
-    glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-    CHECK_GL_ERROR();
-    glTexCoordPointer( 2, GL_FLOAT, 0, &TexCoords[0] );
-    CHECK_GL_ERROR();
-    glVertexPointer( 3, GL_FLOAT, 0, &Vertices[0] );
-    CHECK_GL_ERROR();
-    glDrawArrays( GL_TRIANGLES, 0, Vertices.size() );
+    glDrawArrays( GL_TRIANGLES, first, Vertices.size() );
+
     CHECK_GL_ERROR();
     glPopMatrix();
     CHECK_GL_ERROR();
@@ -278,22 +317,19 @@ void Primitive::applyOperations(double nTime, double WidthScale, double HeightSc
 
 void SceneObject::display(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();
-    for(size_t i(0); i < maPrimitives.size(); ++i) {
-        // 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();
-        if (DispHeight > DispWidth)
-            glScaled(DispHeight/DispWidth, 1, 1);
-        else
-            glScaled(1, DispWidth/DispHeight, 1);
-        maPrimitives[i].display(nTime, 1, 1);
-        CHECK_GL_ERROR();
-        glPopMatrix();
-        CHECK_GL_ERROR();
-    }
+    glPushMatrix();
+    CHECK_GL_ERROR();
+    if (DispHeight > DispWidth)
+        glScaled(DispHeight/DispWidth, 1, 1);
+    else
+        glScaled(1, DispWidth/DispHeight, 1);
+    CHECK_GL_ERROR();
+    display_primitives(maPrimitives, nTime, 1, 1);
+    CHECK_GL_ERROR();
+    glPopMatrix();
     CHECK_GL_ERROR();
 }
 
@@ -1063,8 +1099,6 @@ Primitive& Primitive::operator=(const Primitive& rvalue)
 Primitive::Primitive(const Primitive& rvalue)
     : Operations(rvalue.Operations)
     , Vertices(rvalue.Vertices)
-    , Normals(rvalue.Normals)
-    , TexCoords(rvalue.TexCoords)
 {
 }
 
@@ -1074,8 +1108,6 @@ void Primitive::swap(Primitive& rOther)
 
     swap(Operations, rOther.Operations);
     swap(Vertices, rOther.Vertices);
-    swap(Normals, rOther.Normals);
-    swap(TexCoords, rOther.TexCoords);
 }
 
 void Primitive::pushTriangle(const glm::vec2& SlideLocation0,const glm::vec2& SlideLocation1,const glm::vec2& SlideLocation2)
@@ -1108,17 +1140,9 @@ void Primitive::pushTriangle(const glm::vec2& SlideLocation0,const glm::vec2& Sl
         Verts.push_back(glm::vec3( 2*SlideLocation1.x - 1, -2*SlideLocation1.y + 1 , 0.0 ));
     }
 
-    Vertices.push_back(Verts[0]);
-    Vertices.push_back(Verts[1]);
-    Vertices.push_back(Verts[2]);
-
-    TexCoords.push_back(Texs[0]);
-    TexCoords.push_back(Texs[1]);
-    TexCoords.push_back(Texs[2]);
-
-    Normals.push_back(glm::vec3(0,0,1));//all normals always face the screen when untransformed.
-    Normals.push_back(glm::vec3(0,0,1));//all normals always face the screen when untransformed.
-    Normals.push_back(glm::vec3(0,0,1));//all normals always face the screen when untransformed.
+    Vertices.push_back({Verts[0], glm::vec3(0, 0, 1), Texs[0]}); //all normals always face the screen when untransformed.
+    Vertices.push_back({Verts[1], glm::vec3(0, 0, 1), Texs[1]}); //all normals always face the screen when untransformed.
+    Vertices.push_back({Verts[2], glm::vec3(0, 0, 1), Texs[2]}); //all normals always face the screen when untransformed.
 }
 
 namespace
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
index 37df57e..972cb83 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
@@ -277,6 +277,14 @@ private:
     GLuint maTexture;
 };
 
+struct Vertex
+{
+    glm::vec3 position;
+    glm::vec3 normal;
+    glm::vec2 texcoord;
+};
+static_assert(sizeof(Vertex) == (3 + 3 + 2) * 4, "Vertex struct has wrong size/alignment");
+
 /** This class is a list of Triangles that will share Operations, and could possibly share
 */
 class Primitive
@@ -290,7 +298,7 @@ public:
     void swap(Primitive& rOther);
 
     void applyOperations(double nTime, double SlideWidthScale, double SlideHeightScale) const;
-    void display(double nTime, double SlideWidthScale, double SlideHeightScale) const;
+    void display(double nTime, double SlideWidthScale, double SlideHeightScale, 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.
 
@@ -311,7 +319,24 @@ public:
         @return
         the list of vertices
     */
-    const glm::vec3& getVertex(int n) const {return Vertices[n];}
+    const glm::vec3& getVertex(int n) const {return Vertices[n].position;}
+
+    /** accessor for the size of the vertices data
+
+        @return
+        the size in bytes of the Vertices data
+    */
+    int getVerticesSize() const {return Vertices.size() * sizeof(Vertex);}
+
+    /** copies all vertices to the C array passed
+
+        @return
+        the number of written vertices
+    */
+    int writeVertices(Vertex *location) const {
+        std::copy(Vertices.begin(), Vertices.end(), location);
+        return Vertices.size();
+    }
 
     /** list of Operations to be performed on this primitive.These operations will be called in the order they were pushed back in. In OpenGL this effectively uses the operations in the opposite order they were pushed back.
 
@@ -324,15 +349,7 @@ public:
 private:
     /** list of vertices
     */
-    std::vector<glm::vec3> Vertices;
-
-    /** list of Normals
-    */
-    std::vector<glm::vec3> Normals;
-
-    /** list of Texture Coordinates
-    */
-    std::vector<glm::vec2> TexCoords;
+    std::vector<Vertex> Vertices;
 };
 
 /** This class is to be derived to make any operation (transform) you may need in order to construct your transitions
commit 04e2caeba5e346fb5d415d633b1956ef24c41037
Author: Emmanuel Gil Peyrot <emmanuel.peyrot at collabora.com>
Date:   Thu Nov 19 17:18:54 2015 +0000

    slideshow: Use gl_ModelViewProjectionMatrix in vertex shaders
    
    ftransform() is deprecated, and we shouldn’t do an extraneous
    multiplication to obtain the two matrices together.
    
    Change-Id: Iaa16c106b8b702468f7be643a812107f0967acdd

diff --git a/slideshow/opengl/basicVertexShader.glsl b/slideshow/opengl/basicVertexShader.glsl
index da83554..bd26c1b 100644
--- a/slideshow/opengl/basicVertexShader.glsl
+++ b/slideshow/opengl/basicVertexShader.glsl
@@ -32,7 +32,7 @@ varying vec2 v_texturePosition;
 
 void main( void )
 {
-    gl_Position = ftransform();
+    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
     v_texturePosition = gl_MultiTexCoord0.xy;
 }
 
diff --git a/slideshow/opengl/vortexVertexShader.glsl b/slideshow/opengl/vortexVertexShader.glsl
index 07a00f2..ff86546 100755
--- a/slideshow/opengl/vortexVertexShader.glsl
+++ b/slideshow/opengl/vortexVertexShader.glsl
@@ -96,7 +96,7 @@ void main( void )
         v_textureSelect = 1;
     }
 
-    gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * v;
+    gl_Position = gl_ModelViewProjectionMatrix * v;
 
     v_texturePosition = gl_MultiTexCoord0.xy;
 }
commit cad6045f5c1870bbc7b3c909b08b84d9d1ccc235
Author: Emmanuel Gil Peyrot <emmanuel.peyrot at collabora.com>
Date:   Thu Nov 19 17:18:53 2015 +0000

    slideshow: Always enable normals, there is no case where they are empty
    
    Change-Id: Ia45a3ec98a1f548b5a976f485d4165bb3d1ff2e4

diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
index 54033df..11e6c4e 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -251,14 +251,9 @@ void Primitive::display(double nTime, double WidthScale, double HeightScale) con
     CHECK_GL_ERROR();
     glEnableClientState( GL_VERTEX_ARRAY );
     CHECK_GL_ERROR();
-    if(!Normals.empty())
-    {
-        CHECK_GL_ERROR();
-        glNormalPointer( GL_FLOAT , 0 , &Normals[0] );
-        CHECK_GL_ERROR();
-        glEnableClientState( GL_NORMAL_ARRAY );
-        CHECK_GL_ERROR();
-    }
+    glNormalPointer( GL_FLOAT , 0 , &Normals[0] );
+    CHECK_GL_ERROR();
+    glEnableClientState( GL_NORMAL_ARRAY );
     CHECK_GL_ERROR();
     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
     CHECK_GL_ERROR();
commit ba02afad40570cf45b1f4af3287333e7c060a3fd
Author: Emmanuel Gil Peyrot <emmanuel.peyrot at collabora.com>
Date:   Thu Nov 19 17:18:52 2015 +0000

    slideshow: Don’t create the permTexture if the shaders don’t use it
    
    Change-Id: I0aefe2130a85303213e247676d45546d9859cf62

diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
index 529034f..54033df 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -1525,16 +1525,16 @@ void ShaderTransition::impl_preparePermShader()
             CHECK_GL_ERROR();
         }
 
-        glActiveTexture(GL_TEXTURE1);
-        CHECK_GL_ERROR();
-        if( !m_nHelperTexture )
-            initPermTexture( &m_nHelperTexture );
-
-        glActiveTexture(GL_TEXTURE0);
-        CHECK_GL_ERROR();
-
         location = glGetUniformLocation( m_nProgramObject, "permTexture" );
         if( location != -1 ) {
+            glActiveTexture(GL_TEXTURE1);
+            CHECK_GL_ERROR();
+            if( !m_nHelperTexture )
+                initPermTexture( &m_nHelperTexture );
+
+            glActiveTexture(GL_TEXTURE0);
+            CHECK_GL_ERROR();
+
             glUniform1i( location, 1 );  // texture unit 1
             CHECK_GL_ERROR();
         }
commit f41358a71f4a6641141d90c33cdd763f9c4d3395
Author: Emmanuel Gil Peyrot <emmanuel.peyrot at collabora.com>
Date:   Thu Nov 19 17:18:51 2015 +0000

    slideshow: Rename getVertices into getVertex, to match its only usage

diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
index e9c9214..529034f 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -818,13 +818,13 @@ std::shared_ptr<OGLTransitionImpl> makeHelix( sal_uInt16 nRows )
 
         Tile.pushTriangle(glm::vec2( 1.0 , iPDn ) , glm::vec2( 1.0 , iDn ) , glm::vec2( 0.0 , iPDn ));
 
-        Tile.Operations.push_back( makeSRotate( glm::vec3( 0 , 1 , 0 ) , ( Tile.getVertices()[1] + Tile.getVertices()[3] )/2.0f , 180 ,
+        Tile.Operations.push_back( makeSRotate( glm::vec3( 0 , 1 , 0 ) , ( Tile.getVertex(1) + Tile.getVertex(3) )/2.0f , 180 ,
                                                 true, std::min(std::max(static_cast<double>(i - nRows/2.0)*invN/2.0,0.0),1.0),
                                                 std::min(std::max(static_cast<double>(i + nRows/2.0)*invN/2.0,0.0),1.0) ) );
 
         aLeavingSlide.push_back(Tile);
 
-        Tile.Operations.push_back( makeSRotate( glm::vec3( 0 , 1 , 0 ) , ( Tile.getVertices()[1] + Tile.getVertices()[3] )/2.0f , -180 , false,0.0,1.0) );
+        Tile.Operations.push_back( makeSRotate( glm::vec3( 0 , 1 , 0 ) , ( Tile.getVertex(1) + Tile.getVertex(3) )/2.0f , -180 , false,0.0,1.0) );
 
         aEnteringSlide.push_back(Tile);
 
@@ -867,10 +867,10 @@ std::shared_ptr<OGLTransitionImpl> makeNByMTileFlip( sal_uInt16 n, sal_uInt16 m
             aTile.pushTriangle(x21, x11, x12);
             aTile.pushTriangle(x22, x21, x12);
 
-            aTile.Operations.push_back(makeSRotate( glm::vec3(0 , 1, 0), (aTile.getVertices()[1] + aTile.getVertices()[3]) / 2.0f, 180 , true, x11.x * x11.y / 2.0f , ((x22.x * x22.y) + 1.0f) / 2.0f));
+            aTile.Operations.push_back(makeSRotate( glm::vec3(0 , 1, 0), (aTile.getVertex(1) + aTile.getVertex(3)) / 2.0f, 180 , true, x11.x * x11.y / 2.0f , ((x22.x * x22.y) + 1.0f) / 2.0f));
             aLeavingSlide.push_back(aTile);
 
-            aTile.Operations.push_back(makeSRotate( glm::vec3(0 , 1, 0), (aTile.getVertices()[1] + aTile.getVertices()[3]) / 2.0f, -180, false, x11.x * x11.y / 2.0f , ((x22.x * x22.y) + 1.0f) / 2.0f));
+            aTile.Operations.push_back(makeSRotate( glm::vec3(0 , 1, 0), (aTile.getVertex(1) + aTile.getVertex(3)) / 2.0f, -180, false, x11.x * x11.y / 2.0f , ((x22.x * x22.y) + 1.0f) / 2.0f));
             aEnteringSlide.push_back(aTile);
         }
     }
@@ -1901,7 +1901,7 @@ std::shared_ptr<OGLTransitionImpl> makeGlitter()
             Primitive aHexagon;
             createHexagon(aHexagon, x, y, NX, NY);
 
-            glm::vec3 aCenter = aHexagon.getVertices()[2];
+            glm::vec3 aCenter = aHexagon.getVertex(2);
 
             float fRandom = comphelper::rng::uniform_real_distribution(-0.25, std::nextafter(0.2, DBL_MAX));
 
diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
index a14694f..37df57e 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx
@@ -311,7 +311,7 @@ public:
         @return
         the list of vertices
     */
-    const std::vector<glm::vec3>& getVertices() const {return Vertices;}
+    const glm::vec3& getVertex(int n) const {return Vertices[n];}
 
     /** list of Operations to be performed on this primitive.These operations will be called in the order they were pushed back in. In OpenGL this effectively uses the operations in the opposite order they were pushed back.
 


More information about the Libreoffice-commits mailing list