clray
diff src/rt.cc @ 22:6c44e4b1726d
OMG alignment is a bitch
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 11 Aug 2010 04:30:35 +0100 |
parents | bd6c2b25f6e7 |
children | 13091c00d7ca |
line diff
1.1 --- a/src/rt.cc Tue Aug 10 07:24:18 2010 +0100 1.2 +++ b/src/rt.cc Wed Aug 11 04:30:35 2010 +0100 1.3 @@ -4,7 +4,7 @@ 1.4 #include <assert.h> 1.5 #include "ogl.h" 1.6 #include "ocl.h" 1.7 -#include "mesh.h" 1.8 +#include "scene.h" 1.9 1.10 // kernel arguments 1.11 enum { 1.12 @@ -21,10 +21,10 @@ 1.13 }; 1.14 1.15 struct RendInfo { 1.16 + float ambient[4]; 1.17 int xsz, ysz; 1.18 int num_faces, num_lights; 1.19 int max_iter; 1.20 - float ambient[4]; 1.21 }; 1.22 1.23 struct Ray { 1.24 @@ -44,7 +44,7 @@ 1.25 static int global_size; 1.26 1.27 static Light lightlist[] = { 1.28 - {{-8, 15, -18, 0}, {1, 1, 1, 1}} 1.29 + {{-8, 15, 18, 0}, {1, 1, 1, 1}} 1.30 }; 1.31 1.32 1.33 @@ -54,7 +54,7 @@ 1.34 bool init_renderer(int xsz, int ysz, Scene *scn) 1.35 { 1.36 // render info 1.37 - rinf.ambient[0] = rinf.ambient[1] = rinf.ambient[2] = 0.075; 1.38 + rinf.ambient[0] = rinf.ambient[1] = rinf.ambient[2] = 0.0; 1.39 rinf.ambient[3] = 0.0; 1.40 1.41 rinf.xsz = xsz; 1.42 @@ -115,13 +115,9 @@ 1.43 1.44 bool render() 1.45 { 1.46 - printf("Running kernel... "); 1.47 - fflush(stdout); 1.48 if(!prog->run(1, global_size)) { 1.49 return false; 1.50 } 1.51 - printf("done\n"); 1.52 - 1.53 1.54 CLMemBuffer *mbuf = prog->get_arg_buffer(KARG_FRAMEBUFFER); 1.55 void *fb = map_mem_buffer(mbuf, MAP_RD); 1.56 @@ -130,6 +126,12 @@ 1.57 return false; 1.58 } 1.59 1.60 + static int foo = 0; 1.61 + if(!foo++) { 1.62 + bool write_ppm(const char *fname, float *fb, int xsz, int ysz); 1.63 + write_ppm("foo.ppm", (float*)fb, rinf.xsz, rinf.ysz); 1.64 + } 1.65 + 1.66 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rinf.xsz, rinf.ysz, GL_RGBA, GL_FLOAT, fb); 1.67 unmap_mem_buffer(mbuf); 1.68 return true; 1.69 @@ -148,7 +150,7 @@ 1.70 1.71 void dbg_render_gl(Scene *scn) 1.72 { 1.73 - glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT); 1.74 + glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_LIGHTING_BIT); 1.75 1.76 for(int i=0; i<rinf.num_lights; i++) { 1.77 float lpos[4]; 1.78 @@ -158,12 +160,12 @@ 1.79 1.80 glLightfv(GL_LIGHT0 + i, GL_POSITION, lpos); 1.81 glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, lightlist[i].color); 1.82 + glEnable(GL_LIGHT0 + i); 1.83 } 1.84 1.85 glDisable(GL_TEXTURE_2D); 1.86 glEnable(GL_DEPTH_TEST); 1.87 glEnable(GL_LIGHTING); 1.88 - glEnable(GL_LIGHT0); 1.89 1.90 glMatrixMode(GL_PROJECTION); 1.91 glPushMatrix(); 1.92 @@ -194,6 +196,8 @@ 1.93 1.94 glPopMatrix(); 1.95 glPopAttrib(); 1.96 + 1.97 + assert(glGetError() == GL_NO_ERROR); 1.98 } 1.99 1.100 void set_xform(float *matrix, float *invtrans) 1.101 @@ -204,20 +208,10 @@ 1.102 1.103 float *mem = (float*)map_mem_buffer(mbuf_xform, MAP_WR); 1.104 memcpy(mem, matrix, 16 * sizeof *mem); 1.105 - /*printf("-- xform:\n"); 1.106 - for(int i=0; i<16; i++) { 1.107 - printf("%2.3f\t", mem[i]); 1.108 - if(i % 4 == 3) putchar('\n'); 1.109 - }*/ 1.110 unmap_mem_buffer(mbuf_xform); 1.111 1.112 mem = (float*)map_mem_buffer(mbuf_invtrans, MAP_WR); 1.113 memcpy(mem, invtrans, 16 * sizeof *mem); 1.114 - /*printf("-- inverse-transpose:\n"); 1.115 - for(int i=0; i<16; i++) { 1.116 - printf("%2.3f\t", mem[i]); 1.117 - if(i % 4 == 3) putchar('\n'); 1.118 - }*/ 1.119 unmap_mem_buffer(mbuf_invtrans); 1.120 } 1.121