2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* texture.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2018-01-01 14:40:08 +01:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01: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-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef TEXTURE_H
|
|
|
|
#define TEXTURE_H
|
|
|
|
|
2017-04-30 16:27:10 +02:00
|
|
|
#include "curve.h"
|
2017-02-01 13:45:45 +01:00
|
|
|
#include "io/resource_loader.h"
|
2018-07-16 16:43:26 +02:00
|
|
|
#include "os/mutex.h"
|
2018-08-23 18:27:17 +02:00
|
|
|
#include "os/rw_lock.h"
|
2018-07-16 16:43:26 +02:00
|
|
|
#include "os/thread_safe.h"
|
2018-08-11 10:08:26 +02:00
|
|
|
#include "rect2.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "resource.h"
|
2017-06-24 21:28:22 +02:00
|
|
|
#include "scene/resources/color_ramp.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "servers/visual_server.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
/**
|
|
|
|
@author Juan Linietsky <reduzio@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Texture : public Resource {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(Texture, Resource);
|
|
|
|
OBJ_SAVE_TYPE(Texture); //children are all saved as Texture, so they can be exchanged
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
enum Flags {
|
2017-03-05 16:44:50 +01:00
|
|
|
FLAG_MIPMAPS = VisualServer::TEXTURE_FLAG_MIPMAPS,
|
|
|
|
FLAG_REPEAT = VisualServer::TEXTURE_FLAG_REPEAT,
|
|
|
|
FLAG_FILTER = VisualServer::TEXTURE_FLAG_FILTER,
|
|
|
|
FLAG_ANISOTROPIC_FILTER = VisualServer::TEXTURE_FLAG_ANISOTROPIC_FILTER,
|
|
|
|
FLAG_CONVERT_TO_LINEAR = VisualServer::TEXTURE_FLAG_CONVERT_TO_LINEAR,
|
|
|
|
FLAG_VIDEO_SURFACE = VisualServer::TEXTURE_FLAG_USED_FOR_STREAMING,
|
|
|
|
FLAGS_DEFAULT = FLAG_MIPMAPS | FLAG_REPEAT | FLAG_FILTER,
|
|
|
|
FLAG_MIRRORED_REPEAT = VisualServer::TEXTURE_FLAG_MIRRORED_REPEAT
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual int get_width() const = 0;
|
|
|
|
virtual int get_height() const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual Size2 get_size() const;
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual RID get_rid() const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-08-24 03:10:15 +02:00
|
|
|
virtual bool is_pixel_opaque(int p_x, int p_y) const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual bool has_alpha() const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_flags(uint32_t p_flags) = 0;
|
|
|
|
virtual uint32_t get_flags() const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-18 04:26:49 +02: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 Ref<Texture> &p_normal_map = Ref<Texture>()) 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 Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
2017-06-19 03:55:02 +02:00
|
|
|
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, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
2017-03-05 16:44:50 +01: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 02:10:30 +01:00
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
virtual Ref<Image> get_data() const { return Ref<Image>(); }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Texture();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VARIANT_ENUM_CAST(Texture::Flags);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-08-24 03:10:15 +02:00
|
|
|
class BitMap;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
class ImageTexture : public Texture {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(ImageTexture, Texture);
|
2014-02-10 02:10:30 +01:00
|
|
|
RES_BASE_EXTENSION("tex");
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
|
|
|
enum Storage {
|
|
|
|
STORAGE_RAW,
|
|
|
|
STORAGE_COMPRESS_LOSSY,
|
|
|
|
STORAGE_COMPRESS_LOSSLESS
|
|
|
|
};
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
private:
|
|
|
|
RID texture;
|
|
|
|
Image::Format format;
|
|
|
|
uint32_t flags;
|
2017-03-05 16:44:50 +01:00
|
|
|
int w, h;
|
2014-02-10 02:10:30 +01:00
|
|
|
Storage storage;
|
|
|
|
Size2 size_override;
|
|
|
|
float lossy_storage_quality;
|
2018-08-24 03:10:15 +02:00
|
|
|
mutable Ref<BitMap> alpha_cache;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
protected:
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void reload_from_file();
|
|
|
|
|
2017-03-05 16:44:50 +01: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 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _reload_hook(const RID &p_hook);
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void _resource_path_changed();
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
void _set_data(Dictionary p_data);
|
|
|
|
|
|
|
|
public:
|
2017-03-05 16:44:50 +01:00
|
|
|
void create(int p_width, int p_height, Image::Format p_format, uint32_t p_flags = FLAGS_DEFAULT);
|
2017-05-17 12:36:47 +02:00
|
|
|
void create_from_image(const Ref<Image> &p_image, uint32_t p_flags = FLAGS_DEFAULT);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_flags(uint32_t p_flags);
|
|
|
|
uint32_t get_flags() const;
|
|
|
|
Image::Format get_format() const;
|
2018-08-14 21:52:40 +02:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
2018-05-12 16:53:45 +02:00
|
|
|
Error load(const String &p_path);
|
2018-08-14 21:52:40 +02:00
|
|
|
#endif
|
2017-05-17 12:36:47 +02:00
|
|
|
void set_data(const Ref<Image> &p_image);
|
|
|
|
Ref<Image> get_data() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
int get_width() const;
|
|
|
|
int get_height() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual RID get_rid() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool has_alpha() const;
|
2017-06-18 04:26:49 +02: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 Ref<Texture> &p_normal_map = Ref<Texture>()) 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 Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
2017-06-19 03:55:02 +02:00
|
|
|
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, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_storage(Storage p_storage);
|
|
|
|
Storage get_storage() const;
|
|
|
|
|
2018-08-24 03:10:15 +02:00
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_lossy_storage_quality(float p_lossy_storage_quality);
|
|
|
|
float get_lossy_storage_quality() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_size_override(const Size2 &p_size);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_path(const String &p_path, bool p_take_over = false);
|
2015-10-21 14:50:44 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
ImageTexture();
|
|
|
|
~ImageTexture();
|
|
|
|
};
|
|
|
|
|
2017-02-01 13:45:45 +01:00
|
|
|
class StreamTexture : public Texture {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(StreamTexture, Texture);
|
|
|
|
|
2017-02-01 13:45:45 +01:00
|
|
|
public:
|
|
|
|
enum DataFormat {
|
|
|
|
DATA_FORMAT_IMAGE,
|
|
|
|
DATA_FORMAT_LOSSLESS,
|
|
|
|
DATA_FORMAT_LOSSY
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FormatBits {
|
2017-03-05 16:44:50 +01:00
|
|
|
FORMAT_MASK_IMAGE_FORMAT = (1 << 20) - 1,
|
|
|
|
FORMAT_BIT_LOSSLESS = 1 << 20,
|
|
|
|
FORMAT_BIT_LOSSY = 1 << 21,
|
|
|
|
FORMAT_BIT_STREAM = 1 << 22,
|
|
|
|
FORMAT_BIT_HAS_MIPMAPS = 1 << 23,
|
|
|
|
FORMAT_BIT_DETECT_3D = 1 << 24,
|
|
|
|
FORMAT_BIT_DETECT_SRGB = 1 << 25,
|
2017-06-17 02:47:28 +02:00
|
|
|
FORMAT_BIT_DETECT_NORMAL = 1 << 26,
|
2017-02-01 13:45:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2017-05-23 13:55:32 +02:00
|
|
|
Error _load_data(const String &p_path, int &tw, int &th, int &flags, Ref<Image> &image, int p_size_limit = 0);
|
2017-02-01 13:45:45 +01:00
|
|
|
String path_to_file;
|
|
|
|
RID texture;
|
|
|
|
Image::Format format;
|
|
|
|
uint32_t flags;
|
2017-03-05 16:44:50 +01:00
|
|
|
int w, h;
|
2018-08-24 03:10:15 +02:00
|
|
|
mutable Ref<BitMap> alpha_cache;
|
2017-02-01 13:45:45 +01:00
|
|
|
|
|
|
|
virtual void reload_from_file();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static void _requested_3d(void *p_ud);
|
|
|
|
static void _requested_srgb(void *p_ud);
|
2017-06-17 02:47:28 +02:00
|
|
|
static void _requested_normal(void *p_ud);
|
2017-02-06 04:38:39 +01:00
|
|
|
|
2017-02-01 13:45:45 +01:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2017-03-05 16:44:50 +01:00
|
|
|
typedef void (*TextureFormatRequestCallback)(const Ref<StreamTexture> &);
|
2017-02-06 04:38:39 +01:00
|
|
|
|
|
|
|
static TextureFormatRequestCallback request_3d_callback;
|
|
|
|
static TextureFormatRequestCallback request_srgb_callback;
|
2017-06-17 02:47:28 +02:00
|
|
|
static TextureFormatRequestCallback request_normal_callback;
|
2017-02-06 04:38:39 +01:00
|
|
|
|
2017-02-01 13:45:45 +01:00
|
|
|
uint32_t get_flags() const;
|
|
|
|
Image::Format get_format() const;
|
2017-03-05 16:44:50 +01:00
|
|
|
Error load(const String &p_path);
|
2017-02-01 13:45:45 +01:00
|
|
|
String get_load_path() const;
|
|
|
|
|
|
|
|
int get_width() const;
|
|
|
|
int get_height() const;
|
|
|
|
virtual RID get_rid() const;
|
|
|
|
|
2017-06-18 04:26:49 +02: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 Ref<Texture> &p_normal_map = Ref<Texture>()) 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 Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
2017-06-19 03:55:02 +02:00
|
|
|
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, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
2017-02-01 13:45:45 +01:00
|
|
|
|
|
|
|
virtual bool has_alpha() const;
|
|
|
|
virtual void set_flags(uint32_t p_flags);
|
2018-08-24 03:10:15 +02:00
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const;
|
2017-02-01 13:45:45 +01:00
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
virtual Ref<Image> get_data() const;
|
2017-02-15 12:29:46 +01:00
|
|
|
|
2017-02-01 13:45:45 +01:00
|
|
|
StreamTexture();
|
|
|
|
~StreamTexture();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceFormatLoaderStreamTexture : public ResourceFormatLoader {
|
|
|
|
public:
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
|
2017-02-01 13:45:45 +01:00
|
|
|
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual bool handles_type(const String &p_type) const;
|
2017-02-01 13:45:45 +01:00
|
|
|
virtual String get_resource_type(const String &p_path) const;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VARIANT_ENUM_CAST(ImageTexture::Storage);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class AtlasTexture : public Texture {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(AtlasTexture, Texture);
|
2017-06-16 00:44:11 +02:00
|
|
|
RES_BASE_EXTENSION("atlastex");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
protected:
|
2014-02-10 02:10:30 +01:00
|
|
|
Ref<Texture> atlas;
|
|
|
|
Rect2 region;
|
|
|
|
Rect2 margin;
|
2017-11-05 21:45:36 +01:00
|
|
|
bool filter_clip;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual int get_width() const;
|
|
|
|
virtual int get_height() const;
|
|
|
|
virtual RID get_rid() const;
|
|
|
|
|
|
|
|
virtual bool has_alpha() const;
|
|
|
|
|
|
|
|
virtual void set_flags(uint32_t p_flags);
|
|
|
|
virtual uint32_t get_flags() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_atlas(const Ref<Texture> &p_atlas);
|
2014-02-10 02:10:30 +01:00
|
|
|
Ref<Texture> get_atlas() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_region(const Rect2 &p_region);
|
|
|
|
Rect2 get_region() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_margin(const Rect2 &p_margin);
|
|
|
|
Rect2 get_margin() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-11-05 21:45:36 +01:00
|
|
|
void set_filter_clip(const bool p_enable);
|
|
|
|
bool has_filter_clip() const;
|
|
|
|
|
2017-06-18 04:26:49 +02: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 Ref<Texture> &p_normal_map = Ref<Texture>()) 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 Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
2017-06-19 03:55:02 +02:00
|
|
|
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, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
2017-03-05 16:44:50 +01: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 02:10:30 +01:00
|
|
|
|
2018-08-24 03:10:15 +02:00
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
AtlasTexture();
|
|
|
|
};
|
|
|
|
|
|
|
|
class LargeTexture : public Texture {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(LargeTexture, Texture);
|
2017-06-16 00:44:11 +02:00
|
|
|
RES_BASE_EXTENSION("largetex");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
protected:
|
2014-02-10 02:10:30 +01:00
|
|
|
struct Piece {
|
|
|
|
|
|
|
|
Point2 offset;
|
|
|
|
Ref<Texture> texture;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Piece> pieces;
|
|
|
|
Size2i size;
|
|
|
|
|
|
|
|
Array _get_data() const;
|
2017-03-05 16:44:50 +01:00
|
|
|
void _set_data(const Array &p_array);
|
2014-02-10 02:10:30 +01:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual int get_width() const;
|
|
|
|
virtual int get_height() const;
|
|
|
|
virtual RID get_rid() const;
|
|
|
|
|
|
|
|
virtual bool has_alpha() const;
|
|
|
|
|
|
|
|
virtual void set_flags(uint32_t p_flags);
|
|
|
|
virtual uint32_t get_flags() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int add_piece(const Point2 &p_offset, const Ref<Texture> &p_texture);
|
|
|
|
void set_piece_offset(int p_idx, const Point2 &p_offset);
|
|
|
|
void set_piece_texture(int p_idx, const Ref<Texture> &p_texture);
|
2014-04-29 02:56:43 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_size(const Size2 &p_size);
|
2014-02-10 02:10:30 +01:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
int get_piece_count() const;
|
|
|
|
Vector2 get_piece_offset(int p_idx) const;
|
|
|
|
Ref<Texture> get_piece_texture(int p_idx) const;
|
|
|
|
|
2017-06-18 04:26:49 +02: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 Ref<Texture> &p_normal_map = Ref<Texture>()) 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 Ref<Texture> &p_normal_map = Ref<Texture>()) const;
|
2017-06-19 03:55:02 +02:00
|
|
|
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, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-08-24 03:10:15 +02:00
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
LargeTexture();
|
|
|
|
};
|
|
|
|
|
|
|
|
class CubeMap : public Resource {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(CubeMap, Resource);
|
2017-06-16 00:44:11 +02:00
|
|
|
RES_BASE_EXTENSION("cubemap");
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
|
|
|
enum Storage {
|
|
|
|
STORAGE_RAW,
|
|
|
|
STORAGE_COMPRESS_LOSSY,
|
|
|
|
STORAGE_COMPRESS_LOSSLESS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Side {
|
|
|
|
|
|
|
|
SIDE_LEFT,
|
|
|
|
SIDE_RIGHT,
|
|
|
|
SIDE_BOTTOM,
|
|
|
|
SIDE_TOP,
|
|
|
|
SIDE_FRONT,
|
|
|
|
SIDE_BACK
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Flags {
|
2017-03-05 16:44:50 +01:00
|
|
|
FLAG_MIPMAPS = VisualServer::TEXTURE_FLAG_MIPMAPS,
|
|
|
|
FLAG_REPEAT = VisualServer::TEXTURE_FLAG_REPEAT,
|
|
|
|
FLAG_FILTER = VisualServer::TEXTURE_FLAG_FILTER,
|
|
|
|
FLAGS_DEFAULT = FLAG_MIPMAPS | FLAG_REPEAT | FLAG_FILTER,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool valid[6];
|
|
|
|
RID cubemap;
|
|
|
|
Image::Format format;
|
|
|
|
uint32_t flags;
|
2017-03-05 16:44:50 +01:00
|
|
|
int w, h;
|
2014-02-10 02:10:30 +01:00
|
|
|
Storage storage;
|
|
|
|
Size2 size_override;
|
|
|
|
float lossy_storage_quality;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ bool _is_valid() const {
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
if (valid[i]) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
protected:
|
2017-03-05 16:44:50 +01: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 02:10:30 +01:00
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_flags(uint32_t p_flags);
|
|
|
|
uint32_t get_flags() const;
|
2017-05-17 12:36:47 +02:00
|
|
|
void set_side(Side p_side, const Ref<Image> &p_image);
|
|
|
|
Ref<Image> get_side(Side p_side) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Image::Format get_format() const;
|
|
|
|
int get_width() const;
|
|
|
|
int get_height() const;
|
|
|
|
|
|
|
|
virtual RID get_rid() const;
|
|
|
|
|
|
|
|
void set_storage(Storage p_storage);
|
|
|
|
Storage get_storage() const;
|
|
|
|
|
|
|
|
void set_lossy_storage_quality(float p_lossy_storage_quality);
|
|
|
|
float get_lossy_storage_quality() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_path(const String &p_path, bool p_take_over = false);
|
2015-10-21 14:50:44 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
CubeMap();
|
|
|
|
~CubeMap();
|
|
|
|
};
|
|
|
|
|
2017-04-30 16:27:10 +02:00
|
|
|
VARIANT_ENUM_CAST(CubeMap::Flags)
|
|
|
|
VARIANT_ENUM_CAST(CubeMap::Side)
|
|
|
|
VARIANT_ENUM_CAST(CubeMap::Storage)
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
class TextureLayered : public Resource {
|
2018-06-26 13:59:26 +02:00
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
GDCLASS(TextureLayered, Resource)
|
2018-06-26 13:59:26 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum Flags {
|
|
|
|
FLAG_MIPMAPS = VisualServer::TEXTURE_FLAG_MIPMAPS,
|
|
|
|
FLAG_REPEAT = VisualServer::TEXTURE_FLAG_REPEAT,
|
|
|
|
FLAG_FILTER = VisualServer::TEXTURE_FLAG_FILTER,
|
2018-08-06 19:56:06 +02:00
|
|
|
FLAG_CONVERT_TO_LINEAR = VisualServer::TEXTURE_FLAG_CONVERT_TO_LINEAR,
|
|
|
|
FLAGS_DEFAULT = FLAG_FILTER,
|
2018-06-26 13:59:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2018-08-06 19:56:06 +02:00
|
|
|
bool is_3d;
|
2018-06-26 13:59:26 +02:00
|
|
|
RID texture;
|
|
|
|
Image::Format format;
|
|
|
|
uint32_t flags;
|
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int depth;
|
2018-06-26 13:59:26 +02:00
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
void _set_data(const Dictionary &p_data);
|
|
|
|
Dictionary _get_data() const;
|
2018-06-26 13:59:26 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_flags(uint32_t p_flags);
|
|
|
|
uint32_t get_flags() const;
|
|
|
|
|
|
|
|
Image::Format get_format() const;
|
|
|
|
uint32_t get_width() const;
|
|
|
|
uint32_t get_height() const;
|
|
|
|
uint32_t get_depth() const;
|
|
|
|
|
|
|
|
void create(uint32_t p_width, uint32_t p_height, uint32_t p_depth, Image::Format p_format, uint32_t p_flags = FLAGS_DEFAULT);
|
2018-08-06 19:56:06 +02:00
|
|
|
void set_layer_data(const Ref<Image> &p_image, int p_layer);
|
|
|
|
Ref<Image> get_layer_data(int p_layer) const;
|
|
|
|
void set_data_partial(const Ref<Image> &p_image, int p_x_ofs, int p_y_ofs, int p_z, int p_mipmap = 0);
|
2018-06-26 13:59:26 +02:00
|
|
|
|
|
|
|
virtual RID get_rid() const;
|
2018-08-06 19:56:06 +02:00
|
|
|
virtual void set_path(const String &p_path, bool p_take_over = false);
|
2018-06-26 13:59:26 +02:00
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
TextureLayered(bool p_3d = false);
|
|
|
|
~TextureLayered();
|
|
|
|
};
|
2018-06-26 13:59:26 +02:00
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
VARIANT_ENUM_CAST(TextureLayered::Flags)
|
2018-06-26 13:59:26 +02:00
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
class Texture3D : public TextureLayered {
|
2018-06-26 13:59:26 +02:00
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
GDCLASS(Texture3D, TextureLayered)
|
|
|
|
public:
|
|
|
|
Texture3D() :
|
|
|
|
TextureLayered(true) {}
|
|
|
|
};
|
2018-06-26 13:59:26 +02:00
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
class TextureArray : public TextureLayered {
|
2018-06-26 13:59:26 +02:00
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
GDCLASS(TextureArray, TextureLayered)
|
|
|
|
public:
|
|
|
|
TextureArray() :
|
|
|
|
TextureLayered(false) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceFormatLoaderTextureLayered : public ResourceFormatLoader {
|
|
|
|
public:
|
|
|
|
enum Compression {
|
|
|
|
COMPRESSION_LOSSLESS,
|
|
|
|
COMPRESSION_VRAM,
|
|
|
|
COMPRESSION_UNCOMPRESSED
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
|
|
|
|
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 13:59:26 +02:00
|
|
|
};
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
class CurveTexture : public Texture {
|
|
|
|
|
2017-04-30 16:27:10 +02:00
|
|
|
GDCLASS(CurveTexture, Texture)
|
|
|
|
RES_BASE_EXTENSION("curvetex")
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
private:
|
2017-04-30 16:27:10 +02:00
|
|
|
RID _texture;
|
|
|
|
Ref<Curve> _curve;
|
|
|
|
int _width;
|
|
|
|
|
|
|
|
void _update();
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_width(int p_width);
|
|
|
|
int get_width() const;
|
|
|
|
|
2017-07-30 22:53:40 +02:00
|
|
|
void ensure_default_setup(float p_min = 0, float p_max = 1);
|
2017-04-30 16:27:10 +02:00
|
|
|
|
|
|
|
void set_curve(Ref<Curve> p_curve);
|
|
|
|
Ref<Curve> get_curve() const;
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
virtual RID get_rid() const;
|
|
|
|
|
|
|
|
virtual int get_height() const { return 1; }
|
|
|
|
virtual bool has_alpha() const { return false; }
|
|
|
|
|
|
|
|
virtual void set_flags(uint32_t p_flags) {}
|
|
|
|
virtual uint32_t get_flags() const { return FLAG_FILTER; }
|
|
|
|
|
|
|
|
CurveTexture();
|
|
|
|
~CurveTexture();
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
/*
|
|
|
|
enum CubeMapSide {
|
|
|
|
|
|
|
|
CUBEMAP_LEFT,
|
|
|
|
CUBEMAP_RIGHT,
|
|
|
|
CUBEMAP_BOTTOM,
|
|
|
|
CUBEMAP_TOP,
|
|
|
|
CUBEMAP_FRONT,
|
|
|
|
CUBEMAP_BACK,
|
|
|
|
};
|
|
|
|
|
|
|
|
*/
|
|
|
|
//VARIANT_ENUM_CAST( Texture::CubeMapSide );
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
class GradientTexture : public Texture {
|
2017-06-24 21:28:22 +02:00
|
|
|
GDCLASS(GradientTexture, Texture)
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
struct Point {
|
|
|
|
|
|
|
|
float offset;
|
|
|
|
Color color;
|
|
|
|
bool operator<(const Point &p_ponit) const {
|
|
|
|
return offset < p_ponit.offset;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2017-06-24 21:28:22 +02:00
|
|
|
Ref<Gradient> gradient;
|
2017-04-07 04:36:37 +02:00
|
|
|
bool update_pending;
|
|
|
|
RID texture;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
void _queue_update();
|
|
|
|
void _update();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2017-06-24 21:28:22 +02:00
|
|
|
void set_gradient(Ref<Gradient> p_gradient);
|
|
|
|
Ref<Gradient> get_gradient() const;
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
void set_width(int p_width);
|
|
|
|
int get_width() const;
|
|
|
|
|
|
|
|
virtual RID get_rid() const { return texture; }
|
|
|
|
virtual int get_height() const { return 1; }
|
|
|
|
virtual bool has_alpha() const { return true; }
|
|
|
|
|
|
|
|
virtual void set_flags(uint32_t p_flags) {}
|
|
|
|
virtual uint32_t get_flags() const { return FLAG_FILTER; }
|
|
|
|
|
2017-06-09 05:23:50 +02:00
|
|
|
virtual Ref<Image> get_data() const;
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
GradientTexture();
|
|
|
|
virtual ~GradientTexture();
|
|
|
|
};
|
|
|
|
|
2017-12-04 20:54:17 +01:00
|
|
|
class ProxyTexture : public Texture {
|
|
|
|
GDCLASS(ProxyTexture, Texture)
|
|
|
|
|
|
|
|
private:
|
|
|
|
RID proxy;
|
|
|
|
Ref<Texture> base;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_base(const Ref<Texture> &p_texture);
|
|
|
|
Ref<Texture> get_base() const;
|
|
|
|
|
|
|
|
virtual int get_width() const;
|
|
|
|
virtual int get_height() const;
|
|
|
|
virtual RID get_rid() const;
|
|
|
|
|
|
|
|
virtual bool has_alpha() const;
|
|
|
|
|
|
|
|
virtual void set_flags(uint32_t p_flags);
|
|
|
|
virtual uint32_t get_flags() const;
|
|
|
|
|
|
|
|
ProxyTexture();
|
|
|
|
~ProxyTexture();
|
|
|
|
};
|
|
|
|
|
2018-07-16 16:43:26 +02:00
|
|
|
class AnimatedTexture : public Texture {
|
|
|
|
GDCLASS(AnimatedTexture, Texture)
|
|
|
|
|
2018-08-23 18:27:17 +02:00
|
|
|
//use readers writers lock for this, since its far more times read than written to
|
|
|
|
RWLock *rw_lock;
|
2018-07-16 16:43:26 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum {
|
|
|
|
MAX_FRAMES = 256
|
|
|
|
};
|
|
|
|
|
|
|
|
RID proxy;
|
|
|
|
|
|
|
|
struct Frame {
|
|
|
|
|
|
|
|
Ref<Texture> texture;
|
|
|
|
float delay_sec;
|
|
|
|
|
|
|
|
Frame() {
|
|
|
|
delay_sec = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Frame frames[MAX_FRAMES];
|
|
|
|
int frame_count;
|
|
|
|
int current_frame;
|
|
|
|
|
|
|
|
float fps;
|
|
|
|
|
|
|
|
float time;
|
|
|
|
|
|
|
|
uint64_t prev_ticks;
|
|
|
|
|
|
|
|
void _update_proxy();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
void _validate_property(PropertyInfo &property) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_frames(int p_frames);
|
|
|
|
int get_frames() const;
|
|
|
|
|
|
|
|
void set_frame_texture(int p_frame, const Ref<Texture> &p_texture);
|
|
|
|
Ref<Texture> get_frame_texture(int p_frame) const;
|
|
|
|
|
|
|
|
void set_frame_delay(int p_frame, float p_delay_sec);
|
|
|
|
float get_frame_delay(int p_frame) const;
|
|
|
|
|
|
|
|
void set_fps(float p_fps);
|
|
|
|
float get_fps() const;
|
|
|
|
|
|
|
|
virtual int get_width() const;
|
|
|
|
virtual int get_height() const;
|
|
|
|
virtual RID get_rid() const;
|
|
|
|
|
|
|
|
virtual bool has_alpha() const;
|
|
|
|
|
|
|
|
virtual void set_flags(uint32_t p_flags);
|
|
|
|
virtual uint32_t get_flags() const;
|
|
|
|
|
|
|
|
virtual Ref<Image> get_data() const;
|
|
|
|
|
2018-08-24 03:10:15 +02:00
|
|
|
bool is_pixel_opaque(int p_x, int p_y) const;
|
|
|
|
|
2018-07-16 16:43:26 +02:00
|
|
|
AnimatedTexture();
|
|
|
|
~AnimatedTexture();
|
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|