curve_texture.h 4.1 KB

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