Elevate Engine 1
Loading...
Searching...
No Matches
RenderBucket.cpp
Go to the documentation of this file.
1#include "RenderBucket.h"
3
4namespace Elevate
5{
7 {
8 m_commands.push_back(command);
9 m_isSorted = false;
10 }
11
13 {
14 if (m_commands.empty()) return;
15
16 // Sends each command to be executed by the renderer
17 for (const auto& command : m_commands)
18 {
19 Renderer::Dispatch(command);
20 }
21
22 Clear();
23 }
24
26 {
27 m_commands.clear();
28 m_isSorted = false;
29 }
30
32 {
33 if (m_commands.empty() || m_isSorted) return;
34
35 const size_t n = m_commands.size();
36 std::vector<RenderCommand> tempBuffer(n);
37
38 RenderCommand* src = m_commands.data();
39 RenderCommand* dst = tempBuffer.data();
40
41 const int bitsPerPass = 8;
42 const int bucketCount = 1 << bitsPerPass;
43 const uint32_t mask = bucketCount - 1;
44 const uint16_t keySizeBits = sizeof(m_commands[0].m_SortingKey) * 8;
45
46 for (uint16_t shift = 0; shift < keySizeBits; shift += bitsPerPass)
47 {
48 uint32_t count[bucketCount] = { 0 };
49
50 for (size_t i = 0; i < n; i++)
51 {
52 count[(src[i].m_SortingKey >> shift) & mask]++;
53 }
54
55 for (int i = 1; i < bucketCount; ++i)
56 {
57 count[i] += count[i - 1];
58 }
59
60 for (long long i = (long long)m_commands.size() - 1; i >= 0; --i)
61 {
62 uint32_t bucket = (src[i].m_SortingKey >> shift) & mask;
63 dst[--count[bucket]] = src[i];
64 }
65
66 std::swap(src, dst);
67 }
68
69 if (src != m_commands.data())
70 {
71 std::copy(tempBuffer.begin(), tempBuffer.end(), m_commands.begin());
72 }
73
74 m_isSorted = true;
75 }
76
78 {
79 return m_commands.size();
80 }
81
83 {
84 return GetCommandCount() * sizeof(RenderCommand);
85 }
86}
std::vector< RenderCommand > m_commands
size_t GetCommandCount() const
void Submit(const RenderCommand &command)
size_t GetMemoryUsage() const
static void Dispatch(const RenderCommand &command)
Immediatly process a RenderCommand. Do not use directly unless you know what you are donig.
Definition Renderer.cpp:112