Files
dusk/src/dusk/display/renderpipeline.h
T
2026-06-18 07:51:09 -05:00

69 lines
2.4 KiB
C

/**
* 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 "entity/component/display/entityrenderable.h"
#include "display/shader/shader.h"
#include "util/sort.h"
typedef struct {
entityid_t entityId;
componentid_t componentId;
/**
* Precomputed position component ID, or COMPONENT_ID_INVALID if the entity
* has no position. Used for secondary sort and model-matrix batching.
*/
componentid_t posComp;
int8_t effectivePriority;
} renderpipelineentry_t;
/**
* Returns the effective render priority for a renderable. When the
* renderable's explicit priority is non-zero that value is returned directly;
* otherwise an automatic value is derived from the renderable type and display
* state flags.
*
* @param r The renderable component data.
* @return Effective priority: lower renders first, higher renders last.
*/
int8_t renderPipelineGetPriority(const entityrenderable_t *r);
/**
* sortcompare_t comparator for renderpipelineentry_t. Primary sort by
* effectivePriority ascending. Secondary sort: entries with no position
* component (posComp == COMPONENT_ID_INVALID) sort before entries with a
* position component, grouping them to reduce redundant identity matrix
* uploads.
*
* @param a Pointer to the first renderpipelineentry_t.
* @param b Pointer to the second renderpipelineentry_t.
* @return Negative, zero, or positive.
*/
int_t renderPipelineCompare(const void *a, const void *b);
/**
* Returns the shader that will be used to render the given renderable.
* SPRITEBATCH and CUSTOM default to SHADER_UNLIT; SHADER_MATERIAL uses the
* shader indexed by the material's shaderType field in SHADER_LIST_DEFS.
*
* @param r The renderable component data.
* @return Pointer to the shader, never NULL.
*/
shader_t *renderPipelineGetShader(const entityrenderable_t *r);
/**
* Renders all entities with renderable components in priority order.
* Lower priority renders first (behind); higher renders last (on top).
* When priority is 0 the effective value is derived from the renderable's type
* and flags; otherwise the explicit priority is used directly.
*
* @param cameraId The entity ID of the active camera, or ENTITY_ID_INVALID.
* @return Error state.
*/
errorret_t renderPipeline(const entityid_t cameraId);