deepstone

diff src/scantmpl.h @ 9:bce78aaafc68

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 26 Nov 2011 03:59:48 +0200
parents 0e781cc43178
children 059bb38506b3
line diff
     1.1 --- a/src/scantmpl.h	Mon Nov 21 12:45:18 2011 +0200
     1.2 +++ b/src/scantmpl.h	Sat Nov 26 03:59:48 2011 +0200
     1.3 @@ -66,17 +66,41 @@
     1.4  	start = (int)ROUND(v0->pos.y);
     1.5  	end = (int)ROUND(v1->pos.y);
     1.6  
     1.7 -	x = v0->pos.x;
     1.8 +	if(start >= 0) {
     1.9 +
    1.10 +		x = v0->pos.x;
    1.11  #ifdef INTERP_DEPTH
    1.12 -	z = v0->pos.z;
    1.13 +		z = v0->pos.z;
    1.14  #endif
    1.15  #ifdef INTERP_ENERGY
    1.16 -	e = v0->energy;
    1.17 +		e = v0->energy;
    1.18  #endif
    1.19  #ifdef INTERP_TEX
    1.20 -	u = v0->tc.x;
    1.21 -	v = v0->tc.y;
    1.22 +		u = v0->tc.x;
    1.23 +		v = v0->tc.y;
    1.24  #endif
    1.25 +	} else {
    1.26 +		float lines = -v0->pos.y;
    1.27 +
    1.28 +		x = v0->pos.x + dfdx * lines;
    1.29 +#ifdef INTERP_DEPTH
    1.30 +		z = v0->pos.z + dfdz * lines;
    1.31 +#endif
    1.32 +#ifdef INTERP_ENERGY
    1.33 +		e = v0->energy + dfde * lines;
    1.34 +#endif
    1.35 +#ifdef INTERP_TEX
    1.36 +		u = v0->tc.x + dfdu * lines;
    1.37 +		v = v0->tc.y + dfdv * lines;
    1.38 +#endif
    1.39 +		start = 0;
    1.40 +	}
    1.41 +
    1.42 +	if(end >= fb->height) {
    1.43 +		end = fb->height - 1;
    1.44 +	}
    1.45 +
    1.46 +
    1.47  	for(i=start; i<end; i++) {
    1.48  		edge[i].pos.x = x;
    1.49  		x += dfdx;
    1.50 @@ -124,7 +148,6 @@
    1.51  
    1.52  	x0 = (int)ROUND(vleft[y].pos.x);
    1.53  	x1 = (int)ROUND(vright[y].pos.x);
    1.54 -	len = x1 - x0;
    1.55  
    1.56  	if(x1 < x0) {
    1.57  		if(st->flags & MGL_CULL_FACE) {
    1.58 @@ -133,7 +156,6 @@
    1.59  		tmp = x0;
    1.60  		x0 = x1;
    1.61  		x1 = tmp;
    1.62 -		len = -len;
    1.63  
    1.64  		left = vright;
    1.65  		right = vleft;
    1.66 @@ -142,13 +164,15 @@
    1.67  		right = vright;
    1.68  	}
    1.69  
    1.70 -	if(x0 < 0) x0 = 0;
    1.71 -	if(x1 >= fb->width) x1 = fb->width - 1;
    1.72 -
    1.73 -	assert(len >= 0);
    1.74 +	if(x1 >= fb->width) {
    1.75 +		x1 = fb->width - 1;
    1.76 +	}
    1.77  
    1.78  	cidx = left[y].cidx;
    1.79  #if !defined(INTERP_DEPTH) && !defined(INTERP_ENERGY) && !defined(INTERP_TEX)
    1.80 +	if(x0 < 0) x0 = 0;
    1.81 +	len = x1 - x0;
    1.82 +	assert(len >= 0);
    1.83  	/* no interpolation at all, just memset the whole scanline */
    1.84  	memset(sline + x0, cidx + left[y].energy * st->col_range, len);
    1.85  #else
    1.86 @@ -160,29 +184,72 @@
    1.87  		return;
    1.88  	}
    1.89  
    1.90 +	if(x0 >= 0) {
    1.91  #ifdef INTERP_DEPTH
    1.92 -	z = left[y].pos.z;
    1.93 -	dz = right[y].pos.z - z;
    1.94 -	dfdz = dz / dx;
    1.95 +		z = left[y].pos.z;
    1.96 +		dz = right[y].pos.z - z;
    1.97 +		dfdz = dz / dx;
    1.98  #endif
    1.99  #ifdef INTERP_ENERGY
   1.100 -	e = left[y].energy;
   1.101 -	de = right[y].energy - e;
   1.102 -	dfde = de / dx;
   1.103 +		e = left[y].energy;
   1.104 +		de = right[y].energy - e;
   1.105 +		dfde = de / dx;
   1.106  #endif
   1.107  #ifdef INTERP_TEX
   1.108 -	u = left[y].tc.x;
   1.109 -	v = left[y].tc.y;
   1.110 -	du = right[y].tc.x - u;
   1.111 -	dv = right[y].tc.y - v;
   1.112 -	dfdu = du / dx;
   1.113 -	dfdv = dv / dx;
   1.114 +		u = left[y].tc.x;
   1.115 +		v = left[y].tc.y;
   1.116 +		du = right[y].tc.x - u;
   1.117 +		dv = right[y].tc.y - v;
   1.118 +		dfdu = du / dx;
   1.119 +		dfdv = dv / dx;
   1.120  #endif
   1.121 +	} else {
   1.122 +		float dist = -left[y].pos.x;
   1.123 +
   1.124 +#ifdef INTERP_DEPTH
   1.125 +		dz = right[y].pos.z - left[y].pos.z;
   1.126 +		dfdz = dz / dx;
   1.127 +		z = left[y].pos.z + dfdz * dist;
   1.128 +#endif
   1.129 +#ifdef INTERP_ENERGY
   1.130 +		de = right[y].energy - left[y].energy;
   1.131 +		dfde = de / dx;
   1.132 +		e = left[y].energy + dfde * dist;
   1.133 +#endif
   1.134 +#ifdef INTERP_TEX
   1.135 +		du = right[y].tc.x - left[y].tc.x;
   1.136 +		dv = right[y].tc.y - left[y].tc.y;
   1.137 +		dfdu = du / dx;
   1.138 +		dfdv = dv / dx;
   1.139 +		u = left[y].tc.x + dfdu * dist;
   1.140 +		v = left[y].tc.y + dfdv * dist;
   1.141 +#endif
   1.142 +		x0 = 0;
   1.143 +	}
   1.144 +
   1.145 +	len = x1 - x0;
   1.146  
   1.147  	for(i=0; i<len; i++) {
   1.148  		int c = cidx;
   1.149  
   1.150  #ifdef INTERP_DEPTH
   1.151 +		int pix = (sline + x0 + i) - fb->pixels;
   1.152 +		unsigned short zval = (unsigned short)(z * USHRT_MAX);
   1.153 +		unsigned short *zptr = fb->zbuf[ZTILE(pix)] + ZTILE_OFFS(pix);
   1.154 +
   1.155 +		if(z < 0.0 || z >= 1.0 || zval > *zptr) {
   1.156 +# ifdef INTERP_TEX
   1.157 +			u += dfdu;
   1.158 +			v += dfdv;
   1.159 +# endif
   1.160 +# ifdef INTERP_ENERGY
   1.161 +			e += dfde;
   1.162 +# endif
   1.163 +			z += dfdz;
   1.164 +			continue;
   1.165 +		}
   1.166 +
   1.167 +		*zptr = zval;
   1.168  		z += dfdz;
   1.169  #endif
   1.170  #ifdef INTERP_TEX