Debian Codegraph @

scene/resources/image_texture.h

raw symbols SCIP
1 /**************************************************************************/
2 /* image_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 #pragma once
32
33 #include "scene/resources/texture.h"
34
35 class BitMap;
36
37 class ImageTexture : public Texture2D {
38 GDCLASS(ImageTexture, Texture2D);
39 RES_BASE_EXTENSION("tex");
40
41 mutable RID texture;
42 Image::Format format = Image::FORMAT_L8;
43 bool mipmaps = false;
44 int w = 0;
45 int h = 0;
46 Size2 size_override;
47 mutable Ref<BitMap> alpha_cache;
48 bool image_stored = false;
49
50 protected:
51 virtual void reload_from_file() override;
52 static void _bind_methods();
53
54 public:
55 void set_image(const Ref<Image> &p_image);
56 static Ref<ImageTexture> create_from_image(const Ref<Image> &p_image);
57
58 Image::Format get_format() const;
59
60 void update(const Ref<Image> &p_image);
61 Ref<Image> get_image() const override;
62
63 int get_width() const override;
64 int get_height() const override;
65
66 virtual RID get_rid() const override;
67
68 bool has_alpha() const override;
69 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;
70 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;
71 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;
72
73 bool is_pixel_opaque(int p_x, int p_y) const override;
74
75 void set_size_override(const Size2i &p_size);
76
77 virtual void set_path(const String &p_path, bool p_take_over = false) override;
78
79 ~ImageTexture();
80 };
81
82 class ImageTextureLayered : public TextureLayered {
83 GDCLASS(ImageTextureLayered, TextureLayered);
84
85 LayeredType layered_type;
86
87 mutable RID texture;
88 Image::Format format = Image::FORMAT_L8;
89
90 int width = 0;
91 int height = 0;
92 int layers = 0;
93 bool mipmaps = false;
94
95 Error _create_from_images(const TypedArray<Image> &p_images);
96
97 TypedArray<Image> _get_images() const;
98 void _set_images(const TypedArray<Image> &p_images);
99
100 protected:
101 static void _bind_methods();
102
103 public:
104 virtual Image::Format get_format() const override;
105 virtual int get_width() const override;
106 virtual int get_height() const override;
107 virtual int get_layers() const override;
108 virtual bool has_mipmaps() const override;
109 virtual LayeredType get_layered_type() const override;
110
111 Error create_from_images(Vector<Ref<Image>> p_images);
112 void update_layer(const Ref<Image> &p_image, int p_layer);
113 virtual Ref<Image> get_layer_data(int p_layer) const override;
114
115 virtual RID get_rid() const override;
116 virtual void set_path(const String &p_path, bool p_take_over = false) override;
117
118 ImageTextureLayered(LayeredType p_layered_type);
119 ~ImageTextureLayered();
120 };
121
122 class ImageTexture3D : public Texture3D {
123 GDCLASS(ImageTexture3D, Texture3D);
124
125 mutable RID texture;
126
127 Image::Format format = Image::FORMAT_L8;
128 int width = 1;
129 int height = 1;
130 int depth = 1;
131 bool mipmaps = false;
132 bool images_stored = false;
133
134 TypedArray<Image> _get_images() const;
135 void _set_images(const TypedArray<Image> &p_images);
136
137 protected:
138 static void _bind_methods();
139
140 Error _create(Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const TypedArray<Image> &p_data);
141 void _update(const TypedArray<Image> &p_data);
142
143 public:
144 virtual Image::Format get_format() const override;
145 virtual int get_width() const override;
146 virtual int get_height() const override;
147 virtual int get_depth() const override;
148 virtual bool has_mipmaps() const override;
149
150 Error create(Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_data);
151 void update(const Vector<Ref<Image>> &p_data);
152 virtual Vector<Ref<Image>> get_data() const override;
153
154 virtual RID get_rid() const override;
155 virtual void set_path(const String &p_path, bool p_take_over = false) override;
156
157 ImageTexture3D();
158 ~ImageTexture3D();
159 };
160
161 class Texture2DArray : public ImageTextureLayered {
162 GDCLASS(Texture2DArray, ImageTextureLayered)
163
164 protected:
165 static void _bind_methods();
166
167 public:
168 Texture2DArray() :
169 ImageTextureLayered(LAYERED_TYPE_2D_ARRAY) {}
170
171 virtual Ref<Resource> create_placeholder() const;
172 };
173
174 class Cubemap : public ImageTextureLayered {
175 GDCLASS(Cubemap, ImageTextureLayered);
176
177 protected:
178 static void _bind_methods();
179
180 public:
181 Cubemap() :
182 ImageTextureLayered(LAYERED_TYPE_CUBEMAP) {}
183
184 virtual Ref<Resource> create_placeholder() const;
185 };
186
187 class CubemapArray : public ImageTextureLayered {
188 GDCLASS(CubemapArray, ImageTextureLayered);
189
190 protected:
191 static void _bind_methods();
192
193 public:
194 CubemapArray() :
195 ImageTextureLayered(LAYERED_TYPE_CUBEMAP_ARRAY) {}
196
197 virtual Ref<Resource> create_placeholder() const;
198 };