More code moving

This commit is contained in:
2026-03-07 12:09:40 -06:00
parent dd048d9b0d
commit 71e6079054
22 changed files with 261 additions and 291 deletions

View File

@@ -11,4 +11,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
# Subdirs
add_subdirectory(framebuffer)
add_subdirectory(texture)
add_subdirectory(texture)
add_subdirectory(mesh)

View File

@@ -6,4 +6,5 @@
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
framebuffergl.c
)

View File

@@ -0,0 +1,10 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
meshgl.c
)

View File

@@ -0,0 +1,67 @@
/**
* 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();
}

View File

@@ -0,0 +1,66 @@
/**
* 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 {
} 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
);
/**
* 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);

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "meshgl.h"
typedef meshprimitivetypegl_t meshprimitivetypeplatform_t;
typedef meshgl_t meshplatform_t;
#define meshInitPlatform meshInitGL
#define meshDrawPlatform meshDrawGL
#define meshGetVertexCountPlatform meshGetVertexCountGL
#define meshDisposePlatform meshDisposeGL