Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
RenderQueue.cpp
Go to the documentation of this file.
1#include "render/RenderQueue.h"
2
3#include "Common.h"
4#include "Engine.h"
5#include "Log.h"
6#include "editor/Editor.h"
7#include "graphics/GraphicsAPI.h"
9#include "graphics/ShaderProgram.h"
10#include "render/Material.h"
11#include "render/Mesh.h"
12
13namespace mnd
14{
15
17{
18 if (!command.material || !command.mesh)
19 {
21 "RenderQueue::Submit received incomplete command (material=%p mesh=%p)",
22 (void *)command.material,
23 (void *)command.mesh
24 );
25 }
26 m_commands.push_back(command);
27}
28
29void RenderQueue::Draw(GraphicsAPI &graphicsAPI, const CameraData &cameraData, const std::vector<LightData> &lights)
30{
32 int drawn = 0;
33
34 for (auto &command : m_commands)
35 {
36 if (!command.material)
37 {
38 LOG_ERROR("RenderQueue::Draw skipping command with null material");
39 continue;
40 }
41 graphicsAPI.BindMaterial(command.material);
42 auto *program = command.material->GetShaderProgram();
43 if (!program)
44 {
45 LOG_ERROR("RenderQueue::Draw material has no shader program");
46 continue;
47 }
48 program->SetUniform("uModel", command.modelMatrix);
49 program->SetUniform("uView", cameraData.viewMatrix);
50 program->SetUniform("uProjection", cameraData.projectionMatrix);
51 program->SetUniform("uCameraPos", cameraData.position);
52 if (!lights.empty())
53 {
54 auto &light = lights[0];
55 program->SetUniform("uLight.color", light.color);
56 program->SetUniform("uLight.position", light.position);
57 }
58
59 // Editor-controlled PSX shader uniforms. ShaderProgram::SetUniform is a no-op
60 // for shaders that don't declare the uniform, so this is safe across materials.
61 // program->SetUniform("uSnapResolutionX", rs.snapX);
62 // program->SetUniform("uSnapResolutionY", rs.snapY);
63 // program->SetUniform("uFogStart", rs.fogStart);
64 // program->SetUniform("uFogEnd", rs.fogEnd);
65 // program->SetUniform("uAmbient", rs.ambient);
66 // program->SetUniform("uLightDir", rs.lightDir);
67 // program->SetUniform("uColorDepth", rs.colorDepth);
68 // program->SetUniform("uDitherStrength", rs.ditherStrength);
69
70 graphicsAPI.BindMesh(command.mesh);
71 graphicsAPI.DrawMesh(command.mesh);
72 graphicsAPI.UnbindMesh(command.mesh);
73 ++drawn;
74 }
75
76 m_commands.clear();
78}
79
80} // namespace mnd
In-game ImGui overlay: hierarchy, inspector, console, stats.
Console logging macros for all engine and game code.
#define LOG_WARN(fmt,...)
Definition Log.h:80
#define LOG_ERROR(fmt,...)
Definition Log.h:81
Per-frame renderer tuning knobs (PSX-style pixelation, fog, ambient).
void NotifyDrawCount(int n)
Stats panel hook: report per-frame draw call count.
Definition Editor.h:68
Editor & GetEditor()
ImGui-based editor overlay.
Definition Engine.h:149
static Engine & GetInstance()
Returns the single Engine instance (created on first call).
Definition Engine.cpp:59
RenderSettings & GetRenderSettings()
Mutable render settings edited by the Editor's Render panel.
Definition Engine.h:152
OpenGL 3.3 Core Profile abstraction layer.
Definition GraphicsAPI.h:41
void BindMaterial(Material *material)
Upload all material parameters as uniforms to the active shader.
void UnbindMesh(Mesh *mesh)
void DrawMesh(Mesh *mesh)
Issue a draw call for the bound mesh.
void BindMesh(Mesh *mesh)
Bind the mesh's VAO so the next draw call uses its geometry.
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.
Per-frame camera matrices and world-space position.
Definition Common.h:35
mat4 projectionMatrix
Camera → Clip space transform (perspective or ortho).
Definition Common.h:37
mat4 viewMatrix
World → Camera space transform (glm::lookAt result).
Definition Common.h:36
vec3 position
Camera world-space position, used for specular calculations.
Definition Common.h:38
One draw call unit: a Mesh + Material + world-space transform.
Definition RenderQueue.h:44
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