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

123 lines
2.8 KiB

  1. /*
  2. * Copyright (C) 2021 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 <array>
  22. namespace gl {
  23. class rasterizer;
  24. class texture_2d;
  25. enum class framebuffer_attachment_type
  26. {
  27. color,
  28. depth,
  29. stencil
  30. };
  31. class framebuffer
  32. {
  33. public:
  34. /**
  35. * Creates a framebuffer.
  36. */
  37. framebuffer(int width, int height);
  38. /// Destroys a framebuffer.
  39. ~framebuffer();
  40. /**
  41. * Resizes the framebuffer. Note: This does not resize any attached textures.
  42. *
  43. * @param width New width of the framebuffer.
  44. * @param height New height of the framebuffer.
  45. */
  46. void resize(const std::array<int, 2>& dimensions);
  47. /**
  48. * Attaches a color, depth, or stencil texture to the framebuffer.
  49. *
  50. * @param attachment_type Type of attachment.
  51. */
  52. void attach(framebuffer_attachment_type attachment_type, texture_2d* texture);
  53. /// Returns the dimensions of the framebuffer, in pixels.
  54. const std::array<int, 2>& get_dimensions() const;
  55. const texture_2d* get_color_attachment() const;
  56. texture_2d* get_color_attachment();
  57. const texture_2d* get_depth_attachment() const;
  58. texture_2d* get_depth_attachment();
  59. const texture_2d* get_stencil_attachment() const;
  60. texture_2d* get_stencil_attachment();
  61. private:
  62. friend class rasterizer;
  63. framebuffer();
  64. unsigned int gl_framebuffer_id;
  65. std::array<int, 2> dimensions;
  66. texture_2d* color_attachment;
  67. texture_2d* depth_attachment;
  68. texture_2d* stencil_attachment;
  69. };
  70. inline const std::array<int, 2>& framebuffer::get_dimensions() const
  71. {
  72. return dimensions;
  73. }
  74. inline const texture_2d* framebuffer::get_color_attachment() const
  75. {
  76. return color_attachment;
  77. }
  78. inline texture_2d* framebuffer::get_color_attachment()
  79. {
  80. return color_attachment;
  81. }
  82. inline const texture_2d* framebuffer::get_depth_attachment() const
  83. {
  84. return depth_attachment;
  85. }
  86. inline texture_2d* framebuffer::get_depth_attachment()
  87. {
  88. return depth_attachment;
  89. }
  90. inline const texture_2d* framebuffer::get_stencil_attachment() const
  91. {
  92. return stencil_attachment;
  93. }
  94. inline texture_2d* framebuffer::get_stencil_attachment()
  95. {
  96. return stencil_attachment;
  97. }
  98. } // namespace gl
  99. #endif // ANTKEEPER_GL_FRAMEBUFFER_HPP