Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
RenderBin.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32/*The system is similar to the one used in Torque3D (RenderPassMgr / RenderBinManager) as it was used as an inspiration.
33 All credit goes to GarageGames for the idea:
34 - http://garagegames.com/
35 - https://github.com/GarageGames/Torque3D
36 */
37
38#pragma once
39#ifndef DVD_RENDER_BIN_H_
40#define DVD_RENDER_BIN_H_
41
42namespace Divide {
43
44struct Task;
45class GFXDevice;
46class SceneGraphNode;
47class RenderingComponent;
48struct RenderStagePass;
49
50namespace GFX {
51 class CommandBuffer;
52};
53
56 size_t _stateHash{ 0u };
60 bool _hasTransparency{ false };
61};
62
63enum class RenderingOrder : U8 {
64 NONE = 0,
69 COUNT
70};
71
72//Bins can hold certain node types. This is also the order in which nodes will be rendered!
73enum class RenderBinType : U8 {
74 OPAQUE,
75 WATER,
76 TERRAIN,
78 SKY,
80 IMPOSTOR,
81 COUNT
82};
83
84namespace Names {
85 static const char* renderBinType[] = {
86 "OPAQUE", "WATER", "TERRAIN", "TERRAIN_AUX", "SKY", "TRANSLUCENT", "IMPOSTOR", "UNKNOWN"
87 };
88};
89
90static_assert(ArrayCount( Names::renderBinType ) == to_base( RenderBinType::COUNT ) + 1, "RenderBinType name array out of sync!");
91
92struct RenderPackage;
93
94class SceneRenderState;
95class RenderPassManager;
96
97enum class RenderQueueListType : U8 {
98 OCCLUDERS = 0,
100 COUNT
101};
102
103class RenderBin;
107};
108
109using RenderQueuePackages = eastl::fixed_vector<RenderQueuePackage, Config::MAX_VISIBLE_NODES, false>;
110
113 public:
114 using RenderBinStack = eastl::array<RenderBinItem, Config::MAX_VISIBLE_NODES>;
115 using SortedQueue = eastl::fixed_vector<RenderingComponent*, Config::MAX_VISIBLE_NODES, false>;
117
118 RenderBin() = default;
119
120 void sort(RenderBinType type, RenderingOrder renderOrder);
121 void populateRenderQueue(RenderStagePass stagePass, RenderQueuePackages& queueInOut) const;
122 void postRender(const SceneRenderState& renderState, RenderStagePass stagePass, GFX::CommandBuffer& bufferInOut);
123
124 void addNodeToBin(const SceneGraphNode* sgn, RenderStagePass renderStagePass, F32 minDistToCameraSq);
125 void clear() noexcept;
126
127 [[nodiscard]] U16 getSortedNodes(SortedQueue& nodes) const;
128 [[nodiscard]] U16 getBinSize() const noexcept;
129 [[nodiscard]] const RenderBinItem& getItem(const U16 index) const;
130
131 [[nodiscard]] inline bool empty() const noexcept { return getBinSize() == 0; }
132
133 private:
134 std::atomic_ushort _renderBinIndex;
136};
137
139
140}; // namespace Divide
141
142#endif //DVD_RENDER_BIN_H_
constexpr auto ArrayCount(Args &&... args) -> decltype(std::size(FWD(args)...))
#define FWD_DECLARE_MANAGED_CLASS(T)
This class contains a list of "RenderBinItem"'s and stores them sorted depending on designation.
Definition: RenderBin.h:112
eastl::fixed_vector< RenderingComponent *, Config::MAX_VISIBLE_NODES, false > SortedQueue
Definition: RenderBin.h:115
void postRender(const SceneRenderState &renderState, RenderStagePass stagePass, GFX::CommandBuffer &bufferInOut)
Definition: RenderBin.cpp:155
RenderBin()=default
void addNodeToBin(const SceneGraphNode *sgn, RenderStagePass renderStagePass, F32 minDistToCameraSq)
Definition: RenderBin.cpp:123
std::atomic_ushort _renderBinIndex
Definition: RenderBin.h:134
void populateRenderQueue(RenderStagePass stagePass, RenderQueuePackages &queueInOut) const
Definition: RenderBin.cpp:140
U16 getSortedNodes(SortedQueue &nodes) const
Definition: RenderBin.cpp:108
std::array< SortedQueue, to_base(RenderBinType::COUNT)> SortedQueues
Definition: RenderBin.h:116
void sort(RenderBinType type, RenderingOrder renderOrder)
Definition: RenderBin.cpp:16
bool empty() const noexcept
Definition: RenderBin.h:131
eastl::array< RenderBinItem, Config::MAX_VISIBLE_NODES > RenderBinStack
Definition: RenderBin.h:114
RenderBinStack _renderBinStack
Definition: RenderBin.h:135
void clear() noexcept
Definition: RenderBin.cpp:92
const RenderBinItem & getItem(const U16 index) const
Definition: RenderBin.cpp:97
U16 getBinSize() const noexcept
Definition: RenderBin.cpp:103
static const char * renderBinType[]
Definition: RenderBin.h:85
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
eastl::fixed_vector< RenderQueuePackage, Config::MAX_VISIBLE_NODES, false > RenderQueuePackages
Definition: RenderBin.h:109
RenderBinType
Definition: RenderBin.h:73
@ WATER
Water might end up being as expensive as terrain, so these will probably need reshuffling.
@ IMPOSTOR
Impostors should be overlayed over everything since they are a debugging tool.
@ TERRAIN_AUX
E.g. infinite ground plane.
@ TRANSLUCENT
Translucent items use a [0.0...1.0] alpha value supplied via an opacity map or via the albedo's alpha...
@ SKY
Sky needs to be drawn after ALL opaque geometry to save on fillrate.
@ TERRAIN
Actual terrain. It should cover most of the remaining empty screen space.
@ OPAQUE
Opaque objects will occlude a lot of the terrain and terrain is REALLY expensive to render,...
uint8_t U8
RenderQueueListType
Definition: RenderBin.h:97
uint16_t U16
constexpr I64 I64_LOWEST
RenderingOrder
Definition: RenderBin.h:63
int64_t I64
constexpr auto to_base(const Type value) -> Type
RenderingComponent * _renderable
Definition: RenderBin.h:55
RenderPackage * _rPackage
Definition: RenderBin.h:106
RenderingComponent * _rComp
Definition: RenderBin.h:105