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

94 lines
2.5 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_FRAMEBUFFER_HPP
  20. #define ANTKEEPER_GL_FRAMEBUFFER_HPP
  21. #include <engine/gl/framebuffer-attachment.hpp>
  22. #include <engine/gl/framebuffer-usage-bits.hpp>
  23. #include <array>
  24. #include <cstdint>
  25. #include <span>
  26. #include <vector>
  27. namespace gl {
  28. /**
  29. *
  30. */
  31. class framebuffer
  32. {
  33. public:
  34. /**
  35. * Constructs a framebuffer.
  36. *
  37. * @param attachments Framebuffer attachments.
  38. * @param width Width of the framebuffer.
  39. * @param height Height of the framebuffer.
  40. */
  41. framebuffer(std::span<const framebuffer_attachment> attachments, std::uint32_t width, std::uint32_t height);
  42. /// Destroys a framebuffer.
  43. ~framebuffer();
  44. /**
  45. * Resizes the framebuffer.
  46. *
  47. * @param width New width of the framebuffer.
  48. * @param height New height of the framebuffer.
  49. *
  50. * @warning Does not resize framebuffer attachments.
  51. */
  52. void resize(std::uint32_t width, std::uint32_t height);
  53. /// Returns the framebuffer attachments.
  54. [[nodiscard]] inline constexpr const std::vector<framebuffer_attachment>& attachments() const noexcept
  55. {
  56. return m_attachments;
  57. }
  58. /// Returns the dimensions of the framebuffer.
  59. [[nodiscard]] inline constexpr const std::array<std::uint32_t, 2>& dimensions() const noexcept
  60. {
  61. return m_dimensions;
  62. }
  63. /// Returns the width of the framebuffer.
  64. [[nodiscard]] inline constexpr std::uint32_t width() const noexcept
  65. {
  66. return m_dimensions[0];
  67. }
  68. /// Returns the height of the framebuffer.
  69. [[nodiscard]] inline constexpr std::uint32_t height() const noexcept
  70. {
  71. return m_dimensions[1];
  72. }
  73. private:
  74. friend class pipeline;
  75. std::vector<framebuffer_attachment> m_attachments;
  76. std::array<std::uint32_t, 2> m_dimensions{0, 0};
  77. unsigned int m_gl_named_framebuffer{0};
  78. };
  79. } // namespace gl
  80. #endif // ANTKEEPER_GL_FRAMEBUFFER_HPP