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

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