SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
RenderCommandQueue.hpp
Go to the documentation of this file.
1#ifndef _RENDERCOMMANDQUEUE_H
2#define _RENDERCOMMANDQUEUE_H
3
5#include "RenderCommands.hpp"
8
9namespace Sleak {
10 namespace RenderEngine {
11 /// Frame-scoped queue of recorded draw/state commands, replayed into a RenderContext at flush time.
13 public:
14 /// Queues an indexed draw with its vertex/index buffers and constant buffers.
16 RefPtr<BufferBase> vertexBuffer,
17 RefPtr<BufferBase> indexBuffer,
18 List<RefPtr<BufferBase>> constantBuffers,
19 uint32_t indexCount,
20 uint32_t startIndexLocation = 0,
21 int32_t baseVertexLocation = 0,
22 bool castsShadow = true
23 );
24
25 /// Queues a non-indexed draw with its vertex buffer and constant buffers.
26 void SubmitDraw(
27 RefPtr<BufferBase> vertexBuffer,
28 List<RefPtr<BufferBase>> constantBuffers,
29 uint32_t vertexCount,
30 uint32_t startVertexLocation = 0
31 );
32
33 /// Queues a constant buffer bind at the given slot.
35 RefPtr<BufferBase> buffer,
36 uint8_t slot
37 );
38
39 /// Queues a constant buffer write with data captured at submit time.
41 RefPtr<BufferBase> buffer,
42 void* Data,
43 uint16_t Size
44 );
45
46 /// Queues a material bind, switching shader/texture state for subsequent draws.
48
50
52
53 /// Queues an arbitrary callback to run inline with other render commands.
55
56 // Execute all queued commands.
57 // In deferred mode: runs opaque draws in the geometry pass, then triggers the
58 // lighting pass, then runs transparent/custom draws in the forward pass.
59 // In forward mode: runs all commands in order (legacy behavior).
60 void ExecuteCommands(RenderContext* context);
61
62 void ExecuteShadowPass(RenderContext* context);
63
64 bool HasCachedShadowDraws() const { return cachedShadowDraws.GetSize() > 0; }
65
66 /// Drops queued commands for the current frame, keeping the cached shadow draw list.
67 void Clear();
68
69 /// Drops queued commands and the cached shadow draw list.
70 void ClearAll();
71 static void Shutdown();
72
73 void SortCommands();
74 void OptimizeBatching();
75
76 /// Lazily creates and returns the process-wide singleton instance.
78 {
79 Instance = Instance ? Instance : new RenderCommandQueue();
80 return Instance;
81 }
82
83 /// A draw command paired with the transform/bone buffers it needs to replay in the shadow pass.
86 RefPtr<BufferBase> transformBuffer; // last-bound slot-0 buffer
87 RefPtr<BufferBase> boneBuffer; // slot-3 bone UBO for skinned draws
88 };
89
90 private:
91 static constexpr int RETIRE_FRAMES = 3;
92 static RenderCommandQueue* Instance;
94 List<ShadowDrawEntry> cachedShadowDraws;
95 List<ShadowDrawEntry> m_retiredShadowDraws[RETIRE_FRAMES];
96 int m_retireIndex = 0;
97 };
98 }
99}
100
101#endif
Implements a dynamic array-like list for storing and managing a collection of elements.
Definition List.hpp:20
Implements a FIFO (First-In, First-Out) queue data structure.
Definition Queue.hpp:32
std::function< void(RenderContext *)> ExecuteFunction
Frame-scoped queue of recorded draw/state commands, replayed into a RenderContext at flush time.
void Clear()
Drops queued commands for the current frame, keeping the cached shadow draw list.
void SubmitUpdateConstantBuffer(RefPtr< BufferBase > buffer, void *Data, uint16_t Size)
Queues a constant buffer write with data captured at submit time.
void SubmitCustomCommand(CustomCommand::ExecuteFunction function)
Queues an arbitrary callback to run inline with other render commands.
void ExecuteCommands(RenderContext *context)
static RenderCommandQueue * GetInstance()
Lazily creates and returns the process-wide singleton instance.
void SubmitBindMaterial(::Sleak::Material *material)
Queues a material bind, switching shader/texture state for subsequent draws.
void ExecuteShadowPass(RenderContext *context)
void SubmitDrawIndexed(RefPtr< BufferBase > vertexBuffer, RefPtr< BufferBase > indexBuffer, List< RefPtr< BufferBase > > constantBuffers, uint32_t indexCount, uint32_t startIndexLocation=0, int32_t baseVertexLocation=0, bool castsShadow=true)
Queues an indexed draw with its vertex/index buffers and constant buffers.
void ClearAll()
Drops queued commands and the cached shadow draw list.
void SubmitDraw(RefPtr< BufferBase > vertexBuffer, List< RefPtr< BufferBase > > constantBuffers, uint32_t vertexCount, uint32_t startVertexLocation=0)
Queues a non-indexed draw with its vertex buffer and constant buffers.
void SubmitBindConstantBuffer(RefPtr< BufferBase > buffer, uint8_t slot)
Queues a constant buffer bind at the given slot.
Abstract interface for high-level graphics command execution and resource management.
Backend-facing rendering layer shared by the four graphics backends.
RenderMode
Rasterizer fill style for a draw.
RenderFace
Which triangle winding gets culled.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10
A draw command paired with the transform/bone buffers it needs to replay in the shadow pass.