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

92 lines
2.7 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. #include <engine/render/renderer.hpp>
  20. #include <engine/render/context.hpp>
  21. #include <engine/render/compositor.hpp>
  22. #include <engine/scene/collection.hpp>
  23. #include <engine/scene/camera.hpp>
  24. #include <engine/scene/static-mesh.hpp>
  25. #include <engine/scene/billboard.hpp>
  26. #include <engine/scene/light-probe.hpp>
  27. #include <engine/scene/text.hpp>
  28. #include <engine/render/model.hpp>
  29. #include <engine/gl/drawing-mode.hpp>
  30. #include <engine/math/matrix.hpp>
  31. #include <engine/geom/projection.hpp>
  32. #include <engine/config.hpp>
  33. #include <engine/math/quaternion.hpp>
  34. #include <engine/math/numbers.hpp>
  35. #include <functional>
  36. #include <set>
  37. namespace render {
  38. renderer::renderer(gl::rasterizer& rasterizer, ::resource_manager& resource_manager)
  39. {
  40. m_light_probe_stage = std::make_unique<render::light_probe_stage>(rasterizer, resource_manager);
  41. m_culling_stage = std::make_unique<render::culling_stage>();
  42. m_queue_stage = std::make_unique<render::queue_stage>();
  43. }
  44. void renderer::render(float t, float dt, float alpha, scene::collection& collection)
  45. {
  46. // Init render context
  47. m_ctx.collection = &collection;
  48. m_ctx.t = t;
  49. m_ctx.dt = dt;
  50. m_ctx.alpha = alpha;
  51. // Execute light probe stage
  52. m_light_probe_stage->execute(m_ctx);
  53. // Get list of cameras to be sorted
  54. const auto& cameras = collection.get_objects(scene::camera::object_type_id);
  55. // Process cameras in order
  56. for (scene::object_base* camera_object: cameras)
  57. {
  58. scene::camera& camera = static_cast<scene::camera&>(*camera_object);
  59. // Skip cameras with no compositors
  60. compositor* compositor = camera.get_compositor();
  61. if (!compositor)
  62. {
  63. continue;
  64. }
  65. // Update render context camera
  66. m_ctx.camera = &camera;
  67. // Clear render queues
  68. m_ctx.objects.clear();
  69. m_ctx.operations.clear();
  70. // Execute culling stage
  71. m_culling_stage->execute(m_ctx);
  72. // Execute queue stage
  73. m_queue_stage->execute(m_ctx);
  74. // Pass render context to the camera's compositor
  75. compositor->composite(m_ctx);
  76. }
  77. }
  78. } // namespace render