DebugRenderer.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #ifndef RENDERER_DEBUGRENDERER_H
  24. #define RENDERER_DEBUGRENDERER_H
  25. #include "Color.h"
  26. #include "EventListener.h"
  27. #include "Matrix4.h"
  28. #include "SceneExtension.h"
  29. #include "SharedPtr.h"
  30. #include <vector>
  31. class BoundingBox;
  32. class Camera;
  33. class Frustum;
  34. class GeometryNode;
  35. class Light;
  36. class Matrix4x3;
  37. class Pipeline;
  38. class Skeleton;
  39. //! Debug rendering line
  40. struct DebugLine
  41. {
  42. //! Construct as undefined
  43. DebugLine()
  44. {
  45. }
  46. //! Construct with start and end positions and color
  47. DebugLine(const Vector3& start, const Vector3& end, unsigned color) :
  48. mStart(start),
  49. mEnd(end),
  50. mColor(color)
  51. {
  52. }
  53. //! Start position
  54. Vector3 mStart;
  55. //! End position
  56. Vector3 mEnd;
  57. //! Color
  58. unsigned mColor;
  59. };
  60. //! Debug geometry renderer
  61. class DebugRenderer : public SceneExtension, public EventListener
  62. {
  63. DEFINE_TYPE(DebugRenderer);
  64. public:
  65. //! Construct
  66. DebugRenderer();
  67. //! Add a line
  68. void addLine(const Vector3& start, const Vector3& end, const Color& color, bool depthTest = true);
  69. //! Add a bounding box
  70. void addBoundingBox(const BoundingBox& box, const Color& color, bool depthTest = true);
  71. //! Add a bounding box with transform
  72. void addBoundingBox(const BoundingBox& box, const Matrix4x3& transform, const Color& color, bool depthTest = true);
  73. //! Add a frustum
  74. void addFrustum(const Frustum& frustum, const Color& color, bool depthTest = true);
  75. //! Add a skeleton
  76. void addSkeleton(const Skeleton& skeleton, const Color& color, bool depthTest = true);
  77. //! Render all debug lines from a specific camera. The viewport and rendertarget should be set before
  78. void render(Pipeline* pipeline, Camera* camera);
  79. private:
  80. //! Handle end of frame. Clear debug geometry
  81. void handleEndFrame(StringHash eventType, VariantMap& eventData);
  82. //! Lines rendered with depth test
  83. std::vector<DebugLine> mLines;
  84. //! Lines rendered without depth test
  85. std::vector<DebugLine> mNoDepthLines;
  86. };
  87. #endif // RENDERR_DEBUGGEOMETRY_H