Elevate Engine 1
Loading...
Searching...
No Matches
Elevate::RenderBucket Class Reference

#include <RenderBucket.h>

Public Types

enum  Type : uint8_t {
  ShadowMap , GBuffer , Opaque , Transparent ,
  UI , Debug , Count
}
 

Public Member Functions

void Submit (const RenderCommand &command)
 
void Sort ()
 
void Flush ()
 
void Clear ()
 
size_t GetCommandCount () const
 
size_t GetMemoryUsage () const
 

Protected Attributes

std::vector< RenderCommandm_commands
 
bool m_isSorted = true
 

Detailed Description

Definition at line 8 of file RenderBucket.h.

Member Enumeration Documentation

◆ Type

Enumerator
ShadowMap 
GBuffer 
Opaque 
Transparent 
UI 
Debug 
Count 

Definition at line 11 of file RenderBucket.h.

12 {
14 GBuffer,
15 Opaque,
17 UI,
18 Debug,
19 Count // Only used to keep the number of bucket at compile time
20 };

Member Function Documentation

◆ Clear()

void Elevate::RenderBucket::Clear ( )

Definition at line 25 of file RenderBucket.cpp.

26 {
27 m_commands.clear();
28 m_isSorted = false;
29 }
std::vector< RenderCommand > m_commands

◆ Flush()

void Elevate::RenderBucket::Flush ( )

Definition at line 12 of file RenderBucket.cpp.

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 }
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

◆ GetCommandCount()

size_t Elevate::RenderBucket::GetCommandCount ( ) const

Definition at line 77 of file RenderBucket.cpp.

78 {
79 return m_commands.size();
80 }

◆ GetMemoryUsage()

size_t Elevate::RenderBucket::GetMemoryUsage ( ) const

Definition at line 82 of file RenderBucket.cpp.

83 {
84 return GetCommandCount() * sizeof(RenderCommand);
85 }
size_t GetCommandCount() const

◆ Sort()

void Elevate::RenderBucket::Sort ( )

Definition at line 31 of file RenderBucket.cpp.

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 }

◆ Submit()

void Elevate::RenderBucket::Submit ( const RenderCommand command)

Definition at line 6 of file RenderBucket.cpp.

7 {
8 m_commands.push_back(command);
9 m_isSorted = false;
10 }

Member Data Documentation

◆ m_commands

std::vector<RenderCommand> Elevate::RenderBucket::m_commands
protected

Definition at line 31 of file RenderBucket.h.

◆ m_isSorted

bool Elevate::RenderBucket::m_isSorted = true
protected

Definition at line 32 of file RenderBucket.h.


The documentation for this class was generated from the following files: