noise_texture.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*************************************************************************/
  2. /* noise_texture.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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 NOISE_TEXTURE_H
  31. #define NOISE_TEXTURE_H
  32. #include "open_simplex_noise.h"
  33. #include "core/image.h"
  34. #include "core/reference.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_plugin.h"
  37. #include "editor/property_editor.h"
  38. class NoiseTexture : public Texture {
  39. GDCLASS(NoiseTexture, Texture)
  40. private:
  41. Ref<Image> data;
  42. Thread *noise_thread;
  43. bool first_time;
  44. bool update_queued;
  45. bool regen_queued;
  46. RID texture;
  47. uint32_t flags;
  48. Ref<OpenSimplexNoise> noise;
  49. Vector2i size;
  50. bool seamless;
  51. bool as_normalmap;
  52. void _thread_done(const Ref<Image> &p_image);
  53. static void _thread_function(void *p_ud);
  54. void _queue_update();
  55. Ref<Image> _generate_texture();
  56. void _update_texture();
  57. void _set_texture_data(const Ref<Image> &p_image);
  58. protected:
  59. static void _bind_methods();
  60. public:
  61. void set_noise(Ref<OpenSimplexNoise> p_noise);
  62. Ref<OpenSimplexNoise> get_noise();
  63. void set_width(int p_width);
  64. void set_height(int p_hieght);
  65. void set_seamless(bool p_seamless);
  66. bool get_seamless();
  67. void set_as_normalmap(bool p_seamless);
  68. bool is_normalmap();
  69. int get_width() const;
  70. int get_height() const;
  71. virtual void set_flags(uint32_t p_flags);
  72. virtual uint32_t get_flags() const;
  73. virtual RID get_rid() const { return texture; }
  74. virtual bool has_alpha() const { return false; }
  75. virtual Ref<Image> get_data() const;
  76. NoiseTexture();
  77. virtual ~NoiseTexture();
  78. };
  79. #endif // NOISE_TEXTURE_H