Game no longer crashes on Dolphin
This commit is contained in:
73
src/duskdolphin/display/mesh/meshdolphin.c
Normal file
73
src/duskdolphin/display/mesh/meshdolphin.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* 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"
|
||||
);
|
||||
|
||||
// Prepare Vertex descriptor
|
||||
DCFlushRange(
|
||||
(void*)&mesh->vertices[vertexOffset],
|
||||
sizeof(meshvertex_t) * vertexCount
|
||||
);
|
||||
|
||||
const u8 stride = (u8)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, stride);
|
||||
GX_SetArray(GX_VA_TEX0, (void*)&mesh->vertices[vertexOffset].uv[0], stride);
|
||||
|
||||
textureDolphinUploadTEV();
|
||||
|
||||
GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)vertexCount);
|
||||
for(u16 i = 0; i < (u16)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();
|
||||
}
|
||||
Reference in New Issue
Block a user