fixed issue with texture loading in asset packer, fixed shader bug, textures now work

This commit is contained in:
Matthew 2025-05-10 17:04:56 +10:00
parent 5ff767e916
commit 2ae1196e25
12 changed files with 51 additions and 22 deletions

BIN
assets/cheesoid.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

BIN
assets/ham_smoke.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 KiB

BIN
assets/hamster.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 961 KiB

View File

@ -32,6 +32,9 @@ typedef enum TextureAsset_e : u32
PATTERMON_OBESE,
PATTERMON_PURPLOID,
PATTERMON_ORIENTAL,
HAMSTER,
HAMSMOKER,
CHEESOID,
TEXTURE_ASSET_MAX
} TextureAsset;

View File

@ -78,9 +78,13 @@ static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count)
rViewportSize(&ctx->pc.res);
rDescHandle pattermon = rTextureCreateAndUpload(PATTERMON_OBESE);
rDescHandle pattermon = rTextureLoad(CHEESOID);
rDescHandle purplemon = rTextureLoad(HAMSMOKER);
rDescHandle pattermon2 = rTextureLoad(HAMSTER);
gWindow(ctx, "Pattermon", 100.0f, 100.0f, 300.0f, 300.0f, pattermon);
gWindow(ctx, "Pattermon2", 350.0f, 350.0f, 550.0f, 550.0f, purplemon);
gWindow(ctx, "Pattermon3", 600.0f, 100.0f, 800.0f, 300.0f, pattermon2);
rawptr vert_buffer = rBufferGUIVertMapping();
rawptr idx_buffer = rBufferGUIIdxMapping();

View File

@ -30,6 +30,9 @@ const FileMapping g_Texture_File_Map[] = {
{ .file_name = "pattermon.png", .ix = PATTERMON_OBESE },
{ .file_name = "patamon.png", .ix = PATTERMON_ORIENTAL },
{ .file_name = "purplemon.png", .ix = PATTERMON_PURPLOID },
{ .file_name = "hamster.png", .ix = HAMSTER },
{ .file_name = "ham_smoke.png", .ix = HAMSMOKER },
{ .file_name = "cheesoid.png", .ix = CHEESOID },
};
c8 *g_Shader_File_Names[SHADER_ASSET_MAX] = {0};
@ -211,7 +214,7 @@ void PackFiles(Arena *arena, FileHeader *header)
{
c8 *asset_name = g_Shader_File_Names[i];
//Printfln("Packing file: %s...", asset_name);
Printfln("Packing file: %s...", asset_name);
FILE *asset_file = OpenFile(asset_name, "r");
u64 file_size = FileLength(asset_file);
@ -238,7 +241,7 @@ void PackFiles(Arena *arena, FileHeader *header)
{
c8 *asset_name = g_Texture_File_Names[i];
//Printfln("Packing file: %s...", asset_name);
Printfln("Packing file: %s...", asset_name);
FILE *asset_file = OpenFile(asset_name, "r");
u64 file_size = FileLength(asset_file);
@ -246,8 +249,9 @@ void PackFiles(Arena *arena, FileHeader *header)
u8 *file_data = MakeArray(arena, u8, file_size);
ReadData(file_data, 0, file_size, asset_file);
int w, h, ch;
u8 *image_bytes = stbi_load_from_memory(file_data, file_size, &w, &h, &ch, 4);
int ch = 4;
int w, h, has_ch;
u8 *image_bytes = stbi_load_from_memory(file_data, file_size, &w, &h, &has_ch, ch);
u64 loaded_length = u64(w * h * ch);
@ -296,8 +300,9 @@ static inline void TestAssetIsCorrect(Arena *arena, c8 *file_name, AssetFile *fi
u64 image_length;
if (type == TEXTURE_ASSET)
{
int w, h, ch;
image_bytes = stbi_load_from_memory(file_data, size, &w, &h, &ch, 4);
int ch = 4;
int w, h, has_ch;
image_bytes = stbi_load_from_memory(file_data, size, &w, &h, &has_ch, ch);
image_length = u64(w * h * ch);
Assert(file_info->len == image_length, "file length incorrect");

View File

@ -92,8 +92,6 @@ typedef struct rMappedBuffer
u32 elem_count;
} rMappedBuffer;
typedef u32 rAssetHandle;
typedef rawptr rBuffer;
// ::Renderer::Initialization::Header::
@ -108,10 +106,10 @@ static b32 rBufferMap();
static void rBufferFree(rRenderBuffer *buffers, u32 buffer_count);
static b32 rBufferUpload(rRenderBuffer **buffer, rawptr *ptr, u32 count, u32 thr_ix);
static void rBufferCreateAndUpload(ModelAsset asset_id);
static rDescHandle rTextureCreateAndUpload(TextureAsset asset_id);
static rDescHandle rTextureLoad(TextureAsset asset_id);
static void rTextureUnload(rDescHandle handle);
static void rBufferBindVertex(rRenderBuffer *buffer);
static void rBufferBindIndex(rRenderBuffer *buffer);
static rAssetHandle rTextureLoad(TextureAsset asset_id);
static void rBufferQueueReset();
static rawptr rBufferGUIVertMapping();
static rawptr rBufferGUIIdxMapping();

View File

@ -927,6 +927,13 @@ static b32 vDeviceCheckFeatureSupport(VkPhysicalDevice device)
result &= (b32)features_12.descriptorIndexing;
result &= (b32)features_12.bufferDeviceAddress;
result &= (b32)features_12.descriptorBindingUniformBufferUpdateAfterBind;
result &= (b32)features_12.descriptorBindingSampledImageUpdateAfterBind;
result &= (b32)features_12.descriptorBindingStorageImageUpdateAfterBind;
result &= (b32)features_12.descriptorBindingStorageBufferUpdateAfterBind;
result &= (b32)features_12.descriptorBindingPartiallyBound;
result &= (b32)features_12.runtimeDescriptorArray;
result &= (b32)features_12.shaderSampledImageArrayNonUniformIndexing;
result &= (b32)features_13.synchronization2;
result &= (b32)features_13.dynamicRendering;

View File

@ -289,7 +289,7 @@ static void rBufferCreateAndUpload(ModelAsset asset_id)
*/
}
static rDescHandle rTextureCreateAndUpload(TextureAsset asset_id)
static rDescHandle rTextureLoad(TextureAsset asset_id)
{
rDescHandle handle = vDescHandleSearch(vDT_SAMPLED_IMAGE, asset_id);
@ -301,7 +301,7 @@ static rDescHandle rTextureCreateAndUpload(TextureAsset asset_id)
TextureAssetMeta meta = apGetTextureMeta(asset_id);
// TODO: handle errors instead of failing
Assert(vImageViewCreate(view, meta.w, meta.h, meta.ch), "rTextureCreateAndUpload failure: vImageViewCreate failed");
Assert(vImageViewCreate(view, meta.w, meta.h, meta.ch), "rTextureLoad failure: vImageViewCreate failed");
handle.asset_id = asset_id;
handle.desc_index = vDescPushImage(view);
@ -334,6 +334,16 @@ static rDescHandle rTextureCreateAndUpload(TextureAsset asset_id)
return handle;
}
static void rTextureUnload(rDescHandle current_handle)
{
rDescHandle handle = vDescHandleSearch(vDT_SAMPLED_IMAGE, current_handle.asset_id);
if (handle.asset_id != UINT32_MAX)
{
}
}
static void rBufferFree(rRenderBuffer *buffers, u32 buffer_count)
{
VkDevice device = v_Renderer.handles.device;
@ -367,13 +377,6 @@ static void rBufferBindIndex(rRenderBuffer *buffer)
vkCmdBindIndexBuffer(cmd, buffer->buffer, 0, VK_INDEX_TYPE_UINT32);
}
static rAssetHandle rTextureLoad(TextureAsset asset_id)
{
rAssetHandle handle = 0;
return handle;
}
static void vBufferQueueWait()
{
while (!JobQueueCompleted(&v_Renderer.upload.job_queue))

View File

@ -14,5 +14,5 @@ layout (location = 0) out vec4 out_frag_col;
void main()
{
out_frag_col = texture(sampler2D(Textures[in_image], SamplerNearest), in_uv);
out_frag_col = texture(sampler2D(Textures[nonuniformEXT(in_image)], SamplerNearest), in_uv);
}

View File

@ -15,6 +15,13 @@ layout (location = 0) out vec4 out_color;
layout (location = 1) out vec2 out_uv;
layout (location = 2) out uint out_image;
vec2 uvs[] = {
vec2(0.0, 1.0),
vec2(0.0, 0.0),
vec2(1.0, 1.0),
vec2(1.0, 0.0)
};
void main()
{
// Draw with 6 indices, gl_VertexIndex will use the appropriate index, iterates through 0-3 and not 0-5
@ -23,7 +30,7 @@ void main()
gl_VertexIndex == 2 ? vec2(in_gui_pos_1.x, in_gui_pos_1.y) :
gl_VertexIndex == 3 ? vec2(in_gui_pos_1.x, in_gui_pos_0.y) : vec2(0.0, 0.0);
out_uv = vec2(2 * dst_pos.x / PC.res.x - 1, 2 * dst_pos.y / PC.res.y - 1);
out_uv = uvs[gl_VertexIndex];
out_color = in_col;
out_image = in_image;

View File

@ -81,6 +81,8 @@ static VkPhysicalDeviceVulkan12Features vk_12_features = {
.descriptorBindingStorageImageUpdateAfterBind = VK_TRUE,
.descriptorBindingStorageBufferUpdateAfterBind = VK_TRUE,
.descriptorBindingPartiallyBound = VK_TRUE,
.shaderSampledImageArrayNonUniformIndexing = VK_TRUE,
.runtimeDescriptorArray = VK_TRUE,
};
static VkPhysicalDeviceVulkan11Features vk_11_features = {