2014-02-10 01:10:30 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* texture.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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();
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(int, _get_width)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(int, _get_height)
|
2022-03-10 07:17:38 +00:00
|
|
|
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;
|
2014-05-29 13:56: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;
|
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
|
|
|
|
2022-12-20 21:49:11 +00:00
|
|
|
virtual Ref<Resource> create_placeholder() const;
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Texture2D();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(Image::Format, _get_format)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(uint32_t, _get_layered_type)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(int, _get_width)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(int, _get_height)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(int, _get_layers)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(bool, _has_mipmaps)
|
|
|
|
GDVIRTUAL1RC_REQUIRED(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)
|
|
|
|
|
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
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(Image::Format, _get_format)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(int, _get_width)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(int, _get_height)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(int, _get_depth)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(bool, _has_mipmaps)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(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;
|
2022-12-20 21:49:11 +00:00
|
|
|
virtual Ref<Resource> create_placeholder() const;
|
2020-09-09 15:40:51 +00:00
|
|
|
};
|
|
|
|
|
2022-07-23 21:41:51 +00:00
|
|
|
#endif // TEXTURE_H
|