archivemuh
This commit is contained in:
75
archive/dusksdl2/display/spritebatch/spritebatch.c
Normal file
75
archive/dusksdl2/display/spritebatch/spritebatch.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "spritebatch.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "console/console.h"
|
||||
|
||||
spritebatch_t SPRITEBATCH;
|
||||
|
||||
void spriteBatchInit() {
|
||||
SPRITEBATCH.spriteCount = 0;
|
||||
SPRITEBATCH.currentTexture = NULL;
|
||||
|
||||
meshInit(
|
||||
&SPRITEBATCH.mesh,
|
||||
GL_TRIANGLES,
|
||||
SPRITEBATCH_VERTEX_COUNT,
|
||||
&SPRITEBATCH.vertices[0]
|
||||
);
|
||||
}
|
||||
|
||||
void spriteBatchPush(
|
||||
texture_t *texture,
|
||||
const float_t minX,
|
||||
const float_t minY,
|
||||
const float_t maxX,
|
||||
const float_t maxY,
|
||||
const uint8_t r,
|
||||
const uint8_t g,
|
||||
const uint8_t b,
|
||||
const uint8_t a,
|
||||
const float_t u0,
|
||||
const float_t v0,
|
||||
const float_t u1,
|
||||
const float_t v1
|
||||
) {
|
||||
// Need to flush?
|
||||
if(
|
||||
SPRITEBATCH.currentTexture != texture ||
|
||||
SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX
|
||||
) {
|
||||
spriteBatchFlush();
|
||||
SPRITEBATCH.currentTexture = texture;
|
||||
}
|
||||
|
||||
quadBuffer(
|
||||
&SPRITEBATCH.vertices[SPRITEBATCH.spriteCount * QUAD_VERTEX_COUNT],
|
||||
minX, minY, maxX, maxY,
|
||||
r, g, b, a,
|
||||
u0, v0, u1, v1
|
||||
);
|
||||
|
||||
SPRITEBATCH.spriteCount++;
|
||||
}
|
||||
|
||||
void spriteBatchClear() {
|
||||
SPRITEBATCH.spriteCount = 0;
|
||||
SPRITEBATCH.currentTexture = NULL;
|
||||
}
|
||||
|
||||
void spriteBatchFlush() {
|
||||
if(SPRITEBATCH.spriteCount == 0) return;
|
||||
textureBind(SPRITEBATCH.currentTexture);
|
||||
meshDraw(&SPRITEBATCH.mesh, 0, QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount);
|
||||
spriteBatchClear();
|
||||
}
|
||||
|
||||
void spriteBatchDispose() {
|
||||
meshDispose(&SPRITEBATCH.mesh);
|
||||
}
|
Reference in New Issue
Block a user