texture.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**************************************************************************/
  2. /* 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 TEXTURE_H
  31. #define TEXTURE_H
  32. #include "core/io/file_access.h"
  33. #include "core/io/resource.h"
  34. #include "core/io/resource_loader.h"
  35. #include "core/math/rect2.h"
  36. #include "core/os/mutex.h"
  37. #include "core/os/rw_lock.h"
  38. #include "core/os/thread_safe.h"
  39. #include "scene/resources/curve.h"
  40. #include "scene/resources/gradient.h"
  41. #include "servers/camera_server.h"
  42. #include "servers/rendering_server.h"
  43. class Texture : public Resource {
  44. GDCLASS(Texture, Resource);
  45. public:
  46. Texture() {}
  47. };
  48. class Texture2D : public Texture {
  49. GDCLASS(Texture2D, Texture);
  50. OBJ_SAVE_TYPE(Texture2D); // Saves derived classes with common type so they can be interchanged.
  51. protected:
  52. static void _bind_methods();
  53. GDVIRTUAL0RC_REQUIRED(int, _get_width)
  54. GDVIRTUAL0RC_REQUIRED(int, _get_height)
  55. GDVIRTUAL2RC(bool, _is_pixel_opaque, int, int)
  56. GDVIRTUAL0RC(bool, _has_alpha)
  57. GDVIRTUAL4C(_draw, RID, Point2, Color, bool)
  58. GDVIRTUAL5C(_draw_rect, RID, Rect2, bool, Color, bool)
  59. GDVIRTUAL6C(_draw_rect_region, RID, Rect2, Rect2, Color, bool, bool)
  60. public:
  61. virtual int get_width() const;
  62. virtual int get_height() const;
  63. virtual Size2 get_size() const;
  64. virtual bool is_pixel_opaque(int p_x, int p_y) const;
  65. virtual bool has_alpha() const;
  66. virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false) const;
  67. 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;
  68. 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;
  69. virtual bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
  70. virtual Ref<Image> get_image() const { return Ref<Image>(); }
  71. virtual Ref<Resource> create_placeholder() const;
  72. Texture2D();
  73. };
  74. class TextureLayered : public Texture {
  75. GDCLASS(TextureLayered, Texture);
  76. protected:
  77. static void _bind_methods();
  78. GDVIRTUAL0RC_REQUIRED(Image::Format, _get_format)
  79. GDVIRTUAL0RC_REQUIRED(uint32_t, _get_layered_type)
  80. GDVIRTUAL0RC_REQUIRED(int, _get_width)
  81. GDVIRTUAL0RC_REQUIRED(int, _get_height)
  82. GDVIRTUAL0RC_REQUIRED(int, _get_layers)
  83. GDVIRTUAL0RC_REQUIRED(bool, _has_mipmaps)
  84. GDVIRTUAL1RC_REQUIRED(Ref<Image>, _get_layer_data, int)
  85. public:
  86. enum LayeredType {
  87. LAYERED_TYPE_2D_ARRAY,
  88. LAYERED_TYPE_CUBEMAP,
  89. LAYERED_TYPE_CUBEMAP_ARRAY
  90. };
  91. virtual Image::Format get_format() const;
  92. virtual LayeredType get_layered_type() const;
  93. virtual int get_width() const;
  94. virtual int get_height() const;
  95. virtual int get_layers() const;
  96. virtual bool has_mipmaps() const;
  97. virtual Ref<Image> get_layer_data(int p_layer) const;
  98. TextureLayered() {}
  99. };
  100. VARIANT_ENUM_CAST(TextureLayered::LayeredType)
  101. class Texture3D : public Texture {
  102. GDCLASS(Texture3D, Texture);
  103. protected:
  104. static void _bind_methods();
  105. TypedArray<Image> _get_datai() const;
  106. GDVIRTUAL0RC_REQUIRED(Image::Format, _get_format)
  107. GDVIRTUAL0RC_REQUIRED(int, _get_width)
  108. GDVIRTUAL0RC_REQUIRED(int, _get_height)
  109. GDVIRTUAL0RC_REQUIRED(int, _get_depth)
  110. GDVIRTUAL0RC_REQUIRED(bool, _has_mipmaps)
  111. GDVIRTUAL0RC_REQUIRED(TypedArray<Image>, _get_data)
  112. public:
  113. virtual Image::Format get_format() const;
  114. virtual int get_width() const;
  115. virtual int get_height() const;
  116. virtual int get_depth() const;
  117. virtual bool has_mipmaps() const;
  118. virtual Vector<Ref<Image>> get_data() const;
  119. virtual Ref<Resource> create_placeholder() const;
  120. };
  121. #endif // TEXTURE_H