00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00037 #ifndef VIDEOGL_ARM9_INCLUDE
00038 #define VIDEOGL_ARM9_INCLUDE
00039
00040
00041 #include "nds/dma.h"
00042 #include "nds/ndstypes.h"
00043 #include "nds/arm9/video.h"
00044 #include "nds/arm9/cache.h"
00045 #include "nds/arm9/trig_lut.h"
00046 #include "nds/arm9/math.h"
00047 #include "nds/dynamicArray.h"
00048
00049
00050 #define GL_STATIC_INL static inline
00051
00052 #ifndef ARM9
00053 #error 3D hardware is only available from the ARM9
00054 #endif
00055
00056
00057
00058
00059
00060
00061
00062
00063 #define LUT_SIZE (1<<15)
00064 #define LUT_MASK ((1<<15) - 1)
00065
00067
00069
00070 #define MAX_TEXTURES 2048 //this should be enough ! but feel free to change
00071
00072
00074
00076
00077 typedef uint16 fixed12d3;
00080 #define int_to_12d3(n) ((n) << 3)
00081 #define float_to_12d3(n) ((fixed12d3)((n) * (1 << 3)))
00082 #define GL_MAX_DEPTH 0x7FFF
00084
00085
00086 #define inttof32(n) ((n) << 12)
00087 #define f32toint(n) ((n) >> 12)
00088 #define floattof32(n) ((int32)((n) * (1 << 12)))
00089 #define f32tofloat(n) (((float)(n)) / (float)(1<<12))
00091 typedef short t16;
00092 #define f32tot16(n) ((t16)(n >> 8))
00093 #define inttot16(n) ((n) << 4)
00094 #define t16toint(n) ((n) >> 4)
00095 #define floattot16(n) ((t16)((n) * (1 << 4)))
00096 #define TEXTURE_PACK(u,v) (((u) & 0xFFFF) | ((v) << 16))
00098 typedef short int v16;
00099 #define inttov16(n) ((n) << 12)
00100 #define f32tov16(n) (n)
00101 #define v16toint(n) ((n) >> 12)
00102 #define floattov16(n) ((v16)((n) * (1 << 12)))
00103 #define VERTEX_PACK(x,y) (((x) & 0xFFFF) | ((y) << 16))
00105 typedef short int v10;
00106 #define inttov10(n) ((n) << 9)
00107 #define f32tov10(n) ((v10)(n >> 3))
00108 #define v10toint(n) ((n) >> 9)
00109 #define floattov10(n) ((n>.998) ? 0x1FF : ((v10)((n)*(1<<9))))
00110 #define NORMAL_PACK(x,y,z) (((x) & 0x3FF) | (((y) & 0x3FF) << 10) | ((z) << 20))
00112
00113
00114 typedef unsigned short rgb;
00117 typedef struct m3x3 {
00118 int32 m[9];
00119 } m3x3;
00120
00122 typedef struct m4x4 {
00123 int32 m[16];
00124 } m4x4;
00125
00127 typedef struct m4x3 {
00128 int32 m[12];
00129 } m4x3;
00130
00132 typedef struct GLvector {
00133 int32 x, y, z;
00134 } GLvector;
00135
00137
00138 #define GL_FALSE 0
00139 #define GL_TRUE 1
00140
00144 typedef enum {
00145 GL_TRIANGLES = 0,
00146 GL_QUADS = 1,
00147 GL_TRIANGLE_STRIP = 2,
00148 GL_QUAD_STRIP = 3,
00149 GL_TRIANGLE = 0,
00150 GL_QUAD = 1
00151 } GL_GLBEGIN_ENUM;
00152
00156 typedef enum {
00157 GL_PROJECTION = 0,
00158 GL_POSITION = 1,
00159 GL_MODELVIEW = 2,
00160 GL_TEXTURE = 3
00161 } GL_MATRIX_MODE_ENUM;
00162
00166 typedef enum {
00167 GL_AMBIENT = 0x01,
00168 GL_DIFFUSE = 0x02,
00169 GL_AMBIENT_AND_DIFFUSE = 0x03,
00170 GL_SPECULAR = 0x04,
00171 GL_SHININESS = 0x08,
00172 GL_EMISSION = 0x10
00173 } GL_MATERIALS_ENUM;
00174
00178 enum GL_POLY_FORMAT_ENUM {
00179 POLY_FORMAT_LIGHT0 = (1<<0),
00180 POLY_FORMAT_LIGHT1 = (1<<1),
00181 POLY_FORMAT_LIGHT2 = (1<<2),
00182 POLY_FORMAT_LIGHT3 = (1<<3),
00183 POLY_MODULATION = (0<<4),
00184 POLY_DECAL = (1<<4),
00185 POLY_TOON_HIGHLIGHT = (2<<4),
00186 POLY_SHADOW = (3<<4),
00187 POLY_CULL_FRONT = (1<<6),
00188 POLY_CULL_BACK = (2<<6),
00189 POLY_CULL_NONE = (3<<6),
00190 POLY_FOG = (1<<15)
00191 };
00192
00195 enum GL_TEXTURE_SIZE_ENUM {
00196 TEXTURE_SIZE_8 = 0,
00197 TEXTURE_SIZE_16 = 1,
00198 TEXTURE_SIZE_32 = 2,
00199 TEXTURE_SIZE_64 = 3,
00200 TEXTURE_SIZE_128 = 4,
00201 TEXTURE_SIZE_256 = 5,
00202 TEXTURE_SIZE_512 = 6,
00203 TEXTURE_SIZE_1024 = 7
00204 };
00205
00209 typedef enum {
00210 GL_TEXTURE_WRAP_S = (1 << 16),
00211 GL_TEXTURE_WRAP_T = (1 << 17),
00212 GL_TEXTURE_FLIP_S = (1 << 18),
00213 GL_TEXTURE_FLIP_T = (1 << 19),
00214 GL_TEXTURE_COLOR0_TRANSPARENT = (1<<29),
00215 TEXGEN_OFF = (0<<30),
00216 TEXGEN_TEXCOORD = (1<<30),
00217 TEXGEN_NORMAL = (2<<30),
00218 TEXGEN_POSITION = (3<<30)
00219 }GL_TEXTURE_PARAM_ENUM;
00220
00224 typedef enum {
00225 GL_RGB32_A3 = 1,
00226 GL_RGB4 = 2,
00227 GL_RGB16 = 3,
00228 GL_RGB256 = 4,
00229 GL_COMPRESSED = 5,
00230 GL_RGB8_A5 = 6,
00231 GL_RGBA = 7,
00232 GL_RGB = 8
00233 } GL_TEXTURE_TYPE_ENUM;
00234
00238 enum DISP3DCNT_ENUM {
00239 GL_TEXTURE_2D = (1<<0),
00240 GL_TOON_HIGHLIGHT = (1<<1),
00241 GL_ALPHA_TEST = (1<<2),
00242 GL_BLEND = (1<<3),
00243 GL_ANTIALIAS = (1<<4),
00244 GL_OUTLINE = (1<<5),
00245 GL_FOG_ONLY_ALPHA = (1<<6),
00246 GL_FOG = (1<<7),
00247 GL_COLOR_UNDERFLOW = (1<<12),
00248 GL_POLY_OVERFLOW = (1<<13),
00249 GL_CLEAR_BMP = (1<<14)
00250 };
00251
00255 typedef enum {
00256 GL_GET_VERTEX_RAM_COUNT,
00257 GL_GET_POLYGON_RAM_COUNT,
00258 GL_GET_MATRIX_VECTOR,
00259 GL_GET_MATRIX_POSITION,
00260 GL_GET_MATRIX_PROJECTION,
00261 GL_GET_MATRIX_CLIP,
00262 GL_GET_TEXTURE_WIDTH,
00263 GL_GET_TEXTURE_HEIGHT
00264 } GL_GET_ENUM;
00265
00266
00270 enum GLFLUSH_ENUM {
00271 GL_TRANS_MANUALSORT = (1<<0),
00272 GL_WBUFFERING = (1<<1)
00273 };
00274
00275
00276
00277
00278
00279
00280
00281
00282 typedef struct gl_hidden_globals {
00283 GL_MATRIX_MODE_ENUM matrixMode;
00284
00285
00286 uint32 clearColor;
00287
00288
00289 uint32 textures[MAX_TEXTURES];
00290 DynamicArray texturePtrs;
00291 uint32 activeTexture;
00292 uint32* nextBlock;
00293 uint32 nextPBlock;
00294 int nameCount;
00295
00296 } gl_hidden_globals;
00297
00298
00299 extern gl_hidden_globals glGlobalData;
00300
00301
00302 static gl_hidden_globals* glGlob = &glGlobalData;
00303
00304
00305
00306
00307
00308 #define FIFO_COMMAND_PACK(c1,c2,c3,c4) (((c4) << 24) | ((c3) << 16) | ((c2) << 8) | (c1))
00310 #define REG2ID(r) (u8)( ( ((u32)(&(r)))-0x04000400 ) >> 2 )
00312 #define FIFO_NOP REG2ID(GFX_FIFO)
00313 #define FIFO_STATUS REG2ID(GFX_STATUS)
00314 #define FIFO_COLOR REG2ID(GFX_COLOR)
00316 #define FIFO_VERTEX16 REG2ID(GFX_VERTEX16)
00317 #define FIFO_TEX_COORD REG2ID(GFX_TEX_COORD)
00318 #define FIFO_TEX_FORMAT REG2ID(GFX_TEX_FORMAT)
00319 #define FIFO_PAL_FORMAT REG2ID(GFX_PAL_FORMAT)
00321 #define FIFO_CLEAR_COLOR REG2ID(GFX_CLEAR_COLOR)
00322 #define FIFO_CLEAR_DEPTH REG2ID(GFX_CLEAR_DEPTH)
00324 #define FIFO_LIGHT_VECTOR REG2ID(GFX_LIGHT_VECTOR)
00325 #define FIFO_LIGHT_COLOR REG2ID(GFX_LIGHT_COLOR)
00326 #define FIFO_NORMAL REG2ID(GFX_NORMAL)
00328 #define FIFO_DIFFUSE_AMBIENT REG2ID(GFX_DIFFUSE_AMBIENT)
00329 #define FIFO_SPECULAR_EMISSION REG2ID(GFX_SPECULAR_EMISSION)
00330 #define FIFO_SHININESS REG2ID(GFX_SHININESS)
00332 #define FIFO_POLY_FORMAT REG2ID(GFX_POLY_FORMAT)
00334 #define FIFO_BEGIN REG2ID(GFX_BEGIN)
00335 #define FIFO_END REG2ID(GFX_END)
00336 #define FIFO_FLUSH REG2ID(GFX_FLUSH)
00337 #define FIFO_VIEWPORT REG2ID(GFX_VIEWPORT)
00340 #ifdef __cplusplus
00341 extern "C" {
00342 #endif
00343
00349 void glRotatef32i(int angle, int32 x, int32 y, int32 z);
00350
00360 int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, int param, const uint8* texture);
00361
00366 void glTexLoadPal(const u16* pal, u16 count, u32 addr );
00367
00372 int gluTexLoadPal(const u16* pal, u16 count, uint8 format);
00373
00380 void glTexParameter( uint8 sizeX, uint8 sizeY,
00381 const uint32* addr,
00382 GL_TEXTURE_TYPE_ENUM mode,
00383 GL_TEXTURE_PARAM_ENUM param) ;
00384
00386 u32 glGetTexParameter(void);
00387
00390 void* glGetTexturePointer( int name);
00391
00395 void glBindTexture(int target, int name);
00396
00398 void glColorTable(uint8 format, uint32 addr);
00399
00403 int glGenTextures(int n, int *names);
00404
00406 void glResetTextures(void);
00407
00412 void glTexCoord2f32(int32 u, int32 v);
00413
00417 void glMaterialf(GL_MATERIALS_ENUM mode, rgb color);
00418
00419
00420 void glInit_C(void);
00421
00422
00423 gl_hidden_globals* glGetGlobals();
00424
00425
00426 #ifdef __cplusplus
00427 }
00428 #endif
00429
00430
00431 GL_STATIC_INL
00435 uint32 POLY_ALPHA(int n) { return (uint32)((n) << 16); };
00436
00437 GL_STATIC_INL
00441 uint32 POLY_ID(int n) { return (uint32)((n)<<24); };
00442
00443 GL_STATIC_INL
00447 void glBegin(GL_GLBEGIN_ENUM mode) { GFX_BEGIN = mode; }
00448
00449 GL_STATIC_INL
00452 void glEnd(void) { GFX_END = 0; }
00453
00454 GL_STATIC_INL
00459 void glClearDepth(fixed12d3 depth) { GFX_CLEAR_DEPTH = depth; }
00460
00461 GL_STATIC_INL
00467 void glColor3b(uint8 red, uint8 green, uint8 blue) { GFX_COLOR = (vuint32)RGB15(red>>3, green>>3, blue>>3); }
00468
00469 GL_STATIC_INL
00473 void glColor(rgb color) { GFX_COLOR = (vuint32)color; }
00474
00475 GL_STATIC_INL
00481 void glVertex3v16(v16 x, v16 y, v16 z) {
00482 GFX_VERTEX16 = (y << 16) | (x & 0xFFFF);
00483 GFX_VERTEX16 = ((uint32)(uint16)z);
00484 }
00485
00486 GL_STATIC_INL
00492 void glTexCoord2t16(t16 u, t16 v) { GFX_TEX_COORD = TEXTURE_PACK(u,v); }
00493
00494 GL_STATIC_INL
00498 void glPushMatrix(void) { MATRIX_PUSH = 0; }
00499
00500 GL_STATIC_INL
00505 void glPopMatrix(int32 num) { MATRIX_POP = num; }
00506
00507 GL_STATIC_INL
00512 void glRestoreMatrix(int32 index) { MATRIX_RESTORE = index; }
00513
00514 GL_STATIC_INL
00519 void glStoreMatrix(int32 index) { MATRIX_STORE = index; }
00520
00521 GL_STATIC_INL
00526 void glScalev(const GLvector* v) {
00527 MATRIX_SCALE = v->x;
00528 MATRIX_SCALE = v->y;
00529 MATRIX_SCALE = v->z;
00530 }
00531
00532 GL_STATIC_INL
00537 void glTranslatev(const GLvector* v) {
00538 MATRIX_TRANSLATE = v->x;
00539 MATRIX_TRANSLATE = v->y;
00540 MATRIX_TRANSLATE = v->z;
00541 }
00542
00543 GL_STATIC_INL
00550 void glTranslate3f32(int32 x, int32 y, int32 z) {
00551 MATRIX_TRANSLATE = x;
00552 MATRIX_TRANSLATE = y;
00553 MATRIX_TRANSLATE = z;
00554 }
00555
00556 GL_STATIC_INL
00561 void glScalef32(int32 factor) {
00562 MATRIX_SCALE = factor;
00563 MATRIX_SCALE = factor;
00564 MATRIX_SCALE = factor;
00565 }
00566
00567 GL_STATIC_INL
00576 void glLight(int id, rgb color, v10 x, v10 y, v10 z) {
00577 id = (id & 3) << 30;
00578 GFX_LIGHT_VECTOR = id | ((z & 0x3FF) << 20) | ((y & 0x3FF) << 10) | (x & 0x3FF);
00579 GFX_LIGHT_COLOR = id | color;
00580 }
00581
00582 GL_STATIC_INL
00588 void glNormal(uint32 normal) { GFX_NORMAL = normal; }
00589
00590 GL_STATIC_INL
00593 void glLoadIdentity(void) { MATRIX_IDENTITY = 0; }
00594
00595 GL_STATIC_INL
00600 void glMatrixMode(GL_MATRIX_MODE_ENUM mode) { MATRIX_CONTROL = mode; }
00601
00602 GL_STATIC_INL
00610 void glViewport(uint8 x1, uint8 y1, uint8 x2, uint8 y2) { GFX_VIEWPORT = (x1) + (y1 << 8) + (x2 << 16) + (y2 << 24); }
00611
00612 GL_STATIC_INL
00617 void glFlush(uint32 mode) { GFX_FLUSH = mode; }
00618
00619 GL_STATIC_INL
00622 void glMaterialShinyness(void) {
00623 uint32 shiny32[128/4];
00624 uint8 *shiny8 = (uint8*)shiny32;
00625
00626 int i;
00627
00628 for (i = 0; i < 128 * 2; i += 2)
00629 shiny8[i>>1] = i;
00630
00631 for (i = 0; i < 128 / 4; i++)
00632 GFX_SHININESS = shiny32[i];
00633 }
00634
00635 GL_STATIC_INL
00642 void glCallList(const u32* list) {
00643 u32 count = *list++;
00644
00645
00646 DC_FlushRange(list, count*4);
00647
00648
00649
00650 while((DMA_CR(0) & DMA_BUSY)||(DMA_CR(1) & DMA_BUSY)||(DMA_CR(2) & DMA_BUSY)||(DMA_CR(3) & DMA_BUSY));
00651
00652
00653 DMA_SRC(0) = (uint32)list;
00654 DMA_DEST(0) = 0x4000400;
00655 DMA_CR(0) = DMA_FIFO | count;
00656 while(DMA_CR(0) & DMA_BUSY);
00657 }
00658 GL_STATIC_INL
00663 void glPolyFmt(uint32 params) { GFX_POLY_FORMAT = params; }
00664
00665 GL_STATIC_INL
00669 void glEnable(int bits) { GFX_CONTROL |= bits; }
00670
00671 GL_STATIC_INL
00675 void glDisable(int bits) { GFX_CONTROL &= ~bits; }
00676
00677 GL_STATIC_INL
00681 void glLoadMatrix4x4(const m4x4 *m) {
00682 MATRIX_LOAD4x4 = m->m[0];
00683 MATRIX_LOAD4x4 = m->m[1];
00684 MATRIX_LOAD4x4 = m->m[2];
00685 MATRIX_LOAD4x4 = m->m[3];
00686
00687 MATRIX_LOAD4x4 = m->m[4];
00688 MATRIX_LOAD4x4 = m->m[5];
00689 MATRIX_LOAD4x4 = m->m[6];
00690 MATRIX_LOAD4x4 = m->m[7];
00691
00692 MATRIX_LOAD4x4 = m->m[8];
00693 MATRIX_LOAD4x4 = m->m[9];
00694 MATRIX_LOAD4x4 = m->m[10];
00695 MATRIX_LOAD4x4 = m->m[11];
00696
00697 MATRIX_LOAD4x4 = m->m[12];
00698 MATRIX_LOAD4x4 = m->m[13];
00699 MATRIX_LOAD4x4 = m->m[14];
00700 MATRIX_LOAD4x4 = m->m[15];
00701 }
00702
00703 GL_STATIC_INL
00707 void glLoadMatrix4x3(const m4x3 * m) {
00708 MATRIX_LOAD4x3 = m->m[0];
00709 MATRIX_LOAD4x3 = m->m[1];
00710 MATRIX_LOAD4x3 = m->m[2];
00711 MATRIX_LOAD4x3 = m->m[3];
00712
00713 MATRIX_LOAD4x3 = m->m[4];
00714 MATRIX_LOAD4x3 = m->m[5];
00715 MATRIX_LOAD4x3 = m->m[6];
00716 MATRIX_LOAD4x3 = m->m[7];
00717
00718 MATRIX_LOAD4x3 = m->m[8];
00719 MATRIX_LOAD4x3 = m->m[9];
00720 MATRIX_LOAD4x3 = m->m[10];
00721 MATRIX_LOAD4x3 = m->m[11];
00722 }
00723 GL_STATIC_INL
00727 void glMultMatrix4x4(const m4x4 * m) {
00728 MATRIX_MULT4x4 = m->m[0];
00729 MATRIX_MULT4x4 = m->m[1];
00730 MATRIX_MULT4x4 = m->m[2];
00731 MATRIX_MULT4x4 = m->m[3];
00732
00733 MATRIX_MULT4x4 = m->m[4];
00734 MATRIX_MULT4x4 = m->m[5];
00735 MATRIX_MULT4x4 = m->m[6];
00736 MATRIX_MULT4x4 = m->m[7];
00737
00738 MATRIX_MULT4x4 = m->m[8];
00739 MATRIX_MULT4x4 = m->m[9];
00740 MATRIX_MULT4x4 = m->m[10];
00741 MATRIX_MULT4x4 = m->m[11];
00742
00743 MATRIX_MULT4x4 = m->m[12];
00744 MATRIX_MULT4x4 = m->m[13];
00745 MATRIX_MULT4x4 = m->m[14];
00746 MATRIX_MULT4x4 = m->m[15];
00747 }
00748
00749 GL_STATIC_INL
00753 void glMultMatrix4x3(const m4x3 * m) {
00754 MATRIX_MULT4x3 = m->m[0];
00755 MATRIX_MULT4x3 = m->m[1];
00756 MATRIX_MULT4x3 = m->m[2];
00757 MATRIX_MULT4x3 = m->m[3];
00758
00759 MATRIX_MULT4x3 = m->m[4];
00760 MATRIX_MULT4x3 = m->m[5];
00761 MATRIX_MULT4x3 = m->m[6];
00762 MATRIX_MULT4x3 = m->m[7];
00763
00764 MATRIX_MULT4x3 = m->m[8];
00765 MATRIX_MULT4x3 = m->m[9];
00766 MATRIX_MULT4x3 = m->m[10];
00767 MATRIX_MULT4x3 = m->m[11];
00768
00769 }
00770
00771 GL_STATIC_INL
00775 void glMultMatrix3x3(const m3x3 * m) {
00776 MATRIX_MULT3x3 = m->m[0];
00777 MATRIX_MULT3x3 = m->m[1];
00778 MATRIX_MULT3x3 = m->m[2];
00779
00780 MATRIX_MULT3x3 = m->m[3];
00781 MATRIX_MULT3x3 = m->m[4];
00782 MATRIX_MULT3x3 = m->m[5];
00783
00784 MATRIX_MULT3x3 = m->m[6];
00785 MATRIX_MULT3x3 = m->m[7];
00786 MATRIX_MULT3x3 = m->m[8];
00787 }
00788
00789 GL_STATIC_INL
00793 void glRotateXi(int angle) {
00794 int32 sine = sinLerp(angle);
00795 int32 cosine = cosLerp(angle);
00796
00797 MATRIX_MULT3x3 = inttof32(1);
00798 MATRIX_MULT3x3 = 0;
00799 MATRIX_MULT3x3 = 0;
00800
00801 MATRIX_MULT3x3 = 0;
00802 MATRIX_MULT3x3 = cosine;
00803 MATRIX_MULT3x3 = sine;
00804
00805 MATRIX_MULT3x3 = 0;
00806 MATRIX_MULT3x3 = -sine;
00807 MATRIX_MULT3x3 = cosine;
00808 }
00809
00810 GL_STATIC_INL
00814 void glRotateYi(int angle) {
00815 int32 sine = sinLerp(angle);
00816 int32 cosine = cosLerp(angle);
00817
00818 MATRIX_MULT3x3 = cosine;
00819 MATRIX_MULT3x3 = 0;
00820 MATRIX_MULT3x3 = -sine;
00821
00822 MATRIX_MULT3x3 = 0;
00823 MATRIX_MULT3x3 = inttof32(1);
00824 MATRIX_MULT3x3 = 0;
00825
00826 MATRIX_MULT3x3 = sine;
00827 MATRIX_MULT3x3 = 0;
00828 MATRIX_MULT3x3 = cosine;
00829 }
00830
00831 GL_STATIC_INL
00835 void glRotateZi(int angle) {
00836 int32 sine = sinLerp(angle);
00837 int32 cosine = cosLerp(angle);
00838
00839 MATRIX_MULT3x3 = cosine;
00840 MATRIX_MULT3x3 = sine;
00841 MATRIX_MULT3x3 = 0;
00842
00843 MATRIX_MULT3x3 = - sine;
00844 MATRIX_MULT3x3 = cosine;
00845 MATRIX_MULT3x3 = 0;
00846
00847 MATRIX_MULT3x3 = 0;
00848 MATRIX_MULT3x3 = 0;
00849 MATRIX_MULT3x3 = inttof32(1);
00850 }
00851
00852 GL_STATIC_INL
00861 void glOrthof32(int32 left, int32 right, int32 bottom, int32 top, int32 zNear, int32 zFar) {
00862 MATRIX_MULT4x4 = divf32(inttof32(2), right - left);
00863 MATRIX_MULT4x4 = 0;
00864 MATRIX_MULT4x4 = 0;
00865 MATRIX_MULT4x4 = 0;
00866
00867 MATRIX_MULT4x4 = 0;
00868 MATRIX_MULT4x4 = divf32(inttof32(2), top - bottom);
00869 MATRIX_MULT4x4 = 0;
00870 MATRIX_MULT4x4 = 0;
00871
00872 MATRIX_MULT4x4 = 0;
00873 MATRIX_MULT4x4 = 0;
00874 MATRIX_MULT4x4 = divf32(inttof32(-2), zFar - zNear);
00875 MATRIX_MULT4x4 = 0;
00876
00877 MATRIX_MULT4x4 = -divf32(right + left, right - left);
00878 MATRIX_MULT4x4 = -divf32(top + bottom, top - bottom);
00879 MATRIX_MULT4x4 = -divf32(zFar + zNear, zFar - zNear);
00880 MATRIX_MULT4x4 = floattof32(1.0F);
00881 }
00882 GL_STATIC_INL
00894 void gluLookAtf32(int32 eyex, int32 eyey, int32 eyez, int32 lookAtx, int32 lookAty, int32 lookAtz, int32 upx, int32 upy, int32 upz) {
00895 int32 side[3], forward[3], up[3], eye[3];
00896
00897 forward[0] = eyex - lookAtx;
00898 forward[1] = eyey - lookAty;
00899 forward[2] = eyez - lookAtz;
00900
00901 normalizef32(forward);
00902
00903 up[0] = upx;
00904 up[1] = upy;
00905 up[2] = upz;
00906 eye[0] = eyex;
00907 eye[1] = eyey;
00908 eye[2] = eyez;
00909
00910 crossf32(up, forward, side);
00911
00912 normalizef32(side);
00913
00914
00915 crossf32(forward, side, up);
00916
00917 glMatrixMode(GL_MODELVIEW);
00918
00919
00920
00921 MATRIX_MULT4x3 = side[0];
00922 MATRIX_MULT4x3 = up[0];
00923 MATRIX_MULT4x3 = forward[0];
00924
00925 MATRIX_MULT4x3 = side[1];
00926 MATRIX_MULT4x3 = up[1];
00927 MATRIX_MULT4x3 = forward[1];
00928
00929 MATRIX_MULT4x3 = side[2];
00930 MATRIX_MULT4x3 = up[2];
00931 MATRIX_MULT4x3 = forward[2];
00932
00933 MATRIX_MULT4x3 = -dotf32(eye,side);
00934 MATRIX_MULT4x3 = -dotf32(eye,up);
00935 MATRIX_MULT4x3 = -dotf32(eye,forward);
00936
00937 }
00938
00939 GL_STATIC_INL
00948 void glFrustumf32(int32 left, int32 right, int32 bottom, int32 top, int32 near, int32 far) {
00949
00950 MATRIX_MULT4x4 = divf32(2*near, right - left);
00951 MATRIX_MULT4x4 = 0;
00952 MATRIX_MULT4x4 = 0;
00953 MATRIX_MULT4x4 = 0;
00954
00955 MATRIX_MULT4x4 = 0;
00956 MATRIX_MULT4x4 = divf32(2*near, top - bottom);
00957 MATRIX_MULT4x4 = 0;
00958 MATRIX_MULT4x4 = 0;
00959
00960 MATRIX_MULT4x4 = divf32(right + left, right - left);
00961 MATRIX_MULT4x4 = divf32(top + bottom, top - bottom);
00962 MATRIX_MULT4x4 = -divf32(far + near, far - near);
00963 MATRIX_MULT4x4 = floattof32(-1.0F);
00964
00965 MATRIX_MULT4x4 = 0;
00966 MATRIX_MULT4x4 = 0;
00967 MATRIX_MULT4x4 = -divf32(2 * mulf32(far, near), far - near);
00968 MATRIX_MULT4x4 = 0;
00969
00970 }
00971 GL_STATIC_INL
00978 void gluPerspectivef32(int fovy, int32 aspect, int32 zNear, int32 zFar) {
00979 int32 xmin, xmax, ymin, ymax;
00980
00981 ymax = mulf32(zNear, tanLerp(fovy>>1));
00982
00983 ymin = -ymax;
00984 xmin = mulf32(ymin, aspect);
00985 xmax = mulf32(ymax, aspect);
00986
00987 glFrustumf32(xmin, xmax, ymin, ymax, zNear, zFar);
00988 }
00989 GL_STATIC_INL
00997 void gluPickMatrix(int x, int y, int width, int height, const int viewport[4]) {
00998 MATRIX_MULT4x4 = inttof32(viewport[2]) / width;
00999 MATRIX_MULT4x4 = 0;
01000 MATRIX_MULT4x4 = 0;
01001 MATRIX_MULT4x4 = 0;
01002 MATRIX_MULT4x4 = 0;
01003 MATRIX_MULT4x4 = inttof32(viewport[3]) / height;
01004 MATRIX_MULT4x4 = 0;
01005 MATRIX_MULT4x4 = 0;
01006 MATRIX_MULT4x4 = 0;
01007 MATRIX_MULT4x4 = 0;
01008 MATRIX_MULT4x4 = inttof32(1);
01009 MATRIX_MULT4x4 = 0;
01010 MATRIX_MULT4x4 = inttof32(viewport[2] + ((viewport[0] - x)<<1)) / width;
01011 MATRIX_MULT4x4 = inttof32(viewport[3] + ((viewport[1] - y)<<1)) / height;
01012 MATRIX_MULT4x4 = 0;
01013 MATRIX_MULT4x4 = inttof32(1);
01014 }
01015 GL_STATIC_INL
01018 void glResetMatrixStack(void) {
01019
01020 while(GFX_STATUS & BIT(14)){
01021 GFX_STATUS |= 1 << 15;
01022 }
01023
01024
01025 if((GFX_STATUS&(1<<13))!=0) {
01026 glMatrixMode(GL_PROJECTION);
01027 glPopMatrix(1);
01028 }
01029
01030
01031 glMatrixMode(GL_MODELVIEW);
01032 glPopMatrix((GFX_STATUS >> 8) & 0x1F);
01033
01034
01035 glMatrixMode(GL_MODELVIEW);
01036 glLoadIdentity();
01037 glMatrixMode(GL_PROJECTION);
01038 glLoadIdentity();
01039 glMatrixMode(GL_TEXTURE);
01040 glLoadIdentity();
01041 }
01042 GL_STATIC_INL
01047 void glSetOutlineColor(int id, rgb color) { GFX_EDGE_TABLE[id] = color; }
01048 GL_STATIC_INL
01052 void glSetToonTable(const uint16 *table) {
01053 int i;
01054 for(i = 0; i < 32; i++ )
01055 GFX_TOON_TABLE[i] = table[i];
01056 }
01057 GL_STATIC_INL
01063 void glSetToonTableRange(int start, int end, rgb color) {
01064 int i;
01065 for(i = start; i <= end; i++ )
01066 GFX_TOON_TABLE[i] = color;
01067 }
01068 GL_STATIC_INL
01075 void glGetFixed(const GL_GET_ENUM param, int32* f) {
01076 int i;
01077 switch (param) {
01078 case GL_GET_MATRIX_VECTOR:
01079 while(GFX_BUSY);
01080 for(i = 0; i < 9; i++) f[i] = MATRIX_READ_VECTOR[i];
01081 break;
01082 case GL_GET_MATRIX_CLIP:
01083 while(GFX_BUSY);
01084 for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i];
01085 break;
01086 case GL_GET_MATRIX_PROJECTION:
01087 glMatrixMode(GL_POSITION);
01088 glPushMatrix();
01089 glLoadIdentity();
01090 while(GFX_BUSY);
01091 for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i];
01092 glPopMatrix(1);
01093 break;
01094 case GL_GET_MATRIX_POSITION:
01095 glMatrixMode(GL_PROJECTION);
01096 glPushMatrix();
01097 glLoadIdentity();
01098 while(GFX_BUSY);
01099 for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i];
01100 glPopMatrix(1);
01101 break;
01102 default:
01103 break;
01104 }
01105 }
01106 GL_STATIC_INL
01111 void glAlphaFunc(int alphaThreshold) { GFX_ALPHA_TEST = alphaThreshold; }
01112 GL_STATIC_INL
01117 void glCutoffDepth(fixed12d3 wVal) { GFX_CUTOFF_DEPTH = wVal; }
01118 GL_STATIC_INL
01121 void glInit() {
01122 glInit_C();
01123 }
01124
01125 GL_STATIC_INL
01132 void glClearColor(uint8 red, uint8 green, uint8 blue, uint8 alpha) {
01133 GFX_CLEAR_COLOR = glGlob->clearColor = ( glGlob->clearColor & 0xFFE08000) | (0x7FFF & RGB15(red, green, blue)) | ((alpha & 0x1F) << 16);
01134 }
01135 GL_STATIC_INL
01139 void glClearPolyID(uint8 ID) {
01140 GFX_CLEAR_COLOR = glGlob->clearColor = ( glGlob->clearColor & 0xC0FFFFFF) | (( ID & 0x3F ) << 24 );
01141 }
01142 GL_STATIC_INL
01147 void glGetInt(GL_GET_ENUM param, int* i) {
01148 switch (param) {
01149 case GL_GET_POLYGON_RAM_COUNT:
01150 *i = GFX_POLYGON_RAM_USAGE;
01151 break;
01152 case GL_GET_VERTEX_RAM_COUNT:
01153 *i = GFX_VERTEX_RAM_USAGE;
01154 break;
01155 case GL_GET_TEXTURE_WIDTH:
01156 *i = 8 << (((glGlob->textures[glGlob->activeTexture]) >> 20) & 7);
01157 break;
01158 case GL_GET_TEXTURE_HEIGHT:
01159 *i = 8 << (((glGlob->textures[glGlob->activeTexture]) >> 23) & 7);
01160 break;
01161 default:
01162 break;
01163 }
01164 }
01165
01166
01167
01168
01169
01170
01171
01172 GL_STATIC_INL
01179 void glVertex3f(float x, float y, float z) {
01180 glVertex3v16(floattov16(x), floattov16(y), floattov16(z));
01181 }
01182 GL_STATIC_INL
01190 void glRotatef32(float angle, int32 x, int32 y, int32 z) {
01191 glRotatef32i((int)(angle * DEGREES_IN_CIRCLE / 360.0), x, y, z);
01192 }
01193 GL_STATIC_INL
01201 void glRotatef(float angle, float x, float y, float z) {
01202 glRotatef32(angle, floattof32(x), floattof32(y), floattof32(z));
01203 }
01204 GL_STATIC_INL
01211 void glColor3f(float r, float g, float b) {
01212 glColor3b((uint8)(r*255), (uint8)(g*255), (uint8)(b*255));
01213 }
01214 GL_STATIC_INL
01222 void glScalef(float x, float y, float z) {
01223 MATRIX_SCALE = floattof32(x);
01224 MATRIX_SCALE = floattof32(y);
01225 MATRIX_SCALE = floattof32(z);
01226 }
01227 GL_STATIC_INL
01235 void glTranslatef(float x, float y, float z) {
01236 MATRIX_TRANSLATE = floattof32(x);
01237 MATRIX_TRANSLATE = floattof32(y);
01238 MATRIX_TRANSLATE = floattof32(z);
01239 }
01240
01241 GL_STATIC_INL
01249 void glNormal3f(float x, float y, float z) {
01250 glNormal(NORMAL_PACK(floattov10(x), floattov10(y), floattov10(z)));
01251 }
01252 GL_STATIC_INL
01257 void glRotateX(float angle) {
01258 glRotateXi((int)(angle * DEGREES_IN_CIRCLE / 360.0));
01259 }
01260 GL_STATIC_INL
01265 void glRotateY(float angle) {
01266 glRotateYi((int)(angle * DEGREES_IN_CIRCLE / 360.0));
01267 }
01268 GL_STATIC_INL
01273 void glRotateZ(float angle) {
01274 glRotateZi((int)(angle * DEGREES_IN_CIRCLE / 360.0));
01275 }
01276 GL_STATIC_INL
01286 void glOrtho(float left, float right, float bottom, float top, float zNear, float zFar) {
01287 glOrthof32(floattof32(left), floattof32(right), floattof32(bottom), floattof32(top), floattof32(zNear), floattof32(zFar));
01288 }
01289 GL_STATIC_INL
01304 void gluLookAt( float eyex, float eyey, float eyez,
01305 float lookAtx, float lookAty, float lookAtz,
01306 float upx, float upy, float upz) {
01307 gluLookAtf32(floattof32(eyex), floattof32(eyey), floattof32(eyez),
01308 floattof32(lookAtx), floattof32(lookAty), floattof32(lookAtz),
01309 floattof32(upx), floattof32(upy), floattof32(upz));
01310 }
01311 GL_STATIC_INL
01321 void glFrustum(float left, float right, float bottom, float top, float near, float far) {
01322 glFrustumf32(floattof32(left), floattof32(right), floattof32(bottom), floattof32(top), floattof32(near), floattof32(far));
01323 }
01324 GL_STATIC_INL
01332 void gluPerspective(float fovy, float aspect, float zNear, float zFar) {
01333 gluPerspectivef32((int)(fovy * DEGREES_IN_CIRCLE / 360.0), floattof32(aspect), floattof32(zNear), floattof32(zFar));
01334 }
01335 GL_STATIC_INL
01342 void glTexCoord2f(float s, float t) {
01343 int x = ((glGlob->textures[glGlob->activeTexture]) >> 20) & 7;
01344 int y = ((glGlob->textures[glGlob->activeTexture]) >> 23) & 7;
01345
01346 glTexCoord2t16(floattot16(s*(8 << x)), floattot16(t*(8<<y)));
01347 }
01348
01349
01350 #endif // #ifndef VIDEOGL_ARM9_INCLUDE
01351