From b92b8da6e4d91be47fd92cd2e1b5a002f9dbe560 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 12 Apr 2022 15:15:51 -0700 Subject: [PATCH] more API revisions --- include/Wellspring.h | 34 ++++++++++++++------------------ src/Wellspring.c | 46 ++++++++++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/include/Wellspring.h b/include/Wellspring.h index 263d457..bdb43b4 100644 --- a/include/Wellspring.h +++ b/include/Wellspring.h @@ -74,12 +74,6 @@ typedef struct Wellspring_FontRange uint8_t oversampleV; } Wellspring_FontRange; -typedef struct Wellspring_GlyphQuad -{ - float x0, y0, s0, t0; // top-left - float x1, y1, s1, t1; // bottom-right; -} Wellspring_GlyphQuad; - typedef struct Wellspring_Color { uint8_t r, g, b, a; @@ -95,7 +89,7 @@ typedef struct Wellspring_Vertex /* API definition */ WELLSPRINGAPI Wellspring_Packer* Wellspring_CreatePacker( - uint8_t *fontBytes, + const uint8_t *fontBytes, uint32_t fontBytesLength, uint32_t width, uint32_t height, @@ -109,22 +103,23 @@ WELLSPRINGAPI uint32_t Wellspring_PackFontRanges( uint32_t numRanges ); -/* This data must be uploaded to a texture before you render! +/* Copies pixel data into the given byte array. + * This data must be uploaded to a texture before you render! * The pixel data also becomes outdated if you call PackFontRanges. * Length is width * height. */ WELLSPRINGAPI void Wellspring_GetPixels( Wellspring_Packer *packer, - uint8_t **pData + uint8_t *pData ); /* Batches are not thread-safe, recommend one batch per thread. */ -WELLSPRINGAPI Wellspring_TextBatch* Wellspring_TextBatchCreate(); +WELLSPRINGAPI Wellspring_TextBatch* Wellspring_CreateTextBatch(); /* Also restarts the batch */ -WELLSPRINGAPI void Wellspring_TextBatchStart(Wellspring_TextBatch *textBatch); +WELLSPRINGAPI void Wellspring_StartTextBatch(Wellspring_TextBatch *textBatch); -WELLSPRINGAPI uint8_t Wellspring_DrawTextBatched( +WELLSPRINGAPI uint8_t Wellspring_Draw( Wellspring_TextBatch *textBatch, Wellspring_Packer *packer, float x, @@ -135,20 +130,19 @@ WELLSPRINGAPI uint8_t Wellspring_DrawTextBatched( uint32_t strLengthInBytes ); -WELLSPRINGAPI void Wellspring_TextBatchGetBufferLengths( +WELLSPRINGAPI void Wellspring_GetBufferLengths( Wellspring_TextBatch *textBatch, - uint32_t *pVertexLength, - uint32_t *pIndexLength + uint32_t *pVertexCount, + uint32_t *pIndexCount ); -WELLSPRINGAPI void Wellspring_TextBatchGetBuffers( +WELLSPRINGAPI void Wellspring_GetBufferData( Wellspring_TextBatch *textBatch, - Wellspring_Vertex **pVertexBuffer, - uint32_t **pIndexBuffer + Wellspring_Vertex *pVertexBuffer, + uint32_t *pIndexBuffer ); -WELLSPRINGAPI void Wellspring_TextBatchDestroy(Wellspring_TextBatch *textBatch); - +WELLSPRINGAPI void Wellspring_DestroyTextBatch(Wellspring_TextBatch *textBatch); WELLSPRINGAPI void Wellspring_DestroyPacker(Wellspring_Packer *packer); /* Function defines */ diff --git a/src/Wellspring.c b/src/Wellspring.c index e6c2c15..c5f5758 100644 --- a/src/Wellspring.c +++ b/src/Wellspring.c @@ -137,7 +137,7 @@ uint32_t Wellspring_LinkedVersion(void) } Wellspring_Packer* Wellspring_CreatePacker( - uint8_t *fontBytes, + const uint8_t *fontBytes, uint32_t fontBytesLength, uint32_t width, uint32_t height, @@ -216,13 +216,17 @@ uint32_t Wellspring_PackFontRanges( void Wellspring_GetPixels( Wellspring_Packer *packer, - uint8_t **pData + uint8_t *pData ) { Packer* myPacker = (Packer*) packer; - *pData = myPacker->pixels; + Wellspring_memcpy( + pData, + myPacker->pixels, + sizeof(uint8_t) * myPacker->width * myPacker->height + ); } -Wellspring_TextBatch* Wellspring_TextBatchCreate() +Wellspring_TextBatch* Wellspring_CreateTextBatch() { Batch *batch = Wellspring_malloc(sizeof(Batch)); @@ -237,14 +241,14 @@ Wellspring_TextBatch* Wellspring_TextBatchCreate() return (Wellspring_TextBatch*) batch; } -void Wellspring_TextBatchStart(Wellspring_TextBatch *textBatch) +void Wellspring_StartTextBatch(Wellspring_TextBatch *textBatch) { Batch *batch = (Batch*) textBatch; batch->vertexCount = 0; batch->indexCount = 0; } -uint8_t Wellspring_DrawTextBatched( +uint8_t Wellspring_Draw( Wellspring_TextBatch *textBatch, Wellspring_Packer *packer, float x, @@ -373,27 +377,35 @@ uint8_t Wellspring_DrawTextBatched( return 1; } -void Wellspring_TextBatchGetBufferLengths( +void Wellspring_GetBufferLengths( Wellspring_TextBatch *textBatch, - uint32_t *pVertexLength, - uint32_t *pIndexLength + uint32_t *pVertexCount, + uint32_t *pIndexCount ) { Batch *batch = (Batch*) textBatch; - *pVertexLength = batch->vertexCount; - *pIndexLength = batch->indexCount; + *pVertexCount = batch->vertexCount; + *pIndexCount = batch->indexCount; } -void Wellspring_TextBatchGetBuffers( +void Wellspring_GetBufferData( Wellspring_TextBatch *textBatch, - Wellspring_Vertex **pVertexBuffer, - uint32_t **pIndexBuffer + Wellspring_Vertex *pVertexBuffer, + uint32_t *pIndexBuffer ) { Batch *batch = (Batch*) textBatch; - *pVertexBuffer = batch->vertices; - *pIndexBuffer = batch->indices; + Wellspring_memcpy( + pVertexBuffer, + batch->vertices, + sizeof(Wellspring_Vertex) * batch->vertexCount + ); + Wellspring_memcpy( + pIndexBuffer, + batch->indices, + sizeof(uint32_t) * batch->indexCount + ); } -void Wellspring_TextBatchDestroy(Wellspring_TextBatch *textBatch) +void Wellspring_DestroyTextBatch(Wellspring_TextBatch *textBatch) { Batch *batch = (Batch*) textBatch; Wellspring_free(batch->vertices);