| 1 | /**************************************************************************/ |
| 2 | /* texture.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifndef TEXTURE_H |
| 32 | #define TEXTURE_H |
| 33 | |
| 34 | #include "core/io/file_access.h" |
| 35 | #include "core/io/resource.h" |
| 36 | #include "core/io/resource_loader.h" |
| 37 | #include "core/math/rect2.h" |
| 38 | #include "core/os/mutex.h" |
| 39 | #include "core/os/rw_lock.h" |
| 40 | #include "core/os/thread_safe.h" |
| 41 | #include "scene/resources/curve.h" |
| 42 | #include "scene/resources/gradient.h" |
| 43 | #include "servers/camera_server.h" |
| 44 | #include "servers/rendering_server.h" |
| 45 | |
| 46 | class Texture : public Resource { |
| 47 | GDCLASS(Texture, Resource); |
| 48 | |
| 49 | public: |
| 50 | Texture() {} |
| 51 | }; |
| 52 | |
| 53 | class Texture2D : public Texture { |
| 54 | GDCLASS(Texture2D, Texture); |
| 55 | OBJ_SAVE_TYPE(Texture2D); // Saves derived classes with common type so they can be interchanged. |
| 56 | |
| 57 | protected: |
| 58 | static void _bind_methods(); |
| 59 | |
| 60 | GDVIRTUAL0RC(int, _get_width) |
| 61 | GDVIRTUAL0RC(int, _get_height) |
| 62 | GDVIRTUAL2RC(bool, _is_pixel_opaque, int, int) |
| 63 | GDVIRTUAL0RC(bool, _has_alpha) |
| 64 | |
| 65 | GDVIRTUAL4C(_draw, RID, Point2, Color, bool) |
| 66 | GDVIRTUAL5C(_draw_rect, RID, Rect2, bool, Color, bool) |
| 67 | GDVIRTUAL6C(_draw_rect_region, RID, Rect2, Rect2, Color, bool, bool) |
| 68 | |
| 69 | public: |
| 70 | virtual int get_width() const; |
| 71 | virtual int get_height() const; |
| 72 | virtual Size2 get_size() const; |
| 73 | |
| 74 | virtual bool is_pixel_opaque(int p_x, int p_y) const; |
| 75 | |
| 76 | virtual bool has_alpha() const; |
| 77 | |
| 78 | virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const; |
| 79 | 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; |
| 80 | 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; |
| 81 | virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const; |
| 82 | |
| 83 | virtual Ref<Image> get_image() const { return Ref<Image>(); } |
| 84 | |
| 85 | virtual Ref<Resource> create_placeholder() const; |
| 86 | |
| 87 | Texture2D(); |
| 88 | }; |
| 89 | |
| 90 | class TextureLayered : public Texture { |
| 91 | GDCLASS(TextureLayered, Texture); |
| 92 | |
| 93 | protected: |
| 94 | static void _bind_methods(); |
| 95 | |
| 96 | GDVIRTUAL0RC(Image::Format, _get_format) |
| 97 | GDVIRTUAL0RC(uint32_t, _get_layered_type) |
| 98 | GDVIRTUAL0RC(int, _get_width) |
| 99 | GDVIRTUAL0RC(int, _get_height) |
| 100 | GDVIRTUAL0RC(int, _get_layers) |
| 101 | GDVIRTUAL0RC(bool, _has_mipmaps) |
| 102 | GDVIRTUAL1RC(Ref<Image>, _get_layer_data, int) |
| 103 | public: |
| 104 | enum LayeredType { |
| 105 | LAYERED_TYPE_2D_ARRAY, |
| 106 | LAYERED_TYPE_CUBEMAP, |
| 107 | LAYERED_TYPE_CUBEMAP_ARRAY |
| 108 | }; |
| 109 | |
| 110 | virtual Image::Format get_format() const; |
| 111 | virtual LayeredType get_layered_type() const; |
| 112 | virtual int get_width() const; |
| 113 | virtual int get_height() const; |
| 114 | virtual int get_layers() const; |
| 115 | virtual bool has_mipmaps() const; |
| 116 | virtual Ref<Image> get_layer_data(int p_layer) const; |
| 117 | |
| 118 | TextureLayered() {} |
| 119 | }; |
| 120 | |
| 121 | VARIANT_ENUM_CAST(TextureLayered::LayeredType) |
| 122 | |
| 123 | class Texture3D : public Texture { |
| 124 | GDCLASS(Texture3D, Texture); |
| 125 | |
| 126 | protected: |
| 127 | static void _bind_methods(); |
| 128 | |
| 129 | TypedArray<Image> _get_datai() const; |
| 130 | |
| 131 | GDVIRTUAL0RC(Image::Format, _get_format) |
| 132 | GDVIRTUAL0RC(int, _get_width) |
| 133 | GDVIRTUAL0RC(int, _get_height) |
| 134 | GDVIRTUAL0RC(int, _get_depth) |
| 135 | GDVIRTUAL0RC(bool, _has_mipmaps) |
| 136 | GDVIRTUAL0RC(TypedArray<Image>, _get_data) |
| 137 | public: |
| 138 | virtual Image::Format get_format() const; |
| 139 | virtual int get_width() const; |
| 140 | virtual int get_height() const; |
| 141 | virtual int get_depth() const; |
| 142 | virtual bool has_mipmaps() const; |
| 143 | virtual Vector<Ref<Image>> get_data() const; |
| 144 | virtual Ref<Resource> create_placeholder() const; |
| 145 | }; |
| 146 | |
| 147 | #endif // TEXTURE_H |
| 148 | |