Skip to content

Commit 9a7d990

Browse files
committed
Added docs to the Mesh class and edited the Renderer2D push constant
1 parent 104cd51 commit 9a7d990

File tree

19 files changed

+263
-86
lines changed

19 files changed

+263
-86
lines changed

engine/render/assets/shaders/texturedQuad.vert

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#version 450
22

33
layout(location = 0) in vec2 inPosition;
4-
layout(location = 1) in vec4 inColor;
5-
layout (location = 2) in vec2 inUv;
4+
layout (location = 1) in vec2 inUv;
65

76
layout(location = 0) out vec3 fragColor;
87
layout(location = 1) out vec2 outUv;
@@ -11,6 +10,7 @@ layout(location = 2) out uint outTexId;
1110
layout (push_constant) uniform Transform
1211
{
1312
mat4 transform;
13+
vec4 texColour;
1414
uint texIndex;
1515
} QuadTransform;
1616

@@ -31,7 +31,7 @@ void main() {
3131

3232
gl_Position = camera.projectionMatrix * camera.viewMatrix * positionWorld;
3333

34-
fragColor = vec3(inColor);
34+
fragColor = vec3(QuadTransform.texColour);
3535
outUv = inUv;
3636
outTexId = QuadTransform.texIndex;
3737
}

engine/render/renderer/lights/PointLight.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#ifndef SIEGE_ENGINE_POINT_LIGHT_H
1010
#define SIEGE_ENGINE_POINT_LIGHT_H
1111

12+
#include <utils/Colour.h>
13+
1214
#include "../Core.h"
1315
#include "../model/Model.h"
1416

15-
#include <utils/Colour.h>
16-
1717
namespace Siege
1818
{
1919

engine/render/renderer/model/Model.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,14 @@ void Model::LoadModelFromFile(const String& filePath)
144144

145145
using Vulkan::Mesh;
146146

147-
SetMesh(Mesh({sizeof(ModelVertex3D),
148-
objVertices.data(),
149-
static_cast<uint32_t>(objVertices.size())},{objIndices.data(),
150-
static_cast<uint32_t>(objIndices.size())}));
147+
SetMesh(
148+
Mesh({sizeof(ModelVertex3D), objVertices.data(), static_cast<uint32_t>(objVertices.size())},
149+
{objIndices.data(), static_cast<uint32_t>(objIndices.size())}));
151150
}
152151

153-
void Model::UpdateMeshIndexed(uint32_t currentFrame, const Vulkan::Mesh::VertexData& vertexData, const Vulkan::Mesh::IndexData& indices)
152+
void Model::UpdateMeshIndexed(uint32_t currentFrame,
153+
const Vulkan::Mesh::VertexData& vertexData,
154+
const Vulkan::Mesh::IndexData& indices)
154155
{
155156
mesh.UpdateIndexed(vertexData, indices, currentFrame);
156157
}
@@ -175,12 +176,16 @@ void Model::BindIndexed(Vulkan::CommandBuffer& commandBuffer, uint32_t frameInde
175176
mesh.BindIndexed(commandBuffer, frameIndex);
176177
}
177178

178-
void Model::Draw(Vulkan::CommandBuffer& commandBuffer, uint32_t currentFrame, const uint32_t& instances)
179+
void Model::Draw(Vulkan::CommandBuffer& commandBuffer,
180+
uint32_t currentFrame,
181+
const uint32_t& instances)
179182
{
180183
vkCmdDraw(commandBuffer.Get(), mesh.GetVertexCount(currentFrame), 1, 0, instances);
181184
}
182185

183-
void Model::DrawIndexed(Vulkan::CommandBuffer& commandBuffer, const uint32_t frameIndex, const uint32_t& instances)
186+
void Model::DrawIndexed(Vulkan::CommandBuffer& commandBuffer,
187+
const uint32_t frameIndex,
188+
const uint32_t& instances)
184189
{
185190
vkCmdDrawIndexed(commandBuffer.Get(), mesh.GetIndexCount(frameIndex), 1, 0, 0, instances);
186191
}

engine/render/renderer/model/Model.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#ifndef SIEGE_ENGINE_MODEL_H
1010
#define SIEGE_ENGINE_MODEL_H
1111

12+
#include <utils/Colour.h>
1213
#include <utils/Hash.h>
1314
#include <utils/math/mat/Mat4.h>
1415

1516
#include <unordered_map>
16-
#include <utils/Colour.h>
1717

1818
#include "../buffer/Buffer.h"
1919
#include "render/renderer/platform/vulkan/Material.h"
@@ -28,6 +28,7 @@ namespace Siege
2828
class Model
2929
{
3030
public:
31+
3132
// TODO(Aryeh): Move model loading into a separate file? That way we can separate the Vertex
3233
// TODO(Aryeh): from this class
3334
struct ModelVertex3D
@@ -65,15 +66,21 @@ class Model
6566
void Bind(Vulkan::CommandBuffer& commandBuffer, uint32_t frameIndex);
6667
void BindIndexed(Vulkan::CommandBuffer& commandBuffer, uint32_t frameIndex);
6768

68-
void Draw(Vulkan::CommandBuffer& commandBuffer, uint32_t currentFrame, const uint32_t& instances = 0);
69-
void DrawIndexed(Vulkan::CommandBuffer& commandBuffer, const uint32_t frameIndex, const uint32_t& instance = 0);
69+
void Draw(Vulkan::CommandBuffer& commandBuffer,
70+
uint32_t currentFrame,
71+
const uint32_t& instances = 0);
72+
void DrawIndexed(Vulkan::CommandBuffer& commandBuffer,
73+
const uint32_t frameIndex,
74+
const uint32_t& instance = 0);
7075

7176
Vulkan::Material* GetMaterial()
7277
{
7378
return material;
7479
}
7580

76-
void UpdateMeshIndexed(uint32_t currentFrame, const Vulkan::Mesh::VertexData& vertexData, const Vulkan::Mesh::IndexData& indices);
81+
void UpdateMeshIndexed(uint32_t currentFrame,
82+
const Vulkan::Mesh::VertexData& vertexData,
83+
const Vulkan::Mesh::IndexData& indices);
7784
void UpdateMesh(uint32_t currentFrame, const Vulkan::Mesh::VertexData& vertexData);
7885
void SetMesh(Vulkan::Mesh&& newMesh);
7986
void SetMaterial(Vulkan::Material* newMaterial)

engine/render/renderer/platform/vulkan/Mesh.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
//
88

99
#include "Mesh.h"
10-
#include "Swapchain.h"
11-
#include "utils/TypeAdaptor.h"
1210

1311
#include <utils/Logging.h>
1412

13+
#include "Swapchain.h"
14+
#include "utils/TypeAdaptor.h"
15+
1516
namespace Siege::Vulkan
1617
{
1718
Mesh::Mesh(const VertexData& vertices)
@@ -24,7 +25,7 @@ Mesh::Mesh(const VertexData& vertices)
2425

2526
if (vertices.count == 0) return;
2627

27-
for(size_t i = 0; i < frames; i++) SetVertexBuffers(vertices, i);
28+
for (size_t i = 0; i < frames; i++) SetVertexBuffers(vertices, i);
2829
}
2930

3031
Mesh::Mesh(const VertexData& vertices, const IndexData& indices) : Mesh(vertices)
@@ -37,7 +38,7 @@ Mesh::Mesh(const VertexData& vertices, const IndexData& indices) : Mesh(vertices
3738

3839
if (indices.count == 0) return;
3940

40-
for(size_t i = 0; i < frames; i++) SetIndexBuffers(indices, i);
41+
for (size_t i = 0; i < frames; i++) SetIndexBuffers(indices, i);
4142
}
4243

4344
void Mesh::Swap(Mesh& other)
@@ -59,8 +60,15 @@ Mesh::~Mesh()
5960

6061
void Mesh::Free()
6162
{
62-
perFrameVertexBuffers.MForEach(LAMBDA(VertexBufferUpdate& buffer){ Buffer::DestroyBuffer(buffer.updateBuffer); });
63-
perFrameIndexBuffers.MForEach(LAMBDA(IndexBufferUpdate& buffer){ Buffer::DestroyBuffer(buffer.updateBuffer); });
63+
for (auto it = perFrameVertexBuffers.CreateIterator(); it; ++it)
64+
{
65+
Buffer::DestroyBuffer((*it).updateBuffer);
66+
}
67+
68+
for (auto it = perFrameIndexBuffers.CreateIterator(); it; ++it)
69+
{
70+
Buffer::DestroyBuffer((*it).updateBuffer);
71+
}
6472

6573
perFrameVertexBuffers.Clear();
6674
perFrameIndexBuffers.Clear();
@@ -83,10 +91,14 @@ void Mesh::SetVertexBuffers(const VertexData& vertices, uint32_t currentFrame)
8391
if (vertices.count > vertexBufferUpdate.count)
8492
{
8593
Buffer::DestroyBuffer(vertexBufferUpdate.updateBuffer);
86-
AllocateBuffer(vertexBufferUpdate.updateBuffer, vertices.vertexSize * vertices.count, Utils::BufferType::VERTEX_BUFFER);
94+
AllocateBuffer(vertexBufferUpdate.updateBuffer,
95+
vertices.vertexSize * vertices.count,
96+
Utils::BufferType::VERTEX_BUFFER);
8797
}
8898

89-
Buffer::CopyData(vertexBufferUpdate.updateBuffer, vertices.vertexSize * vertices.count, vertices.vertices);
99+
Buffer::CopyData(vertexBufferUpdate.updateBuffer,
100+
vertices.vertexSize * vertices.count,
101+
vertices.vertices);
90102

91103
vertexBufferUpdate.count = vertices.count;
92104
}
@@ -98,10 +110,14 @@ void Mesh::SetIndexBuffers(const IndexData& indices, uint32_t currentFrame)
98110
if (indices.count > indexBufferUpdate.count)
99111
{
100112
Buffer::DestroyBuffer(indexBufferUpdate.updateBuffer);
101-
AllocateBuffer(indexBufferUpdate.updateBuffer, sizeof(uint32_t) * indices.count, Utils::BufferType::INDEX_BUFFER);
113+
AllocateBuffer(indexBufferUpdate.updateBuffer,
114+
sizeof(uint32_t) * indices.count,
115+
Utils::BufferType::INDEX_BUFFER);
102116
}
103117

104-
Buffer::CopyData(indexBufferUpdate.updateBuffer, indices.count * sizeof(uint32_t), indices.indices);
118+
Buffer::CopyData(indexBufferUpdate.updateBuffer,
119+
indices.count * sizeof(uint32_t),
120+
indices.indices);
105121

106122
indexBufferUpdate.count = indices.count;
107123
}
@@ -125,7 +141,9 @@ void Mesh::Update(const VertexData& vertices, uint32_t currentFrameIndex)
125141
SetVertexBuffers(vertices, currentFrameIndex);
126142
}
127143

128-
void Mesh::UpdateIndexed(const VertexData& vertices, const IndexData& indices, uint32_t currentFrameIndex)
144+
void Mesh::UpdateIndexed(const VertexData& vertices,
145+
const IndexData& indices,
146+
uint32_t currentFrameIndex)
129147
{
130148
Update(vertices, currentFrameIndex);
131149
SetIndexBuffers(indices, currentFrameIndex);

0 commit comments

Comments
 (0)