debugDraw.h
Engine/source/gfx/sim/debugDraw.h
Classes:
class
Debug output class.
Public Defines
define
Detailed Description
Public Defines
ENABLE_DEBUGDRAW()
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 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 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell 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 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _DEBUGDRAW_H_ 25#define _DEBUGDRAW_H_ 26 27#ifndef _SIMOBJECT_H_ 28#include "console/simObject.h" 29#endif 30 31#ifndef _GFXDEVICE_H_ 32#include "gfx/gfxDevice.h" 33#endif 34 35#ifndef _PRIMBUILDER_H_ 36#include "gfx/primBuilder.h" 37#endif 38 39#ifndef _GFONT_H_ 40#include "gfx/gFont.h" 41#endif 42 43#ifndef _DATACHUNKER_H_ 44#include "core/dataChunker.h" 45#endif 46 47#ifndef _MPOLYHEDRON_H_ 48#include "math/mPolyhedron.h" 49#endif 50 51 52class GFont; 53 54 55// We enable the debug drawer for non-shipping 56// builds.... you better be using shipping builds 57// for your final release. 58#ifndef TORQUE_SHIPPING 59#define ENABLE_DEBUGDRAW 60#endif 61 62 63/// Debug output class. 64/// 65/// This class provides you with a flexible means of drawing debug output. It is 66/// often useful when debugging collision code or complex 3d algorithms to have 67/// them draw debug information, like culling hulls or bounding volumes, normals, 68/// simple lines, and so forth. In TGE1.2, which was based directly on a simple 69/// OpenGL rendering layer, it was a simple matter to do debug rendering directly 70/// inline. 71/// 72/// Unfortunately, this doesn't hold true with more complex rendering scenarios, 73/// where render modes and targets may be in abritrary states. In addition, it is 74/// often useful to be able to freeze frame debug information for closer inspection. 75/// 76/// Therefore, Torque provides a global DebugDrawer instance, called gDebugDraw, which 77/// you can use to draw debug information. It exposes a number of methods for drawing 78/// a variety of debug primitives, including lines, triangles and boxes. 79/// Internally, DebugDrawer maintains a list of active debug primitives, and draws the 80/// contents of the list after each frame is done rendering. This way, you can be 81/// assured that your debug rendering won't interfere with TSE's various effect 82/// rendering passes or render-to-target calls. 83/// 84/// The DebugDrawer can also be used for more interesting uses, like freezing its 85/// primitive list so you can look at a situation more closely, or dumping the 86/// primitive list to disk for closer analysis. 87/// 88/// DebugDrawer is accessible by script under the name DebugDrawer, and by C++ under 89/// the symbol gDebugDraw. There are a variety of methods available for drawing 90/// different sorts of output; see the class reference for more information. 91/// 92/// DebugDrawer works solely in worldspace. Primitives are rendered with cull mode of 93/// none. 94/// 95class DebugDrawer : public SimObject 96{ 97public: 98 DECLARE_CONOBJECT(DebugDrawer); 99 100 DebugDrawer(); 101 ~DebugDrawer(); 102 103 static DebugDrawer* get(); 104 105 /// Called at engine init to set up the global debug draw object. 106 static void init(); 107 108 /// Called globally to render debug draw state. Also does state updates. 109 void render(bool clear=true); 110 111 bool willDraw() { return isDrawing && mHead; } 112 113 void toggleFreeze() { shouldToggleFreeze = true; }; 114 void toggleDrawing() 115 { 116#ifdef ENABLE_DEBUGDRAW 117 isDrawing = !isDrawing; 118#endif 119 }; 120 121 122 /// @name ddrawmeth Debug Draw Methods 123 /// 124 /// @{ 125 126 void drawBoxOutline(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f)); 127 void drawTransformedBoxOutline(const Point3F &a, const Point3F &b, const ColorF &color, const MatrixF& transform); 128 129 void drawBox(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f,1.0f,1.0f)); 130 void drawLine(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f,1.0f,1.0f)); 131 void drawTri(const Point3F &a, const Point3F &b, const Point3F &c, const ColorF &color = ColorF(1.0f,1.0f,1.0f)); 132 void drawText(const Point3F& pos, const String& text, const ColorF &color = ColorF(1.0f,1.0f,1.0f)); 133 void drawCapsule(const Point3F &a, const F32 &radius, const F32 &height, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f)); 134 void drawDirectionLine(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f)); 135 void drawOutlinedText(const Point3F& pos, const String& text, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f), const ColorF &colorOutline = ColorF(0.0f, 0.0f, 0.0f)); 136 137 /// Render a wireframe view of the given polyhedron. 138 void drawPolyhedron( const AnyPolyhedron& polyhedron, const ColorF& color = ColorF( 1.f, 1.f, 1.f ) ); 139 140 /// Render the plane indices, edge indices, edge direction indicators, and point coordinates 141 /// of the given polyhedron for debugging. 142 /// 143 /// Green lines are plane normals. Red lines point from edge midpoints along the edge direction (i.e. to the 144 /// second vertex). This shows if the orientation is correct to yield CW ordering for face[0]. Indices and 145 /// coordinates of vertices are shown in white. Plane indices are rendered in black. Edge indices and their 146 /// plane indices are rendered in white. 147 void drawPolyhedronDebugInfo( const AnyPolyhedron& polyhedron, const MatrixF& transform, const Point3F& scale ); 148 149 /// Set the TTL for the last item we entered... 150 /// 151 /// Primitives default to lasting one frame (ie, ttl=0) 152 enum : <a href="/coding/file/types_8h/#types_8h_1ac3df7cf3c8cb172a588adec881447d68">U32</a> 153 { 154 DD_INFINITE = U32_MAX 155 }; 156 // How long should this primitive be draw for, 0 = one frame, DD_INFINITE = draw forever 157 void setLastTTL(U32 ms); 158 159 /// Disable/enable z testing on the last primitive. 160 /// 161 /// Primitives default to z testing on. 162 void setLastZTest(bool enabled); 163 164 /// @} 165private: 166 typedef SimObject Parent; 167 168 static DebugDrawer* sgDebugDrawer; 169 170 struct DebugPrim 171 { 172 /// Color used for this primitive. 173 ColorF color; 174 ColorF color2; 175 176 /// Points used to store positional data. Exact semantics determined by type. 177 Point3F a, b, c; 178 enum { 179 Tri, 180 Box, 181 Line, 182 Text, 183 DirectionLine, 184 OutlinedText, 185 Capsule, 186 } type; ///< Type of the primitive. The meanings of a,b,c are determined by this. 187 188 SimTime dieTime; ///< Time at which we should remove this from the list. 189 bool useZ; ///< If true, do z-checks for this primitive. 190 char mText[256]; // Text to display 191 192 DebugPrim *next; 193 }; 194 195 196 FreeListChunker<DebugPrim> mPrimChunker; 197 DebugPrim *mHead; 198 199 bool isFrozen; 200 bool shouldToggleFreeze; 201 bool isDrawing; 202 203 GFXStateBlockRef mRenderZOffSB; 204 GFXStateBlockRef mRenderZOnSB; 205 GFXStateBlockRef mRenderAlpha; 206 207 Resource<GFont> mFont; 208 209 void setupStateBlocks(); 210}; 211 212#endif // _DEBUGDRAW_H_ 213
