Reshuffled

This commit is contained in:
2021-04-19 21:30:34 +10:00
parent eca6c56d00
commit 365a57ff5a
45 changed files with 218 additions and 140 deletions

59
src/display/spritebatch.c Normal file
View File

@ -0,0 +1,59 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "spritebatch.h"
spritebatch_t * spriteBatchCreate(int32_t maxSprites) {
spritebatch_t *batch = malloc(sizeof(spritebatch_t));
if(batch == NULL) return NULL;
batch->maxSprites = maxSprites;
batch->currentSprite = 0;
batch->primitive = primitiveCreate(
maxSprites*QUAD_VERTICE_COUNT, maxSprites*QUAD_INDICE_COUNT
);
if(batch == NULL) {
free(batch);
return NULL;
}
return batch;
}
void spriteBatchQuad(spritebatch_t *spriteBatch, int32_t index,
float x, float y, float z, float width, float height,
float u0, float v0, float u1, float v1
) {
if(index == -1) {
index = spriteBatch->currentSprite++;
} else {
spriteBatch->currentSprite = mathMax(index, spriteBatch->currentSprite);
}
quadBuffer(spriteBatch->primitive, z,
x, y, u0, v0,
x+width, y+height, u1, v1,
index*QUAD_VERTICE_COUNT, index*QUAD_INDICE_COUNT
);
}
void spriteBatchFlush(spritebatch_t *spriteBatch) {
spriteBatch->currentSprite = 0;
}
void spriteBatchDraw(spritebatch_t *spriteBatch, int32_t index, int32_t count) {
if(count == -1) count = spriteBatch->currentSprite;
primitiveDraw(spriteBatch->primitive,
index*QUAD_INDICE_COUNT, count*QUAD_INDICE_COUNT
);
}
void spriteBatchDispose(spritebatch_t *spriteBatch) {
primitiveDispose(spriteBatch->primitive);
free(spriteBatch);
}