2019-06-22 18:34:26 +02:00
|
|
|
/*************************************************************************/
|
2020-12-04 19:26:24 +01:00
|
|
|
/* renderer_storage_rd.cpp */
|
2019-06-22 18:34:26 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2019-06-22 18:34:26 +02:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
#include "renderer_storage_rd.h"
|
2020-03-31 13:50:25 +02:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/config/engine.h"
|
|
|
|
#include "core/config/project_settings.h"
|
2020-04-17 04:52:00 +02:00
|
|
|
#include "core/io/resource_loader.h"
|
2021-05-19 14:12:55 +02:00
|
|
|
#include "core/math/math_defs.h"
|
2020-12-04 19:26:24 +01:00
|
|
|
#include "renderer_compositor_rd.h"
|
2022-05-20 04:52:19 +02:00
|
|
|
#include "servers/rendering/renderer_rd/environment/gi.h"
|
2022-04-09 11:34:31 +02:00
|
|
|
#include "servers/rendering/renderer_rd/storage_rd/light_storage.h"
|
2022-04-02 07:29:04 +02:00
|
|
|
#include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h"
|
2022-04-12 13:41:50 +02:00
|
|
|
#include "servers/rendering/renderer_rd/storage_rd/particles_storage.h"
|
2022-04-02 07:29:04 +02:00
|
|
|
#include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"
|
2021-07-01 04:17:47 +02:00
|
|
|
#include "servers/rendering/rendering_server_globals.h"
|
2020-03-27 19:21:27 +01:00
|
|
|
#include "servers/rendering/shader_language.h"
|
2019-06-11 20:43:37 +02:00
|
|
|
|
2021-10-03 13:28:55 +02:00
|
|
|
/* FOG VOLUMES */
|
|
|
|
|
|
|
|
RID RendererStorageRD::fog_volume_allocate() {
|
|
|
|
return fog_volume_owner.allocate_rid();
|
|
|
|
}
|
|
|
|
void RendererStorageRD::fog_volume_initialize(RID p_rid) {
|
|
|
|
fog_volume_owner.initialize_rid(p_rid, FogVolume());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RendererStorageRD::fog_volume_set_shape(RID p_fog_volume, RS::FogVolumeShape p_shape) {
|
|
|
|
FogVolume *fog_volume = fog_volume_owner.get_or_null(p_fog_volume);
|
|
|
|
ERR_FAIL_COND(!fog_volume);
|
|
|
|
|
|
|
|
if (p_shape == fog_volume->shape) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fog_volume->shape = p_shape;
|
|
|
|
fog_volume->dependency.changed_notify(DEPENDENCY_CHANGED_AABB);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RendererStorageRD::fog_volume_set_extents(RID p_fog_volume, const Vector3 &p_extents) {
|
|
|
|
FogVolume *fog_volume = fog_volume_owner.get_or_null(p_fog_volume);
|
|
|
|
ERR_FAIL_COND(!fog_volume);
|
|
|
|
|
|
|
|
fog_volume->extents = p_extents;
|
|
|
|
fog_volume->dependency.changed_notify(DEPENDENCY_CHANGED_AABB);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RendererStorageRD::fog_volume_set_material(RID p_fog_volume, RID p_material) {
|
|
|
|
FogVolume *fog_volume = fog_volume_owner.get_or_null(p_fog_volume);
|
|
|
|
ERR_FAIL_COND(!fog_volume);
|
|
|
|
fog_volume->material = p_material;
|
|
|
|
}
|
|
|
|
|
|
|
|
RID RendererStorageRD::fog_volume_get_material(RID p_fog_volume) const {
|
|
|
|
FogVolume *fog_volume = fog_volume_owner.get_or_null(p_fog_volume);
|
|
|
|
ERR_FAIL_COND_V(!fog_volume, RID());
|
|
|
|
|
|
|
|
return fog_volume->material;
|
|
|
|
}
|
|
|
|
|
|
|
|
RS::FogVolumeShape RendererStorageRD::fog_volume_get_shape(RID p_fog_volume) const {
|
|
|
|
FogVolume *fog_volume = fog_volume_owner.get_or_null(p_fog_volume);
|
|
|
|
ERR_FAIL_COND_V(!fog_volume, RS::FOG_VOLUME_SHAPE_BOX);
|
|
|
|
|
|
|
|
return fog_volume->shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
AABB RendererStorageRD::fog_volume_get_aabb(RID p_fog_volume) const {
|
|
|
|
FogVolume *fog_volume = fog_volume_owner.get_or_null(p_fog_volume);
|
|
|
|
ERR_FAIL_COND_V(!fog_volume, AABB());
|
|
|
|
|
|
|
|
switch (fog_volume->shape) {
|
|
|
|
case RS::FOG_VOLUME_SHAPE_ELLIPSOID:
|
2022-05-21 12:17:49 +02:00
|
|
|
case RS::FOG_VOLUME_SHAPE_CONE:
|
|
|
|
case RS::FOG_VOLUME_SHAPE_CYLINDER:
|
2021-10-03 13:28:55 +02:00
|
|
|
case RS::FOG_VOLUME_SHAPE_BOX: {
|
|
|
|
AABB aabb;
|
|
|
|
aabb.position = -fog_volume->extents;
|
|
|
|
aabb.size = fog_volume->extents * 2;
|
|
|
|
return aabb;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// Need some size otherwise will get culled
|
|
|
|
return AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return AABB();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 RendererStorageRD::fog_volume_get_extents(RID p_fog_volume) const {
|
|
|
|
const FogVolume *fog_volume = fog_volume_owner.get_or_null(p_fog_volume);
|
|
|
|
ERR_FAIL_COND_V(!fog_volume, Vector3());
|
|
|
|
return fog_volume->extents;
|
|
|
|
}
|
|
|
|
|
2021-06-16 20:43:02 +02:00
|
|
|
/* VISIBILITY NOTIFIER */
|
|
|
|
|
|
|
|
RID RendererStorageRD::visibility_notifier_allocate() {
|
|
|
|
return visibility_notifier_owner.allocate_rid();
|
|
|
|
}
|
|
|
|
void RendererStorageRD::visibility_notifier_initialize(RID p_notifier) {
|
|
|
|
visibility_notifier_owner.initialize_rid(p_notifier, VisibilityNotifier());
|
|
|
|
}
|
|
|
|
void RendererStorageRD::visibility_notifier_set_aabb(RID p_notifier, const AABB &p_aabb) {
|
2021-09-29 19:08:41 +02:00
|
|
|
VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_notifier);
|
2021-06-16 20:43:02 +02:00
|
|
|
ERR_FAIL_COND(!vn);
|
|
|
|
vn->aabb = p_aabb;
|
|
|
|
vn->dependency.changed_notify(DEPENDENCY_CHANGED_AABB);
|
|
|
|
}
|
|
|
|
void RendererStorageRD::visibility_notifier_set_callbacks(RID p_notifier, const Callable &p_enter_callbable, const Callable &p_exit_callable) {
|
2021-09-29 19:08:41 +02:00
|
|
|
VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_notifier);
|
2021-06-16 20:43:02 +02:00
|
|
|
ERR_FAIL_COND(!vn);
|
|
|
|
vn->enter_callback = p_enter_callbable;
|
|
|
|
vn->exit_callback = p_exit_callable;
|
|
|
|
}
|
|
|
|
|
|
|
|
AABB RendererStorageRD::visibility_notifier_get_aabb(RID p_notifier) const {
|
2021-09-29 19:08:41 +02:00
|
|
|
const VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_notifier);
|
2021-06-16 20:43:02 +02:00
|
|
|
ERR_FAIL_COND_V(!vn, AABB());
|
|
|
|
return vn->aabb;
|
|
|
|
}
|
|
|
|
void RendererStorageRD::visibility_notifier_call(RID p_notifier, bool p_enter, bool p_deferred) {
|
2021-09-29 19:08:41 +02:00
|
|
|
VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_notifier);
|
2021-06-16 20:43:02 +02:00
|
|
|
ERR_FAIL_COND(!vn);
|
|
|
|
|
|
|
|
if (p_enter) {
|
|
|
|
if (!vn->enter_callback.is_null()) {
|
|
|
|
if (p_deferred) {
|
|
|
|
vn->enter_callback.call_deferred(nullptr, 0);
|
|
|
|
} else {
|
|
|
|
Variant r;
|
|
|
|
Callable::CallError ce;
|
|
|
|
vn->enter_callback.call(nullptr, 0, r, ce);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!vn->exit_callback.is_null()) {
|
|
|
|
if (p_deferred) {
|
|
|
|
vn->exit_callback.call_deferred(nullptr, 0);
|
|
|
|
} else {
|
|
|
|
Variant r;
|
|
|
|
Callable::CallError ce;
|
|
|
|
vn->exit_callback.call(nullptr, 0, r, ce);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:41:50 +02:00
|
|
|
/* misc */
|
|
|
|
|
2021-01-04 13:33:25 +01:00
|
|
|
void RendererStorageRD::base_update_dependency(RID p_base, DependencyTracker *p_instance) {
|
2022-04-02 07:29:04 +02:00
|
|
|
if (RendererRD::MeshStorage::get_singleton()->owns_mesh(p_base)) {
|
|
|
|
RendererRD::Mesh *mesh = RendererRD::MeshStorage::get_singleton()->get_mesh(p_base);
|
2021-01-04 13:33:25 +01:00
|
|
|
p_instance->update_dependency(&mesh->dependency);
|
2022-04-02 07:29:04 +02:00
|
|
|
} else if (RendererRD::MeshStorage::get_singleton()->owns_multimesh(p_base)) {
|
|
|
|
RendererRD::MultiMesh *multimesh = RendererRD::MeshStorage::get_singleton()->get_multimesh(p_base);
|
2021-01-04 13:33:25 +01:00
|
|
|
p_instance->update_dependency(&multimesh->dependency);
|
2019-09-14 05:37:42 +02:00
|
|
|
if (multimesh->mesh.is_valid()) {
|
|
|
|
base_update_dependency(multimesh->mesh, p_instance);
|
|
|
|
}
|
2022-04-09 11:34:31 +02:00
|
|
|
} else if (RendererRD::LightStorage::get_singleton()->owns_reflection_probe(p_base)) {
|
|
|
|
RendererRD::ReflectionProbe *rp = RendererRD::LightStorage::get_singleton()->get_reflection_probe(p_base);
|
2021-01-04 13:33:25 +01:00
|
|
|
p_instance->update_dependency(&rp->dependency);
|
2022-04-07 16:00:51 +02:00
|
|
|
} else if (RendererRD::TextureStorage::get_singleton()->owns_decal(p_base)) {
|
|
|
|
RendererRD::Decal *decal = RendererRD::TextureStorage::get_singleton()->get_decal(p_base);
|
2021-01-04 13:33:25 +01:00
|
|
|
p_instance->update_dependency(&decal->dependency);
|
2022-05-20 04:52:19 +02:00
|
|
|
} else if (RendererRD::GI::get_singleton()->owns_voxel_gi(p_base)) {
|
|
|
|
RendererRD::GI::VoxelGI *gip = RendererRD::GI::get_singleton()->get_voxel_gi(p_base);
|
2021-01-04 13:33:25 +01:00
|
|
|
p_instance->update_dependency(&gip->dependency);
|
2022-04-09 11:34:31 +02:00
|
|
|
} else if (RendererRD::LightStorage::get_singleton()->owns_lightmap(p_base)) {
|
|
|
|
RendererRD::Lightmap *lm = RendererRD::LightStorage::get_singleton()->get_lightmap(p_base);
|
2021-01-04 13:33:25 +01:00
|
|
|
p_instance->update_dependency(&lm->dependency);
|
2022-04-09 11:34:31 +02:00
|
|
|
} else if (RendererRD::LightStorage::get_singleton()->owns_light(p_base)) {
|
|
|
|
RendererRD::Light *l = RendererRD::LightStorage::get_singleton()->get_light(p_base);
|
2021-01-04 13:33:25 +01:00
|
|
|
p_instance->update_dependency(&l->dependency);
|
2022-04-12 13:41:50 +02:00
|
|
|
} else if (RendererRD::ParticlesStorage::get_singleton()->owns_particles(p_base)) {
|
|
|
|
RendererRD::Particles *p = RendererRD::ParticlesStorage::get_singleton()->get_particles(p_base);
|
2021-01-04 13:33:25 +01:00
|
|
|
p_instance->update_dependency(&p->dependency);
|
2022-04-12 13:41:50 +02:00
|
|
|
} else if (RendererRD::ParticlesStorage::get_singleton()->owns_particles_collision(p_base)) {
|
|
|
|
RendererRD::ParticlesCollision *pc = RendererRD::ParticlesStorage::get_singleton()->get_particles_collision(p_base);
|
2021-01-04 13:33:25 +01:00
|
|
|
p_instance->update_dependency(&pc->dependency);
|
2021-10-03 13:28:55 +02:00
|
|
|
} else if (fog_volume_owner.owns(p_base)) {
|
|
|
|
FogVolume *fv = fog_volume_owner.get_or_null(p_base);
|
|
|
|
p_instance->update_dependency(&fv->dependency);
|
2021-06-16 20:43:02 +02:00
|
|
|
} else if (visibility_notifier_owner.owns(p_base)) {
|
2021-09-29 19:08:41 +02:00
|
|
|
VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_base);
|
2021-06-16 20:43:02 +02:00
|
|
|
p_instance->update_dependency(&vn->dependency);
|
2019-08-19 00:40:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
RS::InstanceType RendererStorageRD::get_base_type(RID p_rid) const {
|
2022-04-02 07:29:04 +02:00
|
|
|
if (RendererRD::MeshStorage::get_singleton()->owns_mesh(p_rid)) {
|
2020-03-27 19:21:27 +01:00
|
|
|
return RS::INSTANCE_MESH;
|
2019-08-20 22:54:03 +02:00
|
|
|
}
|
2022-04-02 07:29:04 +02:00
|
|
|
if (RendererRD::MeshStorage::get_singleton()->owns_multimesh(p_rid)) {
|
2020-03-27 19:21:27 +01:00
|
|
|
return RS::INSTANCE_MULTIMESH;
|
2019-09-14 05:37:42 +02:00
|
|
|
}
|
2022-04-09 11:34:31 +02:00
|
|
|
if (RendererRD::LightStorage::get_singleton()->owns_reflection_probe(p_rid)) {
|
2020-03-27 19:21:27 +01:00
|
|
|
return RS::INSTANCE_REFLECTION_PROBE;
|
2019-09-07 03:51:27 +02:00
|
|
|
}
|
2022-04-07 16:00:51 +02:00
|
|
|
if (RendererRD::TextureStorage::get_singleton()->owns_decal(p_rid)) {
|
2020-04-14 05:05:21 +02:00
|
|
|
return RS::INSTANCE_DECAL;
|
|
|
|
}
|
2022-05-20 04:52:19 +02:00
|
|
|
if (RendererRD::GI::get_singleton()->owns_voxel_gi(p_rid)) {
|
2021-06-05 00:47:26 +02:00
|
|
|
return RS::INSTANCE_VOXEL_GI;
|
2019-10-03 22:39:08 +02:00
|
|
|
}
|
2022-04-09 11:34:31 +02:00
|
|
|
if (RendererRD::LightStorage::get_singleton()->owns_light(p_rid)) {
|
2020-03-27 19:21:27 +01:00
|
|
|
return RS::INSTANCE_LIGHT;
|
2019-09-07 03:51:27 +02:00
|
|
|
}
|
2022-04-09 11:34:31 +02:00
|
|
|
if (RendererRD::LightStorage::get_singleton()->owns_lightmap(p_rid)) {
|
2020-05-01 14:34:23 +02:00
|
|
|
return RS::INSTANCE_LIGHTMAP;
|
|
|
|
}
|
2022-04-12 13:41:50 +02:00
|
|
|
if (RendererRD::ParticlesStorage::get_singleton()->owns_particles(p_rid)) {
|
2020-08-19 15:38:24 +02:00
|
|
|
return RS::INSTANCE_PARTICLES;
|
|
|
|
}
|
2022-04-12 13:41:50 +02:00
|
|
|
if (RendererRD::ParticlesStorage::get_singleton()->owns_particles_collision(p_rid)) {
|
2020-10-08 02:29:49 +02:00
|
|
|
return RS::INSTANCE_PARTICLES_COLLISION;
|
|
|
|
}
|
2021-10-03 13:28:55 +02:00
|
|
|
if (fog_volume_owner.owns(p_rid)) {
|
|
|
|
return RS::INSTANCE_FOG_VOLUME;
|
|
|
|
}
|
2021-06-16 20:43:02 +02:00
|
|
|
if (visibility_notifier_owner.owns(p_rid)) {
|
|
|
|
return RS::INSTANCE_VISIBLITY_NOTIFIER;
|
|
|
|
}
|
2019-09-07 03:51:27 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
return RS::INSTANCE_NONE;
|
2019-08-20 22:54:03 +02:00
|
|
|
}
|
2020-04-14 05:05:21 +02:00
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
void RendererStorageRD::update_dirty_resources() {
|
2022-03-21 12:25:25 +01:00
|
|
|
RendererRD::MaterialStorage::get_singleton()->_update_global_variables(); //must do before materials, so it can queue them for update
|
|
|
|
RendererRD::MaterialStorage::get_singleton()->_update_queued_materials();
|
2022-04-02 07:29:04 +02:00
|
|
|
RendererRD::MeshStorage::get_singleton()->_update_dirty_multimeshes();
|
|
|
|
RendererRD::MeshStorage::get_singleton()->_update_dirty_skeletons();
|
2022-04-07 16:00:51 +02:00
|
|
|
RendererRD::TextureStorage::get_singleton()->update_decal_atlas();
|
2019-07-21 16:31:30 +02:00
|
|
|
}
|
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
bool RendererStorageRD::has_os_feature(const String &p_feature) const {
|
2022-05-28 13:09:23 +02:00
|
|
|
if (!RD::get_singleton()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-27 04:16:44 +02:00
|
|
|
if (p_feature == "rgtc" && RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_BC5_UNORM_BLOCK, RD::TEXTURE_USAGE_SAMPLING_BIT)) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-14 05:37:42 +02:00
|
|
|
|
|
|
|
if (p_feature == "s3tc" && RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_BC1_RGB_UNORM_BLOCK, RD::TEXTURE_USAGE_SAMPLING_BIT)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_feature == "bptc" && RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_BC7_UNORM_BLOCK, RD::TEXTURE_USAGE_SAMPLING_BIT)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((p_feature == "etc" || p_feature == "etc2") && RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, RD::TEXTURE_USAGE_SAMPLING_BIT)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
bool RendererStorageRD::free(RID p_rid) {
|
2022-03-12 12:19:59 +01:00
|
|
|
if (RendererRD::TextureStorage::get_singleton()->owns_texture(p_rid)) {
|
|
|
|
RendererRD::TextureStorage::get_singleton()->texture_free(p_rid);
|
2022-04-07 16:00:51 +02:00
|
|
|
} else if (RendererRD::TextureStorage::get_singleton()->owns_canvas_texture(p_rid)) {
|
|
|
|
RendererRD::TextureStorage::get_singleton()->canvas_texture_free(p_rid);
|
2022-03-21 12:25:25 +01:00
|
|
|
} else if (RendererRD::MaterialStorage::get_singleton()->owns_shader(p_rid)) {
|
|
|
|
RendererRD::MaterialStorage::get_singleton()->shader_free(p_rid);
|
|
|
|
} else if (RendererRD::MaterialStorage::get_singleton()->owns_material(p_rid)) {
|
|
|
|
RendererRD::MaterialStorage::get_singleton()->material_free(p_rid);
|
2022-04-02 07:29:04 +02:00
|
|
|
} else if (RendererRD::MeshStorage::get_singleton()->owns_mesh(p_rid)) {
|
|
|
|
RendererRD::MeshStorage::get_singleton()->mesh_free(p_rid);
|
|
|
|
} else if (RendererRD::MeshStorage::get_singleton()->owns_mesh_instance(p_rid)) {
|
|
|
|
RendererRD::MeshStorage::get_singleton()->mesh_instance_free(p_rid);
|
|
|
|
} else if (RendererRD::MeshStorage::get_singleton()->owns_multimesh(p_rid)) {
|
|
|
|
RendererRD::MeshStorage::get_singleton()->multimesh_free(p_rid);
|
|
|
|
} else if (RendererRD::MeshStorage::get_singleton()->owns_skeleton(p_rid)) {
|
|
|
|
RendererRD::MeshStorage::get_singleton()->skeleton_free(p_rid);
|
2022-04-09 11:34:31 +02:00
|
|
|
} else if (RendererRD::LightStorage::get_singleton()->owns_reflection_probe(p_rid)) {
|
|
|
|
RendererRD::LightStorage::get_singleton()->reflection_probe_free(p_rid);
|
2022-04-07 16:00:51 +02:00
|
|
|
} else if (RendererRD::TextureStorage::get_singleton()->owns_decal(p_rid)) {
|
|
|
|
RendererRD::TextureStorage::get_singleton()->decal_free(p_rid);
|
2022-05-20 04:52:19 +02:00
|
|
|
} else if (RendererRD::GI::get_singleton()->owns_voxel_gi(p_rid)) {
|
|
|
|
RendererRD::GI::get_singleton()->voxel_gi_free(p_rid);
|
2022-04-09 11:34:31 +02:00
|
|
|
} else if (RendererRD::LightStorage::get_singleton()->owns_lightmap(p_rid)) {
|
|
|
|
RendererRD::LightStorage::get_singleton()->lightmap_free(p_rid);
|
|
|
|
} else if (RendererRD::LightStorage::get_singleton()->owns_light(p_rid)) {
|
|
|
|
RendererRD::LightStorage::get_singleton()->light_free(p_rid);
|
2022-04-12 13:41:50 +02:00
|
|
|
} else if (RendererRD::ParticlesStorage::get_singleton()->owns_particles(p_rid)) {
|
|
|
|
RendererRD::ParticlesStorage::get_singleton()->particles_free(p_rid);
|
|
|
|
} else if (RendererRD::ParticlesStorage::get_singleton()->owns_particles_collision(p_rid)) {
|
|
|
|
RendererRD::ParticlesStorage::get_singleton()->particles_collision_free(p_rid);
|
2021-06-16 20:43:02 +02:00
|
|
|
} else if (visibility_notifier_owner.owns(p_rid)) {
|
2021-09-29 19:08:41 +02:00
|
|
|
VisibilityNotifier *vn = visibility_notifier_owner.get_or_null(p_rid);
|
2021-06-16 20:43:02 +02:00
|
|
|
vn->dependency.deleted_notify(p_rid);
|
|
|
|
visibility_notifier_owner.free(p_rid);
|
2022-04-12 13:41:50 +02:00
|
|
|
} else if (RendererRD::ParticlesStorage::get_singleton()->owns_particles_collision_instance(p_rid)) {
|
|
|
|
RendererRD::ParticlesStorage::get_singleton()->particles_collision_instance_free(p_rid);
|
2021-10-03 13:28:55 +02:00
|
|
|
} else if (fog_volume_owner.owns(p_rid)) {
|
|
|
|
FogVolume *fog_volume = fog_volume_owner.get_or_null(p_rid);
|
|
|
|
fog_volume->dependency.deleted_notify(p_rid);
|
|
|
|
fog_volume_owner.free(p_rid);
|
2022-04-07 16:00:51 +02:00
|
|
|
} else if (RendererRD::TextureStorage::get_singleton()->owns_render_target(p_rid)) {
|
|
|
|
RendererRD::TextureStorage::get_singleton()->render_target_free(p_rid);
|
2019-06-16 04:45:24 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-21 16:31:30 +02:00
|
|
|
|
2021-07-20 13:40:16 +02:00
|
|
|
void RendererStorageRD::init_effects(bool p_prefer_raster_effects) {
|
|
|
|
effects = memnew(EffectsRD(p_prefer_raster_effects));
|
|
|
|
}
|
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
EffectsRD *RendererStorageRD::get_effects() {
|
2021-07-20 13:40:16 +02:00
|
|
|
ERR_FAIL_NULL_V_MSG(effects, nullptr, "Effects haven't been initialised yet.");
|
|
|
|
return effects;
|
2019-07-27 15:23:24 +02:00
|
|
|
}
|
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
void RendererStorageRD::capture_timestamps_begin() {
|
2021-01-26 01:52:58 +01:00
|
|
|
RD::get_singleton()->capture_timestamp("Frame Begin");
|
2019-09-20 22:58:06 +02:00
|
|
|
}
|
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
void RendererStorageRD::capture_timestamp(const String &p_name) {
|
2021-01-26 01:52:58 +01:00
|
|
|
RD::get_singleton()->capture_timestamp(p_name);
|
2019-09-20 22:58:06 +02:00
|
|
|
}
|
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
uint32_t RendererStorageRD::get_captured_timestamps_count() const {
|
2019-09-20 22:58:06 +02:00
|
|
|
return RD::get_singleton()->get_captured_timestamps_count();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
uint64_t RendererStorageRD::get_captured_timestamps_frame() const {
|
2019-09-20 22:58:06 +02:00
|
|
|
return RD::get_singleton()->get_captured_timestamps_frame();
|
|
|
|
}
|
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
uint64_t RendererStorageRD::get_captured_timestamp_gpu_time(uint32_t p_index) const {
|
2019-09-20 22:58:06 +02:00
|
|
|
return RD::get_singleton()->get_captured_timestamp_gpu_time(p_index);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
uint64_t RendererStorageRD::get_captured_timestamp_cpu_time(uint32_t p_index) const {
|
2019-09-20 22:58:06 +02:00
|
|
|
return RD::get_singleton()->get_captured_timestamp_cpu_time(p_index);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
String RendererStorageRD::get_captured_timestamp_name(uint32_t p_index) const {
|
2019-09-20 22:58:06 +02:00
|
|
|
return RD::get_singleton()->get_captured_timestamp_name(p_index);
|
|
|
|
}
|
|
|
|
|
2021-07-03 01:14:19 +02:00
|
|
|
void RendererStorageRD::update_memory_info() {
|
|
|
|
texture_mem_cache = RenderingDevice::get_singleton()->get_memory_usage(RenderingDevice::MEMORY_TEXTURES);
|
|
|
|
buffer_mem_cache = RenderingDevice::get_singleton()->get_memory_usage(RenderingDevice::MEMORY_BUFFERS);
|
|
|
|
total_mem_cache = RenderingDevice::get_singleton()->get_memory_usage(RenderingDevice::MEMORY_TOTAL);
|
|
|
|
}
|
|
|
|
uint64_t RendererStorageRD::get_rendering_info(RS::RenderingInfo p_info) {
|
|
|
|
if (p_info == RS::RENDERING_INFO_TEXTURE_MEM_USED) {
|
|
|
|
return texture_mem_cache;
|
|
|
|
} else if (p_info == RS::RENDERING_INFO_BUFFER_MEM_USED) {
|
|
|
|
return buffer_mem_cache;
|
|
|
|
} else if (p_info == RS::RENDERING_INFO_VIDEO_MEM_USED) {
|
|
|
|
return total_mem_cache;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
String RendererStorageRD::get_video_adapter_name() const {
|
|
|
|
return RenderingDevice::get_singleton()->get_device_name();
|
|
|
|
}
|
2021-12-10 17:01:51 +01:00
|
|
|
|
2021-07-03 01:14:19 +02:00
|
|
|
String RendererStorageRD::get_video_adapter_vendor() const {
|
|
|
|
return RenderingDevice::get_singleton()->get_device_vendor_name();
|
|
|
|
}
|
|
|
|
|
2021-12-10 17:01:51 +01:00
|
|
|
RenderingDevice::DeviceType RendererStorageRD::get_video_adapter_type() const {
|
|
|
|
return RenderingDevice::get_singleton()->get_device_type();
|
|
|
|
}
|
|
|
|
|
2021-07-31 15:39:46 +02:00
|
|
|
String RendererStorageRD::get_video_adapter_api_version() const {
|
|
|
|
return RenderingDevice::get_singleton()->get_device_api_version();
|
|
|
|
}
|
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
RendererStorageRD *RendererStorageRD::base_singleton = nullptr;
|
2020-04-17 04:52:00 +02:00
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
RendererStorageRD::RendererStorageRD() {
|
2020-04-17 04:52:00 +02:00
|
|
|
base_singleton = this;
|
2019-07-21 16:31:30 +02:00
|
|
|
}
|
|
|
|
|
2020-12-04 19:26:24 +01:00
|
|
|
RendererStorageRD::~RendererStorageRD() {
|
2021-07-20 13:40:16 +02:00
|
|
|
if (effects) {
|
|
|
|
memdelete(effects);
|
2021-10-12 09:30:55 +02:00
|
|
|
effects = nullptr;
|
2021-07-20 13:40:16 +02:00
|
|
|
}
|
2019-07-21 16:31:30 +02:00
|
|
|
}
|