fixed issue with texture loading in asset packer, fixed shader bug, textures now work
This commit is contained in:
parent
5ff767e916
commit
2ae1196e25
BIN
assets/cheesoid.png
Executable file
BIN
assets/cheesoid.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
BIN
assets/ham_smoke.png
Normal file
BIN
assets/ham_smoke.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 728 KiB |
BIN
assets/hamster.png
Normal file
BIN
assets/hamster.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 961 KiB |
@ -32,6 +32,9 @@ typedef enum TextureAsset_e : u32
|
|||||||
PATTERMON_OBESE,
|
PATTERMON_OBESE,
|
||||||
PATTERMON_PURPLOID,
|
PATTERMON_PURPLOID,
|
||||||
PATTERMON_ORIENTAL,
|
PATTERMON_ORIENTAL,
|
||||||
|
HAMSTER,
|
||||||
|
HAMSMOKER,
|
||||||
|
CHEESOID,
|
||||||
|
|
||||||
TEXTURE_ASSET_MAX
|
TEXTURE_ASSET_MAX
|
||||||
} TextureAsset;
|
} TextureAsset;
|
||||||
|
|||||||
@ -78,9 +78,13 @@ static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count)
|
|||||||
|
|
||||||
rViewportSize(&ctx->pc.res);
|
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, "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 vert_buffer = rBufferGUIVertMapping();
|
||||||
rawptr idx_buffer = rBufferGUIIdxMapping();
|
rawptr idx_buffer = rBufferGUIIdxMapping();
|
||||||
|
|||||||
17
src/packer.c
17
src/packer.c
@ -30,6 +30,9 @@ const FileMapping g_Texture_File_Map[] = {
|
|||||||
{ .file_name = "pattermon.png", .ix = PATTERMON_OBESE },
|
{ .file_name = "pattermon.png", .ix = PATTERMON_OBESE },
|
||||||
{ .file_name = "patamon.png", .ix = PATTERMON_ORIENTAL },
|
{ .file_name = "patamon.png", .ix = PATTERMON_ORIENTAL },
|
||||||
{ .file_name = "purplemon.png", .ix = PATTERMON_PURPLOID },
|
{ .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};
|
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];
|
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");
|
FILE *asset_file = OpenFile(asset_name, "r");
|
||||||
u64 file_size = FileLength(asset_file);
|
u64 file_size = FileLength(asset_file);
|
||||||
@ -238,7 +241,7 @@ void PackFiles(Arena *arena, FileHeader *header)
|
|||||||
{
|
{
|
||||||
c8 *asset_name = g_Texture_File_Names[i];
|
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");
|
FILE *asset_file = OpenFile(asset_name, "r");
|
||||||
u64 file_size = FileLength(asset_file);
|
u64 file_size = FileLength(asset_file);
|
||||||
@ -246,8 +249,9 @@ void PackFiles(Arena *arena, FileHeader *header)
|
|||||||
u8 *file_data = MakeArray(arena, u8, file_size);
|
u8 *file_data = MakeArray(arena, u8, file_size);
|
||||||
ReadData(file_data, 0, file_size, asset_file);
|
ReadData(file_data, 0, file_size, asset_file);
|
||||||
|
|
||||||
int w, h, ch;
|
int ch = 4;
|
||||||
u8 *image_bytes = stbi_load_from_memory(file_data, file_size, &w, &h, &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);
|
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;
|
u64 image_length;
|
||||||
if (type == TEXTURE_ASSET)
|
if (type == TEXTURE_ASSET)
|
||||||
{
|
{
|
||||||
int w, h, ch;
|
int ch = 4;
|
||||||
image_bytes = stbi_load_from_memory(file_data, size, &w, &h, &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);
|
image_length = u64(w * h * ch);
|
||||||
|
|
||||||
Assert(file_info->len == image_length, "file length incorrect");
|
Assert(file_info->len == image_length, "file length incorrect");
|
||||||
|
|||||||
@ -92,8 +92,6 @@ typedef struct rMappedBuffer
|
|||||||
u32 elem_count;
|
u32 elem_count;
|
||||||
} rMappedBuffer;
|
} rMappedBuffer;
|
||||||
|
|
||||||
typedef u32 rAssetHandle;
|
|
||||||
|
|
||||||
typedef rawptr rBuffer;
|
typedef rawptr rBuffer;
|
||||||
|
|
||||||
// ::Renderer::Initialization::Header::
|
// ::Renderer::Initialization::Header::
|
||||||
@ -108,10 +106,10 @@ static b32 rBufferMap();
|
|||||||
static void rBufferFree(rRenderBuffer *buffers, u32 buffer_count);
|
static void rBufferFree(rRenderBuffer *buffers, u32 buffer_count);
|
||||||
static b32 rBufferUpload(rRenderBuffer **buffer, rawptr *ptr, u32 count, u32 thr_ix);
|
static b32 rBufferUpload(rRenderBuffer **buffer, rawptr *ptr, u32 count, u32 thr_ix);
|
||||||
static void rBufferCreateAndUpload(ModelAsset asset_id);
|
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 rBufferBindVertex(rRenderBuffer *buffer);
|
||||||
static void rBufferBindIndex(rRenderBuffer *buffer);
|
static void rBufferBindIndex(rRenderBuffer *buffer);
|
||||||
static rAssetHandle rTextureLoad(TextureAsset asset_id);
|
|
||||||
static void rBufferQueueReset();
|
static void rBufferQueueReset();
|
||||||
static rawptr rBufferGUIVertMapping();
|
static rawptr rBufferGUIVertMapping();
|
||||||
static rawptr rBufferGUIIdxMapping();
|
static rawptr rBufferGUIIdxMapping();
|
||||||
|
|||||||
@ -927,6 +927,13 @@ static b32 vDeviceCheckFeatureSupport(VkPhysicalDevice device)
|
|||||||
|
|
||||||
result &= (b32)features_12.descriptorIndexing;
|
result &= (b32)features_12.descriptorIndexing;
|
||||||
result &= (b32)features_12.bufferDeviceAddress;
|
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.synchronization2;
|
||||||
result &= (b32)features_13.dynamicRendering;
|
result &= (b32)features_13.dynamicRendering;
|
||||||
|
|||||||
@ -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);
|
rDescHandle handle = vDescHandleSearch(vDT_SAMPLED_IMAGE, asset_id);
|
||||||
|
|
||||||
@ -301,7 +301,7 @@ static rDescHandle rTextureCreateAndUpload(TextureAsset asset_id)
|
|||||||
TextureAssetMeta meta = apGetTextureMeta(asset_id);
|
TextureAssetMeta meta = apGetTextureMeta(asset_id);
|
||||||
|
|
||||||
// TODO: handle errors instead of failing
|
// 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.asset_id = asset_id;
|
||||||
handle.desc_index = vDescPushImage(view);
|
handle.desc_index = vDescPushImage(view);
|
||||||
@ -334,6 +334,16 @@ static rDescHandle rTextureCreateAndUpload(TextureAsset asset_id)
|
|||||||
return handle;
|
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)
|
static void rBufferFree(rRenderBuffer *buffers, u32 buffer_count)
|
||||||
{
|
{
|
||||||
VkDevice device = v_Renderer.handles.device;
|
VkDevice device = v_Renderer.handles.device;
|
||||||
@ -367,13 +377,6 @@ static void rBufferBindIndex(rRenderBuffer *buffer)
|
|||||||
vkCmdBindIndexBuffer(cmd, buffer->buffer, 0, VK_INDEX_TYPE_UINT32);
|
vkCmdBindIndexBuffer(cmd, buffer->buffer, 0, VK_INDEX_TYPE_UINT32);
|
||||||
}
|
}
|
||||||
|
|
||||||
static rAssetHandle rTextureLoad(TextureAsset asset_id)
|
|
||||||
{
|
|
||||||
rAssetHandle handle = 0;
|
|
||||||
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void vBufferQueueWait()
|
static void vBufferQueueWait()
|
||||||
{
|
{
|
||||||
while (!JobQueueCompleted(&v_Renderer.upload.job_queue))
|
while (!JobQueueCompleted(&v_Renderer.upload.job_queue))
|
||||||
|
|||||||
@ -14,5 +14,5 @@ layout (location = 0) out vec4 out_frag_col;
|
|||||||
|
|
||||||
void main()
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,13 @@ layout (location = 0) out vec4 out_color;
|
|||||||
layout (location = 1) out vec2 out_uv;
|
layout (location = 1) out vec2 out_uv;
|
||||||
layout (location = 2) out uint out_image;
|
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()
|
void main()
|
||||||
{
|
{
|
||||||
// Draw with 6 indices, gl_VertexIndex will use the appropriate index, iterates through 0-3 and not 0-5
|
// 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 == 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);
|
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_color = in_col;
|
||||||
out_image = in_image;
|
out_image = in_image;
|
||||||
|
|
||||||
|
|||||||
@ -81,6 +81,8 @@ static VkPhysicalDeviceVulkan12Features vk_12_features = {
|
|||||||
.descriptorBindingStorageImageUpdateAfterBind = VK_TRUE,
|
.descriptorBindingStorageImageUpdateAfterBind = VK_TRUE,
|
||||||
.descriptorBindingStorageBufferUpdateAfterBind = VK_TRUE,
|
.descriptorBindingStorageBufferUpdateAfterBind = VK_TRUE,
|
||||||
.descriptorBindingPartiallyBound = VK_TRUE,
|
.descriptorBindingPartiallyBound = VK_TRUE,
|
||||||
|
.shaderSampledImageArrayNonUniformIndexing = VK_TRUE,
|
||||||
|
.runtimeDescriptorArray = VK_TRUE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static VkPhysicalDeviceVulkan11Features vk_11_features = {
|
static VkPhysicalDeviceVulkan11Features vk_11_features = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user