Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
RenderQueue.h
Go to the documentation of this file.
1/**
2 * @file RenderQueue.h
3 * @ingroup mnd_render
4 * @brief Per-frame command list that batches and issues all draw calls.
5 *
6 * ## Why a command queue?
7 * Separating "what to draw" from "when to draw" gives the engine a clean
8 * boundary between game logic and rendering. Application::Update() submits
9 * RenderCommands by value; the engine drains and draws the queue once per
10 * frame after Update() returns.
11 *
12 * ## Frame lifecycle
13 * 1. Game code (via MeshComponent::Update or manual calls) calls Submit().
14 * 2. Engine::Run() calls RenderQueue::Draw() after all updates are done.
15 * 3. Draw() iterates the command list, binds each material + mesh, uploads
16 * MVP and light uniforms, and issues the GL draw call.
17 * 4. The command list is cleared automatically at the end of Draw(), ready
18 * for the next frame.
19 *
20 * @see RenderCommand, GraphicsAPI::DrawMesh, Engine::Run
21 */
22
23#pragma once
24
25#include <vector>
26
27#include "Common.h"
28#include "Types.h"
29
30namespace mnd
31{
32class Mesh;
33class Material;
34class GraphicsAPI;
35
36/**
37 * @brief One draw call unit: a Mesh + Material + world-space transform.
38 *
39 * Submitted by application code each frame. The RenderQueue processes it
40 * during Draw() by binding the material, uploading the model matrix as a
41 * uniform, binding the mesh, and calling GraphicsAPI::DrawMesh().
42 */
44{
45 Mesh *mesh = nullptr; ///< Geometry to draw (non-owning raw pointer).
46 Material *material = nullptr; ///< Surface definition (non-owning raw pointer).
47 mat4 modelMatrix; ///< Object → World transform for this draw call.
48};
49
50/**
51 * @brief Accumulates RenderCommands during Update and draws them in one pass.
52 *
53 * The queue is stateless across frames — it is filled during Update and
54 * drained (and cleared) during Draw, forming a clean producer/consumer pattern.
55 */
57{
58public:
59 /**
60 * @brief Add a draw command to the queue for this frame.
61 * @param command The mesh + material + transform to be drawn.
62 */
63 void Submit(const RenderCommand &command);
64
65 /**
66 * @brief Draw all submitted commands, then clear the queue.
67 *
68 * For each command:
69 * 1. Bind the material's shader program.
70 * 2. Upload view, projection, and model matrices as uniforms.
71 * 3. Upload camera position and all light data as uniforms.
72 * 4. Bind the material (textures + float params).
73 * 5. Bind the mesh VAO and issue the draw call.
74 *
75 * @param graphicsAPI The GL wrapper that issues the actual gl* calls.
76 * @param cameraData View and projection matrices for this frame.
77 * @param lights World-space light positions and colours.
78 */
79 void Draw(GraphicsAPI &graphicsAPI, const CameraData &cameraData, const std::vector<LightData> &lights);
80
81private:
82 std::vector<RenderCommand> m_commands; ///< Commands accumulated this frame; cleared after Draw().
83};
84
85} // namespace mnd
Engine-wide primitive type aliases and GLM math imports.
OpenGL 3.3 Core Profile abstraction layer.
Definition GraphicsAPI.h:41
Shader + uniform storage that defines how a surface is rendered.
Definition Material.h:54
Immutable GPU mesh (VAO + VBO + optional EBO).
Definition Mesh.h:43
Accumulates RenderCommands during Update and draws them in one pass.
Definition RenderQueue.h:57
void Draw(GraphicsAPI &graphicsAPI, const CameraData &cameraData, const std::vector< LightData > &lights)
Draw all submitted commands, then clear the queue.
void Submit(const RenderCommand &command)
Add a draw command to the queue for this frame.
glm::mat4 mat4
4×4 column-major float matrix (model/view/projection).
Definition Types.h:63
Per-frame camera matrices and world-space position.
Definition Common.h:35
One draw call unit: a Mesh + Material + world-space transform.
Definition RenderQueue.h:44
mat4 modelMatrix
Object → World transform for this draw call.
Definition RenderQueue.h:47
Mesh * mesh
Geometry to draw (non-owning raw pointer).
Definition RenderQueue.h:45
Material * material
Surface definition (non-owning raw pointer).
Definition RenderQueue.h:46