Browse Source

Split the OpenGL layer out, pt 25: updated documentation code snippets.

pull/233/head
Vladimír Vondruš 8 years ago
parent
commit
499984e82c
  1. 128
      doc/generated/primitives.cpp
  2. 126
      doc/generated/shaders.cpp
  3. 16
      doc/snippets/MagnumGL-framebuffer.cpp
  4. 674
      doc/snippets/MagnumGL.cpp
  5. 21
      doc/snippets/MagnumMeshTools.cpp
  6. 4
      doc/snippets/MagnumPlatform-custom.cpp
  7. 4
      doc/snippets/MagnumPlatform-windowless-custom.cpp
  8. 4
      doc/snippets/MagnumPlatform-windowless-thread.cpp
  9. 4
      doc/snippets/MagnumPlatform-windowless.cpp
  10. 8
      doc/snippets/MagnumPlatform.cpp
  11. 92
      doc/snippets/MagnumShaders.cpp
  12. 8
      doc/snippets/MagnumText.cpp
  13. 17
      doc/snippets/getting-started-blue.cpp
  14. 4
      doc/snippets/getting-started.cpp

128
doc/generated/primitives.cpp

@ -36,16 +36,16 @@
#error no windowless application available on this platform
#endif
#include <Magnum/Buffer.h>
#include <Magnum/Framebuffer.h>
#include <Magnum/Image.h>
#include <Magnum/Mesh.h>
#include <Magnum/PixelFormat.h>
#include <Magnum/Renderbuffer.h>
#include <Magnum/RenderbufferFormat.h>
#include <Magnum/Renderer.h>
#include <Magnum/Texture.h>
#include <Magnum/TextureFormat.h>
#include <Magnum/GL/Buffer.h>
#include <Magnum/GL/Framebuffer.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/GL/Renderbuffer.h>
#include <Magnum/GL/RenderbufferFormat.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/Texture.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/MeshTools/Compile.h>
#include <Magnum/MeshTools/Interleave.h>
#include <Magnum/MeshTools/Transform.h>
@ -135,56 +135,56 @@ int PrimitiveVisualizer::exec() {
std::exit(1);
}
Renderbuffer multisampleColor, multisampleDepth;
multisampleColor.setStorageMultisample(16, RenderbufferFormat::RGBA8, ImageSize);
multisampleDepth.setStorageMultisample(16, RenderbufferFormat::DepthComponent24, ImageSize);
GL::Renderbuffer multisampleColor, multisampleDepth;
multisampleColor.setStorageMultisample(16, GL::RenderbufferFormat::RGBA8, ImageSize);
multisampleDepth.setStorageMultisample(16, GL::RenderbufferFormat::DepthComponent24, ImageSize);
Framebuffer multisampleFramebuffer{{{}, ImageSize}};
multisampleFramebuffer.attachRenderbuffer(Framebuffer::ColorAttachment{0}, multisampleColor)
.attachRenderbuffer(Framebuffer::BufferAttachment::Depth, multisampleDepth)
GL::Framebuffer multisampleFramebuffer{{{}, ImageSize}};
multisampleFramebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, multisampleColor)
.attachRenderbuffer(GL::Framebuffer::BufferAttachment::Depth, multisampleDepth)
.bind();
CORRADE_INTERNAL_ASSERT(multisampleFramebuffer.checkStatus(FramebufferTarget::Draw) == Framebuffer::Status::Complete);
CORRADE_INTERNAL_ASSERT(multisampleFramebuffer.checkStatus(GL::FramebufferTarget::Draw) == GL::Framebuffer::Status::Complete);
Renderbuffer color;
color.setStorage(RenderbufferFormat::RGBA8, ImageSize);
Framebuffer framebuffer{{{}, ImageSize}};
framebuffer.attachRenderbuffer(Framebuffer::ColorAttachment{0}, color);
GL::Renderbuffer color;
color.setStorage(GL::RenderbufferFormat::RGBA8, ImageSize);
GL::Framebuffer framebuffer{{{}, ImageSize}};
framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, color);
/* Cheating a bit and enabling only face culling instead of depth test in
order to draw the wireframe over. I couldn't get polygon offset to work
on the first try so I gave up. This will of course break with things
like torus later. */
Renderer::enable(Renderer::Feature::FaceCulling);
Renderer::enable(Renderer::Feature::Blending);
Renderer::setBlendFunction(Renderer::BlendFunction::One, Renderer::BlendFunction::One);
Renderer::setClearColor(0x000000_rgbaf);
Renderer::setLineWidth(1.5f);
GL::Renderer::enable(GL::Renderer::Feature::FaceCulling);
GL::Renderer::enable(GL::Renderer::Feature::Blending);
GL::Renderer::setBlendFunction(GL::Renderer::BlendFunction::One, GL::Renderer::BlendFunction::One);
GL::Renderer::setClearColor(0x000000_rgbaf);
GL::Renderer::setLineWidth(1.5f);
{
Shaders::VertexColor2D shader;
shader.setTransformationProjectionMatrix(Projection2D*Transformation2D);
for(auto fun: {&PrimitiveVisualizer::axis2D}) {
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth);
multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename;
Containers::Optional<Trade::MeshData2D> data;
std::tie(data, filename) = (this->*fun)();
/* TODO: use MeshTools::compile() once it can handle colors */
Buffer vertices, indices;
vertices.setData(MeshTools::interleave(data->positions(0), data->colors(0)), BufferUsage::StaticDraw);
indices.setData(data->indices(), BufferUsage::StaticDraw);
Mesh mesh;
GL::Buffer vertices, indices;
vertices.setData(MeshTools::interleave(data->positions(0), data->colors(0)), GL::BufferUsage::StaticDraw);
indices.setData(data->indices(), GL::BufferUsage::StaticDraw);
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::VertexColor2D::Position{}, Shaders::VertexColor2D::Color{Shaders::VertexColor2D::Color::Components::Four})
.setIndexBuffer(indices, 0, Mesh::IndexType::UnsignedInt)
.setIndexBuffer(indices, 0, GL::MeshIndexType::UnsignedInt)
.setCount(data->indices().size())
.setPrimitive(data->primitive());
mesh.draw(shader);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte});
GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
}
}
@ -194,26 +194,26 @@ int PrimitiveVisualizer::exec() {
shader.setTransformationProjectionMatrix(Projection3D*Transformation3D);
for(auto fun: {&PrimitiveVisualizer::axis3D}) {
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth);
multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename;
Containers::Optional<Trade::MeshData3D> data;
std::tie(data, filename) = (this->*fun)();
/* TODO: use MeshTools::compile() once it can handle colors */
Buffer vertices, indices;
vertices.setData(MeshTools::interleave(data->positions(0), data->colors(0)), BufferUsage::StaticDraw);
indices.setData(data->indices(), BufferUsage::StaticDraw);
Mesh mesh;
GL::Buffer vertices, indices;
vertices.setData(MeshTools::interleave(data->positions(0), data->colors(0)), GL::BufferUsage::StaticDraw);
indices.setData(data->indices(), GL::BufferUsage::StaticDraw);
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::VertexColor3D::Position{}, Shaders::VertexColor3D::Color{Shaders::VertexColor3D::Color::Components::Four})
.setIndexBuffer(indices, 0, Mesh::IndexType::UnsignedInt)
.setIndexBuffer(indices, 0, GL::MeshIndexType::UnsignedInt)
.setCount(data->indices().size())
.setPrimitive(data->primitive());
mesh.draw(shader);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte});
GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
}
}
@ -229,20 +229,20 @@ int PrimitiveVisualizer::exec() {
&PrimitiveVisualizer::line2D,
&PrimitiveVisualizer::squareWireframe})
{
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth);
multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename;
Containers::Optional<Trade::MeshData2D> data;
std::tie(data, filename) = (this->*fun)();
std::unique_ptr<Buffer> vertices, indices;
Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(*data, BufferUsage::StaticDraw);
std::unique_ptr<GL::Buffer> vertices, indices;
GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(*data, GL::BufferUsage::StaticDraw);
mesh.draw(shader);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte});
GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
}
}
@ -263,20 +263,20 @@ int PrimitiveVisualizer::exec() {
&PrimitiveVisualizer::planeWireframe,
&PrimitiveVisualizer::uvSphereWireframe})
{
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth);
multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename;
Containers::Optional<Trade::MeshData3D> data;
std::tie(data, filename) = (this->*fun)();
std::unique_ptr<Buffer> vertices, indices;
Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(*data, BufferUsage::StaticDraw);
std::unique_ptr<GL::Buffer> vertices, indices;
GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(*data, GL::BufferUsage::StaticDraw);
mesh.draw(shader);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte});
GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
}
}
@ -296,24 +296,24 @@ int PrimitiveVisualizer::exec() {
for(auto fun: {&PrimitiveVisualizer::circle2DSolid,
&PrimitiveVisualizer::squareSolid})
{
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth);
multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename;
Containers::Optional<Trade::MeshData2D> data;
std::tie(data, filename) = (this->*fun)();
/* TODO: use MeshTools::compile() and MeshVisualizer2D once it exists */
Buffer vertices;
vertices.setData(data->positions(0), BufferUsage::StaticDraw);
Mesh mesh;
GL::Buffer vertices;
vertices.setData(data->positions(0), GL::BufferUsage::StaticDraw);
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::MeshVisualizer::Position{Shaders::MeshVisualizer::Position::Components::Two})
.setCount(data->positions(0).size())
.setPrimitive(data->primitive());
mesh.draw(shader);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte});
GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
}
}
@ -344,21 +344,21 @@ int PrimitiveVisualizer::exec() {
&PrimitiveVisualizer::planeSolid,
&PrimitiveVisualizer::uvSphereSolid})
{
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth);
multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename;
Containers::Optional<Trade::MeshData3D> data;
std::tie(data, filename) = (this->*fun)();
std::unique_ptr<Buffer> vertices, indices;
Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(*data, BufferUsage::StaticDraw);
std::unique_ptr<GL::Buffer> vertices, indices;
GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(*data, GL::BufferUsage::StaticDraw);
mesh.draw(phong);
mesh.draw(wireframe);
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte});
GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "primitives-" + filename));
}
}

126
doc/generated/shaders.cpp

@ -36,16 +36,16 @@
#error no windowless application available on this platform
#endif
#include <Magnum/Buffer.h>
#include <Magnum/Framebuffer.h>
#include <Magnum/Image.h>
#include <Magnum/Mesh.h>
#include <Magnum/PixelFormat.h>
#include <Magnum/Renderbuffer.h>
#include <Magnum/RenderbufferFormat.h>
#include <Magnum/Renderer.h>
#include <Magnum/Texture.h>
#include <Magnum/TextureFormat.h>
#include <Magnum/GL/Buffer.h>
#include <Magnum/GL/Framebuffer.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/GL/Renderbuffer.h>
#include <Magnum/GL/RenderbufferFormat.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/Texture.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/MeshTools/Compile.h>
#include <Magnum/MeshTools/Interleave.h>
#include <Magnum/Primitives/Square.h>
@ -102,23 +102,23 @@ int ShaderVisualizer::exec() {
std::exit(1);
}
Renderbuffer multisampleColor, multisampleDepth;
multisampleColor.setStorageMultisample(16, RenderbufferFormat::RGBA8, ImageSize);
multisampleDepth.setStorageMultisample(16, RenderbufferFormat::DepthComponent24, ImageSize);
GL::Renderbuffer multisampleColor, multisampleDepth;
multisampleColor.setStorageMultisample(16, GL::RenderbufferFormat::RGBA8, ImageSize);
multisampleDepth.setStorageMultisample(16, GL::RenderbufferFormat::DepthComponent24, ImageSize);
Framebuffer multisampleFramebuffer{{{}, ImageSize}};
multisampleFramebuffer.attachRenderbuffer(Framebuffer::ColorAttachment{0}, multisampleColor)
.attachRenderbuffer(Framebuffer::BufferAttachment::Depth, multisampleDepth)
GL::Framebuffer multisampleFramebuffer{{{}, ImageSize}};
multisampleFramebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, multisampleColor)
.attachRenderbuffer(GL::Framebuffer::BufferAttachment::Depth, multisampleDepth)
.bind();
CORRADE_INTERNAL_ASSERT(multisampleFramebuffer.checkStatus(FramebufferTarget::Draw) == Framebuffer::Status::Complete);
CORRADE_INTERNAL_ASSERT(multisampleFramebuffer.checkStatus(GL::FramebufferTarget::Draw) == GL::Framebuffer::Status::Complete);
Renderbuffer color;
color.setStorage(RenderbufferFormat::RGBA8, ImageSize);
Framebuffer framebuffer{{{}, ImageSize}};
framebuffer.attachRenderbuffer(Framebuffer::ColorAttachment{0}, color);
GL::Renderbuffer color;
color.setStorage(GL::RenderbufferFormat::RGBA8, ImageSize);
GL::Framebuffer framebuffer{{{}, ImageSize}};
framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, color);
Renderer::enable(Renderer::Feature::DepthTest);
Renderer::setClearColor(0x000000_rgbaf);
GL::Renderer::enable(GL::Renderer::Feature::DepthTest);
GL::Renderer::setClearColor(0x000000_rgbaf);
for(auto fun: {&ShaderVisualizer::phong,
&ShaderVisualizer::meshVisualizer,
@ -126,12 +126,12 @@ int ShaderVisualizer::exec() {
&ShaderVisualizer::vertexColor,
&ShaderVisualizer::vector,
&ShaderVisualizer::distanceFieldVector}) {
multisampleFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth);
multisampleFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
std::string filename = (this->*fun)();
AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA, PixelType::UnsignedByte});
GL::AbstractFramebuffer::blit(multisampleFramebuffer, framebuffer, framebuffer.viewport(), GL::FramebufferBlit::Color);
Image2D result = framebuffer.read(framebuffer.viewport(), {PixelFormat::RGBA8Unorm});
converter->exportToFile(result, Utility::Directory::join("../", "shaders-" + filename));
}
@ -148,9 +148,9 @@ namespace {
}
std::string ShaderVisualizer::phong() {
std::unique_ptr<Buffer> vertices, indices;
Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::uvSphereSolid(16, 32), BufferUsage::StaticDraw);
std::unique_ptr<GL::Buffer> vertices, indices;
GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::uvSphereSolid(16, 32), GL::BufferUsage::StaticDraw);
Shaders::Phong shader;
shader.setAmbientColor(0x22272e_rgbf)
@ -167,9 +167,9 @@ std::string ShaderVisualizer::phong() {
}
std::string ShaderVisualizer::meshVisualizer() {
std::unique_ptr<Buffer> vertices, indices;
Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::icosphereSolid(1), BufferUsage::StaticDraw);
std::unique_ptr<GL::Buffer> vertices, indices;
GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::icosphereSolid(1), GL::BufferUsage::StaticDraw);
const Matrix4 projection = Projection*Transformation*
Matrix4::rotationZ(13.7_degf)*
@ -187,9 +187,9 @@ std::string ShaderVisualizer::meshVisualizer() {
}
std::string ShaderVisualizer::flat() {
std::unique_ptr<Buffer> vertices, indices;
Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::uvSphereSolid(16, 32), BufferUsage::StaticDraw);
std::unique_ptr<GL::Buffer> vertices, indices;
GL::Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::uvSphereSolid(16, 32), GL::BufferUsage::StaticDraw);
Shaders::Flat3D shader;
shader.setColor(BaseColor)
@ -210,17 +210,17 @@ std::string ShaderVisualizer::vertexColor() {
for(Vector3 position: sphere.positions(0))
colors.push_back(Color3::fromHsv(Math::lerp(240.0_degf, 420.0_degf, Math::max(1.0f - (position - target).length(), 0.0f)), 0.75f, 0.75f));
Buffer vertices, indices;
vertices.setData(MeshTools::interleave(sphere.positions(0), colors), BufferUsage::StaticDraw);
indices.setData(sphere.indices(), BufferUsage::StaticDraw);
GL::Buffer vertices, indices;
vertices.setData(MeshTools::interleave(sphere.positions(0), colors), GL::BufferUsage::StaticDraw);
indices.setData(sphere.indices(), GL::BufferUsage::StaticDraw);
Mesh mesh;
mesh.setPrimitive(MeshPrimitive::Triangles)
GL::Mesh mesh;
mesh.setPrimitive(GL::MeshPrimitive::Triangles)
.setCount(sphere.indices().size())
.addVertexBuffer(vertices, 0,
Shaders::VertexColor3D::Position{},
Shaders::VertexColor3D::Color{Shaders::VertexColor3D::Color::Components::Three})
.setIndexBuffer(indices, 0, Mesh::IndexType::UnsignedInt);
.setIndexBuffer(indices, 0, GL::MeshIndexType::UnsignedInt);
Shaders::VertexColor3D shader;
shader.setTransformationProjectionMatrix(Projection*Transformation);
@ -237,29 +237,29 @@ std::string ShaderVisualizer::vector() {
return "vector.png";
}
Texture2D texture;
texture.setMinificationFilter(Sampler::Filter::Linear)
.setMagnificationFilter(Sampler::Filter::Linear)
.setWrapping(Sampler::Wrapping::ClampToEdge)
.setStorage(1, TextureFormat::RGBA8, image->size())
GL::Texture2D texture;
texture.setMinificationFilter(GL::SamplerFilter::Linear)
.setMagnificationFilter(GL::SamplerFilter::Linear)
.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setStorage(1, GL::TextureFormat::RGBA8, image->size())
.setSubImage(0, {}, *image);
Mesh mesh{NoCreate};
std::unique_ptr<Buffer> vertices;
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::squareSolid(Primitives::SquareTextureCoords::Generate), BufferUsage::StaticDraw);
GL::Mesh mesh{NoCreate};
std::unique_ptr<GL::Buffer> vertices;
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::squareSolid(Primitives::SquareTextureCoords::Generate), GL::BufferUsage::StaticDraw);
Shaders::Vector2D shader;
shader.setColor(BaseColor)
.bindVectorTexture(texture)
.setTransformationProjectionMatrix({});
Renderer::enable(Renderer::Feature::Blending);
Renderer::setBlendFunction(Renderer::BlendFunction::One, Renderer::BlendFunction::OneMinusSourceAlpha);
Renderer::setBlendEquation(Renderer::BlendEquation::Add, Renderer::BlendEquation::Add);
GL::Renderer::enable(GL::Renderer::Feature::Blending);
GL::Renderer::setBlendFunction(GL::Renderer::BlendFunction::One, GL::Renderer::BlendFunction::OneMinusSourceAlpha);
GL::Renderer::setBlendEquation(GL::Renderer::BlendEquation::Add, GL::Renderer::BlendEquation::Add);
mesh.draw(shader);
Renderer::disable(Renderer::Feature::Blending);
GL::Renderer::disable(GL::Renderer::Feature::Blending);
return "vector.png";
}
@ -271,16 +271,16 @@ std::string ShaderVisualizer::distanceFieldVector() {
return "distancefieldvector.png";
}
Texture2D texture;
texture.setMinificationFilter(Sampler::Filter::Linear)
.setMagnificationFilter(Sampler::Filter::Linear)
.setWrapping(Sampler::Wrapping::ClampToEdge)
.setStorage(1, TextureFormat::RGBA8, image->size())
GL::Texture2D texture;
texture.setMinificationFilter(GL::SamplerFilter::Linear)
.setMagnificationFilter(GL::SamplerFilter::Linear)
.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setStorage(1, GL::TextureFormat::RGBA8, image->size())
.setSubImage(0, {}, *image);
Mesh mesh{NoCreate};
std::unique_ptr<Buffer> vertices;
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::squareSolid(Primitives::SquareTextureCoords::Generate), BufferUsage::StaticDraw);
GL::Mesh mesh{NoCreate};
std::unique_ptr<GL::Buffer> vertices;
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::squareSolid(Primitives::SquareTextureCoords::Generate), GL::BufferUsage::StaticDraw);
Shaders::DistanceFieldVector2D shader;
shader.setColor(BaseColor)
@ -289,13 +289,13 @@ std::string ShaderVisualizer::distanceFieldVector() {
.bindVectorTexture(texture)
.setTransformationProjectionMatrix({});
Renderer::enable(Renderer::Feature::Blending);
Renderer::setBlendFunction(Renderer::BlendFunction::One, Renderer::BlendFunction::OneMinusSourceAlpha);
Renderer::setBlendEquation(Renderer::BlendEquation::Add, Renderer::BlendEquation::Add);
GL::Renderer::enable(GL::Renderer::Feature::Blending);
GL::Renderer::setBlendFunction(GL::Renderer::BlendFunction::One, GL::Renderer::BlendFunction::OneMinusSourceAlpha);
GL::Renderer::setBlendEquation(GL::Renderer::BlendEquation::Add, GL::Renderer::BlendEquation::Add);
mesh.draw(shader);
Renderer::disable(Renderer::Feature::Blending);
GL::Renderer::disable(GL::Renderer::Feature::Blending);
return "distancefieldvector.png";
}

16
doc/snippets/MagnumGL-framebuffer.cpp

@ -23,8 +23,8 @@
DEALINGS IN THE SOFTWARE.
*/
#include "Magnum/DefaultFramebuffer.h"
#include "Magnum/Framebuffer.h"
#include "Magnum/GL/DefaultFramebuffer.h"
#include "Magnum/GL/Framebuffer.h"
#include "Magnum/Platform/Sdl2Application.h"
using namespace Magnum;
@ -32,7 +32,7 @@ using namespace Magnum;
struct A: Platform::Sdl2Application {
/* [DefaultFramebuffer-usage-viewport] */
void viewportEvent(const Vector2i& size) override {
defaultFramebuffer.setViewport({{}, size});
GL::defaultFramebuffer.setViewport({{}, size});
// ...
}
@ -40,7 +40,7 @@ void viewportEvent(const Vector2i& size) override {
/* [DefaultFramebuffer-usage-clear] */
void drawEvent() override {
defaultFramebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth);
GL::defaultFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);
// ...
}
@ -49,17 +49,17 @@ void drawEvent() override {
struct B: Platform::Sdl2Application {
Framebuffer framebuffer;
GL::Framebuffer framebuffer;
/* [Framebuffer-usage-draw] */
void drawEvent() override {
defaultFramebuffer.clear(FramebufferClear::Color);
framebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth|FramebufferClear::Stencil);
GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
framebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth|GL::FramebufferClear::Stencil);
framebuffer.bind();
// ...
defaultFramebuffer.bind();
GL::defaultFramebuffer.bind();
// ...
swapBuffers();

674
doc/snippets/MagnumGL.cpp

File diff suppressed because it is too large Load Diff

21
doc/snippets/MagnumMeshTools.cpp

@ -23,7 +23,8 @@
DEALINGS IN THE SOFTWARE.
*/
#include "Magnum/Buffer.h"
#include "Magnum/GL/Buffer.h"
#include "Magnum/GL/Mesh.h"
#include "Magnum/Math/Color.h"
#include "Magnum/MeshTools/CombineIndexedArrays.h"
#include "Magnum/MeshTools/CompressIndices.h"
@ -59,15 +60,15 @@ std::vector<UnsignedInt> indices = MeshTools::combineIndexedArrays(
std::vector<UnsignedInt> indices;
Containers::Array<char> indexData;
Mesh::IndexType indexType;
MeshIndexType indexType;
UnsignedInt indexStart, indexEnd;
std::tie(indexData, indexType, indexStart, indexEnd) =
MeshTools::compressIndices(indices);
Buffer indexBuffer;
indexBuffer.setData(indexData, BufferUsage::StaticDraw);
GL::Buffer indexBuffer;
indexBuffer.setData(indexData, GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.setCount(indices.size())
.setIndexBuffer(indexBuffer, 0, indexType, indexStart, indexEnd);
/* [compressIndices] */
@ -95,17 +96,17 @@ std::tie(normalIndices, normals) =
{
struct MyShader {
typedef Attribute<0, Vector3> Position;
typedef Attribute<0, Vector2> TextureCoordinates;
typedef GL::Attribute<0, Vector3> Position;
typedef GL::Attribute<0, Vector2> TextureCoordinates;
};
/* [interleave1] */
std::vector<Vector3> positions;
std::vector<Vector2> textureCoordinates;
Buffer vertexBuffer;
vertexBuffer.setData(MeshTools::interleave(positions, textureCoordinates), BufferUsage::StaticDraw);
GL::Buffer vertexBuffer;
vertexBuffer.setData(MeshTools::interleave(positions, textureCoordinates), GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.setCount(positions.size())
.addVertexBuffer(vertexBuffer, 0, MyShader::Position{}, MyShader::TextureCoordinates{});
/* [interleave1] */

4
doc/snippets/MagnumPlatform-custom.cpp

@ -23,7 +23,7 @@
DEALINGS IN THE SOFTWARE.
*/
#include <Magnum/Platform/Context.h>
#include "Magnum/Platform/GLContext.h"
using namespace Magnum;
@ -33,7 +33,7 @@ int main() {
{
/* Initialize Magnum */
Platform::Context context;
Platform::GLContext context;
// Main loop ...

4
doc/snippets/MagnumPlatform-windowless-custom.cpp

@ -24,7 +24,7 @@
*/
#include <Magnum/Platform/WindowlessEglApplication.h>
#include <Magnum/Platform/Context.h>
#include <Magnum/Platform/GLContext.h>
using namespace Magnum;
@ -36,7 +36,7 @@ EGLContext anotherContext{};
int main(int argc, char** argv) {
Platform::WindowlessGLContext glContext{{}};
glContext.makeCurrent();
Platform::Context context{argc, argv};
Platform::GLContext context{argc, argv};
// Your GL code ...

4
doc/snippets/MagnumPlatform-windowless-thread.cpp

@ -25,7 +25,7 @@
#include <thread>
#include <Magnum/Platform/WindowlessEglApplication.h>
#include <Magnum/Platform/Context.h>
#include <Magnum/Platform/GLContext.h>
using namespace Magnum;
@ -35,7 +35,7 @@ int main() {
std::thread worker{[&glContext]{
glContext.makeCurrent();
Platform::Context context;
Platform::GLContext context;
// Use Magnum here ...
}};

4
doc/snippets/MagnumPlatform-windowless.cpp

@ -40,8 +40,8 @@ MyApplication::MyApplication(const Arguments& arguments):
Platform::WindowlessApplication{arguments} {}
int MyApplication::exec() {
Debug{} << "OpenGL version:" << Context::current().versionString();
Debug{} << "OpenGL renderer:" << Context::current().rendererString();
Debug{} << "OpenGL version:" << GL::Context::current().versionString();
Debug{} << "OpenGL renderer:" << GL::Context::current().rendererString();
/* Exit with success */
return 0;

8
doc/snippets/MagnumPlatform.cpp

@ -28,7 +28,7 @@
#include <Magnum/GL/Renderer.h>
#include <Magnum/Math/Color.h>
#include <Magnum/Platform/Sdl2Application.h>
#include <Magnum/Platform/Context.h>
#include <Magnum/Platform/GLContext.h>
using namespace Magnum;
@ -43,12 +43,12 @@ class MyApplication: public Platform::Application {
MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments} {
using namespace Math::Literals;
/* Set clear color to dark blue */
Renderer::setClearColor(0x000066_rgbf);
GL::Renderer::setClearColor(0x000066_rgbf);
}
void MyApplication::drawEvent() {
/* Clear the window */
defaultFramebuffer.clear(FramebufferClear::Color);
GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
/* The context is double-buffered, swap buffers */
swapBuffers();
@ -71,7 +71,7 @@ class MyApplication: public Platform::Application {
// ...
void MyApplication::viewportEvent(const Vector2i& size) {
defaultFramebuffer.setViewport({{}, size});
GL::defaultFramebuffer.setViewport({{}, size});
}
/* [size] */

92
doc/snippets/MagnumShaders.cpp

@ -25,10 +25,10 @@
#include <numeric>
#include "Magnum/Buffer.h"
#include "Magnum/DefaultFramebuffer.h"
#include "Magnum/Mesh.h"
#include "Magnum/Texture.h"
#include "Magnum/GL/Buffer.h"
#include "Magnum/GL/DefaultFramebuffer.h"
#include "Magnum/GL/Mesh.h"
#include "Magnum/GL/Texture.h"
#include "Magnum/Math/Color.h"
#include "Magnum/MeshTools/Duplicate.h"
#include "Magnum/Shaders/DistanceFieldVector.h"
@ -55,10 +55,10 @@ Vertex data[60]{
// ...
};
Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw);
GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
Shaders::Phong::Position{},
Shaders::Phong::Normal{},
@ -69,7 +69,7 @@ mesh.addVertexBuffer(vertices, 0,
/* [shaders-rendering] */
Matrix4 transformationMatrix, projectionMatrix;
Texture2D diffuseTexture, specularTexture;
GL::Texture2D diffuseTexture, specularTexture;
Shaders::Phong shader{Shaders::Phong::Flag::DiffuseTexture};
shader.bindDiffuseTexture(diffuseTexture)
@ -93,7 +93,7 @@ Shaders::MeshVisualizer visualizerShader{Shaders::MeshVisualizer::Flag::Wirefram
visualizerShader
.setColor(0x2f83cc_rgbf)
.setWireframeColor(0xdcdcdc_rgbf)
.setViewportSize(Vector2{defaultFramebuffer.viewport().size()})
.setViewportSize(Vector2{GL::defaultFramebuffer.viewport().size()})
.setTransformationProjectionMatrix(projectionMatrix*transformationMatrix);
mesh.draw(visualizerShader);
@ -110,10 +110,10 @@ Vertex data[60]{
// ...
};
Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw);
GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
Shaders::DistanceFieldVector2D::Position{},
Shaders::DistanceFieldVector2D::TextureCoordinates{})
@ -123,10 +123,10 @@ mesh.addVertexBuffer(vertices, 0,
}
{
Mesh mesh;
GL::Mesh mesh;
/* [DistanceFieldVector-usage2] */
Matrix3 transformationMatrix, projectionMatrix;
Texture2D texture;
GL::Texture2D texture;
Shaders::DistanceFieldVector2D shader;
shader.setColor(0x2f83cc_rgbf)
@ -148,10 +148,10 @@ Vertex data[60]{
//...
};
Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw);
GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::Flat3D::Position{})
// ...
;
@ -179,10 +179,10 @@ Vertex data[60]{
// ...
};
Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw);
GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
Shaders::Flat3D::Position{},
Shaders::Flat3D::TextureCoordinates{})
@ -192,7 +192,7 @@ mesh.addVertexBuffer(vertices, 0,
/* [Flat-usage-textured2] */
Matrix4 transformationMatrix, projectionMatrix;
Texture2D texture;
GL::Texture2D texture;
Shaders::Flat3D shader{Shaders::Flat3D::Flag::Textured};
shader.setTransformationProjectionMatrix(projectionMatrix*transformationMatrix)
@ -211,10 +211,10 @@ Vertex data[60]{
// ...
};
Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw);
GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::MeshVisualizer::Position{});
/* [MeshVisualizer-usage-geom1] */
@ -225,7 +225,7 @@ Matrix4 projectionMatrix = Matrix4::perspectiveProjection(35.0_degf, 1.0f, 0.001
Shaders::MeshVisualizer shader{Shaders::MeshVisualizer::Flag::Wireframe};
shader.setColor(0x2f83cc_rgbf)
.setWireframeColor(0xdcdcdc_rgbf)
.setViewportSize(Vector2{defaultFramebuffer.viewport().size()})
.setViewportSize(Vector2{GL::defaultFramebuffer.viewport().size()})
.setTransformationProjectionMatrix(projectionMatrix*transformationMatrix);
mesh.draw(shader);
@ -236,8 +236,8 @@ constexpr std::size_t vertexCount = Containers::arraySize(data);
Float vertexIndex[vertexCount];
std::iota(vertexIndex, vertexIndex + vertexCount, 0.0f);
Buffer vertexIndices;
vertexIndices.setData(vertexIndex, BufferUsage::StaticDraw);
GL::Buffer vertexIndices;
vertexIndices.setData(vertexIndex, GL::BufferUsage::StaticDraw);
mesh.addVertexBuffer(vertexIndices, 0, Shaders::MeshVisualizer::VertexIndex{});
/* [MeshVisualizer-usage-no-geom-old1] */
@ -245,7 +245,7 @@ mesh.addVertexBuffer(vertexIndices, 0, Shaders::MeshVisualizer::VertexIndex{});
#endif
{
Mesh mesh;
GL::Mesh mesh;
/* [MeshVisualizer-usage-no-geom-old2] */
Matrix4 transformationMatrix, projectionMatrix;
@ -269,11 +269,11 @@ std::vector<Vector3> indexedPositions{
};
/* De-indexing the position array */
Buffer vertices;
GL::Buffer vertices;
vertices.setData(MeshTools::duplicate(indices, indexedPositions),
BufferUsage::StaticDraw);
GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0, Shaders::MeshVisualizer::Position{});
/* [MeshVisualizer-usage-no-geom] */
}
@ -289,10 +289,10 @@ Vertex data[60]{
// ...
};
Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw);
GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
Shaders::Phong::Position{},
Shaders::Phong::Normal{});
@ -325,10 +325,10 @@ Vertex data[60]{
// ...
};
Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw);
GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
Shaders::Phong::Position{},
Shaders::Phong::Normal{},
@ -337,7 +337,7 @@ mesh.addVertexBuffer(vertices, 0,
/* [Phong-usage-texture2] */
Matrix4 transformationMatrix, projectionMatrix;
Texture2D diffuseTexture, specularTexture;
GL::Texture2D diffuseTexture, specularTexture;
Shaders::Phong shader{Shaders::Phong::Flag::DiffuseTexture|
Shaders::Phong::Flag::SpecularTexture};
@ -353,7 +353,7 @@ mesh.draw(shader);
#endif
{
Texture2D ambientAlphaTexture, diffuseAlphaTexture;
GL::Texture2D ambientAlphaTexture, diffuseAlphaTexture;
Color3 diffuseRgb, specularRgb;
/* [Phong-usage-alpha] */
Shaders::Phong shader{Shaders::Phong::Flag::AmbientTexture|
@ -376,10 +376,10 @@ Vertex data[60]{
// ...
};
Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw);
GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
Shaders::Vector2D::Position{},
Shaders::Vector2D::TextureCoordinates{});
@ -387,7 +387,7 @@ mesh.addVertexBuffer(vertices, 0,
/* [Vector-usage2] */
Matrix3 transformationMatrix, projectionMatrix;
Texture2D texture;
GL::Texture2D texture;
Shaders::Vector2D shader;
shader.setColor(0x2f83cc_rgbf)
@ -408,10 +408,10 @@ Vertex data[60]{
// ...
};
Buffer vertices;
vertices.setData(data, BufferUsage::StaticDraw);
GL::Buffer vertices;
vertices.setData(data, GL::BufferUsage::StaticDraw);
Mesh mesh;
GL::Mesh mesh;
mesh.addVertexBuffer(vertices, 0,
Shaders::VertexColor3D::Position{},
Shaders::VertexColor3D::Color{Shaders::VertexColor3D::Color::Components::Three});

8
doc/snippets/MagnumText.cpp

@ -66,12 +66,12 @@ font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
"0123456789?!:;,. ");
Shaders::Vector2D shader;
Buffer vertexBuffer, indexBuffer;
Mesh mesh;
GL::Buffer vertexBuffer, indexBuffer;
GL::Mesh mesh;
/* Render the text, centered */
std::tie(mesh, std::ignore) = Text::Renderer2D::render(*font, cache, 0.15f,
"Hello World!", vertexBuffer, indexBuffer, BufferUsage::StaticDraw,
"Hello World!", vertexBuffer, indexBuffer, GL::BufferUsage::StaticDraw,
Text::Alignment::LineCenter);
/* Draw the text on the screen */
@ -84,7 +84,7 @@ mesh.draw(shader);
/* [Renderer-usage2] */
/* Initialize the renderer and reserve memory for enough glyphs */
Text::Renderer2D renderer{*font, cache, 0.15f, Text::Alignment::LineCenter};
renderer.reserve(32, BufferUsage::DynamicDraw, BufferUsage::StaticDraw);
renderer.reserve(32, GL::BufferUsage::DynamicDraw, GL::BufferUsage::StaticDraw);
/* Update the text occasionally */
renderer.render("Hello World Countdown: 10");

17
doc/snippets/getting-started-blue.cpp

@ -23,12 +23,12 @@
DEALINGS IN THE SOFTWARE.
*/
#include <Magnum/DefaultFramebuffer.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/Platform/Sdl2Application.h>
/** [0] */
#include <Magnum/Context.h>
#include <Magnum/Renderer.h>
#include <Magnum/Version.h>
#include <Magnum/GL/Context.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/GL/Version.h>
#include <Magnum/Math/Color.h>
/** [0] */
@ -46,15 +46,16 @@ class MyApplication: public Platform::Application {
MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments} {
using namespace Magnum::Math::Literals;
Renderer::setClearColor(0xa5c9ea_rgbf);
GL::Renderer::setClearColor(0xa5c9ea_rgbf);
Debug{} << "Hello! This application is running on" << Context::current().version()
<< "using" << Context::current().rendererString();
Debug{} << "Hello! This application is running on"
<< GL::Context::current().version() << "using"
<< GL::Context::current().rendererString();
}
/** [1] */
void MyApplication::drawEvent() {
defaultFramebuffer.clear(FramebufferClear::Color);
GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
// TODO: Add your drawing code here

4
doc/snippets/getting-started.cpp

@ -24,7 +24,7 @@
*/
/** [0] */
#include <Magnum/DefaultFramebuffer.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/Platform/Sdl2Application.h>
using namespace Magnum;
@ -42,7 +42,7 @@ MyApplication::MyApplication(const Arguments& arguments): Platform::Application{
}
void MyApplication::drawEvent() {
defaultFramebuffer.clear(FramebufferClear::Color);
GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
// TODO: Add your drawing code here

Loading…
Cancel
Save