basegfx/source/glm_matrix/b2dglmmatrixtools.cxx | 360 ++++++++++++++++++++++++ canvas/source/opengl/ogl_spritedevicehelper.cxx | 8 canvas/source/opengl/ogl_spritedevicehelper.hxx | 3 include/basegfx/matrix/b2dglmmatrixtools.hxx | 134 ++++++++ 4 files changed, 500 insertions(+), 5 deletions(-)
New commits: commit 813fe994f5588db9639b0cbe7aa6778e400513b8 Author: Michael Jaumann <meta_...@yahoo.com> Date: Mon Nov 3 13:34:01 2014 +0000 replaced B2IVector with glm::vec2 Change-Id: Id89699358ec0a831184b4180a1e0c34c5ce2d9d0 diff --git a/canvas/source/opengl/ogl_spritedevicehelper.cxx b/canvas/source/opengl/ogl_spritedevicehelper.cxx index 5b712b8..70c9507 100644 --- a/canvas/source/opengl/ogl_spritedevicehelper.cxx +++ b/canvas/source/opengl/ogl_spritedevicehelper.cxx @@ -543,7 +543,7 @@ namespace oglcanvas class BufferContextImpl : public IBufferContext { - ::basegfx::B2IVector maSize; + glm::vec2 maSize; GLuint mnFrambufferId; GLuint mnDepthId; GLuint mnTextureId; @@ -566,13 +566,13 @@ namespace oglcanvas } public: - BufferContextImpl(const ::basegfx::B2IVector& rSize) : + BufferContextImpl(const glm::vec2& rSize) : maSize(rSize), mnFrambufferId(0), mnDepthId(0), mnTextureId(0) { - OpenGLHelper::createFramebuffer(maSize.getX(), maSize.getY(), mnFrambufferId, + OpenGLHelper::createFramebuffer(maSize.x, maSize.y, mnFrambufferId, mnDepthId, mnTextureId, false); } @@ -585,7 +585,7 @@ namespace oglcanvas }; } - IBufferContextSharedPtr SpriteDeviceHelper::createBufferContext(const ::basegfx::B2IVector& rSize) const + IBufferContextSharedPtr SpriteDeviceHelper::createBufferContext(const glm::vec2& rSize) const { return IBufferContextSharedPtr(new BufferContextImpl(rSize)); } diff --git a/canvas/source/opengl/ogl_spritedevicehelper.hxx b/canvas/source/opengl/ogl_spritedevicehelper.hxx index 4eb3c4b..e9ecdc2 100644 --- a/canvas/source/opengl/ogl_spritedevicehelper.hxx +++ b/canvas/source/opengl/ogl_spritedevicehelper.hxx @@ -20,6 +20,7 @@ #include "ogl_buffercontext.hxx" +#include <glm/glm.hpp> #include <set> namespace vcl { class Window; } @@ -110,7 +111,7 @@ namespace oglcanvas const ::basegfx::B2DHomMatrix& rTexTransform ); /// create a pbuffer context (for rendering into background surface) - IBufferContextSharedPtr createBufferContext(const ::basegfx::B2IVector& rSize) const; + IBufferContextSharedPtr createBufferContext(const glm::vec2& rSize) const; /// Get instance of internal texture cache TextureCache& getTextureCache() const; commit 6dedd443191f5da89d9b1414274aa1ecaa10c95c Author: Michael Jaumann <meta_...@yahoo.com> Date: Mon Nov 3 13:24:29 2014 +0000 migrate matrixtools to glm Change-Id: Ibd558f5d85f78e52fc6a73ba14acf2ea68ce8a37 diff --git a/basegfx/source/glm_matrix/b2dglmmatrixtools.cxx b/basegfx/source/glm_matrix/b2dglmmatrixtools.cxx new file mode 100644 index 0000000..0c81327 --- /dev/null +++ b/basegfx/source/glm_matrix/b2dglmmatrixtools.cxx @@ -0,0 +1,360 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <basegfx/matrix/b2dglmmatrixtools.hxx> +#include <basegfx/matrix/b2dhommatrixtools.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> + +namespace basegfx +{ + namespace tools + { + + glm::mat4 createScaleGlmMatrix(double fScaleX, double fScaleY) + { + glm::mat4 aRetval; + const double fOne(1.0); + + if(!fTools::equal(fScaleX, fOne)) + { + aRetval[0][0] = fScaleX; + } + + if(!fTools::equal(fScaleY, fOne)) + { + aRetval[1][1] = fScaleY; + } + + return aRetval; + } + + glm::mat4 createShearXGlmMatrix(double fShearX) + { + glm::mat4 aRetval; + + if(!fTools::equalZero(fShearX)) + { + aRetval[1][0] = fShearX; + } + + return aRetval; + } + + glm::mat4 createShearYGlmMatrix(double fShearY) + { + glm::mat4 aRetval; + + if(!fTools::equalZero(fShearY)) + { + aRetval[0][1] = fShearY; + } + + return aRetval; + } + + glm::mat4 createRotateGlmMatrix(double fRadiant) + { + glm::mat4 aRetval; + + if(!fTools::equalZero(fRadiant)) + { + double fSin(0.0); + double fCos(1.0); + + createSinCosOrthogonal(fSin, fCos, fRadiant); + aRetval[0][0] = fCos; + aRetval[1][1] = fCos; + aRetval[0][1] = fSin; + aRetval[1][0] = -fSin; + } + + return aRetval; + } + + glm::mat4 createTranslateGlmMatrix(double fTranslateX, double fTranslateY) + { + glm::mat4 aRetval; + + if(!(fTools::equalZero(fTranslateX) && fTools::equalZero(fTranslateY))) + { + aRetval[2][0] = fTranslateX; + aRetval[2][1] = fTranslateY; + } + + return aRetval; + } + + glm::mat4 createScaleShearXRotateTranslateGlmMatrix( + double fScaleX, double fScaleY, + double fShearX, + double fRadiant, + double fTranslateX, double fTranslateY) + { + const double fOne(1.0); + + if(fTools::equal(fScaleX, fOne) && fTools::equal(fScaleY, fOne)) + { + /// no scale, take shortcut + return createShearXRotateTranslateGlmMatrix(fShearX, fRadiant, fTranslateX, fTranslateY); + } + else + { + /// scale used + if(fTools::equalZero(fShearX)) + { + /// no shear + if(fTools::equalZero(fRadiant)) + { + /// no rotate, take shortcut + return createScaleTranslateGlmMatrix(fScaleX, fScaleY, fTranslateX, fTranslateY); + } + else + { + /// rotate and scale used, no shear + double fSin(0.0); + double fCos(1.0); + + createSinCosOrthogonal(fSin, fCos, fRadiant); + + glm::mat4 aRetval; + aRetval[0][0] = fCos * fScaleX; + aRetval[1][0] = fScaleY * -fSin; + aRetval[2][0] = fTranslateX; + aRetval[0][1] = fSin * fScaleX; + aRetval[1][1] = fScaleY * fCos; + aRetval[2][1] = fTranslateY; + + return aRetval; + } + } + else + { + /// scale and shear used + if(fTools::equalZero(fRadiant)) + { + /// scale and shear, but no rotate + glm::mat4 aRetval; + aRetval[0][0] = fScaleX; + aRetval[1][0] = fScaleY * fShearX; + aRetval[2][0] = fTranslateX; + aRetval[0][1] = 0.0; + aRetval[1][1] = fScaleY; + aRetval[2][1] = fTranslateY; + + return aRetval; + } + else + { + /// scale, shear and rotate used + double fSin(0.0); + double fCos(1.0); + + createSinCosOrthogonal(fSin, fCos, fRadiant); + + glm::mat4 aRetval; + aRetval[0][0] = fCos * fScaleX; + aRetval[1][0] = fScaleY * ((fCos * fShearX) - fSin); + aRetval[2][0] = fTranslateX; + aRetval[0][1] = fSin * fScaleX; + aRetval[1][1] = fScaleY * ((fSin * fShearX) + fCos); + aRetval[2][1] = fTranslateY; + + return aRetval; + } + } + } + } + + glm::mat4 createShearXRotateTranslateGlmMatrix( + double fShearX, + double fRadiant, + double fTranslateX, double fTranslateY) + { + if(fTools::equalZero(fShearX)) + { + /// no shear + if(fTools::equalZero(fRadiant)) + { + /// no shear, no rotate, take shortcut + return createTranslateGlmMatrix(fTranslateX, fTranslateY); + } + else + { + /// no shear, but rotate used + double fSin(0.0); + double fCos(1.0); + + createSinCosOrthogonal(fSin, fCos, fRadiant); + + glm::mat4 aRetval; + aRetval[0][0] = fCos; + aRetval[1][0] = -fSin; + aRetval[2][0] = fTranslateX; + aRetval[0][1] = fSin; + aRetval[1][1] = fCos; + aRetval[2][1] = fTranslateY; + + return aRetval; + } + } + else + { + /// shear used + if(fTools::equalZero(fRadiant)) + { + /// no rotate, but shear used + glm::mat4 aRetval; + aRetval[0][0] = 1.0; + aRetval[1][0] = fShearX; + aRetval[2][0] = fTranslateX; + aRetval[0][1] = 0.0; + aRetval[1][1] = 1.0; + aRetval[2][1] = fTranslateY; + + return aRetval; + } + else + { + /// shear and rotate used + double fSin(0.0); + double fCos(1.0); + + createSinCosOrthogonal(fSin, fCos, fRadiant); + + glm::mat4 aRetval; + aRetval[0][0] = fCos; + aRetval[1][0] = (fCos * fShearX) - fSin; + aRetval[2][0] = fTranslateX; + aRetval[0][1] = fSin; + aRetval[1][1] = (fSin * fShearX) + fCos; + aRetval[2][1] = fTranslateY; + + return aRetval; + } + } + } + + glm::mat4 createScaleTranslateGlmMatrix( + double fScaleX, double fScaleY, + double fTranslateX, double fTranslateY) + { + const double fOne(1.0); + + if(fTools::equal(fScaleX, fOne) && fTools::equal(fScaleY, fOne)) + { + /// no scale, take shortcut + return createTranslateGlmMatrix(fTranslateX, fTranslateY); + } + else + { + /// scale used + if(fTools::equalZero(fTranslateX) && fTools::equalZero(fTranslateY)) + { + /// no translate, but scale. + glm::mat4 aRetval; + + aRetval[0][0] = fScaleX; + aRetval[1][1] = fScaleY; + + return aRetval; + } + else + { + /// translate and scale + glm::mat4 aRetval; + aRetval[0][0] = fScaleX; + aRetval[1][0] = 0.0; + aRetval[2][0] = fTranslateX; + aRetval[0][1] = 0.0; + aRetval[1][1] = fScaleY; + aRetval[2][1] = fTranslateY; + + return aRetval; + } + } + } + + glm::mat4 createRotateAroundPointGlmMatrix( + double fPointX, double fPointY, + double fRadiant) + { + glm::mat4 aRetval; + + if(!fTools::equalZero(fRadiant)) + { + double fSin(0.0); + double fCos(1.0); + + createSinCosOrthogonal(fSin, fCos, fRadiant); + aRetval[0][0] = fCos; + aRetval[1][0] = -fSin; + aRetval[2][0] = (fPointX * (1.0 - fCos)) + (fSin * fPointY); + aRetval[0][1] = fSin; + aRetval[1][1] = fCos; + aRetval[2][1] = (fPointY * (1.0 - fCos)) - (fSin * fPointX); + } + + return aRetval; + } + + /// special for the case to map from source range to target range + glm::mat4 createSourceRangeTargetRangeTransformGlmMatrix( + const B2DRange& rSourceRange, + const B2DRange& rTargetRange) + { + glm::mat4 aRetval; + + if(&rSourceRange == &rTargetRange) + { + return aRetval; + } + + if(!fTools::equalZero(rSourceRange.getMinX()) || !fTools::equalZero(rSourceRange.getMinY())) + { + aRetval[2][0] = -rSourceRange.getMinX(); + aRetval[2][1] = -rSourceRange.getMinY(); + } + + const double fSourceW(rSourceRange.getWidth()); + const double fSourceH(rSourceRange.getHeight()); + const bool bDivX(!fTools::equalZero(fSourceW) && !fTools::equal(fSourceW, 1.0)); + const bool bDivY(!fTools::equalZero(fSourceH) && !fTools::equal(fSourceH, 1.0)); + const double fScaleX(bDivX ? rTargetRange.getWidth() / fSourceW : rTargetRange.getWidth()); + const double fScaleY(bDivY ? rTargetRange.getHeight() / fSourceH : rTargetRange.getHeight()); + + if(!fTools::equalZero(fScaleX) || !fTools::equalZero(fScaleY)) + { + aRetval[0][0] = fScaleX; + aRetval[1][1] = fScaleY; + } + + if(!fTools::equalZero(rTargetRange.getMinX()) || !fTools::equalZero(rTargetRange.getMinY())) + { + aRetval[0][0] *= rTargetRange.getMinX(); + aRetval[1][1] *= rTargetRange.getMinY(); + } + + return aRetval; + } + + } // end of namespace tools +} // end of namespace basegfx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/basegfx/matrix/b2dglmmatrixtools.hxx b/include/basegfx/matrix/b2dglmmatrixtools.hxx new file mode 100644 index 0000000..4b13e29 --- /dev/null +++ b/include/basegfx/matrix/b2dglmmatrixtools.hxx @@ -0,0 +1,134 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_BASEGFX_MATRIX_B2DGLMMATRIXTOOLS_HXX +#define INCLUDED_BASEGFX_MATRIX_B2DGLMMATRIXTOOLS_HXX + +#include <sal/types.h> +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <basegfx/vector/b2dvector.hxx> +#include <basegfx/range/b2drange.hxx> +#include <basegfx/basegfxdllapi.h> +#include <glm/glm.hpp> + + + +namespace basegfx +{ + namespace tools + { + /** Tooling methods for on-the-fly matrix generation e.g. for inline + multiplications + */ + BASEGFX_DLLPUBLIC glm::mat4 createScaleGlmMatrix(double fScaleX, double fScaleY); + BASEGFX_DLLPUBLIC glm::mat4 createShearXGlmMatrix(double fShearX); + BASEGFX_DLLPUBLIC glm::mat4 createShearYGlmMatrix(double fShearY); + BASEGFX_DLLPUBLIC glm::mat4 createRotateGlmMatrix(double fRadiant); + BASEGFX_DLLPUBLIC glm::mat4 createTranslateGlmMatrix(double fTranslateX, double fTranslateY); + + /// inline versions for parameters as tuples + inline glm::mat4 createScaleGlmMatrix(const B2DTuple& rScale) + { + return createScaleGlmMatrix(rScale.getX(), rScale.getY()); + } + + inline glm::mat4 createTranslateGlmMatrix(const B2DTuple& rTranslate) + { + return createTranslateGlmMatrix(rTranslate.getX(), rTranslate.getY()); + } + + /** Tooling methods for faster completely combined matrix creation + when scale, shearX, rotation and translation needs to be done in + exactly that order. It's faster since it direcly calculates + each matrix value based on a symbolic calculation of the three + matrix multiplications. + Inline versions for parameters as tuples added, too. + */ + BASEGFX_DLLPUBLIC glm::mat4 createScaleShearXRotateTranslateGlmMatrix( + double fScaleX, double fScaleY, + double fShearX, + double fRadiant, + double fTranslateX, double fTranslateY); + inline glm::mat4 createScaleShearXRotateTranslateGlmMatrix( + const B2DTuple& rScale, + double fShearX, + double fRadiant, + const B2DTuple& rTranslate) + { + return createScaleShearXRotateTranslateGlmMatrix( + rScale.getX(), rScale.getY(), + fShearX, + fRadiant, + rTranslate.getX(), rTranslate.getY()); + } + + BASEGFX_DLLPUBLIC glm::mat4 createShearXRotateTranslateGlmMatrix( + double fShearX, + double fRadiant, + double fTranslateX, double fTranslateY); + inline glm::mat4 createShearXRotateTranslateGlmMatrix( + double fShearX, + double fRadiant, + const B2DTuple& rTranslate) + { + return createShearXRotateTranslateGlmMatrix( + fShearX, + fRadiant, + rTranslate.getX(), rTranslate.getY()); + } + + BASEGFX_DLLPUBLIC glm::mat4 createScaleTranslateGlmMatrix( + double fScaleX, double fScaleY, + double fTranslateX, double fTranslateY); + inline glm::mat4 createScaleTranslateGlmMatrix( + const B2DTuple& rScale, + const B2DTuple& rTranslate) + { + return createScaleTranslateGlmMatrix( + rScale.getX(), rScale.getY(), + rTranslate.getX(), rTranslate.getY()); + } + + /// special for the often used case of rotation around a point + BASEGFX_DLLPUBLIC glm::mat4 createRotateAroundPointGlmMatrix( + double fPointX, double fPointY, + double fRadiant); + inline glm::mat4 createRotateAroundPointGlmMatrix( + const B2DTuple& rPoint, + double fRadiant) + { + return createRotateAroundPointGlmMatrix( + rPoint.getX(), rPoint.getY(), + fRadiant); + } + + /// special for the case to map from source range to target range + BASEGFX_DLLPUBLIC glm::mat4 createSourceRangeTargetRangeTransformGlmMatrix( + const B2DRange& rSourceRange, + const B2DRange& rTargetRange); + + } // end of namespace tools +} // end of namespace basegfx + + + + +#endif // INCLUDED_BASEGFX_MATRIX_GlmMATRIXTOOLS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits