Files
dusk/archive/old_display_system/display/mesh/mesh.h
T
2026-06-18 20:25:54 -05:00

100 lines
2.6 KiB
C

// Copyright (c) 2026 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/display.h"
#include "display/color.h"
#include "display/mesh/meshplatform.h"
#ifndef meshInitPlatform
#error "meshInitPlatform must be defined"
#endif
#ifndef meshDrawPlatform
#error "meshDrawPlatform must be defined"
#endif
#ifndef meshGetVertexCountPlatform
#error "meshGetVertexCountPlatform must be defined"
#endif
#ifndef meshDisposePlatform
#error "meshDisposePlatform must be defined"
#endif
typedef meshprimitivetypeplatform_t meshprimitivetype_t;
typedef meshplatform_t mesh_t;
/**
* Initializes a mesh.
*
* @param mesh The mesh to initialize.
* @param primitiveType The OpenGL primitive type (e.g., GL_TRIANGLES).
* @param vertexCount The number of vertices in the mesh.
* @param vertices The vertex data for the mesh.
* @return An error indicating success or failure.
*/
errorret_t meshInit(
mesh_t *mesh,
const meshprimitivetype_t primitiveType,
const int32_t vertexCount,
const meshvertex_t *vertices
);
/**
* Instructs the mesh to flush the vertices to the GPU. This is surprisingly
* only really necessary on modern devices, as we tend to let older devices
* read the vertices from the main memory directly.
*
* @param mesh Mesh to flush the vertices for.
* @param vertexOffset Start vertex to flush.
* @param vertexCount Count of vertices to flush, set to -1 for all.
* @return Error state.
*/
errorret_t meshFlush(
mesh_t *mesh,
const int32_t vertexOffset,
const int32_t vertexCount
);
/**
* Draws a mesh.
*
* @param mesh The mesh to draw.
* @param vertexOffset The offset in the vertex array to start drawing from.
* @param vertexCount The number of vertices to draw. If -1, draws all vertices.
* @return An error indicating success or failure.
*/
errorret_t meshDraw(
const mesh_t *mesh,
const int32_t vertexOffset,
const int32_t vertexCount
);
/**
* Gets the axis-aligned bounding box of a mesh.
*
* @param mesh The mesh to get the bounds of.
* @param outMin Output parameter for the minimum corner of the bounding box.
* @param outMax Output parameter for the maximum corner of the bounding box.
*/
void meshGetBounds(
const mesh_t *mesh,
vec3 outMin,
vec3 outMax
);
/**
* Gets the vertex count of a mesh.
*
* @param mesh The mesh to get the vertex count from.
* @return The vertex count of the mesh.
*/
int32_t meshGetVertexCount(const mesh_t *mesh);
/**
* Disposes a mesh.
*
* @param mesh The mesh to dispose.
* @return An error indicating success or failure.
*/
errorret_t meshDispose(mesh_t *mesh);