Debian Codegraph @

scene/resources/portable_compressed_texture.h

raw symbols SCIP
1 /**************************************************************************/
2 /* portable_compressed_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 PortableCompressedTexture2D : public Texture2D {
38 GDCLASS(PortableCompressedTexture2D, Texture2D);
39
40 public:
41 enum DataFormat {
42 DATA_FORMAT_UNDEFINED,
43 DATA_FORMAT_IMAGE,
44 DATA_FORMAT_PNG,
45 DATA_FORMAT_WEBP,
46 DATA_FORMAT_BASIS_UNIVERSAL,
47 };
48
49 enum CompressionMode {
50 COMPRESSION_MODE_LOSSLESS,
51 COMPRESSION_MODE_LOSSY,
52 COMPRESSION_MODE_BASIS_UNIVERSAL,
53 COMPRESSION_MODE_S3TC,
54 COMPRESSION_MODE_ETC2,
55 COMPRESSION_MODE_BPTC,
56 COMPRESSION_MODE_ASTC,
57 };
58
59 private:
60 CompressionMode compression_mode = COMPRESSION_MODE_LOSSLESS;
61 static bool keep_all_compressed_buffers;
62 bool keep_compressed_buffer = false;
63 Vector<uint8_t> compressed_buffer;
64 Size2 size;
65 Size2 size_override;
66 bool mipmaps = false;
67 Image::Format format = Image::FORMAT_L8;
68
69 mutable RID texture;
70 mutable Ref<BitMap> alpha_cache;
71
72 bool image_stored = false;
73
74 Image::BasisUniversalPackerParams basisu_params;
75
76 protected:
77 Vector<uint8_t> _get_data() const;
78 void _set_data(const Vector<uint8_t> &p_data);
79
80 static void _bind_methods();
81
82 public:
83 CompressionMode get_compression_mode() const;
84 void create_from_image(const Ref<Image> &p_image, CompressionMode p_compression_mode, bool p_normal_map = false, float p_lossy_quality = 0.8);
85
86 Image::Format get_format() const;
87
88 void update(const Ref<Image> &p_image);
89 Ref<Image> get_image() const override;
90
91 int get_width() const override;
92 int get_height() const override;
93
94 virtual RID get_rid() const override;
95
96 bool has_alpha() const override;
97 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;
98 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;
99 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;
100
101 bool is_pixel_opaque(int p_x, int p_y) const override;
102
103 virtual void set_path(const String &p_path, bool p_take_over = false) override;
104
105 void set_size_override(const Size2 &p_size);
106 Size2 get_size_override() const;
107
108 void set_keep_compressed_buffer(bool p_keep);
109 bool is_keeping_compressed_buffer() const;
110
111 void set_basisu_compressor_params(int p_uastc_level, float p_rdo_quality_loss);
112
113 static void set_keep_all_compressed_buffers(bool p_keep);
114 static bool is_keeping_all_compressed_buffers();
115
116 ~PortableCompressedTexture2D();
117 };
118
119 VARIANT_ENUM_CAST(PortableCompressedTexture2D::CompressionMode)