1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2008 by Sun Microsystems, Inc.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
28 #ifndef INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
29 #define INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
31 #include <config_lgpl.h>
33 #include <glm/gtc/type_ptr.hpp>
35 #include <o3tl/safeint.hxx>
36 #include <sal/types.h>
48 struct TransitionSettings
50 TransitionSettings() :
51 mbUseMipMapLeaving( true ),
52 mbUseMipMapEntering( true ),
53 mnRequiredGLVersion( 3.0f
)
57 /** Whether to use mipmapping for slides textures
59 bool mbUseMipMapLeaving
;
60 bool mbUseMipMapEntering
;
62 /** which GL version does the transition require
64 float mnRequiredGLVersion
;
67 typedef std::vector
<Primitive
> Primitives_t
;
68 typedef std::vector
<std::shared_ptr
<SceneObject
> > SceneObjects_t
;
69 typedef std::vector
<std::shared_ptr
<Operation
> > Operations_t
;
74 inline TransitionScene(
75 Primitives_t
&& rLeavingSlidePrimitives
,
76 Primitives_t
&& rEnteringSlidePrimitives
,
77 Operations_t
&& rOverallOperations
= Operations_t(),
78 SceneObjects_t
&& rSceneObjects
= SceneObjects_t()
81 inline ~TransitionScene();
83 TransitionScene(TransitionScene
const& rOther
);
84 TransitionScene
& operator=(const TransitionScene
& rOther
);
86 void swap(TransitionScene
& rOther
);
88 const Primitives_t
& getLeavingSlide() const
90 return maLeavingSlidePrimitives
;
93 const Primitives_t
& getEnteringSlide() const
95 return maEnteringSlidePrimitives
;
98 const Operations_t
& getOperations() const
100 return maOverallOperations
;
103 const SceneObjects_t
& getSceneObjects() const
105 return maSceneObjects
;
109 /** All the primitives that use the leaving slide texture
111 Primitives_t maLeavingSlidePrimitives
;
113 /** All the primitives that use the leaving slide texture
115 Primitives_t maEnteringSlidePrimitives
;
117 /** All the operations that should be applied to both leaving and entering slide primitives. 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.
119 Operations_t maOverallOperations
;
121 /** All the surrounding scene objects
123 SceneObjects_t maSceneObjects
;
126 /** OpenGL 3D Transition class. It implicitly is constructed from XOGLTransition
128 It holds Primitives and Operations on those primitives.
130 class OGLTransitionImpl
133 virtual ~OGLTransitionImpl();
135 OGLTransitionImpl(const OGLTransitionImpl
&) = delete;
136 OGLTransitionImpl
& operator=(const OGLTransitionImpl
&) = delete;
138 /** Prepare transition.
140 bool prepare( sal_Int32 glLeavingSlideTex
, sal_Int32 glEnteringSlideTex
, OpenGLContext
*pContext
);
141 /** Display a step of the transition.
143 void display( double nTime
, sal_Int32 glLeavingSlideTex
, sal_Int32 glEnteringSlideTex
, double SlideWidth
, double SlideHeight
, double DispWidth
, double DispHeight
, OpenGLContext
*pContext
);
144 /** Clean up after transition.
148 TransitionSettings
const& getSettings() const
154 OGLTransitionImpl(const TransitionScene
& rScene
, const TransitionSettings
& rSettings
)
156 , maSettings(rSettings
)
159 TransitionScene
const& getScene() const
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
);
170 /** This function is called in display method to prepare the slides, scene, etc.
172 * Default implementation does nothing.
174 virtual void prepare( double SlideWidth
, double SlideHeight
);
176 /** This function is called in display method to prepare the slides, scene, etc.
178 * Default implementation does nothing.
180 virtual void cleanup();
182 /** This function is called after glx context is ready to let the transition prepare GL related things, like GLSL program.
184 * Default implementation does nothing.
186 virtual void prepareTransition( sal_Int32 glLeavingSlideTex
, sal_Int32 glEnteringSlideTex
, OpenGLContext
*pContext
);
188 /** This function is called when the transition needs to clear after itself, like delete own textures etc.
190 * Default implementation does nothing.
192 virtual void finishTransition();
194 /** This function is called in display method to display the slides.
196 * Default implementation applies overall operations and then
197 * displays both slides.
199 virtual void displaySlides_( double nTime
, sal_Int32 glLeavingSlideTex
, sal_Int32 glEnteringSlideTex
, double SlideWidthScale
, double SlideHeightScale
, OpenGLContext
*pContext
);
201 /** This function is called in prepare method to create the GL program.
203 * It is a pure virtual to make sure no class will use a default one.
205 virtual GLuint
makeShader() const = 0;
208 const TransitionScene maScene
;
209 const TransitionSettings maSettings
;
211 /** Calculates the projection and model/view matrices, and upload them.
213 void uploadModelViewProjectionMatrices();
215 /** Uniform locations for transform matrices
217 GLint m_nPrimitiveTransformLocation
= -1;
218 GLint m_nSceneTransformLocation
= -1;
219 GLint m_nOperationsTransformLocation
= -1;
221 /** Per-vertex attribute locations
223 GLint m_nPositionLocation
= -1;
224 GLint m_nNormalLocation
= -1;
225 GLint m_nTexCoordLocation
= -1;
227 GLuint m_nVertexArrayObject
= 0u;
229 std::vector
<int> m_nFirstIndices
;
232 /** GLSL program object
234 GLuint m_nProgramObject
= 0u;
236 /** VBO in which to put primitive data
238 GLuint m_nVertexBufferObject
= 0u;
240 /** Location of the "time" uniform
242 GLint m_nTimeLocation
= -1;
246 // "Constructors" of available transitions
247 std::shared_ptr
<OGLTransitionImpl
> makeOutsideCubeFaceToLeft();
248 std::shared_ptr
<OGLTransitionImpl
> makeInsideCubeFaceToLeft();
249 std::shared_ptr
<OGLTransitionImpl
> makeNByMTileFlip( sal_uInt16 n
, sal_uInt16 m
);
250 std::shared_ptr
<OGLTransitionImpl
> makeRevolvingCircles( sal_uInt16 nCircles
, sal_uInt16 nPointsOnCircles
);
251 std::shared_ptr
<OGLTransitionImpl
> makeHelix( sal_uInt16 nRows
);
252 std::shared_ptr
<OGLTransitionImpl
> makeFallLeaving();
253 std::shared_ptr
<OGLTransitionImpl
> makeTurnAround();
254 std::shared_ptr
<OGLTransitionImpl
> makeTurnDown();
255 std::shared_ptr
<OGLTransitionImpl
> makeIris();
256 std::shared_ptr
<OGLTransitionImpl
> makeRochade();
257 std::shared_ptr
<OGLTransitionImpl
> makeVenetianBlinds( bool vertical
, int parts
);
258 std::shared_ptr
<OGLTransitionImpl
> makeStatic();
259 std::shared_ptr
<OGLTransitionImpl
> makeDissolve();
260 std::shared_ptr
<OGLTransitionImpl
> makeVortex();
261 std::shared_ptr
<OGLTransitionImpl
> makeRipple();
262 std::shared_ptr
<OGLTransitionImpl
> makeGlitter();
263 std::shared_ptr
<OGLTransitionImpl
> makeHoneycomb();
264 std::shared_ptr
<OGLTransitionImpl
> makeNewsflash();
266 /** 2D replacements */
268 std::shared_ptr
<OGLTransitionImpl
> makeDiamond();
269 std::shared_ptr
<OGLTransitionImpl
> makeFadeSmoothly();
270 // fade through black or white
271 std::shared_ptr
<OGLTransitionImpl
> makeFadeThroughColor( bool white
= false );
277 virtual ~SceneObject();
278 SceneObject(const SceneObject
&) = delete;
279 SceneObject
& operator=(const SceneObject
&) = delete;
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() {}
285 void pushPrimitive (const Primitive
&p
);
288 /** All the surrounding scene primitives
290 Primitives_t maPrimitives
;
291 std::vector
<int> maFirstIndices
;
300 static_assert(sizeof(Vertex
) == (3 + 3 + 2) * 4, "Vertex struct has wrong size/alignment");
302 /** This class is a list of Triangles that will share Operations, and could possibly share
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
);
312 void swap(Primitive
& rOther
);
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;
318 /** 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.
320 @param SlideLocation0
321 Location of first Vertex on slide
323 @param SlideLocation1
324 Location of second Vertex on slide
326 @param SlideLocation2
327 Location of third Vertex on slide
330 void pushTriangle(const glm::vec2
& SlideLocation0
,const glm::vec2
& SlideLocation1
,const glm::vec2
& SlideLocation2
);
332 /** guards against directly changing the vertices
337 const glm::vec3
& getVertex(int n
) const {return Vertices
[n
].position
;}
339 int getVerticesCount() const
341 assert(Vertices
.size() < o3tl::make_unsigned(std::numeric_limits
<int>::max()));
342 return int(unsigned(Vertices
.size()));
345 /** accessor for the size of the vertices data
348 the size in bytes of the Vertices data
350 int getVerticesByteSize() const {return Vertices
.size() * sizeof(Vertex
);}
352 /** copies all vertices to the C array passed
355 the number of written vertices
357 int writeVertices(Vertex
*location
) const {
358 std::copy(Vertices
.begin(), Vertices
.end(), location
);
359 return Vertices
.size();
362 /** 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.
365 the list of Operations
368 Operations_t Operations
;
373 std::vector
<Vertex
> Vertices
;
376 TransitionScene::TransitionScene(
377 Primitives_t
&& rLeavingSlidePrimitives
,
378 Primitives_t
&& rEnteringSlidePrimitives
,
379 Operations_t
&& rOverallOperations
,
380 SceneObjects_t
&& rSceneObjects
382 : maLeavingSlidePrimitives(std::move(rLeavingSlidePrimitives
))
383 , maEnteringSlidePrimitives(std::move(rEnteringSlidePrimitives
))
384 , maOverallOperations(std::move(rOverallOperations
))
385 , maSceneObjects(std::move(rSceneObjects
))
389 TransitionScene::~TransitionScene() = default;
391 #endif // INCLUDED_SLIDESHOW_TRANSITION_HXX_
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */