clray

diff src/rt.cc @ 15:754faf15ba36

burp
author John Tsiombikas
date Sun, 08 Aug 2010 09:51:45 +0100
parents 29f9330cfa4b
children 9e4a28063394
line diff
     1.1 --- a/src/rt.cc	Sat Aug 07 03:36:36 2010 +0100
     1.2 +++ b/src/rt.cc	Sun Aug 08 09:51:45 2010 +0100
     1.3 @@ -16,6 +16,7 @@
     1.4  	KARG_PRIM_RAYS,
     1.5  	KARG_XFORM,
     1.6  	KARG_INVTRANS_XFORM,
     1.7 +	KARG_OUTFACES,	/* DBG */
     1.8  
     1.9  	NUM_KERNEL_ARGS
    1.10  };
    1.11 @@ -24,6 +25,7 @@
    1.12  	int xsz, ysz;
    1.13  	int num_faces, num_lights;
    1.14  	int max_iter;
    1.15 +	int dbg;
    1.16  };
    1.17  
    1.18  struct Ray {
    1.19 @@ -58,6 +60,7 @@
    1.20  	rinf.num_faces = scn->get_num_faces();
    1.21  	rinf.num_lights = sizeof lightlist / sizeof *lightlist;
    1.22  	rinf.max_iter = 6;
    1.23 +	rinf.dbg = 8;
    1.24  
    1.25  	/* calculate primary rays */
    1.26  	prim_rays = new Ray[xsz * ysz];
    1.27 @@ -89,6 +92,7 @@
    1.28  	prog->set_arg_buffer(KARG_PRIM_RAYS, ARG_RD, xsz * ysz * sizeof *prim_rays, prim_rays);
    1.29  	prog->set_arg_buffer(KARG_XFORM, ARG_RD, 16 * sizeof(float));
    1.30  	prog->set_arg_buffer(KARG_INVTRANS_XFORM, ARG_RD, 16 * sizeof(float));
    1.31 +	prog->set_arg_buffer(KARG_OUTFACES, ARG_WR, rinf.num_faces * sizeof(Face));
    1.32  
    1.33  	if(prog->get_num_args() < NUM_KERNEL_ARGS) {
    1.34  		return false;
    1.35 @@ -114,6 +118,20 @@
    1.36  	}
    1.37  	printf("done\n");
    1.38  
    1.39 +	/* DEBUG */
    1.40 +	CLMemBuffer *dbgbuf = prog->get_arg_buffer(KARG_OUTFACES);
    1.41 +	Face *outfaces = (Face*)map_mem_buffer(dbgbuf, MAP_RD);
    1.42 +	for(int i=0; i<rinf.num_faces; i++) {
    1.43 +		if(!(faces[i] == outfaces[i])) {
    1.44 +			fprintf(stderr, "SKATA %d\n", i);
    1.45 +			return false;
    1.46 +		}
    1.47 +		faces[i] = outfaces[i];
    1.48 +	}
    1.49 +	printf("equality test passed\n");
    1.50 +	unmap_mem_buffer(dbgbuf);
    1.51 +
    1.52 +
    1.53  	CLMemBuffer *mbuf = prog->get_arg_buffer(KARG_FRAMEBUFFER);
    1.54  	void *fb = map_mem_buffer(mbuf, MAP_RD);
    1.55  	if(!fb) {
    1.56 @@ -126,12 +144,27 @@
    1.57  	return true;
    1.58  }
    1.59  
    1.60 +void dbg_set_dbg(int dbg)
    1.61 +{
    1.62 +	printf("setting dbg: %d\n", dbg);
    1.63 +
    1.64 +	CLMemBuffer *mbuf = prog->get_arg_buffer(KARG_RENDER_INFO);
    1.65 +	RendInfo *rinf = (RendInfo*)map_mem_buffer(mbuf, MAP_WR);
    1.66 +	rinf->dbg = dbg;
    1.67 +	unmap_mem_buffer(mbuf);
    1.68 +}
    1.69 +
    1.70  void dbg_render_gl(Scene *scn)
    1.71  {
    1.72 +	float lpos[] = {-1, 1, 10, 0};
    1.73  	glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT);
    1.74  
    1.75  	glDisable(GL_TEXTURE_2D);
    1.76  	glEnable(GL_DEPTH_TEST);
    1.77 +	glEnable(GL_LIGHTING);
    1.78 +	glEnable(GL_LIGHT0);
    1.79 +	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
    1.80 +	glEnable(GL_COLOR_MATERIAL);
    1.81  
    1.82  	glMatrixMode(GL_PROJECTION);
    1.83  	glPushMatrix();
    1.84 @@ -153,7 +186,9 @@
    1.85  
    1.86  		for(int j=0; j<3; j++) {
    1.87  			float *pos = faces[i].v[j].pos;
    1.88 -			glVertex3f(pos[0], pos[1], pos[2]);
    1.89 +			float *norm = faces[i].normal;
    1.90 +			glNormal3fv(norm);
    1.91 +			glVertex3fv(pos);
    1.92  		}
    1.93  	}
    1.94