diff --git a/doc/generated/shaders.cpp b/doc/generated/shaders.cpp index a56d1db99..8a30f4281 100644 --- a/doc/generated/shaders.cpp +++ b/doc/generated/shaders.cpp @@ -55,12 +55,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -80,6 +82,7 @@ struct ShaderVisualizer: Platform::WindowlessApplication { int exec() override; Containers::StringView phong(); + Containers::StringView line(); Containers::StringView meshVisualizer2D(); Containers::StringView meshVisualizer2DPrimitiveId(); Containers::StringView meshVisualizer3D(); @@ -132,6 +135,7 @@ int ShaderVisualizer::exec() { GL::Renderer::setClearColor(0x000000_srgbaf); for(auto fun: {&ShaderVisualizer::phong, + &ShaderVisualizer::line, &ShaderVisualizer::meshVisualizer2D, &ShaderVisualizer::meshVisualizer2DPrimitiveId, &ShaderVisualizer::meshVisualizer3D, @@ -175,6 +179,43 @@ Containers::StringView ShaderVisualizer::phong() { return "phong.png"; } +Containers::StringView ShaderVisualizer::line() { + struct Vertex { + Vector2 position; + Color3ub color; + }; + Containers::Array vertices{NoInit, 1024}; + const auto map = DebugTools::ColorMap::turbo(); + + for(std::size_t i = 0; i != vertices.size(); ++i) { + const Rad t{Constants::tau()*Float(i)/Float(vertices.size())}; + vertices[i].position = { + /* Original from https://www.quantamagazine.org/how-to-create-art-with-mathematics-20151008/ + Math::cos(t) + Math::cos(6*t)/2 + Math::sin(14*t)/3, + Math::sin(t) + Math::sin(6*t)/2 + Math::cos(14*t)/3 */ + Math::cos(t) + Math::cos(6*t)/3 + Math::sin(14*t)/3, + Math::sin(t) + Math::sin(6*t)/3 + Math::cos(14*t)/3 + }; + vertices[i].color = map[i/4]; + } + + Trade::MeshData mesh{MeshPrimitive::LineLoop, {}, vertices, { + Trade::MeshAttributeData{Trade::MeshAttribute::Position, stridedArrayView(vertices).slice(&Vertex::position)}, + Trade::MeshAttributeData{Trade::MeshAttribute::Color, stridedArrayView(vertices).slice(&Vertex::color)}, + }}; + + Shaders::LineGL2D shader{Shaders::LineGL2D::Configuration{} + .setFlags(Shaders::LineGL2D::Flag::VertexColor)}; + shader + .setTransformationProjectionMatrix(Matrix3::scaling(Vector2{0.5f})) + .setViewportSize(Vector2{ImageSize}) + .setWidth(5.0f) + .setSmoothness(1.0f) + .draw(MeshTools::compileLines(mesh)); + + return "line.png"; +} + Containers::StringView ShaderVisualizer::meshVisualizer2D() { const Matrix3 projection = Matrix3::projection(Vector2{3.0f})* diff --git a/doc/namespaces.dox b/doc/namespaces.dox index dcd811c35..99bbda915 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -685,19 +685,24 @@ See @ref building, @ref cmake and @ref shaders for more information. @parblock -@m_div{m-col-m-4 m-col-t-6 m-text-center m-nopadt m-nopadx} +@m_div{m-col-m-3 m-col-t-6 m-text-center m-nopadt m-nopadx} @image html shaders-flat.png width=256px @ref FlatGL @m_class{m-label m-success} **2D** @m_class{m-label m-primary} **3D** @m_enddiv -@m_div{m-col-m-4 m-col-t-6 m-text-center m-nopadt m-nopadx} +@m_div{m-col-m-3 m-col-t-6 m-text-center m-nopadt m-nopadx} @image html shaders-phong.png width=256px @ref PhongGL @m_class{m-label m-primary} **3D** @m_enddiv @m_div{m-clearfix-t} @m_enddiv -@m_div{m-col-m-4 m-push-t-3 m-push-m-0 m-col-t-6 m-text-center m-nopadt m-nopadx} +@m_div{m-col-m-3 m-col-t-6 m-text-center m-nopadt m-nopadx} +@image html shaders-line.png width=256px +@ref LineGL @m_class{m-label m-success} **2D** @m_class{m-label m-primary} **3D** +@m_enddiv + +@m_div{m-col-m-3 m-col-t-6 m-text-center m-nopadt m-nopadx} @image html shaders-vertexcolor.png width=256px @ref VertexColorGL @m_class{m-label m-success} **2D** @m_class{m-label m-primary} **3D** @m_enddiv diff --git a/doc/shaders-line.png b/doc/shaders-line.png new file mode 100644 index 000000000..ee22444f8 Binary files /dev/null and b/doc/shaders-line.png differ diff --git a/src/Magnum/Shaders/LineGL.h b/src/Magnum/Shaders/LineGL.h index 0b1f002a2..14ed88293 100644 --- a/src/Magnum/Shaders/LineGL.h +++ b/src/Magnum/Shaders/LineGL.h @@ -68,6 +68,8 @@ Renders lines expanded to quads in screen space. Compared to builtin GPU line rendering, the lines can be of arbitrary width, with configurable join and cap styles, and antialiased independently of MSAA being used or not. +@image html shaders-line.png width=256px + @requires_gl30 Extension @gl_extension{EXT,gpu_shader4} @requires_gles30 Requires integer support in shaders which is not available in OpenGL ES 2.0.