slideshow/Library_OGLTrans.mk | 3 slideshow/opengl/basicFragmentShader.glsl | 8 slideshow/opengl/basicVertexShader.glsl | 2 slideshow/opengl/reflectionFragmentShader.glsl | 6 slideshow/opengl/reflectionVertexShader.glsl | 4 slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.cxx | 221 +++++ slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.hxx | 272 ++++++ slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx | 420 ++-------- slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx | 261 ------ 9 files changed, 625 insertions(+), 572 deletions(-)
New commits: commit 68ab250d73cc981fe3760f4e8671d3df3971ca05 Author: Emmanuel Gil Peyrot <[email protected]> Date: Mon Nov 23 21:53:23 2015 +0000 slideshow: Fix rotations when the slide and the screen have a different ratio Change-Id: Ia6dcc352531a6bf067f3e87086cb275b00f81c97 diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.cxx index 7199a7e..3709f3a 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.cxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.cxx @@ -49,20 +49,22 @@ SScale::SScale(const glm::vec3& Scale, const glm::vec3& Origin, } RotateAndScaleDepthByWidth::RotateAndScaleDepthByWidth(const glm::vec3& Axis, - const glm::vec3& Origin, double Angle, bool bInter, double T0, double T1): + const glm::vec3& Origin, double Angle, bool bScale, bool bInter, double T0, double T1): Operation(bInter, T0, T1), axis(Axis), origin(Origin), - angle(Angle) + angle(Angle), + scale(bScale) { } RotateAndScaleDepthByHeight::RotateAndScaleDepthByHeight(const glm::vec3& Axis, - const glm::vec3& Origin, double Angle, bool bInter, double T0, double T1): + const glm::vec3& Origin, double Angle, bool bScale, bool bInter, double T0, double T1): Operation(bInter, T0, T1), axis(Axis), origin(Origin), - angle(Angle) + angle(Angle), + scale(bScale) { } @@ -98,15 +100,15 @@ makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, doub } std::shared_ptr<RotateAndScaleDepthByWidth> -makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1) +makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle, bool bScale, bool bInter, double T0, double T1) { - return std::make_shared<RotateAndScaleDepthByWidth>(Axis, Origin, Angle, bInter, T0, T1); + return std::make_shared<RotateAndScaleDepthByWidth>(Axis, Origin, Angle, bScale, bInter, T0, T1); } std::shared_ptr<RotateAndScaleDepthByHeight> -makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1) +makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bScale, bool bInter, double T0, double T1) { - return std::make_shared<RotateAndScaleDepthByHeight>(Axis, Origin, Angle, bInter, T0, T1); + return std::make_shared<RotateAndScaleDepthByHeight>(Axis, Origin, Angle, bScale, bInter, T0, T1); } inline double intervalInter(double t, double T0, double T1) @@ -132,7 +134,7 @@ void SRotate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, d t = mnT1; t = intervalInter(t,mnT0,mnT1); glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, origin.z); - glm::vec3 scale_vector(SlideWidthScale, SlideHeightScale, 1); + glm::vec3 scale_vector(SlideWidthScale * SlideWidthScale, SlideHeightScale * SlideHeightScale, 1); matrix = glm::translate(matrix, translation_vector); matrix = glm::scale(matrix, scale_vector); matrix = glm::rotate(matrix, static_cast<float>(t*angle), axis); @@ -161,8 +163,13 @@ void RotateAndScaleDepthByWidth::interpolate(glm::mat4& matrix, double t, double t = mnT1; t = intervalInter(t,mnT0,mnT1); glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, SlideWidthScale*origin.z); + glm::vec3 scale_vector(SlideWidthScale * SlideWidthScale, SlideHeightScale * SlideHeightScale, 1); matrix = glm::translate(matrix, translation_vector); + if (scale) + matrix = glm::scale(matrix, scale_vector); matrix = glm::rotate(matrix, static_cast<float>(t*angle), axis); + if (scale) + matrix = glm::scale(matrix, 1.f / scale_vector); matrix = glm::translate(matrix, -translation_vector); } @@ -174,8 +181,13 @@ void RotateAndScaleDepthByHeight::interpolate(glm::mat4& matrix, double t, doubl t = mnT1; t = intervalInter(t,mnT0,mnT1); glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, SlideHeightScale*origin.z); + glm::vec3 scale_vector(SlideWidthScale * SlideWidthScale, SlideHeightScale * SlideHeightScale, 1); matrix = glm::translate(matrix, translation_vector); + if (scale) + matrix = glm::scale(matrix, scale_vector); matrix = glm::rotate(matrix, static_cast<float>(t*angle), axis); + if (scale) + matrix = glm::scale(matrix, 1.f / scale_vector); matrix = glm::translate(matrix, -translation_vector); } diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.hxx index bf657d0..df058c2 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.hxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.hxx @@ -236,16 +236,17 @@ class RotateAndScaleDepthByWidth: public Operation public: 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); + RotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle, bool bScale, bool bInter, double T0, double T1); virtual ~RotateAndScaleDepthByWidth(){} private: glm::vec3 axis; glm::vec3 origin; double angle; + bool scale; }; std::shared_ptr<RotateAndScaleDepthByWidth> -makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1); +makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle, bool bScale, bool bInter, double T0, double T1); /** Same as SRotate, except the depth is scaled by the width of the slide divided by the height of the window. */ @@ -254,16 +255,17 @@ class RotateAndScaleDepthByHeight: public Operation public: 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); + RotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle, bool bScale, bool bInter, double T0, double T1); virtual ~RotateAndScaleDepthByHeight(){} private: glm::vec3 axis; glm::vec3 origin; double angle; + bool scale; }; std::shared_ptr<RotateAndScaleDepthByHeight> -makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1); +makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle, bool bScale, bool bInter, double T0, double T1); #endif // INCLUDED_SLIDESHOW_OPERATIONS_HXX_ diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx index a9991f1..ab44f3d 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx @@ -535,13 +535,13 @@ std::shared_ptr<OGLTransitionImpl> makeOutsideCubeFaceToLeft() Primitives_t aLeavingPrimitives; aLeavingPrimitives.push_back(Slide); - Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,-1),90,false,0.0,1.0)); + Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,-1),90,false,false,0.0,1.0)); Primitives_t aEnteringPrimitives; aEnteringPrimitives.push_back(Slide); Operations_t aOperations; - aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,-1),-90,true,0.0,1.0)); + aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,-1),-90,false,true,0.0,1.0)); return makeSimpleTransition(aLeavingPrimitives, aEnteringPrimitives, aOperations); } @@ -556,13 +556,13 @@ std::shared_ptr<OGLTransitionImpl> makeInsideCubeFaceToLeft() Primitives_t aLeavingPrimitives; aLeavingPrimitives.push_back(Slide); - Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,1),-90,false,0.0,1.0)); + Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,1),-90,false,false,0.0,1.0)); Primitives_t aEnteringPrimitives; aEnteringPrimitives.push_back(Slide); Operations_t aOperations; - aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,1),90,true,0.0,1.0)); + aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,1),90,false,true,0.0,1.0)); return makeSimpleTransition(aLeavingPrimitives, aEnteringPrimitives, aOperations); } @@ -577,7 +577,7 @@ std::shared_ptr<OGLTransitionImpl> makeFallLeaving() Primitives_t aEnteringPrimitives; aEnteringPrimitives.push_back(Slide); - Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(1,0,0),glm::vec3(0,-1,0), 90,true,0.0,1.0)); + Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(1,0,0),glm::vec3(0,-1,0), 90,true,true,0.0,1.0)); Primitives_t aLeavingPrimitives; aLeavingPrimitives.push_back(Slide); @@ -602,7 +602,7 @@ std::shared_ptr<OGLTransitionImpl> makeTurnAround() aLeavingPrimitives.push_back(Slide); Slide.Operations.clear(); - Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0),-180,false,0.0,1.0)); + Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0),-180,true,false,0.0,1.0)); Primitives_t aEnteringPrimitives; aEnteringPrimitives.push_back(Slide); @@ -612,7 +612,7 @@ std::shared_ptr<OGLTransitionImpl> makeTurnAround() Operations_t aOperations; aOperations.push_back(makeSTranslate(glm::vec3(0, 0, -1.5),true, 0, 0.5)); aOperations.push_back(makeSTranslate(glm::vec3(0, 0, 1.5), true, 0.5, 1)); - aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0, 1, 0),glm::vec3(0, 0, 0), -180, true, 0.0, 1.0)); + aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0, 1, 0),glm::vec3(0, 0, 0), -180, true, true, 0.0, 1.0)); return makeReflectionTransition(aLeavingPrimitives, aEnteringPrimitives, aOperations, aSettings); } @@ -767,7 +767,7 @@ std::shared_ptr<OGLTransitionImpl> makeRochade() Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1)); Slide.Operations.push_back(makeSEllipseTranslate(w, h, 0.25, -0.25, true, 0, 1)); - Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0), -45, true, 0, 1)); + Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0), -45, true, true, 0, 1)); Primitives_t aLeavingSlide; aLeavingSlide.push_back(Slide); @@ -777,8 +777,8 @@ std::shared_ptr<OGLTransitionImpl> makeRochade() Slide.Operations.clear(); Slide.Operations.push_back(makeSEllipseTranslate(w, h, 0.75, 0.25, true, 0, 1)); Slide.Operations.push_back(makeSTranslate(glm::vec3(0, 0, -h), false, -1, 0)); - Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0), -45, true, 0, 1)); - Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0), 45, false, -1, 0)); + Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0), -45, true, true, 0, 1)); + Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0), 45, true, false, -1, 0)); Primitives_t aEnteringSlide; aEnteringSlide.push_back(Slide); @@ -1129,11 +1129,11 @@ std::shared_ptr<OGLTransitionImpl> makeVenetianBlinds( bool vertical, int parts if( vertical ) { Slide.pushTriangle (glm::vec2 (ln,0), glm::vec2 (n,0), glm::vec2 (ln,1)); Slide.pushTriangle (glm::vec2 (n,0), glm::vec2 (ln,1), glm::vec2 (n,1)); - Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0, 1, 0), glm::vec3(n + ln - 1, 0, -t30*p), -120, true, 0.0, 1.0)); + Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0, 1, 0), glm::vec3(n + ln - 1, 0, -t30*p), -120, true, true, 0.0, 1.0)); } else { Slide.pushTriangle (glm::vec2 (0,ln), glm::vec2 (1,ln), glm::vec2 (0,n)); Slide.pushTriangle (glm::vec2 (1,ln), glm::vec2 (0,n), glm::vec2 (1,n)); - Slide.Operations.push_back(makeRotateAndScaleDepthByHeight(glm::vec3(1, 0, 0), glm::vec3(0, 1 - n - ln, -t30*p), -120, true, 0.0, 1.0)); + Slide.Operations.push_back(makeRotateAndScaleDepthByHeight(glm::vec3(1, 0, 0), glm::vec3(0, 1 - n - ln, -t30*p), -120, true, true, 0.0, 1.0)); } aLeavingSlide.push_back (Slide); commit 6bc132f8bf85516b4a89386c371fdd3e9937b4bf Author: Emmanuel Gil Peyrot <[email protected]> Date: Mon Nov 23 21:53:22 2015 +0000 slideshow: Add back lighting in the SimpleTransition shaders Change-Id: Iec854a8369a7a9f845f261233e46aea8097db109 diff --git a/slideshow/opengl/basicFragmentShader.glsl b/slideshow/opengl/basicFragmentShader.glsl index 7744432..01d72a2 100644 --- a/slideshow/opengl/basicFragmentShader.glsl +++ b/slideshow/opengl/basicFragmentShader.glsl @@ -30,10 +30,14 @@ uniform sampler2D slideTexture; varying vec2 v_texturePosition; +varying vec3 v_normal; void main() { - // TODO: handle lighting. - gl_FragColor = texture2D(slideTexture, v_texturePosition); + vec3 lightVector = vec3(0.0, 0.0, 1.0); + float light = max(dot(lightVector, v_normal), 0.0); + vec4 fragment = texture2D(slideTexture, v_texturePosition); + vec4 black = vec4(0.0, 0.0, 0.0, fragment.a); + gl_FragColor = mix(black, fragment, light); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/slideshow/opengl/basicVertexShader.glsl b/slideshow/opengl/basicVertexShader.glsl index bd26c1b..020616f 100644 --- a/slideshow/opengl/basicVertexShader.glsl +++ b/slideshow/opengl/basicVertexShader.glsl @@ -29,11 +29,13 @@ #version 120 varying vec2 v_texturePosition; +varying vec3 v_normal; void main( void ) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; v_texturePosition = gl_MultiTexCoord0.xy; + v_normal = normalize(gl_NormalMatrix * gl_Normal); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/slideshow/opengl/reflectionFragmentShader.glsl b/slideshow/opengl/reflectionFragmentShader.glsl index 9bf8ecb..b415279 100644 --- a/slideshow/opengl/reflectionFragmentShader.glsl +++ b/slideshow/opengl/reflectionFragmentShader.glsl @@ -31,9 +31,15 @@ uniform sampler2D slideTexture; varying float v_isShadow; varying vec2 v_texturePosition; +varying vec3 v_normal; void main() { + vec3 lightVector = vec3(0.0, 0.0, 1.0); + float light = max(dot(lightVector, v_normal), 0.0); vec4 fragment = texture2D(slideTexture, v_texturePosition); + vec4 black = vec4(0.0, 0.0, 0.0, fragment.a); + fragment = mix(black, fragment, light); + if (v_isShadow > 0.5) { if (v_texturePosition.y > 1.0 - 0.3) gl_FragColor = mix(fragment, vec4(0.0, 0.0, 0.0, 0.0), (1.0 - v_texturePosition.y) / 0.3); diff --git a/slideshow/opengl/reflectionVertexShader.glsl b/slideshow/opengl/reflectionVertexShader.glsl index b08d0cc..5087b98 100644 --- a/slideshow/opengl/reflectionVertexShader.glsl +++ b/slideshow/opengl/reflectionVertexShader.glsl @@ -28,13 +28,15 @@ #version 130 -varying float v_isShadow; varying vec2 v_texturePosition; +varying vec3 v_normal; +varying float v_isShadow; void main( void ) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; v_texturePosition = gl_MultiTexCoord0.xy; + v_normal = normalize(gl_NormalMatrix * gl_Normal); v_isShadow = float(gl_VertexID >= 6); } commit b8eff3afb4a4b313c9be668951ae2cb458cd6a4a Author: Emmanuel Gil Peyrot <[email protected]> Date: Mon Nov 23 21:53:21 2015 +0000 slideshow: Fix the baseline version, we now require OpenGL 2.1 With ReflectionTransition requiring 3.0 instead. Change-Id: I9497dab91017d1d81a6a5a369524849ce5774694 diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx index 3f4f1f6..a9991f1 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx @@ -591,6 +591,7 @@ std::shared_ptr<OGLTransitionImpl> makeTurnAround() { Primitive Slide; TransitionSettings aSettings; + aSettings.mnRequiredGLVersion = 3.0; Slide.pushTriangle(glm::vec2(0,0),glm::vec2(1,0),glm::vec2(0,1)); Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1)); @@ -755,6 +756,7 @@ std::shared_ptr<OGLTransitionImpl> makeRochade() { Primitive Slide; TransitionSettings aSettings; + aSettings.mnRequiredGLVersion = 3.0; double w, h; @@ -1407,7 +1409,6 @@ std::shared_ptr<OGLTransitionImpl> makeStatic() TransitionSettings aSettings; aSettings.mbUseMipMapLeaving = aSettings.mbUseMipMapEntering = false; - aSettings.mnRequiredGLVersion = 2.0; return makeStaticNoiseTransition(aLeavingSlide, aEnteringSlide, aSettings); } @@ -1458,7 +1459,6 @@ std::shared_ptr<OGLTransitionImpl> makeDissolve() TransitionSettings aSettings; aSettings.mbUseMipMapLeaving = aSettings.mbUseMipMapEntering = false; - aSettings.mnRequiredGLVersion = 2.0; return makeDissolveTransition(aLeavingSlide, aEnteringSlide, aSettings); } @@ -1607,7 +1607,6 @@ std::shared_ptr<OGLTransitionImpl> makeVortex() TransitionSettings aSettings; aSettings.mbUseMipMapLeaving = aSettings.mbUseMipMapEntering = false; - aSettings.mnRequiredGLVersion = 2.0; return makeVortexTransition(aLeavingSlide, aEnteringSlide, aSettings, NX, NY); } @@ -1679,7 +1678,6 @@ std::shared_ptr<OGLTransitionImpl> makeRipple() TransitionSettings aSettings; aSettings.mbUseMipMapLeaving = aSettings.mbUseMipMapEntering = false; - aSettings.mnRequiredGLVersion = 2.0; return makeRippleTransition(aLeavingSlide, aEnteringSlide, aSettings); } diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx index 1d58348..f1a595ef 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx @@ -48,7 +48,7 @@ struct TransitionSettings TransitionSettings() : mbUseMipMapLeaving( true ), mbUseMipMapEntering( true ), - mnRequiredGLVersion( 1.0 ) + mnRequiredGLVersion( 2.1 ) { } commit 2a81e30c596a0cd253093d338368b3aad11eb166 Author: Emmanuel Gil Peyrot <[email protected]> Date: Mon Nov 23 21:53:20 2015 +0000 slideshow: Make the Iris class private to the TransitionImpl translation unit Change-Id: I9bf701a7f19d0f778b8fec7a39b762cc89b061b7 diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx index 0b342cd..3f4f1f6 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx @@ -327,11 +327,21 @@ SceneObject::~SceneObject() { } -Iris::Iris() - : SceneObject() - , maTexture(0) +namespace { -} + +class Iris : public SceneObject +{ +public: + Iris() = default; + + virtual void prepare() override; + virtual void display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight) const override; + virtual void finish() override; + +private: + GLuint maTexture = 0; +}; void Iris::display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight ) const { @@ -362,6 +372,8 @@ void Iris::finish() CHECK_GL_ERROR(); } +} + namespace { diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx index c941ba2..1d58348 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx @@ -263,19 +263,6 @@ protected: Primitives_t maPrimitives; }; -class Iris : public SceneObject -{ -public: - Iris (); - - virtual void prepare() override; - virtual void display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight) const override; - virtual void finish() override; - -private: - GLuint maTexture; -}; - struct Vertex { glm::vec3 position; commit 4c749b121c8b415ef2b7b0445ede1dc4ccc0e6d0 Author: Emmanuel Gil Peyrot <[email protected]> Date: Mon Nov 23 21:53:19 2015 +0000 slideshow: Merge ShaderTransition into OGLTransitionImpl Change-Id: Ia585a5064362c261c137d8c4abefcfda7cb7bdd7 diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx index 8d3735b..0b342cd 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx @@ -81,6 +81,27 @@ void OGLTransitionImpl::prepare( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteri rSceneObjects[i]->prepare(); } + m_nProgramObject = makeShader(); + + CHECK_GL_ERROR(); + if( m_nProgramObject ) { + glUseProgram( m_nProgramObject ); + CHECK_GL_ERROR(); + + GLint location = glGetUniformLocation( m_nProgramObject, "leavingSlideTexture" ); + if( location != -1 ) { + glUniform1i( location, 0 ); // texture unit 0 + CHECK_GL_ERROR(); + } + + location = glGetUniformLocation( m_nProgramObject, "enteringSlideTexture" ); + if( location != -1 ) { + glUniform1i( location, 2 ); // texture unit 2 + CHECK_GL_ERROR(); + } + } + CHECK_GL_ERROR(); + prepareTransition( glLeavingSlideTex, glEnteringSlideTex ); } @@ -92,6 +113,13 @@ void OGLTransitionImpl::finish() } finishTransition(); + + CHECK_GL_ERROR(); + if( m_nProgramObject ) { + glDeleteProgram( m_nProgramObject ); + m_nProgramObject = 0; + } + CHECK_GL_ERROR(); } void OGLTransitionImpl::prepare( double, double, double, double, double ) @@ -115,9 +143,20 @@ void OGLTransitionImpl::displaySlides_( double nTime, sal_Int32 glLeavingSlideTe CHECK_GL_ERROR(); applyOverallOperations( nTime, SlideWidthScale, SlideHeightScale ); + if( m_nProgramObject ) { + GLint location = glGetUniformLocation( m_nProgramObject, "time" ); + if( location != -1 ) { + glUniform1f( location, nTime ); + } + } + glEnable(GL_TEXTURE_2D); - displaySlide( nTime, glLeavingSlideTex, maScene.getLeavingSlide(), SlideWidthScale, SlideHeightScale ); - displaySlide( nTime, glEnteringSlideTex, maScene.getEnteringSlide(), SlideWidthScale, SlideHeightScale ); + glActiveTexture( GL_TEXTURE2 ); + glBindTexture( GL_TEXTURE_2D, glEnteringSlideTex ); + glActiveTexture( GL_TEXTURE0 ); + + displaySlide( nTime, glLeavingSlideTex, getScene().getLeavingSlide(), SlideWidthScale, SlideHeightScale ); + CHECK_GL_ERROR(); } void OGLTransitionImpl::display( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, @@ -326,118 +365,22 @@ void Iris::finish() namespace { -class ShaderTransition : public OGLTransitionImpl -{ -protected: - ShaderTransition(const TransitionScene& rScene, const TransitionSettings& rSettings) - : OGLTransitionImpl(rScene, rSettings) - {} - -private: - virtual void displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) override; - virtual void prepareTransition( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex ) override; - virtual void finishTransition() override; - virtual GLuint makeShader() const; - - void impl_setTextureUniforms(); - virtual void impl_prepareTransition() = 0; - virtual void impl_finishTransition() = 0; - -protected: - /** GLSL program object - */ - GLuint m_nProgramObject = 0; -}; - -void ShaderTransition::displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, - double SlideWidthScale, double SlideHeightScale ) -{ - CHECK_GL_ERROR(); - applyOverallOperations( nTime, SlideWidthScale, SlideHeightScale ); - - if( m_nProgramObject ) { - GLint location = glGetUniformLocation( m_nProgramObject, "time" ); - if( location != -1 ) { - glUniform1f( location, nTime ); - } - } - - glActiveTexture( GL_TEXTURE2 ); - glBindTexture( GL_TEXTURE_2D, glEnteringSlideTex ); - glActiveTexture( GL_TEXTURE0 ); - - displaySlide( nTime, glLeavingSlideTex, getScene().getLeavingSlide(), SlideWidthScale, SlideHeightScale ); - CHECK_GL_ERROR(); -} - -GLuint ShaderTransition::makeShader() const -{ - return OpenGLHelper::LoadShaders( "basicVertexShader", "basicFragmentShader" ); -} - -void ShaderTransition::prepareTransition( sal_Int32 /* glLeavingSlideTex */, sal_Int32 /* glEnteringSlideTex */ ) -{ - m_nProgramObject = makeShader(); - - impl_setTextureUniforms(); - impl_prepareTransition(); -} - -void ShaderTransition::finishTransition() -{ - CHECK_GL_ERROR(); - impl_finishTransition(); - CHECK_GL_ERROR(); - if( m_nProgramObject ) { - glDeleteProgram( m_nProgramObject ); - m_nProgramObject = 0; - } - CHECK_GL_ERROR(); -} - -void ShaderTransition::impl_setTextureUniforms() -{ - CHECK_GL_ERROR(); - if( m_nProgramObject ) { - glUseProgram( m_nProgramObject ); - CHECK_GL_ERROR(); - - GLint location = glGetUniformLocation( m_nProgramObject, "leavingSlideTexture" ); - if( location != -1 ) { - glUniform1i( location, 0 ); // texture unit 0 - CHECK_GL_ERROR(); - } - - location = glGetUniformLocation( m_nProgramObject, "enteringSlideTexture" ); - if( location != -1 ) { - glUniform1i( location, 2 ); // texture unit 2 - CHECK_GL_ERROR(); - } - } - CHECK_GL_ERROR(); -} - -} - -namespace -{ - -class ReflectionTransition : public ShaderTransition +class ReflectionTransition : public OGLTransitionImpl { public: ReflectionTransition(const TransitionScene& rScene, const TransitionSettings& rSettings) - : ShaderTransition(rScene, rSettings) + : OGLTransitionImpl(rScene, rSettings) {} private: virtual GLuint makeShader() const override; virtual void displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) override; - virtual void impl_prepareTransition() override { + virtual void prepareTransition( sal_Int32, sal_Int32 ) override { glDisable(GL_CULL_FACE); } - virtual void impl_finishTransition() override { + virtual void finishTransition() override { glEnable(GL_CULL_FACE); } }; @@ -485,21 +428,25 @@ makeReflectionTransition( namespace { -class SimpleTransition : public ShaderTransition +class SimpleTransition : public OGLTransitionImpl { public: SimpleTransition(const TransitionScene& rScene, const TransitionSettings& rSettings) - : ShaderTransition(rScene, rSettings) + : OGLTransitionImpl(rScene, rSettings) { } private: - virtual void impl_finishTransition() override {} - virtual void impl_prepareTransition() override {} + virtual GLuint makeShader() const override; virtual void displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) override; }; +GLuint SimpleTransition::makeShader() const +{ + return OpenGLHelper::LoadShaders( "basicVertexShader", "basicFragmentShader" ); +} + void SimpleTransition::displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) { @@ -1193,17 +1140,15 @@ std::shared_ptr<OGLTransitionImpl> makeVenetianBlinds( bool vertical, int parts namespace { -class FadeSmoothlyTransition : public ShaderTransition +class FadeSmoothlyTransition : public OGLTransitionImpl { public: FadeSmoothlyTransition(const TransitionScene& rScene, const TransitionSettings& rSettings) - : ShaderTransition(rScene, rSettings) + : OGLTransitionImpl(rScene, rSettings) {} private: virtual GLuint makeShader() const override; - virtual void impl_prepareTransition() override {} - virtual void impl_finishTransition() override {} }; GLuint FadeSmoothlyTransition::makeShader() const @@ -1245,17 +1190,15 @@ std::shared_ptr<OGLTransitionImpl> makeFadeSmoothly() namespace { -class FadeThroughBlackTransition : public ShaderTransition +class FadeThroughBlackTransition : public OGLTransitionImpl { public: FadeThroughBlackTransition(const TransitionScene& rScene, const TransitionSettings& rSettings) - : ShaderTransition(rScene, rSettings) + : OGLTransitionImpl(rScene, rSettings) {} private: virtual GLuint makeShader() const override; - virtual void impl_prepareTransition() override {} - virtual void impl_finishTransition() override {} }; GLuint FadeThroughBlackTransition::makeShader() const @@ -1297,23 +1240,23 @@ std::shared_ptr<OGLTransitionImpl> makeFadeThroughBlack() namespace { -class PermTextureTransition : public ShaderTransition +class PermTextureTransition : public OGLTransitionImpl { protected: PermTextureTransition(const TransitionScene& rScene, const TransitionSettings& rSettings) - : ShaderTransition(rScene, rSettings) + : OGLTransitionImpl(rScene, rSettings) , m_nHelperTexture(0) {} - virtual void impl_finishTransition() override; - virtual void impl_prepareTransition() override; + virtual void finishTransition() override; + virtual void prepareTransition( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex ) override; private: /** various data */ GLuint m_nHelperTexture; }; -void PermTextureTransition::impl_finishTransition() +void PermTextureTransition::finishTransition() { CHECK_GL_ERROR(); if ( m_nHelperTexture ) @@ -1383,7 +1326,7 @@ static void initPermTexture(GLuint *texID) CHECK_GL_ERROR(); } -void PermTextureTransition::impl_prepareTransition() +void PermTextureTransition::prepareTransition( sal_Int32, sal_Int32 ) { CHECK_GL_ERROR(); if( m_nProgramObject ) { @@ -1530,7 +1473,7 @@ private: virtual GLuint makeShader() const override; - virtual void impl_prepareTransition() override; + virtual void prepareTransition( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex ) override; GLint mnTileInfoLocation; GLuint mnTileInfoBuffer; @@ -1565,10 +1508,10 @@ GLuint VortexTransition::makeShader() const return OpenGLHelper::LoadShaders( "vortexVertexShader", "vortexFragmentShader" ); } -void VortexTransition::impl_prepareTransition() +void VortexTransition::prepareTransition( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex ) { CHECK_GL_ERROR(); - PermTextureTransition::impl_prepareTransition(); + PermTextureTransition::prepareTransition( glLeavingSlideTex, glEnteringSlideTex ); CHECK_GL_ERROR(); if (m_nProgramObject) @@ -1660,19 +1603,18 @@ std::shared_ptr<OGLTransitionImpl> makeVortex() namespace { -class RippleTransition : public ShaderTransition +class RippleTransition : public OGLTransitionImpl { public: RippleTransition(const TransitionScene& rScene, const TransitionSettings& rSettings, const glm::vec2& rCenter) - : ShaderTransition(rScene, rSettings), + : OGLTransitionImpl(rScene, rSettings), maCenter(rCenter) { } private: virtual GLuint makeShader() const override; - virtual void impl_prepareTransition() override; - virtual void impl_finishTransition() override {} + virtual void prepareTransition( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex ) override; glm::vec2 maCenter; }; @@ -1682,7 +1624,7 @@ GLuint RippleTransition::makeShader() const return OpenGLHelper::LoadShaders( "basicVertexShader", "rippleFragmentShader" ); } -void RippleTransition::impl_prepareTransition() +void RippleTransition::prepareTransition( sal_Int32, sal_Int32 ) { if (m_nProgramObject) { diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx index aaccd12..c941ba2 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx @@ -202,9 +202,20 @@ private: */ virtual void displaySlides_( double nTime, sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ); + /** This function is called in prepare method to create the GL program. + * + * It is a pure virtual to make sure no class will use a default one. + */ + virtual GLuint makeShader() const = 0; + private: TransitionScene maScene; const TransitionSettings maSettings; + +protected: + /** GLSL program object + */ + GLuint m_nProgramObject = 0; }; commit fb3661a43f7de2ec7eb5ac876ec8192994f80871 Author: Emmanuel Gil Peyrot <[email protected]> Date: Mon Nov 23 21:53:18 2015 +0000 slideshow: Move Operation to its own translation unit Change-Id: Ie0be68055152347e82da66cb48cf76c54b7966c0 diff --git a/slideshow/Library_OGLTrans.mk b/slideshow/Library_OGLTrans.mk index e1754f1..db1c788 100644 --- a/slideshow/Library_OGLTrans.mk +++ b/slideshow/Library_OGLTrans.mk @@ -41,6 +41,7 @@ ifeq ($(strip $(OS)),MACOSX) $(eval $(call gb_Library_add_exception_objects,OGLTrans,\ slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl \ slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl \ + slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation \ )) $(eval $(call gb_Library_use_system_darwin_frameworks,OGLTrans,\ @@ -59,12 +60,14 @@ $(eval $(call gb_Library_use_system_win32_libs,OGLTrans,\ $(eval $(call gb_Library_add_exception_objects,OGLTrans,\ slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl \ slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl \ + slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation \ )) else $(eval $(call gb_Library_add_exception_objects,OGLTrans,\ slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl \ slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl \ + slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation \ )) $(eval $(call gb_Library_add_libs,OGLTrans,\ diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.cxx new file mode 100644 index 0000000..7199a7e --- /dev/null +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.cxx @@ -0,0 +1,209 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2015 by Collabora, Ltd. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <glm/gtc/matrix_transform.hpp> +#include <glm/gtc/type_ptr.hpp> + +#include "OGLTrans_Operation.hxx" + +SRotate::SRotate(const glm::vec3& Axis, const glm::vec3& Origin, + double Angle, bool bInter, double T0, double T1): + Operation(bInter, T0, T1), + axis(Axis), + origin(Origin), + angle(Angle) +{ +} + +SScale::SScale(const glm::vec3& Scale, const glm::vec3& Origin, + bool bInter, double T0, double T1): + Operation(bInter, T0, T1), + scale(Scale), + origin(Origin) +{ +} + +RotateAndScaleDepthByWidth::RotateAndScaleDepthByWidth(const glm::vec3& Axis, + const glm::vec3& Origin, double Angle, bool bInter, double T0, double T1): + Operation(bInter, T0, T1), + axis(Axis), + origin(Origin), + angle(Angle) +{ +} + +RotateAndScaleDepthByHeight::RotateAndScaleDepthByHeight(const glm::vec3& Axis, + const glm::vec3& Origin, double Angle, bool bInter, double T0, double T1): + Operation(bInter, T0, T1), + axis(Axis), + origin(Origin), + angle(Angle) +{ +} + + +STranslate::STranslate(const glm::vec3& Vector, bool bInter, double T0, double T1): + Operation(bInter, T0, T1), + vector(Vector) +{ +} + +std::shared_ptr<SRotate> +makeSRotate(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1) +{ + return std::make_shared<SRotate>(Axis, Origin, Angle, bInter, T0, T1); +} + +std::shared_ptr<SScale> +makeSScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1) +{ + return std::make_shared<SScale>(Scale, Origin, bInter, T0, T1); +} + +std::shared_ptr<STranslate> +makeSTranslate(const glm::vec3& Vector,bool bInter, double T0, double T1) +{ + return std::make_shared<STranslate>(Vector, bInter, T0, T1); +} + +std::shared_ptr<SEllipseTranslate> +makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1) +{ + return std::make_shared<SEllipseTranslate>(dWidth, dHeight, dStartPosition, dEndPosition, bInter, T0, T1); +} + +std::shared_ptr<RotateAndScaleDepthByWidth> +makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1) +{ + return std::make_shared<RotateAndScaleDepthByWidth>(Axis, Origin, Angle, bInter, T0, T1); +} + +std::shared_ptr<RotateAndScaleDepthByHeight> +makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1) +{ + return std::make_shared<RotateAndScaleDepthByHeight>(Axis, Origin, Angle, bInter, T0, T1); +} + +inline double intervalInter(double t, double T0, double T1) +{ + return ( t - T0 ) / ( T1 - T0 ); +} + +void STranslate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const +{ + if(t <= mnT0) + return; + if(!mbInterpolate || t > mnT1) + t = mnT1; + t = intervalInter(t,mnT0,mnT1); + matrix = glm::translate(matrix, glm::vec3(SlideWidthScale*t*vector.x, SlideHeightScale*t*vector.y, t*vector.z)); +} + +void SRotate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const +{ + if(t <= mnT0) + return; + if(!mbInterpolate || t > mnT1) + t = mnT1; + t = intervalInter(t,mnT0,mnT1); + 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(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const +{ + if(t <= mnT0) + return; + if(!mbInterpolate || t > mnT1) + t = mnT1; + t = intervalInter(t,mnT0,mnT1); + 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(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const +{ + if(t <= mnT0) + return; + if(!mbInterpolate || t > mnT1) + t = mnT1; + t = intervalInter(t,mnT0,mnT1); + 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(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const +{ + if(t <= mnT0) + return; + if(!mbInterpolate || t > mnT1) + t = mnT1; + t = intervalInter(t,mnT0,mnT1); + 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, + double dEndPosition, bool bInter, double T0, double T1): + Operation(bInter, T0, T1) +{ + width = dWidth; + height = dHeight; + startPosition = dStartPosition; + endPosition = dEndPosition; +} + +void SEllipseTranslate::interpolate(glm::mat4& matrix, double t, double /* SlideWidthScale */, double /* SlideHeightScale */) const +{ + if(t <= mnT0) + return; + if(!mbInterpolate || t > mnT1) + t = mnT1; + t = intervalInter(t,mnT0,mnT1); + + double a1, a2, x, y; + a1 = startPosition*2*M_PI; + a2 = (startPosition + t*(endPosition - startPosition))*2*M_PI; + x = width*(cos (a2) - cos (a1))/2; + y = height*(sin (a2) - sin (a1))/2; + + matrix = glm::translate(matrix, glm::vec3(x, 0, y)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.hxx new file mode 100644 index 0000000..bf657d0 --- /dev/null +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_Operation.hxx @@ -0,0 +1,270 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2015 by Collabora, Ltd. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef INCLUDED_OGLTRANS_OPERATIONS_HXX_ +#define INCLUDED_OGLTRANS_OPERATIONS_HXX_ + +#include <config_lgpl.h> +#include <glm/gtc/type_ptr.hpp> + +#include <boost/noncopyable.hpp> + +#include <memory> + +/** This class is to be derived to make any operation (transform) you may need in order to construct your transitions +*/ +class Operation : private boost::noncopyable +{ +public: + virtual ~Operation(){} + +protected: + /** Should this operation be interpolated . If TRUE, the transform will smoothly move from making no difference from t = 0.0 to mnT0 to being completely transformed from t = mnT1 to 1. If FALSE, the transform will be inneffectual from t = 0 to mnT0, and completely transformed from t = mnT0 to 1. + */ + bool mbInterpolate; + + /** time to begin the transformation + */ + double mnT0; + + /** time to finish the transformation + */ + double mnT1; +public: + /** this is the function that is called to give the Operation to OpenGL. + + @param t + time from t = 0 to t = 1 + + @param SlideWidthScale + width of slide divided by width of window + + @param SlideHeightScale + height of slide divided by height of window + + */ + virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const = 0; + +protected: + Operation(bool bInterpolate, double nT0, double nT1): + mbInterpolate(bInterpolate), mnT0(nT0), mnT1(nT1){} +}; + +/** this class is a generic CounterClockWise(CCW) rotation with an axis angle +*/ +class SRotate: public Operation +{ +public: + virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override; + + /** Constructor + + @param Axis + axis to rotate about + + @param Origin + position that rotation axis runs through + + @param Angle + angle in radians of CCW rotation + + @param bInter + see Operation + + @param T0 + transformation starting time + + @param T1 + transformation ending time + + */ + SRotate(const glm::vec3& Axis, const glm::vec3& Origin, double Angle, + bool bInter, double T0, double T1); + virtual ~SRotate(){} +private: + /** axis to rotate CCW about + */ + glm::vec3 axis; + + /** position that rotation axis runs through + */ + glm::vec3 origin; + + /** angle in radians of CCW rotation + */ + double angle; +}; + +std::shared_ptr<SRotate> +makeSRotate(const glm::vec3& Axis, const glm::vec3& Origin, double Angle, + bool bInter, double T0, double T1); + +/** scaling transformation +*/ +class SScale: public Operation +{ +public: + virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override; + + /** Constructor + + @param Scale + amount to scale by + + @param Origin + position that rotation axis runs through + + @param bInter + see Operation + + @param T0 + transformation starting time + + @param T1 + transformation ending time + + */ + SScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1); + virtual ~SScale(){} +private: + glm::vec3 scale; + glm::vec3 origin; +}; + +std::shared_ptr<SScale> +makeSScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1); + +/** translation transformation +*/ +class STranslate: public Operation +{ +public: + virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override; + + /** Constructor + + @param Vector + vector to translate + + @param bInter + see Operation + + @param T0 + transformation starting time + + @param T1 + transformation ending time + + */ + STranslate(const glm::vec3& Vector,bool bInter, double T0, double T1); + virtual ~STranslate(){} +private: + /** vector to translate by + */ + glm::vec3 vector; +}; + +std::shared_ptr<STranslate> +makeSTranslate(const glm::vec3& Vector,bool bInter, double T0, double T1); + +/** translation transformation +*/ +class SEllipseTranslate: public Operation +{ +public: + virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override; + + /** Constructor + + @param Vector + vector to translate + + @param bInter + see Operation + + @param T0 + transformation starting time + + @param T1 + transformation ending time + + */ + SEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1); + virtual ~SEllipseTranslate(){} +private: + /** width and length of the ellipse + */ + double width, height; + + /** start and end position on the ellipse <0,1> + */ + double startPosition; + double endPosition; +}; + +std::shared_ptr<SEllipseTranslate> +makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1); + +/** Same as SRotate, except the depth is scaled by the width of the slide divided by the width of the window. +*/ +class RotateAndScaleDepthByWidth: public Operation +{ +public: + 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(){} +private: + glm::vec3 axis; + glm::vec3 origin; + double angle; +}; + +std::shared_ptr<RotateAndScaleDepthByWidth> +makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1); + +/** Same as SRotate, except the depth is scaled by the width of the slide divided by the height of the window. +*/ +class RotateAndScaleDepthByHeight: public Operation +{ +public: + 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(){} +private: + glm::vec3 axis; + glm::vec3 origin; + double angle; +}; + +std::shared_ptr<RotateAndScaleDepthByHeight> +makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1); + +#endif // INCLUDED_SLIDESHOW_OPERATIONS_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx index dd791ae..8d3735b 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx @@ -37,6 +37,7 @@ #include <comphelper/random.hxx> #include "OGLTrans_TransitionImpl.hxx" +#include "OGLTrans_Operation.hxx" #include <math.h> TransitionScene::TransitionScene(TransitionScene const& rOther) @@ -1031,181 +1032,6 @@ std::shared_ptr<OGLTransitionImpl> makeNByMTileFlip( sal_uInt16 n, sal_uInt16 m return makeSimpleTransition(aLeavingSlide, aEnteringSlide); } -SRotate::SRotate(const glm::vec3& Axis, const glm::vec3& Origin, - double Angle, bool bInter, double T0, double T1): - Operation(bInter, T0, T1), - axis(Axis), - origin(Origin), - angle(Angle) -{ -} - -SScale::SScale(const glm::vec3& Scale, const glm::vec3& Origin, - bool bInter, double T0, double T1): - Operation(bInter, T0, T1), - scale(Scale), - origin(Origin) -{ -} - -RotateAndScaleDepthByWidth::RotateAndScaleDepthByWidth(const glm::vec3& Axis, - const glm::vec3& Origin, double Angle, bool bInter, double T0, double T1): - Operation(bInter, T0, T1), - axis(Axis), - origin(Origin), - angle(Angle) -{ -} - -RotateAndScaleDepthByHeight::RotateAndScaleDepthByHeight(const glm::vec3& Axis, - const glm::vec3& Origin, double Angle, bool bInter, double T0, double T1): - Operation(bInter, T0, T1), - axis(Axis), - origin(Origin), - angle(Angle) -{ -} - - -STranslate::STranslate(const glm::vec3& Vector, bool bInter, double T0, double T1): - Operation(bInter, T0, T1), - vector(Vector) -{ -} - -std::shared_ptr<SRotate> -makeSRotate(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1) -{ - return std::make_shared<SRotate>(Axis, Origin, Angle, bInter, T0, T1); -} - -std::shared_ptr<SScale> -makeSScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1) -{ - return std::make_shared<SScale>(Scale, Origin, bInter, T0, T1); -} - -std::shared_ptr<STranslate> -makeSTranslate(const glm::vec3& Vector,bool bInter, double T0, double T1) -{ - return std::make_shared<STranslate>(Vector, bInter, T0, T1); -} - -std::shared_ptr<SEllipseTranslate> -makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1) -{ - return std::make_shared<SEllipseTranslate>(dWidth, dHeight, dStartPosition, dEndPosition, bInter, T0, T1); -} - -std::shared_ptr<RotateAndScaleDepthByWidth> -makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1) -{ - return std::make_shared<RotateAndScaleDepthByWidth>(Axis, Origin, Angle, bInter, T0, T1); -} - -std::shared_ptr<RotateAndScaleDepthByHeight> -makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1) -{ - return std::make_shared<RotateAndScaleDepthByHeight>(Axis, Origin, Angle, bInter, T0, T1); -} - -inline double intervalInter(double t, double T0, double T1) -{ - return ( t - T0 ) / ( T1 - T0 ); -} - -void STranslate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const -{ - if(t <= mnT0) - return; - if(!mbInterpolate || t > mnT1) - t = mnT1; - t = intervalInter(t,mnT0,mnT1); - matrix = glm::translate(matrix, glm::vec3(SlideWidthScale*t*vector.x, SlideHeightScale*t*vector.y, t*vector.z)); -} - -void SRotate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const -{ - if(t <= mnT0) - return; - if(!mbInterpolate || t > mnT1) - t = mnT1; - t = intervalInter(t,mnT0,mnT1); - 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(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const -{ - if(t <= mnT0) - return; - if(!mbInterpolate || t > mnT1) - t = mnT1; - t = intervalInter(t,mnT0,mnT1); - 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(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const -{ - if(t <= mnT0) - return; - if(!mbInterpolate || t > mnT1) - t = mnT1; - t = intervalInter(t,mnT0,mnT1); - 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(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const -{ - if(t <= mnT0) - return; - if(!mbInterpolate || t > mnT1) - t = mnT1; - t = intervalInter(t,mnT0,mnT1); - 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, - double dEndPosition, bool bInter, double T0, double T1): - Operation(bInter, T0, T1) -{ - width = dWidth; - height = dHeight; - startPosition = dStartPosition; - endPosition = dEndPosition; -} - -void SEllipseTranslate::interpolate(glm::mat4& matrix, double t, double /* SlideWidthScale */, double /* SlideHeightScale */) const -{ - if(t <= mnT0) - return; - if(!mbInterpolate || t > mnT1) - t = mnT1; - t = intervalInter(t,mnT0,mnT1); - - double a1, a2, x, y; - a1 = startPosition*2*M_PI; - a2 = (startPosition + t*(endPosition - startPosition))*2*M_PI; - x = width*(cos (a2) - cos (a1))/2; - y = height*(sin (a2) - sin (a1))/2; - - matrix = glm::translate(matrix, glm::vec3(x, 0, y)); -} - Primitive& Primitive::operator=(const Primitive& rvalue) { Primitive aTmp(rvalue); diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx index 0a12c25..aaccd12 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.hxx @@ -29,15 +29,12 @@ #define INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_ #include <config_lgpl.h> -#include <glm/glm.hpp> +#include <glm/gtc/type_ptr.hpp> #include <boost/noncopyable.hpp> #include <GL/glew.h> -#include <basegfx/vector/b2dvector.hxx> -#include <basegfx/vector/b3dvector.hxx> - #include <memory> #include <vector> @@ -343,236 +340,6 @@ private: std::vector<Vertex> Vertices; }; -/** This class is to be derived to make any operation (transform) you may need in order to construct your transitions -*/ -class Operation : private boost::noncopyable -{ -public: - virtual ~Operation(){} - -protected: - /** Should this operation be interpolated . If TRUE, the transform will smoothly move from making no difference from t = 0.0 to mnT0 to being completely transformed from t = mnT1 to 1. If FALSE, the transform will be inneffectual from t = 0 to mnT0, and completely transformed from t = mnT0 to 1. - */ - bool mbInterpolate; - - /** time to begin the transformation - */ - double mnT0; - - /** time to finish the transformation - */ - double mnT1; -public: - /** this is the function that is called to give the Operation to OpenGL. - - @param t - time from t = 0 to t = 1 - - @param SlideWidthScale - width of slide divided by width of window - - @param SlideHeightScale - height of slide divided by height of window - - */ - virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const = 0; - -protected: - Operation(bool bInterpolate, double nT0, double nT1): - mbInterpolate(bInterpolate), mnT0(nT0), mnT1(nT1){} -}; - -/** this class is a generic CounterClockWise(CCW) rotation with an axis angle -*/ -class SRotate: public Operation -{ -public: - virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override; - - /** Constructor - - @param Axis - axis to rotate about - - @param Origin - position that rotation axis runs through - - @param Angle - angle in radians of CCW rotation - - @param bInter - see Operation - - @param T0 - transformation starting time - - @param T1 - transformation ending time - - */ - SRotate(const glm::vec3& Axis, const glm::vec3& Origin, double Angle, - bool bInter, double T0, double T1); - virtual ~SRotate(){} -private: - /** axis to rotate CCW about - */ - glm::vec3 axis; - - /** position that rotation axis runs through - */ - glm::vec3 origin; - - /** angle in radians of CCW rotation - */ - double angle; -}; - -std::shared_ptr<SRotate> -makeSRotate(const glm::vec3& Axis, const glm::vec3& Origin, double Angle, - bool bInter, double T0, double T1); - -/** scaling transformation -*/ -class SScale: public Operation -{ -public: - virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override; - - /** Constructor - - @param Scale - amount to scale by - - @param Origin - position that rotation axis runs through - - @param bInter - see Operation - - @param T0 - transformation starting time - - @param T1 - transformation ending time - - */ - SScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1); - virtual ~SScale(){} -private: - glm::vec3 scale; - glm::vec3 origin; -}; - -std::shared_ptr<SScale> -makeSScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1); - -/** translation transformation -*/ -class STranslate: public Operation -{ -public: - virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override; - - /** Constructor - - @param Vector - vector to translate - - @param bInter - see Operation - - @param T0 - transformation starting time - - @param T1 - transformation ending time - - */ - STranslate(const glm::vec3& Vector,bool bInter, double T0, double T1); - virtual ~STranslate(){} -private: - /** vector to translate by - */ - glm::vec3 vector; -}; - -std::shared_ptr<STranslate> -makeSTranslate(const glm::vec3& Vector,bool bInter, double T0, double T1); - -/** translation transformation -*/ -class SEllipseTranslate: public Operation -{ -public: - virtual void interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const override; - - /** Constructor - - @param Vector - vector to translate - - @param bInter - see Operation - - @param T0 - transformation starting time - - @param T1 - transformation ending time - - */ - SEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1); - virtual ~SEllipseTranslate(){} -private: - /** width and length of the ellipse - */ - double width, height; - - /** start and end position on the ellipse <0,1> - */ - double startPosition; - double endPosition; -}; - -std::shared_ptr<SEllipseTranslate> -makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1); - -/** Same as SRotate, except the depth is scaled by the width of the slide divided by the width of the window. -*/ -class RotateAndScaleDepthByWidth: public Operation -{ -public: - 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(){} -private: - glm::vec3 axis; - glm::vec3 origin; - double angle; -}; - -std::shared_ptr<RotateAndScaleDepthByWidth> -makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1); - -/** Same as SRotate, except the depth is scaled by the width of the slide divided by the height of the window. -*/ -class RotateAndScaleDepthByHeight: public Operation -{ -public: - 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(){} -private: - glm::vec3 axis; - glm::vec3 origin; - double angle; -}; - -std::shared_ptr<RotateAndScaleDepthByHeight> -makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1); - #endif // INCLUDED_SLIDESHOW_TRANSITION_HXX_ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
