/** * Copyright (c) 2026 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once #include "entity/entitybase.h" #include "display/mesh/mesh.h" #include "display/shader/shadermaterial.h" #include "display/spritebatch/spritebatch.h" #define ENTITY_RENDERABLE_SPRITEBATCH_SPRITES_MAX 64 typedef enum { ENTITY_RENDERABLE_TYPE_MATERIAL = 0, ENTITY_RENDERABLE_TYPE_SPRITEBATCH, ENTITY_RENDERABLE_TYPE_CALLBACK, } entityrenderabletype_t; typedef errorret_t (*entityrenderablecallback_t)( const entityid_t entityId, const componentid_t componentId, const mat4 view, const mat4 proj, const mat4 model, void *user ); typedef struct { spritebatchsprite_t sprites[ENTITY_RENDERABLE_SPRITEBATCH_SPRITES_MAX]; uint16_t spriteCount; } entityrenderablespritebatch_t; typedef struct { entityrenderabletype_t type; shader_t *shader; union { struct { mesh_t *mesh; shadermaterial_t material; }; entityrenderablespritebatch_t spritebatch; struct { entityrenderablecallback_t callback; void (*userFree)(void *user); void *user; }; }; } entityrenderable_t; /** * Initializes the entity renderable component. Defaults to * ENTITY_RENDERABLE_TYPE_MATERIAL, the unlit shader, white color, no mesh. */ void entityRenderableInit( const entityid_t entityId, const componentid_t componentId ); /** * Disposes the entity renderable component, freeing any callback user data. */ void entityRenderableDispose( const entityid_t entityId, const componentid_t componentId ); /** * Gets the renderable type. */ entityrenderabletype_t entityRenderableGetType( const entityid_t entityId, const componentid_t componentId ); /** * Sets the renderable type. */ void entityRenderableSetType( const entityid_t entityId, const componentid_t componentId, const entityrenderabletype_t type ); /** * Gets the mesh pointer (ENTITY_RENDERABLE_TYPE_MATERIAL only). */ mesh_t * entityRenderableGetMesh( const entityid_t entityId, const componentid_t componentId ); /** * Sets the mesh pointer (ENTITY_RENDERABLE_TYPE_MATERIAL only). */ void entityRenderableSetMesh( const entityid_t entityId, const componentid_t componentId, mesh_t *mesh ); /** * Gets the shader pointer. */ shader_t * entityRenderableGetShader( const entityid_t entityId, const componentid_t componentId ); /** * Sets the shader pointer. */ void entityRenderableSetShader( const entityid_t entityId, const componentid_t componentId, shader_t *shader ); /** * Gets a pointer to the shader material union * (ENTITY_RENDERABLE_TYPE_MATERIAL only). */ shadermaterial_t * entityRenderableGetShaderMaterial( const entityid_t entityId, const componentid_t componentId ); /** * Sets the unlit color (ENTITY_RENDERABLE_TYPE_MATERIAL only). */ void entityRenderableSetColor( const entityid_t entityId, const componentid_t componentId, const color_t color ); /** * Appends a sprite to the spritebatch renderable * (ENTITY_RENDERABLE_TYPE_SPRITEBATCH only). * Does nothing if the sprite buffer is full. */ void entityRenderableSpriteBatchAdd( const entityid_t entityId, const componentid_t componentId, const spritebatchsprite_t *sprite ); /** * Clears all buffered sprites from the spritebatch renderable * (ENTITY_RENDERABLE_TYPE_SPRITEBATCH only). */ void entityRenderableSpriteBatchClear( const entityid_t entityId, const componentid_t componentId );