summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-05-08 11:56:25 +1000
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-05-08 11:56:25 +1000
commitf1b48b0bbbebb92b9600dac41848304b82f0b3dd (patch)
tree1a66c0ec7c3c1311b8e6f895ac4b504ef6adc894
parentf05ce66a8e6fd0742a8314661a8dc871a5a2c0c3 (diff)
we are so triangle
-rw-r--r--assets/shaders/triangle.vert2
-rw-r--r--examples/triangle/ex_triangle.c4
-rw-r--r--src/renderer/backends/backend_vulkan.c48
3 files changed, 29 insertions, 25 deletions
diff --git a/assets/shaders/triangle.vert b/assets/shaders/triangle.vert
index e160d39..ee3675d 100644
--- a/assets/shaders/triangle.vert
+++ b/assets/shaders/triangle.vert
@@ -1,6 +1,6 @@
#version 450
-vec2 positions[3] = vec2[](vec2(0.0, -0.5), vec2(0.5, 0.5), vec2(-0.5, 0.5));
+vec2 positions[3] = vec2[](vec2(-0.5, 0.5), vec2(0.5, 0.5), vec2(0.0, -0.5));
vec3 colors[3] = vec3[](vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0));
diff --git a/examples/triangle/ex_triangle.c b/examples/triangle/ex_triangle.c
index 50f135a..4aa9e96 100644
--- a/examples/triangle/ex_triangle.c
+++ b/examples/triangle/ex_triangle.c
@@ -45,6 +45,7 @@ int main() {
// Main loop
while (!should_exit(core)) {
+ glfwPollEvents();
input_update(&core->input);
render_frame_begin(&core->renderer);
@@ -72,8 +73,7 @@ int main() {
gpu_backend_end_frame();
render_frame_end(&core->renderer);
- glfwSwapBuffers(core->renderer.window);
- glfwPollEvents();
+ // glfwSwapBuffers(core->renderer.window);
}
gpu_backend_shutdown();
diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c
index 7140d45..e693da3 100644
--- a/src/renderer/backends/backend_vulkan.c
+++ b/src/renderer/backends/backend_vulkan.c
@@ -261,15 +261,16 @@ bool gpu_swapchain_create(gpu_swapchain* out_swapchain) {
TRACE("Vulkan Swapchain created");
// Retrieve Images
- out_swapchain->images =
- arena_alloc(&out_swapchain->swapchain_arena, image_count * sizeof(VkImage));
+ // out_swapchain->images =
+ // arena_alloc(&out_swapchain->swapchain_arena, image_count * sizeof(VkImage));
+ out_swapchain->images = malloc(image_count * sizeof(VkImage));
VK_CHECK(vkGetSwapchainImagesKHR(context.device->logical_device, out_swapchain->handle,
&image_count, out_swapchain->images));
// Create ImageViews
// TODO: Move this to a separate function
- out_swapchain->image_views =
- arena_alloc(&out_swapchain->swapchain_arena, image_count * sizeof(VkImageView));
+ out_swapchain->image_views = malloc(image_count * sizeof(VkImageView));
+ // arena_alloc(&out_swapchain->swapchain_arena, image_count * sizeof(VkImageView));
for (u32 i = 0; i < image_count; i++) {
VkImageViewCreateInfo view_create_info = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };
view_create_info.image = out_swapchain->images[i];
@@ -306,6 +307,8 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
gpu_pipeline* pipeline = malloc(sizeof(gpu_pipeline));
// Shaders
+ printf("Vertex shader: %s\n", description.vs.filepath.buf);
+ printf("Fragment shader: %s\n", description.fs.filepath.buf);
VkShaderModule vertex_shader = create_shader_module(description.vs.code);
VkShaderModule fragment_shader = create_shader_module(description.fs.code);
@@ -358,9 +361,9 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
};
viewport_state.viewportCount = 1;
- viewport_state.pViewports = &viewport;
+ // viewport_state.pViewports = &viewport;
viewport_state.scissorCount = 1;
- viewport_state.pScissors = &scissor;
+ // viewport_state.pScissors = &scissor;
// Rasterizer
VkPipelineRasterizationStateCreateInfo rasterizer_create_info = {
@@ -402,13 +405,13 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
// Blending
VkPipelineColorBlendAttachmentState color_blend_attachment_state;
- color_blend_attachment_state.blendEnable = VK_TRUE;
- color_blend_attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
- color_blend_attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
- color_blend_attachment_state.colorBlendOp = VK_BLEND_OP_ADD;
- color_blend_attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
- color_blend_attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
- color_blend_attachment_state.alphaBlendOp = VK_BLEND_OP_ADD;
+ color_blend_attachment_state.blendEnable = VK_FALSE;
+ // color_blend_attachment_state.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
+ // color_blend_attachment_state.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
+ // color_blend_attachment_state.colorBlendOp = VK_BLEND_OP_ADD;
+ // color_blend_attachment_state.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
+ // color_blend_attachment_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
+ // color_blend_attachment_state.alphaBlendOp = VK_BLEND_OP_ADD;
color_blend_attachment_state.colorWriteMask = VK_COLOR_COMPONENT_R_BIT |
VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
@@ -606,12 +609,13 @@ void gpu_cmd_encoder_begin(gpu_cmd_encoder encoder) {
void gpu_cmd_encoder_begin_render(gpu_cmd_encoder* encoder, gpu_renderpass* renderpass) {
VkRenderPassBeginInfo begin_info = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO };
begin_info.renderPass = renderpass->handle;
+ printf("Current img: %d\n", context.current_img_index);
begin_info.framebuffer = context.swapchain_framebuffers[context.current_img_index];
begin_info.renderArea.offset = (VkOffset2D){ 0, 0 };
begin_info.renderArea.extent = context.swapchain->extent;
// VkClearValue clear_values[2];
- VkClearValue clear_color = { { { 0.0f, 0.0f, 0.0f, 1.0f } } };
+ VkClearValue clear_color = { { { 0.2f, 0.2f, 0.2f, 1.0f } } };
// clear_values[1].depthStencil.depth = renderpass->depth;
// clear_values[1].depthStencil.stencil = renderpass->stencil;
@@ -657,21 +661,22 @@ void encode_set_default_settings(gpu_cmd_encoder* encoder) {
// --- Drawing
void gpu_backend_begin_frame() {
- TRACE("gpu_backend_begin_frame");
+ // TRACE("gpu_backend_begin_frame");
vkWaitForFences(context.device->logical_device, 1, &context.in_flight_fence, VK_TRUE, UINT64_MAX);
vkResetFences(context.device->logical_device, 1, &context.in_flight_fence);
u32 image_index;
- vkAcquireNextImageKHR(context.device->logical_device, context.swapchain->handle, UINT64_MAX,
- context.image_available_semaphore, VK_NULL_HANDLE, &image_index);
+ VK_CHECK(vkAcquireNextImageKHR(context.device->logical_device, context.swapchain->handle,
+ UINT64_MAX, context.image_available_semaphore, VK_NULL_HANDLE,
+ &image_index));
context.current_img_index = image_index;
- DEBUG("Current image_index = %d", image_index);
- vkResetCommandBuffer(context.main_cmd_buf.cmd_buffer, 0);
+ printf("Current img: %d\n", context.current_img_index);
+ VK_CHECK(vkResetCommandBuffer(context.main_cmd_buf.cmd_buffer, 0));
}
void gpu_temp_draw() {
gpu_cmd_encoder* encoder = &context.main_cmd_buf;
-
+ TRACE("Draw call");
vkCmdDraw(encoder->cmd_buffer, 3, 1, 0, 0);
}
@@ -709,8 +714,7 @@ void gpu_queue_submit(gpu_cmd_buffer* buffer) {
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &buffer->cmd_buffer;
- VK_CHECK(
- vkQueueSubmit(context.device->graphics_queue, 1, &submit_info, context.in_flight_fence););
+ VK_CHECK(vkQueueSubmit(context.device->graphics_queue, 1, &submit_info, context.in_flight_fence));
}
inline void encode_draw_indexed(gpu_cmd_encoder* encoder, u64 index_count) {