clray

diff src/clray.cc @ 54:6a30f27fa1e6

separated the OpenGL visualization and added a CPU raytracing mode
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 10 Sep 2010 16:47:00 +0100
parents 55b30d8b6805
children df239a52a091
line diff
     1.1 --- a/src/clray.cc	Sun Sep 05 16:43:55 2010 +0100
     1.2 +++ b/src/clray.cc	Fri Sep 10 16:47:00 2010 +0100
     1.3 @@ -33,14 +33,21 @@
     1.4  static float cam_theta, cam_phi = 25.0;
     1.5  static float cam_dist = 10.0;
     1.6  
     1.7 -static bool dbg_glrender = false;
     1.8 -static bool dbg_show_kdtree = false;
     1.9 +static bool dbg_glrender;
    1.10 +static bool dbg_nocl;
    1.11 +static bool dbg_show_kdtree;
    1.12  static bool dbg_show_obj = true;
    1.13  bool dbg_frame_time = true;
    1.14  
    1.15  static Scene scn;
    1.16  static unsigned int tex;
    1.17  
    1.18 +static Light lightlist[] = {
    1.19 +	{{-8, 15, 18, 0}, {1, 1, 1, 1}}
    1.20 +};
    1.21 +
    1.22 +
    1.23 +
    1.24  int main(int argc, char **argv)
    1.25  {
    1.26  	glutInitWindowSize(800, 600);
    1.27 @@ -81,6 +88,10 @@
    1.28  				dbg_glrender = true;
    1.29  				break;
    1.30  
    1.31 +			case 'n':
    1.32 +				dbg_nocl = true;
    1.33 +				break;
    1.34 +
    1.35  			default:
    1.36  				fprintf(stderr, "unrecognized option: %s\n", argv[i]);
    1.37  				return 1;
    1.38 @@ -103,6 +114,11 @@
    1.39  		return false;
    1.40  	}
    1.41  
    1.42 +	int num_lights = sizeof lightlist / sizeof *lightlist;
    1.43 +	for(int i=0; i<num_lights; i++) {
    1.44 +		scn.add_light(lightlist[i]);
    1.45 +	}
    1.46 +
    1.47  	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    1.48  	glutCreateWindow("OpenCL Raytracer");
    1.49  
    1.50 @@ -171,11 +187,6 @@
    1.51  
    1.52  		glGetFloatv(GL_MODELVIEW_MATRIX, mat.m);
    1.53  
    1.54 -		inv_mat = mat;
    1.55 -		inv_mat.invert();
    1.56 -
    1.57 -		/*inv_trans = inv_mat;
    1.58 -		inv_trans.transpose();*/
    1.59  		inv_trans = mat;
    1.60  		inv_trans.m[3] = inv_trans.m[7] = inv_trans.m[11] = 0.0;
    1.61  		inv_trans.m[12] = inv_trans.m[13] = inv_trans.m[14] = 0.0;
    1.62 @@ -185,14 +196,21 @@
    1.63  		glPopMatrix();
    1.64  
    1.65  		if(!dbg_glrender) {
    1.66 -			if(!render()) {
    1.67 -				exit(1);
    1.68 +			if(dbg_nocl) {
    1.69 +				dbg_render(mat.m, inv_trans.m);
    1.70 +			} else {
    1.71 +				if(!render()) {
    1.72 +					exit(1);
    1.73 +				}
    1.74  			}
    1.75  			need_update = false;
    1.76  		}
    1.77  	}
    1.78  
    1.79  	if(dbg_glrender) {
    1.80 +		inv_mat = mat;
    1.81 +		inv_mat.invert();
    1.82 +
    1.83  		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.84  		glLoadMatrixf(inv_mat.m);
    1.85  		dbg_render_gl(&scn, dbg_show_kdtree, dbg_show_obj);
    1.86 @@ -322,6 +340,13 @@
    1.87  		dbg_frame_time = !dbg_frame_time;
    1.88  		break;
    1.89  
    1.90 +	case 'n':
    1.91 +		dbg_nocl = !dbg_nocl;
    1.92 +		printf("switching to %s rendering\n", dbg_nocl ? "debug CPU" : "OpenCL");
    1.93 +		need_update = true;
    1.94 +		glutPostRedisplay();
    1.95 +		break;
    1.96 +
    1.97  	default:
    1.98  		break;
    1.99  	}