polyadvent

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

vbo.h (2094B)


      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 enum vertex_attr {
     10     va_position,
     11     va_normal,
     12     va_color,
     13     va_index,
     14     va_tex_coord,
     15     va_joint_ids,
     16     va_joint_weights,
     17     MAX_VERTEX_ATTRS
     18 };
     19 
     20 static inline const char *vertex_attr_str(enum vertex_attr addr)
     21 {
     22 	switch(addr) {
     23 		case va_position: return "position";
     24 		case va_normal: return "normal";
     25 		case va_color: return "color";
     26 		case va_index: return "index";
     27 		case va_tex_coord: return "tex_coord";
     28 		default: return "unknown";
     29 	}
     30 }
     31 
     32 struct vbo {
     33     u32 type;
     34     int component_type;
     35     int components;
     36     gpu_addr handle;
     37 };
     38 
     39 struct num_elements {
     40     int num_elements;
     41 };
     42 #define mk_num_elements(x) ((struct num_elements){ .num_elements = x })
     43 
     44 struct element_size {
     45     int element_size;
     46 };
     47 #define mk_element_size(x) ((struct element_size){ .element_size = x })
     48 
     49 struct components {
     50     int components;
     51 };
     52 #define mk_components(c) ((struct components){ .components = c })
     53 
     54 #define NUM_VBO_SLOTS 1
     55 
     56 gpu_addr make_buffer(GLenum target, const void *buffer_data, GLsizei buffer_size);
     57 
     58 struct vbo *init_vbo(struct vbo *);
     59 
     60 struct vbo* make_float_vertex_buffer(struct vbo *vbo,
     61                                      const void *data,
     62                                      struct num_elements,
     63                                      struct components);
     64 
     65 struct vbo* make_index_buffer(struct vbo *vbo,
     66                               const void *data,
     67                               struct num_elements);
     68 
     69 struct vbo * make_uv_buffer(struct vbo *vbo,
     70                             const void *data,
     71                             struct num_elements,
     72                             struct components);
     73 
     74 struct vbo *
     75 make_int_vertex_buffer(struct vbo *vbo, const u32 *data,
     76                        struct num_elements num_elements,
     77                        struct components components);
     78 
     79 
     80 void bind_uv_vbo(struct vbo *vbo, gpu_addr slot);
     81 void bind_vbo(struct vbo *vbo, gpu_addr slot, GLenum type);
     82 void free_vbo(struct vbo *vbo);
     83 
     84 #endif /* POLYADVENT_BUFFER_H */