Merge remote-tracking branch 'origin'
This commit is contained in:
144
code/first.c
144
code/first.c
@@ -2,22 +2,24 @@
|
||||
#include <stdbool.h>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION 1
|
||||
#include <stb_image.h>
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/types.h"
|
||||
#include "game/npc.h"
|
||||
#include "os/core.h"
|
||||
|
||||
#include "vulkan/core.h"
|
||||
#include "game/core.h"
|
||||
|
||||
#include "game/impl/player.c"
|
||||
#include "game/world.h"
|
||||
#include "game/impl/npc.c"
|
||||
#include "game/testnavmesh.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
int main(int argc, char **argv) {
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO))
|
||||
{
|
||||
@@ -34,6 +36,44 @@ int main(int argc, char **argv)
|
||||
|
||||
Vk_Setup(window);
|
||||
|
||||
G_State *game = 0;
|
||||
G_Image *img = 0;
|
||||
{
|
||||
M_Arena *arena = M_ArenaAlloc(GB(64), .initial = MB(4));
|
||||
game = M_ArenaPush(arena, G_State);
|
||||
|
||||
game->arena = arena;
|
||||
|
||||
G_ImagesLoad(game);
|
||||
G_PipelinesLoad(game);
|
||||
|
||||
for (U32 it = 0; it < game->n_images; ++it) {
|
||||
if (Str8_Equal(game->images[it].name, S("saloon_ext"), 0)) {
|
||||
img = &game->images[it];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!img) { img = &game->images[0]; }
|
||||
|
||||
Vk_Buffer *vbo = &game->vbo;
|
||||
vbo->size = KB(4096);
|
||||
vbo->usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
||||
vbo->host_visible = true;
|
||||
|
||||
Vk_BufferCreate(vbo);
|
||||
|
||||
G_Vertex *vertices = cast(G_Vertex *) vbo->data;
|
||||
|
||||
vertices[0] = (G_Vertex) { -0.25f, -0.25f, 1.0f, 1.0f, 0.0f, 0.0f, 0xFFFFFFFF, 0};
|
||||
vertices[1] = (G_Vertex) { 0.25f, -0.25f, 1.0f, 1.0f, 1.0f, 0.0f, 0xFFFFFFFF, 0};
|
||||
vertices[2] = (G_Vertex) { -0.25f, 0.25f, 1.0f, 1.0f, 0.0f, 1.0f, 0xFFFFFFFF, 0};
|
||||
|
||||
vertices[3] = (G_Vertex) { 0.25f, -0.25f, 1.0f, 1.0f, 1.0f, 0.0f, 0xFFFFFFFF, 0};
|
||||
vertices[4] = (G_Vertex) { 0.25f, 0.25f, 1.0f, 1.0f, 1.0f, 1.0f, 0xFFFFFFFF, 0};
|
||||
vertices[5] = (G_Vertex) { -0.25f, 0.25f, 1.0f, 1.0f, 0.0f, 1.0f, 0xFFFFFFFF, 0};
|
||||
}
|
||||
|
||||
bool running = true;
|
||||
Player player;
|
||||
player.pos.x = 0;
|
||||
@@ -78,26 +118,6 @@ int main(int argc, char **argv)
|
||||
|
||||
Vk_Frame *frame = Vk_FrameBegin(window);
|
||||
VkCommandBuffer cmd = frame->cmd;
|
||||
VkImageMemoryBarrier2 colour_optimal = {0};
|
||||
colour_optimal.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2;
|
||||
colour_optimal.srcStageMask = VK_PIPELINE_STAGE_2_NONE;
|
||||
colour_optimal.srcAccessMask = VK_ACCESS_2_NONE;
|
||||
colour_optimal.dstStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
colour_optimal.dstAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
colour_optimal.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
colour_optimal.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
colour_optimal.image = vk.swapchain.images[frame->image];
|
||||
|
||||
colour_optimal.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
colour_optimal.subresourceRange.layerCount = 1;
|
||||
colour_optimal.subresourceRange.levelCount = 1;
|
||||
|
||||
VkDependencyInfo colour_barrier = {0};
|
||||
colour_barrier.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
|
||||
colour_barrier.imageMemoryBarrierCount = 1;
|
||||
colour_barrier.pImageMemoryBarriers = &colour_optimal;
|
||||
|
||||
vk.CmdPipelineBarrier2(cmd, &colour_barrier);
|
||||
|
||||
VkClearValue clear_colour;
|
||||
clear_colour.color.float32[0] = 1.0f;
|
||||
@@ -122,28 +142,61 @@ int main(int argc, char **argv)
|
||||
|
||||
vk.CmdBeginRendering(cmd, &rendering_info);
|
||||
|
||||
Vk_Pipeline *basic = &game->pipelines[0];
|
||||
|
||||
VkDescriptorSet set;
|
||||
VkDescriptorSetAllocateInfo alloc_info = { 0 };
|
||||
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||
alloc_info.descriptorPool = frame->descriptors;
|
||||
alloc_info.descriptorSetCount = 1;
|
||||
alloc_info.pSetLayouts = &basic->layout.set;
|
||||
|
||||
vk.AllocateDescriptorSets(vk.device, &alloc_info, &set);
|
||||
|
||||
// 'update' the descriptor sets for binding
|
||||
{
|
||||
VkWriteDescriptorSet writes[2] = { 0 };
|
||||
|
||||
VkDescriptorBufferInfo vbo_info = { 0 };
|
||||
vbo_info.buffer = game->vbo.handle;
|
||||
vbo_info.offset = 0;
|
||||
vbo_info.range = 256;
|
||||
|
||||
VkDescriptorImageInfo image_info = { 0 };
|
||||
image_info.imageView = img->image.view;
|
||||
image_info.sampler = vk.sampler;
|
||||
image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
|
||||
writes[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
writes[0].dstSet = set;
|
||||
writes[0].dstBinding = 0;
|
||||
writes[0].descriptorCount = 1;
|
||||
writes[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
|
||||
writes[0].pBufferInfo = &vbo_info;
|
||||
|
||||
writes[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
writes[1].dstSet = set;
|
||||
writes[1].dstBinding = 1;
|
||||
writes[1].descriptorCount = 1;
|
||||
writes[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
writes[1].pImageInfo = &image_info;
|
||||
|
||||
vk.UpdateDescriptorSets(vk.device, ArraySize(writes), writes, 0, 0);
|
||||
}
|
||||
|
||||
vk.CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, basic->handle);
|
||||
vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, basic->layout.pipeline, 0, 1, &set, 0, 0);
|
||||
|
||||
VkViewport viewport = { 0, 0, (F32) w, (F32) h, 0.0f, 1.0f };
|
||||
VkRect2D scissor = { 0, 0, w, h };
|
||||
|
||||
vk.CmdSetViewport(cmd, 0, 1, &viewport);
|
||||
vk.CmdSetScissor(cmd, 0, 1, &scissor);
|
||||
|
||||
vk.CmdDraw(cmd, 6, 1, 0, 0);
|
||||
|
||||
vk.CmdEndRendering(cmd);
|
||||
|
||||
VkImageMemoryBarrier2 present_src = {0};
|
||||
present_src.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2;
|
||||
present_src.srcStageMask = VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
present_src.srcAccessMask = VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
present_src.dstStageMask = VK_PIPELINE_STAGE_2_NONE;
|
||||
present_src.dstAccessMask = VK_ACCESS_2_NONE;
|
||||
present_src.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
present_src.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
present_src.image = vk.swapchain.images[frame->image];
|
||||
|
||||
present_src.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
present_src.subresourceRange.layerCount = 1;
|
||||
present_src.subresourceRange.levelCount = 1;
|
||||
|
||||
VkDependencyInfo to_present = {0};
|
||||
to_present.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO;
|
||||
to_present.imageMemoryBarrierCount = 1;
|
||||
to_present.pImageMemoryBarriers = &present_src;
|
||||
|
||||
vk.CmdPipelineBarrier2(cmd, &to_present);
|
||||
|
||||
Vk_FrameEnd();
|
||||
}
|
||||
@@ -157,3 +210,4 @@ int main(int argc, char **argv)
|
||||
#include "core/core.c"
|
||||
#include "os/core.c"
|
||||
#include "vulkan/core.c"
|
||||
#include "game/core.c"
|
||||
|
||||
Reference in New Issue
Block a user