gba-x3dtest

annotate src/ggen.c @ 20:2e903e27e35a

fixed x3d_disable_texture added runtime teture checks in the rasterizer
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 01 Jul 2014 23:23:37 +0300
parents c398d834d64a
children
rev   line source
nuclear@12 1 #include <stdlib.h>
nuclear@12 2 #include "ggen.h"
nuclear@12 3 #include "mesh.h"
nuclear@12 4
nuclear@12 5 #define X1 65536
nuclear@12 6 #define VERTEX(x, y, z) \
nuclear@12 7 do { \
nuclear@12 8 *vptr++ = x; \
nuclear@12 9 *vptr++ = y; \
nuclear@12 10 *vptr++ = z; \
nuclear@12 11 } while(0)
nuclear@12 12
nuclear@13 13 #define COLOR(r, g, b) \
nuclear@13 14 do { \
nuclear@13 15 *cptr++ = r; \
nuclear@13 16 *cptr++ = g; \
nuclear@13 17 *cptr++ = b; \
nuclear@13 18 } while(0)
nuclear@13 19
nuclear@15 20 #define TEXCOORD(u, v) \
nuclear@15 21 do { \
nuclear@15 22 *tptr++ = u; \
nuclear@15 23 *tptr++ = v; \
nuclear@15 24 } while(0)
nuclear@15 25
nuclear@12 26 int gen_box(struct mesh *m)
nuclear@12 27 {
nuclear@13 28 int i;
nuclear@15 29 int num_faces = 6;
nuclear@15 30 int num_verts = num_faces * 4;
nuclear@12 31 int32_t v[8][3] = {
nuclear@12 32 {-X1, -X1, -X1}, {X1, -X1, -X1}, {X1, -X1, X1}, {-X1, -X1, X1},
nuclear@12 33 {-X1, X1, -X1}, {X1, X1, -X1}, {X1, X1, X1}, {-X1, X1, X1}
nuclear@12 34 };
nuclear@15 35 int32_t *vptr, *cptr, *tptr;
nuclear@12 36
nuclear@12 37
nuclear@15 38 m->prim = X3D_QUADS;
nuclear@12 39 m->nverts = num_verts;
nuclear@13 40 if(!(m->verts = malloc(num_verts * 3 * sizeof *m->verts))) {
nuclear@12 41 return -1;
nuclear@12 42 }
nuclear@12 43 vptr = m->verts;
nuclear@12 44
nuclear@13 45 if(!(m->colors = malloc(num_verts * 3 * sizeof *m->colors))) {
nuclear@13 46 return -1;
nuclear@13 47 }
nuclear@13 48 cptr = m->colors;
nuclear@13 49
nuclear@15 50 if(!(m->texcoords = malloc(num_verts * 2 * sizeof *m->texcoords))) {
nuclear@15 51 return -1;
nuclear@15 52 }
nuclear@15 53 tptr = m->texcoords;
nuclear@15 54
nuclear@12 55 /* -Y */
nuclear@12 56 VERTEX(v[0][0], v[0][1], v[0][2]);
nuclear@12 57 VERTEX(v[1][0], v[1][1], v[1][2]);
nuclear@12 58 VERTEX(v[2][0], v[2][1], v[2][2]);
nuclear@12 59 VERTEX(v[3][0], v[3][1], v[3][2]);
nuclear@15 60 TEXCOORD(65536, 0);
nuclear@15 61 TEXCOORD(0, 0);
nuclear@15 62 TEXCOORD(0, 65536);
nuclear@15 63 TEXCOORD(65536, 65536);
nuclear@15 64 for(i=0; i<4; i++) COLOR(65536, 0, 65536);
nuclear@13 65
nuclear@12 66 /* +Y */
nuclear@15 67 VERTEX(v[4][0], v[4][1], v[4][2]);
nuclear@14 68 VERTEX(v[7][0], v[7][1], v[7][2]);
nuclear@14 69 VERTEX(v[6][0], v[6][1], v[6][2]);
nuclear@14 70 VERTEX(v[5][0], v[5][1], v[5][2]);
nuclear@15 71 TEXCOORD(0, 0);
nuclear@15 72 TEXCOORD(0, 65536);
nuclear@15 73 TEXCOORD(65536, 65536);
nuclear@15 74 TEXCOORD(65536, 0);
nuclear@15 75 for(i=0; i<4; i++) COLOR(0, 65536, 0);
nuclear@13 76
nuclear@12 77 /* -Z */
nuclear@12 78 VERTEX(v[0][0], v[0][1], v[0][2]);
nuclear@12 79 VERTEX(v[4][0], v[4][1], v[4][2]);
nuclear@12 80 VERTEX(v[5][0], v[5][1], v[5][2]);
nuclear@12 81 VERTEX(v[1][0], v[1][1], v[1][2]);
nuclear@15 82 TEXCOORD(0, 0);
nuclear@15 83 TEXCOORD(0, 65536);
nuclear@15 84 TEXCOORD(65536, 65536);
nuclear@15 85 TEXCOORD(65536, 0);
nuclear@15 86 for(i=0; i<4; i++) COLOR(65536, 65536, 0);
nuclear@13 87
nuclear@12 88 /* +Z */
nuclear@12 89 VERTEX(v[2][0], v[2][1], v[2][2]);
nuclear@12 90 VERTEX(v[6][0], v[6][1], v[6][2]);
nuclear@12 91 VERTEX(v[7][0], v[7][1], v[7][2]);
nuclear@12 92 VERTEX(v[3][0], v[3][1], v[3][2]);
nuclear@15 93 TEXCOORD(0, 0);
nuclear@15 94 TEXCOORD(0, 65536);
nuclear@15 95 TEXCOORD(65536, 65536);
nuclear@15 96 TEXCOORD(65536, 0);
nuclear@15 97 for(i=0; i<4; i++) COLOR(0, 0, 65536);
nuclear@13 98
nuclear@12 99 /* +X */
nuclear@12 100 VERTEX(v[1][0], v[1][1], v[1][2]);
nuclear@12 101 VERTEX(v[5][0], v[5][1], v[5][2]);
nuclear@12 102 VERTEX(v[6][0], v[6][1], v[6][2]);
nuclear@12 103 VERTEX(v[2][0], v[2][1], v[2][2]);
nuclear@15 104 TEXCOORD(0, 0);
nuclear@15 105 TEXCOORD(0, 65536);
nuclear@15 106 TEXCOORD(65536, 65536);
nuclear@15 107 TEXCOORD(65536, 0);
nuclear@15 108 for(i=0; i<4; i++) COLOR(65536, 0, 0);
nuclear@13 109
nuclear@12 110 /* -X */
nuclear@12 111 VERTEX(v[3][0], v[3][1], v[3][2]);
nuclear@12 112 VERTEX(v[7][0], v[7][1], v[7][2]);
nuclear@12 113 VERTEX(v[4][0], v[4][1], v[4][2]);
nuclear@12 114 VERTEX(v[0][0], v[0][1], v[0][2]);
nuclear@15 115 TEXCOORD(0, 0);
nuclear@15 116 TEXCOORD(0, 65536);
nuclear@15 117 TEXCOORD(65536, 65536);
nuclear@15 118 TEXCOORD(65536, 0);
nuclear@15 119 for(i=0; i<4; i++) COLOR(0, 65536, 65536);
nuclear@12 120
nuclear@12 121 return 0;
nuclear@12 122 }