Files
dusk/src/display/mesh/mesh.h
2025-08-23 10:13:49 -05:00

68 lines
1.5 KiB
C

// Copyright (c) 2025 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/display.h"
typedef enum {
#if DISPLAY_SDL2
MESH_PRIMITIVE_TRIANGLES = GL_TRIANGLES,
MESH_PRIMITIVE_LINES = GL_LINES,
MESH_PRIMITIVE_POINTS = GL_POINTS,
#endif
} meshprimitivetype_t;
#define MESH_VERTEX_COLOR_SIZE 4
#define MESH_VERTEX_UV_SIZE 2
#define MESH_VERTEX_POS_SIZE 3
typedef struct {
#if DISPLAY_SDL2
GLubyte color[MESH_VERTEX_COLOR_SIZE];
GLfloat uv[MESH_VERTEX_UV_SIZE];
GLfloat pos[MESH_VERTEX_POS_SIZE];
#endif
} meshvertex_t;
typedef struct {
const meshvertex_t *vertices;
int32_t vertexCount;
meshprimitivetype_t primitiveType;
} 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.
*/
void meshInit(
mesh_t *mesh,
const meshprimitivetype_t primitiveType,
const int32_t vertexCount,
const meshvertex_t *vertices
);
/**
* 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.
*/
void meshDraw(
const mesh_t *mesh,
const int32_t vertexOffset,
const int32_t vertexCount
);
/**
* Disposes a mesh.
*
* @param mesh The mesh to dispose.
*/
void meshDispose(mesh_t *mesh);