1/**************************************************************************/
2/* placeholder_textures.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 "placeholder_textures.h"
32
33void PlaceholderTexture2D::set_size(Size2 p_size) {
34 size = p_size;
35}
36
37int PlaceholderTexture2D::get_width() const {
38 return size.width;
39}
40
41int PlaceholderTexture2D::get_height() const {
42 return size.height;
43}
44
45bool PlaceholderTexture2D::has_alpha() const {
46 return false;
47}
48
49Ref<Image> PlaceholderTexture2D::get_image() const {
50 return Ref<Image>();
51}
52
53RID PlaceholderTexture2D::get_rid() const {
54 if (rid.is_null()) {
55 rid = RenderingServer::get_singleton()->texture_2d_placeholder_create();
56 }
57 return rid;
58}
59
60void PlaceholderTexture2D::_bind_methods() {
61 ClassDB::bind_method(D_METHOD("set_size", "size"), &PlaceholderTexture2D::set_size);
62
63 ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size", PROPERTY_HINT_NONE, "suffix:px"), "set_size", "get_size");
64}
65
66PlaceholderTexture2D::PlaceholderTexture2D() {
67}
68
69PlaceholderTexture2D::~PlaceholderTexture2D() {
70 ERR_FAIL_NULL(RenderingServer::get_singleton());
71 if (rid.is_valid()) {
72 RS::get_singleton()->free(rid);
73 }
74}
75
76///////////////////////////////////////////////
77
78void PlaceholderTexture3D::set_size(const Vector3i &p_size) {
79 size = p_size;
80}
81
82Vector3i PlaceholderTexture3D::get_size() const {
83 return size;
84}
85
86Image::Format PlaceholderTexture3D::get_format() const {
87 return Image::FORMAT_RGB8;
88}
89
90int PlaceholderTexture3D::get_width() const {
91 return size.x;
92}
93
94int PlaceholderTexture3D::get_height() const {
95 return size.y;
96}
97
98int PlaceholderTexture3D::get_depth() const {
99 return size.z;
100}
101
102bool PlaceholderTexture3D::has_mipmaps() const {
103 return false;
104}
105
106Vector<Ref<Image>> PlaceholderTexture3D::get_data() const {
107 return Vector<Ref<Image>>();
108}
109
110RID PlaceholderTexture3D::get_rid() const {
111 if (rid.is_null()) {
112 rid = RenderingServer::get_singleton()->texture_3d_placeholder_create();
113 }
114 return rid;
115}
116
117void PlaceholderTexture3D::_bind_methods() {
118 ClassDB::bind_method(D_METHOD("set_size", "size"), &PlaceholderTexture3D::set_size);
119 ClassDB::bind_method(D_METHOD("get_size"), &PlaceholderTexture3D::get_size);
120 ADD_PROPERTY(PropertyInfo(Variant::VECTOR3I, "size", PROPERTY_HINT_NONE, "suffix:px"), "set_size", "get_size");
121}
122
123PlaceholderTexture3D::PlaceholderTexture3D() {
124}
125PlaceholderTexture3D::~PlaceholderTexture3D() {
126 ERR_FAIL_NULL(RenderingServer::get_singleton());
127 if (rid.is_valid()) {
128 RS::get_singleton()->free(rid);
129 }
130}
131
132/////////////////////////////////////////////////
133
134void PlaceholderTextureLayered::set_size(const Size2i &p_size) {
135 size = p_size;
136}
137
138Size2i PlaceholderTextureLayered::get_size() const {
139 return size;
140}
141
142void PlaceholderTextureLayered::set_layers(int p_layers) {
143 layers = p_layers;
144}
145
146Image::Format PlaceholderTextureLayered::get_format() const {
147 return Image::FORMAT_RGB8;
148}
149
150TextureLayered::LayeredType PlaceholderTextureLayered::get_layered_type() const {
151 return layered_type;
152}
153
154int PlaceholderTextureLayered::get_width() const {
155 return size.x;
156}
157
158int PlaceholderTextureLayered::get_height() const {
159 return size.y;
160}
161
162int PlaceholderTextureLayered::get_layers() const {
163 return layers;
164}
165
166bool PlaceholderTextureLayered::has_mipmaps() const {
167 return false;
168}
169
170Ref<Image> PlaceholderTextureLayered::get_layer_data(int p_layer) const {
171 return Ref<Image>();
172}
173
174RID PlaceholderTextureLayered::get_rid() const {
175 if (rid.is_null()) {
176 rid = RS::get_singleton()->texture_2d_layered_placeholder_create(RS::TextureLayeredType(layered_type));
177 }
178 return rid;
179}
180
181void PlaceholderTextureLayered::_bind_methods() {
182 ClassDB::bind_method(D_METHOD("set_size", "size"), &PlaceholderTextureLayered::set_size);
183 ClassDB::bind_method(D_METHOD("get_size"), &PlaceholderTextureLayered::get_size);
184 ClassDB::bind_method(D_METHOD("set_layers", "layers"), &PlaceholderTextureLayered::set_layers);
185 ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size", PROPERTY_HINT_NONE, "suffix:px"), "set_size", "get_size");
186 ADD_PROPERTY(PropertyInfo(Variant::INT, "layers", PROPERTY_HINT_RANGE, "1,4096"), "set_layers", "get_layers");
187}
188
189PlaceholderTextureLayered::PlaceholderTextureLayered(LayeredType p_type) {
190 layered_type = p_type;
191}
192PlaceholderTextureLayered::~PlaceholderTextureLayered() {
193 ERR_FAIL_NULL(RenderingServer::get_singleton());
194 if (rid.is_valid()) {
195 RS::get_singleton()->free(rid);
196 }
197}
198