tinyobj loader compiling
This commit is contained in:
parent
b9d9e60e9f
commit
0cc9eb0b38
@ -1,5 +1,8 @@
|
|||||||
// raddbg 0.9.17 project file
|
// raddbg 0.9.17 project file
|
||||||
|
|
||||||
|
recent_file: path: "src/render/render_core.c"
|
||||||
|
recent_file: path: "d:/os/obj/amd64fre/minkernel/crts/ucrt/src/appcrt/heap/mt/objfre/amd64/minkernel/crts/ucrt/src/appcrt/heap/free_base.cpp"
|
||||||
|
recent_file: path: "src/third_party/tinyobj/tinyobj_loader_c.h"
|
||||||
recent_file: path: "src/render/d3d12/render_d3d12.c"
|
recent_file: path: "src/render/d3d12/render_d3d12.c"
|
||||||
recent_file: path: "d:/os/obj/amd64fre/minkernel/crts/ucrt/src/appcrt/string/mt/objfre/amd64/minkernel/crts/ucrt/src/appcrt/string/amd64/strlen.asm"
|
recent_file: path: "d:/os/obj/amd64fre/minkernel/crts/ucrt/src/appcrt/string/mt/objfre/amd64/minkernel/crts/ucrt/src/appcrt/string/amd64/strlen.asm"
|
||||||
recent_file: path: "src/main.c"
|
recent_file: path: "src/main.c"
|
||||||
@ -10,3 +13,8 @@ target:
|
|||||||
working_directory: build
|
working_directory: build
|
||||||
enabled: 1
|
enabled: 1
|
||||||
}
|
}
|
||||||
|
breakpoint:
|
||||||
|
{
|
||||||
|
source_location: "src/render/render_core.c:102:1"
|
||||||
|
hit_count: 1
|
||||||
|
}
|
||||||
|
|||||||
@ -25,6 +25,8 @@ static void entry_point();
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//~
|
//~
|
||||||
|
|
||||||
|
global const char *obj_filename = "D:\\dev\\anton_render\\data\\cube1.obj";
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//~ Main entry
|
//~ Main entry
|
||||||
internal void
|
internal void
|
||||||
@ -37,6 +39,9 @@ entry_point()
|
|||||||
os_console_init();
|
os_console_init();
|
||||||
os_event_init();
|
os_event_init();
|
||||||
r_init();
|
r_init();
|
||||||
|
|
||||||
|
r_load_obj(obj_filename);
|
||||||
|
|
||||||
//test_arena(arena);
|
//test_arena(arena);
|
||||||
|
|
||||||
//r_trigger_debug_message();
|
//r_trigger_debug_message();
|
||||||
|
|||||||
@ -1,2 +1,106 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//~
|
//~
|
||||||
|
|
||||||
|
|
||||||
|
internal void
|
||||||
|
r_tinyobj_get_file_data(void *ctx, const char *filename, const int is_mtl,
|
||||||
|
const char *obj_filename, char **data, size_t *len)
|
||||||
|
{
|
||||||
|
// This function is just used as a callback to the tinyobj library to get the obj data.
|
||||||
|
// Open the obj file in binary mode and just store the text contents to the data buffer.
|
||||||
|
|
||||||
|
|
||||||
|
FILE *file = fopen(filename, "rb");
|
||||||
|
if(!file)
|
||||||
|
{
|
||||||
|
LOG("Failed to open file %s \n", filename);
|
||||||
|
Trap();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
U32 success = 1;
|
||||||
|
|
||||||
|
fseek(file, 0, SEEK_END);
|
||||||
|
U64 file_size = ftell(file);
|
||||||
|
if(file_size < 0)
|
||||||
|
{
|
||||||
|
fclose(file);
|
||||||
|
LOG("Failed to get file size for %s \n", filename);
|
||||||
|
success = 0;
|
||||||
|
Trap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(file, 0, SEEK_SET);
|
||||||
|
*len = (size_t)file_size + 1;
|
||||||
|
*data = (char *)malloc(*len);
|
||||||
|
if(!*data)
|
||||||
|
{
|
||||||
|
fclose(file);
|
||||||
|
LOG("Failed to allocate buffer for obj file %s \n", filename);
|
||||||
|
success = 0;
|
||||||
|
Trap();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t bytes_read = fread(*data, 1, file_size, file);
|
||||||
|
if(bytes_read != (size_t)file_size)
|
||||||
|
{
|
||||||
|
free(*data);
|
||||||
|
fclose(file);
|
||||||
|
LOG("Failed to read file %s \n", filename);
|
||||||
|
success = 0;
|
||||||
|
Trap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(success)
|
||||||
|
{
|
||||||
|
// Null terminate buffer
|
||||||
|
(*data)[file_size] = '\0';
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
R_TinyOBJ_Helper *helper = (R_TinyOBJ_Helper *)ctx;
|
||||||
|
helper->data = *data;
|
||||||
|
helper->len = *len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal void
|
||||||
|
r_load_obj(const char *filename)
|
||||||
|
{
|
||||||
|
// tinyobj stuff, TODO(anton): Write my own obj loader and remove this.
|
||||||
|
tinyobj_attrib_t attrib;
|
||||||
|
tinyobj_shape_t *shapes = 0;
|
||||||
|
U64 shape_count;
|
||||||
|
tinyobj_material_t *materials = 0;
|
||||||
|
U64 material_count;
|
||||||
|
|
||||||
|
|
||||||
|
// Init tinyobj
|
||||||
|
//tinyobj_attrib_init(&attrib);
|
||||||
|
R_TinyOBJ_Helper tinyobj_helper = {0};
|
||||||
|
U32 ret = tinyobj_parse_obj(&attrib, &shapes, &shape_count, &materials, &material_count,
|
||||||
|
filename, r_tinyobj_get_file_data, (void *)&tinyobj_helper, TINYOBJ_FLAG_TRIANGULATE);
|
||||||
|
if(ret != TINYOBJ_SUCCESS)
|
||||||
|
{
|
||||||
|
LOG("Failed to load .obj file %s with tinyobj loader! \n", filename);
|
||||||
|
Trap();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG("Loaded .obj from %s \n", filename);
|
||||||
|
LOG("Shape count: %u \n", shape_count);
|
||||||
|
LOG("Material count: %u \n", material_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
tinyobj_attrib_free(&attrib);
|
||||||
|
tinyobj_shapes_free(shapes, shape_count);
|
||||||
|
tinyobj_materials_free(materials, material_count);
|
||||||
|
|
||||||
|
if(tinyobj_helper.data)
|
||||||
|
{
|
||||||
|
free(tinyobj_helper.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -7,6 +7,20 @@
|
|||||||
|
|
||||||
#define BATCH_LIST_SIZE 256
|
#define BATCH_LIST_SIZE 256
|
||||||
|
|
||||||
|
typedef struct R_TinyOBJ_Helper R_TinyOBJ_Helper;
|
||||||
|
struct R_TinyOBJ_Helper
|
||||||
|
{
|
||||||
|
char *data;
|
||||||
|
size_t len;
|
||||||
|
};
|
||||||
|
|
||||||
|
//typedef struct R_Geom R_Geom;
|
||||||
|
//struct R_Geom
|
||||||
|
//{
|
||||||
|
// U8
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
typedef struct R_Batch R_Batch;
|
typedef struct R_Batch R_Batch;
|
||||||
struct R_Batch
|
struct R_Batch
|
||||||
{
|
{
|
||||||
@ -30,6 +44,8 @@ struct R_BatchList
|
|||||||
|
|
||||||
internal void r_init();
|
internal void r_init();
|
||||||
internal void r_render();
|
internal void r_render();
|
||||||
|
internal void r_load_obj(const char *filename);
|
||||||
|
|
||||||
|
|
||||||
internal void r_log_debug_messages();
|
internal void r_log_debug_messages();
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//~
|
//~
|
||||||
|
|
||||||
|
#define TINYOBJ_LOADER_C_IMPLEMENTATION
|
||||||
|
#include "third_party/tinyobj/tinyobj_loader_c.h"
|
||||||
#include "render/render_core.c"
|
#include "render/render_core.c"
|
||||||
#include "render/d3d12/render_d3d12.c"
|
#include "render/d3d12/render_d3d12.c"
|
||||||
1762
src/third_party/tinyobj/tinyobj_loader_c.h
vendored
Normal file
1762
src/third_party/tinyobj/tinyobj_loader_c.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user