Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/curve_texture.h
21521 views
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
#pragma once
32
33
#include "scene/resources/curve.h"
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
};
77
78
VARIANT_ENUM_CAST(CurveTexture::TextureMode)
79
80
class CurveXYZTexture : public Texture2D {
81
GDCLASS(CurveXYZTexture, Texture2D);
82
RES_BASE_EXTENSION("curvetex")
83
84
private:
85
mutable RID _texture;
86
Ref<Curve> _curve_x;
87
Ref<Curve> _curve_y;
88
Ref<Curve> _curve_z;
89
int _width = 256;
90
int _current_width = 0;
91
92
void _update();
93
94
protected:
95
static void _bind_methods();
96
97
public:
98
void set_width(int p_width);
99
int get_width() const override;
100
101
void ensure_default_setup(float p_min = 0, float p_max = 1);
102
103
void set_curve_x(Ref<Curve> p_curve);
104
Ref<Curve> get_curve_x() const;
105
106
void set_curve_y(Ref<Curve> p_curve);
107
Ref<Curve> get_curve_y() const;
108
109
void set_curve_z(Ref<Curve> p_curve);
110
Ref<Curve> get_curve_z() const;
111
112
virtual RID get_rid() const override;
113
114
virtual int get_height() const override { return 1; }
115
virtual bool has_alpha() const override { return false; }
116
117
~CurveXYZTexture();
118
};
119
120