Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/dummy/storage/utilities.cpp
10279 views
1
/**************************************************************************/
2
/* utilities.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "utilities.h"
32
33
#include "light_storage.h"
34
#include "material_storage.h"
35
#include "mesh_storage.h"
36
#include "texture_storage.h"
37
38
using namespace RendererDummy;
39
40
Utilities *Utilities::singleton = nullptr;
41
42
RS::InstanceType Utilities::get_base_type(RID p_rid) const {
43
if (RendererDummy::MeshStorage::get_singleton()->owns_mesh(p_rid)) {
44
return RS::INSTANCE_MESH;
45
} else if (RendererDummy::MeshStorage::get_singleton()->owns_multimesh(p_rid)) {
46
return RS::INSTANCE_MULTIMESH;
47
} else if (RendererDummy::LightStorage::get_singleton()->owns_lightmap(p_rid)) {
48
return RS::INSTANCE_LIGHTMAP;
49
}
50
return RS::INSTANCE_NONE;
51
}
52
53
bool Utilities::free(RID p_rid) {
54
if (RendererDummy::LightStorage::get_singleton()->free(p_rid)) {
55
return true;
56
} else if (RendererDummy::TextureStorage::get_singleton()->owns_texture(p_rid)) {
57
RendererDummy::TextureStorage::get_singleton()->texture_free(p_rid);
58
return true;
59
} else if (RendererDummy::MeshStorage::get_singleton()->owns_mesh(p_rid)) {
60
RendererDummy::MeshStorage::get_singleton()->mesh_free(p_rid);
61
return true;
62
} else if (RendererDummy::MeshStorage::get_singleton()->owns_multimesh(p_rid)) {
63
RendererDummy::MeshStorage::get_singleton()->multimesh_free(p_rid);
64
return true;
65
} else if (RendererDummy::MaterialStorage::get_singleton()->owns_shader(p_rid)) {
66
RendererDummy::MaterialStorage::get_singleton()->shader_free(p_rid);
67
return true;
68
} else if (RendererDummy::MaterialStorage::get_singleton()->owns_material(p_rid)) {
69
RendererDummy::MaterialStorage::get_singleton()->material_free(p_rid);
70
return true;
71
}
72
return false;
73
}
74
75
void Utilities::base_update_dependency(RID p_base, DependencyTracker *p_instance) {
76
if (RendererDummy::MeshStorage::get_singleton()->owns_mesh(p_base)) {
77
DummyMesh *mesh = RendererDummy::MeshStorage::get_singleton()->get_mesh(p_base);
78
p_instance->update_dependency(&mesh->dependency);
79
}
80
}
81
82
Utilities::Utilities() {
83
singleton = this;
84
}
85
86
Utilities::~Utilities() {
87
singleton = nullptr;
88
}
89
90