mirror of https://github.com/mosra/magnum.git
Browse Source
To make room for Vulkan shaders. Also renaming the headers, of course everything is still aliased to the old names (and marked as deprecated).pull/518/head
74 changed files with 5821 additions and 5127 deletions
@ -0,0 +1,126 @@ |
|||||||
|
#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; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 |
||||||
@ -0,0 +1,275 @@ |
|||||||
|
#ifndef Magnum_Shaders_DistanceFieldVectorGL_h |
||||||
|
#define Magnum_Shaders_DistanceFieldVectorGL_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::DistanceFieldVectorGL, typedef @ref Magnum::Shaders::DistanceFieldVectorGL2D, @ref Magnum::Shaders::DistanceFieldVectorGL3D |
||||||
|
* @m_since_latest |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum/DimensionTraits.h" |
||||||
|
#include "Magnum/Shaders/AbstractVectorGL.h" |
||||||
|
#include "Magnum/Shaders/visibility.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Shaders { |
||||||
|
|
||||||
|
namespace Implementation { |
||||||
|
enum class DistanceFieldVectorGLFlag: UnsignedByte { |
||||||
|
TextureTransformation = 1 << 0 |
||||||
|
}; |
||||||
|
typedef Containers::EnumSet<DistanceFieldVectorGLFlag> DistanceFieldVectorGLFlags; |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Distance field vector OpenGL shader |
||||||
|
@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 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 |
||||||
|
@ref setTransformationProjectionMatrix(), @ref setColor() and others to |
||||||
|
configure the shader. |
||||||
|
|
||||||
|
Alpha / transparency is supported by the shader implicitly, but to have it |
||||||
|
working on the framebuffer, you need to enable |
||||||
|
@ref GL::Renderer::Feature::Blending and set up the blending function. See |
||||||
|
@ref GL::Renderer::setBlendFunction() for details. |
||||||
|
|
||||||
|
@image html shaders-distancefieldvector.png width=256px |
||||||
|
|
||||||
|
@section Shaders-DistanceFieldVectorGL-usage Example usage |
||||||
|
|
||||||
|
Common mesh setup: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp DistanceFieldVectorGL-usage1 |
||||||
|
|
||||||
|
Common rendering setup: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp DistanceFieldVectorGL-usage2 |
||||||
|
|
||||||
|
@see @ref shaders, @ref DistanceFieldVectorGL2D, @ref DistanceFieldVectorGL3D |
||||||
|
@todo Use fragment shader derivations to have proper smoothness in perspective/ |
||||||
|
large zoom levels, make it optional as it might have negative performance |
||||||
|
impact |
||||||
|
*/ |
||||||
|
template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT DistanceFieldVectorGL: public AbstractVectorGL<dimensions> { |
||||||
|
public: |
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
/**
|
||||||
|
* @brief Flag |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @see @ref Flags, @ref flags() |
||||||
|
*/ |
||||||
|
enum class Flag: UnsignedByte { |
||||||
|
/**
|
||||||
|
* Enable texture coordinate transformation. |
||||||
|
* @see @ref setTextureMatrix() |
||||||
|
* @m_since{2020,06} |
||||||
|
*/ |
||||||
|
TextureTransformation = 1 << 0 |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flags |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @see @ref flags() |
||||||
|
*/ |
||||||
|
typedef Containers::EnumSet<Flag> Flags; |
||||||
|
#else |
||||||
|
/* Done this way to be prepared for possible future diversion of 2D
|
||||||
|
and 3D flags (e.g. introducing 3D-specific features) */ |
||||||
|
typedef Implementation::DistanceFieldVectorGLFlag Flag; |
||||||
|
typedef Implementation::DistanceFieldVectorGLFlags Flags; |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param flags Flags |
||||||
|
*/ |
||||||
|
explicit DistanceFieldVectorGL(Flags flags = {}); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct without creating the underlying OpenGL object |
||||||
|
* |
||||||
|
* The constructed instance is equivalent to a moved-from state. Useful |
||||||
|
* in cases where you will overwrite the instance later anyway. Move |
||||||
|
* another object over it to make it useful. |
||||||
|
* |
||||||
|
* This function can be safely used for constructing (and later |
||||||
|
* destructing) objects even without any OpenGL context being active. |
||||||
|
* 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 |
||||||
|
{} |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
DistanceFieldVectorGL(const DistanceFieldVectorGL<dimensions>&) = delete; |
||||||
|
|
||||||
|
/** @brief Move constructor */ |
||||||
|
DistanceFieldVectorGL(DistanceFieldVectorGL<dimensions>&&) noexcept = default; |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
DistanceFieldVectorGL<dimensions>& operator=(const DistanceFieldVectorGL<dimensions>&) = delete; |
||||||
|
|
||||||
|
/** @brief Move assignment */ |
||||||
|
DistanceFieldVectorGL<dimensions>& operator=(DistanceFieldVectorGL<dimensions>&&) noexcept = default; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flags |
||||||
|
* @m_since{2020,06} |
||||||
|
*/ |
||||||
|
Flags flags() const { return _flags; } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set transformation and projection matrix |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Initial value is an identity matrix. |
||||||
|
*/ |
||||||
|
DistanceFieldVectorGL<dimensions>& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set texture coordinate transformation matrix |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* Expects that the shader was created with |
||||||
|
* @ref Flag::TextureTransformation enabled. Initial value is an |
||||||
|
* identity matrix. |
||||||
|
*/ |
||||||
|
DistanceFieldVectorGL<dimensions>& setTextureMatrix(const Matrix3& matrix); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set fill color |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Initial value is @cpp 0xffffffff_rgbaf @ce. |
||||||
|
* @see @ref setOutlineColor() |
||||||
|
*/ |
||||||
|
DistanceFieldVectorGL<dimensions>& setColor(const Color4& color); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set outline color |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Initial value is @cpp 0x00000000_rgbaf @ce and the outline is not |
||||||
|
* drawn --- see @ref setOutlineRange() for more information. |
||||||
|
* @see @ref setOutlineRange(), @ref setColor() |
||||||
|
*/ |
||||||
|
DistanceFieldVectorGL<dimensions>& setOutlineColor(const Color4& color); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set outline range |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* The @p start parameter describes where fill ends and possible |
||||||
|
* outline starts. Initial value is @cpp 0.5f @ce, larger values will |
||||||
|
* make the vector art look thinner, smaller will make it look thicker. |
||||||
|
* |
||||||
|
* The @p end parameter describes where outline ends. If set to value |
||||||
|
* larger than @p start the outline is not drawn. Initial value is |
||||||
|
* @cpp 1.0f @ce. |
||||||
|
* |
||||||
|
* @see @ref setOutlineColor() |
||||||
|
*/ |
||||||
|
DistanceFieldVectorGL<dimensions>& setOutlineRange(Float start, Float end); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set smoothness radius |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Larger values will make edges look less aliased (but blurry), |
||||||
|
* smaller values will make them look more crisp (but possibly |
||||||
|
* aliased). Initial value is @cpp 0.04f @ce. |
||||||
|
*/ |
||||||
|
DistanceFieldVectorGL<dimensions>& setSmoothness(Float value); |
||||||
|
|
||||||
|
#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 |
||||||
|
|
||||||
|
private: |
||||||
|
/* Prevent accidentally calling irrelevant functions */ |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
using GL::AbstractShaderProgram::drawTransformFeedback; |
||||||
|
#endif |
||||||
|
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |
||||||
|
using GL::AbstractShaderProgram::dispatchCompute; |
||||||
|
#endif |
||||||
|
|
||||||
|
Flags _flags; |
||||||
|
Int _transformationProjectionMatrixUniform{0}, |
||||||
|
_textureMatrixUniform{1}, |
||||||
|
_colorUniform{2}, |
||||||
|
_outlineColorUniform{3}, |
||||||
|
_outlineRangeUniform{4}, |
||||||
|
_smoothnessUniform{5}; |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Two-dimensional distance field vector OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
*/ |
||||||
|
typedef DistanceFieldVectorGL<2> DistanceFieldVectorGL2D; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Three-dimensional distance field vector OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
*/ |
||||||
|
typedef DistanceFieldVectorGL<3> DistanceFieldVectorGL3D; |
||||||
|
|
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
/** @debugoperatorclassenum{DistanceFieldVectorGL,DistanceFieldVectorGL::Flag} */ |
||||||
|
template<UnsignedInt dimensions> Debug& operator<<(Debug& debug, DistanceFieldVector<dimensions>::Flag value); |
||||||
|
|
||||||
|
/** @debugoperatorclassenum{DistanceFieldVectorGL,DistanceFieldVectorGL::Flags} */ |
||||||
|
template<UnsignedInt dimensions> Debug& operator<<(Debug& debug, DistanceFieldVector<dimensions>::Flags value); |
||||||
|
#else |
||||||
|
namespace Implementation { |
||||||
|
MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, DistanceFieldVectorGLFlag value); |
||||||
|
MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, DistanceFieldVectorGLFlags value); |
||||||
|
CORRADE_ENUMSET_OPERATORS(DistanceFieldVectorGLFlags) |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,539 @@ |
|||||||
|
#ifndef Magnum_Shaders_FlatGL_h |
||||||
|
#define Magnum_Shaders_FlatGL_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::FlatGL, typedef @ref Magnum::Shaders::FlatGL2D, @ref Magnum::Shaders::FlatGL3D |
||||||
|
* @m_since_latest |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum/DimensionTraits.h" |
||||||
|
#include "Magnum/GL/AbstractShaderProgram.h" |
||||||
|
#include "Magnum/Shaders/GenericGL.h" |
||||||
|
#include "Magnum/Shaders/visibility.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Shaders { |
||||||
|
|
||||||
|
namespace Implementation { |
||||||
|
enum class FlatGLFlag: UnsignedByte { |
||||||
|
Textured = 1 << 0, |
||||||
|
AlphaMask = 1 << 1, |
||||||
|
VertexColor = 1 << 2, |
||||||
|
TextureTransformation = 1 << 3, |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
ObjectId = 1 << 4, |
||||||
|
InstancedObjectId = (1 << 5)|ObjectId, |
||||||
|
#endif |
||||||
|
InstancedTransformation = 1 << 6, |
||||||
|
InstancedTextureOffset = (1 << 7)|TextureTransformation |
||||||
|
}; |
||||||
|
typedef Containers::EnumSet<FlatGLFlag> FlatGLFlags; |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Flat OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
|
||||||
|
Draws the whole mesh with given color or texture. For a colored mesh you need |
||||||
|
to provide the @ref Position attribute in your triangle mesh. By default, the |
||||||
|
shader renders the mesh with a white color in an identity transformation. |
||||||
|
Use @ref setTransformationProjectionMatrix(), @ref setColor() and others to |
||||||
|
configure the shader. |
||||||
|
|
||||||
|
@image html shaders-flat.png width=256px |
||||||
|
|
||||||
|
@section Shaders-FlatGL-colored Colored rendering |
||||||
|
|
||||||
|
Common mesh setup: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp FlatGL-usage-colored1 |
||||||
|
|
||||||
|
Common rendering setup: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp FlatGL-usage-colored2 |
||||||
|
|
||||||
|
@section Shaders-FlatGL-textured Textured rendering |
||||||
|
|
||||||
|
If you want to use a texture, you need to provide also the |
||||||
|
@ref TextureCoordinates attribute. Pass @ref Flag::Textured to the constructor |
||||||
|
and then at render time don't forget to bind also the texture via |
||||||
|
@ref bindTexture(). The texture is multipled by the color, which is by default |
||||||
|
set to @cpp 0xffffffff_rgbaf @ce. Common mesh setup: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp FlatGL-usage-textured1 |
||||||
|
|
||||||
|
Common rendering setup: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp FlatGL-usage-textured2 |
||||||
|
|
||||||
|
For coloring the texture based on intensity you can use the @ref VectorGL |
||||||
|
shader. The 3D version of this shader is equivalent to @ref PhongGL with zero |
||||||
|
lights, however this implementation is much simpler and thus likely also |
||||||
|
faster. See @ref Shaders-PhongGL-lights-zero "its documentation" for more |
||||||
|
information. Conversely, enabling @ref Flag::VertexColor and using a default |
||||||
|
color with no texturing makes this shader equivalent to @ref VertexColorGL. |
||||||
|
|
||||||
|
@section Shaders-FlatGL-alpha Alpha blending and masking |
||||||
|
|
||||||
|
Alpha / transparency is supported by the shader implicitly, but to have it |
||||||
|
working on the framebuffer, you need to enable |
||||||
|
@ref GL::Renderer::Feature::Blending and set up the blending function. See |
||||||
|
@ref GL::Renderer::setBlendFunction() for details. |
||||||
|
|
||||||
|
An alternative is to enable @ref Flag::AlphaMask and tune @ref setAlphaMask() |
||||||
|
for simple binary alpha-masked drawing that doesn't require depth sorting or |
||||||
|
blending enabled. Note that this feature is implemented using the GLSL |
||||||
|
@glsl discard @ce operation which is known to have considerable performance |
||||||
|
impact on some platforms. With proper depth sorting and blending you'll usually |
||||||
|
get much better performance and output quality. |
||||||
|
|
||||||
|
@section Shaders-FlatGL-object-id Object ID output |
||||||
|
|
||||||
|
The shader supports writing object ID to the framebuffer for object picking or |
||||||
|
other annotation purposes. Enable it using @ref Flag::ObjectId and set up an |
||||||
|
integer buffer attached to the @ref ObjectIdOutput attachment. Note that for |
||||||
|
portability you should use @ref GL::Framebuffer::clearColor() instead of |
||||||
|
@ref GL::Framebuffer::clear() as the former usually emits GL errors when called |
||||||
|
on framebuffers with integer attachments. |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp FlatGL-usage-object-id |
||||||
|
|
||||||
|
If you have a batch of meshes with different object IDs, enable |
||||||
|
@ref Flag::InstancedObjectId and supply per-vertex IDs to the @ref ObjectId |
||||||
|
attribute. The output will contain a sum of the per-vertex ID and ID coming |
||||||
|
from @ref setObjectId(). |
||||||
|
|
||||||
|
@requires_gles30 Object ID output requires integer buffer attachments, which |
||||||
|
are not available in OpenGL ES 2.0 or WebGL 1.0. |
||||||
|
|
||||||
|
@section Shaders-FlatGL-instancing Instanced rendering |
||||||
|
|
||||||
|
Enabling @ref Flag::InstancedTransformation will turn the shader into an |
||||||
|
instanced one. It'll take per-instance transformation from the |
||||||
|
@ref TransformationMatrix attribute, applying it before the matrix set by |
||||||
|
@ref setTransformationProjectionMatrix(). Besides that, @ref Flag::VertexColor |
||||||
|
(and the @ref Color3 / @ref Color4) attributes can work as both per-vertex and |
||||||
|
per-instance, and for texturing it's possible to have per-instance texture |
||||||
|
offset taken from @ref TextureOffset when @ref Flag::InstancedTextureOffset is |
||||||
|
enabled (similarly to transformation, applied before @ref setTextureMatrix()). |
||||||
|
The snippet below shows adding a buffer with per-instance transformation and |
||||||
|
color to a mesh: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp FlatGL-usage-instancing |
||||||
|
|
||||||
|
@requires_gl33 Extension @gl_extension{ARB,instanced_arrays} |
||||||
|
@requires_gles30 Extension @gl_extension{ANGLE,instanced_arrays}, |
||||||
|
@gl_extension{EXT,instanced_arrays} or @gl_extension{NV,instanced_arrays} |
||||||
|
in OpenGL ES 2.0. |
||||||
|
@requires_webgl20 Extension @webgl_extension{ANGLE,instanced_arrays} in WebGL |
||||||
|
1.0. |
||||||
|
|
||||||
|
@see @ref shaders, @ref FlatGL2D, @ref FlatGL3D |
||||||
|
*/ |
||||||
|
template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT FlatGL: 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". Used only if @ref Flag::Textured is |
||||||
|
* set. |
||||||
|
*/ |
||||||
|
typedef typename GenericGL<dimensions>::TextureCoordinates TextureCoordinates; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Three-component vertex color |
||||||
|
* @m_since{2019,10} |
||||||
|
* |
||||||
|
* @ref shaders-generic "Generic attribute", @ref Magnum::Color3. Use |
||||||
|
* either this or the @ref Color4 attribute. Used only if |
||||||
|
* @ref Flag::VertexColor is set. |
||||||
|
*/ |
||||||
|
typedef typename GenericGL<dimensions>::Color3 Color3; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Four-component vertex color |
||||||
|
* @m_since{2019,10} |
||||||
|
* |
||||||
|
* @ref shaders-generic "Generic attribute", @ref Magnum::Color4. Use |
||||||
|
* either this or the @ref Color3 attribute. Used only if |
||||||
|
* @ref Flag::VertexColor is set. |
||||||
|
*/ |
||||||
|
typedef typename GenericGL<dimensions>::Color4 Color4; |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
/**
|
||||||
|
* @brief (Instanced) object ID |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @ref shaders-generic "Generic attribute", @ref Magnum::UnsignedInt. |
||||||
|
* Used only if @ref Flag::InstancedObjectId is set. |
||||||
|
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4} |
||||||
|
* @requires_gles30 Object ID output requires integer support in |
||||||
|
* shaders, which is not available in OpenGL ES 2.0 or WebGL 1.0. |
||||||
|
*/ |
||||||
|
typedef typename GenericGL<dimensions>::ObjectId ObjectId; |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (Instanced) transformation matrix |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @ref shaders-generic "Generic attribute", @ref Magnum::Matrix3 in |
||||||
|
* 2D, @ref Magnum::Matrix4 in 3D. Used only if |
||||||
|
* @ref Flag::InstancedTransformation is set. |
||||||
|
* @requires_gl33 Extension @gl_extension{ARB,instanced_arrays} |
||||||
|
* @requires_gles30 Extension @gl_extension{ANGLE,instanced_arrays}, |
||||||
|
* @gl_extension{EXT,instanced_arrays} or |
||||||
|
* @gl_extension{NV,instanced_arrays} in OpenGL ES 2.0. |
||||||
|
* @requires_webgl20 Extension @webgl_extension{ANGLE,instanced_arrays} |
||||||
|
* in WebGL 1.0. |
||||||
|
*/ |
||||||
|
typedef typename GenericGL<dimensions>::TransformationMatrix TransformationMatrix; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (Instanced) texture offset |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @ref shaders-generic "Generic attribute", @ref Magnum::Vector2. Used |
||||||
|
* only if @ref Flag::InstancedTextureOffset is set. |
||||||
|
* @requires_gl33 Extension @gl_extension{ARB,instanced_arrays} |
||||||
|
* @requires_gles30 Extension @gl_extension{ANGLE,instanced_arrays}, |
||||||
|
* @gl_extension{EXT,instanced_arrays} or |
||||||
|
* @gl_extension{NV,instanced_arrays} in OpenGL ES 2.0. |
||||||
|
* @requires_webgl20 Extension @webgl_extension{ANGLE,instanced_arrays} |
||||||
|
* in WebGL 1.0. |
||||||
|
*/ |
||||||
|
typedef typename GenericGL<dimensions>::TextureOffset TextureOffset; |
||||||
|
|
||||||
|
enum: UnsignedInt { |
||||||
|
/**
|
||||||
|
* Color shader output. Present always, expects three- or |
||||||
|
* four-component floating-point or normalized buffer attachment. |
||||||
|
* @m_since{2019,10} |
||||||
|
*/ |
||||||
|
ColorOutput = GenericGL<dimensions>::ColorOutput, |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
/**
|
||||||
|
* Object ID shader output. @ref shaders-generic "Generic output", |
||||||
|
* present only if @ref Flag::ObjectId is set. Expects a |
||||||
|
* single-component unsigned integral attachment. Writes the value |
||||||
|
* set in @ref setObjectId() there, see |
||||||
|
* @ref Shaders-FlatGL-object-id for more information. |
||||||
|
* @requires_gl30 Extension @gl_extension{EXT,texture_integer} |
||||||
|
* @requires_gles30 Object ID output requires integer support in |
||||||
|
* shaders, which is not available in OpenGL ES 2.0 or WebGL |
||||||
|
* 1.0. |
||||||
|
* @m_since{2019,10} |
||||||
|
*/ |
||||||
|
ObjectIdOutput = GenericGL<dimensions>::ObjectIdOutput |
||||||
|
#endif |
||||||
|
}; |
||||||
|
|
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
/**
|
||||||
|
* @brief Flag |
||||||
|
* |
||||||
|
* @see @ref Flags, @ref flags() |
||||||
|
*/ |
||||||
|
enum class Flag: UnsignedByte { |
||||||
|
/**
|
||||||
|
* Multiply color with a texture. |
||||||
|
* @see @ref setColor(), @ref bindTexture() |
||||||
|
*/ |
||||||
|
Textured = 1 << 0, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable alpha masking. If the combined fragment color has an |
||||||
|
* alpha less than the value specified with @ref setAlphaMask(), |
||||||
|
* given fragment is discarded. |
||||||
|
* |
||||||
|
* This uses the @glsl discard @ce operation which is known to have |
||||||
|
* considerable performance impact on some platforms. While useful |
||||||
|
* for cheap alpha masking that doesn't require depth sorting, |
||||||
|
* with proper depth sorting and blending you'll usually get much |
||||||
|
* better performance and output quality. |
||||||
|
*/ |
||||||
|
AlphaMask = 1 << 1, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiply diffuse color with a vertex color. Requires either |
||||||
|
* the @ref Color3 or @ref Color4 attribute to be present. |
||||||
|
* @m_since{2019,10} |
||||||
|
*/ |
||||||
|
VertexColor = 1 << 2, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable texture coordinate transformation. If this flag is set, |
||||||
|
* the shader expects that @ref Flag::Textured is enabled as well. |
||||||
|
* @see @ref setTextureMatrix() |
||||||
|
* @m_since{2020,06} |
||||||
|
*/ |
||||||
|
TextureTransformation = 1 << 3, |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
/**
|
||||||
|
* Enable object ID output. See @ref Shaders-FlatGL-object-id for |
||||||
|
* more information. |
||||||
|
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4} |
||||||
|
* @requires_gles30 Object ID output requires integer support in |
||||||
|
* shaders, which is not available in OpenGL ES 2.0 or WebGL |
||||||
|
* 1.0. |
||||||
|
* @m_since{2019,10} |
||||||
|
*/ |
||||||
|
ObjectId = 1 << 4, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Instanced object ID. Retrieves a per-instance / per-vertex |
||||||
|
* object ID from the @ref ObjectId attribute, outputting a sum of |
||||||
|
* the per-vertex ID and ID coming from @ref setObjectId(). |
||||||
|
* Implicitly enables @ref Flag::ObjectId. See |
||||||
|
* @ref Shaders-FlatGL-object-id for more information. |
||||||
|
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4} |
||||||
|
* @requires_gles30 Object ID output requires integer support in |
||||||
|
* shaders, which is not available in OpenGL ES 2.0 or WebGL |
||||||
|
* 1.0. |
||||||
|
* @m_since{2020,06} |
||||||
|
*/ |
||||||
|
InstancedObjectId = (1 << 5)|ObjectId, |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* Instanced transformation. Retrieves a per-instance |
||||||
|
* transformation matrix from the @ref TransformationMatrix |
||||||
|
* attribute and uses it together with the matrix coming from |
||||||
|
* @ref setTransformationProjectionMatrix() (first the |
||||||
|
* per-instance, then the uniform matrix). See |
||||||
|
* @ref Shaders-FlatGL-instancing for more information. |
||||||
|
* @requires_gl33 Extension @gl_extension{ARB,instanced_arrays} |
||||||
|
* @requires_gles30 Extension @gl_extension{ANGLE,instanced_arrays}, |
||||||
|
* @gl_extension{EXT,instanced_arrays} or |
||||||
|
* @gl_extension{NV,instanced_arrays} in OpenGL ES 2.0. |
||||||
|
* @requires_webgl20 Extension @webgl_extension{ANGLE,instanced_arrays} |
||||||
|
* in WebGL 1.0. |
||||||
|
* @m_since{2020,06} |
||||||
|
*/ |
||||||
|
InstancedTransformation = 1 << 6, |
||||||
|
|
||||||
|
/**
|
||||||
|
* Instanced texture offset. Retrieves a per-instance offset vector |
||||||
|
* from the @ref TextureOffset attribute and uses it together with |
||||||
|
* the matrix coming from @ref setTextureMatrix() (first the |
||||||
|
* per-instance vector, then the uniform matrix). Instanced texture |
||||||
|
* scaling and rotation is not supported at the moment, you can |
||||||
|
* specify that only via the uniform @ref setTextureMatrix(). |
||||||
|
* Implicitly enables @ref Flag::TextureTransformation. See |
||||||
|
* @ref Shaders-FlatGL-instancing for more information. |
||||||
|
* @requires_gl33 Extension @gl_extension{ARB,instanced_arrays} |
||||||
|
* @requires_gles30 Extension @gl_extension{ANGLE,instanced_arrays}, |
||||||
|
* @gl_extension{EXT,instanced_arrays} or |
||||||
|
* @gl_extension{NV,instanced_arrays} in OpenGL ES 2.0. |
||||||
|
* @requires_webgl20 Extension @webgl_extension{ANGLE,instanced_arrays} |
||||||
|
* in WebGL 1.0. |
||||||
|
* @m_since{2020,06} |
||||||
|
*/ |
||||||
|
InstancedTextureOffset = (1 << 7)|TextureTransformation |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flags |
||||||
|
* |
||||||
|
* @see @ref flags() |
||||||
|
*/ |
||||||
|
typedef Containers::EnumSet<Flag> Flags; |
||||||
|
#else |
||||||
|
/* Done this way to be prepared for possible future diversion of 2D
|
||||||
|
and 3D flags (e.g. introducing 3D-specific features) */ |
||||||
|
typedef Implementation::FlatGLFlag Flag; |
||||||
|
typedef Implementation::FlatGLFlags Flags; |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param flags Flags |
||||||
|
*/ |
||||||
|
explicit FlatGL(Flags flags = {}); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct without creating the underlying OpenGL object |
||||||
|
* |
||||||
|
* The constructed instance is equivalent to a moved-from state. Useful |
||||||
|
* in cases where you will overwrite the instance later anyway. Move |
||||||
|
* another object over it to make it useful. |
||||||
|
* |
||||||
|
* This function can be safely used for constructing (and later |
||||||
|
* destructing) objects even without any OpenGL context being active. |
||||||
|
* However note that this is a low-level and a potentially dangerous |
||||||
|
* API, see the documentation of @ref NoCreate for alternatives. |
||||||
|
*/ |
||||||
|
explicit FlatGL(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {} |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
FlatGL(const FlatGL<dimensions>&) = delete; |
||||||
|
|
||||||
|
/** @brief Move constructor */ |
||||||
|
FlatGL(FlatGL<dimensions>&&) noexcept = default; |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
FlatGL<dimensions>& operator=(const FlatGL<dimensions>&) = delete; |
||||||
|
|
||||||
|
/** @brief Move assignment */ |
||||||
|
FlatGL<dimensions>& operator=(FlatGL<dimensions>&&) noexcept = default; |
||||||
|
|
||||||
|
/** @brief Flags */ |
||||||
|
Flags flags() const { return _flags; } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set transformation and projection matrix |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Initial value is an identity matrix. |
||||||
|
*/ |
||||||
|
FlatGL<dimensions>& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set texture coordinate transformation matrix |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* Expects that the shader was created with |
||||||
|
* @ref Flag::TextureTransformation enabled. Initial value is an |
||||||
|
* identity matrix. |
||||||
|
*/ |
||||||
|
FlatGL<dimensions>& setTextureMatrix(const Matrix3& matrix); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set color |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* If @ref Flag::Textured is set, initial value is |
||||||
|
* @cpp 0xffffffff_rgbaf @ce and the color will be multiplied with the |
||||||
|
* texture. |
||||||
|
* @see @ref bindTexture() |
||||||
|
*/ |
||||||
|
FlatGL<dimensions>& setColor(const Magnum::Color4& color); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Bind a color texture |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Expects that the shader was created with @ref Flag::Textured |
||||||
|
* enabled. |
||||||
|
* @see @ref setColor(), @ref Flag::TextureTransformation, |
||||||
|
* @ref setTextureMatrix() |
||||||
|
*/ |
||||||
|
FlatGL<dimensions>& bindTexture(GL::Texture2D& texture); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set alpha mask value |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Expects that the shader was created with @ref Flag::AlphaMask |
||||||
|
* enabled. Fragments with alpha values smaller than the mask value |
||||||
|
* will be discarded. Initial value is @cpp 0.5f @ce. See the flag |
||||||
|
* documentation for further information. |
||||||
|
* |
||||||
|
* This corresponds to @m_class{m-doc-external} [glAlphaFunc()](https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glAlphaFunc.xml)
|
||||||
|
* in classic OpenGL. |
||||||
|
* @m_keywords{glAlphaFunc()} |
||||||
|
*/ |
||||||
|
FlatGL<dimensions>& setAlphaMask(Float mask); |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
/**
|
||||||
|
* @brief Set object ID |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Expects that the shader was created with @ref Flag::ObjectId |
||||||
|
* enabled. Value set here is written to the @ref ObjectIdOutput, see |
||||||
|
* @ref Shaders-FlatGL-object-id for more information. Default is |
||||||
|
* @cpp 0 @ce. If @ref Flag::InstancedObjectId is enabled as well, this |
||||||
|
* value is combined with ID coming from the @ref ObjectId attribute. |
||||||
|
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4} |
||||||
|
* @requires_gles30 Object ID output requires integer support in |
||||||
|
* shaders, which is not available in OpenGL ES 2.0 or WebGL 1.0. |
||||||
|
*/ |
||||||
|
FlatGL<dimensions>& setObjectId(UnsignedInt id); |
||||||
|
#endif |
||||||
|
|
||||||
|
private: |
||||||
|
/* Prevent accidentally calling irrelevant functions */ |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
using GL::AbstractShaderProgram::drawTransformFeedback; |
||||||
|
#endif |
||||||
|
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |
||||||
|
using GL::AbstractShaderProgram::dispatchCompute; |
||||||
|
#endif |
||||||
|
|
||||||
|
Flags _flags; |
||||||
|
Int _transformationProjectionMatrixUniform{0}, |
||||||
|
_textureMatrixUniform{1}, |
||||||
|
_colorUniform{2}, |
||||||
|
_alphaMaskUniform{3}; |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
Int _objectIdUniform{4}; |
||||||
|
#endif |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief 2D flat OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
*/ |
||||||
|
typedef FlatGL<2> FlatGL2D; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief 3D flat OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
*/ |
||||||
|
typedef FlatGL<3> FlatGL3D; |
||||||
|
|
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
/** @debugoperatorclassenum{FlatGL,FlatGL::Flag} */ |
||||||
|
template<UnsignedInt dimensions> Debug& operator<<(Debug& debug, FlatGL<dimensions>::Flag value); |
||||||
|
|
||||||
|
/** @debugoperatorclassenum{FlatGL,FlatGL::Flags} */ |
||||||
|
template<UnsignedInt dimensions> Debug& operator<<(Debug& debug, FlatGL<dimensions>::Flags value); |
||||||
|
#else |
||||||
|
namespace Implementation { |
||||||
|
MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, FlatGLFlag value); |
||||||
|
MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, FlatGLFlags value); |
||||||
|
CORRADE_ENUMSET_OPERATORS(FlatGLFlags) |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,521 @@ |
|||||||
|
#ifndef Magnum_Shaders_GenericGL_h |
||||||
|
#define Magnum_Shaders_GenericGL_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 Struct @ref Magnum::Shaders::GenericGL, typedef @ref Magnum::Shaders::GenericGL2D, @ref Magnum::Shaders::GenericGL3D |
||||||
|
* @m_since_latest |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum/GL/Attribute.h" |
||||||
|
#include "Magnum/Shaders/Shaders.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Shaders { |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Generic OpenGL shader definition |
||||||
|
@m_since_latest |
||||||
|
|
||||||
|
Definitions common for majority of OpenGL shaders in the @ref Shaders |
||||||
|
namespace, allowing mesh or a framebuffer configured for a generic shader to be |
||||||
|
used with any of them. See @ref shaders-generic for more information. |
||||||
|
|
||||||
|
@section Shaders-GenericGL-allocation Attribute allocation |
||||||
|
|
||||||
|
The attribute locations are allocated like shown below, with various tradeoffs |
||||||
|
as GPUs commonly support only 16 attribtes at most, while the mandated minimum |
||||||
|
on OpenGL ES2 and WebGL 1 being only 8. Some locations are only reserved for |
||||||
|
future use, with no attribute definition implemented yet. |
||||||
|
|
||||||
|
@m_class{m-row m-container-inflate} |
||||||
|
|
||||||
|
@parblock |
||||||
|
|
||||||
|
@m_class{m-fullwidth} |
||||||
|
|
||||||
|
<table> |
||||||
|
<tr> |
||||||
|
<th>\#</th> |
||||||
|
<th>Attribute</th> |
||||||
|
<th>Alternative</th> |
||||||
|
<th>Alternative 2</th> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>0</td> |
||||||
|
<td colspan="3"> |
||||||
|
@ref Position |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>1</td> |
||||||
|
<td colspan="3"> |
||||||
|
@ref TextureCoordinates |
||||||
|
|
||||||
|
* *Reserved* --- third component for a layer |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>2</td> |
||||||
|
<td colspan="3"> |
||||||
|
@ref Color3 / @ref Color4 (per-vertex or instanced) |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>3</td> |
||||||
|
<td> |
||||||
|
@ref Tangent / @ref Tangent4 |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
@ref Tangent |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
* *Reserved* --- TBN as a @ref Magnum::Quaternion "Quaternion" |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>4</td> |
||||||
|
<td> |
||||||
|
@ref ObjectId (instanced) |
||||||
|
|
||||||
|
* *Reserved* --- additional components could \n |
||||||
|
represent material ID and other indices, which \n |
||||||
|
could then be used to fetch additional \n |
||||||
|
per-instance properties that wouldn't fit into \n |
||||||
|
vertex attributes. |
||||||
|
</td> |
||||||
|
<td colspan="2"> |
||||||
|
@ref Bitangent |
||||||
|
|
||||||
|
Provided only as a convenience for models that \n |
||||||
|
don't encode bitangent orientation in the last \n |
||||||
|
component of @ref Tangent4. If a model needs \n |
||||||
|
both bitangents and object ID for instancing, \n |
||||||
|
@ref Tangent4 has to be used. |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>5</td> |
||||||
|
<td colspan="3"> |
||||||
|
@ref Normal |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>6</td> |
||||||
|
<td colspan="3"> |
||||||
|
* *Reserved* --- vertex weights |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>7</td> |
||||||
|
<td colspan="3"> |
||||||
|
* *Reserved* --- bone indices |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>8</td> |
||||||
|
<td rowspan="4"> |
||||||
|
@ref TransformationMatrix (instanced) |
||||||
|
</td> |
||||||
|
<td rowspan="2" colspan="2"> |
||||||
|
* *Reserved* --- instanced @ref Magnum::DualQuaternion "DualQuaternion" \n transformation for positions and normals |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>9</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>10</td> |
||||||
|
<td colspan="2"> |
||||||
|
* *Reserved* --- 2nd vertex weights |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>11</td> |
||||||
|
<td colspan="2"> |
||||||
|
* *Reserved* --- 2nd bone indices |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>12</td> |
||||||
|
<td rowspan="3"> |
||||||
|
@ref NormalMatrix (instanced) |
||||||
|
</td> |
||||||
|
<td colspan="2"> |
||||||
|
* *Reserved* --- instanced scale for positions |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>13</td> |
||||||
|
<td rowspan="2"> |
||||||
|
* *Reserved* --- instanced texture \n |
||||||
|
rotation and scale |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
* *Reserved* --- 2nd vertex colors |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>14</td> |
||||||
|
<td> |
||||||
|
* *Reserved* --- 3rd texture coords |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td>15</td> |
||||||
|
<td> |
||||||
|
@ref TextureOffset (instanced) |
||||||
|
|
||||||
|
* *Reserved* --- third component for a layer |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
* *Reserved* --- a single component \n |
||||||
|
representing instanced texture layer \n |
||||||
|
index, UVs being the same always |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
* *Reserved* --- 2nd texture coords |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
@endparblock |
||||||
|
|
||||||
|
The three alternative allocations can be mixed freely as long as the locations |
||||||
|
don't conflict --- so it's possible to have for example a mesh with two sets of |
||||||
|
texture coordinates, weights and colors, as each of those occupies a different |
||||||
|
attribute range; but instancing then has to be done using smaller types as full |
||||||
|
matrices would occupy the locations used by the secondary sets. Additional |
||||||
|
guarantees of the above: |
||||||
|
|
||||||
|
- @ref Tangent, @ref Bitangent and @ref Normal is in consecutive locations to |
||||||
|
allow those being passed as a single TBN @ref Magnum::Matrix3x3 "Matrix3x3" |
||||||
|
attribute as well. |
||||||
|
- @ref Normal and TBN represented as a quaternion use different locations in |
||||||
|
order to allow a mesh to contain both |
||||||
|
- Similarly, texture rotation/scale and offset is in consecutive locations to |
||||||
|
allow passing a single @ref Matrix3 attribute there. |
||||||
|
- Tnstanced texture transformation is available if and only if there's |
||||||
|
exactly one set of texture coordinates (as the additional sets would need |
||||||
|
additional transformations as well). |
||||||
|
|
||||||
|
@section Shaders-GenericGL-custom Generic attributes and custom shaders |
||||||
|
|
||||||
|
Note that while custom shaders don't *have to* follow the above, it's |
||||||
|
recommended to so. If the custom shader diverges from predefined locations of |
||||||
|
common attributes, meshes configured for the builtin shaders (for example with |
||||||
|
@ref MeshTools::compile()) won't work with it and the mesh attribute |
||||||
|
configuration has to be done manually. It also becomes impossible to render a |
||||||
|
mesh configured for a custom shader with for example @ref MeshVisualizer. |
||||||
|
|
||||||
|
If you're using @ref GL::AbstractShaderProgram::bindAttributeLocation(), it's |
||||||
|
rather easy, as you can simply use the @ref GL::Attribute::Location of given |
||||||
|
attribute: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp GenericGL-custom-bind |
||||||
|
|
||||||
|
For attribute location defined directly in shader code (which is the |
||||||
|
recommended way unless you need compatibility with WebGL 1.0 and OpenGL ES |
||||||
|
2.0), the attribute locations can be propagated using a preprocessor define. |
||||||
|
For example: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp GenericGL-custom-preprocessor |
||||||
|
|
||||||
|
Then, the attribute definition in a shader will look like this: |
||||||
|
|
||||||
|
@code{.glsl} |
||||||
|
layout(location = POSITION_ATTRIBUTE_LOCATION) in vec3 position; |
||||||
|
layout(location = NORMAL_ATTRIBUTE_LOCATION) in vec3 normal; |
||||||
|
@endcode |
||||||
|
|
||||||
|
@see @ref shaders, @ref GenericGL2D, @ref GenericGL3D |
||||||
|
*/ |
||||||
|
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||||
|
template<UnsignedInt> struct GenericGL; |
||||||
|
#else |
||||||
|
template<UnsignedInt dimensions> struct GenericGL { |
||||||
|
/* Keep consistent with generic.glsl and the real definitions below */ |
||||||
|
|
||||||
|
enum: UnsignedInt { |
||||||
|
/**
|
||||||
|
* Color shader output. Present always, expects three- or |
||||||
|
* four-component floating-point or normalized buffer attachment. |
||||||
|
*/ |
||||||
|
ColorOutput = 0, |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
/**
|
||||||
|
* Object ID shader output. Expects a single-component unsigned |
||||||
|
* integral attachment. |
||||||
|
* @requires_gl30 Extension @gl_extension{EXT,texture_integer} |
||||||
|
* @requires_gles30 Object ID output requires integer support in |
||||||
|
* shaders, which is not available in OpenGL ES 2.0 or WebGL 1.0. |
||||||
|
*/ |
||||||
|
ObjectIdOutput = 1 |
||||||
|
#endif |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Vertex position |
||||||
|
* |
||||||
|
* @ref Magnum::Vector2 "Vector2" in 2D and @ref Magnum::Vector3 "Vector3" |
||||||
|
* in 3D. Corresponds to @ref Trade::MeshAttribute::Position. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<0, T> Position; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 2D texture coordinates |
||||||
|
* |
||||||
|
* @ref Magnum::Vector2 "Vector2". Corresponds to |
||||||
|
* @ref Trade::MeshAttribute::TextureCoordinates. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<1, Vector2> TextureCoordinates; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Three-component vertex color |
||||||
|
* |
||||||
|
* @ref Magnum::Color3. Use either this or the @ref Color4 attribute. |
||||||
|
* Corresponds to @ref Trade::MeshAttribute::Color. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<2, Magnum::Color3> Color3; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Four-component vertex color |
||||||
|
* |
||||||
|
* @ref Magnum::Color4. Use either this or the @ref Color3 attribute. |
||||||
|
* Corresponds to @ref Trade::MeshAttribute::Color. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<2, Magnum::Color4> Color4; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Vertex tangent |
||||||
|
* @m_since{2019,10} |
||||||
|
* |
||||||
|
* @ref Magnum::Vector3 "Vector3", defined only in 3D. Use either this or |
||||||
|
* the @ref Tangent4 attribute. Corresponds to |
||||||
|
* @ref Trade::MeshAttribute::Tangent. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<3, Vector3> Tangent; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Vertex tangent with a bitangent sign |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @ref Magnum::Vector4 "Vector4", defined only in 3D. The last component |
||||||
|
* is a sign value (@cpp -1.0f @ce or @cpp +1.0f @ce) defining handedness |
||||||
|
* of the tangent basis. Reconstructing the @ref Bitangent attribute can be |
||||||
|
* then done like this: |
||||||
|
* |
||||||
|
* @snippet MagnumTrade.cpp MeshAttribute-bitangent-from-tangent |
||||||
|
* |
||||||
|
* Use either this or the @ref Tangent attribute. Corresponds to |
||||||
|
* @ref Trade::MeshAttribute::Tangent. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<3, Vector4> Tangent4; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Vertex bitangent |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @ref Magnum::Vector3 "Vector3", defined only in 3D. For better storage |
||||||
|
* efficiency, the bitangent can be also reconstructed from the normal and |
||||||
|
* tangent, see @ref Tangent4 for more information. Corresponds to |
||||||
|
* @ref Trade::MeshAttribute::Bitangent. |
||||||
|
* |
||||||
|
* This attribute conflicts with @ref ObjectId, if you want to use both |
||||||
|
* instanced object ID and bitangents, you need to reconstruct them from |
||||||
|
* @ref Tangent4 instead. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<4, Vector3> Bitangent; |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
/**
|
||||||
|
* @brief (Instanced) object ID |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @ref Magnum::UnsignedInt "UnsignedInt". Corresponds to |
||||||
|
* @ref Trade::MeshAttribute::ObjectId. |
||||||
|
* |
||||||
|
* This attribute conflicts with @ref Bitangent, if you want to use both |
||||||
|
* instanced object ID and bitangents, you need to reconstruct them from |
||||||
|
* @ref Tangent4 instead. |
||||||
|
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4} |
||||||
|
* @requires_gles30 Object ID output requires integer support in shaders, |
||||||
|
* which is not available in OpenGL ES 2.0 or WebGL 1.0. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<4, UnsignedInt> ObjectId; |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Index 4 also used by MeshVisualizer::VertexIndex (reusing ObjectId). Not
|
||||||
|
making it generic yet, as its use case is limited to a single shader, |
||||||
|
and even there it's just a fallback for platforms w/o gl_VertexID. */ |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Vertex normal |
||||||
|
* |
||||||
|
* @ref Magnum::Vector3 "Vector3", defined only in 3D. Corresponds to |
||||||
|
* @ref Trade::MeshAttribute::Normal. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<5, Vector3> Normal; |
||||||
|
|
||||||
|
/* 6, 7 reserved for vertex weights / bone IDs */ |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (Instanced) transformation matrix |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @ref Magnum::Matrix3 "Matrix3" in 2D and @ref Magnum::Matrix4 "Matrix4" |
||||||
|
* in 3D. Currently doesn't have a corresponding @ref Trade::MeshAttribute. |
||||||
|
* @requires_gl33 Extension @gl_extension{ARB,instanced_arrays} |
||||||
|
* @requires_gles30 Extension @gl_extension{ANGLE,instanced_arrays}, |
||||||
|
* @gl_extension{EXT,instanced_arrays} or |
||||||
|
* @gl_extension{NV,instanced_arrays} in OpenGL ES 2.0. |
||||||
|
* @requires_webgl20 Extension @webgl_extension{ANGLE,instanced_arrays} |
||||||
|
* in WebGL 1.0. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<8, T> TransformationMatrix; |
||||||
|
|
||||||
|
/* 9, 10, 11 occupied by TransformationMatrix */ |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (Instanced) normal matrix |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @ref Magnum::Matrix3 "Matrix3x3", defined only in 3D. Currently doesn't |
||||||
|
* have a corresponding @ref Trade::MeshAttribute. |
||||||
|
* @requires_gl33 Extension @gl_extension{ARB,instanced_arrays} |
||||||
|
* @requires_gles30 Extension @gl_extension{ANGLE,instanced_arrays}, |
||||||
|
* @gl_extension{EXT,instanced_arrays} or |
||||||
|
* @gl_extension{NV,instanced_arrays} in OpenGL ES 2.0. |
||||||
|
* @requires_webgl20 Extension @webgl_extension{ANGLE,instanced_arrays} |
||||||
|
* in WebGL 1.0. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<12, Matrix3x3> NormalMatrix; |
||||||
|
|
||||||
|
/* 13, 14 occupied by NormalMatrix */ |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief (Instanced) texture offset |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @ref Magnum::Vector2 "Vector2". Currently doesn't have a corresponding |
||||||
|
* @ref Trade::MeshAttribute. |
||||||
|
* @requires_gl33 Extension @gl_extension{ARB,instanced_arrays} |
||||||
|
* @requires_gles30 Extension @gl_extension{ANGLE,instanced_arrays}, |
||||||
|
* @gl_extension{EXT,instanced_arrays} or |
||||||
|
* @gl_extension{NV,instanced_arrays} in OpenGL ES 2.0. |
||||||
|
* @requires_webgl20 Extension @webgl_extension{ANGLE,instanced_arrays} |
||||||
|
* in WebGL 1.0. |
||||||
|
*/ |
||||||
|
typedef GL::Attribute<15, Vector2> TextureOffset; |
||||||
|
}; |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Generic 2D OpenGL shader definition |
||||||
|
@m_since_latest |
||||||
|
*/ |
||||||
|
typedef GenericGL<2> GenericGL2D; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Generic 3D OpenGL shader definition |
||||||
|
@m_since_latest |
||||||
|
*/ |
||||||
|
typedef GenericGL<3> GenericGL3D; |
||||||
|
|
||||||
|
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||||
|
struct BaseGenericGL { |
||||||
|
enum: UnsignedInt { |
||||||
|
ColorOutput = 0, |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
ObjectIdOutput = 1 |
||||||
|
#endif |
||||||
|
}; |
||||||
|
|
||||||
|
typedef GL::Attribute<1, Vector2> TextureCoordinates; |
||||||
|
typedef GL::Attribute<2, Magnum::Color3> Color3; |
||||||
|
typedef GL::Attribute<2, Magnum::Color4> Color4; |
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
typedef GL::Attribute<4, UnsignedInt> ObjectId; |
||||||
|
#endif |
||||||
|
|
||||||
|
typedef GL::Attribute<15, Vector2> TextureOffset; |
||||||
|
}; |
||||||
|
|
||||||
|
template<> struct GenericGL<2>: BaseGenericGL { |
||||||
|
typedef GL::Attribute<0, Vector2> Position; |
||||||
|
/* 1, 2 used by TextureCoordinates and Color */ |
||||||
|
|
||||||
|
typedef GL::Attribute<8, Matrix3> TransformationMatrix; |
||||||
|
/* 9, 10 occupied by TransformationMatrix */ |
||||||
|
/* 15 used by TextureOffset */ |
||||||
|
}; |
||||||
|
|
||||||
|
template<> struct GenericGL<3>: BaseGenericGL { |
||||||
|
typedef GL::Attribute<0, Vector3> Position; |
||||||
|
/* 1, 2 used by TextureCoordinates and Color */ |
||||||
|
typedef GL::Attribute<3, Vector3> Tangent; |
||||||
|
typedef GL::Attribute<3, Vector4> Tangent4; |
||||||
|
typedef GL::Attribute<4, Vector3> Bitangent; /* also ObjectId */ |
||||||
|
typedef GL::Attribute<5, Vector3> Normal; |
||||||
|
/* 6, 7 reserved for vertex weights / bone IDs */ |
||||||
|
|
||||||
|
typedef GL::Attribute<8, Matrix4> TransformationMatrix; |
||||||
|
/* 9, 10, 11 occupied by TransformationMatrix */ |
||||||
|
typedef GL::Attribute<12, Matrix3x3> NormalMatrix; |
||||||
|
/* 13, 14 occupied by NormalMatrix */ |
||||||
|
/* 15 used by TextureOffset */ |
||||||
|
}; |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifdef MAGNUM_BUILD_DEPRECATED |
||||||
|
/* Deprecated aliases present here instead of GenericGL.h, as a lot of existing
|
||||||
|
code relies on these being transitively included from Phong.h etc., and |
||||||
|
there are no forward declarations in Shaders.h as the type is never used |
||||||
|
like that. While we *could* include Generic.h from Phong.h, we'd have to |
||||||
|
also temporarily disable the CORRADE_DEPRECATED_FILE() macro there and it's |
||||||
|
more pain than it's worth. */ |
||||||
|
|
||||||
|
/** @brief @copybrief GenericGL
|
||||||
|
* @m_deprecated_since_latest Use @ref GenericGL instead. |
||||||
|
*/ |
||||||
|
#ifndef CORRADE_MSVC2015_COMPATIBILITY /* Multiple definitions still broken */ |
||||||
|
template<UnsignedInt dimensions> using Generic CORRADE_DEPRECATED_ALIAS("use GenericGL instead") = GenericGL<dimensions>; |
||||||
|
#endif |
||||||
|
|
||||||
|
/** @brief @copybrief GenericGL2D
|
||||||
|
* @m_deprecated_since_latest Use @ref GenericGL2D instead. |
||||||
|
*/ |
||||||
|
typedef CORRADE_DEPRECATED("use GenericGL2D instead") GenericGL2D Generic2D; |
||||||
|
|
||||||
|
/** @brief @copybrief GenericGL3D
|
||||||
|
* @m_deprecated_since_latest Use @ref GenericGL3D instead. |
||||||
|
*/ |
||||||
|
typedef CORRADE_DEPRECATED("use GenericGL3D instead") GenericGL3D Generic3D; |
||||||
|
#endif |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,118 @@ |
|||||||
|
/*
|
||||||
|
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 <Corrade/TestSuite/Tester.h> |
||||||
|
|
||||||
|
#include "Magnum/Shaders/GenericGL.h" |
||||||
|
/* Yes, really */ |
||||||
|
#include "Magnum/Shaders/generic.glsl" |
||||||
|
|
||||||
|
namespace Magnum { namespace Shaders { namespace Test { namespace { |
||||||
|
|
||||||
|
/* There's an underscore between GL and Test to disambiguate from GLTest, which
|
||||||
|
is a common suffix used to mark tests that need a GL context. Ugly, I know. */ |
||||||
|
struct GenericGL_Test: TestSuite::Tester { |
||||||
|
explicit GenericGL_Test(); |
||||||
|
|
||||||
|
void glslMatch(); |
||||||
|
void glslMatchOutput(); |
||||||
|
|
||||||
|
void tbnContiguous(); |
||||||
|
void tbnBothNormalAndQuaternion(); |
||||||
|
void textureTransformContiguous(); |
||||||
|
}; |
||||||
|
|
||||||
|
GenericGL_Test::GenericGL_Test() { |
||||||
|
addTests({&GenericGL_Test::glslMatch, |
||||||
|
&GenericGL_Test::glslMatchOutput, |
||||||
|
|
||||||
|
&GenericGL_Test::tbnContiguous, |
||||||
|
&GenericGL_Test::tbnBothNormalAndQuaternion, |
||||||
|
&GenericGL_Test::textureTransformContiguous}); |
||||||
|
} |
||||||
|
|
||||||
|
void GenericGL_Test::glslMatch() { |
||||||
|
CORRADE_COMPARE(POSITION_ATTRIBUTE_LOCATION, GenericGL2D::Position::Location); |
||||||
|
CORRADE_COMPARE(POSITION_ATTRIBUTE_LOCATION, GenericGL3D::Position::Location); |
||||||
|
|
||||||
|
CORRADE_COMPARE(TEXTURECOORDINATES_ATTRIBUTE_LOCATION, GenericGL2D::TextureCoordinates::Location); |
||||||
|
CORRADE_COMPARE(TEXTURECOORDINATES_ATTRIBUTE_LOCATION, GenericGL3D::TextureCoordinates::Location); |
||||||
|
|
||||||
|
CORRADE_COMPARE(COLOR_ATTRIBUTE_LOCATION, GenericGL2D::Color3::Location); |
||||||
|
CORRADE_COMPARE(COLOR_ATTRIBUTE_LOCATION, GenericGL3D::Color3::Location); |
||||||
|
CORRADE_COMPARE(COLOR_ATTRIBUTE_LOCATION, GenericGL2D::Color4::Location); |
||||||
|
CORRADE_COMPARE(COLOR_ATTRIBUTE_LOCATION, GenericGL3D::Color4::Location); |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
CORRADE_COMPARE(OBJECT_ID_ATTRIBUTE_LOCATION, GenericGL2D::ObjectId::Location); |
||||||
|
CORRADE_COMPARE(OBJECT_ID_ATTRIBUTE_LOCATION, GenericGL3D::ObjectId::Location); |
||||||
|
#endif |
||||||
|
|
||||||
|
CORRADE_COMPARE(TANGENT_ATTRIBUTE_LOCATION, GenericGL3D::Tangent::Location); |
||||||
|
CORRADE_COMPARE(TANGENT_ATTRIBUTE_LOCATION, GenericGL3D::Tangent4::Location); |
||||||
|
CORRADE_COMPARE(BITANGENT_ATTRIBUTE_LOCATION, GenericGL3D::Bitangent::Location); |
||||||
|
CORRADE_COMPARE(NORMAL_ATTRIBUTE_LOCATION, GenericGL3D::Normal::Location); |
||||||
|
|
||||||
|
CORRADE_COMPARE(TRANSFORMATION_MATRIX_ATTRIBUTE_LOCATION, GenericGL2D::TransformationMatrix::Location); |
||||||
|
CORRADE_COMPARE(TRANSFORMATION_MATRIX_ATTRIBUTE_LOCATION, GenericGL3D::TransformationMatrix::Location); |
||||||
|
|
||||||
|
CORRADE_COMPARE(NORMAL_MATRIX_ATTRIBUTE_LOCATION, GenericGL3D::NormalMatrix::Location); |
||||||
|
|
||||||
|
CORRADE_COMPARE(TEXTURE_OFFSET_ATTRIBUTE_LOCATION, GenericGL2D::TextureOffset::Location); |
||||||
|
CORRADE_COMPARE(TEXTURE_OFFSET_ATTRIBUTE_LOCATION, GenericGL3D::TextureOffset::Location); |
||||||
|
} |
||||||
|
|
||||||
|
void GenericGL_Test::glslMatchOutput() { |
||||||
|
CORRADE_COMPARE(COLOR_OUTPUT_ATTRIBUTE_LOCATION, GenericGL2D::ColorOutput); |
||||||
|
CORRADE_COMPARE(COLOR_OUTPUT_ATTRIBUTE_LOCATION, GenericGL3D::ColorOutput); |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES2 |
||||||
|
CORRADE_COMPARE(OBJECT_ID_OUTPUT_ATTRIBUTE_LOCATION, GenericGL2D::ObjectIdOutput); |
||||||
|
CORRADE_COMPARE(OBJECT_ID_OUTPUT_ATTRIBUTE_LOCATION, GenericGL3D::ObjectIdOutput); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
void GenericGL_Test::tbnContiguous() { |
||||||
|
CORRADE_COMPARE(GenericGL3D::Tangent::Location + 1, GenericGL3D::Bitangent::Location); |
||||||
|
CORRADE_COMPARE(GenericGL3D::Bitangent::Location + 1, GenericGL3D::Normal::Location); |
||||||
|
} |
||||||
|
|
||||||
|
void GenericGL_Test::tbnBothNormalAndQuaternion() { |
||||||
|
CORRADE_SKIP("Quaternion TBN not implemented yet."); |
||||||
|
|
||||||
|
//CORRADE_VERIFY(GenericGL3D::TbnQuaternion::Location != GenericGL3D::Normal::Location);
|
||||||
|
} |
||||||
|
|
||||||
|
void GenericGL_Test::textureTransformContiguous() { |
||||||
|
/* These depend on DualQuaternion-based (instanced) transformation */ |
||||||
|
CORRADE_SKIP("TextureRotationScale and TextureMatrix attributes not implemented yet."); |
||||||
|
|
||||||
|
//CORRADE_COMPARE(GenericGL3D::TextureRotationScale::Location, GenericGL3D::TextureMatrix::Location);
|
||||||
|
//CORRADE_COMPARE(GenericGL3D::TextureOffset::Location, GenericGL3D::TextureMatrix::Location + 2);
|
||||||
|
} |
||||||
|
|
||||||
|
}}}} |
||||||
|
|
||||||
|
CORRADE_TEST_MAIN(Magnum::Shaders::Test::GenericGL_Test) |
||||||
@ -1,116 +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 <Corrade/TestSuite/Tester.h> |
|
||||||
|
|
||||||
#include "Magnum/Shaders/Generic.h" |
|
||||||
/* Yes, really */ |
|
||||||
#include "Magnum/Shaders/generic.glsl" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shaders { namespace Test { namespace { |
|
||||||
|
|
||||||
struct GenericTest: TestSuite::Tester { |
|
||||||
explicit GenericTest(); |
|
||||||
|
|
||||||
void glslMatch(); |
|
||||||
void glslMatchOutput(); |
|
||||||
|
|
||||||
void tbnContiguous(); |
|
||||||
void tbnBothNormalAndQuaternion(); |
|
||||||
void textureTransformContiguous(); |
|
||||||
}; |
|
||||||
|
|
||||||
GenericTest::GenericTest() { |
|
||||||
addTests({&GenericTest::glslMatch, |
|
||||||
&GenericTest::glslMatchOutput, |
|
||||||
|
|
||||||
&GenericTest::tbnContiguous, |
|
||||||
&GenericTest::tbnBothNormalAndQuaternion, |
|
||||||
&GenericTest::textureTransformContiguous}); |
|
||||||
} |
|
||||||
|
|
||||||
void GenericTest::glslMatch() { |
|
||||||
CORRADE_COMPARE(POSITION_ATTRIBUTE_LOCATION, Generic2D::Position::Location); |
|
||||||
CORRADE_COMPARE(POSITION_ATTRIBUTE_LOCATION, Generic3D::Position::Location); |
|
||||||
|
|
||||||
CORRADE_COMPARE(TEXTURECOORDINATES_ATTRIBUTE_LOCATION, Generic2D::TextureCoordinates::Location); |
|
||||||
CORRADE_COMPARE(TEXTURECOORDINATES_ATTRIBUTE_LOCATION, Generic3D::TextureCoordinates::Location); |
|
||||||
|
|
||||||
CORRADE_COMPARE(COLOR_ATTRIBUTE_LOCATION, Generic2D::Color3::Location); |
|
||||||
CORRADE_COMPARE(COLOR_ATTRIBUTE_LOCATION, Generic3D::Color3::Location); |
|
||||||
CORRADE_COMPARE(COLOR_ATTRIBUTE_LOCATION, Generic2D::Color4::Location); |
|
||||||
CORRADE_COMPARE(COLOR_ATTRIBUTE_LOCATION, Generic3D::Color4::Location); |
|
||||||
|
|
||||||
#ifndef MAGNUM_TARGET_GLES2 |
|
||||||
CORRADE_COMPARE(OBJECT_ID_ATTRIBUTE_LOCATION, Generic2D::ObjectId::Location); |
|
||||||
CORRADE_COMPARE(OBJECT_ID_ATTRIBUTE_LOCATION, Generic3D::ObjectId::Location); |
|
||||||
#endif |
|
||||||
|
|
||||||
CORRADE_COMPARE(TANGENT_ATTRIBUTE_LOCATION, Generic3D::Tangent::Location); |
|
||||||
CORRADE_COMPARE(TANGENT_ATTRIBUTE_LOCATION, Generic3D::Tangent4::Location); |
|
||||||
CORRADE_COMPARE(BITANGENT_ATTRIBUTE_LOCATION, Generic3D::Bitangent::Location); |
|
||||||
CORRADE_COMPARE(NORMAL_ATTRIBUTE_LOCATION, Generic3D::Normal::Location); |
|
||||||
|
|
||||||
CORRADE_COMPARE(TRANSFORMATION_MATRIX_ATTRIBUTE_LOCATION, Generic2D::TransformationMatrix::Location); |
|
||||||
CORRADE_COMPARE(TRANSFORMATION_MATRIX_ATTRIBUTE_LOCATION, Generic3D::TransformationMatrix::Location); |
|
||||||
|
|
||||||
CORRADE_COMPARE(NORMAL_MATRIX_ATTRIBUTE_LOCATION, Generic3D::NormalMatrix::Location); |
|
||||||
|
|
||||||
CORRADE_COMPARE(TEXTURE_OFFSET_ATTRIBUTE_LOCATION, Generic2D::TextureOffset::Location); |
|
||||||
CORRADE_COMPARE(TEXTURE_OFFSET_ATTRIBUTE_LOCATION, Generic3D::TextureOffset::Location); |
|
||||||
} |
|
||||||
|
|
||||||
void GenericTest::glslMatchOutput() { |
|
||||||
CORRADE_COMPARE(COLOR_OUTPUT_ATTRIBUTE_LOCATION, Generic2D::ColorOutput); |
|
||||||
CORRADE_COMPARE(COLOR_OUTPUT_ATTRIBUTE_LOCATION, Generic3D::ColorOutput); |
|
||||||
|
|
||||||
#ifndef MAGNUM_TARGET_GLES2 |
|
||||||
CORRADE_COMPARE(OBJECT_ID_OUTPUT_ATTRIBUTE_LOCATION, Generic2D::ObjectIdOutput); |
|
||||||
CORRADE_COMPARE(OBJECT_ID_OUTPUT_ATTRIBUTE_LOCATION, Generic3D::ObjectIdOutput); |
|
||||||
#endif |
|
||||||
} |
|
||||||
|
|
||||||
void GenericTest::tbnContiguous() { |
|
||||||
CORRADE_COMPARE(Generic3D::Tangent::Location + 1, Generic3D::Bitangent::Location); |
|
||||||
CORRADE_COMPARE(Generic3D::Bitangent::Location + 1, Generic3D::Normal::Location); |
|
||||||
} |
|
||||||
|
|
||||||
void GenericTest::tbnBothNormalAndQuaternion() { |
|
||||||
CORRADE_SKIP("Quaternion TBN not implemented yet."); |
|
||||||
|
|
||||||
//CORRADE_VERIFY(Generic3D::TbnQuaternion::Location != Generic3D::Normal::Location);
|
|
||||||
} |
|
||||||
|
|
||||||
void GenericTest::textureTransformContiguous() { |
|
||||||
/* These depend on DualQuaternion-based (instanced) transformation */ |
|
||||||
CORRADE_SKIP("TextureRotationScale and TextureMatrix attributes not implemented yet."); |
|
||||||
|
|
||||||
//CORRADE_COMPARE(Generic3D::TextureRotationScale::Location, Generic3D::TextureMatrix::Location);
|
|
||||||
//CORRADE_COMPARE(Generic3D::TextureOffset::Location, Generic3D::TextureMatrix::Location + 2);
|
|
||||||
} |
|
||||||
|
|
||||||
}}}} |
|
||||||
|
|
||||||
CORRADE_TEST_MAIN(Magnum::Shaders::Test::GenericTest) |
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,145 @@ |
|||||||
|
/*
|
||||||
|
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 <sstream> |
||||||
|
#include <Corrade/TestSuite/Tester.h> |
||||||
|
#include <Corrade/Utility/DebugStl.h> |
||||||
|
|
||||||
|
#include "Magnum/Shaders/MeshVisualizerGL.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Shaders { namespace Test { namespace { |
||||||
|
|
||||||
|
/* There's an underscore between GL and Test to disambiguate from GLTest, which
|
||||||
|
is a common suffix used to mark tests that need a GL context. Ugly, I know. */ |
||||||
|
struct MeshVisualizerGL_Test: TestSuite::Tester { |
||||||
|
explicit MeshVisualizerGL_Test(); |
||||||
|
|
||||||
|
void constructNoCreate2D(); |
||||||
|
void constructNoCreate3D(); |
||||||
|
|
||||||
|
void constructCopy2D(); |
||||||
|
void constructCopy3D(); |
||||||
|
|
||||||
|
void vertexIndexSameAsObjectId(); |
||||||
|
|
||||||
|
void debugFlag2D(); |
||||||
|
void debugFlag3D(); |
||||||
|
void debugFlags2D(); |
||||||
|
void debugFlags3D(); |
||||||
|
}; |
||||||
|
|
||||||
|
MeshVisualizerGL_Test::MeshVisualizerGL_Test() { |
||||||
|
addTests({&MeshVisualizerGL_Test::constructNoCreate2D, |
||||||
|
&MeshVisualizerGL_Test::constructNoCreate3D, |
||||||
|
|
||||||
|
&MeshVisualizerGL_Test::constructCopy2D, |
||||||
|
&MeshVisualizerGL_Test::constructCopy3D, |
||||||
|
|
||||||
|
&MeshVisualizerGL_Test::vertexIndexSameAsObjectId, |
||||||
|
|
||||||
|
&MeshVisualizerGL_Test::debugFlag2D, |
||||||
|
&MeshVisualizerGL_Test::debugFlag3D, |
||||||
|
&MeshVisualizerGL_Test::debugFlags2D, |
||||||
|
&MeshVisualizerGL_Test::debugFlags3D}); |
||||||
|
} |
||||||
|
|
||||||
|
void MeshVisualizerGL_Test::constructNoCreate2D() { |
||||||
|
{ |
||||||
|
MeshVisualizerGL2D shader{NoCreate}; |
||||||
|
CORRADE_COMPARE(shader.id(), 0); |
||||||
|
CORRADE_COMPARE(shader.flags(), MeshVisualizerGL2D::Flags{}); |
||||||
|
} |
||||||
|
|
||||||
|
CORRADE_VERIFY(true); |
||||||
|
} |
||||||
|
|
||||||
|
void MeshVisualizerGL_Test::constructNoCreate3D() { |
||||||
|
{ |
||||||
|
MeshVisualizerGL3D shader{NoCreate}; |
||||||
|
CORRADE_COMPARE(shader.id(), 0); |
||||||
|
CORRADE_COMPARE(shader.flags(), MeshVisualizerGL3D::Flags{}); |
||||||
|
} |
||||||
|
|
||||||
|
CORRADE_VERIFY(true); |
||||||
|
} |
||||||
|
|
||||||
|
void MeshVisualizerGL_Test::constructCopy2D() { |
||||||
|
CORRADE_VERIFY(!std::is_copy_constructible<MeshVisualizerGL2D>{}); |
||||||
|
CORRADE_VERIFY(!std::is_copy_assignable<MeshVisualizerGL2D>{}); |
||||||
|
} |
||||||
|
|
||||||
|
void MeshVisualizerGL_Test::constructCopy3D() { |
||||||
|
CORRADE_VERIFY(!std::is_copy_constructible<MeshVisualizerGL3D>{}); |
||||||
|
CORRADE_VERIFY(!std::is_copy_assignable<MeshVisualizerGL3D>{}); |
||||||
|
} |
||||||
|
|
||||||
|
void MeshVisualizerGL_Test::vertexIndexSameAsObjectId() { |
||||||
|
#ifdef MAGNUM_TARGET_GLES2 |
||||||
|
CORRADE_SKIP("Object ID is not available on ES2."); |
||||||
|
#else |
||||||
|
CORRADE_COMPARE(MeshVisualizerGL2D::VertexIndex::Location, GenericGL2D::ObjectId::Location); |
||||||
|
CORRADE_COMPARE(MeshVisualizerGL3D::VertexIndex::Location, GenericGL3D::ObjectId::Location); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
void MeshVisualizerGL_Test::debugFlag2D() { |
||||||
|
std::ostringstream out; |
||||||
|
|
||||||
|
Debug{&out} << MeshVisualizerGL2D::Flag::Wireframe << MeshVisualizerGL2D::Flag(0xf0); |
||||||
|
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL2D::Flag::Wireframe Shaders::MeshVisualizerGL2D::Flag(0xf0)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void MeshVisualizerGL_Test::debugFlag3D() { |
||||||
|
std::ostringstream out; |
||||||
|
|
||||||
|
Debug{&out} << MeshVisualizerGL3D::Flag::Wireframe << MeshVisualizerGL3D::Flag(0xf0); |
||||||
|
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL3D::Flag::Wireframe Shaders::MeshVisualizerGL3D::Flag(0xf0)\n"); |
||||||
|
} |
||||||
|
|
||||||
|
void MeshVisualizerGL_Test::debugFlags2D() { |
||||||
|
std::ostringstream out; |
||||||
|
|
||||||
|
Debug{&out} << (MeshVisualizerGL2D::Flag::Wireframe|MeshVisualizerGL2D::Flag::NoGeometryShader) << MeshVisualizerGL2D::Flags{}; |
||||||
|
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |
||||||
|
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL2D::Flag::Wireframe|Shaders::MeshVisualizerGL2D::Flag::NoGeometryShader Shaders::MeshVisualizerGL2D::Flags{}\n"); |
||||||
|
#else |
||||||
|
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL2D::Flag::Wireframe Shaders::MeshVisualizerGL2D::Flags{}\n"); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
void MeshVisualizerGL_Test::debugFlags3D() { |
||||||
|
std::ostringstream out; |
||||||
|
|
||||||
|
Debug{&out} << (MeshVisualizerGL3D::Flag::Wireframe|MeshVisualizerGL3D::Flag::NoGeometryShader) << MeshVisualizerGL3D::Flags{}; |
||||||
|
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |
||||||
|
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL3D::Flag::Wireframe|Shaders::MeshVisualizerGL3D::Flag::NoGeometryShader Shaders::MeshVisualizerGL3D::Flags{}\n"); |
||||||
|
#else |
||||||
|
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL3D::Flag::Wireframe Shaders::MeshVisualizerGL3D::Flags{}\n"); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
}}}} |
||||||
|
|
||||||
|
CORRADE_TEST_MAIN(Magnum::Shaders::Test::MeshVisualizerGL_Test) |
||||||
@ -1,143 +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 <sstream> |
|
||||||
#include <Corrade/TestSuite/Tester.h> |
|
||||||
#include <Corrade/Utility/DebugStl.h> |
|
||||||
|
|
||||||
#include "Magnum/Shaders/MeshVisualizer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shaders { namespace Test { namespace { |
|
||||||
|
|
||||||
struct MeshVisualizerTest: TestSuite::Tester { |
|
||||||
explicit MeshVisualizerTest(); |
|
||||||
|
|
||||||
void constructNoCreate2D(); |
|
||||||
void constructNoCreate3D(); |
|
||||||
|
|
||||||
void constructCopy2D(); |
|
||||||
void constructCopy3D(); |
|
||||||
|
|
||||||
void vertexIndexSameAsObjectId(); |
|
||||||
|
|
||||||
void debugFlag2D(); |
|
||||||
void debugFlag3D(); |
|
||||||
void debugFlags2D(); |
|
||||||
void debugFlags3D(); |
|
||||||
}; |
|
||||||
|
|
||||||
MeshVisualizerTest::MeshVisualizerTest() { |
|
||||||
addTests({&MeshVisualizerTest::constructNoCreate2D, |
|
||||||
&MeshVisualizerTest::constructNoCreate3D, |
|
||||||
|
|
||||||
&MeshVisualizerTest::constructCopy2D, |
|
||||||
&MeshVisualizerTest::constructCopy3D, |
|
||||||
|
|
||||||
&MeshVisualizerTest::vertexIndexSameAsObjectId, |
|
||||||
|
|
||||||
&MeshVisualizerTest::debugFlag2D, |
|
||||||
&MeshVisualizerTest::debugFlag3D, |
|
||||||
&MeshVisualizerTest::debugFlags2D, |
|
||||||
&MeshVisualizerTest::debugFlags3D}); |
|
||||||
} |
|
||||||
|
|
||||||
void MeshVisualizerTest::constructNoCreate2D() { |
|
||||||
{ |
|
||||||
MeshVisualizer2D shader{NoCreate}; |
|
||||||
CORRADE_COMPARE(shader.id(), 0); |
|
||||||
CORRADE_COMPARE(shader.flags(), MeshVisualizer2D::Flags{}); |
|
||||||
} |
|
||||||
|
|
||||||
CORRADE_VERIFY(true); |
|
||||||
} |
|
||||||
|
|
||||||
void MeshVisualizerTest::constructNoCreate3D() { |
|
||||||
{ |
|
||||||
MeshVisualizer3D shader{NoCreate}; |
|
||||||
CORRADE_COMPARE(shader.id(), 0); |
|
||||||
CORRADE_COMPARE(shader.flags(), MeshVisualizer3D::Flags{}); |
|
||||||
} |
|
||||||
|
|
||||||
CORRADE_VERIFY(true); |
|
||||||
} |
|
||||||
|
|
||||||
void MeshVisualizerTest::constructCopy2D() { |
|
||||||
CORRADE_VERIFY(!std::is_copy_constructible<MeshVisualizer2D>{}); |
|
||||||
CORRADE_VERIFY(!std::is_copy_assignable<MeshVisualizer2D>{}); |
|
||||||
} |
|
||||||
|
|
||||||
void MeshVisualizerTest::constructCopy3D() { |
|
||||||
CORRADE_VERIFY(!std::is_copy_constructible<MeshVisualizer3D>{}); |
|
||||||
CORRADE_VERIFY(!std::is_copy_assignable<MeshVisualizer3D>{}); |
|
||||||
} |
|
||||||
|
|
||||||
void MeshVisualizerTest::vertexIndexSameAsObjectId() { |
|
||||||
#ifdef MAGNUM_TARGET_GLES2 |
|
||||||
CORRADE_SKIP("Object ID is not available on ES2."); |
|
||||||
#else |
|
||||||
CORRADE_COMPARE(MeshVisualizer2D::VertexIndex::Location, Generic2D::ObjectId::Location); |
|
||||||
CORRADE_COMPARE(MeshVisualizer3D::VertexIndex::Location, Generic3D::ObjectId::Location); |
|
||||||
#endif |
|
||||||
} |
|
||||||
|
|
||||||
void MeshVisualizerTest::debugFlag2D() { |
|
||||||
std::ostringstream out; |
|
||||||
|
|
||||||
Debug{&out} << MeshVisualizer2D::Flag::Wireframe << MeshVisualizer2D::Flag(0xf0); |
|
||||||
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizer2D::Flag::Wireframe Shaders::MeshVisualizer2D::Flag(0xf0)\n"); |
|
||||||
} |
|
||||||
|
|
||||||
void MeshVisualizerTest::debugFlag3D() { |
|
||||||
std::ostringstream out; |
|
||||||
|
|
||||||
Debug{&out} << MeshVisualizer3D::Flag::Wireframe << MeshVisualizer3D::Flag(0xf0); |
|
||||||
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizer3D::Flag::Wireframe Shaders::MeshVisualizer3D::Flag(0xf0)\n"); |
|
||||||
} |
|
||||||
|
|
||||||
void MeshVisualizerTest::debugFlags2D() { |
|
||||||
std::ostringstream out; |
|
||||||
|
|
||||||
Debug{&out} << (MeshVisualizer2D::Flag::Wireframe|MeshVisualizer2D::Flag::NoGeometryShader) << MeshVisualizer2D::Flags{}; |
|
||||||
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |
|
||||||
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizer2D::Flag::Wireframe|Shaders::MeshVisualizer2D::Flag::NoGeometryShader Shaders::MeshVisualizer2D::Flags{}\n"); |
|
||||||
#else |
|
||||||
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizer2D::Flag::Wireframe Shaders::MeshVisualizer2D::Flags{}\n"); |
|
||||||
#endif |
|
||||||
} |
|
||||||
|
|
||||||
void MeshVisualizerTest::debugFlags3D() { |
|
||||||
std::ostringstream out; |
|
||||||
|
|
||||||
Debug{&out} << (MeshVisualizer3D::Flag::Wireframe|MeshVisualizer3D::Flag::NoGeometryShader) << MeshVisualizer3D::Flags{}; |
|
||||||
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |
|
||||||
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizer3D::Flag::Wireframe|Shaders::MeshVisualizer3D::Flag::NoGeometryShader Shaders::MeshVisualizer3D::Flags{}\n"); |
|
||||||
#else |
|
||||||
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizer3D::Flag::Wireframe Shaders::MeshVisualizer3D::Flags{}\n"); |
|
||||||
#endif |
|
||||||
} |
|
||||||
|
|
||||||
}}}} |
|
||||||
|
|
||||||
CORRADE_TEST_MAIN(Magnum::Shaders::Test::MeshVisualizerTest) |
|
||||||
@ -0,0 +1,242 @@ |
|||||||
|
#ifndef Magnum_Shaders_VectorGL_h |
||||||
|
#define Magnum_Shaders_VectorGL_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::VectorGL, typedef @ref Magnum::Shaders::VectorGL2D, @ref Magnum::Shaders::VectorGL3D |
||||||
|
* @m_since_latest |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum/DimensionTraits.h" |
||||||
|
#include "Magnum/Shaders/AbstractVectorGL.h" |
||||||
|
#include "Magnum/Shaders/visibility.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Shaders { |
||||||
|
|
||||||
|
namespace Implementation { |
||||||
|
enum class VectorGLFlag: UnsignedByte { |
||||||
|
TextureTransformation = 1 << 0 |
||||||
|
}; |
||||||
|
typedef Containers::EnumSet<VectorGLFlag> VectorGLFlags; |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Vector OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
|
||||||
|
Renders vector art in plain grayscale form. See also @ref DistanceFieldVectorGL |
||||||
|
for more advanced effects. For rendering an unchanged texture you can use the |
||||||
|
@ref FlatGL shader. You need to provide the @ref Position and |
||||||
|
@ref TextureCoordinates attributes in your triangle mesh and call at least |
||||||
|
@ref bindVectorTexture(). By default, the shader renders the texture with a |
||||||
|
white color in an identity transformation. Use |
||||||
|
@ref setTransformationProjectionMatrix(), @ref setColor() and others to |
||||||
|
configure the shader. |
||||||
|
|
||||||
|
@image html shaders-vector.png width=256px |
||||||
|
|
||||||
|
Alpha / transparency is supported by the shader implicitly, but to have it |
||||||
|
working on the framebuffer, you need to enable |
||||||
|
@ref GL::Renderer::Feature::Blending and set up the blending function. See |
||||||
|
@ref GL::Renderer::setBlendFunction() for details. |
||||||
|
|
||||||
|
@section Shaders-VectorGL-usage Example usage |
||||||
|
|
||||||
|
Common mesh setup: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp VectorGL-usage1 |
||||||
|
|
||||||
|
Common rendering setup: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp VectorGL-usage2 |
||||||
|
|
||||||
|
@see @ref shaders, @ref VectorGL2D, @ref VectorGL3D |
||||||
|
*/ |
||||||
|
template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VectorGL: public AbstractVectorGL<dimensions> { |
||||||
|
public: |
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
/**
|
||||||
|
* @brief Flag |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @see @ref Flags, @ref flags() |
||||||
|
*/ |
||||||
|
enum class Flag: UnsignedByte { |
||||||
|
/**
|
||||||
|
* Enable texture coordinate transformation. |
||||||
|
* @see @ref setTextureMatrix() |
||||||
|
* @m_since{2020,06} |
||||||
|
*/ |
||||||
|
TextureTransformation = 1 << 0 |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flags |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* @see @ref flags() |
||||||
|
*/ |
||||||
|
typedef Containers::EnumSet<Flag> Flags; |
||||||
|
#else |
||||||
|
/* Done this way to be prepared for possible future diversion of 2D
|
||||||
|
and 3D flags (e.g. introducing 3D-specific features) */ |
||||||
|
typedef Implementation::VectorGLFlag Flag; |
||||||
|
typedef Implementation::VectorGLFlags Flags; |
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param flags Flags |
||||||
|
*/ |
||||||
|
explicit VectorGL(Flags flags = {}); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct without creating the underlying OpenGL object |
||||||
|
* |
||||||
|
* The constructed instance is equivalent to a moved-from state. Useful |
||||||
|
* in cases where you will overwrite the instance later anyway. Move |
||||||
|
* another object over it to make it useful. |
||||||
|
* |
||||||
|
* This function can be safely used for constructing (and later |
||||||
|
* destructing) objects even without any OpenGL context being active. |
||||||
|
* 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 |
||||||
|
{} |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
VectorGL(const VectorGL<dimensions>&) = delete; |
||||||
|
|
||||||
|
/** @brief Move constructor */ |
||||||
|
VectorGL(VectorGL<dimensions>&&) noexcept = default; |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
VectorGL<dimensions>& operator=(const VectorGL<dimensions>&) = delete; |
||||||
|
|
||||||
|
/** @brief Move assignment */ |
||||||
|
VectorGL<dimensions>& operator=(VectorGL<dimensions>&&) noexcept = default; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flags |
||||||
|
* @m_since{2020,06} |
||||||
|
*/ |
||||||
|
Flags flags() const { return _flags; } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set transformation and projection matrix |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Default is an identity matrix. |
||||||
|
*/ |
||||||
|
VectorGL<dimensions>& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set texture coordinate transformation matrix |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* @m_since{2020,06} |
||||||
|
* |
||||||
|
* Expects that the shader was created with |
||||||
|
* @ref Flag::TextureTransformation enabled. Initial value is an |
||||||
|
* identity matrix. |
||||||
|
*/ |
||||||
|
VectorGL<dimensions>& setTextureMatrix(const Matrix3& matrix); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set background color |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Default is @cpp 0x00000000_rgbaf @ce. |
||||||
|
* @see @ref setColor() |
||||||
|
*/ |
||||||
|
VectorGL<dimensions>& setBackgroundColor(const Color4& color); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set fill color |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Default is @cpp 0xffffffff_rgbaf @ce. |
||||||
|
* @see @ref setBackgroundColor() |
||||||
|
*/ |
||||||
|
VectorGL<dimensions>& setColor(const Color4& color); |
||||||
|
|
||||||
|
#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 |
||||||
|
|
||||||
|
private: |
||||||
|
/* Prevent accidentally calling irrelevant functions */ |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
using GL::AbstractShaderProgram::drawTransformFeedback; |
||||||
|
#endif |
||||||
|
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |
||||||
|
using GL::AbstractShaderProgram::dispatchCompute; |
||||||
|
#endif |
||||||
|
|
||||||
|
Flags _flags; |
||||||
|
Int _transformationProjectionMatrixUniform{0}, |
||||||
|
_textureMatrixUniform{1}, |
||||||
|
_backgroundColorUniform{2}, |
||||||
|
_colorUniform{3}; |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Two-dimensional vector OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
*/ |
||||||
|
typedef VectorGL<2> VectorGL2D; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Three-dimensional vector OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
*/ |
||||||
|
typedef VectorGL<3> VectorGL3D; |
||||||
|
|
||||||
|
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||||
|
/** @debugoperatorclassenum{VectorGL,VectorGL::Flag} */ |
||||||
|
template<UnsignedInt dimensions> Debug& operator<<(Debug& debug, VectorGL<dimensions>::Flag value); |
||||||
|
|
||||||
|
/** @debugoperatorclassenum{VectorGL,VectorGL::Flags} */ |
||||||
|
template<UnsignedInt dimensions> Debug& operator<<(Debug& debug, VectorGL<dimensions>::Flags value); |
||||||
|
#else |
||||||
|
namespace Implementation { |
||||||
|
MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, VectorGLFlag value); |
||||||
|
MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, VectorGLFlags value); |
||||||
|
CORRADE_ENUMSET_OPERATORS(VectorGLFlags) |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,172 @@ |
|||||||
|
#ifndef Magnum_Shaders_VertexColorGL_h |
||||||
|
#define Magnum_Shaders_VertexColorGL_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::VertexColorGL |
||||||
|
* @m_since_latest |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum/DimensionTraits.h" |
||||||
|
#include "Magnum/GL/AbstractShaderProgram.h" |
||||||
|
#include "Magnum/Shaders/GenericGL.h" |
||||||
|
#include "Magnum/Shaders/visibility.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Shaders { |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Vertex color OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
|
||||||
|
Draws a vertex-colored mesh. You need to provide @ref Position and @ref Color3 |
||||||
|
/ @ref Color4 attributes in your triangle mesh. By default, the shader renders |
||||||
|
the mesh in an identity transformation. Use |
||||||
|
@ref setTransformationProjectionMatrix() to configure the shader. |
||||||
|
|
||||||
|
@image html shaders-vertexcolor.png width=256px |
||||||
|
|
||||||
|
This shader is equivalent to @ref FlatGL with @ref FlatGL::Flag::VertexColor |
||||||
|
enabled; the 3D version of this shader is equivalent to @ref PhongGL with |
||||||
|
@ref PhongGL::Flag::VertexColor enabled. In both cases this implementation is |
||||||
|
much simpler and thus likely also faster. |
||||||
|
|
||||||
|
Alpha / transparency is supported by the shader implicitly, but to have it |
||||||
|
working on the framebuffer, you need to enable |
||||||
|
@ref GL::Renderer::Feature::Blending and set up the blending function. See |
||||||
|
@ref GL::Renderer::setBlendFunction() for details. |
||||||
|
|
||||||
|
@section Shaders-VertexColorGL-example Example usage |
||||||
|
|
||||||
|
Common mesh setup. The shader accepts either three- or four-component color |
||||||
|
attribute, use either @ref Color3 or @ref Color4 to specify which one you use. |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp VertexColorGL-usage1 |
||||||
|
|
||||||
|
Common rendering setup: |
||||||
|
|
||||||
|
@snippet MagnumShaders-gl.cpp VertexColorGL-usage2 |
||||||
|
|
||||||
|
@see @ref shaders, @ref VertexColorGL2D, @ref VertexColorGL3D |
||||||
|
*/ |
||||||
|
template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT VertexColorGL: 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 Three-component vertex color |
||||||
|
* |
||||||
|
* @ref shaders-generic "Generic attribute", @ref Magnum::Color3. Use |
||||||
|
* either this or the @ref Color4 attribute. |
||||||
|
*/ |
||||||
|
typedef typename GenericGL<dimensions>::Color3 Color3; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Four-component vertex color |
||||||
|
* |
||||||
|
* @ref shaders-generic "Generic attribute", @ref Magnum::Color4. Use |
||||||
|
* either this or the @ref Color3 attribute. |
||||||
|
*/ |
||||||
|
typedef typename GenericGL<dimensions>::Color4 Color4; |
||||||
|
|
||||||
|
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 |
||||||
|
}; |
||||||
|
|
||||||
|
explicit VertexColorGL(); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct without creating the underlying OpenGL object |
||||||
|
* |
||||||
|
* The constructed instance is equivalent to a moved-from state. Useful |
||||||
|
* in cases where you will overwrite the instance later anyway. Move |
||||||
|
* another object over it to make it useful. |
||||||
|
* |
||||||
|
* This function can be safely used for constructing (and later |
||||||
|
* destructing) objects even without any OpenGL context being active. |
||||||
|
* However note that this is a low-level and a potentially dangerous |
||||||
|
* API, see the documentation of @ref NoCreate for alternatives. |
||||||
|
*/ |
||||||
|
explicit VertexColorGL(NoCreateT) noexcept: AbstractShaderProgram{NoCreate} {} |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
VertexColorGL(const VertexColorGL<dimensions>&) = delete; |
||||||
|
|
||||||
|
/** @brief Move constructor */ |
||||||
|
VertexColorGL(VertexColorGL<dimensions>&&) noexcept = default; |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
VertexColorGL<dimensions>& operator=(const VertexColorGL<dimensions>&) = delete; |
||||||
|
|
||||||
|
/** @brief Move assignment */ |
||||||
|
VertexColorGL<dimensions>& operator=(VertexColorGL<dimensions>&&) noexcept = default; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set transformation and projection matrix |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* Default is an identity matrix. |
||||||
|
*/ |
||||||
|
VertexColorGL<dimensions>& setTransformationProjectionMatrix(const MatrixTypeFor<dimensions, Float>& matrix); |
||||||
|
|
||||||
|
private: |
||||||
|
/* Prevent accidentally calling irrelevant functions */ |
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
using GL::AbstractShaderProgram::drawTransformFeedback; |
||||||
|
#endif |
||||||
|
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) |
||||||
|
using GL::AbstractShaderProgram::dispatchCompute; |
||||||
|
#endif |
||||||
|
|
||||||
|
Int _transformationProjectionMatrixUniform{0}; |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief 2D vertex color OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
*/ |
||||||
|
typedef VertexColorGL<2> VertexColorGL2D; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief 3D vertex color OpenGL shader |
||||||
|
@m_since_latest |
||||||
|
*/ |
||||||
|
typedef VertexColorGL<3> VertexColorGL3D; |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -1,4 +1,4 @@ |
|||||||
group=MagnumShaders |
group=MagnumShadersGL |
||||||
|
|
||||||
[file] |
[file] |
||||||
filename=AbstractVector.vert |
filename=AbstractVector.vert |
||||||
Loading…
Reference in new issue