Added unproject

Broken and buggy font stuff
Fixed some typos
Fixed draw rect not using dim properly
This commit is contained in:
2025-10-05 21:11:18 +01:00
parent 5cabf845b6
commit eb3c81cd04
11 changed files with 349 additions and 22 deletions

View File

@@ -9,14 +9,14 @@ void G_ImagesLoad(G_State *game) {
FS_List assets = FS_PathList(temp.arena, path);
Vk_Buffer staging = { 0 };
staging.size = MB(256);
staging.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
staging.host_visible = true;
Vk_Buffer *staging = &draw->staging;
staging->size = MB(256);
staging->usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
staging->host_visible = true;
Vk_BufferCreate(&staging);
Vk_BufferCreate(staging);
U8 *base = staging.data;
U8 *base = staging->data;
U64 offset = 0;
Vk_CommandBuffer *cmds = Vk_CommandBufferPush();
@@ -108,7 +108,7 @@ void G_ImagesLoad(G_State *game) {
vk.CmdPipelineBarrier2(cmds->handle, &dep);
vk.CmdCopyBufferToImage(cmds->handle, staging.handle, white->image.handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy);
vk.CmdCopyBufferToImage(cmds->handle, staging->handle, white->image.handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy);
dep.pImageMemoryBarriers = &shader_read;
@@ -145,7 +145,7 @@ void G_ImagesLoad(G_State *game) {
base += image_sz;
offset += image_sz;
Assert(offset <= staging.size);
Assert(offset <= staging->size);
draw->n_images += 1;
@@ -198,7 +198,7 @@ void G_ImagesLoad(G_State *game) {
vk.CmdPipelineBarrier2(cmds->handle, &dep);
vk.CmdCopyBufferToImage(cmds->handle, staging.handle, image->image.handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy);
vk.CmdCopyBufferToImage(cmds->handle, staging->handle, image->image.handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy);
dep.pImageMemoryBarriers = &shader_read;
@@ -251,7 +251,7 @@ void G_PipelinesLoad(G_State *game) {
bindings[1].binding = 1;
bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
bindings[1].descriptorCount = game->draw.n_images;
bindings[1].descriptorCount = game->draw.n_images + game->draw.n_fonts;
bindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
VkDescriptorSetLayoutCreateInfo set_info = { 0 };
@@ -298,6 +298,32 @@ void G_CalculateCamera(G_Camera *camera, F32 aspect) {
camera->proj.inv = M4x4F_Mul(view.inv, proj.inv);
}
V3f G_CameraUnprojectAt(G_Camera *camera, V2f clip, F32 z) {
V3f dir = V3f_Sub(camera->p, V3f_Scale(camera->z, z));
V4f z_dist = V4F(dir.x, dir.y, dir.z, 1.0f);
V4f persp = M4x4F_VMul4(camera->proj.fwd, z_dist);
clip = V2f_Scale(clip, persp.w);
V4f world = M4x4F_VMul4(camera->proj.inv, V4F(clip.x, clip.y, persp.z, persp.w));
V3f result = world.xyz;
return result;
}
V3f G_CameraUnproject(G_Camera *camera, V2f clip) {
V3f result = G_CameraUnprojectAt(camera, clip, camera->p.z);
return result;
}
R3f G_CameraBounds(G_Camera *camera) {
R3f result;
result.min = G_CameraUnproject(camera, V2F(-1, -1));
result.max = G_CameraUnproject(camera, V2F( 1, 1));
return result;
}
#include "impl/aabb.c"
#include "impl/nav.c"
#include "impl/player.c"