Merge remote-tracking branch 'origin'
This commit is contained in:
125
code/first.c
125
code/first.c
@@ -11,6 +11,8 @@
|
||||
#include "os/core.h"
|
||||
|
||||
#include "vulkan/core.h"
|
||||
#include "draw/core.h"
|
||||
|
||||
#include "game/core.h"
|
||||
|
||||
#include "game/impl/world.c"
|
||||
@@ -37,7 +39,6 @@ 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);
|
||||
@@ -47,33 +48,28 @@ int main(int argc, char **argv) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
G_Camera *camera = &game->camera;
|
||||
|
||||
if (!img) { img = &game->images[0]; }
|
||||
camera->x = V3F(1, 0, 0);
|
||||
camera->y = V3F(0, 1, 0);
|
||||
camera->z = V3F(0, 0, 1);
|
||||
camera->p = V3F(0, 0, 48);
|
||||
|
||||
Vk_Buffer *vbo = &game->vbo;
|
||||
vbo->size = KB(4096);
|
||||
vbo->usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
||||
vbo->host_visible = true;
|
||||
camera->fov = 60.0f;
|
||||
|
||||
Vk_BufferCreate(vbo);
|
||||
camera->nearp = 0.01f;
|
||||
camera->farp = 1000.0f;
|
||||
|
||||
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};
|
||||
game->draw.camera = camera;
|
||||
}
|
||||
|
||||
Vk_Buffer rbo = { 0 };
|
||||
rbo.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
||||
rbo.size = KB(4);
|
||||
rbo.host_visible = true;
|
||||
|
||||
Vk_BufferCreate(&rbo);
|
||||
|
||||
bool running = true;
|
||||
World world = {
|
||||
.npcCount = 2,
|
||||
@@ -94,10 +90,13 @@ int main(int argc, char **argv) {
|
||||
.currentNavNode = 0
|
||||
}
|
||||
},
|
||||
.navMesh = TestNavMesh,
|
||||
.navMesh = &TestNavMesh,
|
||||
.npcPOI = {100},
|
||||
.player = {.pos = {0,0}}
|
||||
};
|
||||
|
||||
printf("%zu size in bytes\n", sizeof(TestNavMesh));
|
||||
|
||||
while (running)
|
||||
{
|
||||
SDL_Event e;
|
||||
@@ -114,6 +113,11 @@ int main(int argc, char **argv) {
|
||||
int w, h;
|
||||
SDL_GetWindowSizeInPixels(window, &w, &h);
|
||||
|
||||
game->draw.window_width = w;
|
||||
game->draw.window_height = h;
|
||||
|
||||
G_CalulateCamera(&game->camera, (F32) w / (F32) h);
|
||||
|
||||
Vk_Frame *frame = Vk_FrameBegin(window);
|
||||
VkCommandBuffer cmd = frame->cmd;
|
||||
|
||||
@@ -124,78 +128,32 @@ int main(int argc, char **argv) {
|
||||
clear_colour.color.float32[3] = 1.0f;
|
||||
|
||||
VkRenderingAttachmentInfo colour_attachment = {0};
|
||||
colour_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
||||
colour_attachment.imageView = vk.swapchain.views[frame->image];
|
||||
colour_attachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
||||
colour_attachment.imageView = vk.swapchain.views[frame->image];
|
||||
colour_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
colour_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
colour_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
colour_attachment.clearValue = clear_colour;
|
||||
colour_attachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
colour_attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
colour_attachment.clearValue = clear_colour;
|
||||
|
||||
VkRenderingInfo rendering_info = {0};
|
||||
rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
|
||||
rendering_info.renderArea = (VkRect2D){0, 0, w, h};
|
||||
rendering_info.layerCount = 1;
|
||||
rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO;
|
||||
rendering_info.renderArea = (VkRect2D) { 0, 0, w, h };
|
||||
rendering_info.layerCount = 1;
|
||||
rendering_info.colorAttachmentCount = 1;
|
||||
rendering_info.pColorAttachments = &colour_attachment;
|
||||
rendering_info.pColorAttachments = &colour_attachment;
|
||||
|
||||
vk.CmdBeginRendering(cmd, &rendering_info);
|
||||
|
||||
Vk_Pipeline *basic = &game->pipelines[0];
|
||||
D_Begin(&game->draw, frame, D_MAX_RECTS);
|
||||
|
||||
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;
|
||||
D_Rect(&game->draw, 0.0f, 0.0f, .texture = 1);
|
||||
D_Rect(&game->draw, -8.0f, 0.0f, .texture = 2, .scale = 2.0f);
|
||||
D_Rect(&game->draw, 6.0f, 0.0f, .texture = 3);
|
||||
|
||||
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);
|
||||
D_End(&game->draw, frame);
|
||||
|
||||
vk.CmdEndRendering(cmd);
|
||||
|
||||
|
||||
Vk_FrameEnd();
|
||||
}
|
||||
|
||||
@@ -208,4 +166,5 @@ int main(int argc, char **argv) {
|
||||
#include "core/core.c"
|
||||
#include "os/core.c"
|
||||
#include "vulkan/core.c"
|
||||
#include "draw/core.c"
|
||||
#include "game/core.c"
|
||||
|
||||
Reference in New Issue
Block a user