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>
32 #include <glm/gtc/type_ptr.hpp>
44 struct TransitionSettings
46 TransitionSettings() :
47 mbUseMipMapLeaving( true ),
48 mbUseMipMapEntering( true ),
49 mnRequiredGLVersion( 2.1f
)
53 /** Whether to use mipmapping for slides textures
55 bool mbUseMipMapLeaving
;
56 bool mbUseMipMapEntering
;
58 /** which GL version does the transition require
60 float mnRequiredGLVersion
;
63 typedef std::vector
<Primitive
> Primitives_t
;
64 typedef std::vector
<std::shared_ptr
<SceneObject
> > SceneObjects_t
;
65 typedef std::vector
<std::shared_ptr
<Operation
> > Operations_t
;
71 const Primitives_t
& rLeavingSlidePrimitives
,
72 const Primitives_t
& rEnteringSlidePrimitives
,
73 const Operations_t
& rOverallOperations
= Operations_t(),
74 const SceneObjects_t
& rSceneObjects
= SceneObjects_t()
76 : maLeavingSlidePrimitives(rLeavingSlidePrimitives
)
77 , maEnteringSlidePrimitives(rEnteringSlidePrimitives
)
78 , maOverallOperations(rOverallOperations
)
79 , maSceneObjects(rSceneObjects
)
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 nTime
, double SlideWidth
, double SlideHeight
, double DispWidth
, double DispHeight
);
176 /** This function is called in display method to prepare the slides, scene, etc.
178 * Default implementation does nothing.
180 virtual void finish( double nTime
, double SlideWidth
, double SlideHeight
, double DispWidth
, double DispHeight
);
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 std::shared_ptr
<OGLTransitionImpl
> makeFadeThroughBlack();
276 virtual ~SceneObject();
277 SceneObject(const SceneObject
&) = delete;
278 SceneObject
& operator=(const SceneObject
&) = delete;
280 virtual void prepare(GLuint
/* program */) {}
281 virtual void display(GLint sceneTransformLocation
, GLint primitiveTransformLocation
, double nTime
, double SlideWidth
, double SlideHeight
, double DispWidth
, double DispHeight
) const;
282 virtual void finish() {}
284 void pushPrimitive (const Primitive
&p
);
287 /** All the surrounding scene primitives
289 Primitives_t maPrimitives
;
290 std::vector
<int> maFirstIndices
;
299 static_assert(sizeof(Vertex
) == (3 + 3 + 2) * 4, "Vertex struct has wrong size/alignment");
301 /** This class is a list of Triangles that will share Operations, and could possibly share
307 // making copy constructor explicit makes the class un-suitable for use with stl containers
308 Primitive(const Primitive
& rvalue
);
309 Primitive
& operator=(const Primitive
& rvalue
);
311 void swap(Primitive
& rOther
);
313 void applyOperations(glm::mat4
& matrix
, double nTime
, double SlideWidthScale
, double SlideHeightScale
) const;
314 void display(GLint primitiveTransformLocation
, double nTime
, double WidthScale
, double HeightScale
) const;
315 void display(GLint primitiveTransformLocation
, double nTime
, double WidthScale
, double HeightScale
, int first
) const;
317 /** 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.
319 @param SlideLocation0
320 Location of first Vertex on slide
322 @param SlideLocation1
323 Location of second Vertex on slide
325 @param SlideLocation2
326 Location of third Vertex on slide
329 void pushTriangle(const glm::vec2
& SlideLocation0
,const glm::vec2
& SlideLocation1
,const glm::vec2
& SlideLocation2
);
331 /** guards against directly changing the vertices
336 const glm::vec3
& getVertex(int n
) const {return Vertices
[n
].position
;}
338 int getVerticesCount() const
340 assert(Vertices
.size() < unsigned(std::numeric_limits
<int>::max()));
341 return int(unsigned(Vertices
.size()));
344 /** accessor for the size of the vertices data
347 the size in bytes of the Vertices data
349 int getVerticesByteSize() const {return Vertices
.size() * sizeof(Vertex
);}
351 /** copies all vertices to the C array passed
354 the number of written vertices
356 int writeVertices(Vertex
*location
) const {
357 std::copy(Vertices
.begin(), Vertices
.end(), location
);
358 return Vertices
.size();
361 /** 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.
364 the list of Operations
367 Operations_t Operations
;
372 std::vector
<Vertex
> Vertices
;
375 #endif // INCLUDED_SLIDESHOW_TRANSITION_HXX_
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */