mirror of https://github.com/mosra/magnum.git
102 changed files with 1871 additions and 985 deletions
@ -0,0 +1,44 @@
|
||||
# Author: mosra <mosra@centrum.cz> |
||||
pkgname=magnum |
||||
pkgver=dev.es2 |
||||
pkgrel=1 |
||||
pkgdesc="OpenGL graphics engine (OpenGL ES 2.0 version)" |
||||
arch=('i686' 'x86_64') |
||||
url="https://github.com/mosra/magnum" |
||||
license=('MIT') |
||||
depends=('corrade' 'glew') |
||||
makedepends=('cmake') |
||||
options=(!strip) |
||||
provides=('magnum-git') |
||||
|
||||
build() { |
||||
mkdir -p "$startdir/build-es2" |
||||
cd "$startdir/build-es2" |
||||
|
||||
if [ "$CXX" = clang++ ] ; then |
||||
newcxxflags=$(echo $CXXFLAGS | sed s/--param=ssp-buffer-size=4//g) |
||||
export CXXFLAGS="$newcxxflags" |
||||
fi |
||||
|
||||
cmake .. \ |
||||
-DCMAKE_BUILD_TYPE=Debug \ |
||||
-DCMAKE_INSTALL_PREFIX=/usr \ |
||||
-DBUILD_TESTS=ON \ |
||||
-DTARGET_GLES=ON \ |
||||
-DTARGET_GLES2=ON \ |
||||
-DWITH_TEXT=OFF \ |
||||
-DWITH_TEXTURETOOLS=OFF \ |
||||
-DWITH_MAGNUMINFO=OFF \ |
||||
-DWITH_XEGLAPPLICATION=ON |
||||
make |
||||
} |
||||
|
||||
check() { |
||||
cd "$startdir/build-es2" |
||||
ctest --output-on-failure |
||||
} |
||||
|
||||
package() { |
||||
cd "$startdir/build-es2" |
||||
make DESTDIR="$pkgdir/" install |
||||
} |
||||
@ -0,0 +1,45 @@
|
||||
# Author: mosra <mosra@centrum.cz> |
||||
pkgname=magnum |
||||
pkgver=dev.es2desktop |
||||
pkgrel=1 |
||||
pkgdesc="OpenGL graphics engine (desktop OpenGL ES 2.0 version)" |
||||
arch=('i686' 'x86_64') |
||||
url="https://github.com/mosra/magnum" |
||||
license=('MIT') |
||||
depends=('corrade' 'glew') |
||||
makedepends=('cmake') |
||||
options=(!strip) |
||||
provides=('magnum-git') |
||||
|
||||
build() { |
||||
mkdir -p "$startdir/build-es2desktop" |
||||
cd "$startdir/build-es2desktop" |
||||
|
||||
if [ "$CXX" = clang++ ] ; then |
||||
newcxxflags=$(echo $CXXFLAGS | sed s/--param=ssp-buffer-size=4//g) |
||||
export CXXFLAGS="$newcxxflags" |
||||
fi |
||||
|
||||
cmake .. \ |
||||
-DCMAKE_BUILD_TYPE=Debug \ |
||||
-DCMAKE_INSTALL_PREFIX=/usr \ |
||||
-DBUILD_TESTS=ON \ |
||||
-DTARGET_GLES=ON \ |
||||
-DTARGET_GLES2=ON \ |
||||
-DTARGET_DESKTOP_GLES=ON \ |
||||
-DWITH_TEXT=OFF \ |
||||
-DWITH_TEXTURETOOLS=OFF \ |
||||
-DWITH_MAGNUMINFO=OFF \ |
||||
-DWITH_XEGLAPPLICATION=ON |
||||
make |
||||
} |
||||
|
||||
check() { |
||||
cd "$startdir/build-es2desktop" |
||||
ctest --output-on-failure |
||||
} |
||||
|
||||
package() { |
||||
cd "$startdir/build-es2desktop" |
||||
make DESTDIR="$pkgdir/" install |
||||
} |
||||
@ -0,0 +1,44 @@
|
||||
# Author: mosra <mosra@centrum.cz> |
||||
pkgname=magnum |
||||
pkgver=dev.es3 |
||||
pkgrel=1 |
||||
pkgdesc="OpenGL graphics engine (OpenGL ES 3.0 version)" |
||||
arch=('i686' 'x86_64') |
||||
url="https://github.com/mosra/magnum" |
||||
license=('MIT') |
||||
depends=('corrade' 'glew') |
||||
makedepends=('cmake') |
||||
options=(!strip) |
||||
provides=('magnum-git') |
||||
|
||||
build() { |
||||
mkdir -p "$startdir/build-es3" |
||||
cd "$startdir/build-es3" |
||||
|
||||
if [ "$CXX" = clang++ ] ; then |
||||
newcxxflags=$(echo $CXXFLAGS | sed s/--param=ssp-buffer-size=4//g) |
||||
export CXXFLAGS="$newcxxflags" |
||||
fi |
||||
|
||||
cmake .. \ |
||||
-DCMAKE_BUILD_TYPE=Debug \ |
||||
-DCMAKE_INSTALL_PREFIX=/usr \ |
||||
-DBUILD_TESTS=ON \ |
||||
-DTARGET_GLES=ON \ |
||||
-DTARGET_GLES2=OFF \ |
||||
-DWITH_TEXT=OFF \ |
||||
-DWITH_TEXTURETOOLS=OFF \ |
||||
-DWITH_MAGNUMINFO=OFF \ |
||||
-DWITH_XEGLAPPLICATION=ON |
||||
make |
||||
} |
||||
|
||||
check() { |
||||
cd "$startdir/build-es3" |
||||
ctest --output-on-failure |
||||
} |
||||
|
||||
package() { |
||||
cd "$startdir/build-es3" |
||||
make DESTDIR="$pkgdir/" install |
||||
} |
||||
@ -0,0 +1,53 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "SphereRenderer.h" |
||||
|
||||
#include "Mesh.h" |
||||
#include "DebugTools/ShapeRenderer.h" |
||||
#include "Physics/Sphere.h" |
||||
#include "Primitives/Circle.h" |
||||
#include "Shaders/FlatShader.h" |
||||
#include "Trade/MeshData2D.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
AbstractSphereRenderer<2>::AbstractSphereRenderer(): AbstractShapeRenderer<2>("sphere2d", "sphere2d-vertices", {}) { |
||||
if(!mesh) this->createResources(Primitives::Circle::wireframe(40)); |
||||
} |
||||
|
||||
template<UnsignedInt dimensions> SphereRenderer<dimensions>::SphereRenderer(Physics::Sphere<dimensions>& sphere): sphere(sphere) {} |
||||
|
||||
template<UnsignedInt dimensions> void SphereRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) { |
||||
this->shader->setTransformationProjectionMatrix(projectionMatrix* |
||||
DimensionTraits<dimensions>::MatrixType::translation(sphere.position())* |
||||
DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(sphere.radius()))) |
||||
->setColor(options->color()) |
||||
->use(); |
||||
this->mesh->draw(); |
||||
} |
||||
|
||||
template class SphereRenderer<2>; |
||||
|
||||
}}} |
||||
@ -0,0 +1,54 @@
|
||||
#ifndef Magnum_DebugTools_Implementation_SphereRenderer_h |
||||
#define Magnum_DebugTools_Implementation_SphereRenderer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractShapeRenderer.h" |
||||
|
||||
#include "Physics/Physics.h" |
||||
|
||||
#include "corradeCompatibility.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
template<UnsignedInt dimensions> class AbstractSphereRenderer; |
||||
|
||||
template<> class AbstractSphereRenderer<2>: public AbstractShapeRenderer<2> { |
||||
public: |
||||
AbstractSphereRenderer(); |
||||
}; |
||||
|
||||
template<UnsignedInt dimensions> class SphereRenderer: public AbstractSphereRenderer<dimensions> { |
||||
public: |
||||
SphereRenderer(Physics::Sphere<dimensions>& sphere); |
||||
|
||||
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override; |
||||
|
||||
private: |
||||
Physics::Sphere<dimensions>& sphere; |
||||
}; |
||||
|
||||
}}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,66 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Circle.h" |
||||
|
||||
#include "Math/Functions.h" |
||||
#include "Math/Vector2.h" |
||||
#include "Trade/MeshData2D.h" |
||||
|
||||
namespace Magnum { namespace Primitives { |
||||
|
||||
Trade::MeshData2D Circle::solid(UnsignedInt segments) { |
||||
CORRADE_ASSERT(segments >= 3, "Primitives::Circle::solid(): segments must be >= 3", |
||||
Trade::MeshData2D(Mesh::Primitive::TriangleFan, nullptr, {}, {})); |
||||
|
||||
auto positions = new std::vector<Vector2>; |
||||
positions->reserve(segments+1); |
||||
|
||||
/* Central point */ |
||||
positions->emplace_back(); |
||||
|
||||
/* Points on circle */ |
||||
const Rad angleIncrement(2*Constants::pi()/segments); |
||||
for(UnsignedInt i = 0; i != segments; ++i) |
||||
positions->emplace_back(Math::cos(i*angleIncrement), Math::sin(i*angleIncrement)); |
||||
|
||||
return Trade::MeshData2D(Mesh::Primitive::TriangleFan, nullptr, {positions}, {}); |
||||
} |
||||
|
||||
Trade::MeshData2D Circle::wireframe(UnsignedInt segments) { |
||||
CORRADE_ASSERT(segments >= 3, "Primitives::Circle::wireframe(): segments must be >= 3", |
||||
Trade::MeshData2D(Mesh::Primitive::LineLoop, nullptr, {}, {})); |
||||
|
||||
auto positions = new std::vector<Vector2>; |
||||
positions->reserve(segments); |
||||
|
||||
/* Points on circle */ |
||||
const Rad angleIncrement(2*Constants::pi()/segments); |
||||
for(UnsignedInt i = 0; i != segments; ++i) |
||||
positions->emplace_back(Math::cos(i*angleIncrement), Math::sin(i*angleIncrement)); |
||||
|
||||
return Trade::MeshData2D(Mesh::Primitive::LineLoop, nullptr, {positions}, {}); |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,65 @@
|
||||
#ifndef Magnum_Primitives_Circle_h |
||||
#define Magnum_Primitives_Circle_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::Primitives::Circle |
||||
*/ |
||||
|
||||
#include "Trade/Trade.h" |
||||
|
||||
#include "Primitives/magnumPrimitivesVisibility.h" |
||||
|
||||
namespace Magnum { namespace Primitives { |
||||
|
||||
/**
|
||||
@brief 2D circle primitive |
||||
|
||||
Circle with radius 1. |
||||
*/ |
||||
class MAGNUM_PRIMITIVES_EXPORT Circle { |
||||
public: |
||||
/**
|
||||
* @brief Solid circle |
||||
* @param segments Number of segments. Must be greater or equal to 3. |
||||
* |
||||
* Non-indexed @ref Mesh::Primitive "TriangleFan". |
||||
*/ |
||||
static Trade::MeshData2D solid(UnsignedInt segments); |
||||
|
||||
/**
|
||||
* @brief Wireframe circle |
||||
* @param segments Number of segments. Must be greater or equal to 3. |
||||
* |
||||
* Non-indexed @ref Mesh::Primitive "LineLoop". |
||||
*/ |
||||
static Trade::MeshData2D wireframe(UnsignedInt segments); |
||||
|
||||
Circle() = delete; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,71 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include <TestSuite/Tester.h> |
||||
|
||||
#include "Math/Vector2.h" |
||||
#include "Primitives/Circle.h" |
||||
#include "Trade/MeshData2D.h" |
||||
|
||||
namespace Magnum { namespace Primitives { namespace Test { |
||||
|
||||
class CircleTest: public Corrade::TestSuite::Tester { |
||||
public: |
||||
explicit CircleTest(); |
||||
|
||||
void solid(); |
||||
void wireframe(); |
||||
}; |
||||
|
||||
CircleTest::CircleTest() { |
||||
addTests({&CircleTest::solid, |
||||
&CircleTest::wireframe}); |
||||
} |
||||
|
||||
void CircleTest::solid() { |
||||
Trade::MeshData2D circle = Primitives::Circle::solid(8); |
||||
|
||||
CORRADE_COMPARE(*circle.positions(0), (std::vector<Vector2>{ |
||||
{ 0.0f, 0.0f}, |
||||
{ 1.0f, 0.0f}, { Constants::sqrt2()/2.0f, Constants::sqrt2()/2.0f}, |
||||
{ 0.0f, 1.0f}, {-Constants::sqrt2()/2.0f, Constants::sqrt2()/2.0f}, |
||||
{-1.0f, 0.0f}, {-Constants::sqrt2()/2.0f, -Constants::sqrt2()/2.0f}, |
||||
{ 0.0f, -1.0f}, { Constants::sqrt2()/2.0f, -Constants::sqrt2()/2.0f} |
||||
})); |
||||
} |
||||
|
||||
void CircleTest::wireframe() { |
||||
Trade::MeshData2D circle = Primitives::Circle::wireframe(8); |
||||
|
||||
CORRADE_COMPARE(*circle.positions(0), (std::vector<Vector2>{ |
||||
{ 1.0f, 0.0f}, { Constants::sqrt2()/2.0f, Constants::sqrt2()/2.0f}, |
||||
{ 0.0f, 1.0f}, {-Constants::sqrt2()/2.0f, Constants::sqrt2()/2.0f}, |
||||
{-1.0f, 0.0f}, {-Constants::sqrt2()/2.0f, -Constants::sqrt2()/2.0f}, |
||||
{ 0.0f, -1.0f}, { Constants::sqrt2()/2.0f, -Constants::sqrt2()/2.0f} |
||||
})); |
||||
} |
||||
|
||||
}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Primitives::Test::CircleTest) |
||||
@ -0,0 +1,66 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "DistanceFieldGlyphCache.h" |
||||
|
||||
#include "Extensions.h" |
||||
#include "Image.h" |
||||
#include "TextureTools/DistanceField.h" |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
namespace { |
||||
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3) |
||||
const AbstractTexture::InternalFormat internalFormat = AbstractTexture::InternalFormat::R8; |
||||
#else |
||||
const AbstractTexture::InternalFormat internalFormat = AbstractTexture::InternalFormat::Red; |
||||
#endif |
||||
} |
||||
|
||||
DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& originalSize, const Vector2i& distanceFieldSize, UnsignedInt radius): GlyphCache(originalSize, Vector2i(radius)), scale(Vector2(distanceFieldSize)/originalSize), radius(radius) { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); |
||||
#else |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); |
||||
#endif |
||||
|
||||
initialize(internalFormat, distanceFieldSize); |
||||
} |
||||
|
||||
void DistanceFieldGlyphCache::setImage(const Vector2i& offset, Image2D* const image) { |
||||
Texture2D input; |
||||
input.setWrapping(Texture2D::Wrapping::ClampToEdge) |
||||
->setMinificationFilter(Texture2D::Filter::Linear) |
||||
->setMagnificationFilter(Texture2D::Filter::Linear) |
||||
->setImage(0, internalFormat, image); |
||||
|
||||
/* Create distance field from input texture */ |
||||
TextureTools::distanceField(&input, &_texture, Rectanglei::fromSize(offset*scale, image->size()*scale), radius); |
||||
} |
||||
|
||||
void DistanceFieldGlyphCache::setDistanceFieldImage(const Vector2i& offset, Image2D* const image) { |
||||
_texture.setSubImage(0, offset, image); |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,92 @@
|
||||
#ifndef Magnum_Text_DistanceFieldGlyphCache_h |
||||
#define Magnum_Text_DistanceFieldGlyphCache_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::Text::DistanceFieldGlyphCache |
||||
*/ |
||||
|
||||
#include "Text/GlyphCache.h" |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
/**
|
||||
@brief Glyph cache with distance field rendering |
||||
|
||||
Unlike original GlyphCache converts each binary image to distance field. It is |
||||
not possible to use non-binary colors with this cache, internal texture format |
||||
is red channel only. |
||||
|
||||
@section GlyphCache-usage Usage |
||||
|
||||
Usage is similar to GlyphCache, additionaly you need to specify size of |
||||
resulting distance field texture. |
||||
@code |
||||
Text::AbstractFont* font; |
||||
Text::GlyphCache* cache = new Text::DistanceFieldGlyphCache(Vector2i(2048), Vector2i(384)); |
||||
font->createGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz" |
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
||||
"0123456789 "); |
||||
@endcode |
||||
|
||||
@see TextureTools::distanceField() |
||||
*/ |
||||
class MAGNUM_TEXT_EXPORT DistanceFieldGlyphCache: public GlyphCache { |
||||
public: |
||||
/**
|
||||
* @brief Constructor |
||||
* @param originalSize Original cache texture size |
||||
* @param distanceFieldSize Size of computed distance field texture |
||||
* @param radius Distance field computation radius |
||||
* |
||||
* See TextureTools::distanceField() for more information about the |
||||
* parameters. |
||||
*/ |
||||
explicit DistanceFieldGlyphCache(const Vector2i& originalSize, const Vector2i& distanceFieldSize, UnsignedInt radius); |
||||
|
||||
/**
|
||||
* @brief Set cache image |
||||
* |
||||
* Uploads image for one or more glyphs to given offset in original |
||||
* cache texture. The texture is then converted to distance field. |
||||
*/ |
||||
void setImage(const Vector2i& offset, Image2D* const image) override; |
||||
|
||||
/**
|
||||
* @brief Set distance field cache image |
||||
* |
||||
* Uploads already computed distance field image to given offset in |
||||
* distance field texture. |
||||
*/ |
||||
void setDistanceFieldImage(const Vector2i& offset, Image2D* const image); |
||||
|
||||
private: |
||||
const Vector2 scale; |
||||
const UnsignedInt radius; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -1,229 +0,0 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "FreeTypeFont.h" |
||||
|
||||
#include <algorithm> |
||||
#include <ft2build.h> |
||||
#include FT_FREETYPE_H |
||||
#include <Utility/Unicode.h> |
||||
|
||||
#include "Extensions.h" |
||||
#include "Image.h" |
||||
#include "TextureTools/Atlas.h" |
||||
#include "TextureTools/DistanceField.h" |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
namespace { |
||||
|
||||
class FreeTypeLayouter: public AbstractLayouter { |
||||
public: |
||||
FreeTypeLayouter(FreeTypeFont& font, const Float size, const std::string& text); |
||||
|
||||
std::tuple<Rectangle, Rectangle, Vector2> renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) override; |
||||
|
||||
private: |
||||
FreeTypeFont& font; |
||||
std::vector<FT_UInt> glyphs; |
||||
const Float size; |
||||
}; |
||||
|
||||
} |
||||
|
||||
FreeTypeFontRenderer::FreeTypeFontRenderer() { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Init_FreeType(&_library) == 0); |
||||
} |
||||
|
||||
FreeTypeFontRenderer::~FreeTypeFontRenderer() { |
||||
FT_Done_FreeType(_library); |
||||
} |
||||
|
||||
FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size): _size(size) { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &_ftFont) == 0); |
||||
|
||||
finishConstruction(); |
||||
} |
||||
|
||||
FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size): _size(size) { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Memory_Face(renderer.library(), data, dataSize, 0, &_ftFont) == 0); |
||||
|
||||
finishConstruction(); |
||||
} |
||||
|
||||
void FreeTypeFont::finishConstruction() { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(_ftFont, 0, _size*64, 100, 100) == 0); |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); |
||||
#else |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); |
||||
#endif |
||||
|
||||
/* Set up the texture */ |
||||
_texture.setWrapping(Texture2D::Wrapping::ClampToEdge) |
||||
->setMinificationFilter(Texture2D::Filter::Linear) |
||||
->setMagnificationFilter(Texture2D::Filter::Linear); |
||||
} |
||||
|
||||
void FreeTypeFont::prerenderInternal(const std::string& characters, const Vector2i& atlasSize, const Int radius, Texture2D* output) { |
||||
glyphs.clear(); |
||||
|
||||
/** @bug Crash when atlas is too small */ |
||||
|
||||
/* Get glyph codes from characters */ |
||||
std::vector<FT_UInt> charIndices; |
||||
charIndices.reserve(characters.size()+1); |
||||
charIndices.push_back(0); |
||||
for(std::size_t i = 0; i != characters.size(); ) { |
||||
UnsignedInt codepoint; |
||||
std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(characters, i); |
||||
charIndices.push_back(FT_Get_Char_Index(_ftFont, codepoint)); |
||||
} |
||||
|
||||
/* Remove duplicates (e.g. uppercase and lowercase mapped to same glyph) */ |
||||
std::sort(charIndices.begin(), charIndices.end()); |
||||
charIndices.erase(std::unique(charIndices.begin(), charIndices.end()), charIndices.end()); |
||||
|
||||
/* Sizes of all characters */ |
||||
const Vector2i padding = Vector2i(radius); |
||||
std::vector<Vector2i> charSizes; |
||||
charSizes.reserve(charIndices.size()); |
||||
for(auto it = charIndices.begin(); it != charIndices.end(); ++it) { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(_ftFont, *it, FT_LOAD_DEFAULT) == 0); |
||||
charSizes.push_back(Vector2i(_ftFont->glyph->metrics.width, _ftFont->glyph->metrics.height)/64); |
||||
} |
||||
|
||||
/* Create texture atlas */ |
||||
const std::vector<Rectanglei> charPositions = TextureTools::atlas(atlasSize, charSizes, padding); |
||||
|
||||
/* Render all characters to the atlas and create character map */ |
||||
#ifndef CORRADE_GCC44_COMPATIBILITY |
||||
glyphs.reserve(charPositions.size()); |
||||
#endif |
||||
unsigned char* pixmap = new unsigned char[atlasSize.product()](); |
||||
Image2D image(atlasSize, Image2D::Format::Red, Image2D::Type::UnsignedByte, pixmap); |
||||
for(std::size_t i = 0; i != charPositions.size(); ++i) { |
||||
/* Load and render glyph */ |
||||
/** @todo B&W only if radius != 0 */ |
||||
FT_GlyphSlot glyph = _ftFont->glyph; |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(_ftFont, charIndices[i], FT_LOAD_DEFAULT) == 0); |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL) == 0); |
||||
|
||||
/* Copy rendered bitmap to texture image */ |
||||
const FT_Bitmap& bitmap = glyph->bitmap; |
||||
CORRADE_INTERNAL_ASSERT(std::abs(bitmap.width-charPositions[i].width()) <= 2); |
||||
CORRADE_INTERNAL_ASSERT(std::abs(bitmap.rows-charPositions[i].height()) <= 2); |
||||
for(Int yin = 0, yout = charPositions[i].bottom(), ymax = bitmap.rows; yin != ymax; ++yin, ++yout) |
||||
for(Int xin = 0, xout = charPositions[i].left(), xmax = bitmap.width; xin != xmax; ++xin, ++xout) |
||||
pixmap[yout*atlasSize.x() + xout] = bitmap.buffer[(bitmap.rows-yin-1)*bitmap.width + xin]; |
||||
|
||||
/* Save character texture position and texture coordinates for given character index */ |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(glyphs.insert({charIndices[i], std::make_tuple( |
||||
Rectangle::fromSize((Vector2(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height()) - Vector2(radius))/_size, |
||||
Vector2(charPositions[i].size() + 2*padding)/_size), |
||||
Rectangle(Vector2(charPositions[i].bottomLeft() - padding)/atlasSize, |
||||
Vector2(charPositions[i].topRight() + padding)/atlasSize) |
||||
)}).second); |
||||
} |
||||
|
||||
/* Set texture data */ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
output->setImage(0, Texture2D::InternalFormat::R8, &image); |
||||
#else |
||||
output->setImage(0, Texture2D::InternalFormat::Red, &image); |
||||
#endif |
||||
} |
||||
|
||||
void FreeTypeFont::prerender(const std::string& characters, const Vector2i& atlasSize) { |
||||
prerenderInternal(characters, atlasSize, 0, &_texture); |
||||
} |
||||
|
||||
void FreeTypeFont::prerenderDistanceField(const std::string& characters, const Vector2i& sourceAtlasSize, const Vector2i& atlasSize, Int radius) { |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_storage); |
||||
|
||||
/* Render input texture */ |
||||
Texture2D input; |
||||
input.setWrapping(Texture2D::Wrapping::ClampToEdge) |
||||
->setMinificationFilter(Texture2D::Filter::Linear) |
||||
->setMagnificationFilter(Texture2D::Filter::Linear); |
||||
prerenderInternal(characters, sourceAtlasSize, radius, &input); |
||||
|
||||
/* Create distance field from input texture */ |
||||
_texture.setStorage(1, Texture2D::InternalFormat::R8, atlasSize); |
||||
TextureTools::distanceField(&input, &_texture, Rectanglei::fromSize({}, atlasSize), radius); |
||||
} |
||||
|
||||
FreeTypeFont::~FreeTypeFont() { |
||||
FT_Done_Face(_ftFont); |
||||
} |
||||
|
||||
const std::tuple<Rectangle, Rectangle>& FreeTypeFont::operator[](char32_t character) const { |
||||
auto it = glyphs.find(character); |
||||
|
||||
if(it == glyphs.end()) |
||||
return glyphs.at(0); |
||||
return it->second; |
||||
} |
||||
|
||||
AbstractLayouter* FreeTypeFont::layout(const Float size, const std::string& text) { |
||||
return new FreeTypeLayouter(*this, size, text); |
||||
} |
||||
|
||||
namespace { |
||||
|
||||
FreeTypeLayouter::FreeTypeLayouter(FreeTypeFont& font, const Float size, const std::string& text): font(font), size(size) { |
||||
/* Get glyph codes from characters */ |
||||
glyphs.reserve(text.size()); |
||||
_glyphCount = text.size(); |
||||
for(std::size_t i = 0; i != text.size(); ) { |
||||
UnsignedInt codepoint; |
||||
std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(text, i); |
||||
glyphs.push_back(FT_Get_Char_Index(font.font(), codepoint)); |
||||
} |
||||
} |
||||
|
||||
std::tuple<Rectangle, Rectangle, Vector2> FreeTypeLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { |
||||
/* Position of the texture in the resulting glyph, texture coordinates */ |
||||
Rectangle texturePosition, textureCoordinates; |
||||
std::tie(texturePosition, textureCoordinates) = font[glyphs[i]]; |
||||
|
||||
/* Load glyph */ |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(font.font(), glyphs[i], FT_LOAD_DEFAULT) == 0); |
||||
const FT_GlyphSlot slot = font.font()->glyph; |
||||
Vector2 offset = Vector2(0, 0); /** @todo really? */ |
||||
Vector2 advance = Vector2(slot->advance.x, slot->advance.y)/(64*font.size()); |
||||
|
||||
/* Absolute quad position, composed from cursor position, glyph offset
|
||||
and texture position, denormalized to requested text size */ |
||||
Rectangle quadPosition = Rectangle::fromSize( |
||||
(cursorPosition + offset + Vector2(texturePosition.left(), texturePosition.bottom()))*size, |
||||
texturePosition.size()*size); |
||||
|
||||
return std::make_tuple(quadPosition, textureCoordinates, advance); |
||||
} |
||||
|
||||
} |
||||
|
||||
}} |
||||
@ -1,178 +0,0 @@
|
||||
#ifndef Magnum_Text_FreeTypeFont_h |
||||
#define Magnum_Text_FreeTypeFont_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::Text::FreeTypeFontRenderer, Magnum::Text::FreeTypeFont |
||||
*/ |
||||
|
||||
#include <unordered_map> |
||||
|
||||
#include "Math/Geometry/Rectangle.h" |
||||
#include "Texture.h" |
||||
#include "Text/AbstractFont.h" |
||||
#include "Text/magnumTextVisibility.h" |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
struct FT_LibraryRec_; |
||||
typedef FT_LibraryRec_* FT_Library; |
||||
struct FT_FaceRec_; |
||||
typedef FT_FaceRec_* FT_Face; |
||||
#endif |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
/**
|
||||
@brief FreeType font renderer |
||||
|
||||
Contains global instance of font renderer. See FreeTypeFont class documentation |
||||
for more information. |
||||
*/ |
||||
class MAGNUM_TEXT_EXPORT FreeTypeFontRenderer { |
||||
public: |
||||
explicit FreeTypeFontRenderer(); |
||||
|
||||
~FreeTypeFontRenderer(); |
||||
|
||||
/** @brief FreeType library handle */ |
||||
inline FT_Library library() { return _library; } |
||||
|
||||
private: |
||||
FT_Library _library; |
||||
}; |
||||
|
||||
/**
|
||||
@brief FreeType font |
||||
|
||||
Contains font with characters prerendered into texture atlas. |
||||
|
||||
@section FreeTypeFont-usage Usage |
||||
|
||||
You need to maintain instance of FreeTypeFontRenderer during the lifetime of all FreeTypeFont |
||||
instances. The font can be created either from file or from memory location of |
||||
format supported by [FreeType](http://www.freetype.org/) library. Next step is
|
||||
to prerender all the glyphs which will be used in text rendering later. |
||||
@code |
||||
Text::FreeTypeFontRenderer fontRenderer; |
||||
|
||||
Text::FreeTypeFont font(fontRenderer, "MyFreeTypeFont.ttf", 48.0f); |
||||
font.prerender("abcdefghijklmnopqrstuvwxyz" |
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
||||
"0123456789 ", Vector2i(512)); |
||||
@endcode |
||||
See TextRenderer for information about text rendering. |
||||
|
||||
@section FreeTypeFont-extensions Required OpenGL functionality |
||||
|
||||
%Font texture uses one-component internal format, which requires |
||||
@extension{ARB,texture_rg} (also part of OpenGL ES 3.0 or available as |
||||
@es_extension{EXT,texture_rg} in ES 2.0). |
||||
*/ |
||||
class MAGNUM_TEXT_EXPORT FreeTypeFont: public AbstractFont { |
||||
public: |
||||
/**
|
||||
* @brief Create font from file |
||||
* @param renderer %Font renderer |
||||
* @param fontFile %Font file |
||||
* @param size %Font size |
||||
*/ |
||||
explicit FreeTypeFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size); |
||||
|
||||
/**
|
||||
* @brief Create font from memory |
||||
* @param renderer %Font renderer |
||||
* @param data %Font data |
||||
* @param dataSize %Font data size |
||||
* @param size %Font size |
||||
*/ |
||||
explicit FreeTypeFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size); |
||||
|
||||
/**
|
||||
* @brief Prerender given character set |
||||
* @param characters UTF-8 characters to render |
||||
* @param atlasSize Size of resulting atlas |
||||
* |
||||
* Creates new atlas with prerendered characters, replacing the |
||||
* previous one (if any). |
||||
* @attention @p atlasSize must be large enough to contain all |
||||
* rendered glyphs. |
||||
*/ |
||||
void prerender(const std::string& characters, const Vector2i& atlasSize); |
||||
|
||||
/**
|
||||
* @brief Prerender given character set for use with distance-field rendering |
||||
* @param characters UTF-8 characters to render |
||||
* @param sourceAtlasSize Size of distance field source atlas |
||||
* @param atlasSize Size of resulting atlas |
||||
* @param radius Max lookup radius for distance-field creation |
||||
* |
||||
* Creates new atlas with prerendered characters, replacing the |
||||
* previous one (if any). See TextureTools::distanceField() for more |
||||
* information. |
||||
* @attention @p sourceAtlasSize must be large enough to contain all |
||||
* rendered glyphs with padding given by @p radius. |
||||
*/ |
||||
void prerenderDistanceField(const std::string& characters, const Vector2i& sourceAtlasSize, const Vector2i& atlasSize, Int radius); |
||||
|
||||
~FreeTypeFont(); |
||||
|
||||
/** @brief %Font size */ |
||||
inline Float size() const { return _size; } |
||||
|
||||
/** @brief Count of prerendered glyphs in the font */ |
||||
inline std::size_t glyphCount() const { return glyphs.size(); } |
||||
|
||||
/**
|
||||
* @brief Position of given character in the texture |
||||
* @param character Unicode character code (UTF-32) |
||||
* |
||||
* First returned rectangle is texture position relative to point on |
||||
* baseline, second is position of the texture in texture atlas. |
||||
*/ |
||||
const std::tuple<Rectangle, Rectangle>& operator[](char32_t character) const; |
||||
|
||||
/** @brief FreeType font handle */ |
||||
inline FT_Face font() { return _ftFont; } |
||||
|
||||
AbstractLayouter* layout(const Float size, const std::string& text) override; |
||||
|
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
private: |
||||
#else |
||||
protected: |
||||
#endif |
||||
FT_Face _ftFont; |
||||
|
||||
private: |
||||
void MAGNUM_TEXT_LOCAL finishConstruction(); |
||||
void MAGNUM_TEXT_LOCAL prerenderInternal(const std::string& characters, const Vector2i& atlasSize, const Int radius, Texture2D* output); |
||||
|
||||
std::unordered_map<char32_t, std::tuple<Rectangle, Rectangle>> glyphs; |
||||
Float _size; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,91 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "GlyphCache.h" |
||||
|
||||
#include "Extensions.h" |
||||
#include "Image.h" |
||||
#include "TextureTools/Atlas.h" |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
namespace { |
||||
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES3) |
||||
const AbstractTexture::InternalFormat internalFormat = AbstractTexture::InternalFormat::R8; |
||||
#else |
||||
const AbstractTexture::InternalFormat internalFormat = AbstractTexture::InternalFormat::Red; |
||||
#endif |
||||
} |
||||
|
||||
GlyphCache::GlyphCache(const Vector2i& size): _size(size) { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); |
||||
#else |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_rg); |
||||
#endif |
||||
|
||||
initialize(internalFormat, size); |
||||
} |
||||
|
||||
GlyphCache::GlyphCache(const Vector2i& size, const AbstractTexture::InternalFormat internalFormat): _size(size) { |
||||
initialize(internalFormat, size); |
||||
} |
||||
|
||||
GlyphCache::GlyphCache(const Vector2i& size, const Vector2i& padding): _size(size), _padding(padding) {} |
||||
|
||||
GlyphCache::~GlyphCache() = default; |
||||
|
||||
/** @todo Delegating constructor when support for GCC 4.6 is dropped */ |
||||
void GlyphCache::initialize(const AbstractTexture::InternalFormat internalFormat, const Vector2i& size) { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_storage); |
||||
#else |
||||
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::EXT::texture_storage); |
||||
#endif |
||||
|
||||
_texture.setWrapping(Texture2D::Wrapping::ClampToEdge) |
||||
->setMinificationFilter(Texture2D::Filter::Linear) |
||||
->setMagnificationFilter(Texture2D::Filter::Linear) |
||||
->setStorage(1, internalFormat, size); |
||||
} |
||||
|
||||
std::vector<Rectanglei> GlyphCache::reserve(const std::vector<Vector2i>& sizes) { |
||||
CORRADE_ASSERT(glyphs.empty(), "Text::GlyphCache::reserve(): reserving space in non-empty cache is not yet implemented", {}); |
||||
glyphs.reserve(glyphs.size() + sizes.size()); |
||||
return TextureTools::atlas(_size, sizes, _padding); |
||||
} |
||||
|
||||
void GlyphCache::insert(const UnsignedInt glyph, Vector2i position, Rectanglei rectangle) { |
||||
position -= _padding; |
||||
rectangle.bottomLeft() -= _padding; |
||||
rectangle.topRight() += _padding; |
||||
|
||||
glyphs.insert({glyph, {position, rectangle}}); |
||||
} |
||||
|
||||
void GlyphCache::setImage(const Vector2i& offset, Image2D* const image) { |
||||
_texture.setSubImage(0, offset, image); |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,157 @@
|
||||
#ifndef Magnum_Text_GlyphCache_h |
||||
#define Magnum_Text_GlyphCache_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::Text::GlyphCache |
||||
*/ |
||||
|
||||
#include <unordered_map> |
||||
|
||||
#include "Math/Geometry/Rectangle.h" |
||||
#include "Texture.h" |
||||
#include "Text/magnumTextVisibility.h" |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
/**
|
||||
@brief Glyph cache |
||||
|
||||
Contains font glyphs prerendered into texture atlas. |
||||
|
||||
@section GlyphCache-usage Usage |
||||
|
||||
Create %GlyphCache object with sufficient size and then call |
||||
AbstractFont::createGlyphCache() to fill it with glyphs. |
||||
@code |
||||
Text::AbstractFont* font; |
||||
Text::GlyphCache* cache = new GlyphCache(Vector2i(512)); |
||||
font->createGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz" |
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
||||
"0123456789 "); |
||||
@endcode |
||||
|
||||
See TextRenderer for information about text rendering. |
||||
*/ |
||||
class MAGNUM_TEXT_EXPORT GlyphCache { |
||||
public: |
||||
/**
|
||||
* @brief Constructor |
||||
* @param size Glyph cache texture size |
||||
* @param internalFormat Internal texture format |
||||
*/ |
||||
explicit GlyphCache(const Vector2i& size, const Texture2D::InternalFormat internalFormat); |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param size Glyph cache texture size |
||||
* |
||||
* Sets internal texture format to red channel only. Requires |
||||
* @extension{ARB,texture_rg} (also part of OpenGL ES 3.0 or available |
||||
* as @es_extension{EXT,texture_rg} in ES 2.0). |
||||
*/ |
||||
explicit GlyphCache(const Vector2i& size); |
||||
|
||||
virtual ~GlyphCache(); |
||||
|
||||
/**
|
||||
* @brief Cache size |
||||
* |
||||
* Size of unscaled glyph cache texture. |
||||
*/ |
||||
inline Vector2i textureSize() const { return _size; } |
||||
|
||||
/** @brief Count of glyphs in the cache */ |
||||
inline std::size_t glyphCount() const { return glyphs.size(); } |
||||
|
||||
/** @brief Cache texture */ |
||||
inline Texture2D* texture() { return &_texture; } |
||||
|
||||
/**
|
||||
* @brief Parameters of given glyph |
||||
* @param glyph Glyph ID |
||||
* |
||||
* First tuple element is glyph position relative to point on baseline, |
||||
* second element is glyph region in texture atlas. If no glyph is |
||||
* found, glyph on zero index is returned. |
||||
*/ |
||||
inline std::pair<Vector2i, Rectanglei> operator[](const UnsignedInt glyph) const { |
||||
auto it = glyphs.find(glyph); |
||||
return it == glyphs.end() ? glyphs.at(0) : it->second; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Layout glyphs with given sizes to the cache |
||||
* |
||||
* Returns non-overlapping regions in cache texture to store glyphs. |
||||
* The reserved space is reused on next call to reserve() if no glyph |
||||
* was stored there, use insert() to store actual glyph on given |
||||
* position and setImage() to upload glyph image. |
||||
* |
||||
* @attention Cache size must be large enough to contain all rendered |
||||
* glyphs. |
||||
*/ |
||||
std::vector<Rectanglei> reserve(const std::vector<Vector2i>& sizes); |
||||
|
||||
/**
|
||||
* @brief Insert glyph to cache |
||||
* @param glyph Glyph ID |
||||
* @param position Position relative to point on baseline |
||||
* @param rectangle Region in texture atlas |
||||
* |
||||
* You can obtain unused non-overlapping regions with reserve(). See |
||||
* also setImage() to upload glyph image. |
||||
*/ |
||||
void insert(const UnsignedInt glyph, Vector2i position, Rectanglei rectangle); |
||||
|
||||
/**
|
||||
* @brief Set cache image |
||||
* |
||||
* Uploads image for one or more glyphs to given offset in cache |
||||
* texture. |
||||
*/ |
||||
virtual void setImage(const Vector2i& offset, Image2D* const image); |
||||
|
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
private: |
||||
#else |
||||
protected: |
||||
#endif |
||||
/* Used from DistanceFieldGlyphCache */ |
||||
explicit MAGNUM_LOCAL GlyphCache(const Vector2i& size, const Vector2i& padding); |
||||
|
||||
void MAGNUM_LOCAL initialize(const Texture2D::InternalFormat internalFormat, const Vector2i& size); |
||||
|
||||
const Vector2i _size; |
||||
Texture2D _texture; |
||||
|
||||
private: |
||||
const Vector2i _padding; |
||||
std::unordered_map<UnsignedInt, std::pair<Vector2i, Rectanglei>> glyphs; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -1,115 +0,0 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "HarfBuzzFont.h" |
||||
|
||||
#include <hb-ft.h> |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
namespace { |
||||
|
||||
class HarfBuzzLayouter: public AbstractLayouter { |
||||
public: |
||||
HarfBuzzLayouter(HarfBuzzFont& font, const Float size, const std::string& text); |
||||
~HarfBuzzLayouter(); |
||||
|
||||
std::tuple<Rectangle, Rectangle, Vector2> renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) override; |
||||
|
||||
private: |
||||
const HarfBuzzFont& font; |
||||
hb_buffer_t* buffer; |
||||
hb_glyph_info_t* glyphInfo; |
||||
hb_glyph_position_t* glyphPositions; |
||||
const Float size; |
||||
}; |
||||
|
||||
} |
||||
|
||||
HarfBuzzFont::HarfBuzzFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size): FreeTypeFont(renderer, fontFile, size) { |
||||
finishConstruction(); |
||||
} |
||||
|
||||
HarfBuzzFont::HarfBuzzFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size): FreeTypeFont(renderer, data, dataSize, size) { |
||||
finishConstruction(); |
||||
} |
||||
|
||||
void HarfBuzzFont::finishConstruction() { |
||||
/* Create Harfbuzz font */ |
||||
_hbFont = hb_ft_font_create(_ftFont, nullptr); |
||||
} |
||||
|
||||
HarfBuzzFont::~HarfBuzzFont() { |
||||
hb_font_destroy(_hbFont); |
||||
} |
||||
|
||||
AbstractLayouter* HarfBuzzFont::layout(const Float size, const std::string& text) { |
||||
return new HarfBuzzLayouter(*this, size, text); |
||||
} |
||||
|
||||
namespace { |
||||
|
||||
HarfBuzzLayouter::HarfBuzzLayouter(HarfBuzzFont& font, const Float size, const std::string& text): font(font), size(size) { |
||||
/* Prepare HarfBuzz buffer */ |
||||
buffer = hb_buffer_create(); |
||||
hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); |
||||
hb_buffer_set_script(buffer, HB_SCRIPT_LATIN); |
||||
hb_buffer_set_language(buffer, hb_language_from_string("en", 2)); |
||||
|
||||
/* Layout the text */ |
||||
hb_buffer_add_utf8(buffer, text.c_str(), -1, 0, -1); |
||||
hb_shape(font.font(), buffer, nullptr, 0); |
||||
|
||||
glyphInfo = hb_buffer_get_glyph_infos(buffer, &_glyphCount); |
||||
glyphPositions = hb_buffer_get_glyph_positions(buffer, &_glyphCount); |
||||
} |
||||
|
||||
HarfBuzzLayouter::~HarfBuzzLayouter() { |
||||
/* Destroy HarfBuzz buffer */ |
||||
hb_buffer_destroy(buffer); |
||||
} |
||||
|
||||
std::tuple<Rectangle, Rectangle, Vector2> HarfBuzzLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { |
||||
/* Position of the texture in the resulting glyph, texture coordinates */ |
||||
Rectangle texturePosition, textureCoordinates; |
||||
std::tie(texturePosition, textureCoordinates) = font[glyphInfo[i].codepoint]; |
||||
|
||||
/* Glyph offset and advance to next glyph in normalized coordinates */ |
||||
Vector2 offset = Vector2(glyphPositions[i].x_offset, |
||||
glyphPositions[i].y_offset)/(64*font.size()); |
||||
Vector2 advance = Vector2(glyphPositions[i].x_advance, |
||||
glyphPositions[i].y_advance)/(64*font.size()); |
||||
|
||||
/* Absolute quad position, composed from cursor position, glyph offset
|
||||
and texture position, denormalized to requested text size */ |
||||
Rectangle quadPosition = Rectangle::fromSize( |
||||
(cursorPosition + offset + Vector2(texturePosition.left(), texturePosition.bottom()))*size, |
||||
texturePosition.size()*size); |
||||
|
||||
return std::make_tuple(quadPosition, textureCoordinates, advance); |
||||
} |
||||
|
||||
} |
||||
|
||||
}} |
||||
@ -1,84 +0,0 @@
|
||||
#ifndef Magnum_Text_HarfBuzzFont_h |
||||
#define Magnum_Text_HarfBuzzFont_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::Text::HarfBuzzFont |
||||
*/ |
||||
|
||||
#include "Text/FreeTypeFont.h" |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
struct hb_font_t; |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_USE_HARFBUZZ |
||||
#error Magnum is not compiled with HarfBuzz support |
||||
#endif |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
/**
|
||||
@brief HarfBuzz font |
||||
|
||||
Improves FreeTypeFont with [HarfBuzz](http://www.freedesktop.org/wiki/Software/HarfBuzz)
|
||||
text layouting capabilities, such as kerning, ligatures etc. See FreeTypeFont |
||||
class documentation for more information about usage. |
||||
*/ |
||||
class MAGNUM_TEXT_EXPORT HarfBuzzFont: public FreeTypeFont { |
||||
public: |
||||
/**
|
||||
* @brief Create font from file |
||||
* @param renderer %Font renderer |
||||
* @param fontFile %Font file |
||||
* @param size %Font size |
||||
*/ |
||||
explicit HarfBuzzFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size); |
||||
|
||||
/**
|
||||
* @brief Create font from memory |
||||
* @param renderer %Font renderer |
||||
* @param data %Font data |
||||
* @param dataSize %Font data size |
||||
* @param size %Font size |
||||
*/ |
||||
explicit HarfBuzzFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size); |
||||
|
||||
~HarfBuzzFont(); |
||||
|
||||
/** @brief HarfBuzz font handle */ |
||||
inline hb_font_t* font() { return _hbFont; } |
||||
|
||||
AbstractLayouter* layout(const Float size, const std::string& text) override; |
||||
|
||||
private: |
||||
void MAGNUM_TEXT_LOCAL finishConstruction(); |
||||
|
||||
hb_font_t* _hbFont; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,56 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractImageConverter.h" |
||||
|
||||
#include <Utility/Assert.h> |
||||
|
||||
namespace Magnum { namespace Trade { |
||||
|
||||
AbstractImageConverter::AbstractImageConverter() = default; |
||||
|
||||
AbstractImageConverter::AbstractImageConverter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractPlugin(manager, std::move(plugin)) {} |
||||
|
||||
Image2D* AbstractImageConverter::convertToImage(const Image2D* const) const { |
||||
CORRADE_ASSERT(features() & Feature::ConvertToImage, |
||||
"Trade::AbstractImageConverter::convertToImage(): feature advertised but not implemented", nullptr); |
||||
|
||||
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::convertToImage(): feature not implemented", nullptr); |
||||
} |
||||
|
||||
std::pair<const unsigned char*, std::size_t> AbstractImageConverter::convertToData(const Image2D* const) const { |
||||
CORRADE_ASSERT(features() & Feature::ConvertToData, |
||||
"Trade::AbstractImageConverter::convertToData(): feature advertised but not implemented", std::make_pair(nullptr, 0)); |
||||
|
||||
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::convertToData(): feature not implemented", std::make_pair(nullptr, 0)); |
||||
} |
||||
|
||||
bool AbstractImageConverter::convertToFile(const Image2D* const, const std::string&) const { |
||||
CORRADE_ASSERT(features() & Feature::ConvertToFile, |
||||
"Trade::AbstractImageConverter::convertToFile(): feature advertised but not implemented", false); |
||||
|
||||
CORRADE_ASSERT(false, "Trade::AbstractImageConverter::convertToFile(): feature not implemented", false); |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,119 @@
|
||||
#ifndef Magnum_Trade_AbstractImageConverter_h |
||||
#define Magnum_Trade_AbstractImageConverter_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::Trade::AbstractImageConverter |
||||
*/ |
||||
|
||||
#include <PluginManager/AbstractPlugin.h> |
||||
|
||||
#include "Magnum.h" |
||||
#include "Text/Text.h" |
||||
#include "magnumVisibility.h" |
||||
|
||||
namespace Magnum { namespace Trade { |
||||
|
||||
/**
|
||||
@brief Base for image converter plugins |
||||
|
||||
Provides functionality for converting images between various internal formats |
||||
or compressing them. |
||||
|
||||
@section AbstractImageConverter-subclassing Subclassing |
||||
|
||||
Plugin implements function features() and one or more of convertToImage(), |
||||
convertToData() or convertToFile() functions based on what features are |
||||
supported. |
||||
*/ |
||||
class MAGNUM_EXPORT AbstractImageConverter: public Corrade::PluginManager::AbstractPlugin { |
||||
PLUGIN_INTERFACE("cz.mosra.magnum.Trade.AbstractImageConverter/0.1") |
||||
|
||||
public: |
||||
/**
|
||||
* @brief Features supported by this converter |
||||
* |
||||
* @see Features, features() |
||||
*/ |
||||
enum class Feature: UnsignedByte { |
||||
/** Converting to image with different format with convertToImage() */ |
||||
ConvertToImage = 1 << 0, |
||||
|
||||
/** Converting to data with convertToData() */ |
||||
ConvertToData = 1 << 1, |
||||
|
||||
/** Converting to file with convertToFile() */ |
||||
ConvertToFile = 1 << 2 |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Features supported by this converter |
||||
* |
||||
* @see features() |
||||
*/ |
||||
typedef Corrade::Containers::EnumSet<Feature, UnsignedByte> Features; |
||||
|
||||
/** @brief Default constructor */ |
||||
explicit AbstractImageConverter(); |
||||
|
||||
/** @brief Plugin manager constructor */ |
||||
explicit AbstractImageConverter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin); |
||||
|
||||
/** @brief Features supported by this converter */ |
||||
virtual Features features() const = 0; |
||||
|
||||
/**
|
||||
* @brief Convert image to different format |
||||
* |
||||
* Available only if @ref Feature "Feature::ConvertToImage" is supported. |
||||
* Returns converted image on success, `nullptr` otherwise. |
||||
* @see features(), convertToData(), convertToFile() |
||||
*/ |
||||
virtual Image2D* convertToImage(const Image2D* const image) const; |
||||
|
||||
/**
|
||||
* @brief Convert image to raw data |
||||
* |
||||
* Available only if @ref Feature "Feature::ConvertToData" is supported. |
||||
* Returns data pointer and size on success, `nullptr` otherwise. |
||||
* @see features(), convertToImage(), convertToFile() |
||||
*/ |
||||
virtual std::pair<const unsigned char*, std::size_t> convertToData(const Image2D* const image) const; |
||||
|
||||
/**
|
||||
* @brief Convert image and save it to file |
||||
* |
||||
* Available only if @ref Feature "Feature::ConvertToFile" is supported. |
||||
* Returns `true` on success, `false` otherwise. |
||||
* @see features(), convertToImage(), convertToData() |
||||
*/ |
||||
virtual bool convertToFile(const Image2D* const image, const std::string& filename) const; |
||||
}; |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(AbstractImageConverter::Features) |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractMaterialData.h" |
||||
|
||||
namespace Magnum { namespace Trade { |
||||
|
||||
AbstractMaterialData::AbstractMaterialData(AbstractMaterialData::Type type): _type(type) {} |
||||
|
||||
AbstractMaterialData::~AbstractMaterialData() {} |
||||
|
||||
}} |
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "MeshObjectData2D.h" |
||||
|
||||
namespace Magnum { namespace Trade { |
||||
|
||||
MeshObjectData2D::MeshObjectData2D(std::vector<UnsignedInt> children, const Matrix3& transformation, UnsignedInt instance, UnsignedInt material): ObjectData2D(std::move(children), transformation, InstanceType::Mesh, instance), _material(material) {} |
||||
|
||||
}} |
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "MeshObjectData3D.h" |
||||
|
||||
namespace Magnum { namespace Trade { |
||||
|
||||
MeshObjectData3D::MeshObjectData3D(std::vector< UnsignedInt > children, const Matrix4& transformation, UnsignedInt instance, UnsignedInt material): ObjectData3D(children, transformation, InstanceType::Mesh, instance), _material(material) {} |
||||
|
||||
}} |
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "PhongMaterialData.h" |
||||
|
||||
namespace Magnum { namespace Trade { |
||||
|
||||
PhongMaterialData::PhongMaterialData(const Vector3& ambientColor, const Vector3& diffuseColor, const Vector3& specularColor, Float shininess): AbstractMaterialData(Phong), _ambientColor(ambientColor), _diffuseColor(diffuseColor), _specularColor(specularColor), _shininess(shininess) {} |
||||
|
||||
}} |
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "SceneData.h" |
||||
|
||||
namespace Magnum { namespace Trade { |
||||
|
||||
SceneData::SceneData(std::vector<UnsignedInt> children2D, std::vector<UnsignedInt> children3D): _children2D(std::move(children2D)), _children3D(std::move(children3D)) {} |
||||
|
||||
}} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue