From 072f6feabac70a6c4ed1a16f4e983bf31ad62d50 Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 22 Jul 2022 20:06:19 +0200 Subject: Make some Image methods static --- drivers/gles3/storage/texture_storage.cpp | 36 ++++++++----------------------- drivers/png/png_driver_common.cpp | 2 +- 2 files changed, 10 insertions(+), 28 deletions(-) (limited to 'drivers') diff --git a/drivers/gles3/storage/texture_storage.cpp b/drivers/gles3/storage/texture_storage.cpp index 48f460f995..554b4165fa 100644 --- a/drivers/gles3/storage/texture_storage.cpp +++ b/drivers/gles3/storage/texture_storage.cpp @@ -59,9 +59,7 @@ TextureStorage::TextureStorage() { { //create default textures { // White Textures - Ref image; - image.instantiate(); - image->create(4, 4, true, Image::FORMAT_RGBA8); + Ref image = Image::create_empty(4, 4, true, Image::FORMAT_RGBA8); image->fill(Color(1, 1, 1, 1)); image->generate_mipmaps(); @@ -90,9 +88,7 @@ TextureStorage::TextureStorage() { } { // black - Ref image; - image.instantiate(); - image->create(4, 4, true, Image::FORMAT_RGBA8); + Ref image = Image::create_empty(4, 4, true, Image::FORMAT_RGBA8); image->fill(Color(0, 0, 0, 1)); image->generate_mipmaps(); @@ -116,9 +112,7 @@ TextureStorage::TextureStorage() { } { // transparent black - Ref image; - image.instantiate(); - image->create(4, 4, true, Image::FORMAT_RGBA8); + Ref image = Image::create_empty(4, 4, true, Image::FORMAT_RGBA8); image->fill(Color(0, 0, 0, 0)); image->generate_mipmaps(); @@ -127,9 +121,7 @@ TextureStorage::TextureStorage() { } { - Ref image; - image.instantiate(); - image->create(4, 4, true, Image::FORMAT_RGBA8); + Ref image = Image::create_empty(4, 4, true, Image::FORMAT_RGBA8); image->fill(Color(0.5, 0.5, 1, 1)); image->generate_mipmaps(); @@ -138,9 +130,7 @@ TextureStorage::TextureStorage() { } { - Ref image; - image.instantiate(); - image->create(4, 4, true, Image::FORMAT_RGBA8); + Ref image = Image::create_empty(4, 4, true, Image::FORMAT_RGBA8); image->fill(Color(1.0, 0.5, 1, 1)); image->generate_mipmaps(); @@ -745,9 +735,7 @@ void TextureStorage::texture_proxy_update(RID p_texture, RID p_proxy_to) { void TextureStorage::texture_2d_placeholder_initialize(RID p_texture) { //this could be better optimized to reuse an existing image , done this way //for now to get it working - Ref image; - image.instantiate(); - image->create(4, 4, false, Image::FORMAT_RGBA8); + Ref image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8); image->fill(Color(1, 0, 1, 1)); texture_2d_initialize(p_texture, image); @@ -756,9 +744,7 @@ void TextureStorage::texture_2d_placeholder_initialize(RID p_texture) { void TextureStorage::texture_2d_layered_placeholder_initialize(RID p_texture, RenderingServer::TextureLayeredType p_layered_type) { //this could be better optimized to reuse an existing image , done this way //for now to get it working - Ref image; - image.instantiate(); - image->create(4, 4, false, Image::FORMAT_RGBA8); + Ref image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8); image->fill(Color(1, 0, 1, 1)); Vector> images; @@ -777,9 +763,7 @@ void TextureStorage::texture_2d_layered_placeholder_initialize(RID p_texture, Re void TextureStorage::texture_3d_placeholder_initialize(RID p_texture) { //this could be better optimized to reuse an existing image , done this way //for now to get it working - Ref image; - image.instantiate(); - image->create(4, 4, false, Image::FORMAT_RGBA8); + Ref image = Image::create_empty(4, 4, false, Image::FORMAT_RGBA8); image->fill(Color(1, 0, 1, 1)); Vector> images; @@ -833,9 +817,7 @@ Ref TextureStorage::texture_2d_get(RID p_texture) const { data.resize(data_size); ERR_FAIL_COND_V(data.size() == 0, Ref()); - Ref image; - image.instantiate(); - image->create(texture->width, texture->height, texture->mipmaps > 1, texture->real_format, data); + Ref image = Image::create_from_data(texture->width, texture->height, texture->mipmaps > 1, texture->real_format, data); ERR_FAIL_COND_V(image->is_empty(), Ref()); if (texture->format != texture->real_format) { image->convert(texture->format); diff --git a/drivers/png/png_driver_common.cpp b/drivers/png/png_driver_common.cpp index bc4bb3782b..79641464d8 100644 --- a/drivers/png/png_driver_common.cpp +++ b/drivers/png/png_driver_common.cpp @@ -119,7 +119,7 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, bool p_force_linear, ERR_FAIL_COND_V(!success, ERR_FILE_CORRUPT); //print_line("png width: "+itos(png_img.width)+" height: "+itos(png_img.height)); - p_image->create(png_img.width, png_img.height, false, dest_format, buffer); + p_image->set_data(png_img.width, png_img.height, false, dest_format, buffer); return OK; } -- cgit v1.2.3