/** * Copyright (c) 2025 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "mesh.h" #include "util/memory.h" #include "assert/assert.h" #include "console/console.h" void meshInit( mesh_t *mesh, const GLenum 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"); memoryZero(mesh, sizeof(mesh_t)); mesh->primitiveType = primitiveType; mesh->vertexCount = vertexCount; mesh->vertices = vertices; } void meshDraw( const mesh_t *mesh, const int32_t vertexOffset, const int32_t vertexCount ) { const int32_t offset = vertexOffset == -1 ? 0 : vertexOffset; const int32_t count = vertexCount == -1 ? mesh->vertexCount : vertexCount; assertNotNull(mesh, "Mesh cannot be NULL"); assertTrue(offset >= 0, "Vertex offset must be non-negative"); assertTrue(count >= 0, "Vertex count must be non-negative"); assertTrue(offset + count <= mesh->vertexCount, "Vertex offset + count must not exceed vertex count" ); #if 1 // PSP style pointer legacy OpenGL const GLsizei stride = sizeof(meshvertex_t); glColorPointer( MESH_VERTEX_COLOR_SIZE, GL_UNSIGNED_BYTE, stride, (const GLvoid*)&mesh->vertices[offset].color[0] ); glTexCoordPointer( MESH_VERTEX_UV_SIZE, GL_FLOAT, stride, (const GLvoid*)&mesh->vertices[offset].uv[0] ); glVertexPointer( MESH_VERTEX_POS_SIZE, GL_FLOAT, stride, (const GLvoid*)&mesh->vertices[offset].pos[0] ); glDrawArrays( mesh->primitiveType, 0, count ); #else #error "Need to support modern OpenGL with VAOs and VBOs" #endif } void meshDispose(mesh_t *mesh) { assertNotNull(mesh, "Mesh cannot be NULL"); memoryZero(mesh, sizeof(mesh_t)); }