clray

changeset 58:3d13924b22e6

implementing polygon split
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 12 Sep 2010 00:19:04 +0100
parents 14c8ebe8f122
children eb97f9c92e1d
files src/clray.cc src/rt.cc src/scene.cc
diffstat 3 files changed, 44 insertions(+), 13 deletions(-) [+]
line diff
     1.1 --- a/src/clray.cc	Sat Sep 11 03:01:20 2010 +0100
     1.2 +++ b/src/clray.cc	Sun Sep 12 00:19:04 2010 +0100
     1.3 @@ -203,6 +203,11 @@
     1.4  				if(!render()) {
     1.5  					exit(1);
     1.6  				}
     1.7 +
     1.8 +				if(dbg_frame_time) {
     1.9 +					const RenderStats *rstat = get_render_stats();
    1.10 +					printf("render time (msec): %lu\n", rstat->render_time);
    1.11 +				}
    1.12  			}
    1.13  			need_update = false;
    1.14  		}
    1.15 @@ -242,10 +247,7 @@
    1.16  {
    1.17  	glViewport(0, 0, x, y);
    1.18  
    1.19 -	/* reallocate the framebuffer */
    1.20 -	/*delete [] fb;
    1.21 -	fb = new float[x * y * 4];
    1.22 -	set_framebuffer(fb, x, y);*/
    1.23 +	/* TODO reallocate the framebuffer to fit the window */
    1.24  }
    1.25  
    1.26  void idle()
     2.1 --- a/src/rt.cc	Sat Sep 11 03:01:20 2010 +0100
     2.2 +++ b/src/rt.cc	Sun Sep 12 00:19:04 2010 +0100
     2.3 @@ -1,6 +1,7 @@
     2.4  #include <stdio.h>
     2.5  #include <string.h>
     2.6  #include <math.h>
     2.7 +#include <limits.h>
     2.8  #include <assert.h>
     2.9  #include "rt.h"
    2.10  #include "ogl.h"
    2.11 @@ -41,8 +42,6 @@
    2.12  static long timing_sample_sum;
    2.13  static long num_timing_samples;
    2.14  
    2.15 -extern bool dbg_frame_time;
    2.16 -
    2.17  
    2.18  bool init_renderer(int xsz, int ysz, Scene *scn, unsigned int tex)
    2.19  {
    2.20 @@ -137,9 +136,12 @@
    2.21  
    2.22  bool render()
    2.23  {
    2.24 -	// XXX do we need to call glFinish ?
    2.25 +	long tm0 = get_msec();
    2.26  
    2.27 -	long tm0 = get_msec();
    2.28 +	// initialize render-stats
    2.29 +	memset(&rstat, 0, sizeof rstat);
    2.30 +	rstat.min_aabb_tests = rstat.min_triangle_tests = INT_MAX;
    2.31 +	rstat.max_aabb_tests = rstat.max_triangle_tests = 0;
    2.32  
    2.33  #ifdef CLGL_INTEROP
    2.34  	cl_event ev;
    2.35 @@ -180,13 +182,11 @@
    2.36  	unmap_mem_buffer(mbuf);
    2.37  #endif
    2.38  
    2.39 -	long msec = get_msec() - tm0;
    2.40 -	timing_sample_sum += msec;
    2.41 +	rstat.render_time = get_msec() - tm0;
    2.42 +
    2.43 +	timing_sample_sum += rstat.render_time;
    2.44  	num_timing_samples++;
    2.45  
    2.46 -	if(dbg_frame_time) {
    2.47 -		printf("rendered in %ld msec\n", msec);
    2.48 -	}
    2.49  	return true;
    2.50  }
    2.51  
     3.1 --- a/src/scene.cc	Sat Sep 11 03:01:20 2010 +0100
     3.2 +++ b/src/scene.cc	Sun Sep 12 00:19:04 2010 +0100
     3.3 @@ -20,6 +20,7 @@
     3.4  static float eval_cost(const Face *faces, const int *face_idx, int num_faces, const AABBox &aabb, int axis);
     3.5  static void free_kdtree(KDNode *node);
     3.6  static void print_item_counts(const KDNode *node, int level);
     3.7 +static int split_face(const Face *inface, int axis, Face *face1, Face *face2);
     3.8  
     3.9  
    3.10  static int accel_param[NUM_ACCEL_PARAMS] = {
    3.11 @@ -589,3 +590,31 @@
    3.12  	print_item_counts(node->left, level + 1);
    3.13  	print_item_counts(node->right, level + 1);
    3.14  }
    3.15 +/*
    3.16 +#define SWAP(a, b, type)	\
    3.17 +	do { \
    3.18 +		type tmp = a; \
    3.19 +		a = b; \
    3.20 +		b = tmp; \
    3.21 +	} while(0)
    3.22 +
    3.23 +static bool clip_face(const Face *inface, float splitpos, int axis, Face *face1, Face *face2)
    3.24 +{
    3.25 +	assert(inface && face1 && face2);
    3.26 +	assert(inface != face1 && inface != face2);
    3.27 +	assert(axis >= 0 && axis < 3);
    3.28 +
    3.29 +	std::vector<Vertex> verts;
    3.30 +
    3.31 +	// find the edges that must be split
    3.32 +	for(int i=0; i<3; i++) {
    3.33 +		verts.push_back(inface->v[i]);
    3.34 +
    3.35 +		float start = inface->v[i].pos[axis];
    3.36 +		float end = inface->v[(i + 1) % 3].pos[axis];
    3.37 +
    3.38 +		if((splitpos >= start && splitpos < end) || (splitpos >= end && splitpos < start)) {
    3.39 +
    3.40 +		}
    3.41 +	}
    3.42 +}*/