polyadvent

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

shader.h (2112B)


      1 #ifndef POLYADVENT_SHADER_H
      2 #define POLYADVENT_SHADER_H
      3 
      4 #include <time.h>
      5 #include "gl.h"
      6 #include "vbo.h"
      7 #include "lens.h"
      8 
      9 #define SHADER(f) "etc/shaders/" f
     10 
     11 #define MAX_SHADER_INCLUDES 16
     12 #define MAX_INCLUDE_FNAME_LEN 64
     13 #define MAX_SHADERS 5
     14 #define MAX_UNIFORMS 64
     15 #define MAX_SHADER_STRUCTS 4
     16 
     17 /* structure binding */
     18 struct structure_binding {
     19 	struct lens *lenses;
     20 	int num_lenses;
     21 };
     22 
     23 struct shader {
     24 	GLenum type;
     25 	GLuint handle;
     26 	int n_includes;
     27 	const char *filename;
     28 	char includes[MAX_SHADER_INCLUDES][MAX_INCLUDE_FNAME_LEN];
     29 	time_t include_mtimes[MAX_SHADER_INCLUDES];
     30 	time_t load_mtime;
     31 };
     32 
     33 struct uniform {
     34 	int id;
     35 	int location;
     36 	int binding_id;
     37 	int lens_id;
     38 };
     39 
     40 struct gpu_program {
     41 	struct shader shaders[MAX_SHADERS];
     42 	struct uniform uniforms[MAX_UNIFORMS];
     43 	struct structure_binding *bindings;
     44 	int num_bindings;
     45 	gpu_addr vertex_attrs[MAX_VERTEX_ATTRS];
     46 	int n_shaders;
     47 	int num_uniforms;
     48 	int active_attributes;
     49 	int id; // index in gpu programs array
     50 	GLuint handle;
     51 	const char *name;
     52 };
     53 
     54 void add_uniform(struct gpu_program *program, int id, int binding_id, int lens_id);
     55 
     56 void create_shader_bindings(struct gpu_program *program, struct structure_binding *bindings, int num_bindings);
     57 
     58 #define NO_GEOM_SHADER NULL
     59 
     60 int reload_program(struct gpu_program *program, struct gpu_program *programs);
     61 int make_shader(GLenum type, const char *filename, struct shader *shader);
     62 
     63 void bind_uniforms(struct gpu_program *program, void **structures, int num_structs);
     64 
     65 void init_gpu_program(struct gpu_program *program);
     66 int make_program_from_shaders(const char *name,
     67                               struct shader **shaders,
     68                               int n_shaders,
     69                               struct gpu_program *program,
     70 			      struct structure_binding *bindings,
     71 			      int n_bindings
     72 			      );
     73 
     74 struct shader *get_program_shader(struct gpu_program *program, GLenum type);
     75 
     76 int make_program(const char *name, struct shader *vertex, struct shader *fragment,
     77 		struct gpu_program *program, struct structure_binding *bindings,
     78 		int n_bindings);
     79 
     80 #endif /* POLYADVENT_SHADER_H */