Browse Source

Shaders: remove the AbstractVector base.

167 additions, 341 deletions. I think that speaks for itself about
benefits of this base class.
pull/518/head
Vladimír Vondruš 5 years ago
parent
commit
47e7de47c8
  1. 28
      doc/changelog.dox
  2. 70
      src/Magnum/Shaders/AbstractVector.h
  3. 43
      src/Magnum/Shaders/AbstractVectorGL.cpp
  4. 134
      src/Magnum/Shaders/AbstractVectorGL.h
  5. 3
      src/Magnum/Shaders/CMakeLists.txt
  6. 1
      src/Magnum/Shaders/DistanceFieldVector.frag
  7. 47
      src/Magnum/Shaders/DistanceFieldVectorGL.cpp
  8. 70
      src/Magnum/Shaders/DistanceFieldVectorGL.h
  9. 9
      src/Magnum/Shaders/Shaders.h
  10. 1
      src/Magnum/Shaders/Vector.frag
  11. 0
      src/Magnum/Shaders/Vector.vert
  12. 38
      src/Magnum/Shaders/VectorGL.cpp
  13. 60
      src/Magnum/Shaders/VectorGL.h
  14. 6
      src/Magnum/Shaders/resources-gl.conf
  15. 13
      src/Magnum/Text/Renderer.cpp
  16. 7
      src/Magnum/Text/Renderer.h

28
doc/changelog.dox

@ -462,19 +462,17 @@ See also:
@ref DebugTools::FrameProfilerGL. The new name plays better with IDE
autocompletion and makes the GL-specific class appear next to the
API-independent base in alphabetically sorted lists.
- @cpp Shaders::AbstractVector @ce, @cpp Shaders::DistanceFieldVector @ce,
@cpp Shaders::Flat @ce, @cpp Shaders::Generic @ce,
@cpp Shaders::MeshVisualizer2D @ce, @cpp Shaders::MeshVisualizer3D @ce,
@cpp Shaders::Phong @ce, @cpp Shaders::Vector @ce,
@cpp Shaders::VertexColor @ce and related 2D/3D typedefs are deprecated in
favor of @ref Shaders::AbstractVectorGL,
@ref Shaders::DistanceFieldVectorGL, @ref Shaders::FlatGL,
@ref Shaders::GenericGL, @ref Shaders::MeshVisualizerGL2D,
@ref Shaders::MeshVisualizerGL3D, @ref Shaders::PhongGL,
@ref Shaders::VectorGL, @ref Shaders::VertexColorGL and correspondingly
renamed typedefs to make room for Vulkan shaders and functionality shared
between OpenGL and Vulkan implementation such as uniform buffer layout
definitions
- @cpp Shaders::DistanceFieldVector @ce, @cpp Shaders::Flat @ce,
@cpp Shaders::Generic @ce, @cpp Shaders::MeshVisualizer2D @ce,
@cpp Shaders::MeshVisualizer3D @ce, @cpp Shaders::Phong @ce,
@cpp Shaders::Vector @ce, @cpp Shaders::VertexColor @ce and related 2D/3D
typedefs are deprecated in favor of @ref Shaders::DistanceFieldVectorGL,
@ref Shaders::FlatGL, @ref Shaders::GenericGL,
@ref Shaders::MeshVisualizerGL2D, @ref Shaders::MeshVisualizerGL3D,
@ref Shaders::PhongGL, @ref Shaders::VectorGL, @ref Shaders::VertexColorGL
and correspondingly renamed typedefs to make room for Vulkan shaders and
functionality shared between OpenGL and Vulkan implementation such as
uniform buffer layout definitions
- @ref Shaders::PhongGL::setLightPositions() and
@ref Shaders::PhongGL::setLightPosition() taking three-component vectors
are deprecated in favor of variants taking four-component vectors, where the
@ -658,6 +656,10 @@ See also:
isn't available anymore. For backwards compatibility, light positions
supplied through three-component vectors are now represented as directional
lights, which is close, but not exactly the same as before.
- The @cpp Shaders::AbstractVector @ce base class for @ref Shaders::VectorGL
and @ref Shaders::DistanceFieldVectorGL is removed, as its benefits were
rather questionable --- on the contrary, it made subclass implementation
more verbose and less clear
- Mutable access to @ref Trade::PhongMaterialData color and texture
information, deprecated in 2020.06, is now removed, as it's impossible to
implement through the redesigned @ref Trade::MaterialData APIs. However

70
src/Magnum/Shaders/AbstractVector.h

@ -1,70 +0,0 @@
#ifndef Magnum_Shaders_AbstractVector_h
#define Magnum_Shaders_AbstractVector_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021 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.
*/
#ifdef MAGNUM_BUILD_DEPRECATED
/** @file
* @brief Typedef @ref Magnum::Shaders::AbstractVector, alias @ref Magnum::Shaders::AbstractVector2D, @ref Magnum::Shaders::AbstractVector3D
* @m_deprecated_since_latest Use @ref Magnum/Shaders/AbstractVectorGL.h, the
* @ref Magnum::Shaders::AbstractVectorGL "AbstractVectorGL" class and
* related typedefs instead.
*/
#endif
#include "Magnum/configure.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#include "Magnum/Shaders/AbstractVectorGL.h"
CORRADE_DEPRECATED_FILE("use Magnum/Shaders/AbstractVectorGL.h, the AbstractVectorGL class and related typedefs instead")
namespace Magnum { namespace Shaders {
/** @brief @copybrief AbstractVectorGL
* @m_deprecated_since_latest Use @ref AbstractVectorGL instead.
*/
#ifndef CORRADE_MSVC2015_COMPATIBILITY /* Multiple definitions still broken */
template<UnsignedInt dimensions> using AbstractVector CORRADE_DEPRECATED_ALIAS("use AbstractVectorGL instead") = AbstractVectorGL<dimensions>;
#endif
/** @brief @copybrief AbstractVectorGL2D
* @m_deprecated_since_latest Use @ref AbstractVectorGL2D instead.
*/
typedef CORRADE_DEPRECATED("use AbstractVectorGL2D instead") AbstractVectorGL2D AbstractVector2D;
/** @brief @copybrief AbstractVectorGL3D
* @m_deprecated_since_latest Use @ref AbstractVectorGL3D instead.
*/
typedef CORRADE_DEPRECATED("use AbstractVectorGL3D instead") AbstractVectorGL3D AbstractVector3D;
}}
#else
#error use Magnum/Shaders/AbstractVectorGL.h, the AbstractVectorGL class and related typedefs instead
#endif
#endif

43
src/Magnum/Shaders/AbstractVectorGL.cpp

@ -1,43 +0,0 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021 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 "AbstractVectorGL.h"
#include "Magnum/GL/Texture.h"
#include "Magnum/Shaders/visibility.h"
namespace Magnum { namespace Shaders {
template<UnsignedInt dimensions> AbstractVectorGL<dimensions>& AbstractVectorGL<dimensions>::bindVectorTexture(GL::Texture2D& texture) {
texture.bind(VectorTextureUnit);
return *this;
}
#ifndef DOXYGEN_GENERATING_OUTPUT
template class MAGNUM_SHADERS_EXPORT AbstractVectorGL<2>;
template class MAGNUM_SHADERS_EXPORT AbstractVectorGL<3>;
#endif
}}

134
src/Magnum/Shaders/AbstractVectorGL.h

@ -1,134 +0,0 @@
#ifndef Magnum_Shaders_AbstractVectorGL_h
#define Magnum_Shaders_AbstractVectorGL_h
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021 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 @ref Magnum::Shaders::AbstractVectorGL, typedef @ref Magnum::Shaders::AbstractVectorGL2D, @ref Magnum::Shaders::AbstractVectorGL3D
* @m_since_latest
*/
#include "Magnum/GL/AbstractShaderProgram.h"
#include "Magnum/Shaders/GenericGL.h"
namespace Magnum { namespace Shaders {
/**
@brief Base for vector OpenGL shaders
@m_since_latest
See @ref DistanceFieldVectorGL and @ref VectorGL for more information.
@see @ref shaders, @ref AbstractVectorGL2D, @ref AbstractVectorGL3D
*/
template<UnsignedInt dimensions> class AbstractVectorGL: public GL::AbstractShaderProgram {
public:
/**
* @brief Vertex position
*
* @ref shaders-generic "Generic attribute",
* @ref Magnum::Vector2 "Vector2" in 2D, @ref Magnum::Vector3 "Vector3"
* in 3D.
*/
typedef typename GenericGL<dimensions>::Position Position;
/**
* @brief 2D texture coordinates
*
* @ref shaders-generic "Generic attribute",
* @ref Magnum::Vector2 "Vector2".
*/
typedef typename GenericGL<dimensions>::TextureCoordinates TextureCoordinates;
enum: UnsignedInt {
/**
* Color shader output. @ref shaders-generic "Generic output",
* present always. Expects three- or four-component floating-point
* or normalized buffer attachment.
*/
ColorOutput = GenericGL<dimensions>::ColorOutput
};
/** @brief Copying is not allowed */
AbstractVectorGL(const AbstractVectorGL<dimensions>&) = delete;
/** @brief Move constructor */
AbstractVectorGL(AbstractVectorGL<dimensions>&&) noexcept = default;
/** @brief Copying is not allowed */
AbstractVectorGL<dimensions>& operator=(const AbstractVectorGL<dimensions>&) = delete;
/** @brief Move assignment */
AbstractVectorGL<dimensions>& operator=(AbstractVectorGL<dimensions>&&) noexcept = default;
/** @{
* @name Texture binding
*/
/**
* @brief Bind vector texture
* @return Reference to self (for method chaining)
*
* @see @ref DistanceFieldVectorGL::Flag::TextureTransformation,
* @ref VectorGL::Flag::TextureTransformation,
* @ref DistanceFieldVectorGL::setTextureMatrix(),
* @ref VectorGL::setTextureMatrix()
*/
AbstractVectorGL<dimensions>& bindVectorTexture(GL::Texture2D& texture);
/**
* @}
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
protected:
#else
private:
#endif
/* Those textures are quite specific (and likely reused multiple times
per frame for e.g. text rendering, so put them in a specific slot.
Older iOS (and iOS WebGL) has only 8 texture units, so can't go
above that. Unit 7 is used by TextureTools::DistanceField. */
enum: Int { VectorTextureUnit = 6 };
explicit AbstractVectorGL(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {}
explicit AbstractVectorGL() = default;
~AbstractVectorGL() = default;
};
/**
@brief Base for two-dimensional vector OpenGL shaders
@m_since_latest
*/
typedef AbstractVectorGL<2> AbstractVectorGL2D;
/**
@brief Base for three-dimensional vector OpenGL shader
@m_since_latest
*/
typedef AbstractVectorGL<3> AbstractVectorGL3D;
}}
#endif

3
src/Magnum/Shaders/CMakeLists.txt

@ -31,7 +31,6 @@ corrade_add_resource(MagnumShaders_RESOURCES_GL resources-gl.conf)
set_target_properties(MagnumShaders_RESOURCES_GL-dependencies PROPERTIES FOLDER "Magnum/Shaders")
set(MagnumShaders_SRCS
AbstractVectorGL.cpp
VertexColorGL.cpp
${MagnumShaders_RESOURCES_GL})
@ -45,7 +44,6 @@ set(MagnumShaders_GracefulAssert_SRCS
set(MagnumShaders_HEADERS
DistanceFieldVectorGL.h
AbstractVectorGL.h
FlatGL.h
GenericGL.h
MeshVisualizerGL.h
@ -59,7 +57,6 @@ set(MagnumShaders_HEADERS
if(MAGNUM_BUILD_DEPRECATED)
list(APPEND MagnumShaders_HEADERS
DistanceFieldVector.h
AbstractVector.h
Flat.h
Generic.h
MeshVisualizer.h

1
src/Magnum/Shaders/DistanceFieldVector.frag

@ -66,7 +66,6 @@ uniform lowp float smoothness
/* Textures */
#ifdef EXPLICIT_BINDING
/* See AbstractVector.h for details about the ID */
layout(binding = 6)
#endif
uniform lowp sampler2D vectorTexture;

47
src/Magnum/Shaders/DistanceFieldVectorGL.cpp

@ -32,6 +32,7 @@
#include "Magnum/GL/Context.h"
#include "Magnum/GL/Extensions.h"
#include "Magnum/GL/Shader.h"
#include "Magnum/GL/Texture.h"
#include "Magnum/Math/Color.h"
#include "Magnum/Math/Matrix3.h"
#include "Magnum/Math/Matrix4.h"
@ -40,6 +41,10 @@
namespace Magnum { namespace Shaders {
namespace {
enum: Int { TextureUnit = 6 };
}
template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>::DistanceFieldVectorGL(const Flags flags): _flags{flags} {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
@ -62,13 +67,13 @@ template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>::DistanceFiel
vert.addSource(flags & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "")
.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n")
.addSource(rs.get("generic.glsl"))
.addSource(rs.get("AbstractVector.vert"));
.addSource(rs.get("Vector.vert"));
frag.addSource(rs.get("generic.glsl"))
.addSource(rs.get("DistanceFieldVector.frag"));
CORRADE_INTERNAL_ASSERT_OUTPUT(GL::Shader::compile({vert, frag}));
GL::AbstractShaderProgram::attachShaders({vert, frag});
attachShaders({vert, frag});
/* ES3 has this done in the shader directly */
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES2)
@ -76,32 +81,31 @@ template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>::DistanceFiel
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version))
#endif
{
GL::AbstractShaderProgram::bindAttributeLocation(AbstractVectorGL<dimensions>::Position::Location, "position");
GL::AbstractShaderProgram::bindAttributeLocation(AbstractVectorGL<dimensions>::TextureCoordinates::Location, "textureCoordinates");
bindAttributeLocation(Position::Location, "position");
bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates");
}
#endif
CORRADE_INTERNAL_ASSERT_OUTPUT(GL::AbstractShaderProgram::link());
CORRADE_INTERNAL_ASSERT_OUTPUT(link());
#ifndef MAGNUM_TARGET_GLES
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_uniform_location>(version))
#endif
{
_transformationProjectionMatrixUniform = GL::AbstractShaderProgram::uniformLocation("transformationProjectionMatrix");
_transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
if(flags & Flag::TextureTransformation)
_textureMatrixUniform = GL::AbstractShaderProgram::uniformLocation("textureMatrix");
_colorUniform = GL::AbstractShaderProgram::uniformLocation("color");
_outlineColorUniform = GL::AbstractShaderProgram::uniformLocation("outlineColor");
_outlineRangeUniform = GL::AbstractShaderProgram::uniformLocation("outlineRange");
_smoothnessUniform = GL::AbstractShaderProgram::uniformLocation("smoothness");
_textureMatrixUniform = uniformLocation("textureMatrix");
_colorUniform = uniformLocation("color");
_outlineColorUniform = uniformLocation("outlineColor");
_outlineRangeUniform = uniformLocation("outlineRange");
_smoothnessUniform = uniformLocation("smoothness");
}
#ifndef MAGNUM_TARGET_GLES
if(!context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(version))
#endif
{
GL::AbstractShaderProgram::setUniform(GL::AbstractShaderProgram::uniformLocation("vectorTexture"),
AbstractVectorGL<dimensions>::VectorTextureUnit);
setUniform(uniformLocation("vectorTexture"), TextureUnit);
}
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
@ -116,34 +120,39 @@ template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>::DistanceFiel
}
template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>& DistanceFieldVectorGL<dimensions>::setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) {
GL::AbstractShaderProgram::setUniform(_transformationProjectionMatrixUniform, matrix);
setUniform(_transformationProjectionMatrixUniform, matrix);
return *this;
}
template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>& DistanceFieldVectorGL<dimensions>::setTextureMatrix(const Matrix3& matrix) {
CORRADE_ASSERT(_flags & Flag::TextureTransformation,
"Shaders::DistanceFieldVectorGL::setTextureMatrix(): the shader was not created with texture transformation enabled", *this);
GL::AbstractShaderProgram::setUniform(_textureMatrixUniform, matrix);
setUniform(_textureMatrixUniform, matrix);
return *this;
}
template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>& DistanceFieldVectorGL<dimensions>::setColor(const Color4& color) {
GL::AbstractShaderProgram::setUniform(_colorUniform, color);
setUniform(_colorUniform, color);
return *this;
}
template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>& DistanceFieldVectorGL<dimensions>::setOutlineColor(const Color4& color) {
GL::AbstractShaderProgram::setUniform(_outlineColorUniform, color);
setUniform(_outlineColorUniform, color);
return *this;
}
template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>& DistanceFieldVectorGL<dimensions>::setOutlineRange(Float start, Float end) {
GL::AbstractShaderProgram::setUniform(_outlineRangeUniform, Vector2(start, end));
setUniform(_outlineRangeUniform, Vector2(start, end));
return *this;
}
template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>& DistanceFieldVectorGL<dimensions>::setSmoothness(Float value) {
GL::AbstractShaderProgram::setUniform(_smoothnessUniform, value);
setUniform(_smoothnessUniform, value);
return *this;
}
template<UnsignedInt dimensions> DistanceFieldVectorGL<dimensions>& DistanceFieldVectorGL<dimensions>::bindVectorTexture(GL::Texture2D& texture) {
texture.bind(TextureUnit);
return *this;
}

70
src/Magnum/Shaders/DistanceFieldVectorGL.h

@ -31,7 +31,8 @@
*/
#include "Magnum/DimensionTraits.h"
#include "Magnum/Shaders/AbstractVectorGL.h"
#include "Magnum/GL/AbstractShaderProgram.h"
#include "Magnum/Shaders/GenericGL.h"
#include "Magnum/Shaders/visibility.h"
namespace Magnum { namespace Shaders {
@ -48,9 +49,10 @@ namespace Implementation {
@m_since_latest
Renders vector graphics in a form of signed distance field. See
@ref TextureTools::DistanceField for more information. Note that the final
rendered outlook will greatly depend on radius of input distance field and
value passed to @ref setSmoothness(). You need to provide @ref Position and
@ref TextureTools::DistanceField for more information and @ref VectorGL for a
simpler variant of this shader. Note that the final rendered outlook will
greatly depend on radius of input distance field and value passed to
@ref setSmoothness(). You need to provide @ref Position and
@ref TextureCoordinates attributes in your triangle mesh and call at least
@ref bindVectorTexture(). By default, the shader renders the distance field
texture with a white color in an identity transformation, use
@ -79,8 +81,34 @@ Common rendering setup:
large zoom levels, make it optional as it might have negative performance
impact
*/
template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVectorGL: public AbstractVectorGL<dimensions> {
template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVectorGL: public GL::AbstractShaderProgram {
public:
/**
* @brief Vertex position
*
* @ref shaders-generic "Generic attribute",
* @ref Magnum::Vector2 "Vector2" in 2D, @ref Magnum::Vector3 "Vector3"
* in 3D.
*/
typedef typename GenericGL<dimensions>::Position Position;
/**
* @brief 2D texture coordinates
*
* @ref shaders-generic "Generic attribute",
* @ref Magnum::Vector2 "Vector2".
*/
typedef typename GenericGL<dimensions>::TextureCoordinates TextureCoordinates;
enum: UnsignedInt {
/**
* Color shader output. @ref shaders-generic "Generic output",
* present always. Expects three- or four-component floating-point
* or normalized buffer attachment.
*/
ColorOutput = GenericGL<dimensions>::ColorOutput
};
#ifdef DOXYGEN_GENERATING_OUTPUT
/**
* @brief Flag
@ -129,12 +157,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
* However note that this is a low-level and a potentially dangerous
* API, see the documentation of @ref NoCreate for alternatives.
*/
explicit DistanceFieldVectorGL(NoCreateT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: AbstractVectorGL<dimensions>{NoCreate}
#endif
{}
explicit DistanceFieldVectorGL(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {}
/** @brief Copying is not allowed */
DistanceFieldVectorGL(const DistanceFieldVectorGL<dimensions>&) = delete;
@ -226,13 +249,24 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVector
* @}
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
/* Overloads to remove WTF-factor from method chaining order */
DistanceFieldVectorGL<dimensions>& bindVectorTexture(GL::Texture2D& texture) {
AbstractVectorGL<dimensions>::bindVectorTexture(texture);
return *this;
}
#endif
/** @{
* @name Texture binding
*/
/**
* @brief Bind vector texture
* @return Reference to self (for method chaining)
*
* @see @ref DistanceFieldVectorGL::Flag::TextureTransformation,
* @ref VectorGL::Flag::TextureTransformation,
* @ref DistanceFieldVectorGL::setTextureMatrix(),
* @ref VectorGL::setTextureMatrix()
*/
DistanceFieldVectorGL<dimensions>& bindVectorTexture(GL::Texture2D& texture);
/**
* @}
*/
private:
/* Prevent accidentally calling irrelevant functions */

9
src/Magnum/Shaders/Shaders.h

@ -38,15 +38,6 @@
namespace Magnum { namespace Shaders {
#ifndef DOXYGEN_GENERATING_OUTPUT
template<UnsignedInt> class AbstractVectorGL;
typedef AbstractVectorGL<2> AbstractVectorGL2D;
typedef AbstractVectorGL<3> AbstractVectorGL3D;
#ifdef MAGNUM_BUILD_DEPRECATED
template<UnsignedInt dimensions> using AbstractVector CORRADE_DEPRECATED_ALIAS("use AbstractVectorGL instead") = AbstractVectorGL<dimensions>;
typedef CORRADE_DEPRECATED("use AbstractVectorGL2D instead") AbstractVectorGL2D AbstractVector2D;
typedef CORRADE_DEPRECATED("use AbstractVectorGL3D instead") AbstractVectorGL3D AbstractVector3D;
#endif
template<UnsignedInt> class DistanceFieldVectorGL;
typedef DistanceFieldVectorGL<2> DistanceFieldVectorGL2D;
typedef DistanceFieldVectorGL<3> DistanceFieldVectorGL3D;

1
src/Magnum/Shaders/Vector.frag

@ -46,7 +46,6 @@ uniform lowp vec4 color
;
#ifdef EXPLICIT_BINDING
/* See AbstractVector.h for details about the ID */
layout(binding = 6)
#endif
uniform lowp sampler2D vectorTexture;

0
src/Magnum/Shaders/AbstractVector.vert → src/Magnum/Shaders/Vector.vert

38
src/Magnum/Shaders/VectorGL.cpp

@ -32,6 +32,7 @@
#include "Magnum/GL/Context.h"
#include "Magnum/GL/Extensions.h"
#include "Magnum/GL/Shader.h"
#include "Magnum/GL/Texture.h"
#include "Magnum/Math/Color.h"
#include "Magnum/Math/Matrix3.h"
#include "Magnum/Math/Matrix4.h"
@ -40,6 +41,10 @@
namespace Magnum { namespace Shaders {
namespace {
enum: Int { TextureUnit = 6 };
}
template<UnsignedInt dimensions> VectorGL<dimensions>::VectorGL(const Flags flags): _flags{flags} {
#ifdef MAGNUM_BUILD_STATIC
/* Import resources on static build, if not already */
@ -62,13 +67,13 @@ template<UnsignedInt dimensions> VectorGL<dimensions>::VectorGL(const Flags flag
vert.addSource(flags & Flag::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "")
.addSource(dimensions == 2 ? "#define TWO_DIMENSIONS\n" : "#define THREE_DIMENSIONS\n")
.addSource(rs.get("generic.glsl"))
.addSource(rs.get("AbstractVector.vert"));
.addSource(rs.get("Vector.vert"));
frag.addSource(rs.get("generic.glsl"))
.addSource(rs.get("Vector.frag"));
CORRADE_INTERNAL_ASSERT_OUTPUT(GL::Shader::compile({vert, frag}));
GL::AbstractShaderProgram::attachShaders({vert, frag});
attachShaders({vert, frag});
/* ES3 has this done in the shader directly */
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES2)
@ -76,29 +81,29 @@ template<UnsignedInt dimensions> VectorGL<dimensions>::VectorGL(const Flags flag
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_attrib_location>(version))
#endif
{
GL::AbstractShaderProgram::bindAttributeLocation(AbstractVectorGL<dimensions>::Position::Location, "position");
GL::AbstractShaderProgram::bindAttributeLocation(AbstractVectorGL<dimensions>::TextureCoordinates::Location, "textureCoordinates");
bindAttributeLocation(Position::Location, "position");
bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates");
}
#endif
CORRADE_INTERNAL_ASSERT_OUTPUT(GL::AbstractShaderProgram::link());
CORRADE_INTERNAL_ASSERT_OUTPUT(link());
#ifndef MAGNUM_TARGET_GLES
if(!context.isExtensionSupported<GL::Extensions::ARB::explicit_uniform_location>(version))
#endif
{
_transformationProjectionMatrixUniform = GL::AbstractShaderProgram::uniformLocation("transformationProjectionMatrix");
_transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
if(flags & Flag::TextureTransformation)
_textureMatrixUniform = GL::AbstractShaderProgram::uniformLocation("textureMatrix");
_backgroundColorUniform = GL::AbstractShaderProgram::uniformLocation("backgroundColor");
_colorUniform = GL::AbstractShaderProgram::uniformLocation("color");
_textureMatrixUniform = uniformLocation("textureMatrix");
_backgroundColorUniform = uniformLocation("backgroundColor");
_colorUniform = uniformLocation("color");
}
#ifndef MAGNUM_TARGET_GLES
if(!context.isExtensionSupported<GL::Extensions::ARB::shading_language_420pack>(version))
#endif
{
GL::AbstractShaderProgram::setUniform(GL::AbstractShaderProgram::uniformLocation("vectorTexture"), AbstractVectorGL<dimensions>::VectorTextureUnit);
setUniform(uniformLocation("vectorTexture"), TextureUnit);
}
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
@ -111,24 +116,29 @@ template<UnsignedInt dimensions> VectorGL<dimensions>::VectorGL(const Flags flag
}
template<UnsignedInt dimensions> VectorGL<dimensions>& VectorGL<dimensions>::setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix) {
GL::AbstractShaderProgram::setUniform(_transformationProjectionMatrixUniform, matrix);
setUniform(_transformationProjectionMatrixUniform, matrix);
return *this;
}
template<UnsignedInt dimensions> VectorGL<dimensions>& VectorGL<dimensions>::setTextureMatrix(const Matrix3& matrix) {
CORRADE_ASSERT(_flags & Flag::TextureTransformation,
"Shaders::VectorGL::setTextureMatrix(): the shader was not created with texture transformation enabled", *this);
GL::AbstractShaderProgram::setUniform(_textureMatrixUniform, matrix);
setUniform(_textureMatrixUniform, matrix);
return *this;
}
template<UnsignedInt dimensions> VectorGL<dimensions>& VectorGL<dimensions>::setBackgroundColor(const Color4& color) {
GL::AbstractShaderProgram::setUniform(_backgroundColorUniform, color);
setUniform(_backgroundColorUniform, color);
return *this;
}
template<UnsignedInt dimensions> VectorGL<dimensions>& VectorGL<dimensions>::setColor(const Color4& color) {
GL::AbstractShaderProgram::setUniform(_colorUniform, color);
setUniform(_colorUniform, color);
return *this;
}
template<UnsignedInt dimensions> VectorGL<dimensions>& VectorGL<dimensions>::bindVectorTexture(GL::Texture2D& texture) {
texture.bind(TextureUnit);
return *this;
}

60
src/Magnum/Shaders/VectorGL.h

@ -31,7 +31,8 @@
*/
#include "Magnum/DimensionTraits.h"
#include "Magnum/Shaders/AbstractVectorGL.h"
#include "Magnum/GL/AbstractShaderProgram.h"
#include "Magnum/Shaders/GenericGL.h"
#include "Magnum/Shaders/visibility.h"
namespace Magnum { namespace Shaders {
@ -75,8 +76,34 @@ Common rendering setup:
@see @ref shaders, @ref VectorGL2D, @ref VectorGL3D
*/
template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VectorGL: public AbstractVectorGL<dimensions> {
template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VectorGL: public GL::AbstractShaderProgram {
public:
/**
* @brief Vertex position
*
* @ref shaders-generic "Generic attribute",
* @ref Magnum::Vector2 "Vector2" in 2D, @ref Magnum::Vector3 "Vector3"
* in 3D.
*/
typedef typename GenericGL<dimensions>::Position Position;
/**
* @brief 2D texture coordinates
*
* @ref shaders-generic "Generic attribute",
* @ref Magnum::Vector2 "Vector2".
*/
typedef typename GenericGL<dimensions>::TextureCoordinates TextureCoordinates;
enum: UnsignedInt {
/**
* Color shader output. @ref shaders-generic "Generic output",
* present always. Expects three- or four-component floating-point
* or normalized buffer attachment.
*/
ColorOutput = GenericGL<dimensions>::ColorOutput
};
#ifdef DOXYGEN_GENERATING_OUTPUT
/**
* @brief Flag
@ -125,12 +152,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VectorGL: public Ab
* However note that this is a low-level and a potentially dangerous
* API, see the documentation of @ref NoCreate for alternatives.
*/
explicit VectorGL(NoCreateT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: AbstractVectorGL<dimensions>{NoCreate}
#endif
{}
explicit VectorGL(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {}
/** @brief Copying is not allowed */
VectorGL(const VectorGL<dimensions>&) = delete;
@ -195,13 +217,21 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VectorGL: public Ab
* @}
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
/* Overloads to remove WTF-factor from method chaining order */
VectorGL<dimensions>& bindVectorTexture(GL::Texture2D& texture) {
AbstractVectorGL<dimensions>::bindVectorTexture(texture);
return *this;
}
#endif
/** @{
* @name Texture binding
*/
/**
* @brief Bind vector texture
* @return Reference to self (for method chaining)
*
* @see @ref Flag::TextureTransformation, @ref setTextureMatrix()s
*/
VectorGL<dimensions>& bindVectorTexture(GL::Texture2D& texture);
/**
* @}
*/
private:
/* Prevent accidentally calling irrelevant functions */

6
src/Magnum/Shaders/resources-gl.conf

@ -1,8 +1,5 @@
group=MagnumShadersGL
[file]
filename=AbstractVector.vert
[file]
filename=Flat.vert
@ -30,6 +27,9 @@ filename=Phong.vert
[file]
filename=Phong.frag
[file]
filename=Vector.vert
[file]
filename=Vector.frag

13
src/Magnum/Text/Renderer.cpp

@ -33,7 +33,7 @@
#include "Magnum/GL/Extensions.h"
#include "Magnum/GL/Mesh.h"
#include "Magnum/Math/Functions.h"
#include "Magnum/Shaders/AbstractVectorGL.h"
#include "Magnum/Shaders/GenericGL.h"
#include "Magnum/Text/AbstractFont.h"
#include "Magnum/Text/GlyphCache.h"
@ -255,9 +255,9 @@ template<UnsignedInt dimensions> std::tuple<GL::Mesh, Range2D> Renderer<dimensio
auto r = renderInternal(font, cache, size, text, vertexBuffer, indexBuffer, usage, alignment);
GL::Mesh& mesh = std::get<0>(r);
mesh.addVertexBuffer(vertexBuffer, 0,
typename Shaders::AbstractVectorGL<dimensions>::Position(
Shaders::AbstractVectorGL<dimensions>::Position::Components::Two),
typename Shaders::AbstractVectorGL<dimensions>::TextureCoordinates());
typename Shaders::GenericGL<dimensions>::Position(
Shaders::GenericGL<dimensions>::Position::Components::Two),
typename Shaders::GenericGL<dimensions>::TextureCoordinates());
return r;
}
@ -320,8 +320,9 @@ AbstractRenderer::~AbstractRenderer() = default;
template<UnsignedInt dimensions> Renderer<dimensions>::Renderer(AbstractFont& font, const GlyphCache& cache, const Float size, const Alignment alignment): AbstractRenderer(font, cache, size, alignment) {
/* Finalize mesh configuration */
_mesh.addVertexBuffer(_vertexBuffer, 0,
typename Shaders::AbstractVectorGL<dimensions>::Position(Shaders::AbstractVectorGL<dimensions>::Position::Components::Two),
typename Shaders::AbstractVectorGL<dimensions>::TextureCoordinates());
typename Shaders::GenericGL<dimensions>::Position(
Shaders::GenericGL<dimensions>::Position::Components::Two),
typename Shaders::GenericGL<dimensions>::TextureCoordinates());
}
void AbstractRenderer::reserve(const uint32_t glyphCount, const GL::BufferUsage vertexBufferUsage, const GL::BufferUsage indexBufferUsage) {

7
src/Magnum/Text/Renderer.h

@ -202,7 +202,7 @@ asynchronous buffer updates. There is no similar extension in WebGL, thus plain
(and slow) buffer updates are used there.
@see @ref Renderer2D, @ref Renderer3D, @ref AbstractFont,
@ref Shaders::AbstractVectorGL
@ref Shaders::VectorGL, @ref Shaders::DistanceFieldVectorGL
*/
template<UnsignedInt dimensions> class MAGNUM_TEXT_EXPORT Renderer: public AbstractRenderer {
public:
@ -217,8 +217,9 @@ template<UnsignedInt dimensions> class MAGNUM_TEXT_EXPORT Renderer: public Abstr
* @param usage Usage of vertex and index buffer
* @param alignment Text alignment
*
* Returns mesh prepared for use with @ref Shaders::AbstractVectorGL
* subclasses and rectangle spanning the rendered text.
* Returns mesh prepared for use with @ref Shaders::VectorGL or
* @ref Shaders::DistanceFieldVectorGL and rectangle spanning the
* rendered text.
*/
static std::tuple<GL::Mesh, Range2D> render(AbstractFont& font, const GlyphCache& cache, Float size, const std::string& text, GL::Buffer& vertexBuffer, GL::Buffer& indexBuffer, GL::BufferUsage usage, Alignment alignment = Alignment::LineLeft);

Loading…
Cancel
Save