From be789db11952b20eecc741b668b5bf0459bcaaea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 28 Apr 2018 00:05:35 +0200 Subject: [PATCH] doc: compiling Method Chaining page snippets. --- doc/method-chaining.dox | 26 ++------------------------ doc/snippets/Magnum.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/doc/method-chaining.dox b/doc/method-chaining.dox index 54081002a..73e33e572 100644 --- a/doc/method-chaining.dox +++ b/doc/method-chaining.dox @@ -44,19 +44,7 @@ bound somewhere. Method chaining encourages you to configure whole object in one run, effectively reducing the number of needed bindings. Consider the following example: -@code{.cpp} -Texture2D carDiffuseTexture, carSpecularTexture, carBumpTexture; - -carDiffuseTexture.setStorage(5, TextureFormat::SRGB8); -carSpecularTexture.setStorage(3, TextureFormat::R8); -carBumpTexture.setStorage(5, TextureFormat::RGB8); -carDiffuseTexture.setSubImage(0, {}, diffuse); -carSpecularTexture.setSubImage(0, {}, specular; -carBumpTexture.setSubImage(0, {}, bump); -carDiffuseTexture.generateMipmap(); -carSpecularTexture.generateMipmap(); -carBumpTexture.generateMipmap(); -@endcode +@snippet Magnum.cpp method-chaining-texture This code is written that similar configuration steps are grouped together, which might be good when somebody needs to change something for all three @@ -65,17 +53,7 @@ names and after each configuration step the texture must be rebound to another. With method chaining used the code looks much lighter and each object is configured in one run, reducing count of bind calls from 9 to 3. -@code{.cpp} -carDiffuseTexture.setStorage(5, TextureFormat::SRGB8) - .setSubImage(0, {}, diffuse) - .generateMipmap(); -carSpecularTexture.setStorage(3, TextureFormat::R8) - .setSubImage(0, {}, diffuse) - .generateMipmap(); -carBumpTexture.setStorage(5, TextureFormat::RGB8) - .setSubImage(0, {}, bump) - .generateMipmap(); -@endcode +@snippet Magnum.cpp method-chaining-texture-chained Method chaining is not used on non-configuring functions, such as @ref Framebuffer::clear() or @ref Mesh::draw(), as these won't be commonly used diff --git a/doc/snippets/Magnum.cpp b/doc/snippets/Magnum.cpp index 9edf33929..33da7d324 100644 --- a/doc/snippets/Magnum.cpp +++ b/doc/snippets/Magnum.cpp @@ -82,6 +82,39 @@ using namespace Magnum::Math::Literals; int main() { +#ifndef MAGNUM_TARGET_GLES2 +{ +ImageView2D diffuse{PixelFormat::RGBA, PixelType::UnsignedByte, {}}; +ImageView2D specular{PixelFormat::RGBA, PixelType::UnsignedByte, {}}; +ImageView2D bump{PixelFormat::RGBA, PixelType::UnsignedByte, {}}; +/* [method-chaining-texture] */ +Texture2D carDiffuseTexture, carSpecularTexture, carBumpTexture; + +carDiffuseTexture.setStorage(5, TextureFormat::SRGB8, {256, 256}); +carSpecularTexture.setStorage(3, TextureFormat::R8, {256, 256}); +carBumpTexture.setStorage(5, TextureFormat::RGB8, {256, 256}); +carDiffuseTexture.setSubImage(0, {}, diffuse); +carSpecularTexture.setSubImage(0, {}, specular); +carBumpTexture.setSubImage(0, {}, bump); +carDiffuseTexture.generateMipmap(); +carSpecularTexture.generateMipmap(); +carBumpTexture.generateMipmap(); +/* [method-chaining-texture] */ + +/* [method-chaining-texture-chained] */ +carDiffuseTexture.setStorage(5, TextureFormat::SRGB8, {256, 256}) + .setSubImage(0, {}, diffuse) + .generateMipmap(); +carSpecularTexture.setStorage(3, TextureFormat::R8, {256, 256}) + .setSubImage(0, {}, diffuse) + .generateMipmap(); +carBumpTexture.setStorage(5, TextureFormat::RGB8, {256, 256}) + .setSubImage(0, {}, bump) + .generateMipmap(); +/* [method-chaining-texture-chained] */ +} +#endif + { auto importSomeMesh() -> std::tuple; /* [opengl-wrapping-nocreate] */