2023-01-05 13:25:55 +01: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-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef TEXTURE_H
|
|
|
|
#define TEXTURE_H
|
|
|
|
|
2021-06-11 14:51:48 +02:00
|
|
|
#include "core/io/file_access.h"
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/io/resource.h"
|
2018-09-11 18:13:45 +02: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 22:54:35 +02:00
|
|
|
#include "scene/resources/curve.h"
|
2019-02-12 17:18:13 +01:00
|
|
|
#include "scene/resources/gradient.h"
|
2017-08-20 16:17:24 +02:00
|
|
|
#include "servers/camera_server.h"
|
2020-03-27 19:21:27 +01:00
|
|
|
#include "servers/rendering_server.h"
|
2018-09-13 22:54:35 +02:00
|
|
|
|
2019-06-19 22:03:19 +02:00
|
|
|
class Texture : public Resource {
|
|
|
|
GDCLASS(Texture, Resource);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Texture() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Texture2D : public Texture {
|
2020-02-16 18:17:22 +01:00
|
|
|
GDCLASS(Texture2D, Texture);
|
2019-06-11 20:43:37 +02:00
|
|
|
OBJ_SAVE_TYPE(Texture2D); // Saves derived classes with common type so they can be interchanged.
|
2020-01-26 11:24:14 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2024-06-18 17:07:35 +02:00
|
|
|
GDVIRTUAL0RC_REQUIRED(int, _get_width)
|
|
|
|
GDVIRTUAL0RC_REQUIRED(int, _get_height)
|
2022-03-10 08:17:38 +01: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 16:44:50 +01:00
|
|
|
public:
|
2022-03-10 08:17:38 +01:00
|
|
|
virtual int get_width() const;
|
|
|
|
virtual int get_height() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual Size2 get_size() const;
|
|
|
|
|
2018-08-24 03:10:15 +02:00
|
|
|
virtual bool is_pixel_opaque(int p_x, int p_y) const;
|
|
|
|
|
2022-03-10 08:17:38 +01:00
|
|
|
virtual bool has_alpha() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-24 17:15:43 +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;
|
|
|
|
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 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
|
|
|
|
2021-03-28 13:32:17 +02:00
|
|
|
virtual Ref<Image> get_image() const { return Ref<Image>(); }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-12-20 22:49:11 +01:00
|
|
|
virtual Ref<Resource> create_placeholder() const;
|
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
Texture2D();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2019-06-19 22:03:19 +02:00
|
|
|
class TextureLayered : public Texture {
|
2020-02-16 18:17:22 +01:00
|
|
|
GDCLASS(TextureLayered, Texture);
|
2018-06-26 13:59:26 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2024-06-18 17:07:35 +02: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 14:34:23 +02:00
|
|
|
public:
|
|
|
|
enum LayeredType {
|
|
|
|
LAYERED_TYPE_2D_ARRAY,
|
|
|
|
LAYERED_TYPE_CUBEMAP,
|
|
|
|
LAYERED_TYPE_CUBEMAP_ARRAY
|
|
|
|
};
|
|
|
|
|
2022-03-10 08:17:38 +01: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 14:34:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(TextureLayered::LayeredType)
|
|
|
|
|
2020-09-09 17:40:51 +02:00
|
|
|
class Texture3D : public Texture {
|
|
|
|
GDCLASS(Texture3D, Texture);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2022-03-10 08:17:38 +01:00
|
|
|
TypedArray<Image> _get_datai() const;
|
2020-09-09 17:40:51 +02:00
|
|
|
|
2024-06-18 17:07:35 +02: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 17:40:51 +02:00
|
|
|
public:
|
2022-03-10 08:17:38 +01: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 22:49:11 +01:00
|
|
|
virtual Ref<Resource> create_placeholder() const;
|
2020-09-09 17:40:51 +02:00
|
|
|
};
|
|
|
|
|
2022-07-23 23:41:51 +02:00
|
|
|
#endif // TEXTURE_H
|