Merge pull request #47435 from madmiraal/rename-texture-get_data
Rename Texture.get_data() to get_image()
This commit is contained in:
commit
bc29f4bca1
31 changed files with 99 additions and 98 deletions
|
@ -18,11 +18,11 @@
|
||||||
var texture = load("res://icon.png")
|
var texture = load("res://icon.png")
|
||||||
$Sprite2D.texture = texture
|
$Sprite2D.texture = texture
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
This is because images have to be imported as [StreamTexture2D] first to be loaded with [method @GDScript.load]. If you'd still like to load an image file just like any other [Resource], import it as an [Image] resource instead, and then load it normally using the [method @GDScript.load] method.
|
This is because images have to be imported as a [StreamTexture2D] first to be loaded with [method @GDScript.load]. If you'd still like to load an image file just like any other [Resource], import it as an [Image] resource instead, and then load it normally using the [method @GDScript.load] method.
|
||||||
But do note that the image data can still be retrieved from an imported texture as well using the [method Texture2D.get_data] method, which returns a copy of the data:
|
[b]Note:[/b] The image can be retrieved from an imported texture using the [method Texture2D.get_image] method, which returns a copy of the image:
|
||||||
[codeblock]
|
[codeblock]
|
||||||
var texture = load("res://icon.png")
|
var texture = load("res://icon.png")
|
||||||
var image : Image = texture.get_data()
|
var image : Image = texture.get_image()
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
An [ImageTexture] is not meant to be operated from within the editor interface directly, and is mostly useful for rendering images on screen dynamically via code. If you need to generate images procedurally from within the editor, consider saving and importing images as custom texture resources implementing a new [EditorImportPlugin].
|
An [ImageTexture] is not meant to be operated from within the editor interface directly, and is mostly useful for rendering images on screen dynamically via code. If you need to generate images procedurally from within the editor, consider saving and importing images as custom texture resources implementing a new [EditorImportPlugin].
|
||||||
[b]Note:[/b] The maximum texture size is 16384×16384 pixels due to graphics hardware limitations.
|
[b]Note:[/b] The maximum texture size is 16384×16384 pixels due to graphics hardware limitations.
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
Draws a part of the texture using a [CanvasItem] with the [RenderingServer] API.
|
Draws a part of the texture using a [CanvasItem] with the [RenderingServer] API.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_data" qualifiers="const">
|
<method name="get_image" qualifiers="const">
|
||||||
<return type="Image">
|
<return type="Image">
|
||||||
</return>
|
</return>
|
||||||
<description>
|
<description>
|
||||||
|
|
|
@ -80,9 +80,9 @@
|
||||||
</return>
|
</return>
|
||||||
<description>
|
<description>
|
||||||
Returns the viewport's texture.
|
Returns the viewport's texture.
|
||||||
[b]Note:[/b] Due to the way OpenGL works, the resulting [ViewportTexture] is flipped vertically. You can use [method Image.flip_y] on the result of [method Texture2D.get_data] to flip it back, for example:
|
[b]Note:[/b] Due to the way OpenGL works, the resulting [ViewportTexture] is flipped vertically. You can use [method Image.flip_y] on the result of [method Texture2D.get_image] to flip it back, for example:
|
||||||
[codeblock]
|
[codeblock]
|
||||||
var img = get_viewport().get_texture().get_data()
|
var img = get_viewport().get_texture().get_image()
|
||||||
img.flip_y()
|
img.flip_y()
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
|
|
|
@ -41,7 +41,7 @@ Error ResourceSaverPNG::save(const String &p_path, const RES &p_resource, uint32
|
||||||
ERR_FAIL_COND_V_MSG(!texture.is_valid(), ERR_INVALID_PARAMETER, "Can't save invalid texture as PNG.");
|
ERR_FAIL_COND_V_MSG(!texture.is_valid(), ERR_INVALID_PARAMETER, "Can't save invalid texture as PNG.");
|
||||||
ERR_FAIL_COND_V_MSG(!texture->get_width(), ERR_INVALID_PARAMETER, "Can't save empty texture as PNG.");
|
ERR_FAIL_COND_V_MSG(!texture->get_width(), ERR_INVALID_PARAMETER, "Can't save empty texture as PNG.");
|
||||||
|
|
||||||
Ref<Image> img = texture->get_data();
|
Ref<Image> img = texture->get_image();
|
||||||
|
|
||||||
Error err = save_image(p_path, img);
|
Error err = save_image(p_path, img);
|
||||||
|
|
||||||
|
|
|
@ -1381,14 +1381,14 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
|
||||||
} else if (c3d < c2d) {
|
} else if (c3d < c2d) {
|
||||||
Ref<ViewportTexture> viewport_texture = scene_root->get_texture();
|
Ref<ViewportTexture> viewport_texture = scene_root->get_texture();
|
||||||
if (viewport_texture->get_width() > 0 && viewport_texture->get_height() > 0) {
|
if (viewport_texture->get_width() > 0 && viewport_texture->get_height() > 0) {
|
||||||
img = viewport_texture->get_data();
|
img = viewport_texture->get_image();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// The 3D editor may be disabled as a feature, but scenes can still be opened.
|
// The 3D editor may be disabled as a feature, but scenes can still be opened.
|
||||||
// This check prevents the preview from regenerating in case those scenes are then saved.
|
// This check prevents the preview from regenerating in case those scenes are then saved.
|
||||||
Ref<EditorFeatureProfile> profile = feature_profile_manager->get_current_profile();
|
Ref<EditorFeatureProfile> profile = feature_profile_manager->get_current_profile();
|
||||||
if (profile.is_valid() && !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D)) {
|
if (profile.is_valid() && !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D)) {
|
||||||
img = Node3DEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_texture()->get_data();
|
img = Node3DEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_texture()->get_image();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2835,7 +2835,7 @@ void EditorNode::_save_screenshot(NodePath p_path) {
|
||||||
ERR_FAIL_COND_MSG(!viewport, "Cannot get editor main control viewport.");
|
ERR_FAIL_COND_MSG(!viewport, "Cannot get editor main control viewport.");
|
||||||
Ref<ViewportTexture> texture = viewport->get_texture();
|
Ref<ViewportTexture> texture = viewport->get_texture();
|
||||||
ERR_FAIL_COND_MSG(texture.is_null(), "Cannot get editor main control viewport texture.");
|
ERR_FAIL_COND_MSG(texture.is_null(), "Cannot get editor main control viewport texture.");
|
||||||
Ref<Image> img = texture->get_data();
|
Ref<Image> img = texture->get_image();
|
||||||
ERR_FAIL_COND_MSG(img.is_null(), "Cannot get editor main control viewport texture image.");
|
ERR_FAIL_COND_MSG(img.is_null(), "Cannot get editor main control viewport texture image.");
|
||||||
Error error = img->save_png(p_path);
|
Error error = img->save_png(p_path);
|
||||||
ERR_FAIL_COND_MSG(error != OK, "Cannot save screenshot to file '" + p_path + "'.");
|
ERR_FAIL_COND_MSG(error != OK, "Cannot save screenshot to file '" + p_path + "'.");
|
||||||
|
@ -5108,8 +5108,8 @@ Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) {
|
||||||
|
|
||||||
{
|
{
|
||||||
//todo make proper previews
|
//todo make proper previews
|
||||||
Ref<ImageTexture> pic = gui_base->get_theme_icon("FileBigThumb", "EditorIcons");
|
Ref<ImageTexture> texture = gui_base->get_theme_icon("FileBigThumb", "EditorIcons");
|
||||||
Ref<Image> img = pic->get_data();
|
Ref<Image> img = texture->get_image();
|
||||||
img = img->duplicate();
|
img = img->duplicate();
|
||||||
img->resize(48, 48); //meh
|
img->resize(48, 48); //meh
|
||||||
Ref<ImageTexture> resized_pic = Ref<ImageTexture>(memnew(ImageTexture));
|
Ref<ImageTexture> resized_pic = Ref<ImageTexture>(memnew(ImageTexture));
|
||||||
|
|
|
@ -174,7 +174,7 @@ void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref<
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!r_small_texture.is_valid() && r_texture.is_valid() && preview_generators[i]->generate_small_preview_automatically()) {
|
if (!r_small_texture.is_valid() && r_texture.is_valid() && preview_generators[i]->generate_small_preview_automatically()) {
|
||||||
Ref<Image> small_image = r_texture->get_data();
|
Ref<Image> small_image = r_texture->get_image();
|
||||||
small_image = small_image->duplicate();
|
small_image = small_image->duplicate();
|
||||||
small_image->resize(small_thumbnail_size, small_thumbnail_size, Image::INTERPOLATE_CUBIC);
|
small_image->resize(small_thumbnail_size, small_thumbnail_size, Image::INTERPOLATE_CUBIC);
|
||||||
r_small_texture.instance();
|
r_small_texture.instance();
|
||||||
|
|
|
@ -43,7 +43,7 @@ void EditorRunNative::_notification(int p_what) {
|
||||||
}
|
}
|
||||||
Ref<ImageTexture> icon = eep->get_run_icon();
|
Ref<ImageTexture> icon = eep->get_run_icon();
|
||||||
if (!icon.is_null()) {
|
if (!icon.is_null()) {
|
||||||
Ref<Image> im = icon->get_data();
|
Ref<Image> im = icon->get_image();
|
||||||
im = im->duplicate();
|
im = im->duplicate();
|
||||||
im->clear_mipmaps();
|
im->clear_mipmaps();
|
||||||
if (!im->is_empty()) {
|
if (!im->is_empty()) {
|
||||||
|
|
|
@ -91,7 +91,7 @@ static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<ImageTexture> texture(memnew(ImageTexture));
|
Ref<ImageTexture> texture(memnew(ImageTexture));
|
||||||
Ref<Image> img = p_texture->get_data();
|
Ref<Image> img = p_texture->get_image();
|
||||||
img = img->duplicate();
|
img = img->duplicate();
|
||||||
|
|
||||||
if (p_flip_y) {
|
if (p_flip_y) {
|
||||||
|
|
|
@ -117,8 +117,8 @@ void AnimationPlayerEditor::_notification(int p_what) {
|
||||||
autoplay_icon = get_theme_icon("AutoPlay", "EditorIcons");
|
autoplay_icon = get_theme_icon("AutoPlay", "EditorIcons");
|
||||||
reset_icon = get_theme_icon("Reload", "EditorIcons");
|
reset_icon = get_theme_icon("Reload", "EditorIcons");
|
||||||
{
|
{
|
||||||
Ref<Image> autoplay_img = autoplay_icon->get_data();
|
Ref<Image> autoplay_img = autoplay_icon->get_image();
|
||||||
Ref<Image> reset_img = reset_icon->get_data();
|
Ref<Image> reset_img = reset_icon->get_image();
|
||||||
Ref<Image> autoplay_reset_img;
|
Ref<Image> autoplay_reset_img;
|
||||||
Size2 icon_size = Size2(autoplay_img->get_width(), autoplay_img->get_height());
|
Size2 icon_size = Size2(autoplay_img->get_width(), autoplay_img->get_height());
|
||||||
autoplay_reset_img.instance();
|
autoplay_reset_img.instance();
|
||||||
|
|
|
@ -144,8 +144,8 @@ void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const
|
||||||
for (int i = 0; i < preview_images.size(); i++) {
|
for (int i = 0; i < preview_images.size(); i++) {
|
||||||
if (preview_images[i].id == p_index) {
|
if (preview_images[i].id == p_index) {
|
||||||
if (preview_images[i].is_video) {
|
if (preview_images[i].is_video) {
|
||||||
Ref<Image> overlay = previews->get_theme_icon("PlayOverlay", "EditorIcons")->get_data();
|
Ref<Image> overlay = previews->get_theme_icon("PlayOverlay", "EditorIcons")->get_image();
|
||||||
Ref<Image> thumbnail = p_image->get_data();
|
Ref<Image> thumbnail = p_image->get_image();
|
||||||
thumbnail = thumbnail->duplicate();
|
thumbnail = thumbnail->duplicate();
|
||||||
Point2 overlay_pos = Point2((thumbnail->get_width() - overlay->get_width()) / 2, (thumbnail->get_height() - overlay->get_height()) / 2);
|
Point2 overlay_pos = Point2((thumbnail->get_width() - overlay->get_width()) / 2, (thumbnail->get_height() - overlay->get_height()) / 2);
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const RES &p_from, const Siz
|
||||||
return Ref<Texture2D>();
|
return Ref<Texture2D>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> atlas = tex->get_data();
|
Ref<Image> atlas = tex->get_image();
|
||||||
if (!atlas.is_valid()) {
|
if (!atlas.is_valid()) {
|
||||||
return Ref<Texture2D>();
|
return Ref<Texture2D>();
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const RES &p_from, const Siz
|
||||||
} else {
|
} else {
|
||||||
Ref<Texture2D> tex = p_from;
|
Ref<Texture2D> tex = p_from;
|
||||||
if (tex.is_valid()) {
|
if (tex.is_valid()) {
|
||||||
img = tex->get_data();
|
img = tex->get_image();
|
||||||
if (img.is_valid()) {
|
if (img.is_valid()) {
|
||||||
img = img->duplicate();
|
img = img->duplicate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ void Sprite2DEditor::_update_mesh_data() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> image = texture->get_data();
|
Ref<Image> image = texture->get_image();
|
||||||
ERR_FAIL_COND(image.is_null());
|
ERR_FAIL_COND(image.is_null());
|
||||||
|
|
||||||
if (image->is_compressed()) {
|
if (image->is_compressed()) {
|
||||||
|
|
|
@ -339,7 +339,7 @@ public:
|
||||||
// } else {
|
// } else {
|
||||||
// Ref<Texture> texture = ResourceLoader::load(p_path);
|
// Ref<Texture> texture = ResourceLoader::load(p_path);
|
||||||
// ERR_FAIL_COND_V(texture.is_null(), Ref<Image>());
|
// ERR_FAIL_COND_V(texture.is_null(), Ref<Image>());
|
||||||
// Ref<Image> image = texture->get_data();
|
// Ref<Image> image = texture->get_image();
|
||||||
// ERR_FAIL_COND_V(image.is_null(), Ref<Image>());
|
// ERR_FAIL_COND_V(image.is_null(), Ref<Image>());
|
||||||
// state.path_to_image_cache.insert(p_path, image);
|
// state.path_to_image_cache.insert(p_path, image);
|
||||||
// return image;
|
// return image;
|
||||||
|
|
|
@ -2821,7 +2821,7 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path
|
||||||
|
|
||||||
ERR_CONTINUE(state->images[i].is_null());
|
ERR_CONTINUE(state->images[i].is_null());
|
||||||
|
|
||||||
Ref<Image> image = state->images[i]->get_data();
|
Ref<Image> image = state->images[i]->get_image();
|
||||||
ERR_CONTINUE(image.is_null());
|
ERR_CONTINUE(image.is_null());
|
||||||
|
|
||||||
if (p_path.to_lower().ends_with("glb")) {
|
if (p_path.to_lower().ends_with("glb")) {
|
||||||
|
@ -2838,7 +2838,7 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path
|
||||||
Vector<uint8_t> buffer;
|
Vector<uint8_t> buffer;
|
||||||
Ref<ImageTexture> img_tex = image;
|
Ref<ImageTexture> img_tex = image;
|
||||||
if (img_tex.is_valid()) {
|
if (img_tex.is_valid()) {
|
||||||
image = img_tex->get_data();
|
image = img_tex->get_image();
|
||||||
}
|
}
|
||||||
Error err = PNGDriverCommon::image_to_png(image, buffer);
|
Error err = PNGDriverCommon::image_to_png(image, buffer);
|
||||||
ERR_FAIL_COND_V_MSG(err, err, "Can't convert image to PNG.");
|
ERR_FAIL_COND_V_MSG(err, err, "Can't convert image to PNG.");
|
||||||
|
@ -3068,7 +3068,7 @@ GLTFTextureIndex GLTFDocument::_set_texture(Ref<GLTFState> state, Ref<Texture2D>
|
||||||
ERR_FAIL_COND_V(p_texture.is_null(), -1);
|
ERR_FAIL_COND_V(p_texture.is_null(), -1);
|
||||||
Ref<GLTFTexture> gltf_texture;
|
Ref<GLTFTexture> gltf_texture;
|
||||||
gltf_texture.instance();
|
gltf_texture.instance();
|
||||||
ERR_FAIL_COND_V(p_texture->get_data().is_null(), -1);
|
ERR_FAIL_COND_V(p_texture->get_image().is_null(), -1);
|
||||||
GLTFImageIndex gltf_src_image_i = state->images.size();
|
GLTFImageIndex gltf_src_image_i = state->images.size();
|
||||||
state->images.push_back(p_texture);
|
state->images.push_back(p_texture);
|
||||||
gltf_texture->set_src_image(gltf_src_image_i);
|
gltf_texture->set_src_image(gltf_src_image_i);
|
||||||
|
@ -3115,7 +3115,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
|
||||||
Ref<Texture2D> albedo_texture = material->get_texture(BaseMaterial3D::TEXTURE_ALBEDO);
|
Ref<Texture2D> albedo_texture = material->get_texture(BaseMaterial3D::TEXTURE_ALBEDO);
|
||||||
GLTFTextureIndex gltf_texture_index = -1;
|
GLTFTextureIndex gltf_texture_index = -1;
|
||||||
|
|
||||||
if (albedo_texture.is_valid() && albedo_texture->get_data().is_valid()) {
|
if (albedo_texture.is_valid() && albedo_texture->get_image().is_valid()) {
|
||||||
albedo_texture->set_name(material->get_name() + "_albedo");
|
albedo_texture->set_name(material->get_name() + "_albedo");
|
||||||
gltf_texture_index = _set_texture(state, albedo_texture);
|
gltf_texture_index = _set_texture(state, albedo_texture);
|
||||||
}
|
}
|
||||||
|
@ -3128,9 +3128,9 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
|
||||||
|
|
||||||
mr["metallicFactor"] = material->get_metallic();
|
mr["metallicFactor"] = material->get_metallic();
|
||||||
mr["roughnessFactor"] = material->get_roughness();
|
mr["roughnessFactor"] = material->get_roughness();
|
||||||
bool has_roughness = material->get_texture(BaseMaterial3D::TEXTURE_ROUGHNESS).is_valid() && material->get_texture(BaseMaterial3D::TEXTURE_ROUGHNESS)->get_data().is_valid();
|
bool has_roughness = material->get_texture(BaseMaterial3D::TEXTURE_ROUGHNESS).is_valid() && material->get_texture(BaseMaterial3D::TEXTURE_ROUGHNESS)->get_image().is_valid();
|
||||||
bool has_ao = material->get_feature(BaseMaterial3D::FEATURE_AMBIENT_OCCLUSION) && material->get_texture(BaseMaterial3D::TEXTURE_AMBIENT_OCCLUSION).is_valid();
|
bool has_ao = material->get_feature(BaseMaterial3D::FEATURE_AMBIENT_OCCLUSION) && material->get_texture(BaseMaterial3D::TEXTURE_AMBIENT_OCCLUSION).is_valid();
|
||||||
bool has_metalness = material->get_texture(BaseMaterial3D::TEXTURE_METALLIC).is_valid() && material->get_texture(BaseMaterial3D::TEXTURE_METALLIC)->get_data().is_valid();
|
bool has_metalness = material->get_texture(BaseMaterial3D::TEXTURE_METALLIC).is_valid() && material->get_texture(BaseMaterial3D::TEXTURE_METALLIC)->get_image().is_valid();
|
||||||
if (has_ao || has_roughness || has_metalness) {
|
if (has_ao || has_roughness || has_metalness) {
|
||||||
Dictionary mrt;
|
Dictionary mrt;
|
||||||
Ref<Texture2D> roughness_texture = material->get_texture(BaseMaterial3D::TEXTURE_ROUGHNESS);
|
Ref<Texture2D> roughness_texture = material->get_texture(BaseMaterial3D::TEXTURE_ROUGHNESS);
|
||||||
|
@ -3149,10 +3149,10 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
|
||||||
if (has_ao) {
|
if (has_ao) {
|
||||||
height = ao_texture->get_height();
|
height = ao_texture->get_height();
|
||||||
width = ao_texture->get_width();
|
width = ao_texture->get_width();
|
||||||
ao_image = ao_texture->get_data();
|
ao_image = ao_texture->get_image();
|
||||||
Ref<ImageTexture> img_tex = ao_image;
|
Ref<ImageTexture> img_tex = ao_image;
|
||||||
if (img_tex.is_valid()) {
|
if (img_tex.is_valid()) {
|
||||||
ao_image = img_tex->get_data();
|
ao_image = img_tex->get_image();
|
||||||
}
|
}
|
||||||
if (ao_image->is_compressed()) {
|
if (ao_image->is_compressed()) {
|
||||||
ao_image->decompress();
|
ao_image->decompress();
|
||||||
|
@ -3162,10 +3162,10 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
|
||||||
if (has_roughness) {
|
if (has_roughness) {
|
||||||
height = roughness_texture->get_height();
|
height = roughness_texture->get_height();
|
||||||
width = roughness_texture->get_width();
|
width = roughness_texture->get_width();
|
||||||
roughness_image = roughness_texture->get_data();
|
roughness_image = roughness_texture->get_image();
|
||||||
Ref<ImageTexture> img_tex = roughness_image;
|
Ref<ImageTexture> img_tex = roughness_image;
|
||||||
if (img_tex.is_valid()) {
|
if (img_tex.is_valid()) {
|
||||||
roughness_image = img_tex->get_data();
|
roughness_image = img_tex->get_image();
|
||||||
}
|
}
|
||||||
if (roughness_image->is_compressed()) {
|
if (roughness_image->is_compressed()) {
|
||||||
roughness_image->decompress();
|
roughness_image->decompress();
|
||||||
|
@ -3175,17 +3175,17 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
|
||||||
if (has_metalness) {
|
if (has_metalness) {
|
||||||
height = metallic_texture->get_height();
|
height = metallic_texture->get_height();
|
||||||
width = metallic_texture->get_width();
|
width = metallic_texture->get_width();
|
||||||
metallness_image = metallic_texture->get_data();
|
metallness_image = metallic_texture->get_image();
|
||||||
Ref<ImageTexture> img_tex = metallness_image;
|
Ref<ImageTexture> img_tex = metallness_image;
|
||||||
if (img_tex.is_valid()) {
|
if (img_tex.is_valid()) {
|
||||||
metallness_image = img_tex->get_data();
|
metallness_image = img_tex->get_image();
|
||||||
}
|
}
|
||||||
if (metallness_image->is_compressed()) {
|
if (metallness_image->is_compressed()) {
|
||||||
metallness_image->decompress();
|
metallness_image->decompress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ref<Texture2D> albedo_texture = material->get_texture(BaseMaterial3D::TEXTURE_ALBEDO);
|
Ref<Texture2D> albedo_texture = material->get_texture(BaseMaterial3D::TEXTURE_ALBEDO);
|
||||||
if (albedo_texture.is_valid() && albedo_texture->get_data().is_valid()) {
|
if (albedo_texture.is_valid() && albedo_texture->get_image().is_valid()) {
|
||||||
height = albedo_texture->get_height();
|
height = albedo_texture->get_height();
|
||||||
width = albedo_texture->get_width();
|
width = albedo_texture->get_width();
|
||||||
}
|
}
|
||||||
|
@ -3266,10 +3266,10 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
|
||||||
{
|
{
|
||||||
Ref<Texture2D> normal_texture = material->get_texture(BaseMaterial3D::TEXTURE_NORMAL);
|
Ref<Texture2D> normal_texture = material->get_texture(BaseMaterial3D::TEXTURE_NORMAL);
|
||||||
// Code for uncompressing RG normal maps
|
// Code for uncompressing RG normal maps
|
||||||
Ref<Image> img = normal_texture->get_data();
|
Ref<Image> img = normal_texture->get_image();
|
||||||
Ref<ImageTexture> img_tex = img;
|
Ref<ImageTexture> img_tex = img;
|
||||||
if (img_tex.is_valid()) {
|
if (img_tex.is_valid()) {
|
||||||
img = img_tex->get_data();
|
img = img_tex->get_image();
|
||||||
}
|
}
|
||||||
img->decompress();
|
img->decompress();
|
||||||
img->convert(Image::FORMAT_RGBA8);
|
img->convert(Image::FORMAT_RGBA8);
|
||||||
|
@ -3288,7 +3288,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
|
||||||
}
|
}
|
||||||
Ref<Texture2D> normal_texture = material->get_texture(BaseMaterial3D::TEXTURE_NORMAL);
|
Ref<Texture2D> normal_texture = material->get_texture(BaseMaterial3D::TEXTURE_NORMAL);
|
||||||
GLTFTextureIndex gltf_texture_index = -1;
|
GLTFTextureIndex gltf_texture_index = -1;
|
||||||
if (tex.is_valid() && tex->get_data().is_valid()) {
|
if (tex.is_valid() && tex->get_image().is_valid()) {
|
||||||
tex->set_name(material->get_name() + "_normal");
|
tex->set_name(material->get_name() + "_normal");
|
||||||
gltf_texture_index = _set_texture(state, tex);
|
gltf_texture_index = _set_texture(state, tex);
|
||||||
}
|
}
|
||||||
|
@ -3311,7 +3311,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) {
|
||||||
Dictionary et;
|
Dictionary et;
|
||||||
Ref<Texture2D> emission_texture = material->get_texture(BaseMaterial3D::TEXTURE_EMISSION);
|
Ref<Texture2D> emission_texture = material->get_texture(BaseMaterial3D::TEXTURE_EMISSION);
|
||||||
GLTFTextureIndex gltf_texture_index = -1;
|
GLTFTextureIndex gltf_texture_index = -1;
|
||||||
if (emission_texture.is_valid() && emission_texture->get_data().is_valid()) {
|
if (emission_texture.is_valid() && emission_texture->get_image().is_valid()) {
|
||||||
emission_texture->set_name(material->get_name() + "_emission");
|
emission_texture->set_name(material->get_name() + "_emission");
|
||||||
gltf_texture_index = _set_texture(state, emission_texture);
|
gltf_texture_index = _set_texture(state, emission_texture);
|
||||||
}
|
}
|
||||||
|
@ -3370,7 +3370,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
|
||||||
if (diffuse_texture_dict.has("index")) {
|
if (diffuse_texture_dict.has("index")) {
|
||||||
Ref<Texture2D> diffuse_texture = _get_texture(state, diffuse_texture_dict["index"]);
|
Ref<Texture2D> diffuse_texture = _get_texture(state, diffuse_texture_dict["index"]);
|
||||||
if (diffuse_texture.is_valid()) {
|
if (diffuse_texture.is_valid()) {
|
||||||
spec_gloss->diffuse_img = diffuse_texture->get_data();
|
spec_gloss->diffuse_img = diffuse_texture->get_image();
|
||||||
material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, diffuse_texture);
|
material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, diffuse_texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3398,7 +3398,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) {
|
||||||
if (spec_gloss_texture.has("index")) {
|
if (spec_gloss_texture.has("index")) {
|
||||||
const Ref<Texture2D> orig_texture = _get_texture(state, spec_gloss_texture["index"]);
|
const Ref<Texture2D> orig_texture = _get_texture(state, spec_gloss_texture["index"]);
|
||||||
if (orig_texture.is_valid()) {
|
if (orig_texture.is_valid()) {
|
||||||
spec_gloss->spec_gloss_img = orig_texture->get_data();
|
spec_gloss->spec_gloss_img = orig_texture->get_image();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,12 @@
|
||||||
<description>
|
<description>
|
||||||
Uses an [OpenSimplexNoise] to fill the texture data. You can specify the texture size but keep in mind that larger textures will take longer to generate and seamless noise only works with square sized textures.
|
Uses an [OpenSimplexNoise] to fill the texture data. You can specify the texture size but keep in mind that larger textures will take longer to generate and seamless noise only works with square sized textures.
|
||||||
NoiseTexture can also generate normal map textures.
|
NoiseTexture can also generate normal map textures.
|
||||||
The class uses [Thread]s to generate the texture data internally, so [method Texture2D.get_data] may return [code]null[/code] if the generation process has not completed yet. In that case, you need to wait for the texture to be generated before accessing the data:
|
The class uses [Thread]s to generate the texture data internally, so [method Texture2D.get_image] may return [code]null[/code] if the generation process has not completed yet. In that case, you need to wait for the texture to be generated before accessing the image and the generated byte data:
|
||||||
[codeblock]
|
[codeblock]
|
||||||
var texture = preload("res://noise.tres")
|
var texture = preload("res://noise.tres")
|
||||||
yield(texture, "changed")
|
yield(texture, "changed")
|
||||||
var image = texture.get_data()
|
var image = texture.get_image()
|
||||||
|
var data = image.get_data()
|
||||||
[/codeblock]
|
[/codeblock]
|
||||||
</description>
|
</description>
|
||||||
<tutorials>
|
<tutorials>
|
||||||
|
|
|
@ -81,9 +81,9 @@ void NoiseTexture::_validate_property(PropertyInfo &property) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoiseTexture::_set_texture_data(const Ref<Image> &p_image) {
|
void NoiseTexture::_set_texture_image(const Ref<Image> &p_image) {
|
||||||
data = p_image;
|
image = p_image;
|
||||||
if (data.is_valid()) {
|
if (image.is_valid()) {
|
||||||
if (texture.is_valid()) {
|
if (texture.is_valid()) {
|
||||||
RID new_texture = RS::get_singleton()->texture_2d_create(p_image);
|
RID new_texture = RS::get_singleton()->texture_2d_create(p_image);
|
||||||
RS::get_singleton()->texture_replace(texture, new_texture);
|
RS::get_singleton()->texture_replace(texture, new_texture);
|
||||||
|
@ -95,7 +95,7 @@ void NoiseTexture::_set_texture_data(const Ref<Image> &p_image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoiseTexture::_thread_done(const Ref<Image> &p_image) {
|
void NoiseTexture::_thread_done(const Ref<Image> &p_image) {
|
||||||
_set_texture_data(p_image);
|
_set_texture_image(p_image);
|
||||||
noise_thread.wait_to_finish();
|
noise_thread.wait_to_finish();
|
||||||
if (regen_queued) {
|
if (regen_queued) {
|
||||||
noise_thread.start(_thread_function, this);
|
noise_thread.start(_thread_function, this);
|
||||||
|
@ -159,7 +159,7 @@ void NoiseTexture::_update_texture() {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Ref<Image> image = _generate_texture();
|
Ref<Image> image = _generate_texture();
|
||||||
_set_texture_data(image);
|
_set_texture_image(image);
|
||||||
}
|
}
|
||||||
update_queued = false;
|
update_queued = false;
|
||||||
}
|
}
|
||||||
|
@ -253,6 +253,6 @@ RID NoiseTexture::get_rid() const {
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> NoiseTexture::get_data() const {
|
Ref<Image> NoiseTexture::get_image() const {
|
||||||
return data;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ class NoiseTexture : public Texture2D {
|
||||||
GDCLASS(NoiseTexture, Texture2D);
|
GDCLASS(NoiseTexture, Texture2D);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ref<Image> data;
|
Ref<Image> image;
|
||||||
|
|
||||||
Thread noise_thread;
|
Thread noise_thread;
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ private:
|
||||||
void _queue_update();
|
void _queue_update();
|
||||||
Ref<Image> _generate_texture();
|
Ref<Image> _generate_texture();
|
||||||
void _update_texture();
|
void _update_texture();
|
||||||
void _set_texture_data(const Ref<Image> &p_image);
|
void _set_texture_image(const Ref<Image> &p_image);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
@ -94,7 +94,7 @@ public:
|
||||||
virtual RID get_rid() const override;
|
virtual RID get_rid() const override;
|
||||||
virtual bool has_alpha() const override { return false; }
|
virtual bool has_alpha() const override { return false; }
|
||||||
|
|
||||||
virtual Ref<Image> get_data() const override;
|
virtual Ref<Image> get_image() const override;
|
||||||
|
|
||||||
NoiseTexture();
|
NoiseTexture();
|
||||||
virtual ~NoiseTexture();
|
virtual ~NoiseTexture();
|
||||||
|
|
|
@ -341,7 +341,7 @@ void DisplayServerJavaScript::cursor_set_custom_image(const RES &p_cursor, Curso
|
||||||
Rect2 atlas_rect;
|
Rect2 atlas_rect;
|
||||||
|
|
||||||
if (texture.is_valid()) {
|
if (texture.is_valid()) {
|
||||||
image = texture->get_data();
|
image = texture->get_image();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!image.is_valid() && atlas_texture.is_valid()) {
|
if (!image.is_valid() && atlas_texture.is_valid()) {
|
||||||
|
@ -364,7 +364,7 @@ void DisplayServerJavaScript::cursor_set_custom_image(const RES &p_cursor, Curso
|
||||||
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
|
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
|
||||||
ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
|
ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
|
||||||
|
|
||||||
image = texture->get_data();
|
image = texture->get_image();
|
||||||
|
|
||||||
ERR_FAIL_COND(!image.is_valid());
|
ERR_FAIL_COND(!image.is_valid());
|
||||||
|
|
||||||
|
|
|
@ -1917,7 +1917,7 @@ void DisplayServerX11::cursor_set_custom_image(const RES &p_cursor, CursorShape
|
||||||
Rect2i atlas_rect;
|
Rect2i atlas_rect;
|
||||||
|
|
||||||
if (texture.is_valid()) {
|
if (texture.is_valid()) {
|
||||||
image = texture->get_data();
|
image = texture->get_image();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!image.is_valid() && atlas_texture.is_valid()) {
|
if (!image.is_valid() && atlas_texture.is_valid()) {
|
||||||
|
@ -1940,7 +1940,7 @@ void DisplayServerX11::cursor_set_custom_image(const RES &p_cursor, CursorShape
|
||||||
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
|
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
|
||||||
ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
|
ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
|
||||||
|
|
||||||
image = texture->get_data();
|
image = texture->get_image();
|
||||||
|
|
||||||
ERR_FAIL_COND(!image.is_valid());
|
ERR_FAIL_COND(!image.is_valid());
|
||||||
|
|
||||||
|
|
|
@ -3117,7 +3117,7 @@ void DisplayServerOSX::cursor_set_custom_image(const RES &p_cursor, CursorShape
|
||||||
Rect2 atlas_rect;
|
Rect2 atlas_rect;
|
||||||
|
|
||||||
if (texture.is_valid()) {
|
if (texture.is_valid()) {
|
||||||
image = texture->get_data();
|
image = texture->get_image();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!image.is_valid() && atlas_texture.is_valid()) {
|
if (!image.is_valid() && atlas_texture.is_valid()) {
|
||||||
|
@ -3140,7 +3140,7 @@ void DisplayServerOSX::cursor_set_custom_image(const RES &p_cursor, CursorShape
|
||||||
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
|
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
|
||||||
ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
|
ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
|
||||||
|
|
||||||
image = texture->get_data();
|
image = texture->get_image();
|
||||||
|
|
||||||
ERR_FAIL_COND(!image.is_valid());
|
ERR_FAIL_COND(!image.is_valid());
|
||||||
|
|
||||||
|
|
|
@ -855,33 +855,33 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
|
||||||
|
|
||||||
Vector<uint8_t> _get_image_data(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
|
Vector<uint8_t> _get_image_data(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
|
||||||
Vector<uint8_t> data;
|
Vector<uint8_t> data;
|
||||||
StreamTexture2D *image = nullptr;
|
StreamTexture2D *texture = nullptr;
|
||||||
|
|
||||||
if (p_path.find("StoreLogo") != -1) {
|
if (p_path.find("StoreLogo") != -1) {
|
||||||
image = p_preset->get("images/store_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/store_logo")));
|
texture = p_preset->get("images/store_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/store_logo")));
|
||||||
} else if (p_path.find("Square44x44Logo") != -1) {
|
} else if (p_path.find("Square44x44Logo") != -1) {
|
||||||
image = p_preset->get("images/square44x44_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square44x44_logo")));
|
texture = p_preset->get("images/square44x44_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square44x44_logo")));
|
||||||
} else if (p_path.find("Square71x71Logo") != -1) {
|
} else if (p_path.find("Square71x71Logo") != -1) {
|
||||||
image = p_preset->get("images/square71x71_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square71x71_logo")));
|
texture = p_preset->get("images/square71x71_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square71x71_logo")));
|
||||||
} else if (p_path.find("Square150x150Logo") != -1) {
|
} else if (p_path.find("Square150x150Logo") != -1) {
|
||||||
image = p_preset->get("images/square150x150_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square150x150_logo")));
|
texture = p_preset->get("images/square150x150_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square150x150_logo")));
|
||||||
} else if (p_path.find("Square310x310Logo") != -1) {
|
} else if (p_path.find("Square310x310Logo") != -1) {
|
||||||
image = p_preset->get("images/square310x310_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square310x310_logo")));
|
texture = p_preset->get("images/square310x310_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/square310x310_logo")));
|
||||||
} else if (p_path.find("Wide310x150Logo") != -1) {
|
} else if (p_path.find("Wide310x150Logo") != -1) {
|
||||||
image = p_preset->get("images/wide310x150_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/wide310x150_logo")));
|
texture = p_preset->get("images/wide310x150_logo").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/wide310x150_logo")));
|
||||||
} else if (p_path.find("SplashScreen") != -1) {
|
} else if (p_path.find("SplashScreen") != -1) {
|
||||||
image = p_preset->get("images/splash_screen").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/splash_screen")));
|
texture = p_preset->get("images/splash_screen").is_zero() ? nullptr : Object::cast_to<StreamTexture2D>(((Object *)p_preset->get("images/splash_screen")));
|
||||||
} else {
|
} else {
|
||||||
ERR_PRINT("Unable to load logo");
|
ERR_PRINT("Unable to load logo");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!image) {
|
if (!texture) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("uwp_tmp_logo.png");
|
String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("uwp_tmp_logo.png");
|
||||||
|
|
||||||
Error err = image->get_data()->save_png(tmp_path);
|
Error err = texture->get_image()->save_png(tmp_path);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
String err_string = "Couldn't save temp logo file.";
|
String err_string = "Couldn't save temp logo file.";
|
||||||
|
|
|
@ -1299,7 +1299,7 @@ void DisplayServerWindows::cursor_set_custom_image(const RES &p_cursor, CursorSh
|
||||||
Rect2 atlas_rect;
|
Rect2 atlas_rect;
|
||||||
|
|
||||||
if (texture.is_valid()) {
|
if (texture.is_valid()) {
|
||||||
image = texture->get_data();
|
image = texture->get_image();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!image.is_valid() && atlas_texture.is_valid()) {
|
if (!image.is_valid() && atlas_texture.is_valid()) {
|
||||||
|
@ -1322,7 +1322,7 @@ void DisplayServerWindows::cursor_set_custom_image(const RES &p_cursor, CursorSh
|
||||||
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
|
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
|
||||||
ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
|
ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
|
||||||
|
|
||||||
image = texture->get_data();
|
image = texture->get_image();
|
||||||
|
|
||||||
ERR_FAIL_COND(!image.is_valid());
|
ERR_FAIL_COND(!image.is_valid());
|
||||||
|
|
||||||
|
|
|
@ -344,7 +344,7 @@ Voxelizer::MaterialCache Voxelizer::_get_material_cache(Ref<Material> p_material
|
||||||
|
|
||||||
Ref<Image> img_albedo;
|
Ref<Image> img_albedo;
|
||||||
if (albedo_tex.is_valid()) {
|
if (albedo_tex.is_valid()) {
|
||||||
img_albedo = albedo_tex->get_data();
|
img_albedo = albedo_tex->get_image();
|
||||||
mc.albedo = _get_bake_texture(img_albedo, mat->get_albedo(), Color(0, 0, 0)); // albedo texture, color is multiplicative
|
mc.albedo = _get_bake_texture(img_albedo, mat->get_albedo(), Color(0, 0, 0)); // albedo texture, color is multiplicative
|
||||||
} else {
|
} else {
|
||||||
mc.albedo = _get_bake_texture(img_albedo, Color(1, 1, 1), mat->get_albedo()); // no albedo texture, color is additive
|
mc.albedo = _get_bake_texture(img_albedo, Color(1, 1, 1), mat->get_albedo()); // no albedo texture, color is additive
|
||||||
|
@ -358,7 +358,7 @@ Voxelizer::MaterialCache Voxelizer::_get_material_cache(Ref<Material> p_material
|
||||||
Ref<Image> img_emission;
|
Ref<Image> img_emission;
|
||||||
|
|
||||||
if (emission_tex.is_valid()) {
|
if (emission_tex.is_valid()) {
|
||||||
img_emission = emission_tex->get_data();
|
img_emission = emission_tex->get_image();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mat->get_emission_operator() == StandardMaterial3D::EMISSION_OP_ADD) {
|
if (mat->get_emission_operator() == StandardMaterial3D::EMISSION_OP_ADD) {
|
||||||
|
|
|
@ -682,7 +682,7 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> img = r->get_texture()->get_data();
|
Ref<Image> img = r->get_texture()->get_image();
|
||||||
if (img.is_valid() && !img->is_empty()) {
|
if (img.is_valid() && !img->is_empty()) {
|
||||||
Vector2 ofs = mev->get_global_position() - r->get_visible_rect().get_position();
|
Vector2 ofs = mev->get_global_position() - r->get_visible_rect().get_position();
|
||||||
Color c = img->get_pixel(ofs.x, r->get_visible_rect().size.height - ofs.y);
|
Color c = img->get_pixel(ofs.x, r->get_visible_rect().size.height - ofs.y);
|
||||||
|
|
|
@ -1511,9 +1511,9 @@ bool CanvasTexture::has_alpha() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> CanvasTexture::get_data() const {
|
Ref<Image> CanvasTexture::get_image() const {
|
||||||
if (diffuse_texture.is_valid()) {
|
if (diffuse_texture.is_valid()) {
|
||||||
return diffuse_texture->get_data();
|
return diffuse_texture->get_image();
|
||||||
} else {
|
} else {
|
||||||
return Ref<Image>();
|
return Ref<Image>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -475,7 +475,7 @@ public:
|
||||||
virtual bool is_pixel_opaque(int p_x, int p_y) const override;
|
virtual bool is_pixel_opaque(int p_x, int p_y) const override;
|
||||||
virtual bool has_alpha() const override;
|
virtual bool has_alpha() const override;
|
||||||
|
|
||||||
virtual Ref<Image> get_data() const override;
|
virtual Ref<Image> get_image() const override;
|
||||||
|
|
||||||
virtual RID get_rid() const override;
|
virtual RID get_rid() const override;
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ bool ViewportTexture::has_alpha() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> ViewportTexture::get_data() const {
|
Ref<Image> ViewportTexture::get_image() const {
|
||||||
ERR_FAIL_COND_V_MSG(!vp, Ref<Image>(), "Viewport Texture must be set to use it.");
|
ERR_FAIL_COND_V_MSG(!vp, Ref<Image>(), "Viewport Texture must be set to use it.");
|
||||||
return RS::get_singleton()->texture_2d_get(vp->texture_rid);
|
return RS::get_singleton()->texture_2d_get(vp->texture_rid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ public:
|
||||||
|
|
||||||
virtual bool has_alpha() const override;
|
virtual bool has_alpha() const override;
|
||||||
|
|
||||||
virtual Ref<Image> get_data() const override;
|
virtual Ref<Image> get_image() const override;
|
||||||
|
|
||||||
ViewportTexture();
|
ViewportTexture();
|
||||||
~ViewportTexture();
|
~ViewportTexture();
|
||||||
|
|
|
@ -114,7 +114,7 @@ static Ref<Texture2D> flip_icon(Ref<Texture2D> p_texture, bool p_flip_y = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<ImageTexture> texture(memnew(ImageTexture));
|
Ref<ImageTexture> texture(memnew(ImageTexture));
|
||||||
Ref<Image> img = p_texture->get_data();
|
Ref<Image> img = p_texture->get_image();
|
||||||
img = img->duplicate();
|
img = img->duplicate();
|
||||||
|
|
||||||
if (p_flip_y) {
|
if (p_flip_y) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ void Texture2D::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("draw", "canvas_item", "position", "modulate", "transpose"), &Texture2D::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw", "canvas_item", "position", "modulate", "transpose"), &Texture2D::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_rect", "canvas_item", "rect", "tile", "modulate", "transpose"), &Texture2D::draw_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("draw_rect", "canvas_item", "rect", "tile", "modulate", "transpose"), &Texture2D::draw_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "clip_uv"), &Texture2D::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(true));
|
ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "clip_uv"), &Texture2D::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(true));
|
||||||
ClassDB::bind_method(D_METHOD("get_data"), &Texture2D::get_data);
|
ClassDB::bind_method(D_METHOD("get_image"), &Texture2D::get_image);
|
||||||
|
|
||||||
ADD_GROUP("", "");
|
ADD_GROUP("", "");
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) {
|
||||||
|
|
||||||
bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const {
|
bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const {
|
||||||
if (p_name == "image") {
|
if (p_name == "image") {
|
||||||
r_ret = get_data();
|
r_ret = get_image();
|
||||||
} else if (p_name == "size") {
|
} else if (p_name == "size") {
|
||||||
r_ret = Size2(w, h);
|
r_ret = Size2(w, h);
|
||||||
} else {
|
} else {
|
||||||
|
@ -200,7 +200,7 @@ void ImageTexture::_resource_path_changed() {
|
||||||
String path = get_path();
|
String path = get_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> ImageTexture::get_data() const {
|
Ref<Image> ImageTexture::get_image() const {
|
||||||
if (image_stored) {
|
if (image_stored) {
|
||||||
return RenderingServer::get_singleton()->texture_2d_get(texture);
|
return RenderingServer::get_singleton()->texture_2d_get(texture);
|
||||||
} else {
|
} else {
|
||||||
|
@ -251,7 +251,7 @@ 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 {
|
bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const {
|
||||||
if (!alpha_cache.is_valid()) {
|
if (!alpha_cache.is_valid()) {
|
||||||
Ref<Image> img = get_data();
|
Ref<Image> img = get_image();
|
||||||
if (img.is_valid()) {
|
if (img.is_valid()) {
|
||||||
if (img->is_compressed()) { //must decompress, if compressed
|
if (img->is_compressed()) { //must decompress, if compressed
|
||||||
Ref<Image> decom = img->duplicate();
|
Ref<Image> decom = img->duplicate();
|
||||||
|
@ -661,7 +661,7 @@ bool StreamTexture2D::has_alpha() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> StreamTexture2D::get_data() const {
|
Ref<Image> StreamTexture2D::get_image() const {
|
||||||
if (texture.is_valid()) {
|
if (texture.is_valid()) {
|
||||||
return RS::get_singleton()->texture_2d_get(texture);
|
return RS::get_singleton()->texture_2d_get(texture);
|
||||||
} else {
|
} else {
|
||||||
|
@ -671,7 +671,7 @@ Ref<Image> StreamTexture2D::get_data() const {
|
||||||
|
|
||||||
bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const {
|
bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const {
|
||||||
if (!alpha_cache.is_valid()) {
|
if (!alpha_cache.is_valid()) {
|
||||||
Ref<Image> img = get_data();
|
Ref<Image> img = get_image();
|
||||||
if (img.is_valid()) {
|
if (img.is_valid()) {
|
||||||
if (img->is_compressed()) { //must decompress, if compressed
|
if (img->is_compressed()) { //must decompress, if compressed
|
||||||
Ref<Image> decom = img->duplicate();
|
Ref<Image> decom = img->duplicate();
|
||||||
|
@ -1495,7 +1495,7 @@ Ref<Texture2D> LargeTexture::get_piece_texture(int p_idx) const {
|
||||||
Ref<Image> LargeTexture::to_image() const {
|
Ref<Image> LargeTexture::to_image() const {
|
||||||
Ref<Image> img = memnew(Image(this->get_width(), this->get_height(), false, Image::FORMAT_RGBA8));
|
Ref<Image> img = memnew(Image(this->get_width(), this->get_height(), false, Image::FORMAT_RGBA8));
|
||||||
for (int i = 0; i < pieces.size(); i++) {
|
for (int i = 0; i < pieces.size(); i++) {
|
||||||
Ref<Image> src_img = pieces[i].texture->get_data();
|
Ref<Image> src_img = pieces[i].texture->get_image();
|
||||||
img->blit_rect(src_img, Rect2(0, 0, src_img->get_width(), src_img->get_height()), pieces[i].offset);
|
img->blit_rect(src_img, Rect2(0, 0, src_img->get_width(), src_img->get_height()), pieces[i].offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1782,7 +1782,7 @@ int GradientTexture::get_width() const {
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> GradientTexture::get_data() const {
|
Ref<Image> GradientTexture::get_image() const {
|
||||||
if (!texture.is_valid()) {
|
if (!texture.is_valid()) {
|
||||||
return Ref<Image>();
|
return Ref<Image>();
|
||||||
}
|
}
|
||||||
|
@ -2031,14 +2031,14 @@ bool AnimatedTexture::has_alpha() const {
|
||||||
return frames[current_frame].texture->has_alpha();
|
return frames[current_frame].texture->has_alpha();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> AnimatedTexture::get_data() const {
|
Ref<Image> AnimatedTexture::get_image() const {
|
||||||
RWLockRead r(rw_lock);
|
RWLockRead r(rw_lock);
|
||||||
|
|
||||||
if (!frames[current_frame].texture.is_valid()) {
|
if (!frames[current_frame].texture.is_valid()) {
|
||||||
return Ref<Image>();
|
return Ref<Image>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return frames[current_frame].texture->get_data();
|
return frames[current_frame].texture->get_image();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AnimatedTexture::is_pixel_opaque(int p_x, int p_y) const {
|
bool AnimatedTexture::is_pixel_opaque(int p_x, int p_y) const {
|
||||||
|
@ -2543,7 +2543,7 @@ uint32_t CameraTexture::get_flags() const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Image> CameraTexture::get_data() const {
|
Ref<Image> CameraTexture::get_image() const {
|
||||||
// not (yet) supported
|
// not (yet) supported
|
||||||
return Ref<Image>();
|
return Ref<Image>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public:
|
||||||
virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, bool p_clip_uv = true) const;
|
virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, bool p_clip_uv = true) const;
|
||||||
virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
|
virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
|
||||||
|
|
||||||
virtual Ref<Image> get_data() const { return Ref<Image>(); }
|
virtual Ref<Image> get_image() const { return Ref<Image>(); }
|
||||||
|
|
||||||
Texture2D();
|
Texture2D();
|
||||||
};
|
};
|
||||||
|
@ -108,7 +108,7 @@ public:
|
||||||
Image::Format get_format() const;
|
Image::Format get_format() const;
|
||||||
|
|
||||||
void update(const Ref<Image> &p_image, bool p_immediate = false);
|
void update(const Ref<Image> &p_image, bool p_immediate = false);
|
||||||
Ref<Image> get_data() const override;
|
Ref<Image> get_image() const override;
|
||||||
|
|
||||||
int get_width() const override;
|
int get_width() const override;
|
||||||
int get_height() const override;
|
int get_height() const override;
|
||||||
|
@ -203,7 +203,7 @@ public:
|
||||||
virtual bool has_alpha() const override;
|
virtual bool has_alpha() const override;
|
||||||
bool is_pixel_opaque(int p_x, int p_y) const override;
|
bool is_pixel_opaque(int p_x, int p_y) const override;
|
||||||
|
|
||||||
virtual Ref<Image> get_data() const override;
|
virtual Ref<Image> get_image() const override;
|
||||||
|
|
||||||
StreamTexture2D();
|
StreamTexture2D();
|
||||||
~StreamTexture2D();
|
~StreamTexture2D();
|
||||||
|
@ -716,7 +716,7 @@ public:
|
||||||
virtual int get_height() const override { return 1; }
|
virtual int get_height() const override { return 1; }
|
||||||
virtual bool has_alpha() const override { return true; }
|
virtual bool has_alpha() const override { return true; }
|
||||||
|
|
||||||
virtual Ref<Image> get_data() const override;
|
virtual Ref<Image> get_image() const override;
|
||||||
|
|
||||||
GradientTexture();
|
GradientTexture();
|
||||||
virtual ~GradientTexture();
|
virtual ~GradientTexture();
|
||||||
|
@ -812,7 +812,7 @@ public:
|
||||||
|
|
||||||
virtual bool has_alpha() const override;
|
virtual bool has_alpha() const override;
|
||||||
|
|
||||||
virtual Ref<Image> get_data() const override;
|
virtual Ref<Image> get_image() const override;
|
||||||
|
|
||||||
bool is_pixel_opaque(int p_x, int p_y) const override;
|
bool is_pixel_opaque(int p_x, int p_y) const override;
|
||||||
|
|
||||||
|
@ -839,7 +839,7 @@ public:
|
||||||
virtual void set_flags(uint32_t p_flags);
|
virtual void set_flags(uint32_t p_flags);
|
||||||
virtual uint32_t get_flags() const;
|
virtual uint32_t get_flags() const;
|
||||||
|
|
||||||
virtual Ref<Image> get_data() const override;
|
virtual Ref<Image> get_image() const override;
|
||||||
|
|
||||||
void set_camera_feed_id(int p_new_id);
|
void set_camera_feed_id(int p_new_id);
|
||||||
int get_camera_feed_id() const;
|
int get_camera_feed_id() const;
|
||||||
|
|
Loading…
Reference in a new issue