utilities.cpp 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "utilities.h"
  31. #include "light_storage.h"
  32. #include "material_storage.h"
  33. #include "mesh_storage.h"
  34. #include "texture_storage.h"
  35. using namespace RendererDummy;
  36. Utilities *Utilities::singleton = nullptr;
  37. RS::InstanceType Utilities::get_base_type(RID p_rid) const {
  38. if (RendererDummy::MeshStorage::get_singleton()->owns_mesh(p_rid)) {
  39. return RS::INSTANCE_MESH;
  40. } else if (RendererDummy::MeshStorage::get_singleton()->owns_multimesh(p_rid)) {
  41. return RS::INSTANCE_MULTIMESH;
  42. } else if (RendererDummy::LightStorage::get_singleton()->owns_lightmap(p_rid)) {
  43. return RS::INSTANCE_LIGHTMAP;
  44. }
  45. return RS::INSTANCE_NONE;
  46. }
  47. bool Utilities::free(RID p_rid) {
  48. if (RendererDummy::LightStorage::get_singleton()->free(p_rid)) {
  49. return true;
  50. } else if (RendererDummy::TextureStorage::get_singleton()->owns_texture(p_rid)) {
  51. RendererDummy::TextureStorage::get_singleton()->texture_free(p_rid);
  52. return true;
  53. } else if (RendererDummy::MeshStorage::get_singleton()->owns_mesh(p_rid)) {
  54. RendererDummy::MeshStorage::get_singleton()->mesh_free(p_rid);
  55. return true;
  56. } else if (RendererDummy::MeshStorage::get_singleton()->owns_multimesh(p_rid)) {
  57. RendererDummy::MeshStorage::get_singleton()->multimesh_free(p_rid);
  58. return true;
  59. } else if (RendererDummy::MaterialStorage::get_singleton()->owns_shader(p_rid)) {
  60. RendererDummy::MaterialStorage::get_singleton()->shader_free(p_rid);
  61. return true;
  62. } else if (RendererDummy::MaterialStorage::get_singleton()->owns_material(p_rid)) {
  63. RendererDummy::MaterialStorage::get_singleton()->material_free(p_rid);
  64. return true;
  65. }
  66. return false;
  67. }
  68. void Utilities::base_update_dependency(RID p_base, DependencyTracker *p_instance) {
  69. if (RendererDummy::MeshStorage::get_singleton()->owns_mesh(p_base)) {
  70. DummyMesh *mesh = RendererDummy::MeshStorage::get_singleton()->get_mesh(p_base);
  71. p_instance->update_dependency(&mesh->dependency);
  72. }
  73. }
  74. Utilities::Utilities() {
  75. singleton = this;
  76. }
  77. Utilities::~Utilities() {
  78. singleton = nullptr;
  79. }