duDebugDrawTorque.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _DU_DEBUG_DRAW_TORQUE_H_
  23. #define _DU_DEBUG_DRAW_TORQUE_H_
  24. #ifndef _TVECTOR_H_
  25. #include "core/util/tVector.h"
  26. #endif
  27. #include <DebugDraw.h>
  28. #ifndef _GFXSTATEBLOCK_H_
  29. #include "gfx/gfxStateBlock.h"
  30. #endif
  31. #ifndef _GFXVERTEXTYPES_H_
  32. #include "gfx/gfxVertexTypes.h"
  33. #endif
  34. #ifndef _GFXVERTEXBUFFER_H_
  35. #include "gfx/gfxVertexBuffer.h"
  36. #endif
  37. #ifndef _SCENERENDERSTATE_H_
  38. #include "scene/sceneRenderState.h"
  39. #endif
  40. /**
  41. * @class duDebugDrawTorque
  42. * @brief Implements the duDebugDraw interface in Torque.
  43. *
  44. * Every debug draw from recast goes through a process of begin, add vertex and then end
  45. * just like our primbuilder class, but we need to catch these vertices
  46. * and add them to a GFXVertexBuffer as recast supports GL_QUADS which is now
  47. * deprecated.
  48. */
  49. class duDebugDrawTorque : public duDebugDraw {
  50. public:
  51. duDebugDrawTorque();
  52. ~duDebugDrawTorque();
  53. /// Enable/disable Z read.
  54. void depthMask(bool state) override;
  55. /// <summary>
  56. /// Enable/disable Z read and overrides any setting that will come from detour.
  57. /// </summary>
  58. /// <param name="state">Z read state.</param>
  59. /// <param name="isOverride">Set to true to override any future changes.</param>
  60. void depthMask(bool state, bool isOverride);
  61. void blend(bool blend);
  62. /// Begin drawing primitives.
  63. /// @param prim [in] primitive type to draw, one of rcDebugDrawPrimitives.
  64. /// @param size [in] size of a primitive, applies to point size and line width only.
  65. void begin(duDebugDrawPrimitives prim, float size = 1.0f) override;
  66. /// Submit a vertex
  67. /// @param pos [in] position of the verts.
  68. /// @param color [in] color of the verts.
  69. void vertex(const float* pos, unsigned int color) override;
  70. /// Submit a vertex
  71. /// @param x,y,z [in] position of the verts.
  72. /// @param color [in] color of the verts.
  73. void vertex(const float x, const float y, const float z, unsigned int color) override;
  74. /// Submit a vertex
  75. /// @param pos [in] position of the verts.
  76. /// @param color [in] color of the verts.
  77. /// @param uv [in] the uv coordinates.
  78. void vertex(const float* pos, unsigned int color, const float* uv) override;
  79. /// Submit a vertex
  80. /// @param x,y,z [in] position of the verts.
  81. /// @param color [in] color of the verts.
  82. /// @param u [in] the u coordinate.
  83. /// @param v [in] the v coordinate.
  84. void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v) override;
  85. /// Set a texture
  86. /// @param state, use a texture in this draw, usually a checker texture.
  87. void texture(bool state) override;
  88. /// <summary>
  89. /// Assigns a colour to an area type.
  90. /// </summary>
  91. /// <param name="area">The area type.</param>
  92. /// <returns>The colour in recast format for the area.</returns>
  93. unsigned int areaToCol(unsigned int area) override;
  94. /// End drawing primitives.
  95. void end() override;
  96. void clearCache();
  97. void render(SceneRenderState* state);
  98. void immediateRender();
  99. private:
  100. struct CachedDraw {
  101. GFXPrimitiveType primType;
  102. GFXVertexBufferHandle<GFXVertexPCT> buffer;
  103. GFXPrimitiveBufferHandle primitiveBuffer;
  104. U32 vertexCount;
  105. U32 primitiveCount;
  106. GFXStateBlockDesc state;
  107. Box3F bounds;
  108. };
  109. Vector<CachedDraw> mDrawCache;
  110. GFXStateBlockDesc mDesc;
  111. Vector<GFXVertexPCT> mVertList; // Our vertex list for setting up vertexBuffer in the End function.
  112. GFXVertexBufferHandle<GFXVertexPCT> mVertexBuffer; // our vertex buffer for drawing.
  113. U32 mPrimType;
  114. U32 mVertCount;
  115. bool mOverrideState;
  116. void _vertex(const float x, const float y, const float z, unsigned int color);
  117. };
  118. #endif