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

82 lines
2.3 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. #include "render/passes/clear-pass.hpp"
  20. #include "gl/rasterizer.hpp"
  21. #include "gl/framebuffer.hpp"
  22. #include <glad/glad.h>
  23. namespace render {
  24. clear_pass::clear_pass(gl::rasterizer* rasterizer, const gl::framebuffer* framebuffer):
  25. pass(rasterizer, framebuffer),
  26. clear_color_buffer(false),
  27. clear_depth_buffer(false),
  28. clear_stencil_buffer(false),
  29. clear_color({0.0f, 0.0f, 0.0f, 0.0f}),
  30. clear_depth(1.0f),
  31. clear_stencil(0)
  32. {}
  33. clear_pass::~clear_pass()
  34. {}
  35. void clear_pass::render(const render::context& ctx, render::queue& queue) const
  36. {
  37. if (clear_color_buffer)
  38. glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
  39. if (clear_depth_buffer)
  40. glDepthMask(GL_TRUE);
  41. if (clear_stencil_buffer)
  42. glStencilMask(0xFF);
  43. rasterizer->use_framebuffer(*framebuffer);
  44. auto viewport = framebuffer->get_dimensions();
  45. rasterizer->set_viewport(0, 0, std::get<0>(viewport), std::get<1>(viewport));
  46. rasterizer->set_clear_color(clear_color[0], clear_color[1], clear_color[2], clear_color[3]);
  47. rasterizer->set_clear_depth(clear_depth);
  48. rasterizer->set_clear_stencil(clear_stencil);
  49. rasterizer->clear_framebuffer(clear_color_buffer, clear_depth_buffer, clear_stencil_buffer);
  50. }
  51. void clear_pass::set_cleared_buffers(bool color, bool depth, bool stencil)
  52. {
  53. clear_color_buffer = color;
  54. clear_depth_buffer = depth;
  55. clear_stencil_buffer = stencil;
  56. }
  57. void clear_pass::set_clear_color(const float4& color)
  58. {
  59. clear_color = color;
  60. }
  61. void clear_pass::set_clear_depth(float depth)
  62. {
  63. clear_depth = depth;
  64. }
  65. void clear_pass::set_clear_stencil(int stencil)
  66. {
  67. clear_stencil = stencil;
  68. }
  69. } // namespace render