| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "servers/rendering/rendering_server.h" |
| 34 |
|
| 35 |
class DependencyTracker; |
| 36 |
|
| 37 |
class Dependency { |
| 38 |
public: |
| 39 |
enum DependencyChangedNotification { |
| 40 |
DEPENDENCY_CHANGED_AABB, |
| 41 |
DEPENDENCY_CHANGED_MATERIAL, |
| 42 |
DEPENDENCY_CHANGED_MESH, |
| 43 |
DEPENDENCY_CHANGED_MULTIMESH, |
| 44 |
DEPENDENCY_CHANGED_MULTIMESH_VISIBLE_INSTANCES, |
| 45 |
DEPENDENCY_CHANGED_PARTICLES, |
| 46 |
DEPENDENCY_CHANGED_PARTICLES_INSTANCES, |
| 47 |
DEPENDENCY_CHANGED_DECAL, |
| 48 |
DEPENDENCY_CHANGED_SKELETON_DATA, |
| 49 |
DEPENDENCY_CHANGED_SKELETON_BONES, |
| 50 |
DEPENDENCY_CHANGED_LIGHT, |
| 51 |
DEPENDENCY_CHANGED_LIGHT_SOFT_SHADOW_AND_PROJECTOR, |
| 52 |
DEPENDENCY_CHANGED_REFLECTION_PROBE, |
| 53 |
DEPENDENCY_CHANGED_CULL_MASK, |
| 54 |
}; |
| 55 |
|
| 56 |
void changed_notify(DependencyChangedNotification p_notification); |
| 57 |
void deleted_notify(const RID &p_rid); |
| 58 |
|
| 59 |
~Dependency(); |
| 60 |
|
| 61 |
private: |
| 62 |
friend class DependencyTracker; |
| 63 |
HashMap<DependencyTracker *, uint32_t> instances; |
| 64 |
}; |
| 65 |
|
| 66 |
class DependencyTracker { |
| 67 |
public: |
| 68 |
void *userdata = nullptr; |
| 69 |
typedef void (*ChangedCallback)(Dependency::DependencyChangedNotification, DependencyTracker *); |
| 70 |
typedef void (*DeletedCallback)(const RID &, DependencyTracker *); |
| 71 |
|
| 72 |
ChangedCallback changed_callback = nullptr; |
| 73 |
DeletedCallback deleted_callback = nullptr; |
| 74 |
|
| 75 |
void update_begin() { |
| 76 |
instance_version++; |
| 77 |
} |
| 78 |
|
| 79 |
void update_dependency(Dependency *p_dependency) { |
| 80 |
dependencies.insert(p_dependency); |
| 81 |
p_dependency->instances[this] = instance_version; |
| 82 |
} |
| 83 |
|
| 84 |
void update_end() { |
| 85 |
List<Pair<Dependency *, DependencyTracker *>> to_clean_up; |
| 86 |
|
| 87 |
for (Dependency *E : dependencies) { |
| 88 |
Dependency *dep = E; |
| 89 |
HashMap<DependencyTracker *, uint32_t>::Iterator F = dep->instances.find(this); |
| 90 |
ERR_CONTINUE(!F); |
| 91 |
if (F->value != instance_version) { |
| 92 |
Pair<Dependency *, DependencyTracker *> p; |
| 93 |
p.first = dep; |
| 94 |
p.second = F->key; |
| 95 |
to_clean_up.push_back(p); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
while (to_clean_up.size()) { |
| 100 |
to_clean_up.front()->get().first->instances.erase(to_clean_up.front()->get().second); |
| 101 |
dependencies.erase(to_clean_up.front()->get().first); |
| 102 |
to_clean_up.pop_front(); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
void clear() { |
| 107 |
for (Dependency *E : dependencies) { |
| 108 |
Dependency *dep = E; |
| 109 |
dep->instances.erase(this); |
| 110 |
} |
| 111 |
dependencies.clear(); |
| 112 |
} |
| 113 |
|
| 114 |
~DependencyTracker() { clear(); } |
| 115 |
|
| 116 |
private: |
| 117 |
friend class Dependency; |
| 118 |
uint32_t instance_version = 0; |
| 119 |
HashSet<Dependency *> dependencies; |
| 120 |
}; |
| 121 |
|
| 122 |
class RendererUtilities { |
| 123 |
public: |
| 124 |
virtual ~RendererUtilities() {} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
virtual RS::InstanceType get_base_type(RID p_rid) const = 0; |
| 129 |
virtual bool free(RID p_rid) = 0; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
virtual void base_update_dependency(RID p_base, DependencyTracker *p_instance) = 0; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
virtual RID visibility_notifier_allocate() = 0; |
| 138 |
virtual void visibility_notifier_initialize(RID p_notifier) = 0; |
| 139 |
virtual void visibility_notifier_free(RID p_notifier) = 0; |
| 140 |
|
| 141 |
virtual void visibility_notifier_set_aabb(RID p_notifier, const AABB &p_aabb) = 0; |
| 142 |
virtual void visibility_notifier_set_callbacks(RID p_notifier, const Callable &p_enter_callbable, const Callable &p_exit_callable) = 0; |
| 143 |
|
| 144 |
virtual AABB visibility_notifier_get_aabb(RID p_notifier) const = 0; |
| 145 |
virtual void visibility_notifier_call(RID p_notifier, bool p_enter, bool p_deferred) = 0; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
bool capturing_timestamps = false; |
| 150 |
|
| 151 |
#define TIMESTAMP_BEGIN() \ |
| 152 |
{ \ |
| 153 |
if (RSG::utilities->capturing_timestamps) \ |
| 154 |
RSG::utilities->capture_timestamps_begin(); \ |
| 155 |
} |
| 156 |
|
| 157 |
#define RENDER_TIMESTAMP(m_text) \ |
| 158 |
{ \ |
| 159 |
if (RSG::utilities->capturing_timestamps) \ |
| 160 |
RSG::utilities->capture_timestamp(m_text); \ |
| 161 |
} |
| 162 |
|
| 163 |
virtual void capture_timestamps_begin() = 0; |
| 164 |
virtual void capture_timestamp(const String &p_name) = 0; |
| 165 |
virtual uint32_t get_captured_timestamps_count() const = 0; |
| 166 |
virtual uint64_t get_captured_timestamps_frame() const = 0; |
| 167 |
virtual uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const = 0; |
| 168 |
virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const = 0; |
| 169 |
virtual String get_captured_timestamp_name(uint32_t p_index) const = 0; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
virtual void update_dirty_resources() = 0; |
| 174 |
virtual void set_debug_generate_wireframes(bool p_generate) = 0; |
| 175 |
|
| 176 |
virtual bool has_os_feature(const String &p_feature) const = 0; |
| 177 |
|
| 178 |
virtual void update_memory_info() = 0; |
| 179 |
|
| 180 |
virtual uint64_t get_rendering_info(RS::RenderingInfo p_info) = 0; |
| 181 |
virtual String get_video_adapter_name() const = 0; |
| 182 |
virtual String get_video_adapter_vendor() const = 0; |
| 183 |
virtual RenderingDevice::DeviceType get_video_adapter_type() const = 0; |
| 184 |
virtual String get_video_adapter_api_version() const = 0; |
| 185 |
|
| 186 |
virtual Size2i get_maximum_viewport_size() const = 0; |
| 187 |
virtual uint32_t get_maximum_shader_varyings() const = 0; |
| 188 |
virtual uint64_t get_maximum_uniform_buffer_size() const = 0; |
| 189 |
}; |