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.cpp153
1 files changed, 0 insertions, 153 deletions
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index b212bba826..78b8e4d9ff 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -39,7 +39,6 @@
#include "servers/camera/camera_feed.h"
Size2 Texture2D::get_size() const {
-
return Size2(get_width(), get_height());
}
@@ -48,28 +47,24 @@ bool Texture2D::is_pixel_opaque(int p_x, int p_y) const {
}
void Texture2D::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, get_size()), get_rid(), false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
void Texture2D::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, get_rid(), p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
void Texture2D::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
-
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, get_rid(), p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat);
}
bool Texture2D::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {
-
r_rect = p_rect;
r_src_rect = p_src_rect;
@@ -77,7 +72,6 @@ bool Texture2D::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Re
}
void Texture2D::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_width"), &Texture2D::get_width);
ClassDB::bind_method(D_METHOD("get_height"), &Texture2D::get_height);
ClassDB::bind_method(D_METHOD("get_size"), &Texture2D::get_size);
@@ -96,7 +90,6 @@ Texture2D::Texture2D() {
/////////////////////
void ImageTexture::reload_from_file() {
-
String path = ResourceLoader::path_remap(get_path());
if (!path.is_resource_file())
return;
@@ -114,7 +107,6 @@ void ImageTexture::reload_from_file() {
}
bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) {
-
if (p_name == "image")
create_from_image(p_value);
else if (p_name == "size") {
@@ -129,7 +121,6 @@ bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) {
}
bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const {
-
if (p_name == "image")
r_ret = get_data();
else if (p_name == "size")
@@ -141,13 +132,11 @@ bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const {
}
void ImageTexture::_get_property_list(List<PropertyInfo> *p_list) const {
-
p_list->push_back(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Image", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "size", PROPERTY_HINT_NONE, ""));
}
void ImageTexture::_reload_hook(const RID &p_hook) {
-
String path = get_path();
if (!path.is_resource_file())
return;
@@ -166,7 +155,6 @@ void ImageTexture::_reload_hook(const RID &p_hook) {
}
void ImageTexture::create_from_image(const Ref<Image> &p_image) {
-
ERR_FAIL_COND(p_image.is_null());
w = p_image->get_width();
h = p_image->get_height();
@@ -186,12 +174,10 @@ void ImageTexture::create_from_image(const Ref<Image> &p_image) {
}
Image::Format ImageTexture::get_format() const {
-
return format;
}
void ImageTexture::update(const Ref<Image> &p_image, bool p_immediate) {
-
ERR_FAIL_COND(p_image.is_null());
ERR_FAIL_COND(texture.is_null());
ERR_FAIL_COND(p_image->get_width() != w || p_image->get_height() != h);
@@ -212,12 +198,10 @@ void ImageTexture::update(const Ref<Image> &p_image, bool p_immediate) {
}
void ImageTexture::_resource_path_changed() {
-
String path = get_path();
}
Ref<Image> ImageTexture::get_data() const {
-
if (image_stored) {
return RenderingServer::get_singleton()->texture_2d_get(texture);
} else {
@@ -226,17 +210,14 @@ Ref<Image> ImageTexture::get_data() const {
}
int ImageTexture::get_width() const {
-
return w;
}
int ImageTexture::get_height() const {
-
return h;
}
RID ImageTexture::get_rid() const {
-
if (texture.is_null()) {
//we are in trouble, create something temporary
texture = RenderingServer::get_singleton()->texture_2d_placeholder_create();
@@ -245,12 +226,10 @@ RID ImageTexture::get_rid() const {
}
bool ImageTexture::has_alpha() const {
-
return (format == Image::FORMAT_LA8 || format == Image::FORMAT_RGBA8);
}
void ImageTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
if ((w | h) == 0)
return;
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
@@ -258,7 +237,6 @@ void ImageTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
void ImageTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
if ((w | h) == 0)
return;
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
@@ -266,7 +244,6 @@ void ImageTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
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, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
-
if ((w | h) == 0)
return;
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
@@ -275,7 +252,6 @@ void ImageTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons
}
bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const {
-
if (!alpha_cache.is_valid()) {
Ref<Image> img = get_data();
if (img.is_valid()) {
@@ -290,7 +266,6 @@ bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const {
}
if (alpha_cache.is_valid()) {
-
int aw = int(alpha_cache->get_size().width);
int ah = int(alpha_cache->get_size().height);
if (aw == 0 || ah == 0) {
@@ -310,7 +285,6 @@ bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const {
}
void ImageTexture::set_size_override(const Size2 &p_size) {
-
Size2 s = p_size;
if (s.x != 0)
w = s.x;
@@ -320,7 +294,6 @@ void ImageTexture::set_size_override(const Size2 &p_size) {
}
void ImageTexture::set_path(const String &p_path, bool p_take_over) {
-
if (texture.is_valid()) {
RenderingServer::get_singleton()->texture_set_path(texture, p_path);
}
@@ -329,7 +302,6 @@ void ImageTexture::set_path(const String &p_path, bool p_take_over) {
}
void ImageTexture::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("create_from_image", "image"), &ImageTexture::create_from_image);
ClassDB::bind_method(D_METHOD("get_format"), &ImageTexture::get_format);
@@ -339,7 +311,6 @@ void ImageTexture::_bind_methods() {
}
ImageTexture::ImageTexture() {
-
w = h = 0;
image_stored = false;
mipmaps = false;
@@ -347,7 +318,6 @@ ImageTexture::ImageTexture() {
}
ImageTexture::~ImageTexture() {
-
if (texture.is_valid()) {
RenderingServer::get_singleton()->free(texture);
}
@@ -356,7 +326,6 @@ ImageTexture::~ImageTexture() {
//////////////////////////////////////////
Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit) {
-
uint32_t data_format = f->get_32();
uint32_t w = f->get_16();
uint32_t h = f->get_16();
@@ -376,7 +345,6 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit
bool first = true;
for (uint32_t i = 0; i < mipmaps + 1; i++) {
-
uint32_t size = f->get_32();
if (p_size_limit > 0 && i < (mipmaps - 1) && (sw > p_size_limit || sh > p_size_limit)) {
@@ -444,7 +412,6 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit
int ofs = 0;
for (int i = 0; i < mipmap_images.size(); i++) {
-
Vector<uint8_t> id = mipmap_images[i]->get_data();
int len = id.size();
const uint8_t *r = id.ptr();
@@ -458,7 +425,6 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit
}
} else if (data_format == DATA_FORMAT_IMAGE) {
-
int size = Image::get_image_data_size(w, h, format, mipmaps ? true : false);
for (uint32_t i = 0; i < mipmaps + 1; i++) {
@@ -493,7 +459,6 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit
}
void StreamTexture2D::set_path(const String &p_path, bool p_take_over) {
-
if (texture.is_valid()) {
RenderingServer::get_singleton()->texture_set_path(texture, p_path);
}
@@ -502,7 +467,6 @@ void StreamTexture2D::set_path(const String &p_path, bool p_take_over) {
}
void StreamTexture2D::_requested_3d(void *p_ud) {
-
StreamTexture2D *st = (StreamTexture2D *)p_ud;
Ref<StreamTexture2D> stex(st);
ERR_FAIL_COND(!request_3d_callback);
@@ -510,7 +474,6 @@ void StreamTexture2D::_requested_3d(void *p_ud) {
}
void StreamTexture2D::_requested_roughness(void *p_ud, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel) {
-
StreamTexture2D *st = (StreamTexture2D *)p_ud;
Ref<StreamTexture2D> stex(st);
ERR_FAIL_COND(!request_roughness_callback);
@@ -518,7 +481,6 @@ void StreamTexture2D::_requested_roughness(void *p_ud, const String &p_normal_pa
}
void StreamTexture2D::_requested_normal(void *p_ud) {
-
StreamTexture2D *st = (StreamTexture2D *)p_ud;
Ref<StreamTexture2D> stex(st);
ERR_FAIL_COND(!request_normal_callback);
@@ -530,12 +492,10 @@ StreamTexture2D::TextureFormatRoughnessRequestCallback StreamTexture2D::request_
StreamTexture2D::TextureFormatRequestCallback StreamTexture2D::request_normal_callback = nullptr;
Image::Format StreamTexture2D::get_format() const {
-
return format;
}
Error StreamTexture2D::_load_data(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit, int p_size_limit) {
-
alpha_cache.unref();
ERR_FAIL_COND_V(image.is_null(), ERR_INVALID_PARAMETER);
@@ -596,7 +556,6 @@ Error StreamTexture2D::_load_data(const String &p_path, int &tw, int &th, int &t
}
Error StreamTexture2D::load(const String &p_path) {
-
int lw, lh, lwc, lhc;
Ref<Image> image;
image.instance();
@@ -662,20 +621,16 @@ Error StreamTexture2D::load(const String &p_path) {
return OK;
}
String StreamTexture2D::get_load_path() const {
-
return path_to_file;
}
int StreamTexture2D::get_width() const {
-
return w;
}
int StreamTexture2D::get_height() const {
-
return h;
}
RID StreamTexture2D::get_rid() const {
-
if (!texture.is_valid()) {
texture = RS::get_singleton()->texture_2d_placeholder_create();
}
@@ -683,7 +638,6 @@ RID StreamTexture2D::get_rid() const {
}
void StreamTexture2D::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
if ((w | h) == 0)
return;
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
@@ -691,7 +645,6 @@ void StreamTexture2D::draw(RID p_canvas_item, const Point2 &p_pos, const Color &
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
void StreamTexture2D::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
if ((w | h) == 0)
return;
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
@@ -699,7 +652,6 @@ void StreamTexture2D::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_t
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
void StreamTexture2D::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
-
if ((w | h) == 0)
return;
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
@@ -708,12 +660,10 @@ void StreamTexture2D::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, c
}
bool StreamTexture2D::has_alpha() const {
-
return false;
}
Ref<Image> StreamTexture2D::get_data() const {
-
if (texture.is_valid()) {
return RS::get_singleton()->texture_2d_get(texture);
} else {
@@ -722,7 +672,6 @@ Ref<Image> StreamTexture2D::get_data() const {
}
bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const {
-
if (!alpha_cache.is_valid()) {
Ref<Image> img = get_data();
if (img.is_valid()) {
@@ -738,7 +687,6 @@ bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const {
}
if (alpha_cache.is_valid()) {
-
int aw = int(alpha_cache->get_size().width);
int ah = int(alpha_cache->get_size().height);
if (aw == 0 || ah == 0) {
@@ -758,7 +706,6 @@ bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const {
}
void StreamTexture2D::reload_from_file() {
-
String path = get_path();
if (!path.is_resource_file())
return;
@@ -775,7 +722,6 @@ void StreamTexture2D::_validate_property(PropertyInfo &property) const {
}
void StreamTexture2D::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("load", "path"), &StreamTexture2D::load);
ClassDB::bind_method(D_METHOD("get_load_path"), &StreamTexture2D::get_load_path);
@@ -783,21 +729,18 @@ void StreamTexture2D::_bind_methods() {
}
StreamTexture2D::StreamTexture2D() {
-
format = Image::FORMAT_MAX;
w = 0;
h = 0;
}
StreamTexture2D::~StreamTexture2D() {
-
if (texture.is_valid()) {
RS::get_singleton()->free(texture);
}
}
RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
-
Ref<StreamTexture2D> st;
st.instance();
Error err = st->load(p_path);
@@ -810,14 +753,12 @@ RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String
}
void ResourceFormatLoaderStreamTexture2D::get_recognized_extensions(List<String> *p_extensions) const {
-
p_extensions->push_back("stex");
}
bool ResourceFormatLoaderStreamTexture2D::handles_type(const String &p_type) const {
return p_type == "StreamTexture2D";
}
String ResourceFormatLoaderStreamTexture2D::get_resource_type(const String &p_path) const {
-
if (p_path.get_extension().to_lower() == "stex")
return "StreamTexture2D";
return "";
@@ -826,7 +767,6 @@ String ResourceFormatLoaderStreamTexture2D::get_resource_type(const String &p_pa
//////////////////////////////////////////
int AtlasTexture::get_width() const {
-
if (region.size.width == 0) {
if (atlas.is_valid())
return atlas->get_width();
@@ -836,7 +776,6 @@ int AtlasTexture::get_width() const {
}
}
int AtlasTexture::get_height() const {
-
if (region.size.height == 0) {
if (atlas.is_valid())
return atlas->get_height();
@@ -846,7 +785,6 @@ int AtlasTexture::get_height() const {
}
}
RID AtlasTexture::get_rid() const {
-
if (atlas.is_valid())
return atlas->get_rid();
@@ -854,7 +792,6 @@ RID AtlasTexture::get_rid() const {
}
bool AtlasTexture::has_alpha() const {
-
if (atlas.is_valid())
return atlas->has_alpha();
@@ -862,7 +799,6 @@ bool AtlasTexture::has_alpha() const {
}
void AtlasTexture::set_atlas(const Ref<Texture2D> &p_atlas) {
-
ERR_FAIL_COND(p_atlas == this);
if (atlas == p_atlas)
return;
@@ -871,12 +807,10 @@ void AtlasTexture::set_atlas(const Ref<Texture2D> &p_atlas) {
_change_notify("atlas");
}
Ref<Texture2D> AtlasTexture::get_atlas() const {
-
return atlas;
}
void AtlasTexture::set_region(const Rect2 &p_region) {
-
if (region == p_region)
return;
region = p_region;
@@ -885,12 +819,10 @@ void AtlasTexture::set_region(const Rect2 &p_region) {
}
Rect2 AtlasTexture::get_region() const {
-
return region;
}
void AtlasTexture::set_margin(const Rect2 &p_margin) {
-
if (margin == p_margin)
return;
margin = p_margin;
@@ -899,24 +831,20 @@ void AtlasTexture::set_margin(const Rect2 &p_margin) {
}
Rect2 AtlasTexture::get_margin() const {
-
return margin;
}
void AtlasTexture::set_filter_clip(const bool p_enable) {
-
filter_clip = p_enable;
emit_changed();
_change_notify("filter_clip");
}
bool AtlasTexture::has_filter_clip() const {
-
return filter_clip;
}
void AtlasTexture::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_atlas", "atlas"), &AtlasTexture::set_atlas);
ClassDB::bind_method(D_METHOD("get_atlas"), &AtlasTexture::get_atlas);
@@ -936,7 +864,6 @@ void AtlasTexture::_bind_methods() {
}
void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
if (!atlas.is_valid())
return;
@@ -956,7 +883,6 @@ void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m
}
void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
if (!atlas.is_valid())
return;
@@ -978,7 +904,6 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
RS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), rc, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, filter_clip, p_texture_filter, p_texture_repeat);
}
void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
-
//this might not necessarily work well if using a rect, needs to be fixed properly
if (!atlas.is_valid())
return;
@@ -993,7 +918,6 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons
}
bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {
-
if (!atlas.is_valid())
return false;
@@ -1029,7 +953,6 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect,
}
bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const {
-
if (!atlas.is_valid())
return true;
@@ -1077,7 +1000,6 @@ void MeshTexture::set_image_size(const Size2 &p_size) {
}
Size2 MeshTexture::get_image_size() const {
-
return size;
}
@@ -1090,7 +1012,6 @@ Ref<Texture2D> MeshTexture::get_base_texture() const {
}
void MeshTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
if (mesh.is_null() || base_texture.is_null()) {
return;
}
@@ -1128,7 +1049,6 @@ void MeshTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile,
RenderingServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
void MeshTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
-
if (mesh.is_null() || base_texture.is_null()) {
return;
}
@@ -1180,20 +1100,16 @@ MeshTexture::MeshTexture() {
//////////////////////////////////////////
int LargeTexture::get_width() const {
-
return size.width;
}
int LargeTexture::get_height() const {
-
return size.height;
}
RID LargeTexture::get_rid() const {
-
return RID();
}
bool LargeTexture::has_alpha() const {
-
for (int i = 0; i < pieces.size(); i++) {
if (pieces[i].texture->has_alpha())
return true;
@@ -1203,7 +1119,6 @@ bool LargeTexture::has_alpha() const {
}
int LargeTexture::add_piece(const Point2 &p_offset, const Ref<Texture2D> &p_texture) {
-
ERR_FAIL_COND_V(p_texture.is_null(), -1);
Piece p;
p.offset = p_offset;
@@ -1214,13 +1129,11 @@ int LargeTexture::add_piece(const Point2 &p_offset, const Ref<Texture2D> &p_text
}
void LargeTexture::set_piece_offset(int p_idx, const Point2 &p_offset) {
-
ERR_FAIL_INDEX(p_idx, pieces.size());
pieces.write[p_idx].offset = p_offset;
};
void LargeTexture::set_piece_texture(int p_idx, const Ref<Texture2D> &p_texture) {
-
ERR_FAIL_COND(p_texture == this);
ERR_FAIL_COND(p_texture.is_null());
ERR_FAIL_INDEX(p_idx, pieces.size());
@@ -1228,17 +1141,14 @@ void LargeTexture::set_piece_texture(int p_idx, const Ref<Texture2D> &p_texture)
};
void LargeTexture::set_size(const Size2 &p_size) {
-
size = p_size;
}
void LargeTexture::clear() {
-
pieces.clear();
size = Size2i();
}
Array LargeTexture::_get_data() const {
-
Array arr;
for (int i = 0; i < pieces.size(); i++) {
arr.push_back(pieces[i].offset);
@@ -1248,7 +1158,6 @@ Array LargeTexture::_get_data() const {
return arr;
}
void LargeTexture::_set_data(const Array &p_array) {
-
ERR_FAIL_COND(p_array.size() < 1);
ERR_FAIL_COND(!(p_array.size() & 1));
clear();
@@ -1259,24 +1168,19 @@ void LargeTexture::_set_data(const Array &p_array) {
}
int LargeTexture::get_piece_count() const {
-
return pieces.size();
}
Vector2 LargeTexture::get_piece_offset(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, pieces.size(), Vector2());
return pieces[p_idx].offset;
}
Ref<Texture2D> LargeTexture::get_piece_texture(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, pieces.size(), Ref<Texture2D>());
return pieces[p_idx].texture;
}
Ref<Image> LargeTexture::to_image() const {
-
Ref<Image> img = memnew(Image(this->get_width(), this->get_height(), false, Image::FORMAT_RGBA8));
for (int i = 0; i < pieces.size(); i++) {
-
Ref<Image> src_img = pieces[i].texture->get_data();
img->blit_rect(src_img, Rect2(0, 0, src_img->get_width(), src_img->get_height()), pieces[i].offset);
}
@@ -1285,7 +1189,6 @@ Ref<Image> LargeTexture::to_image() const {
}
void LargeTexture::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("add_piece", "ofs", "texture"), &LargeTexture::add_piece);
ClassDB::bind_method(D_METHOD("set_piece_offset", "idx", "ofs"), &LargeTexture::set_piece_offset);
ClassDB::bind_method(D_METHOD("set_piece_texture", "idx", "texture"), &LargeTexture::set_piece_texture);
@@ -1303,16 +1206,13 @@ void LargeTexture::_bind_methods() {
}
void LargeTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
for (int i = 0; i < pieces.size(); i++) {
-
// TODO
pieces[i].texture->draw(p_canvas_item, pieces[i].offset + p_pos, p_modulate, p_transpose, p_normal_map, p_specular_map, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
}
void LargeTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
-
//tiling not supported for this
if (size.x == 0 || size.y == 0)
return;
@@ -1320,13 +1220,11 @@ void LargeTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
Size2 scale = p_rect.size / size;
for (int i = 0; i < pieces.size(); i++) {
-
// TODO
pieces[i].texture->draw_rect(p_canvas_item, Rect2(pieces[i].offset * scale + p_rect.position, pieces[i].texture->get_size() * scale), false, p_modulate, p_transpose, p_normal_map, p_specular_map, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
}
void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
-
//tiling not supported for this
if (p_src_rect.size.x == 0 || p_src_rect.size.y == 0)
return;
@@ -1334,7 +1232,6 @@ void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons
Size2 scale = p_rect.size / p_src_rect.size;
for (int i = 0; i < pieces.size(); i++) {
-
// TODO
Rect2 rect(pieces[i].offset, pieces[i].texture->get_size());
if (!p_src_rect.intersects(rect))
@@ -1349,9 +1246,7 @@ void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons
}
bool LargeTexture::is_pixel_opaque(int p_x, int p_y) const {
-
for (int i = 0; i < pieces.size(); i++) {
-
// TODO
if (!pieces[i].texture.is_valid())
continue;
@@ -1371,7 +1266,6 @@ LargeTexture::LargeTexture() {
///////////////////
void CurveTexture::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_width", "width"), &CurveTexture::set_width);
ClassDB::bind_method(D_METHOD("set_curve", "curve"), &CurveTexture::set_curve);
@@ -1384,14 +1278,12 @@ void CurveTexture::_bind_methods() {
}
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;
}
@@ -1421,7 +1313,6 @@ void CurveTexture::set_curve(Ref<Curve> p_curve) {
}
void CurveTexture::_update() {
-
Vector<uint8_t> data;
data.resize(_width * sizeof(float));
@@ -1457,12 +1348,10 @@ void CurveTexture::_update() {
}
Ref<Curve> CurveTexture::get_curve() const {
-
return _curve;
}
RID CurveTexture::get_rid() const {
-
if (!_texture.is_valid()) {
_texture = RS::get_singleton()->texture_2d_placeholder_create();
}
@@ -1499,7 +1388,6 @@ GradientTexture::~GradientTexture() {
}
void GradientTexture::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_gradient", "gradient"), &GradientTexture::set_gradient);
ClassDB::bind_method(D_METHOD("get_gradient"), &GradientTexture::get_gradient);
@@ -1530,7 +1418,6 @@ Ref<Gradient> GradientTexture::get_gradient() const {
}
void GradientTexture::_queue_update() {
-
if (update_pending)
return;
@@ -1539,7 +1426,6 @@ void GradientTexture::_queue_update() {
}
void GradientTexture::_update() {
-
update_pending = false;
if (gradient.is_null())
@@ -1552,7 +1438,6 @@ void GradientTexture::_update() {
Gradient &g = **gradient;
for (int i = 0; i < width; i++) {
-
float ofs = float(i) / (width - 1);
Color color = g.get_color_at_offset(ofs);
@@ -1576,12 +1461,10 @@ void GradientTexture::_update() {
}
void GradientTexture::set_width(int p_width) {
-
width = p_width;
_queue_update();
}
int GradientTexture::get_width() const {
-
return width;
}
@@ -1595,7 +1478,6 @@ Ref<Image> GradientTexture::get_data() const {
//////////////////////////////////////
void ProxyTexture::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_base", "base"), &ProxyTexture::set_base);
ClassDB::bind_method(D_METHOD("get_base"), &ProxyTexture::get_base);
@@ -1603,7 +1485,6 @@ void ProxyTexture::_bind_methods() {
}
void ProxyTexture::set_base(const Ref<Texture2D> &p_texture) {
-
ERR_FAIL_COND(p_texture == this);
base = p_texture;
@@ -1621,24 +1502,20 @@ void ProxyTexture::set_base(const Ref<Texture2D> &p_texture) {
}
Ref<Texture2D> ProxyTexture::get_base() const {
-
return base;
}
int ProxyTexture::get_width() const {
-
if (base.is_valid())
return base->get_width();
return 1;
}
int ProxyTexture::get_height() const {
-
if (base.is_valid())
return base->get_height();
return 1;
}
RID ProxyTexture::get_rid() const {
-
if (proxy.is_null()) {
proxy_ph = RS::get_singleton()->texture_2d_placeholder_create();
proxy = RS::get_singleton()->texture_proxy_create(proxy_ph);
@@ -1647,19 +1524,16 @@ RID ProxyTexture::get_rid() const {
}
bool ProxyTexture::has_alpha() const {
-
if (base.is_valid())
return base->has_alpha();
return false;
}
ProxyTexture::ProxyTexture() {
-
//proxy = RS::get_singleton()->texture_create();
}
ProxyTexture::~ProxyTexture() {
-
if (proxy_ph.is_valid()) {
RS::get_singleton()->free(proxy_ph);
}
@@ -1670,7 +1544,6 @@ ProxyTexture::~ProxyTexture() {
//////////////////////////////////////////////
void AnimatedTexture::_update_proxy() {
-
RWLockRead r(rw_lock);
float delta;
@@ -1758,7 +1631,6 @@ bool AnimatedTexture::get_oneshot() const {
}
void AnimatedTexture::set_frame_texture(int p_frame, const Ref<Texture2D> &p_texture) {
-
ERR_FAIL_COND(p_texture == this);
ERR_FAIL_INDEX(p_frame, MAX_FRAMES);
@@ -1821,7 +1693,6 @@ RID AnimatedTexture::get_rid() const {
}
bool AnimatedTexture::has_alpha() const {
-
RWLockRead r(rw_lock);
if (!frames[current_frame].texture.is_valid()) {
@@ -1832,7 +1703,6 @@ bool AnimatedTexture::has_alpha() const {
}
Ref<Image> AnimatedTexture::get_data() const {
-
RWLockRead r(rw_lock);
if (!frames[current_frame].texture.is_valid()) {
@@ -1843,7 +1713,6 @@ Ref<Image> AnimatedTexture::get_data() const {
}
bool AnimatedTexture::is_pixel_opaque(int p_x, int p_y) const {
-
RWLockRead r(rw_lock);
if (frames[current_frame].texture.is_valid()) {
@@ -1853,7 +1722,6 @@ bool AnimatedTexture::is_pixel_opaque(int p_x, int p_y) const {
}
void AnimatedTexture::_validate_property(PropertyInfo &property) const {
-
String prop = property.name;
if (prop.begins_with("frame_")) {
int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int();
@@ -1931,7 +1799,6 @@ AnimatedTexture::~AnimatedTexture() {
///////////////////////////////
void TextureLayered::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_format"), &TextureLayered::get_format);
ClassDB::bind_method(D_METHOD("get_layered_type"), &TextureLayered::get_layered_type);
ClassDB::bind_method(D_METHOD("get_width"), &TextureLayered::get_width);
@@ -1990,7 +1857,6 @@ Array ImageTextureLayered::_get_images() const {
}
Error ImageTextureLayered::create_from_images(Vector<Ref<Image>> p_images) {
-
int new_layers = p_images.size();
ERR_FAIL_COND_V(new_layers == 0, ERR_INVALID_PARAMETER);
if (layered_type == LAYERED_TYPE_CUBEMAP) {
@@ -2065,7 +1931,6 @@ void ImageTextureLayered::set_path(const String &p_path, bool p_take_over) {
}
void ImageTextureLayered::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("create_from_images", "images"), &ImageTextureLayered::_create_from_images);
ClassDB::bind_method(D_METHOD("update_layer", "image", "layer"), &ImageTextureLayered::update_layer);
@@ -2092,7 +1957,6 @@ ImageTextureLayered::~ImageTextureLayered() {
///////////////////////////////////////////
void StreamTextureLayered::set_path(const String &p_path, bool p_take_over) {
-
if (texture.is_valid()) {
RenderingServer::get_singleton()->texture_set_path(texture, p_path);
}
@@ -2101,12 +1965,10 @@ void StreamTextureLayered::set_path(const String &p_path, bool p_take_over) {
}
Image::Format StreamTextureLayered::get_format() const {
-
return format;
}
Error StreamTextureLayered::_load_data(const String &p_path, Vector<Ref<Image>> &images, int &mipmap_limit, int p_size_limit) {
-
ERR_FAIL_COND_V(images.size() != 0, ERR_INVALID_PARAMETER);
FileAccessRef f = FileAccess::open(p_path, FileAccess::READ);
@@ -2151,7 +2013,6 @@ Error StreamTextureLayered::_load_data(const String &p_path, Vector<Ref<Image>>
}
Error StreamTextureLayered::load(const String &p_path) {
-
Vector<Ref<Image>> images;
int mipmap_limit;
@@ -2185,20 +2046,16 @@ Error StreamTextureLayered::load(const String &p_path) {
return OK;
}
String StreamTextureLayered::get_load_path() const {
-
return path_to_file;
}
int StreamTextureLayered::get_width() const {
-
return w;
}
int StreamTextureLayered::get_height() const {
-
return h;
}
int StreamTextureLayered::get_layers() const {
-
return layers;
}
bool StreamTextureLayered::has_mipmaps() const {
@@ -2206,12 +2063,10 @@ bool StreamTextureLayered::has_mipmaps() const {
}
TextureLayered::LayeredType StreamTextureLayered::get_layered_type() const {
-
return layered_type;
}
RID StreamTextureLayered::get_rid() const {
-
if (!texture.is_valid()) {
texture = RS::get_singleton()->texture_2d_layered_placeholder_create(RS::TextureLayeredType(layered_type));
}
@@ -2219,7 +2074,6 @@ RID StreamTextureLayered::get_rid() const {
}
Ref<Image> StreamTextureLayered::get_layer_data(int p_layer) const {
-
if (texture.is_valid()) {
return RS::get_singleton()->texture_2d_layer_get(texture, p_layer);
} else {
@@ -2228,7 +2082,6 @@ Ref<Image> StreamTextureLayered::get_layer_data(int p_layer) const {
}
void StreamTextureLayered::reload_from_file() {
-
String path = get_path();
if (!path.is_resource_file())
return;
@@ -2245,7 +2098,6 @@ void StreamTextureLayered::_validate_property(PropertyInfo &property) const {
}
void StreamTextureLayered::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("load", "path"), &StreamTextureLayered::load);
ClassDB::bind_method(D_METHOD("get_load_path"), &StreamTextureLayered::get_load_path);
@@ -2253,7 +2105,6 @@ void StreamTextureLayered::_bind_methods() {
}
StreamTextureLayered::StreamTextureLayered(LayeredType p_type) {
-
layered_type = p_type;
format = Image::FORMAT_MAX;
w = 0;
@@ -2263,7 +2114,6 @@ StreamTextureLayered::StreamTextureLayered(LayeredType p_type) {
}
StreamTextureLayered::~StreamTextureLayered() {
-
if (texture.is_valid()) {
RS::get_singleton()->free(texture);
}
@@ -2272,7 +2122,6 @@ StreamTextureLayered::~StreamTextureLayered() {
/////////////////////////////////////////////////
RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
-
Ref<StreamTextureLayered> st;
if (p_path.get_extension().to_lower() == "stexarray") {
Ref<StreamTexture2DArray> s;
@@ -2302,7 +2151,6 @@ RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const S
}
void ResourceFormatLoaderStreamTextureLayered::get_recognized_extensions(List<String> *p_extensions) const {
-
p_extensions->push_back("stexarray");
p_extensions->push_back("scube");
p_extensions->push_back("scubearray");
@@ -2311,7 +2159,6 @@ bool ResourceFormatLoaderStreamTextureLayered::handles_type(const String &p_type
return p_type == "StreamTexture2DArray" || p_type == "StreamCubemap" || p_type == "StreamCubemapArray";
}
String ResourceFormatLoaderStreamTextureLayered::get_resource_type(const String &p_path) const {
-
if (p_path.get_extension().to_lower() == "stexarray")
return "StreamTexture2DArray";
if (p_path.get_extension().to_lower() == "scube")