💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.7 KiB

  1. /*
  2. * Copyright (C) 2020 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_TEXTURE_2D_HPP
  20. #define ANTKEEPER_TEXTURE_2D_HPP
  21. #include <tuple>
  22. #include "rasterizer/pixel-format.hpp"
  23. #include "rasterizer/pixel-type.hpp"
  24. class framebuffer;
  25. class shader_input;
  26. enum class texture_mag_filter;
  27. enum class texture_min_filter;
  28. enum class texture_wrapping;
  29. /**
  30. * A 2D texture which can be uploaded to shaders via shader inputs.
  31. */
  32. class texture_2d
  33. {
  34. public:
  35. /**
  36. * Creates a 2D texture.
  37. */
  38. texture_2d(int width, int height, ::pixel_type type = ::pixel_type::uint_8, ::pixel_format format = ::pixel_format::rgba, const void* data = nullptr);
  39. /**
  40. * Destroys a 2D texture.
  41. */
  42. ~texture_2d();
  43. /**
  44. * Resizes the texture.
  45. */
  46. void resize(int width, int height, ::pixel_type type, ::pixel_format format, const void* data);
  47. /**
  48. * Sets the texture wrapping modes.
  49. *
  50. * @param wrap_s Wrapping mode for s-coordinates.
  51. * @param wrap_t Wrapping mode for t-coordinates.
  52. */
  53. void set_wrapping(texture_wrapping wrap_s, texture_wrapping wrap_t);
  54. /**
  55. * Sets the texture filtering modes.
  56. *
  57. * @param min_filter Texture minification filter.
  58. * @param mag_filter Texture magnification filter.
  59. */
  60. void set_filters(texture_min_filter min_filter, texture_mag_filter mag_filter);
  61. /**
  62. * Sets the maximum anisotropy.
  63. *
  64. * @param level Max anisotropy on `[0.0, 1.0]`, with `0.0` indicating normal filtering, and `1.0` indicating maximum anisotropic filtering.
  65. */
  66. void set_max_anisotropy(float anisotropy);
  67. /// Returns the dimensions of the texture, in pixels.
  68. const std::tuple<int, int>& get_dimensions() const;
  69. /// Returns the pixel type enumeration.
  70. const pixel_type& get_pixel_type() const;
  71. /// Returns the pixel format enumeration.
  72. const pixel_format& get_pixel_format() const;
  73. /// Returns the wrapping modes of the texture.
  74. const std::tuple<texture_wrapping, texture_wrapping> get_wrapping() const;
  75. /// Returns the filtering modes of the texture.
  76. const std::tuple<texture_min_filter, texture_mag_filter> get_filters() const;
  77. /// Returs the maximum anisotropy.
  78. float get_max_anisotropy() const;
  79. private:
  80. friend class framebuffer;
  81. friend class shader_input;
  82. unsigned int gl_texture_id;
  83. std::tuple<int, int> dimensions;
  84. ::pixel_type pixel_type;
  85. ::pixel_format pixel_format;
  86. std::tuple<texture_wrapping, texture_wrapping> wrapping;
  87. std::tuple<texture_min_filter, texture_mag_filter> filters;
  88. float max_anisotropy;
  89. };
  90. inline const std::tuple<int, int>& texture_2d::get_dimensions() const
  91. {
  92. return dimensions;
  93. }
  94. inline const pixel_type& texture_2d::get_pixel_type() const
  95. {
  96. return pixel_type;
  97. }
  98. inline const pixel_format& texture_2d::get_pixel_format() const
  99. {
  100. return pixel_format;
  101. }
  102. inline const std::tuple<texture_wrapping, texture_wrapping> texture_2d::get_wrapping() const
  103. {
  104. return wrapping;
  105. }
  106. inline const std::tuple<texture_min_filter, texture_mag_filter> texture_2d::get_filters() const
  107. {
  108. return filters;
  109. }
  110. inline float texture_2d::get_max_anisotropy() const
  111. {
  112. return max_anisotropy;
  113. }
  114. #endif // ANTKEEPER_TEXTURE_2D_HPP