summaryrefslogtreecommitdiff
path: root/src/objload.h
blob: d850f3c24d53f83c0026a13454ac147f169f0a80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef OBJLOAD_H
#define OBJLOAD_H

#include <stdint.h>

typedef enum OBJ_RESULT {
    OBJ_SUCCESS = 0,
    OBJ_LINE_UNKNOWN,
    OBJ_NOT_SUPPORTED_LINE,
    OBJ_NOT_SUPPORTED_UNKNOWN,
    OBJ_ERROR_UNKNOWN,
} OBJRES;

typedef struct objload {
    size_t nvert;
    float (*vertices)[3];
    
    size_t nnorm;
    float (*normals)[3];
    
    size_t nuv;
    float (*uvcoord)[2];

    size_t nfaces;
    struct face {
        size_t vertidx;
        size_t normidx;
        size_t uvidx;
    } (*faces)[3];
} objload_t;

struct obj_struct_metadata {
    size_t full_sz;
    
    size_t vert_off;
    size_t norm_off;
    size_t uvtx_off;
    
    enum {
        OBJ_STRUCT_VERT_EXISTS = 1 << 0,
        OBJ_STRUCT_NORM_EXISTS = 1 << 1,
        OBJ_STRUCT_UVTX_EXISTS = 1 << 2,
        OBJ_STRUCT_ALL_EXIST   = 7,
    } exist_flag;
};

typedef uint32_t obj_idx;

OBJRES obj_load(FILE *fp, objload_t *obj);
void obj_free(objload_t obj);

OBJRES obj_transfer_raw(objload_t obj,
                        struct obj_struct_metadata metadata,
                        size_t *nvbo, void *vbo);

// OBJRES obj_transfer_indexed(objload_t obj,
                           // size_t *nvbo, obj_vbo vbo,
                           // size_t *nidx, obj_idx ibo);
#endif