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

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