sky.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**************************************************************************/
  2. /* sky.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 "sky.h"
  31. void Sky::set_radiance_size(RadianceSize p_size) {
  32. ERR_FAIL_INDEX(p_size, RADIANCE_SIZE_MAX);
  33. radiance_size = p_size;
  34. static const int size[RADIANCE_SIZE_MAX] = {
  35. 32, 64, 128, 256, 512, 1024, 2048
  36. };
  37. RS::get_singleton()->sky_set_radiance_size(sky, size[radiance_size]);
  38. }
  39. Sky::RadianceSize Sky::get_radiance_size() const {
  40. return radiance_size;
  41. }
  42. void Sky::set_process_mode(ProcessMode p_mode) {
  43. mode = p_mode;
  44. RS::get_singleton()->sky_set_mode(sky, RS::SkyMode(mode));
  45. }
  46. Sky::ProcessMode Sky::get_process_mode() const {
  47. return mode;
  48. }
  49. void Sky::set_material(const Ref<Material> &p_material) {
  50. sky_material = p_material;
  51. RID material_rid;
  52. if (sky_material.is_valid()) {
  53. material_rid = sky_material->get_rid();
  54. }
  55. RS::get_singleton()->sky_set_material(sky, material_rid);
  56. }
  57. Ref<Material> Sky::get_material() const {
  58. return sky_material;
  59. }
  60. RID Sky::get_rid() const {
  61. return sky;
  62. }
  63. void Sky::_bind_methods() {
  64. ClassDB::bind_method(D_METHOD("set_radiance_size", "size"), &Sky::set_radiance_size);
  65. ClassDB::bind_method(D_METHOD("get_radiance_size"), &Sky::get_radiance_size);
  66. ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Sky::set_process_mode);
  67. ClassDB::bind_method(D_METHOD("get_process_mode"), &Sky::get_process_mode);
  68. ClassDB::bind_method(D_METHOD("set_material", "material"), &Sky::set_material);
  69. ClassDB::bind_method(D_METHOD("get_material"), &Sky::get_material);
  70. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "sky_material", PROPERTY_HINT_RESOURCE_TYPE, "PanoramaSkyMaterial,ProceduralSkyMaterial,PhysicalSkyMaterial,ShaderMaterial"), "set_material", "get_material");
  71. ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Automatic,High-Quality,High-Quality Incremental,Real-Time"), "set_process_mode", "get_process_mode");
  72. ADD_PROPERTY(PropertyInfo(Variant::INT, "radiance_size", PROPERTY_HINT_ENUM, "32,64,128,256,512,1024,2048"), "set_radiance_size", "get_radiance_size");
  73. BIND_ENUM_CONSTANT(RADIANCE_SIZE_32);
  74. BIND_ENUM_CONSTANT(RADIANCE_SIZE_64);
  75. BIND_ENUM_CONSTANT(RADIANCE_SIZE_128);
  76. BIND_ENUM_CONSTANT(RADIANCE_SIZE_256);
  77. BIND_ENUM_CONSTANT(RADIANCE_SIZE_512);
  78. BIND_ENUM_CONSTANT(RADIANCE_SIZE_1024);
  79. BIND_ENUM_CONSTANT(RADIANCE_SIZE_2048);
  80. BIND_ENUM_CONSTANT(RADIANCE_SIZE_MAX);
  81. BIND_ENUM_CONSTANT(PROCESS_MODE_AUTOMATIC);
  82. BIND_ENUM_CONSTANT(PROCESS_MODE_QUALITY);
  83. BIND_ENUM_CONSTANT(PROCESS_MODE_INCREMENTAL);
  84. BIND_ENUM_CONSTANT(PROCESS_MODE_REALTIME);
  85. }
  86. Sky::Sky() {
  87. sky = RS::get_singleton()->sky_create();
  88. }
  89. Sky::~Sky() {
  90. ERR_FAIL_NULL(RenderingServer::get_singleton());
  91. RS::get_singleton()->free(sky);
  92. }