89 lines
2.2 KiB
C
89 lines
2.2 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "error/error.h"
|
|
#include "display/mesh/meshvertex.h"
|
|
|
|
typedef enum {
|
|
MESH_PRIMITIVE_TYPE_TRIANGLES = GL_TRIANGLES,
|
|
MESH_PRIMITIVE_TYPE_LINES = GL_LINES,
|
|
MESH_PRIMITIVE_TYPE_POINTS = GL_POINTS,
|
|
} meshprimitivetypegl_t;
|
|
|
|
typedef struct {
|
|
int32_t vertexCount;
|
|
meshprimitivetypegl_t primitiveType;
|
|
const meshvertex_t *vertices;
|
|
|
|
#ifdef DUSK_OPENGL_LEGACY
|
|
// Nothing needed
|
|
#else
|
|
GLuint vaoId;
|
|
GLuint vboId;
|
|
#endif
|
|
} meshgl_t;
|
|
|
|
/**
|
|
* Initializes a mesh for OpenGL.
|
|
*
|
|
* @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 errorret_t indicating success or failure.
|
|
*/
|
|
errorret_t meshInitGL(
|
|
meshgl_t *mesh,
|
|
const meshprimitivetypegl_t primitiveType,
|
|
const int32_t vertexCount,
|
|
const meshvertex_t *vertices
|
|
);
|
|
|
|
/**
|
|
* Flushes the vertices (stored in memory) to the GPU.
|
|
*
|
|
* @param mesh Mesh to flush vertices for.
|
|
* @param vertOffset First vertice index to flush.
|
|
* @param vertCount Count of vertices to flush.
|
|
* @return Error state.
|
|
*/
|
|
errorret_t meshFlushGL(
|
|
meshgl_t *mesh,
|
|
const int32_t vertOffset,
|
|
const int32_t vertCount
|
|
);
|
|
|
|
/**
|
|
* Draws a mesh using OpenGL.
|
|
*
|
|
* @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 errorret_t indicating success or failure.
|
|
*/
|
|
errorret_t meshDrawGL(
|
|
const meshgl_t *mesh,
|
|
const int32_t vertexOffset,
|
|
const int32_t vertexCount
|
|
);
|
|
|
|
/**
|
|
* Gets the vertex count of a mesh used for OpenGL.
|
|
*
|
|
* @param mesh The mesh to get the vertex count from.
|
|
* @return The vertex count of the mesh.
|
|
*/
|
|
int32_t meshGetVertexCountGL(const meshgl_t *mesh);
|
|
|
|
/**
|
|
* Disposes a mesh used for OpenGL.
|
|
*
|
|
* @param mesh The mesh to dispose.
|
|
* @return An errorret_t indicating success or failure.
|
|
*/
|
|
errorret_t meshDisposeGL(meshgl_t *mesh); |