polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

vbo.h (1815B)


      1 #ifndef POLYADVENT_BUFFER_H
      2 #define POLYADVENT_BUFFER_H
      3 
      4 #include "gl.h"
      5 #include "common.h"
      6 
      7 typedef GLuint gpu_addr;
      8 
      9 #define VERT_ATTRS 6
     10 
     11 enum vertex_attr {
     12     va_position,
     13     va_normal,
     14     va_color,
     15     va_index,
     16     va_tex_coord,
     17     va_joint_ids,
     18     va_joint_weights,
     19     n_vertex_attrs
     20 };
     21 
     22 struct vbo {
     23     u32 type;
     24     int component_type;
     25     int components;
     26     gpu_addr handle;
     27 };
     28 
     29 struct num_elements {
     30     int num_elements;
     31 };
     32 #define mk_num_elements(x) ((struct num_elements){ .num_elements = x })
     33 
     34 struct element_size {
     35     int element_size;
     36 };
     37 #define mk_element_size(x) ((struct element_size){ .element_size = x })
     38 
     39 struct components {
     40     int components;
     41 };
     42 #define mk_components(c) ((struct components){ .components = c })
     43 
     44 #define NUM_VBO_SLOTS 1
     45 
     46 gpu_addr make_buffer(GLenum target, const void *buffer_data, GLsizei buffer_size);
     47 
     48 struct vbo *init_vbo(struct vbo *);
     49 
     50 struct vbo* make_float_vertex_buffer(struct vbo *vbo,
     51                                      const void *data,
     52                                      struct num_elements,
     53                                      struct components);
     54 
     55 struct vbo* make_index_buffer(struct vbo *vbo,
     56                               const void *data,
     57                               struct num_elements);
     58 
     59 struct vbo * make_uv_buffer(struct vbo *vbo,
     60                             const void *data,
     61                             struct num_elements,
     62                             struct components);
     63 
     64 struct vbo *
     65 make_int_vertex_buffer(struct vbo *vbo, const u32 *data,
     66                        struct num_elements num_elements,
     67                        struct components components);
     68 
     69 
     70 void bind_uv_vbo(struct vbo *vbo, gpu_addr slot);
     71 void bind_vbo(struct vbo *vbo, gpu_addr slot, GLenum type);
     72 void free_vbo(struct vbo *vbo);
     73 
     74 #endif /* POLYADVENT_BUFFER_H */