openTRI 0.1
triTypes.h
1/*
2 * triTypes.h: Header for common datatypes throughout the triEngine
3 * This file is part of the "tri Engine".
4 *
5 * Copyright (C) 2007 tri
6 * Copyright (C) 2007 Alexander Berl 'Raphael' <raphael@fx-world.org>
7 * Copyright (C) 2007 David Perry 'InsertWittyName' <tias_dp@hotmail.com>
8 * Copyright (C) 2007 Tomas Jakobsson 'Tomaz'
9 *
10 * $Id: $
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27
28#ifndef __TRITYPES_H__
29#define __TRITYPES_H__
30
31#ifdef _DEBUG
32#ifndef DEBUG
33#define DEBUG
34#endif // DEBUG
35#endif // _DEBUG
36#ifdef DEBUG
37#ifndef _DEBUG
38#define _DEBUG
39#endif // _DEBUG
40#endif // DEBUG
41
42#include <pspgu.h>
43
44#define TRUE 1
45#define FALSE 0
46
47#define ALIGN16 __attribute__((aligned(16)))
48
49typedef void triVoid;
50typedef char triChar;
51typedef unsigned char triUChar;
52typedef signed int triSInt; // sizeof(int) is platform specific, so we might want to have that for optimal code parts
53typedef unsigned int triUInt;
54
55typedef signed long long triS64;
56typedef unsigned long long triU64;
57typedef signed long triS32;
58typedef unsigned long triU32;
59typedef signed short triS16;
60typedef unsigned short triU16;
61typedef signed char triS8;
62typedef unsigned char triU8;
63typedef unsigned char triBool;
64typedef float triFloat;
65
66// For now triDouble isn't quaranteed to be 64bit, but is platform dependant -> PSP has no 64bit FPU, so we avoid that
67#ifndef __PSP__
68typedef double triDouble;
69#else
70typedef float triDouble; // FIXME: portability issue -> double should be expected to be 64bit
71#endif
72
73typedef float triF32; // Workaround: Define size guaranted floats
74typedef double triF64;
75
76
84typedef struct triVec2
85{
86 triFloat x, y;
87} triVec2, triVec2f; // Untyped vectors are always supposed to be float types
88
89
93typedef struct triVec2S32
94{
95 triS32 x, y; // Sizes should be the same as triVec*f, hence S32 instead of platform specific SInt
97
98
102typedef struct triVec2U32
103{
104 triU32 x, y;
106
107
111typedef struct triVec2S16
112{
113 triS16 x, y;
115
116
120typedef struct triVec2U16
121{
122 triU16 x, y;
124
125
126
130typedef struct triVec2S8
131{
132 triS8 x, y;
134
135
139typedef struct triVec2U8
140{
141 triU8 x, y;
143
144
145 // End triVec2
146
147
155typedef struct triVec3
156{
157 triFloat x, y, z;
159
160
164typedef struct triVec3S32
165{
166 triS32 x, y, z;
168
169
173typedef struct triVec3U32
174{
175 triU32 x, y, z;
177
178
182typedef struct triVec3S16
183{
184 triS16 x, y, z;
186
187
191typedef struct triVec3U16
192{
193 triU16 x, y, z;
195
196
197
201typedef struct triVec3S8
202{
203 triS8 x, y, z;
205
206
210typedef struct triVec3U8
211{
212 triU8 x, y, z;
214
215
216 // End triVec3
217
218
227typedef struct triVec4
228{
229 triFloat x, y, z, w;
230} triVec4 ALIGN16, triVec4f ALIGN16, triQuat ALIGN16;
231
232
236typedef struct triVec4S32
237{
238 triS32 x, y, z, w;
239} triVec4S32, triVec4i ALIGN16, triQuati ALIGN16;
240
241
245typedef struct triVec4U32
246{
247 triU32 x, y, z, w;
249
250
251
255typedef struct triVec4S16
256{
257 triS16 x, y, z, w;
259
260
264typedef struct triVec4U16
265{
266 triU16 x, y, z, w;
268
269
270
274typedef struct triVec4S8
275{
276 triS8 x, y, z, w;
278
279
283typedef struct triVec4U8
284{
285 triU8 x, y, z, w;
287
288
289
290 // End triVec4
291
292
300typedef struct triColor3
301{
302 triFloat r, g, b;
304
305
309typedef struct triColor3i
310{
311 triS32 r, g, b;
313
314
318typedef struct triColor4
319{
320 triFloat r, g, b, a;
321} triColor4 ALIGN16, triColor4f ALIGN16;
322
323
327typedef struct triColor4i
328{
329 triS32 r, g, b, a;
330} triColor4i ALIGN16;
331
332
333
337typedef struct triColor8880
338{
339 triU8 r, g, b;
341
342
343
347typedef union triColor8888
348{
349 struct
350 {
351 triU8 r, g, b, a;
352 };
353 triU32 color; // For fast r,g,b,a -> color conversion
355
356
357
361typedef union triColor4444
362{
363 struct
364 {
365 triU16 r:4, g:4, b:4, a:4;
366 };
367 triU16 color; // For fast r,g,b,a -> color conversion
369
370
371
375typedef union triColor5551
376{
377 struct
378 {
379 triU16 r:5, g:5, b:5, a:1;
380 };
381 triU16 color; // For fast r,g,b,a -> color conversion
383
384
385
389typedef union triColor5650
390{
391 struct
392 {
393 triU16 r:5, g:6, b:5;
394 };
395 triU16 color; // For fast r,g,b,a -> color conversion
397
398
399 // End triColor
400
401
402
410typedef union triMat3
411{
412 struct
413 {
414 triVec3f x, y, z;
415 };
416 triFloat m[9];
417 triFloat md[3][3];
419
420
421
425typedef union triMat4
426{
427 struct
428 {
429 triVec4f x, y, z, w;
430 };
431 triFloat m[16];
432 triFloat md[4][4];
433} triMat4 ALIGN16, triMat4f ALIGN16;
434
435
436 // End triMat
437
438
439
440
446#define TRI_VERTC_FORMAT (GU_COLOR_8888|GU_VERTEX_32BITF)
450typedef struct triVertC
451{
452 triU32 color;
453 triFloat x, y, z;
454} triVertC, triVertCf; // 16 bytes
455
456
457#define TRI_VERTCN_FORMAT (GU_NORMAL_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF)
461typedef struct triVertCN
462{
463 triU32 color;
464 triFloat nx, ny, nz;
465 triFloat x, y, z;
466} triVertCN, triVertCNf; // 28 bytes
467
468
469#define TRI_VERTUV_FORMAT (GU_TEXTURE_32BITF|GU_VERTEX_32BITF)
473typedef struct triVertUV
474{
475 triFloat u, v;
476 triFloat x, y, z;
477} triVertUV, triVertUVf; // 20 bytes
478
479
480#define TRI_VERTUVC_FORMAT (GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF)
484typedef struct triVertUVC
485{
486 triFloat u, v;
487 triU32 color;
488 triFloat x, y, z;
489} triVertUVC, triVertUVCf; // 24 bytes
490
491
492
493#define TRI_VERTUVN_FORMAT (GU_NORMAL_32BITF|GU_TEXTURE_32BITF|GU_VERTEX_32BITF)
497typedef struct triVertUVN
498{
499 triFloat u, v;
500 triFloat nx, ny, nz;
501 triFloat x, y, z;
502} triVertUVN, triVertUVNf; // 32 bytes
503
504
505#define TRI_VERTUVCN_FORMAT (GU_NORMAL_32BITF|GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF)
509typedef struct triVertUVCN
510{
511 triFloat u, v;
512 triU32 color;
513 triFloat nx, ny, nz;
514 triFloat x, y, z;
516
517
518
519
520#define TRI_VERTFASTUV_FORMAT (GU_TEXTURE_8BIT|GU_VERTEX_16BIT)
524typedef struct triVertFastUV
525{
526 triU8 u, v;
527 triS16 x, y, z;
528} triVertFastUV; // 2 + 6 = 8 bytes
529
530
531#define TRI_VERTFASTUVF_FORMAT (GU_TEXTURE_8BIT|GU_VERTEX_32BITF)
535typedef struct triVertFastUVf
536{
537 triU16 u, v;
538 triFloat x, y, z;
539} triVertFastUVf; // 4 + 12 = 16 bytes
540
541
542#define TRI_VERTFASTUVC_FORMAT (GU_TEXTURE_8BIT|GU_COLOR_5650|GU_VERTEX_16BIT)
546typedef struct triVertFastUVC
547{
548 triU8 u, v;
549 triU16 color;
550 triS16 x, y, z;
551} triVertFastUVC; // 2 + 2 + 6 = 10 bytes
552
553
554#define TRI_VERTFASTUVCF_FORMAT (GU_TEXTURE_8BIT|GU_COLOR_4444|GU_VERTEX_32BITF)
558typedef struct triVertFastUVCf
559{
560 triU8 u, v;
561 triU16 color;
562 triFloat x, y, z;
563} triVertFastUVCf; // 2 + 2 + 12 = 16 bytes
564
565
566#define TRI_VERTFASTUVN_FORMAT (GU_NORMAL_8BIT|GU_TEXTURE_8BIT|GU_VERTEX_16BIT)
570typedef struct triVertFastUVN
571{
572 triU8 u, v;
573 triS8 nx, ny, nz;
574 triS16 x, y, z;
575} triVertFastUVN; // 2 + 3 (+ 1) + 6 = 12 bytes
576
577
578#define TRI_VERTFASTUVNF_FORMAT (GU_NORMAL_16BIT|GU_TEXTURE_8BIT|GU_VERTEX_32BITF)
582typedef struct triVertFastUVNf
583{
584 triU8 u, v;
585 triS16 nx, ny, nz;
586 triFloat x, y, z;
587} triVertFastUVNf; // 2 + 6 + 12 = 20 bytes
588
589
590#define TRI_VERTFASTUVCN_FORMAT (GU_NORMAL_8BIT|GU_TEXTURE_8BIT|GU_COLOR_5650|GU_VERTEX_16BIT)
594typedef struct triVertFastUVCN
595{
596 triU8 u, v;
597 triU16 color;
598 triS8 nx, ny, nz;
599 triS16 x, y, z;
600} triVertFastUVCN; // 2 + 2 + 3 (+ 1) + 6 = 14 bytes
601
602
603#define TRI_VERTFASTUVCNF_FORMAT (GU_NORMAL_8BIT|GU_TEXTURE_8BIT|GU_COLOR_5650|GU_VERTEX_32BITF)
607typedef struct triVertFastUVCNf
608{
609 triU8 u, v;
610 triU16 color;
611 triS8 nx, ny, nz;
612 triFloat x, y, z;
613} triVertFastUVCNf; // 2 + 2 + 3 (+ 1) + 12 = 20 bytes
614
615 // End triVert
616
617#endif // __TRITYPES_H__
struct triColor3 triColor3
RGB float color (96bit)
struct triColor3i triColor3i
RGB int color (96bit)
union triColor5650 triColor5650
RGBA5650 color (16bit)
union triColor8888 triColor4b
RGBA8888 color (32bit)
union triColor4444 triColor4444
RGBA4444 color (16bit)
struct triColor8880 triColor3b
RGBA8880 color (24bit)
union triColor5551 triColor5551
RGBA5551 color (16bit)
union triMat3 triMat3
3D (3x3) Matrix
struct triVec2S16 triVec2S16
2D signed short Vector
struct triVec2U8 triVec2U8
2D unsigned char Vector
struct triVec2 triVec2
2D float Vector
struct triVec2S8 triVec2S8
2D signed char Vector
struct triVec2S32 triVec2S32
2D signed int Vector
struct triVec2U16 triVec2U16
2D unsigned short Vector
struct triVec2U32 triVec2U32
2D unsigned int Vector
struct triVec3S16 triVec3S16
3D signed short Vector
struct triVec3U32 triVec3U32
3D unsigned int Vector
struct triVec3S32 triVec3S32
3D signed int Vector
struct triVec3S8 triVec3S8
3D signed char Vector
struct triVec3U16 triVec3U16
3D unsigned short Vector
struct triVec3 triVec3
3D float Vector
struct triVec3U8 triVec3U8
3D unsigned char Vector
struct triVec4U8 triVec4U8
4D unsigned char Vector
struct triVec4S8 triVec4S8
4D signed char Vector
struct triVec4U32 triVec4U32
4D unsigned int Vector
struct triVec4S16 triVec4S16
4D signed short Vector
struct triVec4S32 triVec4S32
4D signed int Vector (quaternion)
struct triVec4U16 triVec4U16
4D unsigned short Vector
struct triVertFastUVNf triVertFastUVNf
Vertex with texture coordinates and normale, optimized.
struct triVertC triVertC
Vertex with color.
struct triVertFastUVCNf triVertFastUVCNf
Vertex with texture coordinates, color and normale, optimized.
struct triVertUVC triVertUVC
Vertex with texture coordinates and color.
struct triVertFastUV triVertFastUV
Vertex with texture coordinates and color, optimized.
struct triVertCN triVertCN
Vertex with color and normale.
struct triVertFastUVN triVertFastUVN
Vertex with texture coordinates and normale, optimized.
struct triVertUV triVertUV
Vertex with texture coordinates.
struct triVertFastUVCf triVertFastUVCf
Vertex with texture coordinates and color, optimized.
struct triVertFastUVC triVertFastUVC
Vertex with texture coordinates and color, optimized.
struct triVertFastUVf triVertFastUVf
Vertex with texture coordinates and color, optimized.
struct triVertFastUVCN triVertFastUVCN
Vertex with texture coordinates, color and normale, optimized.
struct triVertUVCN triVertUVCN
Vertex with texture coordinates, color and normale.
struct triVertUVN triVertUVN
Vertex with texture coordinates and normale.
RGB float color (96bit)
Definition triTypes.h:301
RGB int color (96bit)
Definition triTypes.h:310
RGBA float color (128bit)
Definition triTypes.h:319
RGBA int color (128bit)
Definition triTypes.h:328
RGBA8880 color (24bit)
Definition triTypes.h:338
2D signed short Vector
Definition triTypes.h:112
2D signed int Vector
Definition triTypes.h:94
2D signed char Vector
Definition triTypes.h:131
2D unsigned short Vector
Definition triTypes.h:121
2D unsigned int Vector
Definition triTypes.h:103
2D unsigned char Vector
Definition triTypes.h:140
2D float Vector
Definition triTypes.h:85
3D signed short Vector
Definition triTypes.h:183
3D signed int Vector
Definition triTypes.h:165
3D signed char Vector
Definition triTypes.h:202
3D unsigned short Vector
Definition triTypes.h:192
3D unsigned int Vector
Definition triTypes.h:174
3D unsigned char Vector
Definition triTypes.h:211
3D float Vector
Definition triTypes.h:156
4D signed short Vector
Definition triTypes.h:256
4D signed int Vector (quaternion)
Definition triTypes.h:237
4D signed char Vector
Definition triTypes.h:275
4D unsigned short Vector
Definition triTypes.h:265
4D unsigned int Vector
Definition triTypes.h:246
4D unsigned char Vector
Definition triTypes.h:284
4D float Vector (quaternion)
Definition triTypes.h:228
Vertex with color and normale.
Definition triTypes.h:462
Vertex with color.
Definition triTypes.h:451
Vertex with texture coordinates, color and normale, optimized.
Definition triTypes.h:595
Vertex with texture coordinates, color and normale, optimized.
Definition triTypes.h:608
Vertex with texture coordinates and color, optimized.
Definition triTypes.h:547
Vertex with texture coordinates and color, optimized.
Definition triTypes.h:559
Vertex with texture coordinates and normale, optimized.
Definition triTypes.h:571
Vertex with texture coordinates and normale, optimized.
Definition triTypes.h:583
Vertex with texture coordinates and color, optimized.
Definition triTypes.h:525
Vertex with texture coordinates and color, optimized.
Definition triTypes.h:536
Vertex with texture coordinates, color and normale.
Definition triTypes.h:510
Vertex with texture coordinates and color.
Definition triTypes.h:485
Vertex with texture coordinates and normale.
Definition triTypes.h:498
Vertex with texture coordinates.
Definition triTypes.h:474
RGBA4444 color (16bit)
Definition triTypes.h:362
RGBA5551 color (16bit)
Definition triTypes.h:376
RGBA5650 color (16bit)
Definition triTypes.h:390
RGBA8888 color (32bit)
Definition triTypes.h:348
3D (3x3) Matrix
Definition triTypes.h:411
4D (4x4) Matrix
Definition triTypes.h:426