clray

diff src/rt.cc @ 14:29f9330cfa4b

trying to debug the bloody thing
author John Tsiombikas
date Sat, 07 Aug 2010 03:36:36 +0100
parents 407935b73af3
children 754faf15ba36
line diff
     1.1 --- a/src/rt.cc	Wed Aug 04 04:51:06 2010 +0100
     1.2 +++ b/src/rt.cc	Sat Aug 07 03:36:36 2010 +0100
     1.3 @@ -2,15 +2,7 @@
     1.4  #include <string.h>
     1.5  #include <math.h>
     1.6  #include <assert.h>
     1.7 -
     1.8 -#ifndef __APPLE__
     1.9 -#include <GL/gl.h>
    1.10 -#include <GL/glu.h>
    1.11 -#else
    1.12 -#include <OpenGL/gl.h>
    1.13 -#include <OpenGL/glu.h>
    1.14 -#endif
    1.15 -
    1.16 +#include "ogl.h"
    1.17  #include "ocl.h"
    1.18  #include "mesh.h"
    1.19  
    1.20 @@ -23,7 +15,9 @@
    1.21  	KARG_LIGHTS,
    1.22  	KARG_PRIM_RAYS,
    1.23  	KARG_XFORM,
    1.24 -	KARG_INVTRANS_XFORM
    1.25 +	KARG_INVTRANS_XFORM,
    1.26 +
    1.27 +	NUM_KERNEL_ARGS
    1.28  };
    1.29  
    1.30  struct RendInfo {
    1.31 @@ -89,13 +83,17 @@
    1.32  	/* setup argument buffers */
    1.33  	prog->set_arg_buffer(KARG_FRAMEBUFFER, ARG_WR, xsz * ysz * 4 * sizeof(float));
    1.34  	prog->set_arg_buffer(KARG_RENDER_INFO, ARG_RD, sizeof rinf, &rinf);
    1.35 -	prog->set_arg_buffer(KARG_FACES, ARG_RD, rinf.num_faces, faces);
    1.36 -	prog->set_arg_buffer(KARG_MATLIB, ARG_RD, scn->matlib.size() * sizeof(Material), &scn->matlib[0]);
    1.37 +	prog->set_arg_buffer(KARG_FACES, ARG_RD, rinf.num_faces * sizeof(Face), faces);
    1.38 +	prog->set_arg_buffer(KARG_MATLIB, ARG_RD, scn->get_num_materials() * sizeof(Material), scn->get_materials());
    1.39  	prog->set_arg_buffer(KARG_LIGHTS, ARG_RD, sizeof lightlist, lightlist);
    1.40  	prog->set_arg_buffer(KARG_PRIM_RAYS, ARG_RD, xsz * ysz * sizeof *prim_rays, prim_rays);
    1.41  	prog->set_arg_buffer(KARG_XFORM, ARG_RD, 16 * sizeof(float));
    1.42  	prog->set_arg_buffer(KARG_INVTRANS_XFORM, ARG_RD, 16 * sizeof(float));
    1.43  
    1.44 +	if(prog->get_num_args() < NUM_KERNEL_ARGS) {
    1.45 +		return false;
    1.46 +	}
    1.47 +
    1.48  	delete [] prim_rays;
    1.49  
    1.50  	global_size = xsz * ysz;
    1.51 @@ -140,11 +138,18 @@
    1.52  	glLoadIdentity();
    1.53  	gluPerspective(45.0, (float)rinf.xsz / (float)rinf.ysz, 0.5, 1000.0);
    1.54  
    1.55 +	Material *materials = scn->get_materials();
    1.56 +
    1.57  	glBegin(GL_TRIANGLES);
    1.58  	int num_faces = scn->get_num_faces();
    1.59  	for(int i=0; i<num_faces; i++) {
    1.60 -		Material *mat = &scn->matlib[faces[i].matid];
    1.61 -		glColor3f(mat->kd[0], mat->kd[1], mat->kd[2]);
    1.62 +		Material *mat = materials ? materials + faces[i].matid : 0;
    1.63 +
    1.64 +		if(mat) {
    1.65 +			glColor3f(mat->kd[0], mat->kd[1], mat->kd[2]);
    1.66 +		} else {
    1.67 +			glColor3f(1, 1, 1);
    1.68 +		}
    1.69  
    1.70  		for(int j=0; j<3; j++) {
    1.71  			float *pos = faces[i].v[j].pos;