Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
Builder.h
Go to the documentation of this file.
1/**
2 * @file Builder.h
3 * @ingroup mnd_render
4 * @brief Static factory methods for creating common primitive mesh shapes.
5 *
6 * Builder produces MeshData — plain CPU-side geometry bundles (vertices,
7 * indices, layout). Call buildMesh() on the result to upload to the GPU
8 * and get a Mesh ready for rendering.
9 *
10 * ## Typical usage
11 * @code
12 * MeshData data = Builder::CreateRectangle(1.0f, 1.0f);
13 * auto mesh = data.buildMesh(); // uploads to GPU → shared_ptr<Mesh>
14 * // mesh is now ready to submit in a RenderCommand
15 * @endcode
16 *
17 * All generated meshes include position, normal, and UV attributes laid out
18 * according to VertexElement::PositionIndex / NormalIndex / UVIndex.
19 *
20 * @see MeshData, Mesh, VertexLayout
21 */
22
23#pragma once
24
25#include <cstdint>
26#include <memory>
27#include <vector>
28
29#include "Types.h"
30#include "graphics/VertexLayout.h"
31#include "render/Mesh.h"
32
33namespace mnd
34{
35
36/**
37 * @brief CPU-side mesh bundle produced by Builder factory methods.
38 *
39 * Holds raw vertex data, index data, and the VertexLayout that describes
40 * how the interleaved bytes map to shader attributes. Call buildMesh() to
41 * hand the data off to the GPU.
42 */
44{
45 std::vector<f32> vertices; ///< Interleaved vertex data (pos, normal, UV …).
46 std::vector<u32> indices; ///< Triangle list indices (empty → non-indexed draw).
47 VertexLayout layout; ///< Attribute layout that matches the vertex data format.
48
49 /**
50 * @brief Upload this geometry to the GPU and return a renderable Mesh.
51 * @return Shared pointer to the uploaded Mesh.
52 */
53 std::shared_ptr<Mesh> buildMesh();
54};
55
56/**
57 * @brief Factory that generates MeshData for common geometric primitives.
58 *
59 * All methods are static — Builder is never instantiated. Generated shapes
60 * follow a consistent winding order (counter-clockwise front face) compatible
61 * with the engine's default back-face culling state.
62 */
64{
65public:
66 /**
67 * @brief Create a flat quad with the given dimensions.
68 * @param width Extent along the X axis.
69 * @param height Extent along the Y axis.
70 */
71 static MeshData CreateRectangle(f32 width, f32 height);
72
73 /**
74 * @brief Create a box (6 faces) with the given dimensions.
75 * @param width Extent along X.
76 * @param height Extent along Y (also used for Z in the current implementation).
77 */
78 static MeshData CreateCube(f32 width, f32 height);
79
80 /**
81 * @brief Create an equilateral triangle centred at the origin.
82 * @param size Side length.
83 */
84 static MeshData CreateTriangle(f32 size);
85
86 /**
87 * @brief Create a clip-space quad covering the entire screen.
88 *
89 * Useful for post-processing or Shadertoy-style full-screen fragment shaders.
90 * The quad spans NDC [-1, 1] in both X and Y.
91 */
93};
94
95} // namespace mnd
Engine-wide primitive type aliases and GLM math imports.
Factory that generates MeshData for common geometric primitives.
Definition Builder.h:64
static MeshData CreateCube(f32 width, f32 height)
Create a box (6 faces) with the given dimensions.
Definition Builder.cpp:15
static MeshData CreateFullscreenQuad()
Create a clip-space quad covering the entire screen.
Definition Builder.cpp:151
static MeshData CreateRectangle(f32 width, f32 height)
Create a flat quad with the given dimensions.
Definition Builder.cpp:97
static MeshData CreateTriangle(f32 size)
Create an equilateral triangle centred at the origin.
Definition Builder.cpp:124
float f32
32-bit IEEE float — the standard GL scalar type.
Definition Types.h:40
CPU-side mesh bundle produced by Builder factory methods.
Definition Builder.h:44
std::vector< f32 > vertices
Interleaved vertex data (pos, normal, UV …).
Definition Builder.h:45
std::vector< u32 > indices
Triangle list indices (empty → non-indexed draw).
Definition Builder.h:46
std::shared_ptr< Mesh > buildMesh()
Upload this geometry to the GPU and return a renderable Mesh.
Definition Builder.cpp:10
VertexLayout layout
Attribute layout that matches the vertex data format.
Definition Builder.h:47
Complete description of how vertex data is packed in a VBO.