dungeon_crawler
view 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 |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <limits.h>
5 #include "opengl.h"
6 #include "renderer.h"
7 #include "sdr.h"
8 #include "datapath.h"
10 #define MRT_COUNT (sizeof mrt_sdr_file / sizeof *mrt_sdr_file)
12 static const char *mrt_sdr_file[][2] = {
13 {0, "mrt0.p.glsl"}/*,
14 {0, "mrt1.p.glsl"},
15 {0, "mrt2.p.glsl"},
16 {0, "mrt3.p.glsl"}*/
17 };
19 static unsigned int mrt_prog[MRT_COUNT];
20 static unsigned int deferred_prog;
22 bool init_renderer()
23 {
24 char vsfile[PATH_MAX], psfile[PATH_MAX];
25 const char *fname;
27 for(int i=0; i<MRT_COUNT; i++) {
28 if((fname = datafile_path(mrt_sdr_file[i][0]))) {
29 strcpy(vsfile, mrt_sdr_file[i][0]);
30 } else {
31 vsfile[0] = 0;
32 }
34 if((fname = datafile_path(mrt_sdr_file[i][1]))) {
35 strcpy(psfile, mrt_sdr_file[i][1]);
36 } else {
37 psfile[0] = 0;
38 }
40 if(!(mrt_prog[i] = create_program_load(vsfile, psfile))) {
41 fprintf(stderr, "failed to load MRT program\n");
42 return false;
43 }
44 }
46 if((fname = datafile_path("deferred.v.glsl"))) {
47 strcpy(vsfile, fname);
48 } else {
49 vsfile[0] = 0;
50 }
51 if((fname = datafile_path("deferred.p.glsl"))) {
52 strcpy(psfile, fname);
53 } else {
54 psfile[0] = 0;
55 }
57 if(!(deferred_prog = create_program_load(vsfile, psfile))) {
58 fprintf(stderr, "failed to load deferred shader program\n");
59 return false;
60 }
61 return true;
62 }
64 void destroy_renderer()
65 {
66 for(int i=0; i<MRT_COUNT; i++) {
67 free_program(mrt_prog[i]);
68 }
69 free_program(deferred_prog);
70 }
72 void render_deferred(void (*draw_func)())
73 {
76 draw_func();
77 }