From 06f750068a41b53da4571ec75904234c3af171ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 28 Aug 2013 17:22:55 +0200 Subject: [PATCH] Primitives: added texture coordinates to Plane and Square primitives. --- src/Primitives/Plane.cpp | 12 ++++++++++-- src/Primitives/Plane.h | 11 ++++++++++- src/Primitives/Square.cpp | 12 ++++++++++-- src/Primitives/Square.h | 11 ++++++++++- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Primitives/Plane.cpp b/src/Primitives/Plane.cpp index d3fe3787e..dc889f75d 100644 --- a/src/Primitives/Plane.cpp +++ b/src/Primitives/Plane.cpp @@ -29,7 +29,15 @@ namespace Magnum { namespace Primitives { -Trade::MeshData3D Plane::solid() { +Trade::MeshData3D Plane::solid(const TextureCoords textureCoords) { + std::vector> coords; + if(textureCoords == TextureCoords::Generate) coords.push_back({ + {1.0f, 0.0f}, + {1.0f, 1.0f}, + {0.0f, 0.0f}, + {0.0f, 1.0f} + }); + return Trade::MeshData3D(Mesh::Primitive::TriangleStrip, {}, {{ {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, @@ -40,7 +48,7 @@ Trade::MeshData3D Plane::solid() { {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f} - }}, {}); + }}, std::move(coords)); } Trade::MeshData3D Plane::wireframe() { diff --git a/src/Primitives/Plane.h b/src/Primitives/Plane.h index 163d2cdf8..b25273124 100644 --- a/src/Primitives/Plane.h +++ b/src/Primitives/Plane.h @@ -38,16 +38,25 @@ namespace Magnum { namespace Primitives { @brief 3D plane primitive 2x2 plane. +@see @ref Square */ class MAGNUM_PRIMITIVES_EXPORT Plane { public: + /** @brief Whether to generate texture coordinates */ + enum class TextureCoords: UnsignedByte { + DontGenerate, /**< Don't generate texture coordinates */ + + /** Generate texture coordinates with origin in bottom left corner. */ + Generate + }; + /** * @brief Solid plane * * Non-indexed @ref Mesh::Primitive "TriangleStrip" with normals in * positive Z direction. */ - static Trade::MeshData3D solid(); + static Trade::MeshData3D solid(TextureCoords textureCoords = TextureCoords::DontGenerate); /** * @brief Wireframe plane diff --git a/src/Primitives/Square.cpp b/src/Primitives/Square.cpp index e5bfda106..8f86b1dd3 100644 --- a/src/Primitives/Square.cpp +++ b/src/Primitives/Square.cpp @@ -29,13 +29,21 @@ namespace Magnum { namespace Primitives { -Trade::MeshData2D Square::solid() { +Trade::MeshData2D Square::solid(const TextureCoords textureCoords) { + std::vector> coords; + if(textureCoords == TextureCoords::Generate) coords.push_back({ + {1.0f, 0.0f}, + {1.0f, 1.0f}, + {0.0f, 0.0f}, + {0.0f, 1.0f} + }); + return Trade::MeshData2D(Mesh::Primitive::TriangleStrip, {}, {{ {1.0f, -1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f}, {-1.0f, 1.0f} - }}, {}); + }}, std::move(coords)); } Trade::MeshData2D Square::wireframe() { diff --git a/src/Primitives/Square.h b/src/Primitives/Square.h index 5ba34f1ec..77a7afedb 100644 --- a/src/Primitives/Square.h +++ b/src/Primitives/Square.h @@ -38,15 +38,24 @@ namespace Magnum { namespace Primitives { @brief 2D square primitive 2x2 square. +@see @ref Plane */ class MAGNUM_PRIMITIVES_EXPORT Square { public: + /** @brief Whether to generate texture coordinates */ + enum class TextureCoords: UnsignedByte { + DontGenerate, /**< Don't generate texture coordinates */ + + /** Generate texture coordinates with origin in bottom left corner. */ + Generate + }; + /** * @brief Solid square * * Non-indexed @ref Mesh::Primitive "TriangleStrip". */ - static Trade::MeshData2D solid(); + static Trade::MeshData2D solid(TextureCoords textureCoords = TextureCoords::DontGenerate); /** * @brief Wireframe square