Browse Source

Shaders: rethink generic attribute allocation from scratch.

This adds binormals, object IDs and instanced transformation, but has to
break existing locations in order to provide new guarantees.
pull/430/head
Vladimír Vondruš 6 years ago
parent
commit
f3a92c2afb
  1. 18
      doc/changelog.dox
  2. 333
      src/Magnum/Shaders/Generic.h
  3. 7
      src/Magnum/Shaders/MeshVisualizer.h
  4. 2
      src/Magnum/Shaders/MeshVisualizer.vert
  5. 1
      src/Magnum/Shaders/Test/CMakeLists.txt
  6. 116
      src/Magnum/Shaders/Test/GenericTest.cpp
  7. 17
      src/Magnum/Shaders/Test/MeshVisualizerTest.cpp
  8. 14
      src/Magnum/Shaders/generic.glsl
  9. 7
      src/Magnum/Trade/MeshData.h

18
doc/changelog.dox

@ -197,6 +197,12 @@ See also:
- Texture coordinate transformation in @ref Shaders::DistanceFieldVector,
@ref Shaders::Flat, @ref Shaders::Phong and @ref Shaders::Vector
- New attribute definitions and an location allocation scheme in
@ref Shaders::Generic --- @ref Shaders::Generic::Tangent4,
@ref Shaders::Generic::Bitangent, @ref Shaders::Generic::ObjectId plus
@ref Shaders::Generic::TransformationMatrix,
@ref Shaders::Generic::NormalMatrix and
@ref Shaders::Generic::TextureOffset for instancing
@subsubsection changelog-latest-new-trade Trade library
@ -515,6 +521,18 @@ See also:
was deprecated in 2019.10 is now removed. Usually a deprecated feature is
kept for at least a year before removal, but in this case it was severely
limiting multithreaded applications and removing it was necessary.
- Locations of generic shader attributes was changed in order to accomodate
for new attributes and use cases. This may break custom shaders if these
rely on generic attribute definitions or are used together with
@ref MeshTools::compile(). To avoid further breakages you're advised to
reuse the definitions from @ref Shaders::Generic (and propagating them to
shader code as well) instead of hardcoding the locations directly.
- @ref Shaders::Generic::Color3 / @ref Shaders::Generic::Color4 location
changed from @cpp 3 @ce to @cpp 2 @ce
- @ref Shaders::Generic::Normal location changed from @cpp 2 @ce to
@cpp 5 @ce
- @ref Shaders::Generic::Tangent location changed from @cpp 4 @ce to
@cpp 3 @ce
- Removed remaining APIs deprecated in version 2018.04:
- @cpp Audio::Buffer::Format @ce, use @ref Audio::BufferFormat instead
- @cpp Shaders::*Vector::setVectorTexture() @ce,

333
src/Magnum/Shaders/Generic.h

@ -43,6 +43,191 @@ namespace Magnum { namespace Shaders {
Definitions common for majority of 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-Generic-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).
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.
@see @ref shaders, @ref Generic2D, @ref Generic3D
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
@ -70,10 +255,6 @@ template<UnsignedInt dimensions> struct Generic {
#endif
};
/* Index 5 used by MeshVisualizer::VertexIndex. Update
MeshVisualizerTest::vertexIndexNoConflict() when adding new attributes
here. */
/**
* @brief Vertex position
*
@ -91,36 +272,124 @@ template<UnsignedInt dimensions> struct Generic {
typedef GL::Attribute<1, Vector2> TextureCoordinates;
/**
* @brief Vertex normal
* @brief Three-component vertex color
*
* @ref Magnum::Vector3 "Vector3", defined only in 3D. Corresponds to
* @ref Trade::MeshAttribute::Normal.
* @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, Vector3> Normal;
typedef GL::Attribute<2, Magnum::Color4> Color4;
/**
* @brief Vertex tangent
* @m_since{2019,10}
*
* @ref Magnum::Vector3 "Vector3", defined only in 3D.
* @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<4, Vector3> Tangent;
typedef GL::Attribute<3, Vector3> Tangent;
/**
* @brief Three-component vertex color.
* @brief Vertex tangent with a bitangent sign
* @m_since_latest
*
* @ref Magnum::Color3. Use either this or the @ref Color4 attribute.
* Corresponds to @ref Trade::MeshAttribute::Color.
* @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, Magnum::Color3> Color3;
typedef GL::Attribute<3, Vector4> Tangent4;
/**
* @brief Four-component vertex color.
* @brief Vertex bitangent
* @m_since_latest
*
* @ref Magnum::Color4. Use either this or the @ref Color3 attribute.
* Corresponds to @ref Trade::MeshAttribute::Color.
* @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<3, Magnum::Color4> Color4;
typedef GL::Attribute<4, Vector3> Bitangent;
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief (Instanced) object ID
* @m_since_latest
*
* @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_gles30 Object ID output requires integer attributes, which are
* 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_latest
*
* @ref Magnum::Matrix3 "Matrix3" in 2D and @ref Magnum::Matrix4 "Matrix4"
* in 3D. Currently doesn't have a corresponding @ref Trade::MeshAttribute.
*/
typedef GL::Attribute<8, T> TransformationMatrix;
/* 9, 10, 11 occupied by TransformationMatrix */
/**
* @brief (Instanced) normal matrix
* @m_since_latest
*
* @ref Magnum::Matrix3 "Matrix3x3", defined only in 3D. Currently doesn't
* have a corresponding @ref Trade::MeshAttribute.
*/
typedef GL::Attribute<12, Matrix3x3> NormalMatrix;
/* 13, 14 occupied by NormalMatrix */
/**
* @brief (Instanced) texture offset
* @m_since_latest
*
* @ref Magnum::Vector2 "Vector2". Currently doesn't have a corresponding
* @ref Trade::MeshAttribute.
*/
typedef GL::Attribute<15, Vector2> TextureOffset;
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@ -163,8 +432,13 @@ struct BaseGeneric {
};
typedef GL::Attribute<1, Vector2> TextureCoordinates;
typedef GL::Attribute<3, Magnum::Color3> Color3;
typedef GL::Attribute<3, Magnum::Color4> Color4;
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;
#ifdef MAGNUM_BUILD_DEPRECATED
struct Color: GL::Attribute<3, Magnum::Color4> {
@ -177,12 +451,27 @@ struct BaseGeneric {
template<> struct Generic<2>: BaseGeneric {
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 Generic<3>: BaseGeneric {
typedef GL::Attribute<0, Vector3> Position;
typedef GL::Attribute<2, Vector3> Normal;
typedef GL::Attribute<4, Vector3> Tangent;
/* 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

7
src/Magnum/Shaders/MeshVisualizer.h

@ -124,8 +124,13 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public GL::AbstractShaderProgram {
* 3.1, OpenGL ES 3.0 and newer this value is provided via the
* @cb{.glsl} gl_VertexID @ce shader builtin, so the attribute is not
* needed.
*
* @note This attribute uses the same slot as @ref Generic::ObjectId,
* but since Object ID is available only on ES3+ and vertex index
* is used only on ES2 contexts without @glsl gl_VertexID @ce,
* there should be no conflict between these two.
*/
typedef GL::Attribute<5, Float> VertexIndex;
typedef GL::Attribute<4, Float> VertexIndex;
enum: UnsignedInt {
/**

2
src/Magnum/Shaders/MeshVisualizer.vert

@ -45,7 +45,7 @@ in highp vec4 position;
#if defined(WIREFRAME_RENDERING) && defined(NO_GEOMETRY_SHADER)
#if (!defined(GL_ES) && __VERSION__ < 140) || (defined(GL_ES) && __VERSION__ < 300)
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = 5)
layout(location = 4)
#endif
in lowp float vertexIndex;
#define gl_VertexID int(vertexIndex)

1
src/Magnum/Shaders/Test/CMakeLists.txt

@ -25,6 +25,7 @@
corrade_add_test(ShadersDistanceFieldVectorTest DistanceFieldVectorTest.cpp LIBRARIES MagnumShaders)
corrade_add_test(ShadersFlatTest FlatTest.cpp LIBRARIES MagnumShaders)
corrade_add_test(ShadersGenericTest GenericTest.cpp LIBRARIES MagnumShaders)
corrade_add_test(ShadersMeshVisualizerTest MeshVisualizerTest.cpp LIBRARIES MagnumShaders)
corrade_add_test(ShadersPhongTest PhongTest.cpp LIBRARIES MagnumShaders)
corrade_add_test(ShadersVectorTest VectorTest.cpp LIBRARIES MagnumShaders)

116
src/Magnum/Shaders/Test/GenericTest.cpp

@ -0,0 +1,116 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
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)

17
src/Magnum/Shaders/Test/MeshVisualizerTest.cpp

@ -37,7 +37,7 @@ struct MeshVisualizerTest: TestSuite::Tester {
void constructNoCreate();
void constructCopy();
void vertexIndexNoConflict();
void vertexIndexSameAsObjectId();
void debugFlag();
void debugFlags();
@ -47,7 +47,7 @@ MeshVisualizerTest::MeshVisualizerTest() {
addTests({&MeshVisualizerTest::constructNoCreate,
&MeshVisualizerTest::constructCopy,
&MeshVisualizerTest::vertexIndexNoConflict,
&MeshVisualizerTest::vertexIndexSameAsObjectId,
&MeshVisualizerTest::debugFlag,
&MeshVisualizerTest::debugFlags});
@ -67,13 +67,12 @@ void MeshVisualizerTest::constructCopy() {
CORRADE_VERIFY(!(std::is_assignable<MeshVisualizer, const MeshVisualizer&>{}));
}
void MeshVisualizerTest::vertexIndexNoConflict() {
CORRADE_VERIFY(MeshVisualizer::VertexIndex::Location != UnsignedInt(Generic3D::Position::Location));
CORRADE_VERIFY(MeshVisualizer::VertexIndex::Location != UnsignedInt(Generic3D::Normal::Location));
CORRADE_VERIFY(MeshVisualizer::VertexIndex::Location != UnsignedInt(Generic3D::TextureCoordinates::Location));
CORRADE_VERIFY(MeshVisualizer::VertexIndex::Location != UnsignedInt(Generic3D::Color3::Location));
CORRADE_VERIFY(MeshVisualizer::VertexIndex::Location != UnsignedInt(Generic3D::Color4::Location));
CORRADE_VERIFY(MeshVisualizer::VertexIndex::Location != UnsignedInt(Generic3D::Tangent::Location));
void MeshVisualizerTest::vertexIndexSameAsObjectId() {
#ifdef MAGNUM_TARGET_GLES2
CORRADE_SKIP("Object ID is not available on ES2.");
#else
CORRADE_COMPARE(MeshVisualizer::VertexIndex::Location, Generic3D::ObjectId::Location);
#endif
}
void MeshVisualizerTest::debugFlag() {

14
src/Magnum/Shaders/generic.glsl

@ -23,13 +23,19 @@
DEALINGS IN THE SOFTWARE.
*/
/* Keep consistent with Generic.h */
/* Kept consistent with Generic.h (tested in ShadersGenericTest) */
#define POSITION_ATTRIBUTE_LOCATION 0
#define TEXTURECOORDINATES_ATTRIBUTE_LOCATION 1
#define NORMAL_ATTRIBUTE_LOCATION 2
#define COLOR_ATTRIBUTE_LOCATION 3
#define TANGENT_ATTRIBUTE_LOCATION 4
#define COLOR_ATTRIBUTE_LOCATION 2
#define TANGENT_ATTRIBUTE_LOCATION 3
#define BITANGENT_ATTRIBUTE_LOCATION 4 /* also ObjectId */
#define OBJECT_ID_ATTRIBUTE_LOCATION 4 /* also Bitangent */
#define NORMAL_ATTRIBUTE_LOCATION 5
#define TRANSFORMATION_MATRIX_ATTRIBUTE_LOCATION 8
#define NORMAL_MATRIX_ATTRIBUTE_LOCATION 12
#define TEXTURE_OFFSET_ATTRIBUTE_LOCATION 15
/* Outputs */
#define COLOR_OUTPUT_ATTRIBUTE_LOCATION 0

7
src/Magnum/Trade/MeshData.h

@ -86,7 +86,8 @@ enum class MeshAttribute: UnsignedShort {
*
* @snippet MagnumTrade.cpp MeshAttribute-bitangent-from-tangent
*
* Corresponds to @ref Shaders::Generic::Tangent.
* Corresponds to @ref Shaders::Generic::Tangent or
* @ref Shaders::Generic::Tangent4.
* @see @ref MeshData::tangentsAsArray(),
* @ref MeshData::bitangentSignsAsArray()
*/
@ -97,7 +98,8 @@ enum class MeshAttribute: UnsignedShort {
* @ref VertexFormat::Vector3h, @ref VertexFormat::Vector3bNormalized or
* @ref VertexFormat::Vector3sNormalized. For better storage efficiency,
* the bitangent can be also reconstructed from the normal and tangent, see
* @ref MeshAttribute::Tangent for more information.
* @ref MeshAttribute::Tangent for more information. Corresponds to
* @ref Shaders::Generic::Bitangent.
* @see @ref MeshData::bitangentsAsArray()
*/
Bitangent,
@ -140,6 +142,7 @@ enum class MeshAttribute: UnsignedShort {
* (Instanced) object ID for editor selection or scene annotation. Type is
* usually @ref VertexFormat::UnsignedInt, but can be also
* @ref VertexFormat::UnsignedShort or @ref VertexFormat::UnsignedByte.
* Corresponds to @ref Shaders::Generic::ObjectId.
* @see @ref MeshData::objectIdsAsArray()
*/
ObjectId,

Loading…
Cancel
Save