diff options
Diffstat (limited to 'modules/opensimplex/noise_texture.cpp')
-rw-r--r-- | modules/opensimplex/noise_texture.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp index aa1c822813..d60099e676 100644 --- a/modules/opensimplex/noise_texture.cpp +++ b/modules/opensimplex/noise_texture.cpp @@ -42,17 +42,16 @@ NoiseTexture::NoiseTexture() { seamless = false; as_normalmap = false; bump_strength = 8.0; - flags = FLAGS_DEFAULT; noise = Ref<OpenSimplexNoise>(); - texture = VS::get_singleton()->texture_create(); - _queue_update(); } NoiseTexture::~NoiseTexture() { - VS::get_singleton()->free(texture); + if (texture.is_valid()) { + VS::get_singleton()->free(texture); + } if (noise_thread) { Thread::wait_to_finish(noise_thread); memdelete(noise_thread); @@ -85,7 +84,7 @@ void NoiseTexture::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "height", PROPERTY_HINT_RANGE, "1,2048,1,or_greater"), "set_height", "get_height"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "seamless"), "set_seamless", "get_seamless"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "as_normalmap"), "set_as_normalmap", "is_normalmap"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "bump_strength", PROPERTY_HINT_RANGE, "0,32,0.1,or_greater"), "set_bump_strength", "get_bump_strength"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bump_strength", PROPERTY_HINT_RANGE, "0,32,0.1,or_greater"), "set_bump_strength", "get_bump_strength"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "noise", PROPERTY_HINT_RESOURCE_TYPE, "OpenSimplexNoise"), "set_noise", "get_noise"); } @@ -101,8 +100,12 @@ void NoiseTexture::_validate_property(PropertyInfo &property) const { void NoiseTexture::_set_texture_data(const Ref<Image> &p_image) { data = p_image; if (data.is_valid()) { - VS::get_singleton()->texture_allocate(texture, size.x, size.y, 0, Image::FORMAT_RGBA8, VS::TEXTURE_TYPE_2D, flags); - VS::get_singleton()->texture_set_data(texture, p_image); + if (texture.is_valid()) { + RID new_texture = VS::get_singleton()->texture_2d_create(p_image); + VS::get_singleton()->texture_replace(texture, new_texture); + } else { + texture = VS::get_singleton()->texture_2d_create(p_image); + } } emit_changed(); } @@ -181,11 +184,11 @@ void NoiseTexture::set_noise(Ref<OpenSimplexNoise> p_noise) { if (p_noise == noise) return; if (noise.is_valid()) { - noise->disconnect(CoreStringNames::get_singleton()->changed, this, "_queue_update"); + noise->disconnect_compat(CoreStringNames::get_singleton()->changed, this, "_queue_update"); } noise = p_noise; if (noise.is_valid()) { - noise->connect(CoreStringNames::get_singleton()->changed, this, "_queue_update"); + noise->connect_compat(CoreStringNames::get_singleton()->changed, this, "_queue_update"); } _queue_update(); } @@ -250,13 +253,12 @@ int NoiseTexture::get_height() const { return size.y; } -void NoiseTexture::set_flags(uint32_t p_flags) { - flags = p_flags; - VS::get_singleton()->texture_set_flags(texture, flags); -} +RID NoiseTexture::get_rid() const { + if (!texture.is_valid()) { + texture = VS::get_singleton()->texture_2d_placeholder_create(); + } -uint32_t NoiseTexture::get_flags() const { - return flags; + return texture; } Ref<Image> NoiseTexture::get_data() const { |