Added unproject
Broken and buggy font stuff Fixed some typos Fixed draw rect not using dim properly
This commit is contained in:
@@ -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, ©);
|
||||
vk.CmdCopyBufferToImage(cmds->handle, staging->handle, white->image.handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©);
|
||||
|
||||
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, ©);
|
||||
vk.CmdCopyBufferToImage(cmds->handle, staging->handle, image->image.handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©);
|
||||
|
||||
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"
|
||||
|
||||
@@ -25,6 +25,12 @@ function void G_PipelinesLoad(G_State *game);
|
||||
|
||||
function void G_CalculateCamera(G_Camera *camera, F32 aspect);
|
||||
|
||||
// Assumes 'calculate' has been called
|
||||
function V3f G_CameraUnprojectAt(G_Camera *camera, V2f clip, F32 z);
|
||||
function V3f G_CameraUnproject(G_Camera *camera, V2f clip);
|
||||
|
||||
function R3f G_CameraBounds(G_Camera *camera);
|
||||
|
||||
#include "aabb.h"
|
||||
#include "player.h"
|
||||
#include "nav.h"
|
||||
|
||||
@@ -16,3 +16,24 @@ void UpdateNPCs(F32 delta, World *world) {
|
||||
void ProcessEvents(SDL_Event *event, World *world) {
|
||||
PlayerUpdate(event, &world->player);
|
||||
}
|
||||
|
||||
void G_WorldDraw(G_State *game, World *world) {
|
||||
D_Context *draw = &game->draw;
|
||||
|
||||
(void) world;
|
||||
|
||||
for (F32 y = -128; y < 128; y += 1.1f) {
|
||||
for (F32 x = -128; x < 128; x += 1.1f) {
|
||||
|
||||
U32 ux = (U32) x;
|
||||
U32 uy = (U32) y;
|
||||
|
||||
U32 tid = 15;
|
||||
if ((ux % 11) == 0 || ((uy % 7) == 0)) {
|
||||
tid = 16;
|
||||
}
|
||||
|
||||
D_Rect(draw, x, y, .texture = tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,6 @@ function void ProcessEvents(SDL_Event *event, World *world);
|
||||
function void UpdateNPCs(F32 delta, World *world);
|
||||
function void updateNPC(F32 delta, NPC *npc, World *world);
|
||||
|
||||
function void G_WorldDraw(G_State *game, World *world);
|
||||
|
||||
#endif // LD_GAME_WORLD_H_
|
||||
|
||||
Reference in New Issue
Block a user