///////////////////////////////////////////////////////////////////////////
//
// N64DRAW.C
//
///////////////////////////////////////////////////////////////////////////
#include "x_debug.h"
#include "x_color.h"
#include "Q_Draw.h"
#include "Q_Engine.h"
#include "Q_SMem.h"
#include "Q_N64.h"
#include "Q_N64_RM.h"
#include "N64_Eng.h"
#include "N64Video.h"
///////////////////////////////////////////////////////////////////////////
// STRUCTURES
///////////////////////////////////////////////////////////////////////////
typedef struct
{
bool ThreeD; // false -> 2D
bool Fill; // false -> wireframe
bool Texture; // false -> solid
bool Alpha; // false -> opaque
bool ZBuffer; // false -> not z-buffered
} draw_mode;
///////////////////////////////////////////////////////////////////////////
// GLOBALS
///////////////////////////////////////////////////////////////////////////
static draw_mode ActiveDrawMode;
static bool DrawModeDefined = FALSE;
static bool ForcedLineMode = FALSE;
static bool ForcedNoTexture = FALSE;
static bool ForcedL2WOverride = FALSE;
static s32 TextureWidth = 0;
static s32 TextureHeight = 0;
static matrix4 UserL2W;
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Helper functions.
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
static
void DRAW_VertToN64Vtx( Vtx* N64V, draw_vert* V )
{
N64V->v.ob[0] = V->X; // X
N64V->v.ob[1] = V->Y; // Y
N64V->v.ob[2] = V->Z; // Z
N64V->v.tc[0] = V->U * (TextureWidth <<6); // U
N64V->v.tc[1] = V->V * (TextureHeight<<6); // V
COLOR_TO_RGBA( V->C, N64V->v.cn[0], // R
N64V->v.cn[1], // G
N64V->v.cn[2], // B
N64V->v.cn[3] ); // A
}
///////////////////////////////////////////////////////////////////////////
static
void DRAW_SetupN64Vtx( Vtx* N64V,
f32 X, f32 Y, f32 Z,
f32 U, f32 V,
color Color )
{
N64V->v.ob[0] = X; // X
N64V->v.ob[1] = Y; // Y
N64V->v.ob[2] = Z; // Z
N64V->v.tc[0] = U * (TextureWidth <<6); // U
N64V->v.tc[1] = V * (TextureHeight<<6); // V
COLOR_TO_RGBA( Color, N64V->v.cn[0], // R
N64V->v.cn[1], // G
N64V->v.cn[2], // B
N64V->v.cn[3] ); // A
}
///////////////////////////////////////////////////////////////////////////
static
void DRAW_PrepVertCacheFor2D( void )
{
s32 i, NVerts;
Vtx* Vert;
view* View;
matrix4 W2V;
vector3d Pos;
s16 VertX, VertY, VertZ;
// Clear the N64's L2W (model) matrix.
{
matrix4 L2W;
M4_Identity( &L2W );
N64_SetL2W ( &L2W );
}
// Allocate dummy verts.
NVerts = N64_GetVCacheSize();
Vert = (Vtx*)SMEM_BufferAlloc( sizeof(Vtx)*NVerts );
// Decide on some valid dummy verts.
View = ENG_GetActiveView();
VIEW_GetW2VMatrix( View, &W2V );
VIEW_GetPosition ( View, &Pos );
// Compute position 100 inches off nose of camera.
VertX = (s16)(Pos.X + W2V.M[0][2]*100.0f);
VertY = (s16)(Pos.Y + W2V.M[1][2]*100.0f);
VertZ = (s16)(Pos.Z + W2V.M[2][2]*100.0f);
// Load the dummy verts with respectable values.
for( i=0; i<NVerts; i++ )
{
Vert.v.ob[0] = VertX;
Vert.v.ob[1] = VertY;
Vert.v.ob[2] = VertZ;
Vert.v.tc[0] = 0;
Vert.v.tc[1] = 0;
Vert.v.cn[0] = 255;
Vert.v.cn[1] = 255;
Vert.v.cn[2] = 255;
Vert.v.cn[3] = 255;
}
// Load verts into the cache.
gSPVertex( pDList++, Vert, NVerts, 0 );
// Clear Z values so nobody else has to bother with it.
for( i=0; i<NVerts; i++ )
{
gSPModifyVertex( pDList++, i, G_MWO_POINT_ZSCREEN, 0x00000000 );
}
}
///////////////////////////////////////////////////////////////////////////
static
void DRAW_Set2DVertInVCache( s32 VIndex,
s32 X, s32 Y,
f32 U, f32 V,
color Color )
{
u32 ArgXYS, ArgRGBA, ArgST;
// Add fractional accuracy to UVs.
U *= 32.0f;
V *= 32.0f;
// Compute the arguments to the modify commands.
ArgXYS = ((X & 0xFFFF) << 18) | ((Y & 0xFFFF) << 2);
ArgRGBA = ((Color << 8) & 0xFFFFFF00) | ((Color >> 24) & 0x000000FF);
ArgST = ((((s32)U) << 16) & 0xFFFF0000) | (((s32)V) & 0x0000FFFF);
// Apply modifications.
gSPModifyVertex( pDList++, VIndex, G_MWO_POINT_XYSCREEN, ArgXYS );
gSPModifyVertex( pDList++, VIndex, G_MWO_POINT_RGBA, ArgRGBA );
gSPModifyVertex( pDList++, VIndex, G_MWO_POINT_ST, ArgST );
}
///////////////////////////////////////////////////////////////////////////
static
void DRAW_ForceLineMode( bool Activate )
{
u32 Mode;
// If we are already in the ForceLineMode requested, return.
if( Activate == ForcedLineMode )
return;
// If the ForceLineMode requested is already satisfied by the current
// ActiveDrawMode.Fill setting, then return.
if( Activate != ActiveDrawMode.Fill )
return;
// Build the new mode specifier.
Mode = (ActiveDrawMode.ThreeD ? DRAW_3D : DRAW_2D) |
(Activate ? DRAW_NO_FILL : DRAW_FILL) |
(ActiveDrawMode.Texture ? DRAW_TEXTURE : DRAW_NO_TEXTURE) |
(ActiveDrawMode.Alpha ? DRAW_ALPHA : DRAW_NO_ALPHA) |
(ActiveDrawMode.ZBuffer ? DRAW_ZBUFFER : DRAW_NO_ZBUFFER);
DRAW_SetMode( Mode );
ForcedLineMode = Activate;
}
///////////////////////////////////////////////////////////////////////////
static
void DRAW_ForceNoTexture( bool Activate )
{
// If we are already in the ForceNoTexture setting requested, return.
if( Activate == ForcedNoTexture )
return;
// If the ForceNoTexture request is already satisfied by the current
// ActiveDrawMode.Texture setting, then return.
if( Activate != ActiveDrawMode.Texture )
return;
if( Activate )
{
gSPTexture( pDList++, // Some texture behavior attributes.
0x8000, 0x8000, // UV "scale factors". Value 0x8000 is 0.5.
0, // "Mip levels - 1". We have 1 level, so use 0.
G_TX_RENDERTILE, // Not sure. G_TX_RENDERTILE = 0 which works.
G_OFF ); // G_OFF does NOT activate the texture.
gDPSetCombineMode( pDList++, // Color combine mode for cycles 1 and 2.
G_CC_SHADE, // Given value works for now. Experiment later.
G_CC_SHADE ); // (Same as above for 1 cycle usage.)
}
else
{
gSPTexture( pDList++, // Some texture behavior attributes.
0x8000, 0x8000, // UV "scale factors". Value 0x8000 is 0.5.
0, // "Mip levels - 1". We have 1 level, so use 0.
G_TX_RENDERTILE, // Not sure. G_TX_RENDERTILE = 0 which works.
G_ON ); // G_ON activates the texture.
gDPSetCombineMode( pDList++, // Color combine mode for cycles 1 and 2.
G_CC_MODULATERGB, // Given value works for now. Experiment later.
G_CC_MODULATERGB ); // (Same as above for 1 cycle usage.)
}
ActiveDrawMode.Texture = !Activate;
ForcedNoTexture = Activate;
}
///////////////////////////////////////////////////////////////////////////
static
void DRAW_ForceL2WOverride( matrix4* L2WOverride )
{
// If we are already in the ForceL2WOverride setting requested, then
// just return.
if( (L2WOverride == NULL) && !ForcedL2WOverride )
return;
if( L2WOverride )
{
N64_SetL2W( L2WOverride );
ForcedL2WOverride = TRUE;
}
else
{
// We no longer need a special L2W matrix.
// Put back the last L2W the user provided.
N64_SetL2W ( &UserL2W );
ForcedL2WOverride = FALSE;
}
}
///////////////////////////////////////////////////////////////////////////
static
void DRAW_MegaRectangle( f32 X, f32 Y, f32 Z, // Hot spot (2D Left-Top), (3D Center)
f32 W, f32 H, // (2D pixel W&H), (3D World W&H)
f32 U0, f32 V0, // Upper Left UV [0.0 - 1.0]
f32 U1, f32 V1, // Bottom Right UV [0.0 - 1.0]
color TLColor, // Top Left color
color TRColor, // Top Right color
color BLColor, // Bottom Left color
color BRColor ) // Bottom Right color
{
// We need the "distance from center to edge", not the "distance
// from edge to edge". So cut the values in half.
W *= 0.5f;
H *= 0.5f;
//
// Set the verts up in the cache.
//
// 0 3
// +-----+
// | |
// | \ |
// | |
// +-----+
// 1 2
//
if( ActiveDrawMode.ThreeD )
{
Vtx* Vertex;
view* View;
matrix4 V2W;
vector3d CamUp; // Camera UP in world space.
vector3d CamLeft; // Camera LEFT in world space.
vector3d UpR; // Vectors in world space that point up and
vector3d UpL; // to the right and left in camera space.
// We're gonna do a "3D sprite"-esque rectangle.
// To provide reasonable accuracy on a 3D sprite, we have to scale
// the verts about on the N64. To do so, we must overwrite the L2W
// with a "scale down" matrix. In the meantime, back up any matrix
// the user had provided.
{
matrix4 L2W;
M4_Identity( &L2W );
M4_SetUniScale( &L2W, 0.01f );
DRAW_ForceL2WOverride( &L2W );
}
// And to balance the "scale down" L2W matrix, we need to scale up
// the verts. For the corners, we can do this, simply by tickling
// the size of the rectange specified.
W *= 100.0f;
H *= 100.0f;
// For the center, we must scale its vector by 100.
X *= 100.0f;
Y *= 100.0f;
Z *= 100.0f;
// Get the V2W matrix.
View = ENG_GetActiveView();
VIEW_GetV2WMatrix( View, &V2W );
//
// We are going to take columns out of the V2W matrix to
// create our helper vectors. And we will scale these according
// to the given Width and Height values.
//
// Camera 'i-vector' (left) in world space.
// |
// |
// |-----------|
CamLeft.X = V2W.M[0][0] * W;
CamLeft.Y = V2W.M[0][1] * W;
CamLeft.Z = V2W.M[0][2] * W;
// Camera 'j-vector' (up) in world space.
// |
// |
// |-----------|
CamUp.X = V2W.M[1][0] * H;
CamUp.Y = V2W.M[1][1] * H;
CamUp.Z = V2W.M[1][2] * H;
// Now that we have our helper vectors, we can create the vectors
// we need to position the corners of the rectangle.
UpL.X = CamUp.X + CamLeft.X;
UpL.Y = CamUp.Y + CamLeft.Y;
UpL.Z = CamUp.Z + CamLeft.Z;
UpR.X = CamUp.X - CamLeft.X;
UpR.Y = CamUp.Y - CamLeft.Y;
UpR.Z = CamUp.Z - CamLeft.Z;
// Allocate space for the N64 vertices in the scratch buffer.
Vertex = (Vtx*)SMEM_BufferAlloc( sizeof(Vtx) * 4 );
// Build the N64 verts in place in the scratch buffer.
DRAW_SetupN64Vtx( Vertex+0, X+UpL.X, Y+UpL.Y, Z+UpL.Z, U0, V0, TLColor );
DRAW_SetupN64Vtx( Vertex+1, X-UpR.X, Y-UpR.Y, Z-UpR.Z, U0, V1, BLColor );
DRAW_SetupN64Vtx( Vertex+2, X-UpL.X, Y-UpL.Y, Z-UpL.Z, U1, V1, BRColor );
DRAW_SetupN64Vtx( Vertex+3, X+UpR.X, Y+UpR.Y, Z+UpR.Z, U1, V0, TRColor );
// Load 'em all up!
gSPVertex( pDList++, Vertex, 4, 0 );
}
else
{
// In 2D mode, there are dummy verts already in the cache.
// We simply have to modify them.
//##############################################################################
// CLIPPING!
DRAW_Set2DVertInVCache( 0, X+W, Y+H, U0, V0, TLColor );
DRAW_Set2DVertInVCache( 1, X+W, Y-H, U0, V1, TRColor );
DRAW_Set2DVertInVCache( 2, X-W, Y-H, U1, V1, BLColor );
DRAW_Set2DVertInVCache( 3, X-W, Y+H, U1, V0, BRColor );
}
//
// The verts are ready. Now let's render something.
//
if( !ActiveDrawMode.Fill )
{
// We are in wire mode. Just draw four lines.
gSPLine3D( pDList++, 0, 1, 0 );
gSPLine3D( pDList++, 1, 2, 0 );
gSPLine3D( pDList++, 2, 3, 0 );
gSPLine3D( pDList++, 3, 0, 0 );
return;
}
if( (!ActiveDrawMode.Texture) || (ActiveDrawMode.ThreeD) )
{
// We want a colored rectangle or a 3D sprite.
// Use 2 triangles.
gSP2Triangles( pDList++, 0, 1, 2, 0, 2, 3, 0, 0 );
return;
}
// At this point, it must be a 2D sprite.
{
ASSERT( ActiveDrawMode.Texture );
ASSERT( !ActiveDrawMode.ThreeD );
//##############################################################################
// Draw the sprite.
}
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Internal functions to be used by N64_Eng.c. Do not make static.
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
void DRAW_ClearMode( void )
{
ASSERT( N64_RenderContext() );
if( DrawModeDefined )
{
// Make sure we restore the microcode.
if( !ActiveDrawMode.Fill )
N64_WireFrameMode( FALSE );
DrawModeDefined = FALSE;
ForcedLineMode = FALSE;
ForcedNoTexture = FALSE;
}
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Public functions.
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
s32 DRAW_GetOptimalVertexCount( void )
{
return( N64_GetVCacheSize() );
}
///////////////////////////////////////////////////////////////////////////
void DRAW_SetVertAll( draw_vert* Vert,
f32 X, f32 Y, f32 Z,
f32 U, f32 V, // 0.0 thru 1.0
color C )
{
ASSERT( Vert );
Vert->X = X;
Vert->Y = Y;
Vert->Z = Z;
Vert->U = U;
Vert->V = V;
Vert->C = C;
}
///////////////////////////////////////////////////////////////////////////
void DRAW_SetVert2D( draw_vert* Vert,
f32 X, f32 Y,
color C )
{
ASSERT( Vert );
Vert->X = X;
Vert->Y = Y;
Vert->Z = 0.0;
Vert->U = 0.0;
Vert->V = 0.0;
Vert->C = C;
}
///////////////////////////////////////////////////////////////////////////
void DRAW_SetVert3D( draw_vert* Vert,
f32 X, f32 Y, f32 Z,
color C )
{
ASSERT( Vert );
Vert->X = X;
Vert->Y = Y;
Vert->Z = Z;
Vert->U = 0.0;
Vert->V = 0.0;
Vert->C = C;
}
///////////////////////////////////////////////////////////////////////////
void DRAW_SetL2W( matrix4* L2W )
{
ASSERT( N64_RenderContext() );
UserL2W = *L2W;
if( !ForcedL2WOverride )
N64_SetL2W( L2W );
}
///////////////////////////////////////////////////////////////////////////
/*
void DRAW_SetMode( bool ThreeD, // false -> 2D
bool Fill, // false -> wireframe
bool Texture, // false -> solid
bool Alpha, // false -> opaque
bool ZBuffer ) // false -> not z-buffered
*/
void DRAW_SetMode( u32 DrawMode )
{
draw_mode NewDrawMode;
ASSERTS( N64_RenderContext(), "DRAW_SetMode: Render Mode not active" );
//
// Make sure draw mode specifier includes values for all 5 options.
//
ASSERTS( DrawMode & (DRAW_2D & DRAW_3D),
"DRAW_SetMode : 2D or 3D not specified" );
ASSERTS( DrawMode & (DRAW_FILL & DRAW_NO_FILL),
"DRAW_SetMode: FILL or NO_FILL not specified" );
ASSERTS( DrawMode & (DRAW_TEXTURE & DRAW_NO_TEXTURE),
"DRAW_SetMode: TEXTURE or NO_TEXTURE not specified" );
ASSERTS( DrawMode & (DRAW_ALPHA & DRAW_NO_ALPHA),
"DRAW_SetMode: ALPHA or NO_ALPHA not specified" );
ASSERTS( DrawMode & (DRAW_ZBUFFER & DRAW_NO_ZBUFFER),
"DRAW_SetMode: ZBUFFER or NO_ZBUFFER not specified" );
//
// Convert draw mode specifier into our collection of bools.
//
NewDrawMode.ThreeD = ((DrawMode & DRAW_3D) == DRAW_3D);
NewDrawMode.Fill = ((DrawMode & DRAW_FILL) == DRAW_FILL);
NewDrawMode.Texture = ((DrawMode & DRAW_TEXTURE) == DRAW_TEXTURE);
NewDrawMode.Alpha = ((DrawMode & DRAW_ALPHA) == DRAW_ALPHA);
NewDrawMode.ZBuffer = ((DrawMode & DRAW_ZBUFFER) == DRAW_ZBUFFER);
// Clear out previous state.
DRAW_ClearMode();
gDPPipeSync( pDList++ ); // Make sure pipeline is clear.
// NOTE: Make sure to activate wire mode (via microcode) before
// everything else because the microcode change kills most
// settings.
if( !NewDrawMode.Fill )
{
N64_WireFrameMode( TRUE );
}
gDPSetCycleType ( pDList++, G_CYC_1CYCLE );
gSPClearGeometryMode ( pDList++, G_ALL );
gSPSetGeometryMode ( pDList++, G_SHADE |
G_SHADING_SMOOTH |
G_CULL_BACK );
if( !NewDrawMode.ThreeD )
{
DRAW_PrepVertCacheFor2D();
}
if( NewDrawMode.Texture )
{
gSPTexture( pDList++, // Some texture behavior attributes.
0x8000, 0x8000, // UV "scale factors". Value 0x8000 is 0.5.
0, // "Mip levels - 1". We have 1 level, so use 0.
G_TX_RENDERTILE, //
G_ON ); // G_ON activates the texture.
gDPSetCombineMode( pDList++, // Color combine mode for cycles 1 and 2.
G_CC_MODULATERGB, //
G_CC_MODULATERGB ); //
}
else
{
gSPTexture( pDList++, // Some texture behavior attributes.
0x8000, 0x8000, // UV "scale factors". Value 0x8000 is 0.5.
0, // "Mip levels - 1". We have 1 level, so use 0.
G_TX_RENDERTILE, //
G_OFF ); // G_OFF does NOT activate the texture.
gDPSetCombineMode( pDList++, // Color combine mode for cycles 1 and 2.
G_CC_SHADE, //
G_CC_SHADE ); //
}
if( NewDrawMode.ThreeD )
{
gDPSetTexturePersp ( pDList++, G_TP_PERSP );
}
else
{
gDPSetTexturePersp ( pDList++, G_TP_NONE );
}
if( NewDrawMode.ZBuffer )
{
gSPSetGeometryMode ( pDList++, G_ZBUFFER );
}
//
// Okay. We need to set the render mode. On the N64, its a one shot
// function call with mangled up parameters. We're going to determine
// the parameters first based on the desired settings. Then we will
// go ahead and set the render mode.
//
{
s32 Combination = 0;
u32 Mode1;
u32 Mode2;
if( NewDrawMode.Alpha ) Combination += 1;
if( NewDrawMode.ZBuffer ) Combination += 2;
switch( Combination )
{
case 0: // [ ] Alpha [ ] ZBuffer
Mode1 = G_RM_OPA_SURF;
Mode2 = G_RM_OPA_SURF2;
break;
case 1: // [X] Alpha [ ] ZBuffer
Mode1 = G_RM_XLU_SURF;
Mode2 = G_RM_XLU_SURF2;
break;
case 2: // [ ] Alpha [X] ZBuffer
Mode1 = G_RM_ZB_OPA_SURF;
Mode2 = G_RM_ZB_OPA_SURF2;
break;
case 3: // [X] Alpha [X] ZBuffer
Mode1 = G_RM_ZB_XLU_SURF;
Mode2 = G_RM_ZB_XLU_SURF2;
break;
}
// Now set the render mode.
gDPSetRenderMode ( pDList++, Mode1, Mode2 );
}
//
// Retain the settings.
//
ActiveDrawMode = NewDrawMode;
DrawModeDefined = TRUE;
}
///////////////////////////////////////////////////////////////////////////
void DRAW_SetTexture( vram_bitmap* Texture )
{
ASSERT( N64_RenderContext() );
if( Texture )
{
VRAM_Activate( Texture );
TextureWidth = VRAM_GetWidth ( Texture );
TextureHeight = VRAM_GetHeight( Texture );
}
else
{
TextureWidth = 0;
TextureHeight = 0;
}
gDPSetTextureFilter( pDList++, G_TF_BILERP );
}
///////////////////////////////////////////////////////////////////////////
void DRAW_Points( draw_vert* VertList, s32 NVerts )
{
ASSERT( N64_RenderContext() );
ASSERT( DrawModeDefined );
ASSERT( VertList );
ASSERT( NVerts > 0 );
// Make sure we are not in a forced mode.
DRAW_ForceLineMode ( FALSE );
DRAW_ForceNoTexture ( FALSE );
DRAW_ForceL2WOverride( NULL );
// Temporary solution.
ASSERT( NVerts <= N64_GetVCacheSize() );
ASSERT( FALSE );
}
///////////////////////////////////////////////////////////////////////////
void DRAW_Lines( draw_vert* VertList, s32 NVerts,
s16* IndexList, s32 NLines )
{
s32 i;
ASSERT( N64_RenderContext() );
ASSERT( DrawModeDefined );
ASSERT( VertList );
ASSERT( IndexList );
ASSERT( NVerts > 0 );
ASSERT( NLines > 0 );
// Make sure we are in a line mode. Force it if needed.
// Make sure other forced modes are off.
DRAW_ForceLineMode ( TRUE );
DRAW_ForceNoTexture ( FALSE );
DRAW_ForceL2WOverride( NULL );
// Temporary solution.
ASSERT( NVerts <= N64_GetVCacheSize() );
//
// Set the verts up in the cache.
//
if( ActiveDrawMode.ThreeD )
{
Vtx* Vertex;
// In 3D mode, we have to make N64 verts in the scratch memory.
// But other than that, we'll let the N64 do the work.
// Allocate space for the N64 vertices in the scratch buffer.
Vertex = (Vtx*)SMEM_BufferAlloc( sizeof(Vtx) * NVerts );
// Build the N64 verts in place in the scratch buffer.
for( i = 0; i < NVerts; i++ )
{
DRAW_VertToN64Vtx( Vertex+i, VertList+i );
}
// Load 'em all up!
gSPVertex( pDList++, Vertex, NVerts, 0 );
}
else
{
// In 2D mode, there are dummy verts already in the cache.
// We simply have to modify them.
for( i = 0; i < NVerts; i++ )
{
DRAW_Set2DVertInVCache( i,
VertList.X, VertList.Y,
VertList.U, VertList.V,
VertList.C );
}
}
//
// Render the lines.
//
while( NLines )
{
ASSERT( IndexList[0] < NVerts );
ASSERT( IndexList[1] < NVerts );
gSPLine3D( pDList++, IndexList[0],
IndexList[1],
0 );
IndexList += 2;
NLines -= 1;
}
}
///////////////////////////////////////////////////////////////////////////
void DRAW_Triangles( draw_vert* VertList, s32 NVerts,
s16* IndexList, s32 NTris )
{
s32 i;
ASSERT( N64_RenderContext() );
ASSERT( DrawModeDefined );
ASSERT( VertList );
ASSERT( IndexList );
ASSERT( NVerts > 0 );
ASSERT( NTris > 0 );
// Make sure we are not in a forced mode.
DRAW_ForceLineMode ( FALSE );
DRAW_ForceNoTexture ( FALSE );
DRAW_ForceL2WOverride( NULL );
// Temporary solution.
ASSERT( NVerts <= N64_GetVCacheSize() );
//
// Set the verts up in the cache.
//
if( ActiveDrawMode.ThreeD )
{
Vtx* Vertex;
// In 3D mode, we have to make N64 verts in the scratch memory.
// But other than that, we'll let the N64 do the work.
// Allocate space for the N64 vertices in the scratch buffer.
Vertex = (Vtx*)SMEM_BufferAlloc( sizeof(Vtx) * NVerts );
// Build the N64 verts in place in the scratch buffer.
for( i = 0; i < NVerts; i++ )
{
DRAW_VertToN64Vtx( Vertex+i, VertList+i );
}
// Load 'em all up!
gSPVertex( pDList++, Vertex, NVerts, 0 );
}
else
{
// In 2D mode, there are dummy verts already in the cache.
// We simply have to modify them.
for( i = 0; i < NVerts; i++ )
{
DRAW_Set2DVertInVCache( i,
VertList.X, VertList.Y,
VertList.U, VertList.V,
VertList.C );
}
}
//
// Render the triangles.
//
// If needed, start with a single triangle.
if( NTris & 0x01 )
{
ASSERT( IndexList[0] < NVerts );
ASSERT( IndexList[1] < NVerts );
ASSERT( IndexList[2] < NVerts );
gSP1Triangle( pDList++, IndexList[0],
IndexList[1],
IndexList[2],
0 );
IndexList += 3;
NTris -= 1;
}
// Draw as many pairs of triangles as needed to finish.
while( NTris )
{
ASSERT( IndexList[0] < NVerts );
ASSERT( IndexList[1] < NVerts );
ASSERT( IndexList[2] < NVerts );
ASSERT( IndexList[3] < NVerts );
ASSERT( IndexList[4] < NVerts );
ASSERT( IndexList[5] < NVerts );
gSP2Triangles( pDList++, IndexList[0],
IndexList[1],
IndexList[2],
0,
IndexList[3],
IndexList[4],
IndexList[5],
0 );
IndexList += 6;
NTris -= 2;
}
}
///////////////////////////////////////////////////////////////////////////
void DRAW_Sprite( f32 X, f32 Y, f32 Z, // Hot spot (2D Left-Top), (3D Center)
f32 W, f32 H, // (2D pixel W&H), (3D World W&H)
color Color )
{
ASSERT( N64_RenderContext() );
ASSERT( DrawModeDefined );
// Make sure we are not in a forced mode.
DRAW_ForceLineMode ( FALSE );
DRAW_ForceNoTexture( FALSE );
// And finally...
DRAW_MegaRectangle( X, Y, Z,
W, H,
0, 0,
1, 1,
Color,
Color,
Color,
Color );
}
///////////////////////////////////////////////////////////////////////////
void DRAW_SpriteUV( f32 X, f32 Y, f32 Z, // Hot spot (2D Left-Top), (3D Center)
f32 W, f32 H, // (2D pixel W&H), (3D World W&H)
f32 U0, f32 V0, // Upper Left UV [0.0 - 1.0]
f32 U1, f32 V1, // Bottom Right UV [0.0 - 1.0]
color Color )
{
ASSERT( N64_RenderContext() );
ASSERT( DrawModeDefined );
// Make sure we are not in a forced mode.
DRAW_ForceLineMode ( FALSE );
DRAW_ForceNoTexture( FALSE );
// And finally...
DRAW_MegaRectangle( X, Y, Z,
W, H,
U0, V0,
U1, V1,
Color,
Color,
Color,
Color );
}
///////////////////////////////////////////////////////////////////////////
void DRAW_Rectangle( f32 X, f32 Y, f32 Z, // Hot spot (2D Left-Top), (3D Center)
f32 W, f32 H, // (2D pixel W&H), (3D World W&H)
color TLColor, // Top Left color
color TRColor, // Top Right color
color BLColor, // Bottom Left color
color BRColor ) // Bottom Right color
{
ASSERT( N64_RenderContext() );
ASSERT( DrawModeDefined );
// Make sure we do not use a texture. Force it if needed.
DRAW_ForceLineMode ( FALSE );
DRAW_ForceNoTexture( TRUE );
// And finally...
DRAW_MegaRectangle( X, Y, Z,
W, H,
0, 0,
0, 0,
TLColor,
TRColor,
BLColor,
BRColor );
}
///////////////////////////////////////////////////////////////////////////