gba-x3dtest

diff src/x3d.c @ 15:b755fb002f17

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 25 Jun 2014 17:02:48 +0300
parents c398d834d64a
children 0a7f402892b3
line diff
     1.1 --- a/src/x3d.c	Mon Jun 23 10:33:24 2014 +0300
     1.2 +++ b/src/x3d.c	Wed Jun 25 17:02:48 2014 +0300
     1.3 @@ -17,7 +17,8 @@
     1.4  	int32_t m[12];
     1.5  };
     1.6  
     1.7 -static void proc_vertex(const int32_t *vin, const int32_t *cin, pvec3 *vout, pvec3 *cout);
     1.8 +static void proc_vertex(const int32_t *vin, const int32_t *cin, const int32_t *tin,
     1.9 +		pvec3 *vout, pvec3 *cout, pvec2 *tout);
    1.10  static int dump_frame(struct pixel_buffer *frame);
    1.11  
    1.12  
    1.13 @@ -39,8 +40,11 @@
    1.14  static unsigned short vertex_count;
    1.15  static const int32_t *color_array;
    1.16  static unsigned short color_count;
    1.17 +static const int32_t *texcoord_array;
    1.18 +static unsigned short texcoord_count;
    1.19  
    1.20  static int32_t im_color[3];
    1.21 +static int32_t im_texcoord[2];
    1.22  static uint8_t im_color_index;
    1.23  
    1.24  void x3d_projection(int fov, int32_t aspect, int32_t nearz, int32_t farz)
    1.25 @@ -163,11 +167,18 @@
    1.26  	color_count = count;
    1.27  }
    1.28  
    1.29 +void x3d_texcoord_array(int count, const int32_t *ptr)
    1.30 +{
    1.31 +	texcoord_array = ptr;
    1.32 +	texcoord_count = count;
    1.33 +}
    1.34 +
    1.35  int x3d_draw(int prim, int vnum)
    1.36  {
    1.37  	int i, j, pverts = prim;
    1.38  	const int32_t *vptr = vertex_array;
    1.39  	const int32_t *cptr = color_array;
    1.40 +	const int32_t *tptr = texcoord_array;
    1.41  #ifndef PALMODE
    1.42  	short cr, cg, cb;
    1.43  #endif
    1.44 @@ -185,14 +196,20 @@
    1.45  				__FUNCTION__, vnum, color_count);
    1.46  		vnum = color_count;
    1.47  	}
    1.48 +	if(texcoord_array && vnum > texcoord_count) {
    1.49 +		logmsg(LOG_DBG, "%s called with vnum=%d, but current texcoord array has %d elements\n",
    1.50 +				__FUNCTION__, vnum, texcoord_count);
    1.51 +		vnum = texcoord_count;
    1.52 +	}
    1.53  
    1.54  	for(i=0; i<vnum; i+=pverts) {
    1.55  		/* process vertices */
    1.56  		pvec3 vpos[4];
    1.57  		pvec3 col[4];
    1.58 +		pvec2 tex[4];
    1.59  
    1.60  		for(j=0; j<pverts; j++) {
    1.61 -			proc_vertex(vptr, cptr, vpos + j, col + j);
    1.62 +			proc_vertex(vptr, cptr, tptr, vpos + j, col + j, tex + j);
    1.63  
    1.64  			if(vpos[j].z <= proj_near) {
    1.65  				goto skip_prim;
    1.66 @@ -200,6 +217,7 @@
    1.67  
    1.68  			vptr += 3;
    1.69  			if(cptr) cptr += 3;
    1.70 +			if(tptr) tptr += 2;
    1.71  		}
    1.72  
    1.73  #ifdef PALMODE
    1.74 @@ -239,7 +257,7 @@
    1.75  
    1.76  		case X3D_TRIANGLES:
    1.77  		case X3D_QUADS:
    1.78 -			draw_poly(pverts, vpos, color);
    1.79 +			draw_poly(pverts, vpos, tex, color);
    1.80  			if(dbg_fill_dump) {
    1.81  				dump_frame(back_buffer);
    1.82  			}
    1.83 @@ -252,7 +270,8 @@
    1.84  	return 0;
    1.85  }
    1.86  
    1.87 -static void proc_vertex(const int32_t *vin, const int32_t *cin, pvec3 *vout, pvec3 *cout)
    1.88 +static void proc_vertex(const int32_t *vin, const int32_t *cin, const int32_t *tin,
    1.89 +		pvec3 *vout, pvec3 *cout, pvec2 *tout)
    1.90  {
    1.91  	int i;
    1.92  	int32_t tvert[3];
    1.93 @@ -283,6 +302,14 @@
    1.94  		cout->y = im_color[1];
    1.95  		cout->z = im_color[2];
    1.96  	}
    1.97 +
    1.98 +	if(texcoord_array) {
    1.99 +		tout->x = tin[0];
   1.100 +		tout->y = tin[1];
   1.101 +	} else {
   1.102 +		tout->x = im_texcoord[0];
   1.103 +		tout->y = im_texcoord[1];
   1.104 +	}
   1.105  }
   1.106  
   1.107  void x3d_color_index(int cidx)