-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStandard2DRenderer.h
More file actions
75 lines (63 loc) · 2.38 KB
/
Copy pathStandard2DRenderer.h
File metadata and controls
75 lines (63 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include "DekiRenderer.h"
#include "RenderPass.h"
#include <cstdint>
#include <utility>
// Forward declarations
class DekiObject;
/**
* @brief Standard 2D renderer with built-in support for sprites, clipping, and sorting groups
*
* This is the default renderer for 2D scenes. It handles:
* - RendererComponent: blits content via QuadBlit
* - ClipComponent: pushes/pops clip rects around children
* - SortingGroupComponent: groups children for sorting
*
* Extensible via:
* - AddPass(): register custom RenderPass objects for new component types
* - AddSortingCallback(): register custom sorting for new component types
*
* Can also be composed inside other renderers (e.g., a 3D renderer
* that uses Standard2DRenderer for UI overlays).
*/
class Standard2DRenderer : public DekiRenderer
{
public:
static constexpr uint32_t RendererTypeID = 0x53324452; // "S2DR"
uint32_t GetRendererType() const override { return RendererTypeID; }
void Render(Scene* scene, const RenderContext& ctx) override;
/**
* @brief Add a custom render pass
* @param pass Non-owning pointer to a RenderPass (caller manages lifetime)
*/
void AddPass(RenderPass* pass);
/**
* @brief Remove a previously added render pass
* @param pass The pass to remove
*/
void RemovePass(RenderPass* pass);
/**
* @brief Add a custom sorting callback for new component types
* @param cb Function that returns true if an object is sortable, setting outOrder
*/
void AddSortingCallback(SortingCallback cb);
/**
* @brief Remove a previously added sorting callback
* @param cb The callback to remove
*/
void RemoveSortingCallback(SortingCallback cb);
private:
static constexpr int MAX_PASSES = 16;
static constexpr int MAX_SORTING_CALLBACKS = 8;
RenderPass* m_Passes[MAX_PASSES] = {};
int m_PassCount = 0;
SortingCallback m_SortingCallbacks[MAX_SORTING_CALLBACKS] = {};
int m_SortingCallbackCount = 0;
void CollectSortableItems(DekiObject* obj,
std::pair<DekiObject*, int>* items, int& count, int maxItems);
void RenderObject(DekiObject* obj, const RenderContext& ctx);
// Built-in component handling
bool GetBuiltinSortingOrder(DekiObject* obj, int32_t& outOrder);
void ExecuteBuiltins(DekiObject* obj, RenderContext& ctx);
void PostExecuteBuiltins(DekiObject* obj, RenderContext& ctx);
};