texture.h 5.5 KB

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