Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
MeshComponent.h
Go to the documentation of this file.
1/**
2 * @file MeshComponent.h
3 * @ingroup mnd_components
4 * @brief Bridges the scene graph with the render pipeline by submitting a RenderCommand each frame.
5 *
6 * Attaching a MeshComponent to a GameObject makes it visible. On each
7 * Update() call the component reads the owner's world transform, packages
8 * it together with its Mesh and Material into a RenderCommand, and submits
9 * it to the engine's RenderQueue.
10 *
11 * ## Ownership model
12 * Both Mesh and Material are shared via shared_ptr — multiple MeshComponents
13 * (and multiple GameObjects) can reference the same GPU resources without
14 * duplication. The RenderCommand holds only raw pointers for the duration of
15 * the frame; it does not extend lifetime.
16 *
17 * @see RenderCommand, RenderQueue::Submit, Material, Mesh
18 */
19
20#pragma once
21
22#include <memory>
23
24#include "Types.h"
25#include "scene/Component.h"
26
27namespace mnd
28{
29
30class Material;
31class Mesh;
32
33/**
34 * @brief Makes a GameObject renderable by submitting its mesh each frame.
35 *
36 * Update() packages (Mesh + Material + owner world transform) into a
37 * RenderCommand and hands it to the engine's RenderQueue. The actual draw
38 * call happens later in RenderQueue::Draw().
39 */
41{
43
44public:
45 /**
46 * @brief Construct a MeshComponent with a mesh-material pair.
47 * @param material The surface description (shader + uniforms + textures).
48 * @param mesh The GPU geometry to draw.
49 */
50 MeshComponent() = default;
51 MeshComponent(const std::shared_ptr<Material> &material, const std::shared_ptr<Mesh> &mesh);
52
53 /**
54 * @brief Submit a RenderCommand for this object's current world transform.
55 * @param deltaTime Not used directly, but keeps the Component interface uniform.
56 */
57 void Update(f32 deltaTime) override;
58 void SetMaterial(const std::shared_ptr<Material> &material);
59 void SetMesh(const std::shared_ptr<Mesh> &mesh);
60
61 void LoadProperties(const nlohmann::json &json) override;
62
63private:
64 std::shared_ptr<Material> m_material; ///< Shared surface material (shader + params).
65 std::shared_ptr<Mesh> m_mesh; ///< Shared GPU geometry.
66};
67
68} // namespace mnd
std::shared_ptr< Material > material
std::shared_ptr< Mesh > mesh
Engine-wide primitive type aliases and GLM math imports.
Makes a GameObject renderable by submitting its mesh each frame.
void LoadProperties(const nlohmann::json &json) override
MeshComponent()=default
Construct a MeshComponent with a mesh-material pair.
void Update(f32 deltaTime) override
Submit a RenderCommand for this object's current world transform.
void SetMesh(const std::shared_ptr< Mesh > &mesh)
void SetMaterial(const std::shared_ptr< Material > &material)
#define COMPONENT(ComponentClass)
Definition Component.h:105
float f32
32-bit IEEE float — the standard GL scalar type.
Definition Types.h:40