summaryrefslogtreecommitdiff
path: root/slideshow
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <emmanuel.peyrot@collabora.com>2015-12-09 21:39:35 +0000
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-12-12 09:32:38 +0100
commitcc6d80170f9f008fc564e47a0af86a8c237c703f (patch)
tree095dc2fd1abba607ed741e1ca9edc209768c5194 /slideshow
parentd030595513dc15edbc01ecd26ecf6cc2f90d6b8f (diff)
slideshow: Improve the performances of the Glitter transition
Change-Id: Iaf482b357577ff8a5511607844a69c90ea28d29f (cherry picked from commit d9116f2235e1a79c86446fc67231684edac49d82)
Diffstat (limited to 'slideshow')
-rw-r--r--slideshow/Package_opengl.mk2
-rw-r--r--slideshow/opengl/glitterFragmentShader.glsl36
-rw-r--r--slideshow/opengl/glitterVertexShader.glsl79
-rw-r--r--slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx111
4 files changed, 205 insertions, 23 deletions
diff --git a/slideshow/Package_opengl.mk b/slideshow/Package_opengl.mk
index 5e9c8d384ecb..bed17d9e6b3d 100644
--- a/slideshow/Package_opengl.mk
+++ b/slideshow/Package_opengl.mk
@@ -15,6 +15,8 @@ $(eval $(call gb_Package_add_files,slideshow_opengl_shader,$(LIBO_ETC_FOLDER)/op
dissolveFragmentShader.glsl \
fadeBlackFragmentShader.glsl \
fadeFragmentShader.glsl \
+ glitterVertexShader.glsl \
+ glitterFragmentShader.glsl \
honeycombVertexShader.glsl \
honeycombGeometryShader.glsl \
honeycombFragmentShader.glsl \
diff --git a/slideshow/opengl/glitterFragmentShader.glsl b/slideshow/opengl/glitterFragmentShader.glsl
new file mode 100644
index 000000000000..1bec20102be6
--- /dev/null
+++ b/slideshow/opengl/glitterFragmentShader.glsl
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#version 130
+
+#define M_PI 3.1415926535897932384626433832795
+
+uniform sampler2D leavingSlideTexture;
+uniform sampler2D enteringSlideTexture;
+varying vec2 v_texturePosition;
+varying vec3 v_normal;
+
+uniform float time;
+varying float angle;
+
+void main() {
+ vec3 lightVector = vec3(0.0, 0.0, 1.0);
+ float light = dot(lightVector, v_normal);
+
+ vec4 fragment;
+ if (angle < M_PI)
+ fragment = texture2D(leavingSlideTexture, v_texturePosition);
+ else
+ fragment = texture2D(enteringSlideTexture, v_texturePosition);
+
+ vec4 black = vec4(0.0, 0.0, 0.0, fragment.a);
+ gl_FragColor = mix(black, fragment, max(light, 0.0));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/slideshow/opengl/glitterVertexShader.glsl b/slideshow/opengl/glitterVertexShader.glsl
new file mode 100644
index 000000000000..9fdaf2999a14
--- /dev/null
+++ b/slideshow/opengl/glitterVertexShader.glsl
@@ -0,0 +1,79 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#version 130
+
+#define M_PI 3.1415926535897932384626433832795
+
+attribute vec3 a_position;
+attribute vec3 a_normal;
+
+uniform mat4 u_projectionMatrix;
+uniform mat4 u_modelViewMatrix;
+uniform mat4 u_sceneTransformMatrix;
+uniform mat4 u_primitiveTransformMatrix;
+uniform mat4 u_operationsTransformMatrix;
+
+varying vec2 v_texturePosition;
+varying vec3 v_normal;
+
+attribute vec3 center;
+uniform float time;
+uniform ivec2 numTiles;
+uniform sampler2D permTexture;
+varying float angle;
+
+float snoise(vec2 p)
+{
+ return texture2D(permTexture, p).r;
+}
+
+mat4 translationMatrix(vec3 axis)
+{
+ return mat4(1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ axis.x, axis.y, axis.z, 1.0);
+}
+
+mat4 rotationMatrix(vec3 axis, float angle)
+{
+ axis = normalize(axis);
+ float s = sin(angle);
+ float c = cos(angle);
+ float oc = 1.0 - c;
+
+ return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
+ oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
+ oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
+}
+
+void main( void )
+{
+ // There are 18 vertices in an hexagon
+ int instanceID = gl_VertexID / 18;
+
+ vec2 pos = (center.xy + 1) / 2;
+ float fuzz = snoise(pos);
+ float startTime = pos.x * 0.5 + fuzz * 0.25;
+ float endTime = startTime + 0.25;
+ float actualTime = clamp((time - startTime) / (endTime - startTime), 0, 1);
+ angle = actualTime * M_PI * 2;
+
+ mat4 modelViewMatrix = u_modelViewMatrix * u_operationsTransformMatrix * u_sceneTransformMatrix * u_primitiveTransformMatrix;
+ mat4 transformMatrix = translationMatrix(center) * rotationMatrix(vec3(0, 1, 0), angle) * translationMatrix(-center);
+
+ mat3 normalMatrix = mat3(transpose(inverse(transformMatrix)));
+ gl_Position = u_projectionMatrix * modelViewMatrix * transformMatrix * vec4(a_position, 1.0);
+ v_texturePosition = vec2((a_position.x + 1) / 2, (1 - a_position.y) / 2);
+ v_normal = normalize(normalMatrix * a_normal);
+}
+
+/* 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 36ee0e767e97..86cc2c729459 100644
--- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
+++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionImpl.cxx
@@ -1768,40 +1768,105 @@ void createHexagon(Primitive& aHexagon, const int x, const int y, const int NX,
}
}
-std::shared_ptr<OGLTransitionImpl> makeGlitter()
+namespace
{
- const int NX = 80;
- const int NY = NX * 4 / 3;
- Primitives_t aLeavingSlide;
- Primitives_t aEnteringSlide;
-
- for (int y = 0; y < NY+2; y+=2)
+class GlitterTransition : public PermTextureTransition
+{
+public:
+ GlitterTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
+ : PermTextureTransition(rScene, rSettings)
{
- for (int x = 0; x < NX+2; x+=2)
- {
- Primitive aHexagon;
- createHexagon(aHexagon, x, y, NX, NY);
+ }
- glm::vec3 aCenter = aHexagon.getVertex(2);
+private:
+ virtual GLuint makeShader() const override;
+ virtual void prepareTransition( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex ) override;
+ virtual void finish( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight ) override;
- float fRandom = comphelper::rng::uniform_real_distribution(-0.25, std::nextafter(0.2, DBL_MAX));
+ GLuint maBuffer = 0;
+};
- double fDelta = 0.6 + fRandom;
- double fHorizontal = fdiv(x, NX + 2) * fDelta;
+GLuint GlitterTransition::makeShader() const
+{
+ return OpenGLHelper::LoadShaders( "glitterVertexShader", "glitterFragmentShader" );
+}
- double fStart = fHorizontal;
- double fEnd = fHorizontal + (1.0 - fDelta);
+struct ThreeFloats
+{
+ GLfloat x, y, z;
+};
- aHexagon.Operations.push_back(makeSRotate(glm::vec3(0, 1, 0), aCenter, 180 , true, fStart, fEnd));
- aLeavingSlide.push_back(aHexagon);
+void GlitterTransition::prepareTransition( sal_Int32 glLeavingSlideTex, sal_Int32 glEnteringSlideTex )
+{
+ CHECK_GL_ERROR();
+ PermTextureTransition::prepareTransition( glLeavingSlideTex, glEnteringSlideTex );
+ CHECK_GL_ERROR();
- aHexagon.Operations.push_back(makeSRotate(glm::vec3(0, 1, 0), aCenter, 180 , false, fStart, fEnd));
- aEnteringSlide.push_back(aHexagon);
- }
+ GLint nNumTilesLocation = glGetUniformLocation(m_nProgramObject, "numTiles");
+ if (nNumTilesLocation != -1) {
+ glUniform2iv(nNumTilesLocation, 1, glm::value_ptr(glm::ivec2(41, 41 * 4 / 3)));
+ CHECK_GL_ERROR();
}
- return makeSimpleTransition(aLeavingSlide, aEnteringSlide);
+ glGenBuffers(1, &maBuffer);
+ glBindBuffer(GL_ARRAY_BUFFER, maBuffer);
+
+ // Upload the center of each hexagon.
+ const Primitive& primitive = getScene().getLeavingSlide()[0];
+ int nbVertices = primitive.getVerticesSize() / sizeof(Vertex);
+ std::vector<ThreeFloats> vertices;
+ for (int i = 2; i < nbVertices; i += 18) {
+ const glm::vec3& center = primitive.getVertex(i);
+ for (int j = 0; j < 18; ++j)
+ vertices.push_back({center.x, center.y, center.z});
+ }
+ glBufferData(GL_ARRAY_BUFFER, vertices.size() * 3 * sizeof(GLfloat), vertices.data(), GL_STATIC_DRAW);
+
+ GLint location = glGetAttribLocation(m_nProgramObject, "center");
+ if (location != -1) {
+ glEnableVertexAttribArray(location);
+ glVertexAttribPointer( location, 3, GL_FLOAT, false, 0, NULL );
+ CHECK_GL_ERROR();
+ }
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+}
+
+void GlitterTransition::finish( double, double, double, double, double )
+{
+ CHECK_GL_ERROR();
+ glDeleteBuffers(1, &maBuffer);
+ CHECK_GL_ERROR();
+}
+
+std::shared_ptr<OGLTransitionImpl>
+makeGlitterTransition(const Primitives_t& rLeavingSlidePrimitives,
+ const Primitives_t& rEnteringSlidePrimitives,
+ const TransitionSettings& rSettings = TransitionSettings())
+{
+ return std::make_shared<GlitterTransition>(TransitionScene(rLeavingSlidePrimitives, rEnteringSlidePrimitives),
+ rSettings);
+}
+
+}
+
+std::shared_ptr<OGLTransitionImpl> makeGlitter()
+{
+ const int NX = 80;
+ const int NY = NX * 4 / 3;
+
+ Primitives_t aSlide;
+ Primitives_t aEmptySlide;
+ Primitive aHexagon;
+
+ for (int y = 0; y < NY+2; y+=2)
+ for (int x = 0; x < NX+2; x+=2)
+ createHexagon(aHexagon, x, y, NX, NY);
+
+ aSlide.push_back(aHexagon);
+
+ return makeGlitterTransition(aSlide, aEmptySlide);
}
namespace