summaryrefslogtreecommitdiff
path: root/scene/resources/texture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/texture.cpp')
-rw-r--r--scene/resources/texture.cpp80
1 files changed, 28 insertions, 52 deletions
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index 0bd8c41228..2b078f1985 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -73,6 +73,7 @@ void Texture::_bind_methods() {
ClassDB::bind_method(D_METHOD("draw", "canvas_item", "pos", "modulate", "transpose", "normal_map:Texture"), &Texture::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("draw_rect", "canvas_item", "rect", "tile", "modulate", "transpose", "normal_map:Texture"), &Texture::draw_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "normal_map:Texture", "clip_uv"), &Texture::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("get_data:Image", "cube_side"), &ImageTexture::get_data);
BIND_CONSTANT(FLAG_MIPMAPS);
BIND_CONSTANT(FLAG_REPEAT);
@@ -91,7 +92,7 @@ Texture::Texture() {
void ImageTexture::reload_from_file() {
- String path = get_path();
+ String path = ResourceLoader::path_remap(get_path());
if (!path.is_resource_file())
return;
@@ -194,6 +195,7 @@ void ImageTexture::create(int p_width, int p_height, Image::Format p_format, uin
}
void ImageTexture::create_from_image(const Ref<Image> &p_image, uint32_t p_flags) {
+ ERR_FAIL_COND(p_image.is_null());
flags = p_flags;
w = p_image->get_width();
h = p_image->get_height();
@@ -352,7 +354,6 @@ void ImageTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_format"), &ImageTexture::get_format);
ClassDB::bind_method(D_METHOD("load", "path"), &ImageTexture::load);
ClassDB::bind_method(D_METHOD("set_data", "image:Image"), &ImageTexture::set_data);
- ClassDB::bind_method(D_METHOD("get_data:Image", "cube_side"), &ImageTexture::get_data);
ClassDB::bind_method(D_METHOD("set_storage", "mode"), &ImageTexture::set_storage);
ClassDB::bind_method(D_METHOD("get_storage"), &ImageTexture::get_storage);
ClassDB::bind_method(D_METHOD("set_lossy_storage_quality", "quality"), &ImageTexture::set_lossy_storage_quality);
@@ -710,13 +711,16 @@ void StreamTexture::set_flags(uint32_t p_flags) {
void StreamTexture::reload_from_file() {
-#ifdef TOOLS_ENABLED
- String ipath = get_import_path();
- if (ipath.is_resource_file() && ipath != path_to_file) {
- path_to_file = ipath;
- }
-#endif
- load(path_to_file);
+ String path = get_path();
+ if (!path.is_resource_file())
+ return;
+
+ path = ResourceLoader::path_remap(path); //remap for translation
+ path = ResourceLoader::import_remap(path); //remap for import
+ if (!path.is_resource_file())
+ return;
+
+ load(path);
}
void StreamTexture::_bind_methods() {
@@ -827,7 +831,7 @@ void AtlasTexture::set_atlas(const Ref<Texture> &p_atlas) {
return;
atlas = p_atlas;
emit_changed();
- emit_signal("atlas_changed");
+ _change_notify("atlas");
}
Ref<Texture> AtlasTexture::get_atlas() const {
@@ -836,8 +840,11 @@ Ref<Texture> AtlasTexture::get_atlas() const {
void AtlasTexture::set_region(const Rect2 &p_region) {
+ if (region == p_region)
+ return;
region = p_region;
emit_changed();
+ _change_notify("region");
}
Rect2 AtlasTexture::get_region() const {
@@ -847,8 +854,11 @@ Rect2 AtlasTexture::get_region() const {
void AtlasTexture::set_margin(const Rect2 &p_margin) {
+ if (margin == p_margin)
+ return;
margin = p_margin;
emit_changed();
+ _change_notify("margin");
}
Rect2 AtlasTexture::get_margin() const {
@@ -867,8 +877,6 @@ void AtlasTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_margin", "margin"), &AtlasTexture::set_margin);
ClassDB::bind_method(D_METHOD("get_margin"), &AtlasTexture::get_margin);
- ADD_SIGNAL(MethodInfo("atlas_changed"));
-
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "atlas", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_atlas", "get_atlas");
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "region"), "set_region", "get_region");
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "margin"), "set_margin", "get_margin");
@@ -1320,8 +1328,8 @@ void CubeMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_flags", "flags"), &CubeMap::set_flags);
ClassDB::bind_method(D_METHOD("get_flags"), &CubeMap::get_flags);
- ClassDB::bind_method(D_METHOD("set_side", "side", "image"), &CubeMap::set_side);
- ClassDB::bind_method(D_METHOD("get_side", "side"), &CubeMap::get_side);
+ ClassDB::bind_method(D_METHOD("set_side", "side", "image:Image"), &CubeMap::set_side);
+ ClassDB::bind_method(D_METHOD("get_side:Image", "side"), &CubeMap::get_side);
ClassDB::bind_method(D_METHOD("set_storage", "mode"), &CubeMap::set_storage);
ClassDB::bind_method(D_METHOD("get_storage"), &CubeMap::get_storage);
ClassDB::bind_method(D_METHOD("set_lossy_storage_quality", "quality"), &CubeMap::set_lossy_storage_quality);
@@ -1370,12 +1378,6 @@ CubeMap::~CubeMap() {
void CurveTexture::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_max", "max"), &CurveTexture::set_max);
- ClassDB::bind_method(D_METHOD("get_max"), &CurveTexture::get_max);
-
- ClassDB::bind_method(D_METHOD("set_min", "min"), &CurveTexture::set_min);
- ClassDB::bind_method(D_METHOD("get_min"), &CurveTexture::get_min);
-
ClassDB::bind_method(D_METHOD("set_width", "width"), &CurveTexture::set_width);
ClassDB::bind_method(D_METHOD("set_curve", "curve:Curve"), &CurveTexture::set_curve);
@@ -1383,52 +1385,31 @@ void CurveTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("_update"), &CurveTexture::_update);
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "min", PROPERTY_HINT_RANGE, "-1024,1024"), "set_min", "get_min");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "max", PROPERTY_HINT_RANGE, "-1024,1024"), "set_max", "get_max");
ADD_PROPERTY(PropertyInfo(Variant::INT, "width", PROPERTY_HINT_RANGE, "32,4096"), "set_width", "get_width");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve", "get_curve");
}
-void CurveTexture::set_max(float p_max) {
-
- _max = p_max;
- emit_changed();
-}
-float CurveTexture::get_max() const {
-
- return _max;
-}
-
-void CurveTexture::set_min(float p_min) {
-
- _min = p_min;
- emit_changed();
-}
-float CurveTexture::get_min() const {
- return _min;
-}
void CurveTexture::set_width(int p_width) {
ERR_FAIL_COND(p_width < 32 || p_width > 4096);
_width = p_width;
_update();
}
+
int CurveTexture::get_width() const {
return _width;
}
-void CurveTexture::ensure_default_setup() {
-
+void CurveTexture::ensure_default_setup(float p_min, float p_max) {
if (_curve.is_null()) {
Ref<Curve> curve = Ref<Curve>(memnew(Curve));
curve->add_point(Vector2(0, 1));
curve->add_point(Vector2(1, 1));
+ curve->set_min_value(p_min);
+ curve->set_max_value(p_max);
set_curve(curve);
- }
-
- if (get_min() == 0 && get_max() == 1) {
- set_max(32);
+ // Min and max is 0..1 by default
}
}
@@ -1457,11 +1438,9 @@ void CurveTexture::_update() {
if (_curve.is_valid()) {
Curve &curve = **_curve;
- float height = _max - _min;
for (int i = 0; i < _width; ++i) {
float t = i / static_cast<float>(_width);
- float v = curve.interpolate_baked(t);
- wd[i] = CLAMP(_min + v * height, _min, _max);
+ wd[i] = curve.interpolate_baked(t);
}
} else {
@@ -1490,9 +1469,6 @@ RID CurveTexture::get_rid() const {
}
CurveTexture::CurveTexture() {
-
- _max = 1;
- _min = 0;
_width = 2048;
_texture = VS::get_singleton()->texture_create();
}