/** * Copyright (c) 2025 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once #include "display/mesh/quad.h" #include "display/texture/texture.h" #define SPRITEBATCH_SPRITES_MAX 128 #define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT) #if DOLPHIN #define SPRITEBATCH_SPRITES_MAX 16 #define SPRITEBATCH_BATCH_COUNT 16 #define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT * SPRITEBATCH_BATCH_COUNT) #endif typedef struct { mesh_t mesh; int32_t spriteCount; texture_t *currentTexture; #if DOLPHIN uint8_t batchIndex; #endif } spritebatch_t; // Have to define these seperately because of alignment in certain platforms. // (Looking at you Dolphin)/ extern meshvertex_t SPRITEBATCH_VERTICES[SPRITEBATCH_VERTEX_COUNT]; extern spritebatch_t SPRITEBATCH; /** * Initializes a sprite batch. * * @param spriteBatch The sprite batch to initialize. */ void spriteBatchInit(); /** * Pushes a sprite to the batch. This basically "queues" it to render (well * technically it is buffering the vertices to the mesh at the moment, but * that is likely to change when we switch to VAOs or VBOs or even Shader UBOs). * * Currently changing texture pointer will cause the buffer to flush but this is * also likely to change in the future. * * @param texture The texture to use for the sprite. * @param minX The minimum x coordinate of the sprite. * @param minY The minimum y coordinate of the sprite. * @param maxX The maximum x coordinate of the sprite. * @param maxY The maximum y coordinate of the sprite. * @param color The color to tint the sprite with. * @param u0 The texture coordinate for the top-left corner of the sprite. * @param v0 The texture coordinate for the top-left corner of the sprite. * @param u1 The texture coordinate for the bottom-right corner of the sprite. * @param v1 The texture coordinate for the bottom-right corner of the sprite. */ void spriteBatchPush( texture_t *texture, const float_t minX, const float_t minY, const float_t maxX, const float_t maxY, const color_t color, const float_t u0, const float_t v0, const float_t u1, const float_t v1 ); /** * Pushes a 3D sprite to the batch. This is like spriteBatchPush but takes * 3D coordinates instead of 2D. * * @param texture The texture to use for the sprite. * @param min The minimum (x,y,z) coordinate of the sprite. * @param max The maximum (x,y,z) coordinate of the sprite. * @param color The color to tint the sprite with. * @param uvMin The texture coordinate for the top-left corner of the sprite. * @param uvMax The texture coordinate for the bottom-right corner of the sprite. */ void spriteBatchPush3D( texture_t *texture, const vec3 min, const vec3 max, const color_t color, const vec2 uvMin, const vec2 uvMax ); /** * Clears the sprite batch. This will mean calling flush renders nothing. */ void spriteBatchClear(); /** * Flushes the sprite batch, rendering all queued sprites. */ void spriteBatchFlush(); /** * Disposes of the sprite batch, freeing any allocated resources. */ void spriteBatchDispose();