Skip to content

Commit f4b1f08

Browse files
authored
Merge pull request #31 from CapsCollective/feature/quad-textures
Added Texture2D class and changed Renderer2D to batch quads with textures
2 parents 15c0f54 + 9a7d990 commit f4b1f08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+10148
-976
lines changed

engine/render/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ else ifeq ($(platform), macos)
3434
volkDefines = VK_USE_PLATFORM_MACOS_MVK
3535
glslangValidator := $(vendorDir)/glslang/build/install/bin/glslangValidator
3636
endif
37-
compileFlags += -I $(vendorDir)/vulkan/include -I $(vendorDir)/glfw/include -I $(vendorDir)/glm -I $(vendorDir)/tinyobjloader
37+
compileFlags += -I $(vendorDir)/vulkan/include -I $(vendorDir)/glfw/include -I $(vendorDir)/glm \
38+
-I $(vendorDir)/tinyobjloader -I $(vendorDir)/stb_image
3839

3940
.PHONY: all vulkan-libs
4041

engine/render/assets/shaders/grid.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ void main() {
5656

5757
outColor = (grid(fragPos3D, 1) + grid(fragPos3D, 1))* float(t > 0);
5858
outColor.a *= fading;
59+
60+
if (outColor.a == 0) discard;
5961
}

engine/render/assets/shaders/simpleShader.frag

Lines changed: 0 additions & 9 deletions
This file was deleted.

engine/render/assets/shaders/simpleShader.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ layout (binding = 1) uniform GlobalData {
4040

4141
void main() {
4242

43-
ObjectData object = objectBuffer.objects[gl_BaseInstance];
43+
ObjectData object = objectBuffer.objects[gl_InstanceIndex];
4444

4545
vec4 positionWorld = object.transform * vec4(position, 1.0);
4646

engine/render/assets/shaders/simpleShader2D.vert

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#version 460
2+
3+
layout (location = 0) in vec3 fragColour;
4+
layout (location = 1) in vec2 uv;
5+
layout (location = 2) in flat uint texId;
6+
7+
layout (location = 0) out vec4 outColour;
8+
9+
layout(binding = 1) uniform sampler2D tex[16];
10+
11+
void main() {
12+
vec4 sampled = vec4(texture(tex[texId], uv));
13+
outColour = vec4(fragColour, 1.0) * sampled;
14+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#version 450
2+
3+
layout(location = 0) in vec2 inPosition;
4+
layout (location = 1) in vec2 inUv;
5+
6+
layout(location = 0) out vec3 fragColor;
7+
layout(location = 1) out vec2 outUv;
8+
layout(location = 2) out uint outTexId;
9+
10+
layout (push_constant) uniform Transform
11+
{
12+
mat4 transform;
13+
vec4 texColour;
14+
uint texIndex;
15+
} QuadTransform;
16+
17+
struct CameraData
18+
{
19+
mat4 projectionMatrix;
20+
mat4 viewMatrix;
21+
};
22+
23+
layout (binding = 0) uniform GlobalData {
24+
CameraData cameraData;
25+
} globalData;
26+
27+
CameraData camera = globalData.cameraData;
28+
29+
void main() {
30+
vec4 positionWorld = QuadTransform.transform * vec4(inPosition, 0.0, 1.0);
31+
32+
gl_Position = camera.projectionMatrix * camera.viewMatrix * positionWorld;
33+
34+
fragColor = vec3(QuadTransform.texColour);
35+
outUv = inUv;
36+
outTexId = QuadTransform.texIndex;
37+
}

engine/render/renderer/Renderer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Renderer::Renderer(Window& window) : window {window}
3232
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1024);
3333
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1024);
3434
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1024);
35+
DescriptorPool::AddPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1024);
3536

3637
DescriptorPool::BuildPool();
3738

@@ -46,14 +47,15 @@ Renderer::~Renderer()
4647
CC_LOG_INFO("Destroying renderer")
4748
DescriptorPool::DestroyPool();
4849
Renderer3D::DestroyRenderer3D();
50+
Renderer2D::DestroyRenderer2D();
4951
}
5052

5153
void Renderer::DrawFrame()
5254
{
5355
Renderer2D::GlobalData global2DData = {projection};
5456

55-
Renderer3D::Render(commandBuffers, projection);
56-
Renderer2D::Render(commandBuffers, global2DData);
57+
Renderer3D::Render(currentFrameIndex, commandBuffers, projection);
58+
Renderer2D::Render(commandBuffers, global2DData, currentFrameIndex);
5759
}
5860

5961
void Renderer::RecreateSwapChain()
@@ -110,6 +112,8 @@ bool Renderer::StartFrame()
110112

111113
void Renderer::EndFrame()
112114
{
115+
Renderer2D::Update();
116+
113117
CC_ASSERT(isFrameStarted, "Can't end frame while frame is not in progress!")
114118

115119
auto& swapchain = context.GetSwapchain();

engine/render/renderer/descriptor/DescriptorPool.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
namespace Siege
1616
{
1717
VkDescriptorPool DescriptorPool::descriptorPool {VK_NULL_HANDLE};
18-
Utils::MSArray<VkDescriptorPoolSize, DescriptorPool::MAX_DESCRIPTOR_POOL_SIZES>
19-
DescriptorPool::sizes;
18+
MSArray<VkDescriptorPoolSize, DescriptorPool::MAX_DESCRIPTOR_POOL_SIZES> DescriptorPool::sizes;
2019

2120
void DescriptorPool::AddPoolSize(const VkDescriptorType type, const uint32_t size)
2221
{

engine/render/renderer/descriptor/DescriptorPool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DescriptorPool
3131
static constexpr size_t MAX_DESCRIPTOR_POOL_SIZES = 1024;
3232

3333
static VkDescriptorPool descriptorPool;
34-
static Utils::MSArray<VkDescriptorPoolSize, MAX_DESCRIPTOR_POOL_SIZES> sizes;
34+
static MSArray<VkDescriptorPoolSize, MAX_DESCRIPTOR_POOL_SIZES> sizes;
3535
};
3636
} // namespace Siege
3737

0 commit comments

Comments
 (0)