💿🐜 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.

309 lines
6.6 KiB

  1. /*
  2. * Copyright (C) 2023 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_GL_TEXTURE_HPP
  20. #define ANTKEEPER_GL_TEXTURE_HPP
  21. #include <engine/gl/image-view.hpp>
  22. #include <engine/gl/sampler.hpp>
  23. #include <memory>
  24. namespace gl {
  25. /**
  26. * Image view and sampler object pair.
  27. */
  28. class texture
  29. {
  30. public:
  31. /**
  32. * Constructs a texture.
  33. *
  34. * @param image_view Texture image view.
  35. * @param sampler Texture sampler.
  36. */
  37. /// @{
  38. inline texture(std::shared_ptr<gl::sampler> sampler) noexcept:
  39. m_sampler(sampler)
  40. {}
  41. constexpr texture() noexcept = default;
  42. /// @}
  43. /**
  44. * Sets the sampler object.
  45. *
  46. * @param sampler Sampler object.
  47. */
  48. inline void set_sampler(std::shared_ptr<gl::sampler> sampler)
  49. {
  50. m_sampler = sampler;
  51. }
  52. /// Returns the sampler object.
  53. [[nodiscard]] inline constexpr const std::shared_ptr<sampler>& get_sampler() const noexcept
  54. {
  55. return m_sampler;
  56. }
  57. private:
  58. std::shared_ptr<sampler> m_sampler;
  59. };
  60. /**
  61. * 1D texture.
  62. */
  63. class texture_1d: public texture
  64. {
  65. public:
  66. /// @copydoc texture::texture
  67. /// @{
  68. inline texture_1d(std::shared_ptr<image_view_1d> image_view, std::shared_ptr<gl::sampler> sampler) noexcept:
  69. texture(sampler),
  70. m_image_view(image_view)
  71. {}
  72. constexpr texture_1d() noexcept = default;
  73. /// @}
  74. /**
  75. * Sets the image view.
  76. */
  77. inline void set_image_view(std::shared_ptr<gl::image_view_1d> image_view)
  78. {
  79. m_image_view = image_view;
  80. }
  81. /// Returns the image view.
  82. [[nodiscard]] inline constexpr const std::shared_ptr<image_view_1d>& get_image_view() const noexcept
  83. {
  84. return m_image_view;
  85. }
  86. private:
  87. std::shared_ptr<image_view_1d> m_image_view;
  88. };
  89. /**
  90. * 1D texture array.
  91. */
  92. class texture_1d_array: public texture
  93. {
  94. public:
  95. /// @copydoc texture::texture
  96. /// @{
  97. inline texture_1d_array(std::shared_ptr<image_view_1d_array> image_view, std::shared_ptr<gl::sampler> sampler) noexcept:
  98. texture(sampler),
  99. m_image_view(image_view)
  100. {}
  101. constexpr texture_1d_array() noexcept = default;
  102. /// @}
  103. /**
  104. * Sets the image view.
  105. */
  106. inline void set_image_view(std::shared_ptr<gl::image_view_1d_array> image_view)
  107. {
  108. m_image_view = image_view;
  109. }
  110. /// Returns the image view.
  111. [[nodiscard]] inline constexpr const std::shared_ptr<image_view_1d_array>& get_image_view() const noexcept
  112. {
  113. return m_image_view;
  114. }
  115. private:
  116. std::shared_ptr<image_view_1d_array> m_image_view;
  117. };
  118. /**
  119. * 2D texture.
  120. */
  121. class texture_2d: public texture
  122. {
  123. public:
  124. /// @copydoc texture::texture
  125. /// @{
  126. inline texture_2d(std::shared_ptr<image_view_2d> image_view, std::shared_ptr<gl::sampler> sampler) noexcept:
  127. texture(sampler),
  128. m_image_view(image_view)
  129. {}
  130. constexpr texture_2d() noexcept = default;
  131. /// @}
  132. /**
  133. * Sets the image view.
  134. */
  135. inline void set_image_view(std::shared_ptr<gl::image_view_2d> image_view)
  136. {
  137. m_image_view = image_view;
  138. }
  139. /// Returns the image view.
  140. [[nodiscard]] inline constexpr const std::shared_ptr<image_view_2d>& get_image_view() const noexcept
  141. {
  142. return m_image_view;
  143. }
  144. private:
  145. std::shared_ptr<image_view_2d> m_image_view;
  146. };
  147. /**
  148. * 2D texture array.
  149. */
  150. class texture_2d_array: public texture
  151. {
  152. public:
  153. /// @copydoc texture::texture
  154. /// @{
  155. inline texture_2d_array(std::shared_ptr<image_view_2d_array> image_view, std::shared_ptr<gl::sampler> sampler) noexcept:
  156. texture(sampler),
  157. m_image_view(image_view)
  158. {}
  159. constexpr texture_2d_array() noexcept = default;
  160. /// @}
  161. /**
  162. * Sets the image view.
  163. */
  164. inline void set_image_view(std::shared_ptr<gl::image_view_2d_array> image_view)
  165. {
  166. m_image_view = image_view;
  167. }
  168. /// Returns the image view.
  169. [[nodiscard]] inline constexpr const std::shared_ptr<image_view_2d_array>& get_image_view() const noexcept
  170. {
  171. return m_image_view;
  172. }
  173. private:
  174. std::shared_ptr<image_view_2d_array> m_image_view;
  175. };
  176. /**
  177. * 3D texture.
  178. */
  179. class texture_3d: public texture
  180. {
  181. public:
  182. /// @copydoc texture::texture
  183. /// @{
  184. inline texture_3d(std::shared_ptr<image_view_3d> image_view, std::shared_ptr<gl::sampler> sampler) noexcept:
  185. texture(sampler),
  186. m_image_view(image_view)
  187. {}
  188. constexpr texture_3d() noexcept = default;
  189. /// @}
  190. /**
  191. * Sets the image view.
  192. */
  193. inline void set_image_view(std::shared_ptr<gl::image_view_3d> image_view)
  194. {
  195. m_image_view = image_view;
  196. }
  197. /// Returns the image view.
  198. [[nodiscard]] inline constexpr const std::shared_ptr<image_view_3d>& get_image_view() const noexcept
  199. {
  200. return m_image_view;
  201. }
  202. private:
  203. std::shared_ptr<image_view_3d> m_image_view;
  204. };
  205. /**
  206. * Cube texture.
  207. */
  208. class texture_cube: public texture
  209. {
  210. public:
  211. /// @copydoc texture::texture
  212. /// @{
  213. inline texture_cube(std::shared_ptr<image_view_cube> image_view, std::shared_ptr<gl::sampler> sampler) noexcept:
  214. texture(sampler),
  215. m_image_view(image_view)
  216. {}
  217. constexpr texture_cube() noexcept = default;
  218. /// @}
  219. /**
  220. * Sets the image view.
  221. */
  222. inline void set_image_view(std::shared_ptr<gl::image_view_cube> image_view)
  223. {
  224. m_image_view = image_view;
  225. }
  226. /// Returns the image view.
  227. [[nodiscard]] inline constexpr const std::shared_ptr<image_view_cube>& get_image_view() const noexcept
  228. {
  229. return m_image_view;
  230. }
  231. private:
  232. std::shared_ptr<image_view_cube> m_image_view;
  233. };
  234. /**
  235. * Cube texture array.
  236. */
  237. class texture_cube_array: public texture
  238. {
  239. public:
  240. /// @copydoc texture::texture
  241. /// @{
  242. inline texture_cube_array(std::shared_ptr<image_view_cube_array> image_view, std::shared_ptr<gl::sampler> sampler) noexcept:
  243. texture(sampler),
  244. m_image_view(image_view)
  245. {}
  246. constexpr texture_cube_array() noexcept = default;
  247. /// @}
  248. /**
  249. * Sets the image view.
  250. */
  251. inline void set_image_view(std::shared_ptr<gl::image_view_cube_array> image_view)
  252. {
  253. m_image_view = image_view;
  254. }
  255. /// Returns the image view.
  256. [[nodiscard]] inline constexpr const std::shared_ptr<image_view_cube_array>& get_image_view() const noexcept
  257. {
  258. return m_image_view;
  259. }
  260. private:
  261. std::shared_ptr<image_view_cube_array> m_image_view;
  262. };
  263. } // namespace gl
  264. #endif // ANTKEEPER_GL_TEXTURE_HPP