|
|
|
@ -33,35 +33,81 @@ |
|
|
|
namespace Magnum { namespace Shaders { |
|
|
|
namespace Magnum { namespace Shaders { |
|
|
|
|
|
|
|
|
|
|
|
MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationProjectionMatrixUniform(0), viewportSizeUniform(1), colorUniform(2), wireframeColorUniform(3), wireframeWidthUniform(4), smoothnessUniform(5) { |
|
|
|
MeshVisualizer::MeshVisualizer(const Flags flags): flags(flags), transformationProjectionMatrixUniform(0), viewportSizeUniform(1), colorUniform(2), wireframeColorUniform(3), wireframeWidthUniform(4), smoothnessUniform(5) { |
|
|
|
if(flags & Flag::Wireframe) MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::geometry_shader4); |
|
|
|
#ifndef MAGNUM_TARGET_GLES |
|
|
|
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::explicit_attrib_location); |
|
|
|
if(flags & Flag::Wireframe && !(flags & Flag::NoGeometryShader)) |
|
|
|
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::explicit_uniform_location); |
|
|
|
MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::geometry_shader4); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
Utility::Resource rs("MagnumShaders"); |
|
|
|
Utility::Resource rs("MagnumShaders"); |
|
|
|
|
|
|
|
|
|
|
|
Shader vert(Version::GL330, Shader::Type::Vertex); |
|
|
|
#ifndef MAGNUM_TARGET_GLES |
|
|
|
|
|
|
|
const Version v = Context::current()->supportedVersion({Version::GL320, Version::GL310, Version::GL210}); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
const Version v = Context::current()->supportedVersion({Version::GLES300, Version::GLES200}); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Shader vert(v, Shader::Type::Vertex); |
|
|
|
vert.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") |
|
|
|
vert.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") |
|
|
|
|
|
|
|
.addSource(flags & Flag::NoGeometryShader ? "#define NO_GEOMETRY_SHADER\n" : "") |
|
|
|
.addSource(rs.get("compatibility.glsl")) |
|
|
|
.addSource(rs.get("compatibility.glsl")) |
|
|
|
.addSource(rs.get("MeshVisualizer.vert")); |
|
|
|
.addSource(rs.get("MeshVisualizer.vert")); |
|
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); |
|
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile()); |
|
|
|
|
|
|
|
vert.compile(); |
|
|
|
attachShader(vert); |
|
|
|
attachShader(vert); |
|
|
|
|
|
|
|
|
|
|
|
if(flags & Flag::Wireframe) { |
|
|
|
#ifndef MAGNUM_TARGET_GLES |
|
|
|
Shader geom(Version::GL330, Shader::Type::Geometry); |
|
|
|
if(flags & Flag::Wireframe && !(flags & Flag::NoGeometryShader)) { |
|
|
|
|
|
|
|
Shader geom(v, Shader::Type::Geometry); |
|
|
|
geom.addSource(rs.get("compatibility.glsl")) |
|
|
|
geom.addSource(rs.get("compatibility.glsl")) |
|
|
|
.addSource(rs.get("MeshVisualizer.geom")); |
|
|
|
.addSource(rs.get("MeshVisualizer.geom")); |
|
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(geom.compile()); |
|
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(geom.compile()); |
|
|
|
|
|
|
|
geom.compile(); |
|
|
|
attachShader(geom); |
|
|
|
attachShader(geom); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
Shader frag(Version::GL330, Shader::Type::Fragment); |
|
|
|
Shader frag(v, Shader::Type::Fragment); |
|
|
|
frag.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") |
|
|
|
frag.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "") |
|
|
|
|
|
|
|
.addSource(flags & Flag::NoGeometryShader ? "#define NO_GEOMETRY_SHADER\n" : "") |
|
|
|
.addSource(rs.get("compatibility.glsl")) |
|
|
|
.addSource(rs.get("compatibility.glsl")) |
|
|
|
.addSource(rs.get("MeshVisualizer.frag")); |
|
|
|
.addSource(rs.get("MeshVisualizer.frag")); |
|
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); |
|
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(frag.compile()); |
|
|
|
|
|
|
|
frag.compile(); |
|
|
|
attachShader(frag); |
|
|
|
attachShader(frag); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES |
|
|
|
|
|
|
|
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_attrib_location>() || |
|
|
|
|
|
|
|
Context::current()->version() == Version::GL210) |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
if(!Context::current()->isVersionSupported(Version::GLES300)) |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bindAttributeLocation(Position::Location, "position"); |
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES |
|
|
|
|
|
|
|
if(v < Version::GL310) |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
if(v < Version::GLES300) |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
bindAttributeLocation(VertexIndex::Location, "vertexIndex"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORRADE_INTERNAL_ASSERT_OUTPUT(link()); |
|
|
|
link(); |
|
|
|
link(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MAGNUM_TARGET_GLES |
|
|
|
|
|
|
|
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::explicit_uniform_location>()) |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); |
|
|
|
|
|
|
|
colorUniform = uniformLocation("color"); |
|
|
|
|
|
|
|
if(flags & Flag::Wireframe) { |
|
|
|
|
|
|
|
wireframeColorUniform = uniformLocation("wireframeColor"); |
|
|
|
|
|
|
|
wireframeWidthUniform = uniformLocation("wireframeWidth"); |
|
|
|
|
|
|
|
smoothnessUniform = uniformLocation("smoothness"); |
|
|
|
|
|
|
|
if(!(flags & Flag::NoGeometryShader)) |
|
|
|
|
|
|
|
viewportSizeUniform = uniformLocation("viewportSize"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}} |
|
|
|
}} |
|
|
|
|