image_texture.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /**************************************************************************/
  2. /* image_texture.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 "image_texture.h"
  31. #include "core/io/image_loader.h"
  32. #include "scene/resources/bit_map.h"
  33. #include "scene/resources/placeholder_textures.h"
  34. #include "servers/rendering/rendering_server.h"
  35. void ImageTexture::reload_from_file() {
  36. String path = ResourceLoader::path_remap(get_path());
  37. if (!path.is_resource_file()) {
  38. return;
  39. }
  40. Ref<Image> img;
  41. img.instantiate();
  42. if (ImageLoader::load_image(path, img) == OK) {
  43. set_image(img);
  44. } else {
  45. Resource::reload_from_file();
  46. notify_property_list_changed();
  47. emit_changed();
  48. }
  49. }
  50. Ref<ImageTexture> ImageTexture::create_from_image(const Ref<Image> &p_image) {
  51. ERR_FAIL_COND_V_MSG(p_image.is_null(), Ref<ImageTexture>(), "Invalid image: null");
  52. ERR_FAIL_COND_V_MSG(p_image->is_empty(), Ref<ImageTexture>(), "Invalid image: image is empty");
  53. Ref<ImageTexture> image_texture;
  54. image_texture.instantiate();
  55. image_texture->set_image(p_image);
  56. return image_texture;
  57. }
  58. void ImageTexture::set_image(const Ref<Image> &p_image) {
  59. if (p_image.is_null() || p_image->is_empty()) {
  60. if (image_stored) {
  61. ERR_PRINT("Invalid image");
  62. }
  63. return;
  64. }
  65. w = p_image->get_width();
  66. h = p_image->get_height();
  67. format = p_image->get_format();
  68. mipmaps = p_image->has_mipmaps();
  69. if (texture.is_null()) {
  70. texture = RenderingServer::get_singleton()->texture_2d_create(p_image);
  71. } else {
  72. RID new_texture = RenderingServer::get_singleton()->texture_2d_create(p_image);
  73. RenderingServer::get_singleton()->texture_replace(texture, new_texture);
  74. }
  75. notify_property_list_changed();
  76. emit_changed();
  77. image_stored = true;
  78. }
  79. Image::Format ImageTexture::get_format() const {
  80. return format;
  81. }
  82. void ImageTexture::update(const Ref<Image> &p_image) {
  83. ERR_FAIL_COND_MSG(p_image.is_null(), "Invalid image");
  84. ERR_FAIL_COND_MSG(texture.is_null(), "Texture is not initialized.");
  85. ERR_FAIL_COND_MSG(p_image->get_width() != w || p_image->get_height() != h,
  86. "The new image dimensions must match the texture size.");
  87. ERR_FAIL_COND_MSG(p_image->get_format() != format,
  88. "The new image format must match the texture's image format.");
  89. ERR_FAIL_COND_MSG(mipmaps != p_image->has_mipmaps(),
  90. "The new image mipmaps configuration must match the texture's image mipmaps configuration");
  91. RS::get_singleton()->texture_2d_update(texture, p_image);
  92. notify_property_list_changed();
  93. emit_changed();
  94. alpha_cache.unref();
  95. image_stored = true;
  96. }
  97. Ref<Image> ImageTexture::get_image() const {
  98. if (image_stored) {
  99. return RenderingServer::get_singleton()->texture_2d_get(texture);
  100. } else {
  101. return Ref<Image>();
  102. }
  103. }
  104. int ImageTexture::get_width() const {
  105. return w;
  106. }
  107. int ImageTexture::get_height() const {
  108. return h;
  109. }
  110. RID ImageTexture::get_rid() const {
  111. if (texture.is_null()) {
  112. // We are in trouble, create something temporary.
  113. texture = RenderingServer::get_singleton()->texture_2d_placeholder_create();
  114. }
  115. return texture;
  116. }
  117. bool ImageTexture::has_alpha() const {
  118. return (format == Image::FORMAT_LA8 || format == Image::FORMAT_RGBA8);
  119. }
  120. void ImageTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose) const {
  121. if ((w | h) == 0) {
  122. return;
  123. }
  124. RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose);
  125. }
  126. void ImageTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose) const {
  127. if ((w | h) == 0) {
  128. return;
  129. }
  130. RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose);
  131. }
  132. void ImageTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, bool p_clip_uv) const {
  133. if ((w | h) == 0) {
  134. return;
  135. }
  136. RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, p_clip_uv);
  137. }
  138. bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const {
  139. if (alpha_cache.is_null()) {
  140. Ref<Image> img = get_image();
  141. if (img.is_valid()) {
  142. if (img->is_compressed()) { //must decompress, if compressed
  143. Ref<Image> decom = img->duplicate();
  144. decom->decompress();
  145. img = decom;
  146. }
  147. alpha_cache.instantiate();
  148. alpha_cache->create_from_image_alpha(img);
  149. }
  150. }
  151. if (alpha_cache.is_valid()) {
  152. int aw = int(alpha_cache->get_size().width);
  153. int ah = int(alpha_cache->get_size().height);
  154. if (aw == 0 || ah == 0) {
  155. return true;
  156. }
  157. int x = p_x * aw / w;
  158. int y = p_y * ah / h;
  159. x = CLAMP(x, 0, aw - 1);
  160. y = CLAMP(y, 0, ah - 1);
  161. return alpha_cache->get_bit(x, y);
  162. }
  163. return true;
  164. }
  165. void ImageTexture::set_size_override(const Size2i &p_size) {
  166. Size2i s = p_size;
  167. if (s.x != 0) {
  168. w = s.x;
  169. }
  170. if (s.y != 0) {
  171. h = s.y;
  172. }
  173. RenderingServer::get_singleton()->texture_set_size_override(texture, w, h);
  174. }
  175. void ImageTexture::set_path(const String &p_path, bool p_take_over) {
  176. if (texture.is_valid()) {
  177. RenderingServer::get_singleton()->texture_set_path(texture, p_path);
  178. }
  179. Resource::set_path(p_path, p_take_over);
  180. }
  181. void ImageTexture::_bind_methods() {
  182. ClassDB::bind_static_method("ImageTexture", D_METHOD("create_from_image", "image"), &ImageTexture::create_from_image);
  183. ClassDB::bind_method(D_METHOD("get_format"), &ImageTexture::get_format);
  184. ClassDB::bind_method(D_METHOD("set_image", "image"), &ImageTexture::set_image);
  185. ClassDB::bind_method(D_METHOD("update", "image"), &ImageTexture::update);
  186. ClassDB::bind_method(D_METHOD("set_size_override", "size"), &ImageTexture::set_size_override);
  187. ClassDB::bind_method(D_METHOD("_set_image", "image"), &ImageTexture::set_image);
  188. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Image", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT), "_set_image", "get_image");
  189. }
  190. ImageTexture::~ImageTexture() {
  191. if (texture.is_valid()) {
  192. ERR_FAIL_NULL(RenderingServer::get_singleton());
  193. RenderingServer::get_singleton()->free_rid(texture);
  194. }
  195. }
  196. Image::Format ImageTextureLayered::get_format() const {
  197. return format;
  198. }
  199. int ImageTextureLayered::get_width() const {
  200. return width;
  201. }
  202. int ImageTextureLayered::get_height() const {
  203. return height;
  204. }
  205. int ImageTextureLayered::get_layers() const {
  206. return layers;
  207. }
  208. bool ImageTextureLayered::has_mipmaps() const {
  209. return mipmaps;
  210. }
  211. ImageTextureLayered::LayeredType ImageTextureLayered::get_layered_type() const {
  212. return layered_type;
  213. }
  214. Error ImageTextureLayered::_create_from_images(const TypedArray<Image> &p_images) {
  215. Vector<Ref<Image>> images;
  216. for (int i = 0; i < p_images.size(); i++) {
  217. Ref<Image> img = p_images[i];
  218. ERR_FAIL_COND_V(img.is_null(), ERR_INVALID_PARAMETER);
  219. images.push_back(img);
  220. }
  221. return create_from_images(images);
  222. }
  223. TypedArray<Image> ImageTextureLayered::_get_images() const {
  224. TypedArray<Image> images;
  225. for (int i = 0; i < layers; i++) {
  226. images.push_back(get_layer_data(i));
  227. }
  228. return images;
  229. }
  230. void ImageTextureLayered::_set_images(const TypedArray<Image> &p_images) {
  231. ERR_FAIL_COND(_create_from_images(p_images) != OK);
  232. }
  233. Error ImageTextureLayered::create_from_images(Vector<Ref<Image>> p_images) {
  234. int new_layers = p_images.size();
  235. ERR_FAIL_COND_V(new_layers == 0, ERR_INVALID_PARAMETER);
  236. if (layered_type == LAYERED_TYPE_CUBEMAP) {
  237. ERR_FAIL_COND_V_MSG(new_layers != 6, ERR_INVALID_PARAMETER,
  238. "Cubemaps require exactly 6 layers");
  239. } else if (layered_type == LAYERED_TYPE_CUBEMAP_ARRAY) {
  240. ERR_FAIL_COND_V_MSG((new_layers % 6) != 0, ERR_INVALID_PARAMETER,
  241. "Cubemap array layers must be a multiple of 6");
  242. }
  243. ERR_FAIL_COND_V(p_images[0].is_null() || p_images[0]->is_empty(), ERR_INVALID_PARAMETER);
  244. Image::Format new_format = p_images[0]->get_format();
  245. int new_width = p_images[0]->get_width();
  246. int new_height = p_images[0]->get_height();
  247. bool new_mipmaps = p_images[0]->has_mipmaps();
  248. for (int i = 1; i < p_images.size(); i++) {
  249. ERR_FAIL_COND_V_MSG(p_images[i]->get_format() != new_format, ERR_INVALID_PARAMETER,
  250. "All images must share the same format");
  251. ERR_FAIL_COND_V_MSG(p_images[i]->get_width() != new_width || p_images[i]->get_height() != new_height, ERR_INVALID_PARAMETER,
  252. "All images must share the same dimensions");
  253. ERR_FAIL_COND_V_MSG(p_images[i]->has_mipmaps() != new_mipmaps, ERR_INVALID_PARAMETER,
  254. "All images must share the usage of mipmaps");
  255. }
  256. if (texture.is_valid()) {
  257. RID new_texture = RS::get_singleton()->texture_2d_layered_create(p_images, RS::TextureLayeredType(layered_type));
  258. ERR_FAIL_COND_V(!new_texture.is_valid(), ERR_CANT_CREATE);
  259. RS::get_singleton()->texture_replace(texture, new_texture);
  260. } else {
  261. texture = RS::get_singleton()->texture_2d_layered_create(p_images, RS::TextureLayeredType(layered_type));
  262. ERR_FAIL_COND_V(!texture.is_valid(), ERR_CANT_CREATE);
  263. }
  264. format = new_format;
  265. width = new_width;
  266. height = new_height;
  267. layers = new_layers;
  268. mipmaps = new_mipmaps;
  269. return OK;
  270. }
  271. void ImageTextureLayered::update_layer(const Ref<Image> &p_image, int p_layer) {
  272. ERR_FAIL_COND_MSG(texture.is_null(), "Texture is not initialized.");
  273. ERR_FAIL_COND_MSG(p_image.is_null(), "Invalid image.");
  274. ERR_FAIL_COND_MSG(p_image->get_format() != format, "Image format must match texture's image format.");
  275. ERR_FAIL_COND_MSG(p_image->get_width() != width || p_image->get_height() != height, "Image size must match texture's image size.");
  276. ERR_FAIL_COND_MSG(p_image->has_mipmaps() != mipmaps, "Image mipmap configuration must match texture's image mipmap configuration.");
  277. ERR_FAIL_INDEX_MSG(p_layer, layers, "Layer index is out of bounds.");
  278. RS::get_singleton()->texture_2d_update(texture, p_image, p_layer);
  279. }
  280. Ref<Image> ImageTextureLayered::get_layer_data(int p_layer) const {
  281. ERR_FAIL_INDEX_V(p_layer, layers, Ref<Image>());
  282. return RS::get_singleton()->texture_2d_layer_get(texture, p_layer);
  283. }
  284. RID ImageTextureLayered::get_rid() const {
  285. if (texture.is_null()) {
  286. texture = RS::get_singleton()->texture_2d_layered_placeholder_create(RS::TextureLayeredType(layered_type));
  287. }
  288. return texture;
  289. }
  290. void ImageTextureLayered::set_path(const String &p_path, bool p_take_over) {
  291. if (texture.is_valid()) {
  292. RS::get_singleton()->texture_set_path(texture, p_path);
  293. }
  294. Resource::set_path(p_path, p_take_over);
  295. }
  296. void ImageTextureLayered::_bind_methods() {
  297. ClassDB::bind_method(D_METHOD("create_from_images", "images"), &ImageTextureLayered::_create_from_images);
  298. ClassDB::bind_method(D_METHOD("update_layer", "image", "layer"), &ImageTextureLayered::update_layer);
  299. ClassDB::bind_method(D_METHOD("_get_images"), &ImageTextureLayered::_get_images);
  300. ClassDB::bind_method(D_METHOD("_set_images", "images"), &ImageTextureLayered::_set_images);
  301. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_images", PROPERTY_HINT_ARRAY_TYPE, "Image", PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT), "_set_images", "_get_images");
  302. }
  303. ImageTextureLayered::ImageTextureLayered(LayeredType p_layered_type) {
  304. layered_type = p_layered_type;
  305. }
  306. ImageTextureLayered::~ImageTextureLayered() {
  307. if (texture.is_valid()) {
  308. ERR_FAIL_NULL(RenderingServer::get_singleton());
  309. RS::get_singleton()->free_rid(texture);
  310. }
  311. }
  312. Image::Format ImageTexture3D::get_format() const {
  313. return format;
  314. }
  315. int ImageTexture3D::get_width() const {
  316. return width;
  317. }
  318. int ImageTexture3D::get_height() const {
  319. return height;
  320. }
  321. int ImageTexture3D::get_depth() const {
  322. return depth;
  323. }
  324. bool ImageTexture3D::has_mipmaps() const {
  325. return mipmaps;
  326. }
  327. Error ImageTexture3D::_create(Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const TypedArray<Image> &p_data) {
  328. Vector<Ref<Image>> images;
  329. images.resize(p_data.size());
  330. for (int i = 0; i < images.size(); i++) {
  331. images.write[i] = p_data[i];
  332. }
  333. return create(p_format, p_width, p_height, p_depth, p_mipmaps, images);
  334. }
  335. void ImageTexture3D::_update(const TypedArray<Image> &p_data) {
  336. Vector<Ref<Image>> images;
  337. images.resize(p_data.size());
  338. for (int i = 0; i < images.size(); i++) {
  339. images.write[i] = p_data[i];
  340. }
  341. return update(images);
  342. }
  343. Error ImageTexture3D::create(Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data) {
  344. RID tex = RenderingServer::get_singleton()->texture_3d_create(p_format, p_width, p_height, p_depth, p_mipmaps, p_data);
  345. ERR_FAIL_COND_V(tex.is_null(), ERR_CANT_CREATE);
  346. if (texture.is_valid()) {
  347. RenderingServer::get_singleton()->texture_replace(texture, tex);
  348. } else {
  349. texture = tex;
  350. }
  351. format = p_format;
  352. width = p_width;
  353. height = p_height;
  354. depth = p_depth;
  355. mipmaps = p_mipmaps;
  356. return OK;
  357. }
  358. void ImageTexture3D::update(const Vector<Ref<Image>> &p_data) {
  359. ERR_FAIL_COND(!texture.is_valid());
  360. RenderingServer::get_singleton()->texture_3d_update(texture, p_data);
  361. }
  362. Vector<Ref<Image>> ImageTexture3D::get_data() const {
  363. ERR_FAIL_COND_V(!texture.is_valid(), Vector<Ref<Image>>());
  364. return RS::get_singleton()->texture_3d_get(texture);
  365. }
  366. RID ImageTexture3D::get_rid() const {
  367. if (!texture.is_valid()) {
  368. texture = RS::get_singleton()->texture_3d_placeholder_create();
  369. }
  370. return texture;
  371. }
  372. void ImageTexture3D::set_path(const String &p_path, bool p_take_over) {
  373. if (texture.is_valid()) {
  374. RenderingServer::get_singleton()->texture_set_path(texture, p_path);
  375. }
  376. Resource::set_path(p_path, p_take_over);
  377. }
  378. TypedArray<Image> ImageTexture3D::_get_images() const {
  379. TypedArray<Image> images;
  380. if (texture.is_valid()) {
  381. Vector<Ref<Image>> raw_images = get_data();
  382. ERR_FAIL_COND_V(raw_images.is_empty(), TypedArray<Image>());
  383. for (int i = 0; i < raw_images.size(); i++) {
  384. images.push_back(raw_images[i]);
  385. }
  386. }
  387. return images;
  388. }
  389. void ImageTexture3D::_set_images(const TypedArray<Image> &p_images) {
  390. if (p_images.size() == 0) {
  391. if (images_stored) {
  392. ERR_PRINT("Invalid images");
  393. }
  394. return;
  395. }
  396. Ref<Image> img_base = p_images[0];
  397. ERR_FAIL_COND(img_base.is_null());
  398. Image::Format new_format = img_base->get_format();
  399. int new_width = img_base->get_width();
  400. int new_height = img_base->get_height();
  401. int new_depth = 0;
  402. bool new_mipmaps = false;
  403. for (int i = 1; i < p_images.size(); i++) {
  404. Ref<Image> img = p_images[i];
  405. ERR_FAIL_COND(img.is_null());
  406. ERR_FAIL_COND_MSG(img->get_format() != new_format, "All images must share the same format.");
  407. if (img->get_width() != new_width || img->get_height() != new_height) {
  408. new_mipmaps = true;
  409. if (new_depth == 0) {
  410. new_depth = i;
  411. }
  412. }
  413. }
  414. if (new_depth == 0) {
  415. new_depth = p_images.size();
  416. }
  417. Error err = _create(new_format, new_width, new_height, new_depth, new_mipmaps, p_images);
  418. ERR_FAIL_COND(err != OK);
  419. images_stored = true;
  420. }
  421. void ImageTexture3D::_bind_methods() {
  422. ClassDB::bind_method(D_METHOD("create", "format", "width", "height", "depth", "use_mipmaps", "data"), &ImageTexture3D::_create);
  423. ClassDB::bind_method(D_METHOD("update", "data"), &ImageTexture3D::_update);
  424. ClassDB::bind_method(D_METHOD("_get_images"), &ImageTexture3D::_get_images);
  425. ClassDB::bind_method(D_METHOD("_set_images", "images"), &ImageTexture3D::_set_images);
  426. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_images", PROPERTY_HINT_ARRAY_TYPE, "Image", PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT), "_set_images", "_get_images");
  427. }
  428. ImageTexture3D::ImageTexture3D() {
  429. }
  430. ImageTexture3D::~ImageTexture3D() {
  431. if (texture.is_valid()) {
  432. ERR_FAIL_NULL(RenderingServer::get_singleton());
  433. RS::get_singleton()->free_rid(texture);
  434. }
  435. }
  436. void Texture2DArray::_bind_methods() {
  437. ClassDB::bind_method(D_METHOD("create_placeholder"), &Texture2DArray::create_placeholder);
  438. }
  439. Ref<Resource> Texture2DArray::create_placeholder() const {
  440. Ref<PlaceholderTexture2DArray> placeholder;
  441. placeholder.instantiate();
  442. placeholder->set_size(Size2i(get_width(), get_height()));
  443. placeholder->set_layers(get_layers());
  444. return placeholder;
  445. }
  446. void Cubemap::_bind_methods() {
  447. ClassDB::bind_method(D_METHOD("create_placeholder"), &Cubemap::create_placeholder);
  448. }
  449. Ref<Resource> Cubemap::create_placeholder() const {
  450. Ref<PlaceholderCubemap> placeholder;
  451. placeholder.instantiate();
  452. placeholder->set_size(Size2i(get_width(), get_height()));
  453. placeholder->set_layers(get_layers());
  454. return placeholder;
  455. }
  456. void CubemapArray::_bind_methods() {
  457. ClassDB::bind_method(D_METHOD("create_placeholder"), &CubemapArray::create_placeholder);
  458. }
  459. Ref<Resource> CubemapArray::create_placeholder() const {
  460. Ref<PlaceholderCubemapArray> placeholder;
  461. placeholder.instantiate();
  462. placeholder->set_size(Size2i(get_width(), get_height()));
  463. placeholder->set_layers(get_layers());
  464. return placeholder;
  465. }