DebugRenderer.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "Types.h"
  25. #include "Vec3.h"
  26. #include "Color4.h"
  27. #include "Mat4.h"
  28. namespace crown
  29. {
  30. const uint32_t MAX_DEBUG_LINES = 4096;
  31. class Renderer;
  32. /// Util class to render various types of primiteves
  33. /// for debugging purposes only.
  34. /// @note
  35. /// All the coordinates are in world-space.
  36. class DebugRenderer
  37. {
  38. public:
  39. DebugRenderer(Renderer& renderer);
  40. ~DebugRenderer();
  41. void add_line(const Vec3& start, const Vec3& end, const Color4& color, bool depth_write);
  42. /// Total cost: 72 lines
  43. void add_sphere(const Vec3& center, const float radius, const Color4& color, bool depth_write);
  44. /// Total cost: 12 lines
  45. void add_box(const Vec3& min, const Vec3& max, const Color4& color, bool depth_write);
  46. /// Total cost: 3 lines
  47. void add_pose(const Mat4& pose, bool depth_write);
  48. private:
  49. void draw_all();
  50. private:
  51. Renderer& m_renderer;
  52. uint32_t m_lines_count;
  53. Vec3 m_lines[MAX_DEBUG_LINES * 2];
  54. Color4 m_colors[MAX_DEBUG_LINES * 2];
  55. bool m_depth_writes[MAX_DEBUG_LINES * 2];
  56. friend class Device;
  57. };
  58. } // namespace crown