Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
RenderPassCuller.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#pragma once
33#ifndef DVD_RENDER_PASS_CULLER_H_
34#define DVD_RENDER_PASS_CULLER_H_
35
37
40namespace Divide {
41
42class SceneState;
43class SceneRenderState;
44
45struct Task;
46class Camera;
47class SceneNode;
48class SceneGraph;
49class SceneGraphNode;
50class PlatformContext;
51enum class RenderStage : U8;
52
53enum class CullOptions : U16
54{
61};
62
63class Frustum;
64struct GUIDList {
65 I64* _guids = nullptr;
66 size_t _count = 0u;
67};
68
75 const Frustum* _frustum = nullptr;
79};
80
84 bool _materialReady = true;
85};
86
88
89template<typename T = VisibleNode, size_t N = Config::MAX_VISIBLE_NODES>
91{
92 using Container = std::array<T, N>;
93
94 void append(const VisibleNodeList& other) noexcept
95 {
96 assert(_index + other._index < _nodes.size());
97
98 std::memcpy(_nodes.data() + _index, other._nodes.data(), other._index * sizeof(T));
99 _index += other._index;
100 }
101
102 void append(const T& node) noexcept
103 {
104 _nodes[_index.fetch_add(1)] = node;
105 }
106
107 void remove(const size_t idx)
108 {
109 const size_t lastPos = _index.fetch_sub(1);
110 assert(idx <= lastPos);
111 _nodes[idx] = _nodes[lastPos - 1];
112 _nodes[lastPos - 1] = {};
113 }
114
115 void reset() noexcept { _index.store(0); }
116 [[nodiscard]] size_t size() const noexcept { return _index.load(); }
117 [[nodiscard]] bufferPtr data() const noexcept { return (bufferPtr)_nodes.data(); }
118
119 [[nodiscard]] const T& node(const size_t idx) const noexcept
120 {
121 assert(idx < _index.load());
122 return _nodes[idx];
123 }
124
125 [[nodiscard]] T& node(const size_t idx) noexcept
126 {
127 assert(idx < _index.load());
128 return _nodes[idx];
129 }
130
132 {
133 reset();
134 append(other);
135 return *this;
136 }
137
138private:
140 std::atomic_size_t _index = 0;
141};
142
144 enum class EntityFilter : U8
145 {
146 PRIMITIVES = toBit( 0 ),
147 MESHES = toBit( 1 ),
148 TERRAIN = toBit( 2 ),
149 VEGETATION = toBit( 3 ),
150 WATER = toBit( 4 ),
151 SKY = toBit( 5 ),
152 PARTICLES = toBit( 6 ),
153 COUNT = 7
154 };
155
156 static void FrustumCull(const NodeCullParams& params, U16 cullFlags, const SceneGraph& sceneGraph, const SceneState& sceneState, PlatformContext& context, VisibleNodeList<>& nodesOut);
157 static void FrustumCull(const PlatformContext& context, const NodeCullParams& params, const U16 cullFlags, const vector<SceneGraphNode*>& nodes, VisibleNodeList<>& nodesOut);
158 static void ToVisibleNodes(const Camera* camera, const vector<SceneGraphNode*>& nodes, VisibleNodeList<>& nodesOut);
159
160private:
161 [[nodiscard]] static U32 FilterMask( const PlatformContext& context ) noexcept;
162
163 static void PostCullNodes(const NodeCullParams& params, U16 cullFlags, U32 filterMask, VisibleNodeList<>& nodesInOut);
164 static void FrustumCullNode(SceneGraphNode* currentNode, const NodeCullParams& params, U16 cullFlags, U8 recursionLevel, VisibleNodeList<>& nodes);
165};
166
167} // namespace Divide
168
169#endif //DVD_RENDER_PASS_CULLER_H_
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
constexpr F32 F32_MAX
uint16_t U16
int64_t I64
uint32_t U32
void * bufferPtr
constexpr T toBit(const T X)
Converts an arbitrary positive integer value to a bitwise value used for masks.
vector< VisibleNode > FeedBackContainer
FrustumClipPlanes _clippingPlanes
const Frustum * _frustum
static void FrustumCull(const NodeCullParams &params, U16 cullFlags, const SceneGraph &sceneGraph, const SceneState &sceneState, PlatformContext &context, VisibleNodeList<> &nodesOut)
static void PostCullNodes(const NodeCullParams &params, U16 cullFlags, U32 filterMask, VisibleNodeList<> &nodesInOut)
static void ToVisibleNodes(const Camera *camera, const vector< SceneGraphNode * > &nodes, VisibleNodeList<> &nodesOut)
static U32 FilterMask(const PlatformContext &context) noexcept
static void FrustumCullNode(SceneGraphNode *currentNode, const NodeCullParams &params, U16 cullFlags, U8 recursionLevel, VisibleNodeList<> &nodes)
This method performs the visibility check on the given node and all of its children and adds them to ...
SceneGraphNode * _node
void remove(const size_t idx)
void append(const VisibleNodeList &other) noexcept
std::array< T, N > Container
bufferPtr data() const noexcept
void append(const T &node) noexcept
VisibleNodeList & operator=(const VisibleNodeList &other)
size_t size() const noexcept
T & node(const size_t idx) noexcept
const T & node(const size_t idx) const noexcept
std::atomic_size_t _index