LibreOffice Module slideshow (master) 1
TransitionImpl.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * Copyright 2008 by Sun Microsystems, Inc.
7 *
8 * OpenOffice.org - a multi-platform office productivity suite
9 *
10 * This file is part of OpenOffice.org.
11 *
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
15 *
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
26 *
27 ************************************************************************/
28#ifndef INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
29#define INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
30
31#include <config_lgpl.h>
32#include <epoxy/gl.h>
33#include <glm/gtc/type_ptr.hpp>
34
35#include <o3tl/safeint.hxx>
36#include <sal/types.h>
37
38#include <limits>
39#include <memory>
40#include <vector>
41
42class Primitive;
43class OpenGLContext;
44class Operation;
45class SceneObject;
46class TransitionData;
47
49{
51 mbUseMipMapLeaving( true ),
52 mbUseMipMapEntering( true ),
54 {
55 }
56
61
65};
66
67typedef std::vector<Primitive> Primitives_t;
68typedef std::vector<std::shared_ptr<SceneObject> > SceneObjects_t;
69typedef std::vector<std::shared_ptr<Operation> > Operations_t;
70
72{
73public:
74 inline TransitionScene(
75 Primitives_t&& rLeavingSlidePrimitives,
76 Primitives_t&& rEnteringSlidePrimitives,
77 Operations_t&& rOverallOperations = Operations_t(),
78 SceneObjects_t&& rSceneObjects = SceneObjects_t()
79 );
80
82
83 TransitionScene(TransitionScene const& rOther);
85
86 void swap(TransitionScene& rOther);
87
89 {
91 }
92
94 {
96 }
97
99 {
100 return maOverallOperations;
101 }
102
104 {
105 return maSceneObjects;
106 }
107
108private:
112
116
120
124};
125
131{
132public:
133 virtual ~OGLTransitionImpl();
134
137
140 bool prepare( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, OpenGLContext *pContext );
143 void display( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight, OpenGLContext *pContext );
146 void finish();
147
149 {
150 return maSettings;
151 }
152
153protected:
154 OGLTransitionImpl(const TransitionScene& rScene, const TransitionSettings& rSettings)
155 : maScene(rScene)
156 , maSettings(rSettings)
157 {}
158
160 {
161 return maScene;
162 }
163
164 void displaySlide( double nTime, sal_Int32 glSlideTex, const Primitives_t& primitives, double SlideWidthScale, double SlideHeightScale );
165 void displayUnbufferedSlide( double nTime, sal_Int32 glSlideTex, const Primitives_t& primitives, double SlideWidthScale, double SlideHeightScale );
166 void displayScene( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight);
167 void applyOverallOperations( double nTime, double SlideWidthScale, double SlideHeightScale );
168
169private:
174 virtual void prepare( double SlideWidth, double SlideHeight );
175
180 virtual void cleanup();
181
186 virtual void prepareTransition( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, OpenGLContext *pContext );
187
192 virtual void finishTransition();
193
199 virtual void displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale, OpenGLContext *pContext );
200
205 virtual GLuint makeShader() const = 0;
206
207private:
210
214
220
226
228
229 std::vector<int> m_nFirstIndices;
230
231protected:
235
239
242 GLint m_nTimeLocation = -1;
243};
244
245
246// "Constructors" of available transitions
247std::shared_ptr<OGLTransitionImpl> makeOutsideCubeFaceToLeft();
248std::shared_ptr<OGLTransitionImpl> makeInsideCubeFaceToLeft();
249std::shared_ptr<OGLTransitionImpl> makeNByMTileFlip( sal_uInt16 n, sal_uInt16 m );
250std::shared_ptr<OGLTransitionImpl> makeRevolvingCircles( sal_uInt16 nCircles , sal_uInt16 nPointsOnCircles );
251std::shared_ptr<OGLTransitionImpl> makeHelix( sal_uInt16 nRows );
252std::shared_ptr<OGLTransitionImpl> makeFallLeaving();
253std::shared_ptr<OGLTransitionImpl> makeTurnAround();
254std::shared_ptr<OGLTransitionImpl> makeTurnDown();
255std::shared_ptr<OGLTransitionImpl> makeIris();
256std::shared_ptr<OGLTransitionImpl> makeRochade();
257std::shared_ptr<OGLTransitionImpl> makeVenetianBlinds( bool vertical, int parts );
258std::shared_ptr<OGLTransitionImpl> makeStatic();
259std::shared_ptr<OGLTransitionImpl> makeDissolve();
260std::shared_ptr<OGLTransitionImpl> makeVortex();
261std::shared_ptr<OGLTransitionImpl> makeRipple();
262std::shared_ptr<OGLTransitionImpl> makeGlitter();
263std::shared_ptr<OGLTransitionImpl> makeHoneycomb();
264std::shared_ptr<OGLTransitionImpl> makeNewsflash();
265
268std::shared_ptr<OGLTransitionImpl> makeDiamond();
269std::shared_ptr<OGLTransitionImpl> makeFadeSmoothly();
270// fade through black or white
271std::shared_ptr<OGLTransitionImpl> makeFadeThroughColor( bool white = false );
272
274{
275public:
276 SceneObject();
277 virtual ~SceneObject();
278 SceneObject(const SceneObject&) = delete;
280
281 virtual void prepare(GLuint /* program */) {}
282 virtual void display(GLint sceneTransformLocation, GLint primitiveTransformLocation, double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight ) const;
283 virtual void finish() {}
284
285 void pushPrimitive (const Primitive &p);
286
287protected:
291 std::vector<int> maFirstIndices;
292};
293
294struct Vertex
295{
296 glm::vec3 position;
297 glm::vec3 normal;
298 glm::vec2 texcoord;
299};
300static_assert(sizeof(Vertex) == (3 + 3 + 2) * 4, "Vertex struct has wrong size/alignment");
301
305{
306public:
308 // making copy constructor explicit makes the class un-suitable for use with stl containers
309 Primitive(const Primitive& rvalue);
310 Primitive& operator=(const Primitive& rvalue);
311
312 void swap(Primitive& rOther);
313
314 void applyOperations(glm::mat4& matrix, double nTime, double SlideWidthScale, double SlideHeightScale) const;
315 void display(GLint primitiveTransformLocation, double nTime, double WidthScale, double HeightScale) const;
316 void display(GLint primitiveTransformLocation, double nTime, double WidthScale, double HeightScale, int first) const;
317
330 void pushTriangle(const glm::vec2& SlideLocation0,const glm::vec2& SlideLocation1,const glm::vec2& SlideLocation2);
331
337 const glm::vec3& getVertex(int n) const {return Vertices[n].position;}
338
340 {
341 assert(Vertices.size() < o3tl::make_unsigned(std::numeric_limits<int>::max()));
342 return int(unsigned(Vertices.size()));
343 }
344
350 int getVerticesByteSize() const {return Vertices.size() * sizeof(Vertex);}
351
357 int writeVertices(Vertex *location) const {
358 std::copy(Vertices.begin(), Vertices.end(), location);
359 return Vertices.size();
360 }
361
369
370private:
373 std::vector<Vertex> Vertices;
374};
375
377 Primitives_t&& rLeavingSlidePrimitives,
378 Primitives_t&& rEnteringSlidePrimitives,
379 Operations_t&& rOverallOperations,
380 SceneObjects_t&& rSceneObjects
381)
382 : maLeavingSlidePrimitives(std::move(rLeavingSlidePrimitives))
383 , maEnteringSlidePrimitives(std::move(rEnteringSlidePrimitives))
384 , maOverallOperations(std::move(rOverallOperations))
385 , maSceneObjects(std::move(rSceneObjects))
386{
387}
388
390
391#endif // INCLUDED_SLIDESHOW_TRANSITION_HXX_
392
393/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< OGLTransitionImpl > makeFadeThroughColor(bool white=false)
std::shared_ptr< OGLTransitionImpl > makeTurnAround()
std::shared_ptr< OGLTransitionImpl > makeHoneycomb()
std::shared_ptr< OGLTransitionImpl > makeRipple()
std::shared_ptr< OGLTransitionImpl > makeVenetianBlinds(bool vertical, int parts)
std::vector< Primitive > Primitives_t
std::shared_ptr< OGLTransitionImpl > makeGlitter()
std::shared_ptr< OGLTransitionImpl > makeDiamond()
2D replacements
std::shared_ptr< OGLTransitionImpl > makeDissolve()
std::shared_ptr< OGLTransitionImpl > makeRochade()
std::shared_ptr< OGLTransitionImpl > makeRevolvingCircles(sal_uInt16 nCircles, sal_uInt16 nPointsOnCircles)
std::shared_ptr< OGLTransitionImpl > makeNByMTileFlip(sal_uInt16 n, sal_uInt16 m)
std::shared_ptr< OGLTransitionImpl > makeFallLeaving()
std::shared_ptr< OGLTransitionImpl > makeFadeSmoothly()
std::shared_ptr< OGLTransitionImpl > makeIris()
std::vector< std::shared_ptr< Operation > > Operations_t
std::shared_ptr< OGLTransitionImpl > makeNewsflash()
std::shared_ptr< OGLTransitionImpl > makeStatic()
std::shared_ptr< OGLTransitionImpl > makeOutsideCubeFaceToLeft()
std::shared_ptr< OGLTransitionImpl > makeTurnDown()
std::vector< std::shared_ptr< SceneObject > > SceneObjects_t
std::shared_ptr< OGLTransitionImpl > makeVortex()
std::shared_ptr< OGLTransitionImpl > makeHelix(sal_uInt16 nRows)
std::shared_ptr< OGLTransitionImpl > makeInsideCubeFaceToLeft()
OpenGL 3D Transition class.
std::vector< int > m_nFirstIndices
void displaySlide(double nTime, sal_Int32 glSlideTex, const Primitives_t &primitives, double SlideWidthScale, double SlideHeightScale)
void uploadModelViewProjectionMatrices()
Calculates the projection and model/view matrices, and upload them.
TransitionSettings const & getSettings() const
GLint m_nOperationsTransformLocation
GLint m_nTimeLocation
Location of the "time" uniform.
OGLTransitionImpl & operator=(const OGLTransitionImpl &)=delete
void finish()
Clean up after transition.
const TransitionScene maScene
virtual void displaySlides_(double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale, OpenGLContext *pContext)
This function is called in display method to display the slides.
void display(double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight, OpenGLContext *pContext)
Display a step of the transition.
GLuint m_nVertexBufferObject
VBO in which to put primitive data.
GLuint m_nProgramObject
GLSL program object.
virtual void prepareTransition(sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, OpenGLContext *pContext)
This function is called after glx context is ready to let the transition prepare GL related things,...
virtual void finishTransition()
This function is called when the transition needs to clear after itself, like delete own textures etc...
void displayScene(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight)
OGLTransitionImpl(const OGLTransitionImpl &)=delete
virtual void cleanup()
This function is called in display method to prepare the slides, scene, etc.
GLint m_nPrimitiveTransformLocation
Uniform locations for transform matrices.
void displayUnbufferedSlide(double nTime, sal_Int32 glSlideTex, const Primitives_t &primitives, double SlideWidthScale, double SlideHeightScale)
bool prepare(sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, OpenGLContext *pContext)
Prepare transition.
virtual ~OGLTransitionImpl()
TransitionScene const & getScene() const
GLint m_nPositionLocation
Per-vertex attribute locations.
void applyOverallOperations(double nTime, double SlideWidthScale, double SlideHeightScale)
virtual GLuint makeShader() const =0
This function is called in prepare method to create the GL program.
OGLTransitionImpl(const TransitionScene &rScene, const TransitionSettings &rSettings)
const TransitionSettings maSettings
This class is to be derived to make any operation (transform) you may need in order to construct your...
Definition: Operation.hxx:39
This class is a list of Triangles that will share Operations, and could possibly share.
void applyOperations(glm::mat4 &matrix, double nTime, double SlideWidthScale, double SlideHeightScale) const
int writeVertices(Vertex *location) const
copies all vertices to the C array passed
Operations_t Operations
list of Operations to be performed on this primitive.These operations will be called in the order the...
void swap(Primitive &rOther)
std::vector< Vertex > Vertices
list of vertices
const glm::vec3 & getVertex(int n) const
guards against directly changing the vertices
void display(GLint primitiveTransformLocation, double nTime, double WidthScale, double HeightScale) const
int getVerticesByteSize() const
accessor for the size of the vertices data
void pushTriangle(const glm::vec2 &SlideLocation0, const glm::vec2 &SlideLocation1, const glm::vec2 &SlideLocation2)
PushBack a vertex,normal, and tex coord.
Primitive & operator=(const Primitive &rvalue)
int getVerticesCount() const
virtual void finish()
void pushPrimitive(const Primitive &p)
Primitives_t maPrimitives
All the surrounding scene primitives.
virtual void prepare(GLuint)
std::vector< int > maFirstIndices
virtual ~SceneObject()
SceneObject & operator=(const SceneObject &)=delete
SceneObject(const SceneObject &)=delete
virtual void display(GLint sceneTransformLocation, GLint primitiveTransformLocation, double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight) const
const SceneObjects_t & getSceneObjects() const
void swap(TransitionScene &rOther)
Primitives_t maLeavingSlidePrimitives
All the primitives that use the leaving slide texture.
TransitionScene(Primitives_t &&rLeavingSlidePrimitives, Primitives_t &&rEnteringSlidePrimitives, Operations_t &&rOverallOperations=Operations_t(), SceneObjects_t &&rSceneObjects=SceneObjects_t())
SceneObjects_t maSceneObjects
All the surrounding scene objects.
const Operations_t & getOperations() const
const Primitives_t & getEnteringSlide() const
const Primitives_t & getLeavingSlide() const
Operations_t maOverallOperations
All the operations that should be applied to both leaving and entering slide primitives.
Primitives_t maEnteringSlidePrimitives
All the primitives that use the leaving slide texture.
TransitionScene & operator=(const TransitionScene &rOther)
float u
sal_Int64 n
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
bool mbUseMipMapLeaving
Whether to use mipmapping for slides textures.
float mnRequiredGLVersion
which GL version does the transition require
glm::vec3 position
glm::vec2 texcoord
glm::vec3 normal