2017-02-09 04:30:25 +01:00
|
|
|
#include "internal.h"
|
2014-12-20 21:34:19 +01:00
|
|
|
|
2015-09-07 14:47:20 +02:00
|
|
|
void C3D_DrawElements(GPU_Primitive_t primitive, int count, int type, const void* indices)
|
2014-12-20 21:34:19 +01:00
|
|
|
{
|
2015-09-07 14:47:20 +02:00
|
|
|
C3D_Context* ctx = C3Di_GetContext();
|
2015-11-20 17:25:50 +01:00
|
|
|
u32 pa = osConvertVirtToPhys(indices);
|
2015-09-07 14:47:20 +02:00
|
|
|
u32 base = ctx->bufInfo.base_paddr;
|
|
|
|
if (pa < base) return;
|
|
|
|
|
2014-12-20 21:34:19 +01:00
|
|
|
C3Di_UpdateContext();
|
|
|
|
|
|
|
|
// Set primitive type
|
2017-01-29 21:44:12 +01:00
|
|
|
GPUCMD_AddMaskedWrite(GPUREG_PRIMITIVE_CONFIG, 2, primitive != GPU_TRIANGLES ? primitive : GPU_GEOMETRY_PRIM);
|
2015-12-05 14:26:21 +01:00
|
|
|
// Start a new primitive (breaks off a triangle strip/fan)
|
|
|
|
GPUCMD_AddWrite(GPUREG_RESTART_PRIMITIVE, 1);
|
2015-09-07 14:47:20 +02:00
|
|
|
// Configure the index buffer
|
|
|
|
GPUCMD_AddWrite(GPUREG_INDEXBUFFER_CONFIG, (pa - base) | (type << 31));
|
2014-12-20 21:34:19 +01:00
|
|
|
// Number of vertices
|
2015-09-07 14:47:20 +02:00
|
|
|
GPUCMD_AddWrite(GPUREG_NUMVERTICES, count);
|
2015-09-07 19:31:48 +02:00
|
|
|
// First vertex
|
|
|
|
GPUCMD_AddWrite(GPUREG_VERTEX_OFFSET, 0);
|
2016-07-20 17:38:05 +02:00
|
|
|
// Enable triangle element drawing mode if necessary
|
|
|
|
if (primitive == GPU_TRIANGLES)
|
|
|
|
{
|
|
|
|
GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG, 2, 0x100);
|
|
|
|
GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG2, 2, 0x100);
|
|
|
|
}
|
2015-12-05 14:26:21 +01:00
|
|
|
// Enable drawing mode
|
|
|
|
GPUCMD_AddMaskedWrite(GPUREG_START_DRAW_FUNC0, 1, 0);
|
|
|
|
// Trigger element drawing
|
|
|
|
GPUCMD_AddWrite(GPUREG_DRAWELEMENTS, 1);
|
|
|
|
// Go back to configuration mode
|
|
|
|
GPUCMD_AddMaskedWrite(GPUREG_START_DRAW_FUNC0, 1, 1);
|
2016-07-20 17:38:05 +02:00
|
|
|
// Disable triangle element drawing mode if necessary
|
|
|
|
if (primitive == GPU_TRIANGLES)
|
|
|
|
{
|
|
|
|
GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG, 2, 0);
|
|
|
|
GPUCMD_AddMaskedWrite(GPUREG_GEOSTAGE_CONFIG2, 2, 0);
|
|
|
|
}
|
2015-12-05 14:26:21 +01:00
|
|
|
// Clear the post-vertex cache
|
|
|
|
GPUCMD_AddWrite(GPUREG_VTX_FUNC, 1);
|
2017-02-15 00:31:27 +01:00
|
|
|
GPUCMD_AddMaskedWrite(GPUREG_PRIMITIVE_CONFIG, 0x8, 0);
|
|
|
|
GPUCMD_AddMaskedWrite(GPUREG_PRIMITIVE_CONFIG, 0x8, 0);
|
2014-12-20 21:34:19 +01:00
|
|
|
|
2015-09-20 14:04:50 +02:00
|
|
|
C3Di_GetContext()->flags |= C3DiF_DrawUsed;
|
2014-12-20 21:34:19 +01:00
|
|
|
}
|