|
| 1 | +/*--------------------------------------------------------------------------------- |
| 2 | +
|
| 3 | + Video API vaguely similar to OpenGL |
| 4 | +
|
| 5 | + Copyright (C) 2005 |
| 6 | + Michael Noland (joat) |
| 7 | + Jason Rogers (dovoto) |
| 8 | + Dave Murphy (WinterMute) |
| 9 | +
|
| 10 | + This software is provided 'as-is', without any express or implied |
| 11 | + warranty. In no event will the authors be held liable for any |
| 12 | + damages arising from the use of this software. |
| 13 | +
|
| 14 | + Permission is granted to anyone to use this software for any |
| 15 | + purpose, including commercial applications, and to alter it and |
| 16 | + redistribute it freely, subject to the following restrictions: |
| 17 | +
|
| 18 | + 1. The origin of this software must not be misrepresented; you |
| 19 | + must not claim that you wrote the original software. If you use |
| 20 | + this software in a product, an acknowledgment in the product |
| 21 | + documentation would be appreciated but is not required. |
| 22 | + 2. Altered source versions must be plainly marked as such, and |
| 23 | + must not be misrepresented as being the original software. |
| 24 | + 3. This notice may not be removed or altered from any source |
| 25 | + distribution. |
| 26 | +
|
| 27 | +
|
| 28 | +---------------------------------------------------------------------------------*/ |
| 29 | + |
| 30 | +#include <nds/ndstypes.h> |
| 31 | +#include <nds/memory.h> |
| 32 | +#include <nds/bios.h> |
| 33 | +#include <nds/system.h> |
| 34 | +#include <nds/arm9/math.h> |
| 35 | +#include <nds/arm9/video.h> |
| 36 | +#include <nds/arm9/videoGL.h> |
| 37 | +#include <nds/arm9/trig_lut.h> |
| 38 | +#include <nds/arm9/sassert.h> |
| 39 | + |
| 40 | +u32 glCurClearColor; |
| 41 | + |
| 42 | +//--------------------------------------------------------------------------------- |
| 43 | +void glRotatef32i(int angle, s32 x, s32 y, s32 z) { |
| 44 | +//--------------------------------------------------------------------------------- |
| 45 | + s32 axis[3]; |
| 46 | + s32 sine = sinLerp(angle);//SIN[angle & LUT_MASK]; |
| 47 | + s32 cosine = cosLerp(angle);//COS[angle & LUT_MASK]; |
| 48 | + s32 one_minus_cosine = inttof32(1) - cosine; |
| 49 | + |
| 50 | + axis[0]=x; |
| 51 | + axis[1]=y; |
| 52 | + axis[2]=z; |
| 53 | + |
| 54 | + normalizef32(axis); // should require passed in normalized? |
| 55 | + |
| 56 | + MATRIX_MULT3x3 = cosine + mulf32(one_minus_cosine, mulf32(axis[0], axis[0])); |
| 57 | + MATRIX_MULT3x3 = mulf32(one_minus_cosine, mulf32(axis[0], axis[1])) + mulf32(axis[2], sine); |
| 58 | + MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[0]), axis[2]) - mulf32(axis[1], sine); |
| 59 | + |
| 60 | + MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[0]), axis[1]) - mulf32(axis[2], sine); |
| 61 | + MATRIX_MULT3x3 = cosine + mulf32(mulf32(one_minus_cosine, axis[1]), axis[1]); |
| 62 | + MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[1]), axis[2]) + mulf32(axis[0], sine); |
| 63 | + |
| 64 | + MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[0]), axis[2]) + mulf32(axis[1], sine); |
| 65 | + MATRIX_MULT3x3 = mulf32(mulf32(one_minus_cosine, axis[1]), axis[2]) - mulf32(axis[0], sine); |
| 66 | + MATRIX_MULT3x3 = cosine + mulf32(mulf32(one_minus_cosine, axis[2]), axis[2]); |
| 67 | +} |
| 68 | + |
| 69 | +//--------------------------------------------------------------------------------- |
| 70 | +void glMaterialf(GL_MATERIALS_ENUM mode, rgb color) { |
| 71 | +//--------------------------------------------------------------------------------- |
| 72 | + static u32 diffuse_ambient = 0; |
| 73 | + static u32 specular_emission = 0; |
| 74 | + |
| 75 | + switch(mode) { |
| 76 | + case GL_AMBIENT: |
| 77 | + diffuse_ambient = (color << 16) | (diffuse_ambient & 0xFFFF); |
| 78 | + break; |
| 79 | + case GL_DIFFUSE: |
| 80 | + diffuse_ambient = color | (diffuse_ambient & 0xFFFF0000); |
| 81 | + break; |
| 82 | + case GL_AMBIENT_AND_DIFFUSE: |
| 83 | + diffuse_ambient= color + (color << 16); |
| 84 | + break; |
| 85 | + case GL_SPECULAR: |
| 86 | + specular_emission = color | (specular_emission & 0xFFFF0000); |
| 87 | + break; |
| 88 | + case GL_SHININESS: |
| 89 | + break; |
| 90 | + case GL_EMISSION: |
| 91 | + specular_emission = (color << 16) | (specular_emission & 0xFFFF); |
| 92 | + break; |
| 93 | + } |
| 94 | + |
| 95 | + GFX_DIFFUSE_AMBIENT = diffuse_ambient; |
| 96 | + GFX_SPECULAR_EMISSION = specular_emission; |
| 97 | +} |
| 98 | + |
| 99 | +//--------------------------------------------------------------------------------- |
| 100 | +MK_WEAK void _glInitGlobals(void) { |
| 101 | +//--------------------------------------------------------------------------------- |
| 102 | + // Dummy implementation when not using the texture VRAM manager |
| 103 | +} |
| 104 | + |
| 105 | +//--------------------------------------------------------------------------------- |
| 106 | +void glInit(void) { |
| 107 | +//--------------------------------------------------------------------------------- |
| 108 | + powerOn(POWER_3D_CORE | POWER_MATRIX); // enable 3D core & geometry engine |
| 109 | + |
| 110 | + // Initialize texture VRAM manager (if needed) |
| 111 | + _glInitGlobals(); |
| 112 | + |
| 113 | + while (GFX_STATUS & (1<<27)); // wait till gfx engine is not busy |
| 114 | + |
| 115 | + // Clear the FIFO |
| 116 | + GFX_STATUS |= (1<<29); |
| 117 | + |
| 118 | + // Clear overflows from list memory |
| 119 | + glResetMatrixStack(); |
| 120 | + |
| 121 | + // prime the vertex/polygon buffers |
| 122 | + glFlush(0); |
| 123 | + |
| 124 | + // reset the control bits |
| 125 | + GFX_CONTROL = 0; |
| 126 | + |
| 127 | + // reset the rear-plane(a.k.a. clear color) to black, ID=0, and opaque |
| 128 | + glCurClearColor = 0; |
| 129 | + glClearColor(0,0,0,31); |
| 130 | + glClearPolyID(0); |
| 131 | + |
| 132 | + // reset the depth to it's max |
| 133 | + glClearDepth(GL_MAX_DEPTH); |
| 134 | + |
| 135 | + GFX_TEX_FORMAT = 0; |
| 136 | + GFX_POLY_FORMAT = 0; |
| 137 | + |
| 138 | + glMatrixMode(GL_PROJECTION); |
| 139 | + glLoadIdentity(); |
| 140 | + |
| 141 | + glMatrixMode(GL_MODELVIEW); |
| 142 | + glLoadIdentity(); |
| 143 | + |
| 144 | + glMatrixMode(GL_TEXTURE); |
| 145 | + glLoadIdentity(); |
| 146 | +} |
0 commit comments