Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
RenderQueue.cpp
Go to the documentation of this file.
1#include "render/RenderQueue.h"
2#include "render/Mesh.h"
3#include "render/Material.h"
4#include "graphics/GraphicsAPI.h"
5#include "graphics/ShaderProgram.h"
6
7namespace eng
8{
10 {
11 m_mesh2D = Mesh::CreatePlane();
12 }
13
15 {
16 m_commands.push_back(command);
17 }
18
20 {
21 m_commands2D.push_back(command);
22 }
23
24 void RenderQueue::Draw(GraphicsAPI& graphicsAPI, const CameraData& cameraData, const std::vector<LightData>& lights)
25 {
26 // 3D
27 for (auto& command : m_commands)
28 {
29 graphicsAPI.BindMaterial(command.material);
30 auto shaderProgram = command.material->GetShaderProgram();
31 shaderProgram->SetUniform("uModel", command.modelMatrix);
32 shaderProgram->SetUniform("uView", cameraData.viewMatrix);
33 shaderProgram->SetUniform("uProjection", cameraData.projectionMatrix);
34 shaderProgram->SetUniform("uCameraPos", cameraData.position);
35 if (!lights.empty())
36 {
37 auto& light = lights[0];
38 shaderProgram->SetUniform("uLight.color", light.color);
39 shaderProgram->SetUniform("uLight.direction", glm::normalize(-light.position));
40 }
41
42 graphicsAPI.BindMesh(command.mesh);
43 graphicsAPI.DrawMesh(command.mesh);
44 graphicsAPI.UnbindMesh(command.mesh);
45 }
46
47 m_commands.clear();
48
49 // 2D
50 graphicsAPI.SetDepthTestEnabled(false);
51 graphicsAPI.SetBlendMode(BlendMode::Alpha);
52 const auto shaderProgram2D = graphicsAPI.GetDefault2DShaderProgram();
53 shaderProgram2D->Bind();
54 m_mesh2D->Bind();
55 for (auto& command : m_commands2D)
56 {
57 // rendering
58 shaderProgram2D->SetUniform("uModel", command.modelMatrix);
59 shaderProgram2D->SetUniform("uView", cameraData.viewMatrix);
60 shaderProgram2D->SetUniform("uProjection", cameraData.orthoMatrix);
61 shaderProgram2D->SetUniform("uSize", command.size.x, command.size.y);
62 shaderProgram2D->SetUniform("uPivot", command.pivot.x, command.pivot.y);
63 shaderProgram2D->SetUniform("uUVMin", command.lowerLeftUV.x, command.lowerLeftUV.y);
64 shaderProgram2D->SetUniform("uUVMax", command.upperRightUV.x, command.upperRightUV.y);
65 shaderProgram2D->SetUniform("uColor", command.color);
66 shaderProgram2D->SetTexture("uTex", command.texture);
67 m_mesh2D->Draw();
68
69 }
70 m_mesh2D->Unbind();
72 graphicsAPI.SetDepthTestEnabled(true);
73 }
74}
void DrawMesh(Mesh *mesh)
void UnbindMesh(Mesh *mesh)
void BindMesh(Mesh *mesh)
void SetDepthTestEnabled(bool enabled)
void BindMaterial(Material *material)
void SetBlendMode(BlendMode mode)
const std::shared_ptr< ShaderProgram > & GetDefault2DShaderProgram()
static std::shared_ptr< Mesh > CreatePlane()
Definition Mesh.cpp:277
void Submit(const RenderCommand &command)
void Draw(GraphicsAPI &graphicsAPI, const CameraData &cameraData, const std::vector< LightData > &lights)
glm::vec3 position
Definition Common.h:13
glm::mat4 orthoMatrix
Definition Common.h:12
glm::mat4 viewMatrix
Definition Common.h:10
glm::mat4 projectionMatrix
Definition Common.h:11