1 | /**************************************************************************/ |
2 | /* curve_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 CURVE_TEXTURE_H |
32 | #define CURVE_TEXTURE_H |
33 | |
34 | #include "scene/resources/texture.h" |
35 | |
36 | class CurveTexture : public Texture2D { |
37 | GDCLASS(CurveTexture, Texture2D); |
38 | RES_BASE_EXTENSION("curvetex" ) |
39 | public: |
40 | enum TextureMode { |
41 | TEXTURE_MODE_RGB, |
42 | TEXTURE_MODE_RED, |
43 | }; |
44 | |
45 | private: |
46 | mutable RID _texture; |
47 | Ref<Curve> _curve; |
48 | int _width = 256; |
49 | int _current_width = 0; |
50 | TextureMode texture_mode = TEXTURE_MODE_RGB; |
51 | TextureMode _current_texture_mode = TEXTURE_MODE_RGB; |
52 | |
53 | void _update(); |
54 | |
55 | protected: |
56 | static void _bind_methods(); |
57 | |
58 | public: |
59 | void set_width(int p_width); |
60 | int get_width() const override; |
61 | |
62 | void set_texture_mode(TextureMode p_mode); |
63 | TextureMode get_texture_mode() const; |
64 | |
65 | void ensure_default_setup(float p_min = 0, float p_max = 1); |
66 | |
67 | void set_curve(Ref<Curve> p_curve); |
68 | Ref<Curve> get_curve() const; |
69 | |
70 | virtual RID get_rid() const override; |
71 | |
72 | virtual int get_height() const override { return 1; } |
73 | virtual bool has_alpha() const override { return false; } |
74 | |
75 | CurveTexture(); |
76 | ~CurveTexture(); |
77 | }; |
78 | |
79 | VARIANT_ENUM_CAST(CurveTexture::TextureMode) |
80 | |
81 | class CurveXYZTexture : public Texture2D { |
82 | GDCLASS(CurveXYZTexture, Texture2D); |
83 | RES_BASE_EXTENSION("curvetex" ) |
84 | |
85 | private: |
86 | mutable RID _texture; |
87 | Ref<Curve> _curve_x; |
88 | Ref<Curve> _curve_y; |
89 | Ref<Curve> _curve_z; |
90 | int _width = 256; |
91 | int _current_width = 0; |
92 | |
93 | void _update(); |
94 | |
95 | protected: |
96 | static void _bind_methods(); |
97 | |
98 | public: |
99 | void set_width(int p_width); |
100 | int get_width() const override; |
101 | |
102 | void ensure_default_setup(float p_min = 0, float p_max = 1); |
103 | |
104 | void set_curve_x(Ref<Curve> p_curve); |
105 | Ref<Curve> get_curve_x() const; |
106 | |
107 | void set_curve_y(Ref<Curve> p_curve); |
108 | Ref<Curve> get_curve_y() const; |
109 | |
110 | void set_curve_z(Ref<Curve> p_curve); |
111 | Ref<Curve> get_curve_z() const; |
112 | |
113 | virtual RID get_rid() const override; |
114 | |
115 | virtual int get_height() const override { return 1; } |
116 | virtual bool has_alpha() const override { return false; } |
117 | |
118 | CurveXYZTexture(); |
119 | ~CurveXYZTexture(); |
120 | }; |
121 | |
122 | #endif // CURVE_TEXTURE_H |
123 | |