From 8690e93b41ffe7bba528b76dfa749ee4bb6f28d5 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 17 Apr 2026 16:44:11 +1000 Subject: [PATCH] update dlib to include vulkan --- assets.d | 67 ++++++++++++++++++++++++++++++++++++++------------ dlibincludes.c | 6 ++++- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/assets.d b/assets.d index c772bdb..12c3d43 100644 --- a/assets.d +++ b/assets.d @@ -1,6 +1,38 @@ module dlib.assets; -import dlibincludes; +import dlibincludes : cgltf_result, + cgltf_memory_options, + cgltf_file_options, + cgltf_size, + cgltf_image, + cgltf_accessor, + cgltf_result_success, + cgltf_result_io_error, + cgltf_free, + cgltf_options, + cgltf_node, + cgltf_load_buffers, + cgltf_data, + cgltf_load_buffer_base64, + stbi_image_free, + stbi_load_from_memory, + cgltf_primitive_type_triangles, + cgltf_node_transform_world, + cgltf_float, + cgltf_mesh, + cgltf_parse, + cgltf_attribute_type_position, + cgltf_type_vec3, + cgltf_component_type_r_32f, + cgltf_attribute_type_normal, + cgltf_attribute_type_tangent, + cgltf_type_vec4, + cgltf_attribute_type_texcoord, + cgltf_type_vec2, + cgltf_component_type_r_8u, + cgltf_component_type_r_16u, + cgltf_attribute_type_color, + cgltf_component_type_r_32u; import dlib.aliases; import dlib.util; import dlib.alloc; @@ -10,7 +42,8 @@ import std.file; import std.path; import std.format; import std.stdio; -import std.exception; +import core.stdc.string : strlen; +import core.stdc.stdio : File = FILE, FOpen = fopen, FSeek = fseek, FTell = ftell, FClose = fclose, FRead = fread, SeekSet = SEEK_SET, SeekEnd = SEEK_END; __gshared ImageData DEFAULT_IMAGE = GenerateDefaultTexture(32, 32); __gshared Material DEFAULT_MATERIAL = GenerateDefaultMaterial(); @@ -148,29 +181,30 @@ U32ColToVec4(u32 col, Vec4* vec) // TODO: make better u8[] -OpenFile(string file_name) +OpenFile(string file_name) nothrow @nogc { - File f; + File* f; u8[] data; - try + f = FOpen(file_name.ptr, "rb"); + if(f) { - f = File(file_name, "rb"); - data = Alloc!(u8)(f.size()); - f.rawRead(data); - } - catch(Exception e) - { - data = null; - } + FSeek(f, 0, SeekEnd); + u64 size = FTell(f); + FSeek(f, 0, SeekSet); - f.close(); + data = Alloc!(u8)(size); + + FRead(data.ptr, 1, size, f); + + FClose(f); + } return data; } extern (C) cgltf_result -GLTFLoadCallback(cgltf_memory_options* memory_opts, cgltf_file_options* file_opts, const(char)* path, cgltf_size* size, void** data) +GLTFLoadCallback(cgltf_memory_options* memory_opts, cgltf_file_options* file_opts, const(char)* path, cgltf_size* size, void** data) nothrow @nogc { u8[] file_data = OpenFile(ConvToStr(path[0 .. strlen(path)])); @@ -183,7 +217,7 @@ GLTFLoadCallback(cgltf_memory_options* memory_opts, cgltf_file_options* file_opt } extern (C) void -GLTFFreeCallback(cgltf_memory_options* memory_opts, cgltf_file_options* file_opts, void* data, cgltf_size size) +GLTFFreeCallback(cgltf_memory_options* memory_opts, cgltf_file_options* file_opts, void* data, cgltf_size size) nothrow @nogc { Free(data); } @@ -779,3 +813,4 @@ GenerateDefaultMaterial() return mat; } +import std.exception; diff --git a/dlibincludes.c b/dlibincludes.c index 217ddab..5cbc29c 100644 --- a/dlibincludes.c +++ b/dlibincludes.c @@ -21,7 +21,11 @@ # include "external/stb/stb_image.h" # include "external/stb/stb_image_write.h" # include "external/stb/stb_truetype.h" -#endif +#endif + +#ifdef DLIB_INCLUDE_VULKAN +# include "../VulkanRenderer/vulkan_includes.c" +#endif #define CGLM_FORCE_DEPTH_ZERO_TO_ONE #include "external/cglm/cglm.h"