67 lines
1.4 KiB
C
67 lines
1.4 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 "assert/assert.h"
|
|
|
|
errorret_t meshInitGL(
|
|
meshgl_t *mesh,
|
|
const meshprimitivetypegl_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 meshDrawGL(
|
|
const meshgl_t *mesh,
|
|
const int32_t offset,
|
|
const int32_t count
|
|
) {
|
|
// PSP style pointer legacy OpenGL
|
|
const GLsizei stride = sizeof(meshvertex_t);
|
|
|
|
glColorPointer(
|
|
sizeof(color4b_t),
|
|
GL_UNSIGNED_BYTE,
|
|
stride,
|
|
(const GLvoid*)&mesh->vertices[offset].color
|
|
);
|
|
glTexCoordPointer(
|
|
MESH_VERTEX_UV_SIZE,
|
|
GL_FLOAT,
|
|
stride,
|
|
(const GLvoid*)&mesh->vertices[offset].uv
|
|
);
|
|
glVertexPointer(
|
|
MESH_VERTEX_POS_SIZE,
|
|
GL_FLOAT,
|
|
stride,
|
|
(const GLvoid*)&mesh->vertices[offset].pos
|
|
);
|
|
|
|
glDrawArrays(mesh->primitiveType, offset, count);
|
|
|
|
errorOk();
|
|
}
|
|
|
|
int32_t meshGetVertexCountGL(const meshgl_t *mesh) {
|
|
return mesh->vertexCount;
|
|
}
|
|
|
|
errorret_t meshDisposeGL(meshgl_t *mesh) {
|
|
// No dynamic resources to free for this mesh implementation
|
|
errorOk();
|
|
} |