duDebugDrawTorque.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #include "core/util/tVector.h"
  25. #include <DebugDraw.h>
  26. #include "gfx/gfxStateBlock.h"
  27. /// @brief Implements the duDebugDraw interface in Torque.
  28. class duDebugDrawTorque: public duDebugDraw {
  29. public:
  30. duDebugDrawTorque();
  31. ~duDebugDrawTorque();
  32. /// Enable/disable Z read.
  33. void depthMask(bool state);
  34. /// Enable/disable texturing. Not used.
  35. void texture(bool state);
  36. /// Special colour overwrite for when I get picky about the colours Mikko chose.
  37. void overrideColor(unsigned int col);
  38. /// Stop the colour override.
  39. void cancelOverride();
  40. /// Begin drawing primitives.
  41. /// @param prim [in] primitive type to draw, one of rcDebugDrawPrimitives.
  42. /// @param size [in] size of a primitive, applies to point size and line width only.
  43. void begin(duDebugDrawPrimitives prim, float size = 1.0f);
  44. /// All new buffers go into this group.
  45. void beginGroup(U32 group);
  46. /// Submit a vertex
  47. /// @param pos [in] position of the verts.
  48. /// @param color [in] color of the verts.
  49. void vertex(const float* pos, unsigned int color);
  50. /// Submit a vertex
  51. /// @param x,y,z [in] position of the verts.
  52. /// @param color [in] color of the verts.
  53. void vertex(const float x, const float y, const float z, unsigned int color);
  54. /// Submit a vertex
  55. /// @param pos [in] position of the verts.
  56. /// @param color [in] color of the verts.
  57. void vertex(const float* pos, unsigned int color, const float* uv);
  58. /// Submit a vertex
  59. /// @param x,y,z [in] position of the verts.
  60. /// @param color [in] color of the verts.
  61. void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v);
  62. /// End drawing primitives.
  63. void end();
  64. /// Render buffered primitive.
  65. void render();
  66. /// Render buffered primitives in a group.
  67. void renderGroup(U32 group);
  68. /// Delete buffered primitive.
  69. void clear();
  70. private:
  71. GFXStateBlockDesc mDesc;
  72. U32 mPrimType;
  73. bool mQuadsMode;
  74. U32 mVertCount;
  75. F32 mStore[3][3];
  76. U32 mGroup;
  77. struct Instruction {
  78. // Contain either a point or a color command.
  79. union {
  80. struct {
  81. U8 r, g, b, a;
  82. } color;
  83. struct {
  84. float x, y, z;
  85. } point;
  86. U32 primType;
  87. } data;
  88. // Which type of data do we store?
  89. enum {
  90. COLOR,
  91. POINT,
  92. PRIMTYPE,
  93. } type;
  94. // Construct as color instruction.
  95. Instruction(U8 r, U8 g, U8 b, U8 a) {
  96. type = COLOR;
  97. data.color.r = r;
  98. data.color.g = g;
  99. data.color.b = b;
  100. data.color.a = a;
  101. }
  102. // Construct as point.
  103. Instruction(float x, float y, float z) {
  104. type = POINT;
  105. data.point.x = x;
  106. data.point.y = y;
  107. data.point.z = z;
  108. }
  109. Instruction(U32 t = 0) {
  110. type = PRIMTYPE;
  111. data.primType = t;
  112. }
  113. };
  114. struct Buffer {
  115. U32 group;
  116. Vector<Instruction> buffer;
  117. GFXPrimitiveType primType;
  118. Buffer(U32 type = 0) {
  119. primType = (GFXPrimitiveType)type;
  120. group = 0;
  121. }
  122. };
  123. Vector<Buffer> mBuffers;
  124. U32 mCurrColor;
  125. U32 mOverrideColor;
  126. bool mOverride;
  127. void _vertex(const float x, const float y, const float z, unsigned int color);
  128. void renderBuffer(Buffer &b);
  129. };
  130. #endif