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

92 lines
3.2 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_CUBE_HPP
  20. #define ANTKEEPER_GL_TEXTURE_CUBE_HPP
  21. #include <engine/gl/texture.hpp>
  22. #include <engine/gl/cube-map-layout.hpp>
  23. namespace gl {
  24. /**
  25. * A cube texture which can be uploaded to shaders via shader inputs.
  26. */
  27. class texture_cube: public texture
  28. {
  29. public:
  30. /**
  31. * Infers the layout of a cube map from its aspect ratio.
  32. *
  33. * @param w Width of the cube map, in pixels.
  34. * @param h Height of the cube map, in pixels.
  35. *
  36. * @return Inferred cube map layout.
  37. */
  38. [[nodiscard]] static cube_map_layout infer_cube_map_layout(std::uint16_t w, std::uint16_t h) noexcept;
  39. /**
  40. * Infers the edge length of a cube map face from its layout and resolution.
  41. *
  42. * @param layout Layout of the cube map.
  43. * @param w Width of the cube map, in pixels.
  44. * @param h Height of the cube map, in pixels.
  45. *
  46. * @return Edge length of the cube map faces, in pixels.
  47. */
  48. [[nodiscard]] static std::uint16_t infer_cube_map_face_size(cube_map_layout layout, std::uint16_t w, std::uint16_t h) noexcept;
  49. /// Constructs a cube texture.
  50. texture_cube(std::uint16_t width, std::uint16_t height, gl::pixel_type type = gl::pixel_type::uint_8, gl::pixel_format format = gl::pixel_format::rgba, gl::transfer_function transfer_function = gl::transfer_function::linear, const std::byte* data = nullptr);
  51. [[nodiscard]] inline constexpr texture_type get_texture_type() const noexcept override
  52. {
  53. return texture_type::cube;
  54. }
  55. /// @copydoc texture::resize(std::uint16_t, std::uint16_t, gl::pixel_type, gl::pixel_format, gl::transfer_function, const std::byte*)
  56. void resize(std::uint16_t width, std::uint16_t height, gl::pixel_type type, gl::pixel_format format, gl::transfer_function transfer_function, const std::byte* data) override;
  57. /**
  58. * Resizes the texture.
  59. *
  60. * @param width Texture width, in pixels.
  61. * @param height Texture height, in pixels.
  62. * @param data Pointer to pixel data.
  63. */
  64. void resize(std::uint16_t width, std::uint16_t height, const std::byte* data);
  65. /// @copydoc texture::set_wrapping(gl::texture_wrapping, gl::texture_wrapping, gl::texture_wrapping)
  66. virtual void set_wrapping(gl::texture_wrapping wrap_s, texture_wrapping wrap_t, texture_wrapping wrap_r);
  67. /// Returns the edge length of the cube texture faces, in pixels.
  68. [[nodiscard]] inline std::uint16_t get_face_size() const noexcept
  69. {
  70. return m_face_size;
  71. }
  72. private:
  73. void resized();
  74. std::uint16_t m_face_size{};
  75. };
  76. } // namespace gl
  77. #endif // ANTKEEPER_GL_TEXTURE_CUBE_HPP