Browse Source

Shaders: implement object ID texture visualization in MeshVisualizer.

Hah this took a while, as there was no texture scaffolding in place at
all. Thus all this had to be added and tested for the first time:

 * 2D textures
 * 2D texture arrays
 * Texture transformation uniforms
 * Texture transformation UBOs
 * Instanced texture offset

This also means that MeshVisualizer can be used to visualize arbitrary
(single-channel) integer textures now, not just render meshes with
object ID textures. Yay for feature parity!
pull/547/head
Vladimír Vondruš 4 years ago
parent
commit
ef387bf6c5
  1. 4
      doc/changelog.dox
  2. 2
      src/Magnum/Shaders/FlatGL.cpp
  3. 28
      src/Magnum/Shaders/MeshVisualizer.frag
  4. 23
      src/Magnum/Shaders/MeshVisualizer.geom
  5. 124
      src/Magnum/Shaders/MeshVisualizer.vert
  6. 158
      src/Magnum/Shaders/MeshVisualizerGL.cpp
  7. 441
      src/Magnum/Shaders/MeshVisualizerGL.h
  8. 2
      src/Magnum/Shaders/PhongGL.cpp
  9. 12
      src/Magnum/Shaders/Test/CMakeLists.txt
  10. 998
      src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp
  11. 36
      src/Magnum/Shaders/Test/MeshVisualizerGL_Test.cpp
  12. BIN
      src/Magnum/Shaders/Test/MeshVisualizerTestFiles/instanced-instancedobjectidtexture2D.tga
  13. BIN
      src/Magnum/Shaders/Test/MeshVisualizerTestFiles/instanced-instancedobjectidtexture3D.tga
  14. BIN
      src/Magnum/Shaders/Test/MeshVisualizerTestFiles/instanced-objectidtexture2D.tga
  15. BIN
      src/Magnum/Shaders/Test/MeshVisualizerTestFiles/instanced-objectidtexture3D.tga
  16. BIN
      src/Magnum/Shaders/Test/MeshVisualizerTestFiles/multidraw-objectidtexture2D.tga
  17. BIN
      src/Magnum/Shaders/Test/MeshVisualizerTestFiles/multidraw-objectidtexture3D.tga
  18. BIN
      src/Magnum/Shaders/Test/MeshVisualizerTestFiles/objectidtexture2D.tga
  19. BIN
      src/Magnum/Shaders/Test/MeshVisualizerTestFiles/objectidtexture3D.tga
  20. BIN
      src/Magnum/Shaders/Test/MeshVisualizerTestFiles/wireframe-objectidtexture2D.tga
  21. BIN
      src/Magnum/Shaders/Test/MeshVisualizerTestFiles/wireframe-objectidtexture3D.tga

4
doc/changelog.dox

@ -207,6 +207,10 @@ See also:
available also in multi-draw and instanced scenarios
- @ref Shaders::FlatGL and @ref Shaders::PhongGL now support object ID
textures in addition to uniform and per-vertex object ID
- @ref Shaders::MeshVisualizerGL2D and @ref Shaders::MeshVisualizerGL3D now
supports object ID textures same as @ref Shaders::FlatGL and
@ref Shaders::PhongGL, including also support for object ID texture
transformation, instanced texture offset and texture arrays
- Support for instanced drawing in @ref Shaders::MeshVisualizerGL2D and
@ref Shaders::MeshVisualizerGL3D for better feature parity with the other
sahders

2
src/Magnum/Shaders/FlatGL.cpp

@ -52,7 +52,7 @@ namespace {
enum: Int {
TextureUnit = 0,
/* 1/2/3 taken by Phong (D/S/N), 4 by MeshVisualizer colormap */
ObjectIdTextureUnit = 5 /* shared with Phong */
ObjectIdTextureUnit = 5 /* shared with Phong and MeshVisualizer */
};
#ifndef MAGNUM_TARGET_GLES2

28
src/Magnum/Shaders/MeshVisualizer.frag

@ -74,7 +74,7 @@ uniform lowp float wireframeWidth
;
#elif defined(TBN_DIRECTION)
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 10)
layout(location = 12)
#endif
uniform lowp float lineWidth
#ifndef GL_ES
@ -191,8 +191,31 @@ layout(binding = 4)
uniform lowp sampler2D colorMapTexture;
#endif
#ifdef OBJECT_ID_TEXTURE
#ifdef EXPLICIT_BINDING
layout(binding = 5)
#endif
uniform lowp
#ifndef TEXTURE_ARRAYS
usampler2D
#else
usampler2DArray
#endif
objectIdTextureData;
#endif
/* Inputs */
#ifdef OBJECT_ID_TEXTURE
in mediump
#ifndef TEXTURE_ARRAYS
vec2
#else
vec3
#endif
interpolatedTextureCoordinates;
#endif
#if defined(WIREFRAME_RENDERING) || defined(TBN_DIRECTION)
#ifndef NO_GEOMETRY_SHADER
#if !defined(GL_ES) || defined(GL_NV_shader_noperspective_interpolation)
@ -274,6 +297,9 @@ void main() {
#ifdef INSTANCED_OBJECT_ID
+ interpolatedInstanceObjectId
#endif
#ifdef OBJECT_ID_TEXTURE
+ texture(objectIdTextureData, interpolatedTextureCoordinates).r
#endif
#elif defined(PRIMITIVE_ID)
gl_PrimitiveID
#elif defined(PRIMITIVE_ID_FROM_VERTEX_ID)

23
src/Magnum/Shaders/MeshVisualizer.geom

@ -66,7 +66,7 @@ uniform lowp vec4 wireframeColor
#if defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(NORMAL_DIRECTION)
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 10)
layout(location = 12)
#endif
uniform lowp float lineWidth
#ifndef GL_ES
@ -160,6 +160,15 @@ in highp vec4 bitangentEndpoint[];
in highp vec4 normalEndpoint[];
#endif
#ifdef TEXTURED
in mediump
#ifndef TEXTURE_ARRAYS
vec2
#else
vec3
#endif
interpolatedVsTextureCoordinates[];
#endif
#ifdef INSTANCED_OBJECT_ID
flat in highp uint interpolatedVsInstanceObjectId[];
#endif
@ -184,6 +193,15 @@ noperspective
#endif
out lowp vec3 dist;
#ifdef TEXTURED
out mediump
#ifndef TEXTURE_ARRAYS
vec2
#else
vec3
#endif
interpolatedTextureCoordinates;
#endif
#ifdef INSTANCED_OBJECT_ID
flat out highp uint interpolatedInstanceObjectId;
#endif
@ -346,6 +364,9 @@ void main() {
#ifdef VERTEX_ID
interpolatedMappedVertexId = interpolatedVsMappedVertexId[i];
#endif
#ifdef TEXTURED
interpolatedTextureCoordinates = interpolatedVsTextureCoordinates[i];
#endif
#if defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(NORMAL_DIRECTION)
backgroundColor = color;
lineColor = wireframeColor;

124
src/Magnum/Shaders/MeshVisualizer.vert

@ -27,6 +27,10 @@
#extension GL_EXT_gpu_shader4: require
#endif
#if defined(UNIFORM_BUFFERS) && defined(TEXTURE_ARRAYS) && !defined(GL_ES)
#extension GL_ARB_shader_bit_encoding: require
#endif
#ifdef MULTI_DRAW
#ifndef GL_ES
#extension GL_ARB_shader_draw_parameters: require
@ -49,7 +53,7 @@
#ifndef UNIFORM_BUFFERS
#ifdef TWO_DIMENSIONS
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 7)
layout(location = 9)
#endif
uniform highp mat3 transformationProjectionMatrix
#ifndef GL_ES
@ -58,7 +62,7 @@ uniform highp mat3 transformationProjectionMatrix
;
#elif defined(THREE_DIMENSIONS)
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 7)
layout(location = 9)
#endif
uniform highp mat4 transformationMatrix
#ifndef GL_ES
@ -66,7 +70,7 @@ uniform highp mat4 transformationMatrix
#endif
;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 8)
layout(location = 10)
#endif
uniform highp mat4 projectionMatrix
#ifndef GL_ES
@ -92,7 +96,7 @@ uniform lowp vec2 colorMapOffsetScale
#if defined(TANGENT_DIRECTION) || defined(BITANGENT_FROM_TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(NORMAL_DIRECTION)
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 9)
layout(location = 11)
#endif
uniform highp mat3 normalMatrix
#ifndef GL_ES
@ -101,7 +105,7 @@ uniform highp mat3 normalMatrix
;
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 11)
layout(location = 13)
#endif
uniform highp float lineLength
#ifndef GL_ES
@ -110,6 +114,25 @@ uniform highp float lineLength
;
#endif
#ifdef TEXTURE_TRANSFORMATION
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 7)
#endif
uniform mediump mat3 textureMatrix
#ifndef GL_ES
= mat3(1.0)
#endif
;
#endif
#ifdef TEXTURE_ARRAYS
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 8)
#endif
/* mediump is just 2^10, which might not be enough, this is 2^16 */
uniform highp uint textureLayer; /* defaults to zero */
#endif
/* Uniform buffers */
#else
@ -156,6 +179,23 @@ layout(std140
#error
#endif
#ifdef TEXTURE_TRANSFORMATION
struct TextureTransformationUniform {
highp vec4 rotationScaling;
highp vec4 offsetLayerReserved;
#define textureTransformation_offset offsetLayerReserved.xy
#define textureTransformation_layer offsetLayerReserved.z
};
layout(std140
#ifdef EXPLICIT_BINDING
, binding = 3
#endif
) uniform TextureTransformation {
TextureTransformationUniform textureTransformations[DRAW_COUNT];
};
#endif
/* Keep in sync with MeshVisualizer.geom and MeshVisualizer.frag. Can't
"outsource" to a common file because the #extension directives need to be
always before any code. */
@ -238,6 +278,26 @@ layout(location = NORMAL_ATTRIBUTE_LOCATION)
in highp vec3 normal;
#endif
#ifdef TEXTURED
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = TEXTURECOORDINATES_ATTRIBUTE_LOCATION)
#endif
in mediump vec2 textureCoordinates;
#endif
#ifdef INSTANCED_TEXTURE_OFFSET
#ifdef EXPLICIT_ATTRIB_LOCATION
layout(location = TEXTURE_OFFSET_ATTRIBUTE_LOCATION)
#endif
in mediump
#ifndef TEXTURE_ARRAYS
vec2
#else
vec3
#endif
instancedTextureOffset;
#endif
#if defined(WIREFRAME_RENDERING) && defined(NO_GEOMETRY_SHADER)
#if (!defined(GL_ES) && __VERSION__ < 140) || (defined(GL_ES) && __VERSION__ < 300)
#ifdef EXPLICIT_ATTRIB_LOCATION
@ -277,6 +337,21 @@ in highp mat3 instancedNormalMatrix;
/* Outputs */
#ifdef TEXTURED
out mediump
#ifndef TEXTURE_ARRAYS
vec2
#else
vec3
#endif
#ifdef NO_GEOMETRY_SHADER
interpolatedTextureCoordinates
#else
interpolatedVsTextureCoordinates
#endif
;
#endif
#if defined(WIREFRAME_RENDERING) && defined(NO_GEOMETRY_SHADER)
out vec3 barycentric;
#endif
@ -359,6 +434,12 @@ void main() {
lowp float colorMapOffset = materials[materialId].material_colorMapOffset;
lowp float colorMapScale = materials[materialId].material_colorMapScale;
highp float lineLength = materials[materialId].material_lineLength;
#ifdef TEXTURE_TRANSFORMATION
mediump const mat3 textureMatrix = mat3(textureTransformations[drawId].rotationScaling.xy, 0.0, textureTransformations[drawId].rotationScaling.zw, 0.0, textureTransformations[drawId].textureTransformation_offset, 1.0);
#ifdef TEXTURE_ARRAYS
highp const uint textureLayer = floatBitsToUint(textureTransformations[drawId].textureTransformation_layer);
#endif
#endif
#endif
#ifdef TWO_DIMENSIONS
@ -398,6 +479,39 @@ void main() {
normalEndpoint = projectionMatrix*(transformedPosition4 + vec4(normalize(finalNormalMatrix*normal)*lineLength, 0.0));
#endif
#ifdef TEXTURED
/* Texture coordinates, if needed */
#ifdef NO_GEOMETRY_SHADER
interpolatedTextureCoordinates
#else
interpolatedVsTextureCoordinates
#endif
.xy =
#ifdef TEXTURE_TRANSFORMATION
(textureMatrix*vec3(
#ifdef INSTANCED_TEXTURE_OFFSET
instancedTextureOffset.xy +
#endif
textureCoordinates, 1.0)).xy
#else
textureCoordinates
#endif
;
#ifdef TEXTURE_ARRAYS
#ifdef NO_GEOMETRY_SHADER
interpolatedTextureCoordinates
#else
interpolatedVsTextureCoordinates
#endif
.z = float(
#ifdef INSTANCED_TEXTURE_OFFSET
uint(instancedTextureOffset.z) +
#endif
textureLayer
);
#endif
#endif
#if defined(WIREFRAME_RENDERING) && defined(NO_GEOMETRY_SHADER)
barycentric = vec3(0.0);

158
src/Magnum/Shaders/MeshVisualizerGL.cpp

@ -41,6 +41,7 @@
#ifndef MAGNUM_TARGET_GLES2
#include "Magnum/GL/Buffer.h"
#include "Magnum/GL/TextureArray.h"
#endif
#include "Magnum/Shaders/Implementation/CreateCompatibilityShader.h"
@ -50,7 +51,8 @@ namespace Magnum { namespace Shaders {
namespace {
enum: Int {
/* First four taken by Phong (A/D/S/N) */
ColorMapTextureUnit = 4
ColorMapTextureUnit = 4,
ObjectIdTextureUnit = 5 /* shared with Flat and Phong */
};
#ifndef MAGNUM_TARGET_GLES2
@ -62,8 +64,7 @@ namespace {
TransformationProjectionBufferBinding = 1,
TransformationBufferBinding = 1,
DrawBufferBinding = 2,
/* Binding 3 is commonly used by TextureTransformationBufferBinding,
leave it reserved */
TextureTransformationBufferBinding = 3,
MaterialBufferBinding = 4,
};
#endif
@ -93,6 +94,15 @@ MeshVisualizerGLBase::MeshVisualizerGLBase(FlagsBase flags
"Shaders::MeshVisualizerGL: Flag::ObjectId, Flag::VertexId and Flag::PrimitiveId are mutually exclusive", );
#endif
#ifndef MAGNUM_TARGET_GLES2
CORRADE_ASSERT(!(flags & FlagBase::TextureTransformation) || flags >= FlagBase::ObjectIdTexture,
"Shaders::MeshVisualizerGL: texture transformation enabled but the shader is not textured", );
CORRADE_ASSERT(!(flags & FlagBase::TextureArrays) || flags >= FlagBase::ObjectIdTexture,
"Shaders::MeshVisualizerGL: texture arrays enabled but the shader is not textured", );
CORRADE_ASSERT(!(flags & FlagBase::UniformBuffers) || !(flags & FlagBase::TextureArrays) || flags >= (FlagBase::TextureArrays|FlagBase::TextureTransformation),
"Shaders::MeshVisualizerGL: texture arrays require texture transformation enabled as well if uniform buffers are used", );
#endif
#ifndef MAGNUM_TARGET_GLES
if(flags >= FlagBase::UniformBuffers)
MAGNUM_ASSERT_GL_EXTENSION_SUPPORTED(GL::Extensions::ARB::uniform_buffer_object);
@ -161,10 +171,14 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
vert.addSource(_flags & FlagBase::Wireframe ? "#define WIREFRAME_RENDERING\n" : "")
#ifndef MAGNUM_TARGET_GLES2
.addSource(_flags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "")
.addSource(_flags & FlagBase::TextureTransformation ? "#define TEXTURE_TRANSFORMATION\n" : "")
.addSource(_flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "")
.addSource(_flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "")
#endif
.addSource(_flags & FlagBase::InstancedTransformation ? "#define INSTANCED_TRANSFORMATION\n" : "")
#ifndef MAGNUM_TARGET_GLES2
.addSource(_flags >= FlagBase::InstancedTextureOffset ? "#define INSTANCED_TEXTURE_OFFSET\n" : "")
.addSource(_flags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "")
.addSource(_flags >= FlagBase::PrimitiveIdFromVertexId ? "#define PRIMITIVE_ID_FROM_VERTEX_ID\n" : "")
#endif
@ -189,6 +203,8 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
frag.addSource(_flags & FlagBase::Wireframe ? "#define WIREFRAME_RENDERING\n" : "")
#ifndef MAGNUM_TARGET_GLES2
.addSource(_flags & FlagBase::ObjectId ? "#define OBJECT_ID\n" : "")
.addSource(_flags >= FlagBase::ObjectIdTexture ? "#define OBJECT_ID_TEXTURE\n" : "")
.addSource(_flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "")
.addSource(_flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "")
.addSource(_flags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "")
.addSource(_flags & FlagBase::PrimitiveId ?
@ -213,6 +229,26 @@ GL::Version MeshVisualizerGLBase::setupShaders(GL::Shader& vert, GL::Shader& fra
}
#ifndef MAGNUM_TARGET_GLES2
MeshVisualizerGLBase& MeshVisualizerGLBase::setTextureMatrix(const Matrix3& matrix) {
#ifndef MAGNUM_TARGET_GLES2
CORRADE_ASSERT(!(_flags >= FlagBase::UniformBuffers),
"Shaders::MeshVisualizerGL::setTextureMatrix(): the shader was created with uniform buffers enabled", *this);
#endif
CORRADE_ASSERT(_flags & FlagBase::TextureTransformation,
"Shaders::MeshVisualizerGL::setTextureMatrix(): the shader was not created with texture transformation enabled", *this);
setUniform(_textureMatrixUniform, matrix);
return *this;
}
MeshVisualizerGLBase& MeshVisualizerGLBase::setTextureLayer(UnsignedInt id) {
CORRADE_ASSERT(!(_flags >= FlagBase::UniformBuffers),
"Shaders::MeshVisualizerGL::setTextureLayer(): the shader was created with uniform buffers enabled", *this);
CORRADE_ASSERT(_flags & FlagBase::TextureArrays,
"Shaders::MeshVisualizerGL::setTextureLayer(): the shader was not created with texture arrays enabled", *this);
setUniform(_textureLayerUniform, id);
return *this;
}
MeshVisualizerGLBase& MeshVisualizerGLBase::setObjectId(UnsignedInt id) {
CORRADE_ASSERT(!(_flags >= FlagBase::UniformBuffers),
"Shaders::MeshVisualizerGL::setObjectId(): the shader was created with uniform buffers enabled", *this);
@ -282,6 +318,24 @@ MeshVisualizerGLBase& MeshVisualizerGLBase::setDrawOffset(const UnsignedInt offs
return *this;
}
MeshVisualizerGLBase& MeshVisualizerGLBase::bindTextureTransformationBuffer(GL::Buffer& buffer) {
CORRADE_ASSERT(_flags >= FlagBase::UniformBuffers,
"Shaders::MeshVisualizerGL::bindTextureTransformationBuffer(): the shader was not created with uniform buffers enabled", *this);
CORRADE_ASSERT(_flags & FlagBase::TextureTransformation,
"Shaders::MeshVisualizerGL::bindTextureTransformationBuffer(): the shader was not created with texture transformation enabled", *this);
buffer.bind(GL::Buffer::Target::Uniform, TextureTransformationBufferBinding);
return *this;
}
MeshVisualizerGLBase& MeshVisualizerGLBase::bindTextureTransformationBuffer(GL::Buffer& buffer, const GLintptr offset, const GLsizeiptr size) {
CORRADE_ASSERT(_flags >= FlagBase::UniformBuffers,
"Shaders::MeshVisualizerGL::bindTextureTransformationBuffer(): the shader was not created with uniform buffers enabled", *this);
CORRADE_ASSERT(_flags & FlagBase::TextureTransformation,
"Shaders::MeshVisualizerGL::bindTextureTransformationBuffer(): the shader was not created with texture transformation enabled", *this);
buffer.bind(GL::Buffer::Target::Uniform, TextureTransformationBufferBinding, offset, size);
return *this;
}
MeshVisualizerGLBase& MeshVisualizerGLBase::bindMaterialBuffer(GL::Buffer& buffer) {
CORRADE_ASSERT(_flags >= FlagBase::UniformBuffers,
"Shaders::MeshVisualizerGL::bindMaterialBuffer(): the shader was not created with uniform buffers enabled", *this);
@ -304,6 +358,26 @@ MeshVisualizerGLBase& MeshVisualizerGLBase::bindColorMapTexture(GL::Texture2D& t
texture.bind(ColorMapTextureUnit);
return *this;
}
MeshVisualizerGLBase& MeshVisualizerGLBase::bindObjectIdTexture(GL::Texture2D& texture) {
CORRADE_ASSERT(_flags >= FlagBase::ObjectIdTexture,
"Shaders::MeshVisualizerGL::bindObjectIdTexture(): the shader was not created with object ID texture enabled", *this);
#ifndef MAGNUM_TARGET_GLES2
CORRADE_ASSERT(!(_flags & FlagBase::TextureArrays),
"Shaders::MeshVisualizerGL::bindObjectIdTexture(): the shader was created with texture arrays enabled, use a Texture2DArray instead", *this);
#endif
texture.bind(ObjectIdTextureUnit);
return *this;
}
MeshVisualizerGLBase& MeshVisualizerGLBase::bindObjectIdTexture(GL::Texture2DArray& texture) {
CORRADE_ASSERT(_flags >= FlagBase::ObjectIdTexture,
"Shaders::MeshVisualizerGL::bindObjectIdTexture(): the shader was not created with object ID texture enabled", *this);
CORRADE_ASSERT(_flags & FlagBase::TextureArrays,
"Shaders::MeshVisualizerGL::bindObjectIdTexture(): the shader was not created with texture arrays enabled, use a Texture2D instead", *this);
texture.bind(ObjectIdTextureUnit);
return *this;
}
#endif
}
@ -312,7 +386,7 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(const Flags flags
#ifndef MAGNUM_TARGET_GLES2
, const UnsignedInt materialCount, const UnsignedInt drawCount
#endif
): Implementation::MeshVisualizerGLBase{Implementation::MeshVisualizerGLBase::FlagBase(UnsignedShort(flags))
): Implementation::MeshVisualizerGLBase{Implementation::MeshVisualizerGLBase::FlagBase(UnsignedInt(flags))
#ifndef MAGNUM_TARGET_GLES2
, materialCount, drawCount
#endif
@ -371,6 +445,8 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(const Flags flags
geom = Implementation::createCompatibilityShader(rs, version, GL::Shader::Type::Geometry);
(*geom)
.addSource("#define WIREFRAME_RENDERING\n#define MAX_VERTICES 3\n")
.addSource(_flags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "")
.addSource(_flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "")
.addSource(_flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "")
.addSource(_flags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "")
.addSource(_flags & FlagBase::PrimitiveId ?
@ -414,11 +490,17 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(const Flags flags
{
bindAttributeLocation(Position::Location, "position");
#ifndef MAGNUM_TARGET_GLES2
if(flags >= Flag::ObjectIdTexture)
bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates");
if(flags >= Flag::InstancedObjectId)
bindAttributeLocation(ObjectId::Location, "instanceObjectId");
#endif
if(flags & Flag::InstancedTransformation)
bindAttributeLocation(TransformationMatrix::Location, "instancedTransformationMatrix");
#ifndef MAGNUM_TARGET_GLES2
if(flags >= Flag::InstancedTextureOffset)
bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset");
#endif
#if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_GLES2)
#ifndef MAGNUM_TARGET_GLES
if(!context.isVersionSupported(GL::Version::GL310))
@ -448,6 +530,12 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(const Flags flags
#endif
{
_transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
#ifndef MAGNUM_TARGET_GLES2
if(flags & Flag::TextureTransformation)
_textureMatrixUniform = uniformLocation("textureMatrix");
if(flags & Flag::TextureArrays)
_textureLayerUniform = uniformLocation("textureLayer");
#endif
if(flags & (Flag::Wireframe
#ifndef MAGNUM_TARGET_GLES2
|Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId
@ -478,10 +566,14 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(const Flags flags
setUniform(uniformLocation("colorMapTexture"), ColorMapTextureUnit);
}
#ifndef MAGNUM_TARGET_GLES2
if(flags >= Flag::ObjectIdTexture)
setUniform(uniformLocation("objectIdTextureData"), ObjectIdTextureUnit);
if(flags >= Flag::UniformBuffers) {
setUniformBlockBinding(uniformBlockIndex("TransformationProjection"), TransformationProjectionBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding);
if(flags & Flag::TextureTransformation)
setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding);
}
#endif
}
@ -585,7 +677,7 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(const Flags flags
#ifndef MAGNUM_TARGET_GLES2
, const UnsignedInt materialCount, const UnsignedInt drawCount
#endif
): Implementation::MeshVisualizerGLBase{Implementation::MeshVisualizerGLBase::FlagBase(UnsignedShort(flags))
): Implementation::MeshVisualizerGLBase{Implementation::MeshVisualizerGLBase::FlagBase(UnsignedInt(flags))
#ifndef MAGNUM_TARGET_GLES2
, materialCount, drawCount
#endif
@ -688,6 +780,8 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(const Flags flags
(*geom)
.addSource(Utility::formatString("#define MAX_VERTICES {}\n", maxVertices))
.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "")
.addSource(_flags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "")
.addSource(_flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "")
.addSource(_flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "")
.addSource(_flags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "")
.addSource(_flags & FlagBase::PrimitiveId ?
@ -734,6 +828,8 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(const Flags flags
{
bindAttributeLocation(Position::Location, "position");
#ifndef MAGNUM_TARGET_GLES2
if(flags >= Flag::ObjectIdTexture)
bindAttributeLocation(TextureCoordinates::Location, "textureCoordinates");
if(flags >= Flag::InstancedObjectId)
bindAttributeLocation(ObjectId::Location, "instanceObjectId");
#endif
@ -744,6 +840,10 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(const Flags flags
bindAttributeLocation(NormalMatrix::Location, "instancedNormalMatrix");
#endif
}
#ifndef MAGNUM_TARGET_GLES2
if(flags >= Flag::InstancedTextureOffset)
bindAttributeLocation(TextureOffset::Location, "instancedTextureOffset");
#endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
if(flags & Flag::TangentDirection ||
flags & Flag::BitangentFromTangentDirection)
@ -789,6 +889,12 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(const Flags flags
{
_transformationMatrixUniform = uniformLocation("transformationMatrix");
_projectionMatrixUniform = uniformLocation("projectionMatrix");
#ifndef MAGNUM_TARGET_GLES2
if(flags & Flag::TextureTransformation)
_textureMatrixUniform = uniformLocation("textureMatrix");
if(flags & Flag::TextureArrays)
_textureLayerUniform = uniformLocation("textureLayer");
#endif
if(flags & (Flag::Wireframe
#ifndef MAGNUM_TARGET_GLES2
|Flag::ObjectId|Flag::VertexId|Flag::PrimitiveIdFromVertexId
@ -832,11 +938,15 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(const Flags flags
setUniform(uniformLocation("colorMapTexture"), ColorMapTextureUnit);
}
#ifndef MAGNUM_TARGET_GLES2
if(flags >= Flag::ObjectIdTexture)
setUniform(uniformLocation("objectIdTextureData"), ObjectIdTextureUnit);
if(flags >= Flag::UniformBuffers) {
setUniformBlockBinding(uniformBlockIndex("Projection"), ProjectionBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Transformation"), TransformationBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Draw"), DrawBufferBinding);
setUniformBlockBinding(uniformBlockIndex("Material"), MaterialBufferBinding);
if(flags & Flag::TextureTransformation)
setUniformBlockBinding(uniformBlockIndex("TextureTransformation"), TextureTransformationBufferBinding);
}
#endif
}
@ -1016,6 +1126,14 @@ MeshVisualizerGL3D& MeshVisualizerGL3D::bindDrawBuffer(GL::Buffer& buffer, const
#endif
Debug& operator<<(Debug& debug, const MeshVisualizerGL2D::Flag value) {
#ifndef MAGNUM_TARGET_GLES2
/* Special case coming from the Flags printer. As both flags are a superset
of ObjectId, printing just one would result in
`Flag::InstancedObjectId|Flag(0x4000)` in the output. */
if(value == MeshVisualizerGL2D::Flag(UnsignedInt(MeshVisualizerGL2D::Flag::InstancedObjectId|MeshVisualizerGL2D::Flag::ObjectIdTexture)))
return debug << MeshVisualizerGL2D::Flag::InstancedObjectId << Debug::nospace << "|" << Debug::nospace << MeshVisualizerGL2D::Flag::ObjectIdTexture;
#endif
debug << "Shaders::MeshVisualizerGL2D::Flag" << Debug::nospace;
switch(value) {
@ -1024,11 +1142,14 @@ Debug& operator<<(Debug& debug, const MeshVisualizerGL2D::Flag value) {
_c(NoGeometryShader)
_c(Wireframe)
#ifndef MAGNUM_TARGET_GLES2
_c(TextureTransformation)
_c(ObjectId)
_c(InstancedObjectId)
_c(ObjectIdTexture)
#endif
_c(InstancedTransformation)
#ifndef MAGNUM_TARGET_GLES2
_c(InstancedTextureOffset)
_c(VertexId)
#ifndef MAGNUM_TARGET_WEBGL
_c(PrimitiveId)
@ -1038,15 +1159,24 @@ Debug& operator<<(Debug& debug, const MeshVisualizerGL2D::Flag value) {
#ifndef MAGNUM_TARGET_GLES2
_c(UniformBuffers)
_c(MultiDraw)
_c(TextureArrays)
#endif
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const MeshVisualizerGL3D::Flag value) {
#ifndef MAGNUM_TARGET_GLES2
/* Special case coming from the Flags printer. As both flags are a superset
of ObjectId, printing just one would result in
`Flag::InstancedObjectId|Flag(0x4000)` in the output. */
if(value == MeshVisualizerGL3D::Flag(UnsignedInt(MeshVisualizerGL3D::Flag::InstancedObjectId|MeshVisualizerGL3D::Flag::ObjectIdTexture)))
return debug << MeshVisualizerGL3D::Flag::InstancedObjectId << Debug::nospace << "|" << Debug::nospace << MeshVisualizerGL3D::Flag::ObjectIdTexture;
#endif
debug << "Shaders::MeshVisualizerGL3D::Flag" << Debug::nospace;
switch(value) {
@ -1061,11 +1191,14 @@ Debug& operator<<(Debug& debug, const MeshVisualizerGL3D::Flag value) {
_c(NormalDirection)
#endif
#ifndef MAGNUM_TARGET_GLES2
_c(TextureTransformation)
_c(ObjectId)
_c(InstancedObjectId)
_c(ObjectIdTexture)
#endif
_c(InstancedTransformation)
#ifndef MAGNUM_TARGET_GLES2
_c(InstancedTextureOffset)
_c(VertexId)
#ifndef MAGNUM_TARGET_WEBGL
_c(PrimitiveId)
@ -1075,12 +1208,13 @@ Debug& operator<<(Debug& debug, const MeshVisualizerGL3D::Flag value) {
#ifndef MAGNUM_TARGET_GLES2
_c(UniformBuffers)
_c(MultiDraw)
_c(TextureArrays)
#endif
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const MeshVisualizerGL2D::Flags value) {
@ -1090,7 +1224,12 @@ Debug& operator<<(Debug& debug, const MeshVisualizerGL2D::Flags value) {
there */
MeshVisualizerGL2D::Flag::NoGeometryShader,
#ifndef MAGNUM_TARGET_GLES2
/* Both are a superset of ObjectId, meaning printing just one would
result in `Flag::InstancedObjectId|Flag(0x4000)` in the output. So
we pass both and let the Flag printer deal with that. */
MeshVisualizerGL2D::Flag(UnsignedInt(MeshVisualizerGL2D::Flag::InstancedObjectId|MeshVisualizerGL2D::Flag::ObjectIdTexture)),
MeshVisualizerGL2D::Flag::InstancedObjectId, /* Superset of ObjectId */
MeshVisualizerGL2D::Flag::ObjectIdTexture, /* Superset of ObjectId */
MeshVisualizerGL2D::Flag::ObjectId,
#endif
MeshVisualizerGL2D::Flag::InstancedTransformation,
@ -1121,7 +1260,12 @@ Debug& operator<<(Debug& debug, const MeshVisualizerGL3D::Flags value) {
MeshVisualizerGL3D::Flag::NormalDirection,
#endif
#ifndef MAGNUM_TARGET_GLES2
/* Both are a superset of ObjectId, meaning printing just one would
result in `Flag::InstancedObjectId|Flag(0x4000)` in the output. So
we pass both and let the Flag printer deal with that. */
MeshVisualizerGL3D::Flag(UnsignedInt(MeshVisualizerGL3D::Flag::InstancedObjectId|MeshVisualizerGL3D::Flag::ObjectIdTexture)),
MeshVisualizerGL3D::Flag::InstancedObjectId, /* Superset of ObjectId */
MeshVisualizerGL3D::Flag::ObjectIdTexture, /* Superset of ObjectId */
MeshVisualizerGL3D::Flag::ObjectId,
#endif
MeshVisualizerGL3D::Flag::InstancedTransformation,

441
src/Magnum/Shaders/MeshVisualizerGL.h

@ -43,7 +43,7 @@ namespace Implementation {
class MAGNUM_SHADERS_EXPORT MeshVisualizerGLBase: public GL::AbstractShaderProgram {
protected:
enum class FlagBase: UnsignedShort {
enum class FlagBase: UnsignedInt {
/* Unlike the public Wireframe flag, this one doesn't include
NoGeometryShader on ES2 as that would make the checks too
complex */
@ -53,12 +53,16 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGLBase: public GL::AbstractShaderProgr
#ifndef MAGNUM_TARGET_GLES2
ObjectId = 1 << 12,
InstancedObjectId = (1 << 2)|ObjectId,
ObjectIdTexture = 1 << 14,
TextureTransformation = 1 << 15,
InstancedTextureOffset = (1 << 16)|TextureTransformation,
VertexId = 1 << 3,
PrimitiveId = 1 << 4,
PrimitiveIdFromVertexId = (1 << 5)|PrimitiveId,
/* bit 6, 7, 8, 9 used by 3D-specific TBN visualization */
UniformBuffers = 1 << 10,
MultiDraw = UniformBuffers|(1 << 11)
MultiDraw = UniformBuffers|(1 << 11),
TextureArrays = 1 << 17,
#endif
};
typedef Containers::EnumSet<FlagBase> FlagsBase;
@ -74,6 +78,8 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGLBase: public GL::AbstractShaderProgr
MAGNUM_SHADERS_LOCAL GL::Version setupShaders(GL::Shader& vert, GL::Shader& frag, const Utility::Resource& rs) const;
MeshVisualizerGLBase& setTextureMatrix(const Matrix3& matrix);
MeshVisualizerGLBase& setTextureLayer(UnsignedInt layer);
MeshVisualizerGLBase& setObjectId(UnsignedInt id);
MeshVisualizerGLBase& setColor(const Color4& color);
MeshVisualizerGLBase& setWireframeColor(const Color4& color);
@ -81,10 +87,14 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGLBase: public GL::AbstractShaderProgr
#ifndef MAGNUM_TARGET_GLES2
MeshVisualizerGLBase& setColorMapTransformation(Float offset, Float scale);
MeshVisualizerGLBase& bindColorMapTexture(GL::Texture2D& texture);
MeshVisualizerGLBase& bindObjectIdTexture(GL::Texture2D& texture);
MeshVisualizerGLBase& bindObjectIdTexture(GL::Texture2DArray& texture);
#endif
#ifndef MAGNUM_TARGET_GLES2
MeshVisualizerGLBase& setDrawOffset(UnsignedInt offset);
MeshVisualizerGLBase& bindTextureTransformationBuffer(GL::Buffer& buffer);
MeshVisualizerGLBase& bindTextureTransformationBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size);
MeshVisualizerGLBase& bindMaterialBuffer(GL::Buffer& buffer);
MeshVisualizerGLBase& bindMaterialBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size);
#endif
@ -108,7 +118,9 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGLBase: public GL::AbstractShaderProgr
_smoothnessUniform{4};
#ifndef MAGNUM_TARGET_GLES2
Int _colorMapOffsetScaleUniform{5},
_objectIdUniform{6};
_objectIdUniform{6},
_textureMatrixUniform{7},
_textureLayerUniform{8};
/* Used instead of all other uniforms except viewportSize when
Flag::UniformBuffers is set, so it can alias them */
Int _drawOffsetUniform{1};
@ -156,6 +168,11 @@ buffer with per-instance transformation to a mesh:
@snippet MagnumShaders-gl.cpp MeshVisualizerGL2D-usage-instancing
If @ref Flag::ObjectIdTexture is used and @ref Flag::InstancedTextureOffset is
enabled, the @ref TextureOffset attribute (or @ref TextureOffsetLayer in case
@ref Flag::TextureArrays is enabled as well) then can supply per-instance
texture offset (or offset and layer).
@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}
@ -173,6 +190,11 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
*/
typedef typename GenericGL2D::Position Position;
#ifndef MAGNUM_TARGET_GLES2
/** @copydoc MeshVisualizerGL3D::TextureCoordinates */
typedef GenericGL2D::TextureCoordinates TextureCoordinates;
#endif
/**
* @brief Vertex index
*
@ -211,6 +233,14 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
*/
typedef GenericGL2D::TransformationMatrix TransformationMatrix;
#ifndef MAGNUM_TARGET_GLES2
/** @copydoc MeshVisualizerGL3D::TextureOffset */
typedef typename GenericGL2D::TextureOffset TextureOffset;
/** @copydoc MeshVisualizerGL3D::TextureOffsetLayer */
typedef typename GenericGL2D::TextureOffsetLayer TextureOffsetLayer;
#endif
enum: UnsignedInt {
/**
* Color shader output. @ref shaders-generic "Generic output",
@ -225,7 +255,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
*
* @see @ref Flags, @ref MeshVisualizerGL2D()
*/
enum class Flag: UnsignedShort {
enum class Flag: UnsignedInt {
/**
* Visualize wireframe. On OpenGL ES 2.0 and WebGL this also
* enables @ref Flag::NoGeometryShader.
@ -277,6 +307,22 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
*/
InstancedObjectId = (1 << 2)|ObjectId,
/**
* Object ID texture. Retrieves object IDs from a texture bound
* with @ref bindObjectIdTexture(), outputting a sum of the object
* ID texture, the ID coming from @ref setObjectId() or
* @ref MeshVisualizerDrawUniform2D::objectId and possibly also the
* per-vertex ID, if @ref Flag::InstancedObjectId is enabled as
* well. Implicitly enables @ref Flag::ObjectId.
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0.
* @m_since_latest
*/
ObjectIdTexture = (1 << 14)|ObjectId,
/** @copydoc MeshVisualizerGL3D::Flag::VertexId */
VertexId = 1 << 3,
@ -311,6 +357,41 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
*/
InstancedTransformation = 1 << 13,
#ifndef MAGNUM_TARGET_GLES2
/** @copydoc MeshVisualizerGL3D::Flag::TextureTransformation */
TextureTransformation = 1 << 15,
/**
* Instanced texture offset for an object ID texture. Retrieves a
* per-instance offset vector from the @ref TextureOffset attribute
* and uses it together with the matrix coming from
* @ref setTextureMatrix() or
* @ref TextureTransformationUniform::rotationScaling and
* @ref TextureTransformationUniform::offset (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-MeshVisualizerGL3D-instancing for more information.
*
* If @ref Flag::TextureArrays is set as well, a three-component
* @ref TextureOffsetLayer attribute can be used instead of
* @ref TextureOffset to specify per-instance texture layer, which
* gets added to the uniform layer numbers set by
* @ref setTextureLayer() or
* @ref TextureTransformationUniform::layer.
* @requires_gl33 Extension @gl_extension{EXT,gpu_shader4} and
* @gl_extension{ARB,instanced_arrays}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0.
* @m_since_latest
* @todoc rewrite the ext requirements once we have more textures
*/
InstancedTextureOffset = (1 << 16)|TextureTransformation,
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* Use uniform buffers. Expects that uniform data are supplied via
@ -348,7 +429,10 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
* relies on uniform buffers, which require WebGL 2.0.
* @m_since_latest
*/
MultiDraw = UniformBuffers|(1 << 11)
MultiDraw = UniformBuffers|(1 << 11),
/** @copydoc MeshVisualizerGL3D::Flag::TextureArrays */
TextureArrays = 1 << 17,
#endif
};
@ -432,7 +516,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
/** @brief Flags */
Flags flags() const {
return Flag(UnsignedShort(Implementation::MeshVisualizerGLBase::_flags));
return Flag(UnsignedInt(Implementation::MeshVisualizerGLBase::_flags));
}
#ifndef MAGNUM_TARGET_GLES2
@ -483,6 +567,18 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
*/
MeshVisualizerGL2D& setTransformationProjectionMatrix(const Matrix3& matrix);
#ifndef MAGNUM_TARGET_GLES2
/** @copydoc MeshVisualizerGL3D::setTextureMatrix() */
MeshVisualizerGL2D& setTextureMatrix(const Matrix3& matrix) {
return static_cast<MeshVisualizerGL2D&>(Implementation::MeshVisualizerGLBase::setTextureMatrix(matrix));
}
/** @copydoc MeshVisualizerGL3D::setTextureLayer() */
MeshVisualizerGL2D& setTextureLayer(UnsignedInt layer) {
return static_cast<MeshVisualizerGL2D&>(Implementation::MeshVisualizerGLBase::setTextureLayer(layer));
}
#endif
/**
* @brief Set viewport size
* @return Reference to self (for method chaining)
@ -663,6 +759,15 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
*/
MeshVisualizerGL2D& bindDrawBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size);
/** @copydoc MeshVisualizerGL3D::bindTextureTransformationBuffer(GL::Buffer&) */
MeshVisualizerGL2D& bindTextureTransformationBuffer(GL::Buffer& buffer) {
return static_cast<MeshVisualizerGL2D&>(Implementation::MeshVisualizerGLBase::bindTextureTransformationBuffer(buffer));
}
/** @copydoc MeshVisualizerGL3D::bindTextureTransformationBuffer(GL::Buffer&, GLintptr, GLsizeiptr) */
MeshVisualizerGL2D& bindTextureTransformationBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size) {
return static_cast<MeshVisualizerGL2D&>(Implementation::MeshVisualizerGLBase::bindTextureTransformationBuffer(buffer, offset, size));
}
/**
* @brief Set a material uniform buffer
* @return Reference to self (for method chaining)
@ -702,6 +807,16 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
MeshVisualizerGL2D& bindColorMapTexture(GL::Texture2D& texture) {
return static_cast<MeshVisualizerGL2D&>(Implementation::MeshVisualizerGLBase::bindColorMapTexture(texture));
}
/** @copydoc MeshVisualizerGL3D::bindObjectIdTexture(GL::Texture2D&) */
MeshVisualizerGL2D& bindObjectIdTexture(GL::Texture2D& texture) {
return static_cast<MeshVisualizerGL2D&>(Implementation::MeshVisualizerGLBase::bindObjectIdTexture(texture));
}
/** @copydoc MeshVisualizerGL3D::bindObjectIdTexture(GL::Texture2DArray&) */
MeshVisualizerGL2D& bindObjectIdTexture(GL::Texture2DArray& texture) {
return static_cast<MeshVisualizerGL2D&>(Implementation::MeshVisualizerGLBase::bindObjectIdTexture(texture));
}
#endif
/**
@ -742,7 +857,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL2D: public Implementation::MeshVisua
#endif
private:
Int _transformationProjectionMatrixUniform{7};
Int _transformationProjectionMatrixUniform{9};
};
/**
@ -880,6 +995,13 @@ the @f$ [0, 1] @f$ texture range. Various colormap presets are in the
@snippet MagnumShaders-gl.cpp MeshVisualizerGL3D-usage-object-id
Consistently with the other shaders, textured object ID is also supported if
@ref Flag::ObjectIdTexture is enabled. In that case you need to provide also
the @ref TextureCoordinates attribute and bind an integer texture via
@ref bindObjectIdTexture(). @ref Flag::TextureTransformation then enables
texture transformation and @ref Flag::TextureArrays texture arrays for the
object ID texture.
If you enable @ref Flag::VertexId, the shader will use the color map to
visualize how are vertices shared among primitives. That's useful for
inspecting mesh connectivity --- primitives sharing vertices will have a smooth
@ -894,7 +1016,8 @@ triangle mesh. You can use @ref MeshTools::duplicate() (and potentially
@ref MeshTools::generateIndices()) to conveniently convert the mesh to a
non-indexed @ref MeshPrimitive::Triangles.
@requires_gl30 Extension @gl_extension{EXT,gpu_shader4} for object ID input
@requires_gl30 Extension @gl_extension{EXT,gpu_shader4} for object ID input,
@gl_extension{EXT,texture_array} for object ID texture arrays
@requires_gl30 The `gl_VertexID` shader variable is not available on OpenGL
2.1.
@requires_gl32 The `gl_PrimitiveID` shader variable is not available on OpenGL
@ -902,12 +1025,14 @@ non-indexed @ref MeshPrimitive::Triangles.
@requires_gles32 The `gl_PrimitiveID` shader variable is not available on
OpenGL ES 3.1 and lower.
@requires_gles30 Object ID input requires integer support in shaders, which
is not available in OpenGL ES 2.0.
is not available in OpenGL ES 2.0. Texture arrays for object ID texture
arrays are not available in OpenGL ES 2.0.
@requires_gles30 The `gl_VertexID` shader variable is not available on OpenGL
ES 2.0.
@requires_gles `gl_PrimitiveID` is not available in WebGL.
@requires_webgl20 Object ID input requires integer support in shaders, which
is not available in WebGL 1.0.
is not available in WebGL 1.0. Texture arrays for object ID texture
arrays are not available in WebGL 1.0.
@requires_webgl20 `gl_VertexID` is not available in WebGL 1.0.
@section Shaders-MeshVisualizerGL3D-instancing Instanced rendering
@ -924,6 +1049,11 @@ including a normal matrix attribute for correct TBN visualization:
@snippet MagnumShaders-gl.cpp MeshVisualizerGL3D-usage-instancing
If @ref Flag::ObjectIdTexture is used and @ref Flag::InstancedTextureOffset is
enabled, the @ref TextureOffset attribute (or @ref TextureOffsetLayer in case
@ref Flag::TextureArrays is enabled as well) then can supply per-instance
texture offset (or offset and layer).
@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}
@ -1016,6 +1146,23 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
*/
typedef typename GenericGL3D::Normal Normal;
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief 2D texture coordinates
* @m_since_latest
*
* @ref shaders-generic "Generic attribute",
* @ref Magnum::Vector2 "Vector2". Used only if
* @ref Flag::ObjectIdTexture is enabled.
* @requires_gl33 Extension @gl_extension{EXT,gpu_shader4}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0.
*/
typedef GenericGL3D::TextureCoordinates TextureCoordinates;
#endif
/**
* @brief Vertex index
*
@ -1084,6 +1231,44 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
typedef GenericGL3D::NormalMatrix NormalMatrix;
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief (Instanced) texture offset for an object ID texture
* @m_since_latest
*
* @ref shaders-generic "Generic attribute", @ref Magnum::Vector2. Used
* only if @ref Flag::InstancedTextureOffset is set.
* @requires_gl33 Extension @gl_extension{EXT,gpu_shader4} and
* @gl_extension{ARB,instanced_arrays}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0.
*/
typedef typename GenericGL3D::TextureOffset TextureOffset;
/**
* @brief (Instanced) texture offset and layer for an object ID texture
* @m_since_latest
*
* @ref shaders-generic "Generic attribute", @ref Magnum::Vector3, with
* the last component interpreted as an integer. Use either this or the
* @ref TextureOffset attribute. First two components used only if
* @ref Flag::InstancedTextureOffset is set, third component only if
* @ref Flag::TextureArrays is set.
* @requires_gl33 Extension @gl_extension{EXT,gpu_shader4},
* @gl_extension{EXT,texture_array} and
* @gl_extension{ARB,instanced_arrays}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0. Texture
* arrays are not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0. Texture arrays
* are not available in WebGL 1.0.
*/
typedef typename GenericGL3D::TextureOffsetLayer TextureOffsetLayer;
#endif
enum: UnsignedInt {
/**
* Color shader output. @ref shaders-generic "Generic output",
@ -1098,7 +1283,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
*
* @see @ref Flags, @ref MeshVisualizer()
*/
enum class Flag: UnsignedShort {
enum class Flag: UnsignedInt {
/**
* Visualize wireframe. On OpenGL ES 2.0 and WebGL this also
* enables @ref Flag::NoGeometryShader.
@ -1155,6 +1340,22 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
*/
InstancedObjectId = (1 << 2)|ObjectId,
/**
* Object ID texture. Retrieves object IDs from a texture bound
* with @ref bindObjectIdTexture(), outputting a sum of the object
* ID texture, the ID coming from @ref setObjectId() or
* @ref MeshVisualizerDrawUniform3D::objectId and possibly also the
* per-vertex ID, if @ref Flag::InstancedObjectId is enabled as
* well. Implicitly enables @ref Flag::ObjectId.
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0.
* @m_since_latest
*/
ObjectIdTexture = (1 << 14)|ObjectId,
/**
* Visualize vertex ID (@cpp gl_VertexID @ce). Useful for
* visualizing mesh connectivity --- primitives sharing vertices
@ -1294,6 +1495,54 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
*/
InstancedTransformation = 1 << 13,
#ifndef MAGNUM_TARGET_GLES2
/**
* Enable texture coordinate transformation for an object ID
* texture. If this flag is set, the shader expects that
* @ref Flag::ObjectIdTexture is enabled as well.
* @see @ref setTextureMatrix()
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0.
* @m_since_latest
* @todoc rewrite the ext requirements once we have more textures
*/
TextureTransformation = 1 << 15,
/**
* Instanced texture offset for an object ID texture. Retrieves a
* per-instance offset vector from the @ref TextureOffset attribute
* and uses it together with the matrix coming from
* @ref setTextureMatrix() or
* @ref TextureTransformationUniform::rotationScaling and
* @ref TextureTransformationUniform::offset (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-MeshVisualizerGL2D-instancing for more information.
*
* If @ref Flag::TextureArrays is set as well, a three-component
* @ref TextureOffsetLayer attribute can be used instead of
* @ref TextureOffset to specify per-instance texture layer, which
* gets added to the uniform layer numbers set by
* @ref setTextureLayer() or
* @ref TextureTransformationUniform::layer.
* @requires_gl30 Extension
* @requires_gl33 Extension @gl_extension{EXT,gpu_shader4} and
* @gl_extension{ARB,instanced_arrays}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0.
* @m_since_latest
* @todoc rewrite the ext requirements once we have more textures
*/
InstancedTextureOffset = (1 << 16)|TextureTransformation,
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* Use uniform buffers. Expects that uniform data are supplied via
@ -1332,7 +1581,30 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
* relies on uniform buffers, which require WebGL 2.0.
* @m_since_latest
*/
MultiDraw = UniformBuffers|(1 << 11)
MultiDraw = UniformBuffers|(1 << 11),
/**
* Use 2D texture arrays for an object ID texture. Expects that the
* texture is supplied via
* @ref bindObjectIdTexture(GL::Texture2DArray&) and the layer
* is set via @ref setTextureLayer() or
* @ref TextureTransformationUniform::layer. If
* @ref Flag::InstancedTextureOffset is set as well and a
* three-component @ref TextureOffsetLayer attribute is used
* instead of @ref TextureOffset, the per-instance and uniform
* layer numbers are added together.
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4} and
* @gl_extension{EXT,texture_array}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0. Texture
* arrays are not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0. Texture
* arrays are not available in WebGL 1.0.
* @m_since_latest
* @todoc rewrite the ext requirements once we have more textures
*/
TextureArrays = 1 << 17
#endif
};
@ -1432,7 +1704,7 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
/** @brief Flags */
Flags flags() const {
return Flag(UnsignedShort(Implementation::MeshVisualizerGLBase::_flags));
return Flag(UnsignedInt(Implementation::MeshVisualizerGLBase::_flags));
}
#ifndef MAGNUM_TARGET_GLES2
@ -1537,6 +1809,64 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
MeshVisualizerGL3D& setNormalMatrix(const Matrix3x3& matrix);
#endif
#ifndef MAGNUM_TARGET_GLES2
/**
* @brief Set texture coordinate transformation matrix for an object ID texture
* @return Reference to self (for method chaining)
* @m_since_latest
*
* Expects that the shader was created with
* @ref Flag::TextureTransformation enabled. Initial value is an
* identity matrix. If @ref Flag::InstancedTextureOffset is set, the
* per-instance offset coming from the @ref TextureOffset attribute is
* applied first, before this matrix.
*
* Expects that @ref Flag::UniformBuffers is not set, in that case fill
* @ref TextureTransformationUniform::rotationScaling and
* @ref TextureTransformationUniform::offset and call
* @ref bindTextureTransformationBuffer() instead.
* @requires_gl33 Extension @gl_extension{EXT,gpu_shader4} and
* @gl_extension{ARB,instanced_arrays}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0.
* @todoc rewrite the ext requirements once we have more textures
*/
MeshVisualizerGL3D& setTextureMatrix(const Matrix3& matrix) {
return static_cast<MeshVisualizerGL3D&>(Implementation::MeshVisualizerGLBase::setTextureMatrix(matrix));
}
/**
* @brief Set texture array layer for an object ID texture
* @return Reference to self (for method chaining)
* @m_since_latest
*
* Expects that the shader was created with @ref Flag::TextureArrays
* enabled. Initial value is @cpp 0 @ce. If
* @ref Flag::InstancedTextureOffset is set and a three-component
* @ref TextureOffsetLayer attribute is used instead of
* @ref TextureOffset, this value is added to the layer coming from the
* third component.
*
* Expects that @ref Flag::UniformBuffers is not set, in that case fill
* @ref TextureTransformationUniform::layer and call
* @ref bindTextureTransformationBuffer() instead.
* @requires_gl33 Extension @gl_extension{EXT,gpu_shader4} and
* @gl_extension{EXT,texture_array}
* @requires_gles30 Object ID input requires integer support in
* shaders, which is not available in OpenGL ES 2.0. Texture
* arrays are not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID input requires integer support in
* shaders, which is not available in WebGL 1.0.Texture arrays are
* not available in WebGL 1.0.
* @todoc rewrite the ext requirements once we have more textures
*/
MeshVisualizerGL3D& setTextureLayer(UnsignedInt layer) {
return static_cast<MeshVisualizerGL3D&>(Implementation::MeshVisualizerGLBase::setTextureLayer(layer));
}
#endif
/**
* @brief Set viewport size
* @return Reference to self (for method chaining)
@ -1816,6 +2146,34 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
*/
MeshVisualizerGL3D& bindDrawBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size);
/**
* @brief Set a texture transformation uniform buffer for an object ID texture
* @return Reference to self (for method chaining)
* @m_since_latest
*
* Expects that both @ref Flag::UniformBuffers and
* @ref Flag::TextureTransformation is set. The buffer is expected to
* contain @ref drawCount() instances of
* @ref TextureTransformationUniform.
* @requires_gl31 Extension @gl_extension{ARB,uniform_buffer_object}
* @requires_gles30 Uniform buffers are not available in OpenGL ES 2.0.
* Object ID input requires integer support in shaders, which is
* not available in OpenGL ES 2.0.
* @requires_webgl20 Uniform buffers are not available in WebGL 1.0.
* Object ID input requires integer support in shaders, which is
* not available in WebGL 1.0.
*/
MeshVisualizerGL3D& bindTextureTransformationBuffer(GL::Buffer& buffer) {
return static_cast<MeshVisualizerGL3D&>(Implementation::MeshVisualizerGLBase::bindTextureTransformationBuffer(buffer));
}
/**
* @overload
* @m_since_latest
*/
MeshVisualizerGL3D& bindTextureTransformationBuffer(GL::Buffer& buffer, GLintptr offset, GLsizeiptr size) {
return static_cast<MeshVisualizerGL3D&>(Implementation::MeshVisualizerGLBase::bindTextureTransformationBuffer(buffer, offset, size));
}
/**
* @brief Set a material uniform buffer
* @return Reference to self (for method chaining)
@ -1871,6 +2229,53 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
MeshVisualizerGL3D& bindColorMapTexture(GL::Texture2D& texture) {
return static_cast<MeshVisualizerGL3D&>(Implementation::MeshVisualizerGLBase::bindColorMapTexture(texture));
}
/**
* @brief Bind an object ID texture
* @return Reference to self (for method chaining)
* @m_since_latest
*
* Expects that the shader was created with @ref Flag::ObjectIdTexture
* enabled. If @ref Flag::TextureArrays is enabled as well, use
* @ref bindObjectIdTexture(GL::Texture2DArray&) instead. The texture
* needs to have an unsigned integer format.
* @see @ref setObjectId(), @ref Flag::TextureTransformation,
* @ref setTextureMatrix()
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4}
* @requires_gles30 Object ID visualization requires integer support in
* shaders, which is not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID visualization requires integer support
* in shaders, which is not available in WebGL 1.0.
*/
MeshVisualizerGL3D& bindObjectIdTexture(GL::Texture2D& texture) {
return static_cast<MeshVisualizerGL3D&>(Implementation::MeshVisualizerGLBase::bindObjectIdTexture(texture));
}
/**
* @brief Bind an object ID array texture
* @return Reference to self (for method chaining)
* @m_since_latest
*
* Expects that the shader was created with both
* @ref Flag::ObjectIdTexture and @ref Flag::TextureArrays enabled. If
* @ref Flag::UniformBuffers is not enabled, the layer is set via
* @ref setTextureLayer(); if @ref Flag::UniformBuffers is enabled,
* @ref Flag::TextureTransformation has to be enabled as well and the
* layer is set via @ref TextureTransformationUniform::layer.
* @see @ref setObjectId(), @ref Flag::TextureTransformation,
* @ref setTextureLayer()
* @requires_gl30 Extension @gl_extension{EXT,gpu_shader4} and
* @gl_extension{EXT,texture_array}
* @requires_gles30 Object ID output requires integer support in
* shaders, which is not available in OpenGL ES 2.0. Texture
* arrays are not available in OpenGL ES 2.0.
* @requires_webgl20 Object ID output requires integer support in
* shaders, which is not available in WebGL 1.0. Texture arrays
* are not available in WebGL 1.0.
*/
MeshVisualizerGL3D& bindObjectIdTexture(GL::Texture2DArray& texture) {
return static_cast<MeshVisualizerGL3D&>(Implementation::MeshVisualizerGLBase::bindObjectIdTexture(texture));
}
#endif
/**
@ -1911,12 +2316,12 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerGL3D: public Implementation::MeshVisua
#endif
private:
Int _transformationMatrixUniform{7},
_projectionMatrixUniform{8};
Int _transformationMatrixUniform{9},
_projectionMatrixUniform{10};
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
Int _normalMatrixUniform{9},
_lineWidthUniform{10},
_lineLengthUniform{11};
Int _normalMatrixUniform{11},
_lineWidthUniform{12},
_lineLengthUniform{13};
#endif
};

2
src/Magnum/Shaders/PhongGL.cpp

@ -59,7 +59,7 @@ namespace {
SpecularTextureUnit = 2,
NormalTextureUnit = 3,
/* 4 taken by MeshVisualizer colormap */
ObjectIdTextureUnit = 5 /* shared with Flat */
ObjectIdTextureUnit = 5 /* shared with Flat and MeshVisualizer */
};
#ifndef MAGNUM_TARGET_GLES2

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

@ -212,6 +212,8 @@ if(BUILD_GL_TESTS)
MeshVisualizerTestFiles/instancedobjectid3D.tga
MeshVisualizerTestFiles/objectid2D.tga
MeshVisualizerTestFiles/objectid3D.tga
MeshVisualizerTestFiles/objectidtexture2D.tga
MeshVisualizerTestFiles/objectidtexture3D.tga
MeshVisualizerTestFiles/primitiveid-tn.tga
MeshVisualizerTestFiles/primitiveid2D.tga
MeshVisualizerTestFiles/primitiveid3D.tga
@ -225,6 +227,8 @@ if(BUILD_GL_TESTS)
MeshVisualizerTestFiles/wireframe-instancedobjectid3D.tga
MeshVisualizerTestFiles/wireframe-nogeo-instancedobjectid2D.tga
MeshVisualizerTestFiles/wireframe-nogeo-instancedobjectid3D.tga
MeshVisualizerTestFiles/wireframe-objectidtexture2D.tga
MeshVisualizerTestFiles/wireframe-objectidtexture3D.tga
MeshVisualizerTestFiles/wireframe-perspective.tga
MeshVisualizerTestFiles/wireframe-primitiveid-tn.tga
MeshVisualizerTestFiles/wireframe-tn-smooth.tga
@ -243,6 +247,10 @@ if(BUILD_GL_TESTS)
MeshVisualizerTestFiles/instanced-vertexid3D.tga
MeshVisualizerTestFiles/instanced-instancedobjectid2D.tga
MeshVisualizerTestFiles/instanced-instancedobjectid3D.tga
MeshVisualizerTestFiles/instanced-instancedobjectidtexture2D.tga
MeshVisualizerTestFiles/instanced-instancedobjectidtexture3D.tga
MeshVisualizerTestFiles/instanced-objectidtexture2D.tga
MeshVisualizerTestFiles/instanced-objectidtexture3D.tga
MeshVisualizerTestFiles/multidraw-wireframe2D.tga
MeshVisualizerTestFiles/multidraw-wireframe3D.tga
MeshVisualizerTestFiles/multidraw-wireframe-tbn3D.tga
@ -251,7 +259,9 @@ if(BUILD_GL_TESTS)
MeshVisualizerTestFiles/multidraw-vertexid2D.tga
MeshVisualizerTestFiles/multidraw-vertexid3D.tga
MeshVisualizerTestFiles/multidraw-instancedobjectid2D.tga
MeshVisualizerTestFiles/multidraw-instancedobjectid3D.tga)
MeshVisualizerTestFiles/multidraw-instancedobjectid3D.tga
MeshVisualizerTestFiles/multidraw-objectidtexture2D.tga
MeshVisualizerTestFiles/multidraw-objectidtexture3D.tga)
target_include_directories(ShadersMeshVisualizerGLTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
if(BUILD_PLUGINS_STATIC)
if(WITH_ANYIMAGEIMPORTER)

998
src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp

File diff suppressed because it is too large Load Diff

36
src/Magnum/Shaders/Test/MeshVisualizerGL_Test.cpp

@ -117,15 +117,15 @@ void MeshVisualizerGL_Test::vertexIndexSameAsObjectId() {
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");
Debug{&out} << MeshVisualizerGL2D::Flag::Wireframe << MeshVisualizerGL2D::Flag(0xbad00000);
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL2D::Flag::Wireframe Shaders::MeshVisualizerGL2D::Flag(0xbad00000)\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");
Debug{&out} << MeshVisualizerGL3D::Flag::Wireframe << MeshVisualizerGL3D::Flag(0xbad00000);
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL3D::Flag::Wireframe Shaders::MeshVisualizerGL3D::Flag(0xbad00000)\n");
}
void MeshVisualizerGL_Test::debugFlags2D() {
@ -152,12 +152,20 @@ void MeshVisualizerGL_Test::debugFlags3D() {
#ifndef MAGNUM_TARGET_GLES2
void MeshVisualizerGL_Test::debugFlagsSupersets2D() {
/* InstancedObjectId is a superset of ObjectId so only one should be
printed */
/* InstancedObjectId and ObjectIdTexture are a superset of ObjectId so only
one should be printed, but if there are both then both should be */
{
std::ostringstream out;
Debug{&out} << (MeshVisualizerGL2D::Flag::InstancedObjectId|MeshVisualizerGL2D::Flag::ObjectId);
Debug{&out} << (MeshVisualizerGL2D::Flag::ObjectId|MeshVisualizerGL2D::Flag::InstancedObjectId);
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL2D::Flag::InstancedObjectId\n");
} {
std::ostringstream out;
Debug{&out} << (MeshVisualizerGL2D::Flag::ObjectId|MeshVisualizerGL2D::Flag::ObjectIdTexture);
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL2D::Flag::ObjectIdTexture\n");
} {
std::ostringstream out;
Debug{&out} << (MeshVisualizerGL2D::Flag::ObjectId|MeshVisualizerGL2D::Flag::InstancedObjectId|MeshVisualizerGL2D::Flag::ObjectIdTexture);
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL2D::Flag::InstancedObjectId|Shaders::MeshVisualizerGL2D::Flag::ObjectIdTexture\n");
}
/* MultiDraw is a superset of UniformBuffers so only one should be printed */
@ -169,12 +177,20 @@ void MeshVisualizerGL_Test::debugFlagsSupersets2D() {
}
void MeshVisualizerGL_Test::debugFlagsSupersets3D() {
/* InstancedObjectId is a superset of ObjectId so only one should be
printed */
/* InstancedObjectId and ObjectIdTexture are a superset of ObjectId so only
one should be printed, but if there are both then both should be */
{
std::ostringstream out;
Debug{&out} << (MeshVisualizerGL3D::Flag::InstancedObjectId|MeshVisualizerGL3D::Flag::ObjectId);
Debug{&out} << (MeshVisualizerGL3D::Flag::ObjectId|MeshVisualizerGL3D::Flag::InstancedObjectId);
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL3D::Flag::InstancedObjectId\n");
} {
std::ostringstream out;
Debug{&out} << (MeshVisualizerGL3D::Flag::ObjectId|MeshVisualizerGL3D::Flag::ObjectIdTexture);
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL3D::Flag::ObjectIdTexture\n");
} {
std::ostringstream out;
Debug{&out} << (MeshVisualizerGL3D::Flag::ObjectId|MeshVisualizerGL3D::Flag::InstancedObjectId|MeshVisualizerGL3D::Flag::ObjectIdTexture);
CORRADE_COMPARE(out.str(), "Shaders::MeshVisualizerGL3D::Flag::InstancedObjectId|Shaders::MeshVisualizerGL3D::Flag::ObjectIdTexture\n");
}
/* MultiDraw is a superset of UniformBuffers so only one should be printed */

BIN
src/Magnum/Shaders/Test/MeshVisualizerTestFiles/instanced-instancedobjectidtexture2D.tga

Binary file not shown.

BIN
src/Magnum/Shaders/Test/MeshVisualizerTestFiles/instanced-instancedobjectidtexture3D.tga

Binary file not shown.

BIN
src/Magnum/Shaders/Test/MeshVisualizerTestFiles/instanced-objectidtexture2D.tga

Binary file not shown.

BIN
src/Magnum/Shaders/Test/MeshVisualizerTestFiles/instanced-objectidtexture3D.tga

Binary file not shown.

BIN
src/Magnum/Shaders/Test/MeshVisualizerTestFiles/multidraw-objectidtexture2D.tga

Binary file not shown.

BIN
src/Magnum/Shaders/Test/MeshVisualizerTestFiles/multidraw-objectidtexture3D.tga

Binary file not shown.

BIN
src/Magnum/Shaders/Test/MeshVisualizerTestFiles/objectidtexture2D.tga

Binary file not shown.

BIN
src/Magnum/Shaders/Test/MeshVisualizerTestFiles/objectidtexture3D.tga

Binary file not shown.

BIN
src/Magnum/Shaders/Test/MeshVisualizerTestFiles/wireframe-objectidtexture2D.tga

Binary file not shown.

BIN
src/Magnum/Shaders/Test/MeshVisualizerTestFiles/wireframe-objectidtexture3D.tga

Binary file not shown.
Loading…
Cancel
Save