Implement spritebatch properly.

This commit is contained in:
2026-03-22 09:13:42 -05:00
parent 66ebcb1608
commit ca0e9fc3b2
19 changed files with 205 additions and 142 deletions

View File

@@ -21,9 +21,10 @@ errorret_t meshInitGL(
mesh->primitiveType = primitiveType;
mesh->vertexCount = vertexCount;
mesh->vertices = vertices;
#ifdef DUSK_OPENGL_LEGACY
mesh->vertices = vertices;
// Nothing needed.
#else
// Generate Vertex Buffer Object
glGenBuffers(1, &mesh->vboId);
@@ -34,7 +35,7 @@ errorret_t meshInitGL(
GL_ARRAY_BUFFER,
vertexCount * sizeof(meshvertex_t),
vertices,
GL_STATIC_DRAW
GL_DYNAMIC_DRAW
);
errorChain(errorGLCheck());
@@ -93,6 +94,27 @@ errorret_t meshInitGL(
errorOk();
}
errorret_t meshFlushGL(
meshgl_t *mesh,
const int32_t vertOffset,
const int32_t vertCount
) {
#ifdef DUSK_OPENGL_LEGACY
// Nothing doing, we use the glClientState stuff.
#else
glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId);
errorChain(errorGLCheck());
glBufferData(
GL_ARRAY_BUFFER,
vertCount * sizeof(meshvertex_t),
&mesh->vertices[vertOffset],
GL_DYNAMIC_DRAW
);
errorChain(errorGLCheck());
#endif
errorOk();
}
errorret_t meshDrawGL(
const meshgl_t *mesh,
const int32_t offset,

View File

@@ -18,9 +18,10 @@ typedef enum {
typedef struct {
int32_t vertexCount;
meshprimitivetypegl_t primitiveType;
const meshvertex_t *vertices;
#ifdef DUSK_OPENGL_LEGACY
const meshvertex_t *vertices;
// Nothing needed
#else
GLuint vaoId;
GLuint vboId;
@@ -43,6 +44,20 @@ errorret_t meshInitGL(
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.
*

View File

@@ -12,6 +12,7 @@ typedef meshprimitivetypegl_t meshprimitivetypeplatform_t;
typedef meshgl_t meshplatform_t;
#define meshInitPlatform meshInitGL
#define meshFlushPlatform meshFlushGL
#define meshDrawPlatform meshDrawGL
#define meshGetVertexCountPlatform meshGetVertexCountGL
#define meshDisposePlatform meshDisposeGL