Debian Codegraph @

scene/resources/sky.cpp

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