2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* texture.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2022-01-03 20:27:34 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef TEXTURE_H
|
|
|
|
#define TEXTURE_H
|
|
|
|
|
2021-06-11 12:51:48 +00:00
|
|
|
#include "core/io/file_access.h"
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/io/resource.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/io/resource_loader.h"
|
|
|
|
#include "core/math/rect2.h"
|
|
|
|
#include "core/os/mutex.h"
|
|
|
|
#include "core/os/rw_lock.h"
|
|
|
|
#include "core/os/thread_safe.h"
|
2018-09-13 20:54:35 +00:00
|
|
|
#include "scene/resources/curve.h"
|
2019-02-12 16:18:13 +00:00
|
|
|
#include "scene/resources/gradient.h"
|
2017-08-20 14:17:24 +00:00
|
|
|
#include "servers/camera_server.h"
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "servers/rendering_server.h"
|
2018-09-13 20:54:35 +00:00
|
|
|
|
2019-06-19 20:03:19 +00:00
|
|
|
class Texture : public Resource {
|
|
|
|
GDCLASS(Texture, Resource);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Texture() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Texture2D : public Texture {
|
2020-02-16 17:17:22 +00:00
|
|
|
GDCLASS(Texture2D, Texture);
|
2019-06-11 18:43:37 +00:00
|
|
|
OBJ_SAVE_TYPE(Texture2D); // Saves derived classes with common type so they can be interchanged.
|
2020-01-26 10:24:14 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2022-03-10 07:17:38 +00:00
|
|
|
GDVIRTUAL0RC(int, _get_width)
|
|
|
|
GDVIRTUAL0RC(int, _get_height)
|
|
|
|
GDVIRTUAL2RC(bool, _is_pixel_opaque, int, int)
|
|
|
|
GDVIRTUAL0RC(bool, _has_alpha)
|
|
|
|
|
|
|
|
GDVIRTUAL4C(_draw, RID, Point2, Color, bool)
|
|
|
|
GDVIRTUAL5C(_draw_rect, RID, Rect2, bool, Color, bool)
|
|
|
|
GDVIRTUAL6C(_draw_rect_region, RID, Rect2, Rect2, Color, bool, bool)
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2022-03-10 07:17:38 +00:00
|
|
|
virtual int get_width() const;
|
|
|
|
virtual int get_height() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
virtual Size2 get_size() const;
|
|
|
|
|
2018-08-24 01:10:15 +00:00
|
|
|
virtual bool is_pixel_opaque(int p_x, int p_y) const;
|
|
|
|
|
2022-03-10 07:17:38 +00:00
|
|
|
virtual bool has_alpha() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const;
|
|
|
|
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) 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;
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-03-28 11:32:17 +00:00
|
|
|
virtual Ref<Image> get_image() const { return Ref<Image>(); }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Texture2D();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2018-08-24 01:10:15 +00:00
|
|
|
class BitMap;
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
class ImageTexture : public Texture2D {
|
|
|
|
GDCLASS(ImageTexture, Texture2D);
|
2014-02-10 01:10:30 +00:00
|
|
|
RES_BASE_EXTENSION("tex");
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
mutable RID texture;
|
2021-02-09 17:24:36 +00:00
|
|
|
Image::Format format = Image::FORMAT_L8;
|
|
|
|
bool mipmaps = false;
|
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
Size2 size_override;
|
2018-08-24 01:10:15 +00:00
|
|
|
mutable Ref<BitMap> alpha_cache;
|
2021-02-09 17:24:36 +00:00
|
|
|
bool image_stored = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
protected:
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual void reload_from_file() override;
|
2022-06-07 22:50:25 +00:00
|
|
|
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2022-05-03 23:49:20 +00:00
|
|
|
void set_image(const Ref<Image> &p_image);
|
|
|
|
static Ref<ImageTexture> create_from_image(const Ref<Image> &p_image);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Image::Format get_format() const;
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2021-07-01 02:17:47 +00:00
|
|
|
void update(const Ref<Image> &p_image);
|
2021-03-28 11:32:17 +00:00
|
|
|
Ref<Image> get_image() const override;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
int get_width() const override;
|
|
|
|
int get_height() const override;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual RID get_rid() const override;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
bool has_alpha() const override;
|
2020-10-24 15:15:43 +00:00
|
|
|
virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;
|
|
|
|
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;
|
|
|
|
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 override;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const override;
|
2018-08-24 01:10:15 +00:00
|
|
|
|
2022-07-09 20:43:34 +00:00
|
|
|
void set_size_override(const Size2i &p_size);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual void set_path(const String &p_path, bool p_take_over = false) override;
|
2015-10-21 12:50:44 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
ImageTexture();
|
|
|
|
~ImageTexture();
|
|
|
|
};
|
|
|
|
|
2022-03-24 17:18:55 +00:00
|
|
|
class PortableCompressedTexture2D : public Texture2D {
|
|
|
|
GDCLASS(PortableCompressedTexture2D, Texture2D);
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum CompressionMode {
|
|
|
|
COMPRESSION_MODE_LOSSLESS,
|
|
|
|
COMPRESSION_MODE_LOSSY,
|
|
|
|
COMPRESSION_MODE_BASIS_UNIVERSAL,
|
|
|
|
COMPRESSION_MODE_S3TC,
|
|
|
|
COMPRESSION_MODE_ETC2,
|
|
|
|
COMPRESSION_MODE_BPTC,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
CompressionMode compression_mode = COMPRESSION_MODE_LOSSLESS;
|
|
|
|
static bool keep_all_compressed_buffers;
|
|
|
|
bool keep_compressed_buffer = false;
|
|
|
|
Vector<uint8_t> compressed_buffer;
|
|
|
|
Size2 size;
|
|
|
|
Size2 size_override;
|
|
|
|
bool mipmaps = false;
|
|
|
|
Image::Format format = Image::FORMAT_L8;
|
|
|
|
|
|
|
|
mutable RID texture;
|
|
|
|
mutable Ref<BitMap> alpha_cache;
|
|
|
|
|
|
|
|
bool image_stored = false;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Vector<uint8_t> _get_data() const;
|
|
|
|
void _set_data(const Vector<uint8_t> &p_data);
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
CompressionMode get_compression_mode() const;
|
|
|
|
void create_from_image(const Ref<Image> &p_image, CompressionMode p_compression_mode, bool p_normal_map = false, float p_lossy_quality = 0.8);
|
|
|
|
|
|
|
|
Image::Format get_format() const;
|
|
|
|
|
|
|
|
void update(const Ref<Image> &p_image);
|
|
|
|
Ref<Image> get_image() const override;
|
|
|
|
|
|
|
|
int get_width() const override;
|
|
|
|
int get_height() const override;
|
|
|
|
|
|
|
|
virtual RID get_rid() const override;
|
|
|
|
|
|
|
|
bool has_alpha() const override;
|
|
|
|
virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;
|
|
|
|
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;
|
|
|
|
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 override;
|
|
|
|
|
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const override;
|
|
|
|
|
|
|
|
virtual void set_path(const String &p_path, bool p_take_over = false) override;
|
|
|
|
|
|
|
|
void set_size_override(const Size2 &p_size);
|
|
|
|
Size2 get_size_override() const;
|
|
|
|
|
|
|
|
void set_keep_compressed_buffer(bool p_keep);
|
|
|
|
bool is_keeping_compressed_buffer() const;
|
|
|
|
|
|
|
|
static void set_keep_all_compressed_buffers(bool p_keep);
|
|
|
|
static bool is_keeping_all_compressed_buffers();
|
|
|
|
|
|
|
|
PortableCompressedTexture2D();
|
|
|
|
~PortableCompressedTexture2D();
|
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(PortableCompressedTexture2D::CompressionMode)
|
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
class CompressedTexture2D : public Texture2D {
|
|
|
|
GDCLASS(CompressedTexture2D, Texture2D);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-02-01 12:45:45 +00:00
|
|
|
public:
|
|
|
|
enum DataFormat {
|
|
|
|
DATA_FORMAT_IMAGE,
|
2021-04-12 16:56:50 +00:00
|
|
|
DATA_FORMAT_PNG,
|
|
|
|
DATA_FORMAT_WEBP,
|
2019-09-27 02:16:44 +00:00
|
|
|
DATA_FORMAT_BASIS_UNIVERSAL,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FORMAT_VERSION = 1
|
2017-02-01 12:45:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum FormatBits {
|
2017-03-05 15:44:50 +00:00
|
|
|
FORMAT_BIT_STREAM = 1 << 22,
|
|
|
|
FORMAT_BIT_HAS_MIPMAPS = 1 << 23,
|
|
|
|
FORMAT_BIT_DETECT_3D = 1 << 24,
|
2019-06-11 18:43:37 +00:00
|
|
|
//FORMAT_BIT_DETECT_SRGB = 1 << 25,
|
2017-06-17 00:47:28 +00:00
|
|
|
FORMAT_BIT_DETECT_NORMAL = 1 << 26,
|
2019-06-11 18:43:37 +00:00
|
|
|
FORMAT_BIT_DETECT_ROUGNESS = 1 << 27,
|
2017-02-01 12:45:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2021-05-25 15:03:12 +00:00
|
|
|
Error _load_data(const String &p_path, int &r_width, int &r_height, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit, int p_size_limit = 0);
|
2017-02-01 12:45:45 +00:00
|
|
|
String path_to_file;
|
2019-06-11 18:43:37 +00:00
|
|
|
mutable RID texture;
|
2021-02-09 17:24:36 +00:00
|
|
|
Image::Format format = Image::FORMAT_MAX;
|
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
2018-08-24 01:10:15 +00:00
|
|
|
mutable Ref<BitMap> alpha_cache;
|
2017-02-01 12:45:45 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual void reload_from_file() override;
|
2017-02-01 12:45:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static void _requested_3d(void *p_ud);
|
2020-03-27 18:21:27 +00:00
|
|
|
static void _requested_roughness(void *p_ud, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel);
|
2017-06-17 00:47:28 +00:00
|
|
|
static void _requested_normal(void *p_ud);
|
2017-02-06 03:38:39 +00:00
|
|
|
|
2017-02-01 12:45:45 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-08-12 20:57:11 +00:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2017-02-01 12:45:45 +00:00
|
|
|
|
|
|
|
public:
|
2022-03-23 09:08:58 +00:00
|
|
|
static Ref<Image> load_image_from_file(Ref<FileAccess> p_file, int p_size_limit);
|
2019-09-27 02:16:44 +00:00
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
typedef void (*TextureFormatRequestCallback)(const Ref<CompressedTexture2D> &);
|
|
|
|
typedef void (*TextureFormatRoughnessRequestCallback)(const Ref<CompressedTexture2D> &, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel);
|
2017-02-06 03:38:39 +00:00
|
|
|
|
|
|
|
static TextureFormatRequestCallback request_3d_callback;
|
2019-06-11 18:43:37 +00:00
|
|
|
static TextureFormatRoughnessRequestCallback request_roughness_callback;
|
2017-06-17 00:47:28 +00:00
|
|
|
static TextureFormatRequestCallback request_normal_callback;
|
2017-02-06 03:38:39 +00:00
|
|
|
|
2017-02-01 12:45:45 +00:00
|
|
|
Image::Format get_format() const;
|
2017-03-05 15:44:50 +00:00
|
|
|
Error load(const String &p_path);
|
2017-02-01 12:45:45 +00:00
|
|
|
String get_load_path() const;
|
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
int get_width() const override;
|
|
|
|
int get_height() const override;
|
|
|
|
virtual RID get_rid() const override;
|
2017-02-01 12:45:45 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual void set_path(const String &p_path, bool p_take_over) override;
|
2018-09-29 11:40:29 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;
|
|
|
|
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;
|
|
|
|
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 override;
|
2017-02-01 12:45:45 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual bool has_alpha() const override;
|
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const override;
|
2017-02-01 12:45:45 +00:00
|
|
|
|
2021-03-28 11:32:17 +00:00
|
|
|
virtual Ref<Image> get_image() const override;
|
2017-02-15 11:29:46 +00:00
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
CompressedTexture2D();
|
|
|
|
~CompressedTexture2D();
|
2017-02-01 12:45:45 +00:00
|
|
|
};
|
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
class ResourceFormatLoaderCompressedTexture2D : public ResourceFormatLoader {
|
2017-02-01 12:45:45 +00:00
|
|
|
public:
|
2022-05-02 23:43:50 +00:00
|
|
|
virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE);
|
2017-02-01 12:45:45 +00:00
|
|
|
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual bool handles_type(const String &p_type) const;
|
2017-02-01 12:45:45 +00:00
|
|
|
virtual String get_resource_type(const String &p_path) const;
|
|
|
|
};
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
class AtlasTexture : public Texture2D {
|
|
|
|
GDCLASS(AtlasTexture, Texture2D);
|
2017-06-15 22:44:11 +00:00
|
|
|
RES_BASE_EXTENSION("atlastex");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
protected:
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> atlas;
|
2014-02-10 01:10:30 +00:00
|
|
|
Rect2 region;
|
|
|
|
Rect2 margin;
|
2021-02-09 17:24:36 +00:00
|
|
|
bool filter_clip = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
virtual RID get_rid() const override;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual bool has_alpha() const override;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
void set_atlas(const Ref<Texture2D> &p_atlas);
|
|
|
|
Ref<Texture2D> get_atlas() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_region(const Rect2 &p_region);
|
|
|
|
Rect2 get_region() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_margin(const Rect2 &p_margin);
|
|
|
|
Rect2 get_margin() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-11-05 20:45:36 +00:00
|
|
|
void set_filter_clip(const bool p_enable);
|
|
|
|
bool has_filter_clip() const;
|
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;
|
|
|
|
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;
|
|
|
|
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 override;
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const override;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const override;
|
2018-08-24 01:10:15 +00:00
|
|
|
|
2021-09-28 14:54:47 +00:00
|
|
|
virtual Ref<Image> get_image() const override;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
AtlasTexture();
|
|
|
|
};
|
|
|
|
|
2019-04-19 18:54:33 +00:00
|
|
|
class Mesh;
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
class MeshTexture : public Texture2D {
|
|
|
|
GDCLASS(MeshTexture, Texture2D);
|
2019-04-19 18:54:33 +00:00
|
|
|
RES_BASE_EXTENSION("meshtex");
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> base_texture;
|
2019-04-19 18:54:33 +00:00
|
|
|
Ref<Mesh> mesh;
|
|
|
|
Size2i size;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
virtual RID get_rid() const override;
|
2019-04-19 18:54:33 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual bool has_alpha() const override;
|
2019-04-19 18:54:33 +00:00
|
|
|
|
|
|
|
void set_mesh(const Ref<Mesh> &p_mesh);
|
|
|
|
Ref<Mesh> get_mesh() const;
|
|
|
|
|
|
|
|
void set_image_size(const Size2 &p_size);
|
|
|
|
Size2 get_image_size() const;
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
void set_base_texture(const Ref<Texture2D> &p_texture);
|
|
|
|
Ref<Texture2D> get_base_texture() const;
|
2019-04-19 18:54:33 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;
|
|
|
|
virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const override;
|
|
|
|
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 override;
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const override;
|
2019-04-19 18:54:33 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const override;
|
2019-04-19 18:54:33 +00:00
|
|
|
|
|
|
|
MeshTexture();
|
|
|
|
};
|
|
|
|
|
2019-06-19 20:03:19 +00:00
|
|
|
class TextureLayered : public Texture {
|
2020-02-16 17:17:22 +00:00
|
|
|
GDCLASS(TextureLayered, Texture);
|
2018-06-26 11:59:26 +00:00
|
|
|
|
2020-05-01 12:34:23 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2022-03-10 07:17:38 +00:00
|
|
|
GDVIRTUAL0RC(Image::Format, _get_format)
|
|
|
|
GDVIRTUAL0RC(uint32_t, _get_layered_type)
|
|
|
|
GDVIRTUAL0RC(int, _get_width)
|
|
|
|
GDVIRTUAL0RC(int, _get_height)
|
|
|
|
GDVIRTUAL0RC(int, _get_layers)
|
|
|
|
GDVIRTUAL0RC(bool, _has_mipmaps)
|
|
|
|
GDVIRTUAL1RC(Ref<Image>, _get_layer_data, int)
|
2020-05-01 12:34:23 +00:00
|
|
|
public:
|
|
|
|
enum LayeredType {
|
|
|
|
LAYERED_TYPE_2D_ARRAY,
|
|
|
|
LAYERED_TYPE_CUBEMAP,
|
|
|
|
LAYERED_TYPE_CUBEMAP_ARRAY
|
|
|
|
};
|
|
|
|
|
2022-03-10 07:17:38 +00:00
|
|
|
virtual Image::Format get_format() const;
|
|
|
|
virtual LayeredType get_layered_type() const;
|
|
|
|
virtual int get_width() const;
|
|
|
|
virtual int get_height() const;
|
|
|
|
virtual int get_layers() const;
|
|
|
|
virtual bool has_mipmaps() const;
|
|
|
|
virtual Ref<Image> get_layer_data(int p_layer) const;
|
|
|
|
|
|
|
|
TextureLayered() {}
|
2020-05-01 12:34:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(TextureLayered::LayeredType)
|
|
|
|
|
|
|
|
class ImageTextureLayered : public TextureLayered {
|
|
|
|
GDCLASS(ImageTextureLayered, TextureLayered);
|
|
|
|
|
|
|
|
LayeredType layered_type;
|
2018-06-26 11:59:26 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
mutable RID texture;
|
2021-02-09 17:24:36 +00:00
|
|
|
Image::Format format = Image::FORMAT_MAX;
|
2018-06-26 11:59:26 +00:00
|
|
|
|
2021-02-09 17:24:36 +00:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
int layers = 0;
|
|
|
|
bool mipmaps = false;
|
2019-06-11 18:43:37 +00:00
|
|
|
|
2022-08-31 17:24:04 +00:00
|
|
|
Error _create_from_images(const TypedArray<Image> &p_images);
|
2018-06-26 11:59:26 +00:00
|
|
|
|
2022-08-31 17:24:04 +00:00
|
|
|
TypedArray<Image> _get_images() const;
|
2018-06-26 11:59:26 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual Image::Format get_format() const override;
|
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
virtual int get_layers() const override;
|
|
|
|
virtual bool has_mipmaps() const override;
|
|
|
|
virtual LayeredType get_layered_type() const override;
|
2018-06-26 11:59:26 +00:00
|
|
|
|
2020-03-17 06:33:00 +00:00
|
|
|
Error create_from_images(Vector<Ref<Image>> p_images);
|
2019-06-11 18:43:37 +00:00
|
|
|
void update_layer(const Ref<Image> &p_image, int p_layer);
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual Ref<Image> get_layer_data(int p_layer) const override;
|
2018-06-26 11:59:26 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual RID get_rid() const override;
|
|
|
|
virtual void set_path(const String &p_path, bool p_take_over = false) override;
|
2018-06-26 11:59:26 +00:00
|
|
|
|
2020-05-01 12:34:23 +00:00
|
|
|
ImageTextureLayered(LayeredType p_layered_type);
|
|
|
|
~ImageTextureLayered();
|
2018-08-06 17:56:06 +00:00
|
|
|
};
|
2018-06-26 11:59:26 +00:00
|
|
|
|
2020-05-01 12:34:23 +00:00
|
|
|
class Texture2DArray : public ImageTextureLayered {
|
|
|
|
GDCLASS(Texture2DArray, ImageTextureLayered)
|
2019-06-11 18:43:37 +00:00
|
|
|
public:
|
|
|
|
Texture2DArray() :
|
2020-05-01 12:34:23 +00:00
|
|
|
ImageTextureLayered(LAYERED_TYPE_2D_ARRAY) {}
|
2019-06-11 18:43:37 +00:00
|
|
|
};
|
2018-06-26 11:59:26 +00:00
|
|
|
|
2020-05-01 12:34:23 +00:00
|
|
|
class Cubemap : public ImageTextureLayered {
|
|
|
|
GDCLASS(Cubemap, ImageTextureLayered);
|
2019-09-14 03:37:42 +00:00
|
|
|
|
2018-08-06 17:56:06 +00:00
|
|
|
public:
|
2019-06-11 18:43:37 +00:00
|
|
|
Cubemap() :
|
2020-05-01 12:34:23 +00:00
|
|
|
ImageTextureLayered(LAYERED_TYPE_CUBEMAP) {}
|
2018-08-06 17:56:06 +00:00
|
|
|
};
|
2018-06-26 11:59:26 +00:00
|
|
|
|
2020-05-01 12:34:23 +00:00
|
|
|
class CubemapArray : public ImageTextureLayered {
|
|
|
|
GDCLASS(CubemapArray, ImageTextureLayered);
|
2019-09-14 03:37:42 +00:00
|
|
|
|
2018-08-06 17:56:06 +00:00
|
|
|
public:
|
2019-06-11 18:43:37 +00:00
|
|
|
CubemapArray() :
|
2020-05-01 12:34:23 +00:00
|
|
|
ImageTextureLayered(LAYERED_TYPE_CUBEMAP_ARRAY) {}
|
2018-08-06 17:56:06 +00:00
|
|
|
};
|
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
class CompressedTextureLayered : public TextureLayered {
|
|
|
|
GDCLASS(CompressedTextureLayered, TextureLayered);
|
2020-05-01 12:34:23 +00:00
|
|
|
|
2018-08-06 17:56:06 +00:00
|
|
|
public:
|
2020-05-01 12:34:23 +00:00
|
|
|
enum DataFormat {
|
|
|
|
DATA_FORMAT_IMAGE,
|
2021-04-12 16:56:50 +00:00
|
|
|
DATA_FORMAT_PNG,
|
|
|
|
DATA_FORMAT_WEBP,
|
2020-05-01 12:34:23 +00:00
|
|
|
DATA_FORMAT_BASIS_UNIVERSAL,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FORMAT_VERSION = 1
|
2018-08-06 17:56:06 +00:00
|
|
|
};
|
|
|
|
|
2020-05-01 12:34:23 +00:00
|
|
|
enum FormatBits {
|
|
|
|
FORMAT_BIT_STREAM = 1 << 22,
|
|
|
|
FORMAT_BIT_HAS_MIPMAPS = 1 << 23,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
Error _load_data(const String &p_path, Vector<Ref<Image>> &images, int &mipmap_limit, int p_size_limit = 0);
|
|
|
|
String path_to_file;
|
|
|
|
mutable RID texture;
|
2021-02-09 17:24:36 +00:00
|
|
|
Image::Format format = Image::FORMAT_MAX;
|
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
|
|
|
int layers = 0;
|
|
|
|
bool mipmaps = false;
|
|
|
|
LayeredType layered_type = LayeredType::LAYERED_TYPE_2D_ARRAY;
|
2020-05-01 12:34:23 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual void reload_from_file() override;
|
2020-05-01 12:34:23 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-08-12 20:57:11 +00:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2020-05-01 12:34:23 +00:00
|
|
|
|
|
|
|
public:
|
2020-07-10 10:34:39 +00:00
|
|
|
Image::Format get_format() const override;
|
2020-05-01 12:34:23 +00:00
|
|
|
Error load(const String &p_path);
|
|
|
|
String get_load_path() const;
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual LayeredType get_layered_type() const override;
|
2020-05-01 12:34:23 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
int get_width() const override;
|
|
|
|
int get_height() const override;
|
|
|
|
int get_layers() const override;
|
|
|
|
virtual bool has_mipmaps() const override;
|
|
|
|
virtual RID get_rid() const override;
|
2020-05-01 12:34:23 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual void set_path(const String &p_path, bool p_take_over) override;
|
2020-05-01 12:34:23 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual Ref<Image> get_layer_data(int p_layer) const override;
|
2020-05-01 12:34:23 +00:00
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
CompressedTextureLayered(LayeredType p_layered_type);
|
|
|
|
~CompressedTextureLayered();
|
2020-05-01 12:34:23 +00:00
|
|
|
};
|
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
class CompressedTexture2DArray : public CompressedTextureLayered {
|
|
|
|
GDCLASS(CompressedTexture2DArray, CompressedTextureLayered)
|
2020-05-01 12:34:23 +00:00
|
|
|
public:
|
2022-03-05 15:43:38 +00:00
|
|
|
CompressedTexture2DArray() :
|
|
|
|
CompressedTextureLayered(LAYERED_TYPE_2D_ARRAY) {}
|
2020-05-01 12:34:23 +00:00
|
|
|
};
|
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
class CompressedCubemap : public CompressedTextureLayered {
|
|
|
|
GDCLASS(CompressedCubemap, CompressedTextureLayered);
|
2020-05-01 12:34:23 +00:00
|
|
|
|
|
|
|
public:
|
2022-03-05 15:43:38 +00:00
|
|
|
CompressedCubemap() :
|
|
|
|
CompressedTextureLayered(LAYERED_TYPE_CUBEMAP) {}
|
2020-05-01 12:34:23 +00:00
|
|
|
};
|
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
class CompressedCubemapArray : public CompressedTextureLayered {
|
|
|
|
GDCLASS(CompressedCubemapArray, CompressedTextureLayered);
|
2020-05-01 12:34:23 +00:00
|
|
|
|
|
|
|
public:
|
2022-03-05 15:43:38 +00:00
|
|
|
CompressedCubemapArray() :
|
|
|
|
CompressedTextureLayered(LAYERED_TYPE_CUBEMAP_ARRAY) {}
|
2020-05-01 12:34:23 +00:00
|
|
|
};
|
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
class ResourceFormatLoaderCompressedTextureLayered : public ResourceFormatLoader {
|
2020-05-01 12:34:23 +00:00
|
|
|
public:
|
2022-05-02 23:43:50 +00:00
|
|
|
virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE);
|
2018-08-06 17:56:06 +00:00
|
|
|
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
|
|
|
virtual bool handles_type(const String &p_type) const;
|
|
|
|
virtual String get_resource_type(const String &p_path) const;
|
2018-06-26 11:59:26 +00:00
|
|
|
};
|
|
|
|
|
2020-09-09 15:40:51 +00:00
|
|
|
class Texture3D : public Texture {
|
|
|
|
GDCLASS(Texture3D, Texture);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2022-03-10 07:17:38 +00:00
|
|
|
TypedArray<Image> _get_datai() const;
|
2020-09-09 15:40:51 +00:00
|
|
|
|
2022-03-10 07:17:38 +00:00
|
|
|
GDVIRTUAL0RC(Image::Format, _get_format)
|
|
|
|
GDVIRTUAL0RC(int, _get_width)
|
|
|
|
GDVIRTUAL0RC(int, _get_height)
|
|
|
|
GDVIRTUAL0RC(int, _get_depth)
|
|
|
|
GDVIRTUAL0RC(bool, _has_mipmaps)
|
|
|
|
GDVIRTUAL0RC(TypedArray<Image>, _get_data)
|
2020-09-09 15:40:51 +00:00
|
|
|
public:
|
2022-03-10 07:17:38 +00:00
|
|
|
virtual Image::Format get_format() const;
|
|
|
|
virtual int get_width() const;
|
|
|
|
virtual int get_height() const;
|
|
|
|
virtual int get_depth() const;
|
|
|
|
virtual bool has_mipmaps() const;
|
|
|
|
virtual Vector<Ref<Image>> get_data() const;
|
2020-09-09 15:40:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ImageTexture3D : public Texture3D {
|
|
|
|
GDCLASS(ImageTexture3D, Texture3D);
|
|
|
|
|
|
|
|
mutable RID texture;
|
|
|
|
|
|
|
|
Image::Format format = Image::FORMAT_MAX;
|
|
|
|
int width = 1;
|
|
|
|
int height = 1;
|
|
|
|
int depth = 1;
|
|
|
|
bool mipmaps = false;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
Error _create(Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const TypedArray<Image> &p_data);
|
|
|
|
void _update(const TypedArray<Image> &p_data);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual Image::Format get_format() const override;
|
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
virtual int get_depth() const override;
|
|
|
|
virtual bool has_mipmaps() const override;
|
|
|
|
|
|
|
|
Error create(Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data);
|
|
|
|
void update(const Vector<Ref<Image>> &p_data);
|
|
|
|
virtual Vector<Ref<Image>> get_data() const override;
|
|
|
|
|
|
|
|
virtual RID get_rid() const override;
|
|
|
|
virtual void set_path(const String &p_path, bool p_take_over = false) override;
|
|
|
|
|
|
|
|
ImageTexture3D();
|
|
|
|
~ImageTexture3D();
|
|
|
|
};
|
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
class CompressedTexture3D : public Texture3D {
|
|
|
|
GDCLASS(CompressedTexture3D, Texture3D);
|
2020-09-09 15:40:51 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum DataFormat {
|
|
|
|
DATA_FORMAT_IMAGE,
|
2021-04-12 16:56:50 +00:00
|
|
|
DATA_FORMAT_PNG,
|
|
|
|
DATA_FORMAT_WEBP,
|
2020-09-09 15:40:51 +00:00
|
|
|
DATA_FORMAT_BASIS_UNIVERSAL,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FORMAT_VERSION = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FormatBits {
|
|
|
|
FORMAT_BIT_STREAM = 1 << 22,
|
|
|
|
FORMAT_BIT_HAS_MIPMAPS = 1 << 23,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
Error _load_data(const String &p_path, Vector<Ref<Image>> &r_data, Image::Format &r_format, int &r_width, int &r_height, int &r_depth, bool &r_mipmaps);
|
|
|
|
String path_to_file;
|
|
|
|
mutable RID texture;
|
2021-02-09 17:24:36 +00:00
|
|
|
Image::Format format = Image::FORMAT_MAX;
|
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
|
|
|
int d = 0;
|
|
|
|
bool mipmaps = false;
|
2020-09-09 15:40:51 +00:00
|
|
|
|
|
|
|
virtual void reload_from_file() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-08-12 20:57:11 +00:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2020-09-09 15:40:51 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Image::Format get_format() const override;
|
|
|
|
Error load(const String &p_path);
|
|
|
|
String get_load_path() const;
|
|
|
|
|
|
|
|
int get_width() const override;
|
|
|
|
int get_height() const override;
|
|
|
|
int get_depth() const override;
|
|
|
|
virtual bool has_mipmaps() const override;
|
|
|
|
virtual RID get_rid() const override;
|
|
|
|
|
|
|
|
virtual void set_path(const String &p_path, bool p_take_over) override;
|
|
|
|
|
|
|
|
virtual Vector<Ref<Image>> get_data() const override;
|
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
CompressedTexture3D();
|
|
|
|
~CompressedTexture3D();
|
2020-09-09 15:40:51 +00:00
|
|
|
};
|
|
|
|
|
2022-03-05 15:43:38 +00:00
|
|
|
class ResourceFormatLoaderCompressedTexture3D : public ResourceFormatLoader {
|
2020-09-09 15:40:51 +00:00
|
|
|
public:
|
2022-05-02 23:43:50 +00:00
|
|
|
virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE);
|
2020-09-09 15:40:51 +00:00
|
|
|
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
|
|
|
virtual bool handles_type(const String &p_type) const;
|
|
|
|
virtual String get_resource_type(const String &p_path) const;
|
|
|
|
};
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
class CurveTexture : public Texture2D {
|
|
|
|
GDCLASS(CurveTexture, Texture2D);
|
2017-04-30 14:27:10 +00:00
|
|
|
RES_BASE_EXTENSION("curvetex")
|
2021-07-01 18:25:35 +00:00
|
|
|
public:
|
|
|
|
enum TextureMode {
|
|
|
|
TEXTURE_MODE_RGB,
|
|
|
|
TEXTURE_MODE_RED,
|
|
|
|
};
|
2017-04-07 02:36:37 +00:00
|
|
|
|
|
|
|
private:
|
2019-06-11 18:43:37 +00:00
|
|
|
mutable RID _texture;
|
2017-04-30 14:27:10 +00:00
|
|
|
Ref<Curve> _curve;
|
2022-01-28 23:28:10 +00:00
|
|
|
int _width = 256;
|
2021-07-01 18:25:35 +00:00
|
|
|
int _current_width = 0;
|
|
|
|
TextureMode texture_mode = TEXTURE_MODE_RGB;
|
|
|
|
TextureMode _current_texture_mode = TEXTURE_MODE_RGB;
|
2017-04-30 14:27:10 +00:00
|
|
|
|
|
|
|
void _update();
|
2017-04-07 02:36:37 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_width(int p_width);
|
2020-07-10 10:34:39 +00:00
|
|
|
int get_width() const override;
|
2017-04-07 02:36:37 +00:00
|
|
|
|
2021-07-01 18:25:35 +00:00
|
|
|
void set_texture_mode(TextureMode p_mode);
|
|
|
|
TextureMode get_texture_mode() const;
|
|
|
|
|
2017-07-30 20:53:40 +00:00
|
|
|
void ensure_default_setup(float p_min = 0, float p_max = 1);
|
2017-04-30 14:27:10 +00:00
|
|
|
|
|
|
|
void set_curve(Ref<Curve> p_curve);
|
|
|
|
Ref<Curve> get_curve() const;
|
2017-04-07 02:36:37 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual RID get_rid() const override;
|
2017-04-07 02:36:37 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual int get_height() const override { return 1; }
|
|
|
|
virtual bool has_alpha() const override { return false; }
|
2017-04-07 02:36:37 +00:00
|
|
|
|
|
|
|
CurveTexture();
|
|
|
|
~CurveTexture();
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-07-01 18:25:35 +00:00
|
|
|
VARIANT_ENUM_CAST(CurveTexture::TextureMode)
|
|
|
|
|
2021-07-13 22:06:44 +00:00
|
|
|
class CurveXYZTexture : public Texture2D {
|
|
|
|
GDCLASS(CurveXYZTexture, Texture2D);
|
2021-07-01 18:25:35 +00:00
|
|
|
RES_BASE_EXTENSION("curvetex")
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable RID _texture;
|
|
|
|
Ref<Curve> _curve_x;
|
|
|
|
Ref<Curve> _curve_y;
|
|
|
|
Ref<Curve> _curve_z;
|
2022-01-28 23:28:10 +00:00
|
|
|
int _width = 256;
|
2021-07-01 18:25:35 +00:00
|
|
|
int _current_width = 0;
|
|
|
|
|
|
|
|
void _update();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_width(int p_width);
|
|
|
|
int get_width() const override;
|
|
|
|
|
|
|
|
void ensure_default_setup(float p_min = 0, float p_max = 1);
|
|
|
|
|
|
|
|
void set_curve_x(Ref<Curve> p_curve);
|
|
|
|
Ref<Curve> get_curve_x() const;
|
|
|
|
|
|
|
|
void set_curve_y(Ref<Curve> p_curve);
|
|
|
|
Ref<Curve> get_curve_y() const;
|
|
|
|
|
|
|
|
void set_curve_z(Ref<Curve> p_curve);
|
|
|
|
Ref<Curve> get_curve_z() const;
|
|
|
|
|
|
|
|
virtual RID get_rid() const override;
|
|
|
|
|
|
|
|
virtual int get_height() const override { return 1; }
|
|
|
|
virtual bool has_alpha() const override { return false; }
|
|
|
|
|
2021-07-13 22:06:44 +00:00
|
|
|
CurveXYZTexture();
|
|
|
|
~CurveXYZTexture();
|
2021-07-01 18:25:35 +00:00
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-11-07 12:35:45 +00:00
|
|
|
class GradientTexture1D : public Texture2D {
|
|
|
|
GDCLASS(GradientTexture1D, Texture2D);
|
2017-04-07 02:36:37 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
struct Point {
|
2021-02-09 17:24:36 +00:00
|
|
|
float offset = 0.0;
|
2017-04-07 02:36:37 +00:00
|
|
|
Color color;
|
|
|
|
bool operator<(const Point &p_ponit) const {
|
|
|
|
return offset < p_ponit.offset;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2017-06-24 19:28:22 +00:00
|
|
|
Ref<Gradient> gradient;
|
2021-02-09 17:24:36 +00:00
|
|
|
bool update_pending = false;
|
2017-04-07 02:36:37 +00:00
|
|
|
RID texture;
|
2022-01-28 23:28:10 +00:00
|
|
|
int width = 256;
|
2021-05-02 01:53:10 +00:00
|
|
|
bool use_hdr = false;
|
2017-04-07 02:36:37 +00:00
|
|
|
|
|
|
|
void _queue_update();
|
|
|
|
void _update();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2017-06-24 19:28:22 +00:00
|
|
|
void set_gradient(Ref<Gradient> p_gradient);
|
|
|
|
Ref<Gradient> get_gradient() const;
|
2017-04-07 02:36:37 +00:00
|
|
|
|
|
|
|
void set_width(int p_width);
|
2020-07-10 10:34:39 +00:00
|
|
|
int get_width() const override;
|
2017-04-07 02:36:37 +00:00
|
|
|
|
2021-05-02 01:53:10 +00:00
|
|
|
void set_use_hdr(bool p_enabled);
|
|
|
|
bool is_using_hdr() const;
|
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual RID get_rid() const override { return texture; }
|
|
|
|
virtual int get_height() const override { return 1; }
|
|
|
|
virtual bool has_alpha() const override { return true; }
|
2017-04-07 02:36:37 +00:00
|
|
|
|
2021-03-28 11:32:17 +00:00
|
|
|
virtual Ref<Image> get_image() const override;
|
2017-06-09 03:23:50 +00:00
|
|
|
|
2021-11-07 12:35:45 +00:00
|
|
|
GradientTexture1D();
|
|
|
|
virtual ~GradientTexture1D();
|
2017-04-07 02:36:37 +00:00
|
|
|
};
|
|
|
|
|
2021-10-12 14:22:30 +00:00
|
|
|
class GradientTexture2D : public Texture2D {
|
|
|
|
GDCLASS(GradientTexture2D, Texture2D);
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum Fill {
|
|
|
|
FILL_LINEAR,
|
|
|
|
FILL_RADIAL,
|
|
|
|
};
|
|
|
|
enum Repeat {
|
|
|
|
REPEAT_NONE,
|
|
|
|
REPEAT,
|
|
|
|
REPEAT_MIRROR,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
Ref<Gradient> gradient;
|
|
|
|
mutable RID texture;
|
|
|
|
|
|
|
|
int width = 64;
|
|
|
|
int height = 64;
|
|
|
|
|
|
|
|
bool use_hdr = false;
|
|
|
|
|
|
|
|
Vector2 fill_from;
|
|
|
|
Vector2 fill_to = Vector2(1, 0);
|
|
|
|
|
|
|
|
Fill fill = FILL_LINEAR;
|
|
|
|
Repeat repeat = REPEAT_NONE;
|
|
|
|
|
|
|
|
float _get_gradient_offset_at(int x, int y) const;
|
|
|
|
|
|
|
|
bool update_pending = false;
|
|
|
|
void _queue_update();
|
|
|
|
void _update();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_gradient(Ref<Gradient> p_gradient);
|
|
|
|
Ref<Gradient> get_gradient() const;
|
|
|
|
|
|
|
|
void set_width(int p_width);
|
|
|
|
virtual int get_width() const override;
|
|
|
|
void set_height(int p_height);
|
|
|
|
virtual int get_height() const override;
|
|
|
|
|
|
|
|
void set_use_hdr(bool p_enabled);
|
|
|
|
bool is_using_hdr() const;
|
|
|
|
|
|
|
|
void set_fill(Fill p_fill);
|
|
|
|
Fill get_fill() const;
|
|
|
|
void set_fill_from(Vector2 p_fill_from);
|
|
|
|
Vector2 get_fill_from() const;
|
|
|
|
void set_fill_to(Vector2 p_fill_to);
|
|
|
|
Vector2 get_fill_to() const;
|
|
|
|
|
|
|
|
void set_repeat(Repeat p_repeat);
|
|
|
|
Repeat get_repeat() const;
|
|
|
|
|
|
|
|
virtual RID get_rid() const override;
|
|
|
|
virtual bool has_alpha() const override { return true; }
|
|
|
|
virtual Ref<Image> get_image() const override;
|
|
|
|
|
|
|
|
GradientTexture2D();
|
|
|
|
virtual ~GradientTexture2D();
|
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(GradientTexture2D::Fill);
|
|
|
|
VARIANT_ENUM_CAST(GradientTexture2D::Repeat);
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
class ProxyTexture : public Texture2D {
|
2017-12-04 19:54:17 +00:00
|
|
|
private:
|
2019-06-24 19:13:06 +00:00
|
|
|
mutable RID proxy_ph;
|
|
|
|
mutable RID proxy;
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> base;
|
2017-12-04 19:54:17 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2019-06-11 18:43:37 +00:00
|
|
|
void set_base(const Ref<Texture2D> &p_texture);
|
|
|
|
Ref<Texture2D> get_base() const;
|
2017-12-04 19:54:17 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
virtual RID get_rid() const override;
|
2017-12-04 19:54:17 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual bool has_alpha() const override;
|
2017-12-04 19:54:17 +00:00
|
|
|
|
|
|
|
ProxyTexture();
|
|
|
|
~ProxyTexture();
|
|
|
|
};
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
class AnimatedTexture : public Texture2D {
|
|
|
|
GDCLASS(AnimatedTexture, Texture2D);
|
2018-07-16 14:43:26 +00:00
|
|
|
|
2018-08-23 16:27:17 +00:00
|
|
|
//use readers writers lock for this, since its far more times read than written to
|
2021-01-18 13:01:38 +00:00
|
|
|
RWLock rw_lock;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
2020-08-30 20:44:41 +00:00
|
|
|
public:
|
2018-07-16 14:43:26 +00:00
|
|
|
enum {
|
|
|
|
MAX_FRAMES = 256
|
|
|
|
};
|
|
|
|
|
2020-08-30 20:44:41 +00:00
|
|
|
private:
|
2019-06-24 19:13:06 +00:00
|
|
|
RID proxy_ph;
|
2018-07-16 14:43:26 +00:00
|
|
|
RID proxy;
|
|
|
|
|
|
|
|
struct Frame {
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> texture;
|
2022-09-01 10:09:06 +00:00
|
|
|
float duration = 1.0;
|
2018-07-16 14:43:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Frame frames[MAX_FRAMES];
|
2021-02-09 17:24:36 +00:00
|
|
|
int frame_count = 1.0;
|
|
|
|
int current_frame = 0;
|
|
|
|
bool pause = false;
|
2022-09-01 13:19:23 +00:00
|
|
|
bool one_shot = false;
|
2022-09-01 10:09:06 +00:00
|
|
|
float speed_scale = 1.0;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
2021-02-09 17:24:36 +00:00
|
|
|
float time = 0.0;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
2021-02-09 17:24:36 +00:00
|
|
|
uint64_t prev_ticks = 0;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
|
|
|
void _update_proxy();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-08-12 20:57:11 +00:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
void set_frames(int p_frames);
|
|
|
|
int get_frames() const;
|
|
|
|
|
2020-04-28 09:03:36 +00:00
|
|
|
void set_current_frame(int p_frame);
|
|
|
|
int get_current_frame() const;
|
|
|
|
|
|
|
|
void set_pause(bool p_pause);
|
|
|
|
bool get_pause() const;
|
|
|
|
|
2022-09-01 13:19:23 +00:00
|
|
|
void set_one_shot(bool p_one_shot);
|
|
|
|
bool get_one_shot() const;
|
2020-04-28 09:03:36 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
void set_frame_texture(int p_frame, const Ref<Texture2D> &p_texture);
|
|
|
|
Ref<Texture2D> get_frame_texture(int p_frame) const;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
2022-09-01 10:09:06 +00:00
|
|
|
void set_frame_duration(int p_frame, float p_duration);
|
|
|
|
float get_frame_duration(int p_frame) const;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
2022-09-01 10:09:06 +00:00
|
|
|
void set_speed_scale(float p_scale);
|
|
|
|
float get_speed_scale() const;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
virtual RID get_rid() const override;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual bool has_alpha() const override;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
2021-03-28 11:32:17 +00:00
|
|
|
virtual Ref<Image> get_image() const override;
|
2018-07-16 14:43:26 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const override;
|
2018-08-24 01:10:15 +00:00
|
|
|
|
2018-07-16 14:43:26 +00:00
|
|
|
AnimatedTexture();
|
|
|
|
~AnimatedTexture();
|
|
|
|
};
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
class CameraTexture : public Texture2D {
|
|
|
|
GDCLASS(CameraTexture, Texture2D);
|
2017-08-20 14:17:24 +00:00
|
|
|
|
|
|
|
private:
|
2021-08-13 09:32:01 +00:00
|
|
|
mutable RID _texture;
|
2021-02-09 17:24:36 +00:00
|
|
|
int camera_feed_id = 0;
|
|
|
|
CameraServer::FeedImage which_feed = CameraServer::FEED_RGBA_IMAGE;
|
2017-08-20 14:17:24 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
virtual RID get_rid() const override;
|
|
|
|
virtual bool has_alpha() const override;
|
2017-08-20 14:17:24 +00:00
|
|
|
|
2021-03-28 11:32:17 +00:00
|
|
|
virtual Ref<Image> get_image() const override;
|
2017-08-20 14:17:24 +00:00
|
|
|
|
|
|
|
void set_camera_feed_id(int p_new_id);
|
|
|
|
int get_camera_feed_id() const;
|
|
|
|
|
|
|
|
void set_which_feed(CameraServer::FeedImage p_which);
|
|
|
|
CameraServer::FeedImage get_which_feed() const;
|
|
|
|
|
|
|
|
void set_camera_active(bool p_active);
|
|
|
|
bool get_camera_active() const;
|
|
|
|
|
|
|
|
CameraTexture();
|
|
|
|
~CameraTexture();
|
|
|
|
};
|
|
|
|
|
2022-04-28 09:46:45 +00:00
|
|
|
class PlaceholderTexture2D : public Texture2D {
|
|
|
|
GDCLASS(PlaceholderTexture2D, Texture2D)
|
|
|
|
|
|
|
|
RID rid;
|
|
|
|
Size2 size = Size2(1, 1);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_size(Size2 p_size);
|
|
|
|
|
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
virtual RID get_rid() const override;
|
|
|
|
virtual bool has_alpha() const override;
|
|
|
|
|
|
|
|
virtual Ref<Image> get_image() const override;
|
|
|
|
|
|
|
|
PlaceholderTexture2D();
|
|
|
|
~PlaceholderTexture2D();
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlaceholderTexture3D : public Texture3D {
|
|
|
|
GDCLASS(PlaceholderTexture3D, Texture3D)
|
|
|
|
|
|
|
|
RID rid;
|
|
|
|
Vector3i size = Vector3i(1, 1, 1);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_size(const Vector3i &p_size);
|
|
|
|
Vector3i get_size() const;
|
|
|
|
virtual Image::Format get_format() const override;
|
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
virtual int get_depth() const override;
|
|
|
|
virtual bool has_mipmaps() const override;
|
|
|
|
virtual Vector<Ref<Image>> get_data() const override;
|
|
|
|
|
|
|
|
PlaceholderTexture3D();
|
|
|
|
~PlaceholderTexture3D();
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlaceholderTextureLayered : public TextureLayered {
|
|
|
|
GDCLASS(PlaceholderTextureLayered, TextureLayered)
|
|
|
|
|
|
|
|
RID rid;
|
|
|
|
Size2i size = Size2i(1, 1);
|
|
|
|
int layers = 1;
|
|
|
|
LayeredType layered_type = LAYERED_TYPE_2D_ARRAY;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_size(const Size2i &p_size);
|
|
|
|
Size2i get_size() const;
|
|
|
|
void set_layers(int p_layers);
|
|
|
|
virtual Image::Format get_format() const override;
|
|
|
|
virtual LayeredType get_layered_type() const override;
|
|
|
|
virtual int get_width() const override;
|
|
|
|
virtual int get_height() const override;
|
|
|
|
virtual int get_layers() const override;
|
|
|
|
virtual bool has_mipmaps() const override;
|
|
|
|
virtual Ref<Image> get_layer_data(int p_layer) const override;
|
|
|
|
|
|
|
|
PlaceholderTextureLayered(LayeredType p_type);
|
|
|
|
~PlaceholderTextureLayered();
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlaceholderTexture2DArray : public PlaceholderTextureLayered {
|
|
|
|
GDCLASS(PlaceholderTexture2DArray, PlaceholderTextureLayered)
|
|
|
|
public:
|
|
|
|
PlaceholderTexture2DArray() :
|
|
|
|
PlaceholderTextureLayered(LAYERED_TYPE_2D_ARRAY) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlaceholderCubemap : public PlaceholderTextureLayered {
|
|
|
|
GDCLASS(PlaceholderCubemap, PlaceholderTextureLayered)
|
|
|
|
public:
|
|
|
|
PlaceholderCubemap() :
|
|
|
|
PlaceholderTextureLayered(LAYERED_TYPE_CUBEMAP) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlaceholderCubemapArray : public PlaceholderTextureLayered {
|
|
|
|
GDCLASS(PlaceholderCubemapArray, PlaceholderTextureLayered)
|
|
|
|
public:
|
|
|
|
PlaceholderCubemapArray() :
|
|
|
|
PlaceholderTextureLayered(LAYERED_TYPE_CUBEMAP_ARRAY) {}
|
|
|
|
};
|
|
|
|
|
2022-07-23 21:41:51 +00:00
|
|
|
#endif // TEXTURE_H
|