polyadvent

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

geometry.h (1814B)


      1 
      2 #ifndef GEOMETRY_H
      3 #define GEOMETRY_H
      4 
      5 #include "common.h"
      6 #include "vbo.h"
      7 #include "shader.h"
      8 #include "resource.h"
      9 
     10 #define DEF_NUM_GEOMETRY 64
     11 #define MAX_GEOMETRY 1024
     12 
     13 // -1 is uninitialized
     14 typedef struct resource_id geometry_id;
     15 
     16 struct geometry {
     17     struct vbo vbos[n_vertex_attrs];
     18     float min[3];
     19     float max[3];
     20 
     21     int has_vbos;
     22     int num_uv_components;
     23     int num_indices;
     24     int num_verts;
     25 };
     26 
     27 struct make_geometry {
     28     float *vertices;
     29     float *normals;
     30     float *colors;
     31     int num_verts;
     32 
     33     u32 *indices;
     34     int num_indices;
     35 
     36     float *tex_coords;
     37     int num_uv_components;
     38 
     39     u32 *joint_ids;
     40     int num_joint_ids;
     41 
     42     float *joint_weights;
     43 };
     44 
     45 struct geometry_manager {
     46     struct geometry geoms[MAX_GEOMETRY];
     47     int num_geometry;
     48 };
     49 
     50 void render_geometry(struct geometry *geom, gpu_addr *vertex_attrs,
     51                      struct gpu_program *current_program);
     52 void bind_geometry(struct geometry *geom, gpu_addr *vertex_attrs);
     53 void init_geometry(struct geometry *geom);
     54 void init_make_geometry(struct make_geometry *mkgeom);
     55 void free_make_geometry(struct make_geometry *mkgeom);
     56 void make_buffer_geometry(struct make_geometry *mkgeom, struct geometry *geom);
     57 void destroy_buffer_geometry(geometry_id *geom);
     58 void geometry_centroid(struct geometry *geom, float *v3);
     59 void init_geometry_manager();
     60 void init_geometry_id(geometry_id *);
     61 struct geometry *new_geometry(geometry_id *);
     62 struct geometry *get_geometry(geometry_id *);
     63 struct geometry *get_all_geometry(u32 *count, geometry_id **ids);
     64 void destroy_geometry(geometry_id *geom_id);
     65 struct resource_manager *get_geometry_manager();
     66 
     67 extern struct resource_manager geom_manager;
     68 
     69 static inline struct geometry *static_geometry()
     70 {
     71     return (struct geometry *)geom_manager.resources;
     72 }
     73 
     74 #endif /* GEOMETRY_H */