source: rtems/c/src/lib/libbsp/arm/nds/libnds/include/nds/arm9/videoGL.h @ 49a40165

4.104.114.95
Last change on this file since 49a40165 was 49a40165, checked in by Joel Sherrill <joel.sherrill@…>, on 08/19/08 at 15:47:14

2008-08-19 Joel Sherrill <joel.sherrill@…>

  • dswifi/arm7/makefile, dswifi/include/netinet/in.h, libnds/basicARM7/source/defaultARM7.c, libnds/include/gbfs.h, libnds/include/nds/bios.h, libnds/include/nds/card.h, libnds/include/nds/dma.h, libnds/include/nds/interrupts.h, libnds/include/nds/ipc.h, libnds/include/nds/jtypes.h, libnds/include/nds/registers_alt.h, libnds/include/nds/system.h, libnds/include/nds/timers.h, libnds/include/nds/arm7/audio.h, libnds/include/nds/arm7/clock.h, libnds/include/nds/arm7/serial.h, libnds/include/nds/arm7/touch.h, libnds/include/nds/arm9/boxtest.h, libnds/include/nds/arm9/cache.h, libnds/include/nds/arm9/console.h, libnds/include/nds/arm9/ndsmotion.h, libnds/include/nds/arm9/video.h, libnds/include/nds/arm9/videoGL.h, libnds/source/arm7/audio.c, libnds/source/arm7/clock.c, libnds/source/arm7/microphone.c, libnds/source/arm7/touch.c, libnds/source/arm7/userSettings.c, libnds/source/arm9/boxtest.c, libnds/source/arm9/gurumeditation.c, libnds/source/arm9/ndsmotion.c, libnds/source/arm9/videoGL.c, libnds/source/common/card.c, libnds/source/common/interruptDispatcher.S, touchscreen/reco.c: Fix various warnings by fixing prototypes. Remove unused .bin files. Convert all files to UNIX CF/LF.
  • libnds/source/arm9/COS.bin, libnds/source/arm9/SIN.bin, libnds/source/arm9/TAN.bin, libnds/source/arm9/default_font.bin: Removed.
  • Property mode set to 100644
File size: 59.6 KB
Line 
1/*---------------------------------------------------------------------------------
2        $Id$
3
4        videoGL.h -- Video API vaguely similar to OpenGL
5
6        Copyright (C) 2005
7                Michael Noland (joat)
8                Jason Rogers (dovoto)
9                Dave Murphy (WinterMute)
10
11        This software is provided 'as-is', without any express or implied
12        warranty.  In no event will the authors be held liable for any
13        damages arising from the use of this software.
14
15        Permission is granted to anyone to use this software for any
16        purpose, including commercial applications, and to alter it and
17        redistribute it freely, subject to the following restrictions:
18
19        1.      The origin of this software must not be misrepresented; you
20                must not claim that you wrote the original software. If you use
21                this software in a product, an acknowledgment in the product
22                documentation would be appreciated but is not required.
23
24        2.      Altered source versions must be plainly marked as such, and
25                must not be misrepresented as being the original software.
26
27        3.      This notice may not be removed or altered from any source
28                distribution.
29
30
31---------------------------------------------------------------------------------*/
32/*! \file videoGL.h
33\brief openGL (ish) interface to DS 3D hardware.
34*/
35
36#ifndef VIDEOGL_ARM9_INCLUDE
37#define VIDEOGL_ARM9_INCLUDE
38
39//---------------------------------------------------------------------------------
40
41// for some reason doxygen doesn't like "static inline" but is fine with "GL_STATIC_INL"
42#define GL_STATIC_INL static inline
43
44#ifndef ARM9
45#error 3D hardware is only available from the ARM9
46#endif
47
48//---------------------------------------------------------------------------------
49#include <nds/jtypes.h>
50#include <nds/arm9/video.h>
51#include <nds/dma.h>
52#include <nds/memory.h>
53#include <nds/bios.h>
54#include <nds/arm9/math.h>
55#include <nds/arm9/trig_lut.h>
56#include <nds/arm9/cache.h>
57
58/*---------------------------------------------------------------------------------
59        lut resolution for trig functions
60        (must be power of two and must be the same as LUT resolution)
61        in other words dont change unless you also change your LUTs
62---------------------------------------------------------------------------------*/
63#define LUT_SIZE (512)
64#define LUT_MASK (0x1FF)
65
66////////////////////////////////////////////////////////////
67// Misc. constants
68////////////////////////////////////////////////////////////
69
70#define MAX_TEXTURES 2048  //this should be enough ! but feel free to change
71
72
73//////////////////////////////////////////////////////////////////////
74// Fixed point / floating point / integer conversion macros
75//////////////////////////////////////////////////////////////////////
76
77typedef uint16 fixed12d3; /*!< \brief Used for depth (glClearDepth, glCutoffDepth) */
78
79#define int_to_12d3(n)    ((n) << 3) /*!< \brief convert int to fixed12d3 */
80#define float_to_12d3(n)  ((fixed12d3)((n) * (1 << 3))) /*!< \brief convert float to fixed12d3 */
81#define GL_MAX_DEPTH      0x7FFF /*!< \brief the maximum value for type fixed12d3 */
82
83//////////////////////////////////////////////////////////////////////
84
85#define inttof32(n)          ((n) << 12) /*!< \brief convert int to f32 */
86#define f32toint(n)          ((n) >> 12) /*!< \brief convert f32 to int */
87#define floattof32(n)        ((int32)((n) * (1 << 12))) /*!< \brief convert float to f32 */
88#define f32tofloat(n)        (((float)(n)) / (float)(1<<12)) /*!< \brief convert f32 to float */
89
90typedef short int t16;        /*!< \brief text coordinate 12.4 fixed point */
91#define f32tot16(n)          ((t16)(n >> 8)) /*!< \brief convert f32 to t16 */
92#define inttot16(n)          ((n) << 4) /*!< \brief convert int to t16 */
93#define t16toint(n)          ((n) >> 4) /*!< \brief convert t16 to int */
94#define floattot16(n)        ((t16)((n) * (1 << 4))) /*!< \brief convert float to t16 */
95#define TEXTURE_PACK(u,v)    ((u & 0xFFFF) | ((v) << 16)) /*!< \brief Pack 2 t16 texture coordinate values into a 32bit value */
96
97typedef short int v16;       /*!< \brief vertex 4.12 fixed format */
98#define inttov16(n)          ((n) << 12) /*!< \brief convert int to v16 */
99#define f32tov16(n)          (n) /*!< \brief f32 to v16 */
100#define v16toint(n)          ((n) >> 12) /*!< \brief convert v16 to int */
101#define floattov16(n)        ((v16)((n) * (1 << 12))) /*!< \brief convert float to v16 */
102#define VERTEX_PACK(x,y)     (((x) & 0xFFFF) | ((y) << 16)) /*!< \brief Pack to v16 values into one 32bit value */
103
104typedef short int v10;       /*!< \brief normal .10 fixed point, NOT USED FOR 10bit VERTEXES!!!*/
105#define inttov10(n)          ((n) << 9) /*!< \brief convert int to v10 */
106#define f32tov10(n)          ((v10)(n >> 3)) /*!< \brief convert f32 to v10 */
107#define v10toint(n)          ((n) >> 9) /*!< \brief convert v10 to int */
108#define floattov10(n)        ((n>.998) ? 0x1FF : ((v10)((n)*(1<<9)))) /*!< \brief convert float to v10 */
109#define NORMAL_PACK(x,y,z)   (((x) & 0x3FF) | (((y) & 0x3FF) << 10) | ((z) << 20)) /*!< \brief Pack 3 v10 normals into a 32bit value */
110
111//////////////////////////////////////////////////////////////////////
112
113typedef unsigned short rgb; /*!< \brief Holds a color value. 1bit alpha, 5bits red, 5bits green, 5bits blue. */
114
115/*! \brief Holds a Matrix of 3x3 */
116typedef struct {
117        int32 m[9]; /*!< array that holds matrix */
118} m3x3;
119
120/*! \brief Holds a Matrix of 4x4 */
121typedef struct {
122        int32 m[16]; /*!< array that holds matrix */
123} m4x4;
124
125/*! \brief Holds a Matrix of 4x3 */
126typedef struct {
127        int32 m[12]; /*!< array that holds matrix */
128} m4x3;
129
130/*! \brief Holds a Vector<BR>related functions: glScalev(), glTranslatev() */
131typedef struct {
132        int32 x, y, z;
133} GLvector;
134
135//////////////////////////////////////////////////////////////////////
136
137#define GL_FALSE     0
138#define GL_TRUE      1
139
140/*! \brief Enums selecting polygon draw mode<BR>
141<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A><BR>
142related functions: glBegin() */
143typedef enum {
144        GL_TRIANGLES      = 0, /*!< draw triangles with each 3 vertices defining a triangle */
145        GL_QUADS          = 1, /*!< draw quads with each 4 vertices defining a quad */
146        GL_TRIANGLE_STRIP = 2, /*!< draw triangles with the first triangle defined by 3 vertices, then each additional triangle being defined by one additional vertex */
147        GL_QUAD_STRIP     = 3, /*!< draw quads with the first quad being defined by 4 vertices, then each additional triangle being defined by 2 vertices. */
148        GL_TRIANGLE       = 0, /*!< same as GL_TRIANGLES, old non-OpenGL version */
149        GL_QUAD           = 1  /*!< same as GL_QUADS, old non-OpenGL version */
150} GL_GLBEGIN_ENUM;
151
152/*! \brief Enums selecting matrix mode<BR>
153<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A><BR>
154related functions: glMatrixMode() */
155typedef enum {
156        GL_PROJECTION     = 0, /*!< used to set the Projection Matrix */
157        GL_POSITION       = 1, /*!< used to set the Position Matrix */
158        GL_MODELVIEW      = 2, /*!< used to set the Modelview Matrix */
159        GL_TEXTURE        = 3  /*!< used to set the Texture Matrix */
160} GL_MATRIX_MODE_ENUM;
161
162/*! \brief Enums for setting up materials<BR>
163<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A><BR>
164related functions: glMaterialf() */
165typedef enum {
166        GL_AMBIENT             = 0x01, /*!< sets the ambient color for the material. The color when the normal is not facing light*/
167        GL_DIFFUSE             = 0x02, /*!< sets the diffuse color for the material. The color when the normal is facing light */
168        GL_AMBIENT_AND_DIFFUSE = 0x03, /*!< sets the set ambient and diffuse colors for the material; just a two-in-one of the above.*/
169        GL_SPECULAR            = 0x04, /*!< sets the specular color for the material. The glossy(highlight) color of the polygon */
170        GL_SHININESS           = 0x08, /*!< sets the shininess color for the material. The color that shines back to the user. I have shiny pants! */
171        GL_EMISSION            = 0x10  /*!< sets the emission color for the material. bright color that is indepentant of normals and lights*/
172} GL_MATERIALS_ENUM;
173
174/*! \brief Enums for setting how polygons will be displayed<BR>
175<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A><BR>
176related functions: glPolyFmt(), glInit(), POLY_ALPHA(), POLY_ID() */
177enum GL_POLY_FORMAT_ENUM {
178        POLY_FORMAT_LIGHT0   = (1<<0), /*!< enable light number 0 */
179        POLY_FORMAT_LIGHT1   = (1<<1), /*!< enable light number 1 */
180        POLY_FORMAT_LIGHT2   = (1<<2), /*!< enable light number 2 */
181        POLY_FORMAT_LIGHT3   = (1<<3), /*!< enable light number 3 */
182        POLY_MODULATION      = (0<<4), /*!< enable modulation shading mode; this is the default */
183        POLY_DECAL           = (1<<4), /*!< enable decal shading */
184        POLY_TOON_HIGHLIGHT  = (2<<4), /*!< enable toon/highlight shading mode */
185        POLY_SHADOW          = (3<<4), /*!< enable shadow shading */
186        POLY_CULL_FRONT      = (1<<6), /*!< cull front polygons */
187        POLY_CULL_BACK       = (2<<6), /*!< cull rear polygons */
188        POLY_CULL_NONE       = (3<<6), /*!< don't cull any polygons */
189        POLY_FOG             = (1<<15) /*!< enable/disable fog for this polygon */
190};
191
192/*! \brief Enums for size of a texture, specify one for horizontal and one for vertical
193related functions: glTexImage2d(), glTexParameter() */
194enum GL_TEXTURE_SIZE_ENUM {
195        TEXTURE_SIZE_8    = 0, /*!< 8 texels */
196        TEXTURE_SIZE_16   = 1, /*!< 16 texels */
197        TEXTURE_SIZE_32   = 2, /*!< 32 texels */
198        TEXTURE_SIZE_64   = 3, /*!< 64 texels */
199        TEXTURE_SIZE_128  = 4, /*!< 128 texels */
200        TEXTURE_SIZE_256  = 5, /*!< 256 texels */
201        TEXTURE_SIZE_512  = 6, /*!< 512 texels */
202        TEXTURE_SIZE_1024 = 7  /*!< 1024 texels */
203};
204
205/*! \brief Enums for texture parameters, such as texture wrapping and texture coord stuff<BR>
206<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A><BR>
207related functions: glTexImage2d(), glTexParameter() */
208enum GL_TEXTURE_PARAM_ENUM {
209        GL_TEXTURE_WRAP_S = (1 << 16), /*!< wrap(repeat) texture on S axis */
210        GL_TEXTURE_WRAP_T = (1 << 17), /*!< wrap(repeat) texture on T axis */
211        GL_TEXTURE_FLIP_S = (1 << 18), /*!< flip texture on S axis when wrapping */
212        GL_TEXTURE_FLIP_T = (1 << 19), /*!< flip texture on T axis when wrapping */
213        GL_TEXTURE_COLOR0_TRANSPARENT = (1<<29), /*!< interpret color 0 as clear, same as old GL_TEXTURE_ALPHA_MASK */
214        TEXGEN_OFF      = (0<<30), /*!< use unmodified texcoord */
215        TEXGEN_TEXCOORD = (1<<30), /*!< multiply texcoords by the texture-matrix */
216        TEXGEN_NORMAL   = (2<<30), /*!< set texcoords equal to normal * texture-matrix, used for spherical reflection mapping */
217        TEXGEN_POSITION = (3<<30)  /*!< set texcoords equal to vertex * texture-matrix */
218};
219
220/*! \brief Enums for texture formats<BR>
221<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureformats">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureformats</A><BR>
222related functions: glTexImage2d(), glTexParameter() */
223typedef enum {
224        GL_RGB32_A3   = 1, /*!< 32 color palette, 3 bits of alpha */
225        GL_RGB4       = 2, /*!< 4 color palette */
226        GL_RGB16      = 3, /*!< 16 color palette */
227        GL_RGB256     = 4, /*!< 256 color palette */
228        GL_COMPRESSED = 5, /*!< compressed texture */
229        GL_RGB8_A5    = 6, /*!< 8 color palette, 5 bits of alpha */
230        GL_RGBA       = 7, /*!< 15 bit direct color, 1 bit of alpha */
231        GL_RGB        = 8  /*!< 15 bit direct color, manually sets alpha bit to 1 */
232} GL_TEXTURE_TYPE_ENUM;
233
234/*! \brief 3D Display Control Register Enums<BR>
235<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A><BR>
236related functions: glEnable(), glDisable(), glInit() */
237enum DISP3DCNT_ENUM {
238        GL_TEXTURE_2D      = (1<<0),  /*!< enable/disable textures on the geometry engine */
239        GL_TOON_HIGHLIGHT  = (1<<1),  /*!< enable = Highlight shading; disable = Toon shading */
240        GL_ALPHA_TEST      = (1<<2),  /*!< whether to use the alpha threshold set in glAlphaFunc() */
241        GL_BLEND           = (1<<3),  /*!< enable/disable alpha blending */
242        GL_ANTIALIAS       = (1<<4),  /*!< nable/disable edge antialiasing; polygons must have different polygon IDs for the effect to work and the rear plane must be clear */
243        GL_OUTLINE         = (1<<5),  /*!< enable/disable edge coloring; the high 3bits of the polygon ID determine the color; glSetOutlineColor() sets the available colors */
244        GL_FOG_ONLY_ALPHA  = (1<<6),  /*!< enable = fade into background?; disable = don't fade? */
245        GL_FOG             = (1<<7),  /*!< enables/disables fog */
246        GL_COLOR_UNDERFLOW = (1<<12), /*!< enable = color buffer underflow, setting resets overflow flag; disable = no color buffer overflow */
247        GL_POLY_OVERFLOW   = (1<<13), /*!< enable = polygon/vertex buffer overflow, setting resets overflow flag; disable = no polygon/vertex buffer overflow */
248        GL_CLEAR_BMP       = (1<<14)  /*!< rear/clear plane is in BMP mode; disable = rear/color plane is in clear mode */
249};
250
251/*! \brief Enums for reading stuff from the geometry engine<BR>
252<A HREF="http://nocash.emubase.de/gbatek.htm#ds3diomap">http://nocash.emubase.de/gbatek.htm#ds3diomap</A><BR>
253related functions: glGetInt(), glGetFixed()*/
254typedef enum {
255        GL_GET_VERTEX_RAM_COUNT,    /*!< returns a count of vertexes currently stored in hardware vertex ram. Use glGetInt() to retrieve */
256        GL_GET_POLYGON_RAM_COUNT,   /*!< returns a count of polygons currently stored in hardware polygon ram. Use glGetInt() to retrieve */
257        GL_GET_MATRIX_VECTOR,           /*!< returns the current 3x3 directional vector matrix. Use glGetFixed() to retrieve */
258        GL_GET_MATRIX_POSITION,     /*!< returns the current 4x4 position matrix. Use glGetFixed() to retrieve */
259        GL_GET_MATRIX_PROJECTION,   /*!< returns the current 4x4 projection matrix. Use glGetFixed() to retrieve */
260        GL_GET_MATRIX_CLIP,                     /*!< returns the current 4x4 clip matrix. Use glGetFixed() to retrieve */
261        GL_GET_TEXTURE_WIDTH,       /*!< returns the width of the currently bound texture. Use glGetInt() to retrieve */
262        GL_GET_TEXTURE_HEIGHT       /*!< returns the height of the currently bound texture. Use glGetInt() to retrieve */
263} GL_GET_ENUM;
264
265
266/*! \brief Enums for glFlush()<BR>
267<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A><BR>
268related functions: glEnable(), glDisable(), glInit() */
269enum GLFLUSH_ENUM {
270        GL_TRANS_MANUALSORT = (1<<0), /*!< enable manual sorting of translucent polygons, otherwise uses Y-sorting */
271        GL_WBUFFERING       = (1<<1)  /*!< enable W depth buffering of vertices, otherwise uses Z depth buffering */
272};
273
274
275/*---------------------------------------------------------------------------------
276This struct hold hidden globals for videoGL. The structure is initialized in the
277.c file and returned by glGetGlobals() so that it can be used across compilation
278units without problem. This is automatically done by glInit() so don't worry too
279much about it. This is only an issue because of hte mix of inlined/real functions.
280---------------------------------------------------------------------------------*/
281typedef struct {
282        GL_MATRIX_MODE_ENUM matrixMode; // holds the current Matrix Mode
283       
284        // holds the current state of the clear color register
285        uint32 clearColor; // state of clear color register
286       
287        // texture globals
288        uint32 textures[MAX_TEXTURES];
289        uint32 activeTexture;
290        uint32* nextBlock;
291        uint32 nextPBlock;
292        int nameCount;
293       
294} gl_hidden_globals;
295
296// Pointer to global data for videoGL
297static gl_hidden_globals* glGlob = 0;
298
299//---------------------------------------------------------------------------------
300//Fifo commands
301//---------------------------------------------------------------------------------
302
303#define FIFO_COMMAND_PACK(c1,c2,c3,c4) (((c4) << 24) | ((c3) << 16) | ((c2) << 8) | (c1)) /*!< \brief packs four packed commands into a 32bit command for sending to the GFX FIFO */
304
305#define REG2ID(r)                               (u8)( ( ((u32)(&(r)))-0x04000400 ) >> 2 ) /*!< \brief converts a GFX command for use in a packed command list */
306
307#define FIFO_NOP                                REG2ID(GFX_FIFO) /*!< \brief packed command for nothing, just here to pad your command lists */
308#define FIFO_STATUS                             REG2ID(GFX_STATUS) /*!< \brief packed command for geometry engine status register<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dstatus">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dstatus</A> */
309#define FIFO_COLOR                              REG2ID(GFX_COLOR) /*!< \brief packed command for vertex color directly<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A> */
310
311#define FIFO_VERTEX16                   REG2ID(GFX_VERTEX16) /*!< \brief packed command for a vertex with 3 16bit paramaters(and 16bits of padding)<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A> */
312#define FIFO_TEX_COORD                  REG2ID(GFX_TEX_COORD) /*!< \brief packed command for a texture coordinate<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtexturecoordinates">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtexturecoordinates</A> */
313#define FIFO_TEX_FORMAT                 REG2ID(GFX_TEX_FORMAT) /*!< \brief packed command for texture format<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureformats">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureformats</A> */
314#define FIFO_PAL_FORMAT                 REG2ID(GFX_PAL_FORMAT) /*!< \brief packed command for texture palette attributes<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A> */
315
316#define FIFO_CLEAR_COLOR                REG2ID(GFX_CLEAR_COLOR) /*!< \brief packed command for clear color of the rear plane<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3drearplane">GBATEK http://nocash.emubase.de/gbatek.htm#ds3drearplane</A> */
317#define FIFO_CLEAR_DEPTH                REG2ID(GFX_CLEAR_DEPTH) /*!< \brief sets depth of the rear plane<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3drearplane">GBATEK http://nocash.emubase.de/gbatek.htm#ds3drearplane</A> */
318
319#define FIFO_LIGHT_VECTOR               REG2ID(GFX_LIGHT_VECTOR) /*!< \brief packed command for direction of a light source<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
320#define FIFO_LIGHT_COLOR                REG2ID(GFX_LIGHT_COLOR) /*!< \brief packed command for color for a light<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
321#define FIFO_NORMAL                             REG2ID(GFX_NORMAL) /*!< \brief packed command for normal for following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
322
323#define FIFO_DIFFUSE_AMBIENT    REG2ID(GFX_DIFFUSE_AMBIENT) /*!< \brief packed command for setting diffuse and ambient material properties for the following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
324#define FIFO_SPECULAR_EMISSION  REG2ID(GFX_SPECULAR_EMISSION) /*!< \brief packed command for setting specular and emmissive material properties for the following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
325#define FIFO_SHININESS                  REG2ID(GFX_SHININESS) /*!< \brief packed command for setting the shininess table to be used for the following vertices<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A> */
326
327#define FIFO_POLY_FORMAT                REG2ID(GFX_POLY_FORMAT) /*!< \brief packed command for setting polygon attributes<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A> */
328
329#define FIFO_BEGIN                              REG2ID(GFX_BEGIN) /*!< \brief packed command that starts a polygon vertex list<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A>*/
330#define FIFO_END                                REG2ID(GFX_END) /*!< \brief packed command that has no discernable effect, it's probably best to never use it since it bloats the size of the list.<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygondefinitionsbyvertices</A>*/
331#define FIFO_FLUSH                              REG2ID(GFX_FLUSH) /*!< \brief packed command that has the same effect as swiWaitForVBlank()<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A> */
332#define FIFO_VIEWPORT                   REG2ID(GFX_VIEWPORT) /*!< \brief packed command for setting viewport<BR><A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A> */
333
334
335#ifdef __cplusplus
336extern "C" {
337#endif
338
339/*! \brief Rotates the model view matrix by angle about the specified unit vector
340\param angle The angle to rotate by
341\param x X component of the unit vector axis.
342\param y Y component of the unit vector axis.
343\param z Z component of the unit vector axis. */
344void glRotatef32i(int angle, int32 x, int32 y, int32 z);
345
346/*! \brief Loads a 2D texture into texture memory and sets the currently bound texture ID to the attributes specified
347\param target not used, just here for OpenGL compatibility
348\param empty1 not used, just here for OpenGL compatibility
349\param type The format of the texture
350\param sizeX the horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
351\param sizeY the vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
352\param empty2 not used, just here for OpenGL compatibility
353\param param parameters for the texture
354\param texture pointer to the texture data to load */
355int glTexImage2D(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, int param, const uint8* texture);
356
357/*! \brief Loads a palette into the specified texture addr
358\param pal pointer to the palette to load
359\param count the size of the palette
360\param addr the offset in VRAM to load the palette */
361void glTexLoadPal(const u16* pal, u16 count, u32 addr );
362
363/*! \brief Loads a palette into the next available palette slot, returns the addr on success or -1
364\param pal pointer to the palette to load
365\param count the size of the palette
366\param format the format of the texture */
367int gluTexLoadPal(const u16* pal, u16 count, uint8 format);
368
369/*! \brief Set parameters for the current texture. Although named the same as its gl counterpart, it is not compatible. Effort may be made in the future to make it so.
370\param sizeX the horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
371\param sizeY the vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM
372\param addr offset into VRAM where you put the texture
373\param mode the type of texture
374\param param paramaters for the texture */
375void glTexParameter(    uint8 sizeX, uint8 sizeY,
376                                                const uint32* addr,
377                                                GL_TEXTURE_TYPE_ENUM mode,
378                                                uint32 param) ;
379
380/*! \brief Returns the active texture parameter (constructed from internal call to glTexParameter) */
381u32 glGetTexParameter();
382
383/*! \brief returns the address alocated to the texure named by name
384\param name the name of the texture to get a pointer to */
385void* glGetTexturePointer(      int name);
386
387/*! \brief glBindTexure sets the current named texture to the active texture. Target is ignored as all DS textures are 2D
388\param target ignored, only here for OpenGL compatability
389\param name the name(int value) to set to the current texture */
390void glBindTexture(int target, int name);
391
392/*! \brief glColorTable establishes the location of the current palette. Roughly follows glColorTableEXT. Association of palettes with named textures is left to the application. */
393void glColorTable(uint8 format, uint32 addr);
394
395/*! \brief Creates room for the specified number of textures
396\param n the number of textures to generate
397\param names pointer to the names array to fill */
398int glGenTextures(int n, int *names);
399
400/*! \brief Resets the gl texture state freeing all texture memory */
401void glResetTextures(void);
402
403/*! \brief Sets texture coordinates for following vertices<BR>
404<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A>
405\param u U(a.k.a. S) texture coordinate (0.0 - 1.0)
406\param v V(a.k.a. T) texture coordinate (0.0 - 1.0)*/
407void glTexCoord2f32(int32 u, int32 v);
408
409/*! \brief specify the material properties to be used in rendering lit polygons
410\param mode which material property to change
411\param color the color to set for that material property */
412void glMaterialf(GL_MATERIALS_ENUM mode, rgb color);
413
414// This handles initialization of the GL state; this is called from glInit to keep globals synced between compilation units
415void glInit_C(void);
416
417// This returns a pointer to the globals for videoGL
418gl_hidden_globals* glGetGlobals();
419
420
421#ifdef __cplusplus
422}
423#endif
424               
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442//////////////////////////////////////////////////////////////////////////////////////////
443//////////////////////////////////////////////////////////////////////////////////////////
444//////////////////////////////////////////////////////////////////////////////////////////
445//////////////////////////////////////////////////////////////////////////////////////////
446////////////                                                                  ////////////
447////////////                                                                  ////////////
448////////////                                                                  ////////////
449////////////                       INLINED FUNCTIONS                          ////////////
450////////////                                                                  ////////////
451////////////                                                                  ////////////
452////////////                                                                  ////////////
453//////////////////////////////////////////////////////////////////////////////////////////
454//////////////////////////////////////////////////////////////////////////////////////////
455//////////////////////////////////////////////////////////////////////////////////////////
456//////////////////////////////////////////////////////////////////////////////////////////
457
458
459
460/*! \brief used in glPolyFmt() to set the alpha level for the following polygons, set to 0 for wireframe mode
461\param n the level of alpha (0-31) */
462GL_STATIC_INL uint32 POLY_ALPHA(int n) { return (uint32)((n) << 16); };
463
464/*! \brief used in glPolyFmt() to set the Polygon ID for the following polygons
465\param n the ID to set for following polygons (0-63) */
466GL_STATIC_INL uint32 POLY_ID(int n) { return (uint32)((n)<<24); };
467
468/*! \brief Starts a polygon group
469\param mode the draw mode for the polygon */
470GL_STATIC_INL void glBegin(GL_GLBEGIN_ENUM mode) { GFX_BEGIN = mode; }
471
472/*! \brief Ends a polygon group, this seems to be a dummy function that does absolutely nothing, feel free to never use it. */
473GL_STATIC_INL void glEnd(void) { GFX_END = 0; }
474
475/*! \brief reset the depth buffer to this value; generally set this to GL_MAX_DEPTH.<BR>
476<A HREF="http://nocash.emubase.de/gbatek.htm#ds3drearplane">GBATEK http://nocash.emubase.de/gbatek.htm#ds3drearplane</A>
477\param depth Something to do with the depth buffer, generally set to GL_MAX_DEPTH */
478GL_STATIC_INL void glClearDepth(fixed12d3 depth) { GFX_CLEAR_DEPTH = depth; }
479
480/*! \brief Set the color for following vertices
481\param red the red component (0-31)
482\param green the green component (0-31)
483\param blue the blue component (0-31) */
484
485GL_STATIC_INL void glColor3b(uint8 red, uint8 green, uint8 blue) { GFX_COLOR = (vuint32)RGB15(red>>3, green>>3, blue>>3); }
486
487/*! \brief Set the color for following vertices
488\param color the 15bit color value */
489GL_STATIC_INL void glColor(rgb color) { GFX_COLOR = (vuint32)color; }
490
491/*! \brief specifies a vertex
492\param x the x component for the vertex
493\param y the y component for the vertex
494\param z the z component for the vertex */
495GL_STATIC_INL void glVertex3v16(v16 x, v16 y, v16 z) {
496        GFX_VERTEX16 = (y << 16) | (x & 0xFFFF);
497        GFX_VERTEX16 = ((uint32)(uint16)z);
498}
499
500/*! \brief Sets texture coordinates for following vertices<BR>
501<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A>
502\param u U(a.k.a. S) texture coordinate in texels
503\param v V(a.k.a. T) texture coordinate in texels */
504GL_STATIC_INL void glTexCoord2t16(t16 u, t16 v) { GFX_TEX_COORD = TEXTURE_PACK(u,v); }
505
506/*! \brief Pushs the current matrix onto the stack<BR>
507<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A> */
508GL_STATIC_INL void glPushMatrix(void) { MATRIX_PUSH = 0; }
509
510/*! \brief Pops num matrices off the stack<BR>
511<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A>
512\param num the number to pop down the stack */
513GL_STATIC_INL void glPopMatrix(int32 num) { MATRIX_POP = num; }
514
515/*! \brief Restores the current matrix from a location in the stack<BR>
516<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A>
517\param index the place in the stack to restore to */
518GL_STATIC_INL void glRestoreMatrix(int32 index) { MATRIX_RESTORE = index; }
519
520/*! \brief Place the current matrix into the stack at a location<BR>
521<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixstack</A>
522\param index the place in the stack to put the current matrix */
523GL_STATIC_INL void glStoreMatrix(int32 index) { MATRIX_STORE = index; }
524
525/*! \brief multiply the current matrix by a translation matrix<BR>
526<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
527\param v the vector to translate by */
528GL_STATIC_INL void glScalev(const GLvector* v) {
529        MATRIX_SCALE = v->x;
530        MATRIX_SCALE = v->y;
531        MATRIX_SCALE = v->z;
532}
533
534/*! \brief multiply the current matrix by a translation matrix<BR>
535<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
536\param v the vector to translate by */
537GL_STATIC_INL void glTranslatev(const GLvector* v) {
538        MATRIX_TRANSLATE = v->x;
539        MATRIX_TRANSLATE = v->y;
540        MATRIX_TRANSLATE = v->z;
541}
542
543/*! \brief multiply the current matrix by a translation matrix<BR>
544<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
545\param x translation on the x axis
546\param y translation on the y axis
547\param z translation on the z axis */
548GL_STATIC_INL void glTranslate3f32(int32 x, int32 y, int32 z) {
549        MATRIX_TRANSLATE = x;
550        MATRIX_TRANSLATE = y;
551        MATRIX_TRANSLATE = z;
552}
553
554/*! \brief multiply the current matrix by a scale matrix<BR>
555<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
556\param factor the factor to scale by */
557GL_STATIC_INL void glScalef32(int32 factor) {
558        MATRIX_SCALE = factor;
559        MATRIX_SCALE = factor;
560        MATRIX_SCALE = factor;
561}
562
563/*! \brief set a light up. Only parallel light sources are supported on the DS<BR>
564<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A>
565\param id the number of the light to setup
566\param color the color of the light
567\param x the x component of the lights directional vector. Direction must be normalized
568\param y the y component of the lights directional vector. Direction must be normalized
569\param z the z component of the lights directional vector. Direction must be normalized */
570GL_STATIC_INL void glLight(int id, rgb color, v10 x, v10 y, v10 z) {
571        id = (id & 3) << 30;
572        GFX_LIGHT_VECTOR = id | ((z & 0x3FF) << 20) | ((y & 0x3FF) << 10) | (x & 0x3FF);
573        GFX_LIGHT_COLOR = id | color;
574}
575
576/*! \brief the normal to use for following vertices<BR>
577<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A>
578\warning The nature of the format means that you can't represent the following normals exactly (0,0,1), (0,1,0), or (1,0,0)
579\param normal the packed normal(3 * 10bit x, y, z) */
580GL_STATIC_INL void glNormal(uint32 normal) { GFX_NORMAL = normal; }
581
582/*! \brief loads an identity matrix to the current matrix, same as glIdentity(void) */
583GL_STATIC_INL void glLoadIdentity(void) { MATRIX_IDENTITY = 0; }
584
585/*! \brief change the current matrix mode<BR>
586<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A><BR>
587\param mode the mode for the matrix */
588GL_STATIC_INL void glMatrixMode(GL_MATRIX_MODE_ENUM mode) { MATRIX_CONTROL = mode; }
589
590/*! \brief specify the viewport for following drawing, can be set several times per frame.<BR>
591<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
592\param x1 the left of the viewport
593\param y1 the bottom of the viewport
594\param x2 the right of the viewport
595\param y2 the top of the viewport */
596GL_STATIC_INL void glViewport(uint8 x1, uint8 y1, uint8 x2, uint8 y2) { GFX_VIEWPORT = (x1) + (y1 << 8) + (x2 << 16) + (y2 << 24); }
597
598/*! \brief Waits for a Vblank and swaps the buffers(like swiWaitForVBlank), but lets you specify some 3D options<BR>
599<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
600\param mode flags from GLFLUSH_ENUM for enabling Y-sorting of translucent polygons and W-Buffering of all vertices*/
601GL_STATIC_INL void glFlush(uint32 mode) { GFX_FLUSH = mode; }
602
603/*! \brief The DS uses a table for shinyness..this generates a half-ass one */
604GL_STATIC_INL void glMaterialShinyness(void) {
605        uint32 shiny32[128/4];
606        uint8  *shiny8 = (uint8*)shiny32;
607       
608        int i;
609       
610        for (i = 0; i < 128 * 2; i += 2)
611                shiny8[i>>1] = i;
612       
613        for (i = 0; i < 128 / 4; i++)
614                GFX_SHININESS = shiny32[i];
615}
616
617/*! \brief throws a packed list of commands into the graphics FIFO via asyncronous DMA<BR>
618The first 32bits is the length of the packed command list, followed by a the packed list.<BR>
619If you want to do this really fast then write your own code that that does this synchronously and only flushes the cache when the list is changed<BR>
620There is sometimes a problem when you pack the GFX_END command into a list, so don't. GFX_END is a dummy command and never needs called<BR>
621<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dgeometrycommands">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dgeometrycommands</A> */
622GL_STATIC_INL void glCallList(const u32* list) {
623        u32 count = *list++;
624       
625        // flush the area that we are going to DMA
626        DC_FlushRange(list, count*4);
627       
628        // don't start DMAing while anything else is being DMAed because FIFO DMA is touchy as hell
629        //    If anyone can explain this better that would be great. -- gabebear
630        while((DMA_CR(0) & DMA_BUSY)||(DMA_CR(1) & DMA_BUSY)||(DMA_CR(2) & DMA_BUSY)||(DMA_CR(3) & DMA_BUSY));
631       
632        // send the packed list asynchronously via DMA to the FIFO
633        DMA_SRC(0) = (uint32)list;
634        DMA_DEST(0) = 0x4000400;
635        DMA_CR(0) = DMA_FIFO | count;
636        while(DMA_CR(0) & DMA_BUSY);
637}
638
639/*! \brief Set the parameters for polygons rendered on the current frame<BR>
640<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes</A>
641\param params the paramters to set for the polygons for the current frame. valid paramters are enumerated in GL_POLY_FORMAT_ENUM and in the functions POLY_ALPHA() and POLY_ID() */
642GL_STATIC_INL void glPolyFmt(uint32 params) { GFX_POLY_FORMAT = params; }
643
644/*! \brief Enables various gl states (blend, alpha test, etc..)
645\param bits bit mask of desired attributes, attributes are enumerated in DISP3DCNT_ENUM */
646GL_STATIC_INL void glEnable(int bits) { GFX_CONTROL |= bits; }
647
648/*! \brief Disables various gl states (blend, alpha test, etc..)
649\param bits bit mask of desired attributes, attributes are enumerated in DISP3DCNT_ENUM */
650GL_STATIC_INL void glDisable(int bits) { GFX_CONTROL &= ~bits; }
651
652/*! \brief Loads a 4x4 matrix into the current matrix
653\param m pointer to a 4x4 matrix */
654GL_STATIC_INL void glLoadMatrix4x4(const m4x4 *m) {
655        MATRIX_LOAD4x4 = m->m[0];
656        MATRIX_LOAD4x4 = m->m[1];
657        MATRIX_LOAD4x4 = m->m[2];
658        MATRIX_LOAD4x4 = m->m[3];
659       
660        MATRIX_LOAD4x4 = m->m[4];
661        MATRIX_LOAD4x4 = m->m[5];
662        MATRIX_LOAD4x4 = m->m[6];
663        MATRIX_LOAD4x4 = m->m[7];
664       
665        MATRIX_LOAD4x4 = m->m[8];
666        MATRIX_LOAD4x4 = m->m[9];
667        MATRIX_LOAD4x4 = m->m[10];
668        MATRIX_LOAD4x4 = m->m[11];
669       
670        MATRIX_LOAD4x4 = m->m[12];
671        MATRIX_LOAD4x4 = m->m[13];
672        MATRIX_LOAD4x4 = m->m[14];
673        MATRIX_LOAD4x4 = m->m[15];
674}
675
676/*! \brief Loads a 4x3 matrix into the current matrix
677\param m pointer to a 4x4 matrix */
678GL_STATIC_INL void glLoadMatrix4x3(const m4x3 * m) {
679        MATRIX_LOAD4x3 = m->m[0];
680        MATRIX_LOAD4x3 = m->m[1];
681        MATRIX_LOAD4x3 = m->m[2];
682        MATRIX_LOAD4x3 = m->m[3];
683       
684        MATRIX_LOAD4x3 = m->m[4];
685        MATRIX_LOAD4x3 = m->m[5];
686        MATRIX_LOAD4x3 = m->m[6];
687        MATRIX_LOAD4x3 = m->m[7];
688       
689        MATRIX_LOAD4x3 = m->m[8];
690        MATRIX_LOAD4x3 = m->m[9];
691        MATRIX_LOAD4x3 = m->m[10];
692        MATRIX_LOAD4x3 = m->m[11];
693}
694
695/*! \brief Multiplies the current matrix by m
696\param m pointer to a 4x4 matrix */
697GL_STATIC_INL void glMultMatrix4x4(const m4x4 * m) {
698        MATRIX_MULT4x4 = m->m[0];
699        MATRIX_MULT4x4 = m->m[1];
700        MATRIX_MULT4x4 = m->m[2];
701        MATRIX_MULT4x4 = m->m[3];
702       
703        MATRIX_MULT4x4 = m->m[4];
704        MATRIX_MULT4x4 = m->m[5];
705        MATRIX_MULT4x4 = m->m[6];
706        MATRIX_MULT4x4 = m->m[7];
707       
708        MATRIX_MULT4x4 = m->m[8];
709        MATRIX_MULT4x4 = m->m[9];
710        MATRIX_MULT4x4 = m->m[10];
711        MATRIX_MULT4x4 = m->m[11];
712       
713        MATRIX_MULT4x4 = m->m[12];
714        MATRIX_MULT4x4 = m->m[13];
715        MATRIX_MULT4x4 = m->m[14];
716        MATRIX_MULT4x4 = m->m[15];
717}
718
719/*! \brief multiplies the current matrix by
720\param m pointer to a 4x3 matrix */
721GL_STATIC_INL void glMultMatrix4x3(const m4x3 * m) {
722        MATRIX_MULT4x3 = m->m[0];
723        MATRIX_MULT4x3 = m->m[1];
724        MATRIX_MULT4x3 = m->m[2];
725        MATRIX_MULT4x3 = m->m[3];
726       
727        MATRIX_MULT4x3 = m->m[4];
728        MATRIX_MULT4x3 = m->m[5];
729        MATRIX_MULT4x3 = m->m[6];
730        MATRIX_MULT4x3 = m->m[7];
731       
732        MATRIX_MULT4x3 = m->m[8];
733        MATRIX_MULT4x3 = m->m[9];
734        MATRIX_MULT4x3 = m->m[10];
735        MATRIX_MULT4x3 = m->m[11];
736       
737}
738
739/*! \brief multiplies the current matrix by m
740\param m pointer to a 3x3 matrix */
741GL_STATIC_INL void glMultMatrix3x3(const m3x3 * m) {
742        MATRIX_MULT3x3 = m->m[0];
743        MATRIX_MULT3x3 = m->m[1];
744        MATRIX_MULT3x3 = m->m[2];
745       
746        MATRIX_MULT3x3 = m->m[3];
747        MATRIX_MULT3x3 = m->m[4];
748        MATRIX_MULT3x3 = m->m[5];
749       
750        MATRIX_MULT3x3 = m->m[6];
751        MATRIX_MULT3x3 = m->m[7];
752        MATRIX_MULT3x3 = m->m[8];
753}
754
755/*! \brief Rotates the current modelview matrix by angle about the x axis
756\param angle The angle to rotate by (angle is 0-511) */
757GL_STATIC_INL void glRotateXi(int angle) {
758        int32 sine = SIN[angle &  LUT_MASK];
759        int32 cosine = COS[angle & LUT_MASK];
760       
761        MATRIX_MULT3x3 = inttof32(1);
762        MATRIX_MULT3x3 = 0;
763        MATRIX_MULT3x3 = 0;
764       
765        MATRIX_MULT3x3 = 0;
766        MATRIX_MULT3x3 = cosine;
767        MATRIX_MULT3x3 = sine;
768       
769        MATRIX_MULT3x3 = 0;
770        MATRIX_MULT3x3 = -sine;
771        MATRIX_MULT3x3 = cosine;
772}
773
774/*! \brief Rotates the current modelview matrix by angle about the y axis
775\param angle The angle to rotate by (angle is 0-511) */
776GL_STATIC_INL void glRotateYi(int angle) {
777        int32 sine = SIN[angle &  LUT_MASK];
778        int32 cosine = COS[angle & LUT_MASK];
779       
780        MATRIX_MULT3x3 = cosine;
781        MATRIX_MULT3x3 = 0;
782        MATRIX_MULT3x3 = -sine;
783       
784        MATRIX_MULT3x3 = 0;
785        MATRIX_MULT3x3 = inttof32(1);
786        MATRIX_MULT3x3 = 0;
787       
788        MATRIX_MULT3x3 = sine;
789        MATRIX_MULT3x3 = 0;
790        MATRIX_MULT3x3 = cosine;
791}
792
793/*! \brief Rotates the current modelview matrix by angle about the z axis
794\param angle The angle to rotate by (angle is 0-511) */
795GL_STATIC_INL void glRotateZi(int angle) {
796        int32 sine = SIN[angle &  LUT_MASK];
797        int32 cosine = COS[angle & LUT_MASK];
798       
799        MATRIX_MULT3x3 = cosine;
800        MATRIX_MULT3x3 = sine;
801        MATRIX_MULT3x3 = 0;
802       
803        MATRIX_MULT3x3 = - sine;
804        MATRIX_MULT3x3 = cosine;
805        MATRIX_MULT3x3 = 0;
806       
807        MATRIX_MULT3x3 = 0;
808        MATRIX_MULT3x3 = 0;
809        MATRIX_MULT3x3 = inttof32(1);
810}
811
812
813/*! \brief Multiplies the current matrix into ortho graphic mode
814\param left left vertical clipping plane
815\param right right vertical clipping plane
816\param bottom bottom vertical clipping plane
817\param top top vertical clipping plane
818\param zNear near clipping plane
819\param zFar far clipping plane */
820GL_STATIC_INL void glOrthof32(int32 left, int32 right, int32 bottom, int32 top, int32 zNear, int32 zFar) {
821        MATRIX_MULT4x4 = divf32(inttof32(2), right - left);     
822        MATRIX_MULT4x4 = 0; 
823        MATRIX_MULT4x4 = 0;     
824        MATRIX_MULT4x4 = 0;
825
826        MATRIX_MULT4x4 = 0; 
827        MATRIX_MULT4x4 = divf32(inttof32(2), top - bottom);     
828        MATRIX_MULT4x4 = 0;   
829        MATRIX_MULT4x4 = 0;
830
831        MATRIX_MULT4x4 = 0; 
832        MATRIX_MULT4x4 = 0; 
833        MATRIX_MULT4x4 = divf32(inttof32(-2), zFar - zNear);     
834        MATRIX_MULT4x4 = 0;
835
836        MATRIX_MULT4x4 = -divf32(right + left, right - left);//0; 
837        MATRIX_MULT4x4 = -divf32(top + bottom, top - bottom); //0; 
838        MATRIX_MULT4x4 = -divf32(zFar + zNear, zFar - zNear);//0; 
839        MATRIX_MULT4x4 = floattof32(1.0F);
840}
841
842/*! \brief Places the camera at the specified location and orientation (fixed point version)
843\param eyex (eyex, eyey, eyez) Location of the camera.
844\param eyey (eyex, eyey, eyez) Location of the camera.
845\param eyez (eyex, eyey, eyez) Location of the camera.
846\param lookAtx (lookAtx, lookAty, lookAtz) Where the camera is looking.
847\param lookAty (lookAtx, lookAty, lookAtz) Where the camera is looking.
848\param lookAtz (lookAtx, lookAty, lookAtz) Where the camera is looking.
849\param upx <upx, upy, upz> Unit vector describing which direction is up for the camera.
850\param upy <upx, upy, upz> Unit vector describing which direction is up for the camera.
851\param upz <upx, upy, upz> Unit vector describing which direction is up for the camera. */
852GL_STATIC_INL void gluLookAtf32(int32 eyex, int32 eyey, int32 eyez, int32 lookAtx, int32 lookAty, int32 lookAtz, int32 upx, int32 upy, int32 upz) {
853        int32 side[3], forward[3], up[3], eye[3];
854       
855        forward[0] = eyex - lookAtx;
856        forward[1] = eyey - lookAty;
857        forward[2] = eyez - lookAtz;
858       
859        normalizef32(forward);
860       
861        up[0] = upx;
862        up[1] = upy;
863        up[2] = upz;
864        eye[0] = eyex;
865        eye[1] = eyey;
866        eye[2] = eyez;
867       
868        crossf32(up, forward, side);
869       
870        normalizef32(side);
871       
872        // Recompute local up
873        crossf32(forward, side, up);
874       
875        glMatrixMode(GL_MODELVIEW);
876       
877       
878        // should we use MATRIX_MULT4x3?
879        MATRIX_MULT4x3 = side[0];
880        MATRIX_MULT4x3 = up[0];
881        MATRIX_MULT4x3 = forward[0];
882       
883        MATRIX_MULT4x3 = side[1];
884        MATRIX_MULT4x3 = up[1];
885        MATRIX_MULT4x3 = forward[1];
886       
887        MATRIX_MULT4x3 = side[2];
888        MATRIX_MULT4x3 = up[2];
889        MATRIX_MULT4x3 = forward[2];
890       
891        MATRIX_MULT4x3 = -dotf32(eye,side);
892        MATRIX_MULT4x3 = -dotf32(eye,up);
893        MATRIX_MULT4x3 = -dotf32(eye,forward);
894       
895}
896
897
898/*! \brief Specifies the viewing frustum for the projection matrix (fixed point version)
899\param left left right top and bottom describe a rectangle located at the near clipping plane
900\param right left right top and bottom describe a rectangle located at the near clipping plane
901\param top left right top and bottom describe a rectangle located at the near clipping plane
902\param bottom left right top and bottom describe a rectangle located at the near clipping plane
903\param near Location of a the near clipping plane (parallel to viewing window)
904\param far Location of a the far clipping plane (parallel to viewing window) */
905GL_STATIC_INL void glFrustumf32(int32 left, int32 right, int32 bottom, int32 top, int32 near, int32 far) {
906/*      MATRIX_MULT4x4 = divf32(2*near, right - left);
907        MATRIX_MULT4x4 = 0;
908        MATRIX_MULT4x4 = divf32(right + left, right - left);
909        MATRIX_MULT4x4 = 0;
910       
911        MATRIX_MULT4x4 = 0;
912        MATRIX_MULT4x4 = divf32(2*near, top - bottom);
913        MATRIX_MULT4x4 = divf32(top + bottom, top - bottom);
914        MATRIX_MULT4x4 = 0;
915       
916        MATRIX_MULT4x4 = 0;
917        MATRIX_MULT4x4 = 0;
918        MATRIX_MULT4x4 = -divf32(far + near, far - near);
919        MATRIX_MULT4x4 = floattof32(-1.0F);
920        MATRIX_MULT4x4 = 0;
921       
922        MATRIX_MULT4x4 = 0;
923        MATRIX_MULT4x4 = -divf32(2 * mulf32(far, near), far - near);
924        MATRIX_MULT4x4 = 0;
925*/
926
927
928        MATRIX_MULT4x4 = divf32(2*near, right - left);
929        MATRIX_MULT4x4 = 0;
930        MATRIX_MULT4x4 = 0;
931        MATRIX_MULT4x4 = 0;
932 
933        MATRIX_MULT4x4 = 0;
934        MATRIX_MULT4x4 = divf32(2*near, top - bottom);
935        MATRIX_MULT4x4 = 0;
936        MATRIX_MULT4x4 = 0;
937 
938        MATRIX_MULT4x4 = divf32(right + left, right - left);
939        MATRIX_MULT4x4 = divf32(top + bottom, top - bottom);
940        MATRIX_MULT4x4 = -divf32(far + near, far - near);
941        MATRIX_MULT4x4 = floattof32(-1.0F);
942 
943        MATRIX_MULT4x4 = 0;
944        MATRIX_MULT4x4 = 0;
945        MATRIX_MULT4x4 = -divf32(2 * mulf32(far, near), far - near);
946        MATRIX_MULT4x4 = 0;
947
948}
949
950/*! \brief Utility function which sets up the projection matrix (fixed point version)
951\param fovy Specifies the field of view in degrees (0 -511)
952\param aspect Specifies the aspect ratio of the screen (normally screen width/screen height)
953\param zNear Specifies the near clipping plane
954\param zFar Specifies the far clipping plane */
955GL_STATIC_INL void gluPerspectivef32(int fovy, int32 aspect, int32 zNear, int32 zFar) {
956        int32 xmin, xmax, ymin, ymax;
957       
958        ymax = mulf32(zNear, TAN[(fovy>>1) & LUT_MASK]);
959        ymin = -ymax;
960        xmin = mulf32(ymin, aspect);
961        xmax = mulf32(ymax, aspect);
962       
963        glFrustumf32(xmin, xmax, ymin, ymax, zNear, zFar);
964}
965
966/*! \brief Utility function which generates a picking matrix for selection
967\param x 2D x of center  (touch x normally)
968\param y 2D y of center  (touch y normally)
969\param width width in pixels of the window (3 or 4 is a good number)
970\param height height in pixels of the window (3 or 4 is a good number)
971\param viewport the current viewport (normaly {0, 0, 255, 191}) */
972GL_STATIC_INL void gluPickMatrix(int x, int y, int width, int height, const int viewport[4]) {
973        MATRIX_MULT4x4 = inttof32(viewport[2]) / width;
974        MATRIX_MULT4x4 = 0;
975        MATRIX_MULT4x4 = 0;
976        MATRIX_MULT4x4 = 0;
977        MATRIX_MULT4x4 = 0;
978        MATRIX_MULT4x4 = inttof32(viewport[3]) / height;
979        MATRIX_MULT4x4 = 0;
980        MATRIX_MULT4x4 = 0;
981        MATRIX_MULT4x4 = 0;
982        MATRIX_MULT4x4 = 0;
983        MATRIX_MULT4x4 = inttof32(1);
984        MATRIX_MULT4x4 = 0;
985        MATRIX_MULT4x4 = inttof32(viewport[2] + ((viewport[0] - x)<<1)) / width;
986        MATRIX_MULT4x4 = inttof32(viewport[3] + ((viewport[1] - y)<<1)) / height;
987        MATRIX_MULT4x4 = 0;
988        MATRIX_MULT4x4 = inttof32(1);
989}
990
991/*! \brief Resets matrix stack to top level */
992GL_STATIC_INL void glResetMatrixStack(void) {
993        // make sure there are no push/pops that haven't executed yet
994        while(GFX_STATUS & BIT(14)){
995                GFX_STATUS |= 1 << 15; // clear push/pop errors or push/pop busy bit never clears
996        }
997       
998        // pop the projection stack to the top; poping 0 off an empty stack causes an error... weird?
999        if((GFX_STATUS&(1<<13))!=0) {
1000                glMatrixMode(GL_PROJECTION);
1001                glPopMatrix(1);
1002        }
1003       
1004        // 31 deep modelview matrix; 32nd entry works but sets error flag
1005        glMatrixMode(GL_MODELVIEW);
1006        glPopMatrix((GFX_STATUS >> 8) & 0x1F);
1007       
1008        // load identity to all the matrices
1009        glMatrixMode(GL_MODELVIEW);
1010        glLoadIdentity();
1011        glMatrixMode(GL_PROJECTION);
1012        glLoadIdentity();
1013        glMatrixMode(GL_TEXTURE);
1014        glLoadIdentity();
1015}
1016
1017/*! \brief Specifies an edge color for polygons
1018\param id which outline color to set (0-7)
1019\param color the 15bit color to set */
1020GL_STATIC_INL void glSetOutlineColor(int id, rgb color) { GFX_EDGE_TABLE[id] = color; }
1021
1022/*! \brief Loads a toon table
1023\param pointer to the 32 color palette to load into the toon table*/
1024GL_STATIC_INL void glSetToonTable(const uint16 *table) {
1025        int i;
1026        for(i = 0; i < 32; i++ )
1027                GFX_TOON_TABLE[i] = table[i];
1028}
1029
1030/*! \brief Sets a range of colors on the toon table
1031\param start the start of the range
1032\param end the end of the range
1033\param color the color to set for that range */
1034GL_STATIC_INL void glSetToonTableRange(int start, int end, rgb color) {
1035        int i;
1036        for(i = start; i <= end; i++ )
1037                GFX_TOON_TABLE[i] = color;
1038}
1039
1040/*! \brief Grabs fixed format of state variables<BR>
1041OpenGL's modelview matrix is handled on the DS with two matrices. The combination of the DS's position matrix and directional vector matrix hold the data that is in OpenGL's one modelview matrix. (a.k.a. modelview = postion and vector)<BR>
1042<A HREF="http://nocash.emubase.de/gbatek.htm#ds3diomap">http://nocash.emubase.de/gbatek.htm#ds3diomap</A>
1043\param param The state variable to retrieve
1044\param f pointer with room to hold the requested data */
1045GL_STATIC_INL void glGetFixed(const GL_GET_ENUM param, int32* f) {
1046        int i;
1047        switch (param) {
1048                case GL_GET_MATRIX_VECTOR:
1049                        while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
1050                        for(i = 0; i < 9; i++) f[i] = MATRIX_READ_VECTOR[i];
1051                        break;
1052                case GL_GET_MATRIX_CLIP:
1053                        while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
1054                        for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i];
1055                        break;
1056                case GL_GET_MATRIX_PROJECTION:
1057                        glMatrixMode(GL_POSITION);
1058                        glPushMatrix(); // save the current state of the position matrix
1059                        glLoadIdentity(); // load an identity matrix into the position matrix so that the clip matrix = projection matrix
1060                        while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
1061                                for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i]; // read out the projection matrix
1062                        glPopMatrix(1); // restore the position matrix
1063                        break;
1064                case GL_GET_MATRIX_POSITION:
1065                        glMatrixMode(GL_PROJECTION);
1066                        glPushMatrix(); // save the current state of the projection matrix
1067                        glLoadIdentity(); // load a identity matrix into the projection matrix so that the clip matrix = position matrix
1068                        while(GFX_BUSY); // wait until the graphics engine has stopped to read matrixes
1069                                for(i = 0; i < 16; i++) f[i] = MATRIX_READ_CLIP[i]; // read out the position matrix
1070                        glPopMatrix(1); // restore the projection matrix
1071                        break;
1072                default:
1073                        break;
1074        }
1075}
1076
1077/*! \brief set the minimum alpha value that will be used<BR>
1078<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
1079\param alphaThreshold minimum alpha value that will be used (0-15) */
1080GL_STATIC_INL void glAlphaFunc(int alphaThreshold) { GFX_ALPHA_TEST = alphaThreshold; }
1081
1082/*! \brief Stop the drawing of polygons that are a certain distance from the camera.<BR>
1083<A HREF="http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol">GBATEK http://nocash.emubase.de/gbatek.htm#ds3ddisplaycontrol</A>
1084\param polygons that are beyond this W-value(distance from camera) will not be drawn; 15bit value. */
1085GL_STATIC_INL void glCutoffDepth(fixed12d3 wVal) { GFX_CUTOFF_DEPTH = wVal; }
1086
1087/*! \brief Initializes the gl state machine (must be called once before using gl calls) */
1088GL_STATIC_INL void glInit() {
1089        glGlob = glGetGlobals(); // make sure globals are synced between compilation units
1090        glInit_C(); // actually does the initialization
1091}
1092
1093/*! \brief sets the color of the rear-plane(a.k.a Clear Color/Plane)
1094\param red component (0-31)
1095\param green component (0-31)
1096\param blue component (0-31)
1097\param alpha from 0(clear) to 31(opaque)*/
1098GL_STATIC_INL void glClearColor(uint8 red, uint8 green, uint8 blue, uint8 alpha) {
1099        GFX_CLEAR_COLOR = glGlob->clearColor = ( glGlob->clearColor & 0xFFE08000) | (0x7FFF & RGB15(red, green, blue)) | ((alpha & 0x1F) << 16);
1100}
1101
1102/*! \brief sets the polygon ID of the rear-plane(a.k.a. Clear/Color Plane), useful for antialiasing and edge coloring
1103\param ID the polygon ID to give the rear-plane */
1104GL_STATIC_INL void glClearPolyID(uint8 ID) {
1105        GFX_CLEAR_COLOR = glGlob->clearColor = ( glGlob->clearColor & 0xC0FFFFFF) | (( ID & 0x3F ) << 24 );
1106}
1107
1108/*! \brief Grabs integer state variables from openGL
1109\param param The state variable to retrieve
1110\param i pointer with room to hold the requested data */
1111GL_STATIC_INL void glGetInt(GL_GET_ENUM param, int* i) {
1112        switch (param) {
1113                case GL_GET_POLYGON_RAM_COUNT:
1114                        *i = GFX_POLYGON_RAM_USAGE;
1115                        break;
1116                case GL_GET_VERTEX_RAM_COUNT:
1117                        *i = GFX_VERTEX_RAM_USAGE;
1118                        break;
1119                case GL_GET_TEXTURE_WIDTH:
1120                        *i = 8 << (((glGlob->textures[glGlob->activeTexture]) >> 20) & 7);
1121                        break;
1122                case GL_GET_TEXTURE_HEIGHT:
1123                        *i = 8 << (((glGlob->textures[glGlob->activeTexture]) >> 23) & 7);
1124                        break;
1125                default:
1126                        break;
1127        }
1128}
1129
1130
1131//---------------------------------------------------------------------------------
1132//                    INLINED FlOAT WRAPPERS
1133//
1134//  All floating point functions.
1135//
1136
1137/*! \brief specifies a vertex location
1138\warning FLOAT VERSION!!!! please use glVertex3v16()
1139\param x the x component of the vertex
1140\param y the y component of the vertex
1141\param z the z component of the vertex */
1142GL_STATIC_INL void glVertex3f(float x, float y, float z) {
1143        glVertex3v16(floattov16(x), floattov16(y), floattov16(z));
1144}
1145
1146/*! \brief Rotate on an arbitrary axis
1147\warning FLOAT VERSION!!!! please use glRotatef32i()
1148\param angle the angle to rotate by
1149\param x the x component of the axis to rotate on
1150\param y the y component of the axis to rotate on
1151\param z the z component of the axis to rotate on */
1152GL_STATIC_INL void glRotatef32(float angle, int32 x, int32 y, int32 z) {
1153    glRotatef32i((int)(angle * LUT_SIZE / 360.0), x, y, z);
1154}
1155
1156/*! \brief Rotate about an arbitrary axis
1157\warning FLOAT VERSION!!!! please use glRotatef32i()
1158\param angle the angle to rotate by
1159\param x the x component of the axis to rotate on
1160\param y the y component of the axis to rotate on
1161\param z the z component of the axis to rotate on */
1162GL_STATIC_INL void glRotatef(float angle, float x, float y, float z) {
1163        glRotatef32(angle, floattof32(x), floattof32(y), floattof32(z));
1164}
1165
1166/*! \brief specify a color for following vertices
1167\warning FLOAT VERSION!!!! please use glColor3b()
1168\param r the red component of the color
1169\param g the green component of the color
1170\param b the blue component of the color */
1171GL_STATIC_INL void glColor3f(float r, float g, float b) {
1172        glColor3b((uint8)(r*255), (uint8)(g*255), (uint8)(b*255));
1173}
1174
1175/*! \brief multiply the current matrix by a scale matrix<BR>
1176<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
1177\warning FLOAT VERSION!!!! please use glScalev() or glScalef32()
1178\param x scaling on the x axis
1179\param y scaling on the y axis
1180\param z scaling on the z axis */
1181GL_STATIC_INL void glScalef(float x, float y, float z) {
1182        MATRIX_SCALE = floattof32(x);
1183        MATRIX_SCALE = floattof32(y);
1184        MATRIX_SCALE = floattof32(z);
1185}
1186
1187/*! \brief multiply the current matrix by a translation matrix<BR>
1188<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dmatrixloadmultiply</A>
1189\warning FLOAT VERSION!!!! please use glTranslate3f32()
1190\param x translation on the x axis
1191\param y translation on the y axis
1192\param z translation on the z axis */
1193GL_STATIC_INL void glTranslatef(float x, float y, float z) {
1194        MATRIX_TRANSLATE = floattof32(x);
1195        MATRIX_TRANSLATE = floattof32(y);
1196        MATRIX_TRANSLATE = floattof32(z);
1197}
1198
1199/*! \brief the normal to use for following vertices<BR>
1200<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dpolygonlightparameters</A>
1201\warning FLOAT VERSION!!!! please use glNormal()
1202\param x x component of the normal, vector must be normalized
1203\param y y component of the normal, vector must be normalized
1204\param z z component of the normal, vector must be normalized */
1205GL_STATIC_INL void glNormal3f(float x, float y, float z) {
1206        glNormal(NORMAL_PACK(floattov10(x), floattov10(y), floattov10(z)));
1207}
1208
1209/*! \brief Rotates the current modelview matrix by angle degrees about the x axis
1210\warning FLOAT VERSION!!!! please use glRotateXi()
1211\param angle The angle to rotate by */
1212GL_STATIC_INL void glRotateX(float angle) {
1213        glRotateXi((int)(angle * LUT_SIZE / 360.0));
1214}
1215
1216/*! \brief Rotates the current modelview matrix by angle degrees about the y axis
1217\warning FLOAT VERSION!!!! please use glRotateYi()
1218\param angle The angle to rotate by */
1219GL_STATIC_INL void glRotateY(float angle) {
1220        glRotateYi((int)(angle * LUT_SIZE / 360.0));
1221}
1222
1223/*! \brief Rotates the current modelview matrix by angle degrees about the z axis
1224\warning FLOAT VERSION!!!! please use glRotateZi()
1225\param angle The angle to rotate by */
1226GL_STATIC_INL void glRotateZ(float angle) {
1227        glRotateZi((int)(angle * LUT_SIZE / 360.0));
1228}
1229
1230/*! \brief Multiplies the current matrix into ortho graphic mode
1231\warning FLOAT VERSION!!!! please use glOrthof32()
1232\param left left vertical clipping plane
1233\param right right vertical clipping plane
1234\param bottom bottom vertical clipping plane
1235\param top top vertical clipping plane
1236\param zNear near clipping plane
1237\param zFar far clipping plane */
1238GL_STATIC_INL void glOrtho(float left, float right, float bottom, float top, float zNear, float zFar) {
1239        glOrthof32(floattof32(left), floattof32(right), floattof32(bottom), floattof32(top), floattof32(zNear), floattof32(zFar));
1240}
1241
1242/*! \brief Places the camera at the specified location and orientation (floating point version)
1243\warning FLOAT VERSION!!!! please use gluLookAtf32()
1244\param eyex (eyex, eyey, eyez) Location of the camera.
1245\param eyey (eyex, eyey, eyez) Location of the camera.
1246\param eyez (eyex, eyey, eyez) Location of the camera.
1247\param lookAtx (lookAtx, lookAty, lookAtz) Where the camera is looking.
1248\param lookAty (lookAtx, lookAty, lookAtz) Where the camera is looking.
1249\param lookAtz (lookAtx, lookAty, lookAtz) Where the camera is looking.
1250\param upx <upx, upy, upz> Unit vector describing which direction is up for the camera.
1251\param upy <upx, upy, upz> Unit vector describing which direction is up for the camera.
1252\param upz <upx, upy, upz> Unit vector describing which direction is up for the camera. */
1253GL_STATIC_INL void gluLookAt(   float eyex, float eyey, float eyez,
1254                                                                float lookAtx, float lookAty, float lookAtz,
1255                                                                float upx, float upy, float upz) {
1256        gluLookAtf32(floattof32(eyex), floattof32(eyey), floattof32(eyez),
1257                                 floattof32(lookAtx), floattof32(lookAty), floattof32(lookAtz),
1258                                 floattof32(upx), floattof32(upy), floattof32(upz));
1259}
1260
1261/*! \brief Specifies the viewing frustum for the projection matrix (floating point version)
1262\warning FLOAT VERSION!!!! please use glFrustumf32()
1263\param left left right top and bottom describe a rectangle located at the near clipping plane
1264\param right left right top and bottom describe a rectangle located at the near clipping plane
1265\param top left right top and bottom describe a rectangle located at the near clipping plane
1266\param bottom left right top and bottom describe a rectangle located at the near clipping plane
1267\param near Location of a the near clipping plane (parallel to viewing window)
1268\param far Location of a the far clipping plane (parallel to viewing window) */
1269GL_STATIC_INL void glFrustum(float left, float right, float bottom, float top, float near, float far) {
1270        glFrustumf32(floattof32(left), floattof32(right), floattof32(bottom), floattof32(top), floattof32(near), floattof32(far));
1271}
1272
1273/*! \brief Utility function which sets up the projection matrix (floating point version)
1274\warning FLOAT VERSION!!!! please use gluPerspectivef32()
1275\param fovy Specifies the field of view in degrees 
1276\param aspect Specifies the aspect ratio of the screen (normally screen width/screen height)
1277\param zNear Specifies the near clipping plane
1278\param zFar Specifies the far clipping plane */
1279GL_STATIC_INL void gluPerspective(float fovy, float aspect, float zNear, float zFar) {
1280        gluPerspectivef32((int)(fovy * LUT_SIZE / 360.0), floattof32(aspect), floattof32(zNear), floattof32(zFar));   
1281}
1282
1283/*! \brief Sets texture coordinates for following vertices<BR>
1284<A HREF="http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes">GBATEK http://nocash.emubase.de/gbatek.htm#ds3dtextureattributes</A>
1285\warning FLOAT VERSION!!!! please use glTexCoord2t16()
1286\param s S(a.k.a. U) texture coordinate (0.0 - 1.0)
1287\param t T(a.k.a. V) texture coordinate (0.0 - 1.0)*/
1288GL_STATIC_INL void glTexCoord2f(float s, float t) {
1289        int x = ((glGlob->textures[glGlob->activeTexture]) >> 20) & 7;
1290        int y = ((glGlob->textures[glGlob->activeTexture]) >> 23) & 7;
1291       
1292        glTexCoord2t16(floattot16(s*(8 << x)), floattot16(t*(8<<y)));
1293}
1294
1295
1296#endif // #ifndef VIDEOGL_ARM9_INCLUDE
1297
Note: See TracBrowser for help on using the repository browser.