Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
EnvironmentProbeComponent.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_ENVIRONMENT_PROBE_COMPONENT_H_
34#define DVD_ENVIRONMENT_PROBE_COMPONENT_H_
35
36#include "SGNComponent.h"
37
39
40namespace Divide {
41
42class Scene;
43class Camera;
44class Pipeline;
45class GFXDevice;
46class IMPrimitive;
47class ShaderProgram;
48
49namespace GFX {
50 class CommandBuffer;
51 struct MemoryBarrierCommand;
52} //namespace GFX
53
55
56public:
57 enum class ProbeType : U8 {
58 TYPE_INFINITE = 0,
59 TYPE_LOCAL,
60 COUNT
61 };
62
63 enum class UpdateType : U8 {
64 ALWAYS = 0,
65 ON_DIRTY,
66 ON_RATE,
67 ONCE,
68 COUNT
69 };
70
71 struct Names {
72 inline static const char* updateType[] = {
73 "Always", "On Dirty", "On Rate", "Once", "ERROR!"
74 };
75 };
76
77public:
80
82 bool refresh(GFX::CommandBuffer& bufferInOut, GFX::MemoryBarrierCommand& memCmdInOut);
84 bool checkCollisionAndQueueUpdate(const BoundingSphere& sphere) noexcept;
85
86 void updateType(UpdateType type);
87
88 void setBounds(const vec3<F32>& min, const vec3<F32>& max) noexcept;
89 void setBounds(const vec3<F32>& center, F32 radius) noexcept;
90
91 void loadFromXML(const boost::property_tree::ptree& pt) override;
92
93 [[nodiscard]] F32 distanceSqTo(const vec3<F32>& pos) const noexcept;
94
95 //Only "dirty" probes gets refreshed. A probe might get dirty if, for example, a reflective node
96 //gets rendered that has this probe as the nearest one
97 void queueRefresh() noexcept { _queueRefresh = true; }
98
99 [[nodiscard]] bool enabled() const override;
100 void enabled(bool state) override;
101
102 PROPERTY_R_IW(U16, rtLayerIndex, 0u);
103 PROPERTY_RW(bool, showParallaxAABB, false);
104 PROPERTY_RW(bool, dirty, true);
105 PROPERTY_RW(U8, updateRate, 1u);
106 PROPERTY_R(UpdateType, updateType, UpdateType::ON_DIRTY);
107
108 PROPERTY_R(U16, poolIndex, 0u);
109
110 inline const BoundingBox& getBounds() const noexcept { return _aabb; }
111protected:
112 friend class SceneEnvironmentProbePool; //for poolIndex(U16)
113 void poolIndex(U16 index) noexcept;
114
115 void OnData(const ECS::CustomEvent& data) override;
116
117 [[nodiscard]] SceneGraphNode* findNodeToIgnore() const noexcept;
118
119 void updateProbeData() const noexcept;
120protected:
122 BoundingBox _refaabb{ vec3<F32>(-1), vec3<F32>(1) };
123
124 U8 _currentUpdateCall = 0u;
125 ProbeType _probeType = ProbeType::TYPE_LOCAL;
126
127private:
128 bool _queueRefresh = true;
129 bool _drawImpostor = false;
130
131END_COMPONENT(EnvironmentProbe);
132
133namespace TypeUtil {
134 [[nodiscard]] const char* EnvProveUpdateTypeToString(EnvironmentProbeComponent::UpdateType type) noexcept;
135 [[nodiscard]] EnvironmentProbeComponent::UpdateType StringToEnvProveUpdateType(const char* name) noexcept;
136}
137
138} //namespace Divide
139
140#endif //DVD_ENVIRONMENT_PROBE_COMPONENT_H_
#define BEGIN_COMPONENT_EXT1(Name, Enum, Base1)
Definition: SGNComponent.h:219
#define END_COMPONENT(Name)
Definition: SGNComponent.h:223
PROPERTY_RW(bool, showParallaxAABB, false)
PROPERTY_R_IW(U16, rtLayerIndex, 0u)
PROPERTY_RW(U8, updateRate, 1u)
PROPERTY_R(U16, poolIndex, 0u)
PROPERTY_R(UpdateType, updateType, UpdateType::ON_DIRTY)
const BoundingBox & getBounds() const noexcept
Utility class that adds basic GUID management to objects.
Definition: GUIDWrapper.h:44
EnvironmentProbeComponent::UpdateType StringToEnvProveUpdateType(const char *name) noexcept
const char * EnvProveUpdateTypeToString(const EnvironmentProbeComponent::UpdateType type) noexcept
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
void OnData(const ECS::CustomEvent &data) override
uint8_t U8
uint16_t U16