RavEngine
Loading...
Searching...
No Matches
DebugDraw.h
1//
2// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
3//
4// This software is provided 'as-is', without any express or implied
5// warranty. In no event will the authors be held liable for any damages
6// arising from the use of this software.
7// Permission is granted to anyone to use this software for any purpose,
8// including commercial applications, and to alter it and redistribute it
9// freely, subject to the following restrictions:
10// 1. The origin of this software must not be misrepresented; you must not
11// claim that you wrote the original software. If you use this software
12// in a product, an acknowledgment in the product documentation would be
13// appreciated but is not required.
14// 2. Altered source versions must be plainly marked as such, and must not be
15// misrepresented as being the original software.
16// 3. This notice may not be removed or altered from any source distribution.
17//
18
19#ifndef DEBUGDRAW_H
20#define DEBUGDRAW_H
21
22// Some math headers don't have PI defined.
23static const float DU_PI = 3.14159265f;
24
25enum duDebugDrawPrimitives
26{
27 DU_DRAW_POINTS,
28 DU_DRAW_LINES,
29 DU_DRAW_TRIS,
30 DU_DRAW_QUADS,
31};
32
35{
36 virtual ~duDebugDraw() = 0;
37
38 virtual void depthMask(bool state) = 0;
39
40 virtual void texture(bool state) = 0;
41
45 virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f) = 0;
46
50 virtual void vertex(const float* pos, unsigned int color) = 0;
51
55 virtual void vertex(const float x, const float y, const float z, unsigned int color) = 0;
56
60 virtual void vertex(const float* pos, unsigned int color, const float* uv) = 0;
61
65 virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v) = 0;
66
68 virtual void end() = 0;
69
71 virtual unsigned int areaToCol(unsigned int area);
72};
73
74inline unsigned int duRGBA(int r, int g, int b, int a)
75{
76 return ((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16) | ((unsigned int)a << 24);
77}
78
79inline unsigned int duRGBAf(float fr, float fg, float fb, float fa)
80{
81 unsigned char r = (unsigned char)(fr*255.0f);
82 unsigned char g = (unsigned char)(fg*255.0f);
83 unsigned char b = (unsigned char)(fb*255.0f);
84 unsigned char a = (unsigned char)(fa*255.0f);
85 return duRGBA(r,g,b,a);
86}
87
88unsigned int duIntToCol(int i, int a);
89void duIntToCol(int i, float* col);
90
91inline unsigned int duMultCol(const unsigned int col, const unsigned int d)
92{
93 const unsigned int r = col & 0xff;
94 const unsigned int g = (col >> 8) & 0xff;
95 const unsigned int b = (col >> 16) & 0xff;
96 const unsigned int a = (col >> 24) & 0xff;
97 return duRGBA((r*d) >> 8, (g*d) >> 8, (b*d) >> 8, a);
98}
99
100inline unsigned int duDarkenCol(unsigned int col)
101{
102 return ((col >> 1) & 0x007f7f7f) | (col & 0xff000000);
103}
104
105inline unsigned int duLerpCol(unsigned int ca, unsigned int cb, unsigned int u)
106{
107 const unsigned int ra = ca & 0xff;
108 const unsigned int ga = (ca >> 8) & 0xff;
109 const unsigned int ba = (ca >> 16) & 0xff;
110 const unsigned int aa = (ca >> 24) & 0xff;
111 const unsigned int rb = cb & 0xff;
112 const unsigned int gb = (cb >> 8) & 0xff;
113 const unsigned int bb = (cb >> 16) & 0xff;
114 const unsigned int ab = (cb >> 24) & 0xff;
115
116 unsigned int r = (ra*(255-u) + rb*u)/255;
117 unsigned int g = (ga*(255-u) + gb*u)/255;
118 unsigned int b = (ba*(255-u) + bb*u)/255;
119 unsigned int a = (aa*(255-u) + ab*u)/255;
120 return duRGBA(r,g,b,a);
121}
122
123inline unsigned int duTransCol(unsigned int c, unsigned int a)
124{
125 return (a<<24) | (c & 0x00ffffff);
126}
127
128
129void duCalcBoxColors(unsigned int* colors, unsigned int colTop, unsigned int colSide);
130
131void duDebugDrawCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
132 float maxx, float maxy, float maxz, unsigned int col, const float lineWidth);
133
134void duDebugDrawBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
135 float maxx, float maxy, float maxz, unsigned int col, const float lineWidth);
136
137void duDebugDrawArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
138 const float x1, const float y1, const float z1, const float h,
139 const float as0, const float as1, unsigned int col, const float lineWidth);
140
141void duDebugDrawArrow(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
142 const float x1, const float y1, const float z1,
143 const float as0, const float as1, unsigned int col, const float lineWidth);
144
145void duDebugDrawCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
146 const float r, unsigned int col, const float lineWidth);
147
148void duDebugDrawCross(struct duDebugDraw* dd, const float x, const float y, const float z,
149 const float size, unsigned int col, const float lineWidth);
150
151void duDebugDrawBox(struct duDebugDraw* dd, float minx, float miny, float minz,
152 float maxx, float maxy, float maxz, const unsigned int* fcol);
153
154void duDebugDrawCylinder(struct duDebugDraw* dd, float minx, float miny, float minz,
155 float maxx, float maxy, float maxz, unsigned int col);
156
157void duDebugDrawGridXZ(struct duDebugDraw* dd, const float ox, const float oy, const float oz,
158 const int w, const int h, const float size,
159 const unsigned int col, const float lineWidth);
160
161
162// Versions without begin/end, can be used to draw multiple primitives.
163void duAppendCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
164 float maxx, float maxy, float maxz, unsigned int col);
165
166void duAppendBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
167 float maxx, float maxy, float maxz, unsigned int col);
168
169void duAppendBoxPoints(struct duDebugDraw* dd, float minx, float miny, float minz,
170 float maxx, float maxy, float maxz, unsigned int col);
171
172void duAppendArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
173 const float x1, const float y1, const float z1, const float h,
174 const float as0, const float as1, unsigned int col);
175
176void duAppendArrow(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
177 const float x1, const float y1, const float z1,
178 const float as0, const float as1, unsigned int col);
179
180void duAppendCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
181 const float r, unsigned int col);
182
183void duAppendCross(struct duDebugDraw* dd, const float x, const float y, const float z,
184 const float size, unsigned int col);
185
186void duAppendBox(struct duDebugDraw* dd, float minx, float miny, float minz,
187 float maxx, float maxy, float maxz, const unsigned int* fcol);
188
189void duAppendCylinder(struct duDebugDraw* dd, float minx, float miny, float minz,
190 float maxx, float maxy, float maxz, unsigned int col);
191
192
194{
195 float* m_pos;
196 unsigned int* m_color;
197 int m_size;
198 int m_cap;
199
200 bool m_depthMask;
201 duDebugDrawPrimitives m_prim;
202 float m_primSize;
203
204 void resize(int cap);
205
206public:
207 duDisplayList(int cap = 512);
209 virtual void depthMask(bool state);
210 virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f);
211 virtual void vertex(const float x, const float y, const float z, unsigned int color);
212 virtual void vertex(const float* pos, unsigned int color);
213 virtual void end();
214 void clear();
215 void draw(struct duDebugDraw* dd);
216private:
217 // Explicitly disabled copy constructor and copy assignment operator.
219 duDisplayList& operator=(const duDisplayList&);
220};
221
222
223#endif // DEBUGDRAW_H
Definition DebugDraw.h:194
virtual void begin(duDebugDrawPrimitives prim, float size=1.0f)
Definition DebugDraw.cpp:575
virtual void end()
End drawing primitives.
Definition DebugDraw.cpp:599
virtual void vertex(const float x, const float y, const float z, unsigned int color)
Definition DebugDraw.cpp:582
Abstract debug draw interface.
Definition DebugDraw.h:35
virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v)=0
virtual void vertex(const float x, const float y, const float z, unsigned int color)=0
virtual void begin(duDebugDrawPrimitives prim, float size=1.0f)=0
virtual void vertex(const float *pos, unsigned int color, const float *uv)=0
virtual void vertex(const float *pos, unsigned int color)=0
virtual unsigned int areaToCol(unsigned int area)
Compute a color for given area.
Definition DebugDraw.cpp:31
virtual void end()=0
End drawing primitives.