dungeon_crawler
annotate prototype/src/renderer.cc @ 16:91180ee7b7d9
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 20 Aug 2012 03:40:51 +0300 |
parents | 3a3236a4833c |
children | d98240a13793 |
rev | line source |
---|---|
nuclear@15 | 1 #include <stdio.h> |
nuclear@15 | 2 #include <stdlib.h> |
nuclear@15 | 3 #include <string.h> |
nuclear@15 | 4 #include <limits.h> |
nuclear@15 | 5 #include "opengl.h" |
nuclear@15 | 6 #include "renderer.h" |
nuclear@15 | 7 #include "sdr.h" |
nuclear@15 | 8 #include "datapath.h" |
nuclear@15 | 9 |
nuclear@16 | 10 #define MRT_COUNT (sizeof mrt_sdr_file / sizeof *mrt_sdr_file) |
nuclear@15 | 11 |
nuclear@15 | 12 static const char *mrt_sdr_file[][2] = { |
nuclear@16 | 13 {0, "mrt0.p.glsl"}/*, |
nuclear@15 | 14 {0, "mrt1.p.glsl"}, |
nuclear@15 | 15 {0, "mrt2.p.glsl"}, |
nuclear@16 | 16 {0, "mrt3.p.glsl"}*/ |
nuclear@15 | 17 }; |
nuclear@15 | 18 |
nuclear@15 | 19 static unsigned int mrt_prog[MRT_COUNT]; |
nuclear@15 | 20 static unsigned int deferred_prog; |
nuclear@15 | 21 |
nuclear@15 | 22 bool init_renderer() |
nuclear@15 | 23 { |
nuclear@15 | 24 char vsfile[PATH_MAX], psfile[PATH_MAX]; |
nuclear@15 | 25 const char *fname; |
nuclear@15 | 26 |
nuclear@15 | 27 for(int i=0; i<MRT_COUNT; i++) { |
nuclear@15 | 28 if((fname = datafile_path(mrt_sdr_file[i][0]))) { |
nuclear@15 | 29 strcpy(vsfile, mrt_sdr_file[i][0]); |
nuclear@15 | 30 } else { |
nuclear@15 | 31 vsfile[0] = 0; |
nuclear@15 | 32 } |
nuclear@15 | 33 |
nuclear@15 | 34 if((fname = datafile_path(mrt_sdr_file[i][1]))) { |
nuclear@15 | 35 strcpy(psfile, mrt_sdr_file[i][1]); |
nuclear@15 | 36 } else { |
nuclear@15 | 37 psfile[0] = 0; |
nuclear@15 | 38 } |
nuclear@15 | 39 |
nuclear@15 | 40 if(!(mrt_prog[i] = create_program_load(vsfile, psfile))) { |
nuclear@15 | 41 fprintf(stderr, "failed to load MRT program\n"); |
nuclear@15 | 42 return false; |
nuclear@15 | 43 } |
nuclear@15 | 44 } |
nuclear@15 | 45 |
nuclear@15 | 46 if((fname = datafile_path("deferred.v.glsl"))) { |
nuclear@15 | 47 strcpy(vsfile, fname); |
nuclear@15 | 48 } else { |
nuclear@15 | 49 vsfile[0] = 0; |
nuclear@15 | 50 } |
nuclear@15 | 51 if((fname = datafile_path("deferred.p.glsl"))) { |
nuclear@15 | 52 strcpy(psfile, fname); |
nuclear@15 | 53 } else { |
nuclear@15 | 54 psfile[0] = 0; |
nuclear@15 | 55 } |
nuclear@15 | 56 |
nuclear@15 | 57 if(!(deferred_prog = create_program_load(vsfile, psfile))) { |
nuclear@15 | 58 fprintf(stderr, "failed to load deferred shader program\n"); |
nuclear@15 | 59 return false; |
nuclear@15 | 60 } |
nuclear@15 | 61 return true; |
nuclear@15 | 62 } |
nuclear@15 | 63 |
nuclear@15 | 64 void destroy_renderer() |
nuclear@15 | 65 { |
nuclear@15 | 66 for(int i=0; i<MRT_COUNT; i++) { |
nuclear@15 | 67 free_program(mrt_prog[i]); |
nuclear@15 | 68 } |
nuclear@15 | 69 free_program(deferred_prog); |
nuclear@15 | 70 } |
nuclear@15 | 71 |
nuclear@15 | 72 void render_deferred(void (*draw_func)()) |
nuclear@15 | 73 { |
nuclear@15 | 74 |
nuclear@15 | 75 |
nuclear@15 | 76 draw_func(); |
nuclear@15 | 77 } |