Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDekiRenderSystem.h
More file actions
Latest commit
105 lines (90 loc) · 4.47 KB
/
Copy pathDekiRenderSystem.h
File metadata and controls
105 lines (90 loc) · 4.47 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once
#include<cstdint>
#include<vector>
#include<deki/Engine.h>
#include<deki/Color.h>
#include"DirtyRegion.h"
#include<deki/providers/IRenderSystem.h>
// Forward declarations
namespaceDeki { classObject; }
classCameraComponent;
classDekiRenderer;
classDekiRenderSystem : publicDeki::IRenderSystem
{
private:
uint8_t* m_RenderBuffer;
int32_t m_ScreenWidth;
int32_t m_ScreenHeight;
Deki::ColorFormat m_ColorFormat;
bool m_OwnsBuffer = true;
// Display whose GetRenderBuffer() was last offered to us; adoption is
// attempted once per display so Render() does not re-query when owning.
classDeki::IDisplay* m_AdoptionCheckedDisplay = nullptr;
// Active renderer (non-owning — caller manages lifetime)
DekiRenderer* m_Renderer = nullptr;
// ---- dirty-rect present (RenderingProjectSettings::dirtyTileTracking) ----
// With tracking on, a frame clears only what the previous frame on the
// same buffer drew, and the present covers this frame's draws plus the
// previous frame's (the display still shows those; they are cleared or
// overdrawn now). One history entry per buffer pointer handles displays
// that hand out alternating buffers. Anything the bookkeeping cannot
// vouch for is a full clear and a full present.
bool m_TrackDirty = false;
int32_t m_DirtyAlign = 32; // rectangle alignment (px), a policy not a limit
structBufferHistory
{
constuint8_t* buffer;
DirtyRegion lastDrawn; // what the frame rendered into this buffer drew
bool valid; // false until the buffer has been fully cleared once
};
std::vector<BufferHistory> m_History;
DirtyRegion m_LastDrawn; // the previous frame's draws, whatever buffer
bool m_HaveLastDrawn = false;
bool m_ForceFull = true;
Deki::Color m_LastClearColor;
bool m_HaveClearColor = false;
DirtyRegion m_DrawnScratch;
DirtyRegion m_PresentScratch;
std::vector<Deki::Rect> m_PresentRects;
int32_t m_PresentCount = -1;
BufferHistory& HistoryFor(constuint8_t* buffer);
voidResetDirtyHistory();
public:
DekiRenderSystem();
~DekiRenderSystem() override;
boolSetup(int32_t width, int32_t height, Deki::ColorFormat format) override;
/// Switch to the display's internal buffer when it exists and matches our
/// size. Returns true when the render buffer now points at the display's.
boolTryAdoptDisplayBuffer();
voidRender(Deki::Scene* current_scene) override;
voidClearBuffer(uint8_t r, uint8_t g, uint8_t b);
voidClearBuffer(const Deki::Color& color);
/// Fill [x, x+w) x [y, y+h) of the framebuffer (clipped) with a colour.
voidClearRect(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t r, uint8_t g, uint8_t b);
// Dirty-rect present. Setup() reads the project setting; hosts and tests
// can override it here (resets the history, so the next frame is full).
voidSetDirtyTracking(bool enabled, int32_t alignment);
boolIsDirtyTracking() const { return m_TrackDirty; }
voidMarkAllDirty() override { m_ForceFull = true; }
const Deki::Rect* GetPresentRects(int32_t* count) constoverride;
// Renderer management
voidSetRenderer(DekiRenderer* renderer) override { m_Renderer = renderer; }
DekiRenderer* GetRenderer() constoverride { return m_Renderer; }
// Access methods for external systems (like HAL)
constuint8_t* GetFrameBuffer() constoverride { return m_RenderBuffer; }
int32_tGetScreenWidth() constoverride { return m_ScreenWidth; }
int32_tGetScreenHeight() constoverride { return m_ScreenHeight; }
Deki::ColorFormat GetColorFormat() constoverride { return m_ColorFormat; }
// Pixel operations (optimized for fast execution)
voidGetPixel(int32_t x, int32_t y, uint8_t* r, uint8_t* g, uint8_t* b) const;
Deki::Color GetPixel(int32_t x, int32_t y) const;
intGetBytesPerPixel(Deki::ColorFormat format);
// Deki::IRenderSystem interface — delegates to the static implementation
voidRenderToBuffer(Deki::Scene* scene, Deki::ICamera* camera,
uint8_t* buffer, int32_t width, int32_t height,
Deki::ColorFormat format) override;
// Static render function (the actual implementation)
staticvoidRenderToBufferStatic(Deki::Scene* scene, Deki::ICamera* camera,
uint8_t* buffer, int32_t width, int32_t height,
Deki::ColorFormat format);
};