Files
dusk/src/duskdolphin/display/mesh/meshdolphin.c
Dominic Masters d21cd7f78b
Some checks failed
Build Dusk / run-tests (push) Failing after 14s
Build Dusk / build-linux (push) Failing after 15s
Build Dusk / build-psp (push) Failing after 22s
Build Dusk / build-gamecube (push) Failing after 18s
Build Dusk / build-wii (push) Failing after 15s
Update error and debug logging methods
2026-03-11 10:33:43 -05:00

79 lines
2.3 KiB
C

/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "display/mesh/mesh.h"
#include "display/texture/texture.h"
#include "assert/assert.h"
errorret_t meshInitDolphin(
meshdolphin_t *mesh,
const meshprimitivetypedolphin_t primitiveType,
const int32_t vertexCount,
const meshvertex_t *vertices
) {
assertNotNull(mesh, "Mesh cannot be null.");
assertNotNull(vertices, "Vertices cannot be null.");
assertTrue(vertexCount > 0, "Vertex count must be greater than 0.");
mesh->primitiveType = primitiveType;
mesh->vertexCount = vertexCount;
mesh->vertices = vertices;
errorOk();
}
errorret_t meshDrawDolphin(
const meshdolphin_t *mesh,
const int32_t vertexOffset,
const int32_t vertexCount
) {
assertNotNull(mesh, "Mesh cannot be NULL.");
assertTrue(vertexOffset >= 0, "Vertex offset must be >= 0");
assertTrue(vertexCount > 0, "Vertex count must be > 0");
assertTrue(
vertexOffset + vertexCount <= mesh->vertexCount,
"Requested vertex range is invalid"
);
assertTrue(vertexCount <= UINT16_MAX, "Vertex count exceeds GX limit");
// Matches vertex format described in displaydolphin.c
assertTrue(sizeof(color_t) == 4, "color_t must be exactly 4 bytes");
assertTrue(offsetof(meshvertex_t, color) == 0, "color offset wrong");
assertTrue(offsetof(meshvertex_t, uv) == 4, "uv offset wrong");
assertTrue(offsetof(meshvertex_t, pos) == 12, "pos offset wrong");
textureDolphinUploadTEV();
DCFlushRange(
(void*)&mesh->vertices[vertexOffset],
sizeof(meshvertex_t) * vertexCount
);
const uint8_t stride = (uint8_t)sizeof(meshvertex_t);
GX_SetArray(GX_VA_POS, (void*)&mesh->vertices[vertexOffset].pos[0], stride);
GX_SetArray(GX_VA_CLR0, (void*)&mesh->vertices[vertexOffset].color.r, stride);
GX_SetArray(GX_VA_TEX0, (void*)&mesh->vertices[vertexOffset].uv[0], stride);
GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)vertexCount);
for(uint16_t i = 0; i < (uint16_t)vertexCount; ++i) {
GX_Position1x16(i);
GX_Color1x16(i);
GX_TexCoord1x16(i);
}
GX_End();
errorOk();
}
int32_t meshGetVertexCountDolphin(const meshdolphin_t *mesh) {
assertNotNull(mesh, "Mesh cannot be NULL.");
return mesh->vertexCount;
}
errorret_t meshDisposeDolphin(meshdolphin_t *mesh) {
errorOk();
}