1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/*
* Copyright 2011-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#ifndef DEBUGDRAW_H_HEADER_GUARD
#define DEBUGDRAW_H_HEADER_GUARD
#include <bx/allocator.h>
#include <bgfx/bgfx.h>
#include "../bounds.h"
struct Axis
{
enum Enum
{
X,
Y,
Z,
Count
};
};
struct DdVertex
{
float x, y, z;
};
struct SpriteHandle { uint16_t idx; };
inline bool isValid(SpriteHandle _handle) { return _handle.idx != UINT16_MAX; }
struct GeometryHandle { uint16_t idx; };
inline bool isValid(GeometryHandle _handle) { return _handle.idx != UINT16_MAX; }
///
void ddInit(bx::AllocatorI* _allocator = NULL);
///
void ddShutdown();
///
SpriteHandle ddCreateSprite(uint16_t _width, uint16_t _height, const void* _data);
///
void ddDestroy(SpriteHandle _handle);
///
GeometryHandle ddCreateGeometry(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const void* _indices = NULL, bool _index32 = false);
///
void ddDestroy(GeometryHandle _handle);
///
struct DebugDrawEncoder
{
///
DebugDrawEncoder();
///
~DebugDrawEncoder();
///
void begin(uint16_t _viewId, bool _depthTestLess = true, bgfx::Encoder* _encoder = NULL);
///
void end();
///
void push();
///
void pop();
///
void setDepthTestLess(bool _depthTestLess);
///
void setState(bool _depthTest, bool _depthWrite, bool _clockwise);
///
void setColor(uint32_t _abgr);
///
void setLod(uint8_t _lod);
///
void setWireframe(bool _wireframe);
///
void setStipple(bool _stipple, float _scale = 1.0f, float _offset = 0.0f);
///
void setSpin(float _spin);
///
void setTransform(const void* _mtx);
///
void setTranslate(float _x, float _y, float _z);
///
void pushTransform(const void* _mtx);
///
void popTransform();
///
void moveTo(float _x, float _y, float _z = 0.0f);
///
void moveTo(const bx::Vec3& _pos);
///
void lineTo(float _x, float _y, float _z = 0.0f);
///
void lineTo(const bx::Vec3& _pos);
///
void close();
///
void draw(const Aabb& _aabb);
///
void draw(const Cylinder& _cylinder);
///
void draw(const Capsule& _capsule);
///
void draw(const Disk& _disk);
///
void draw(const Obb& _obb);
///
void draw(const Sphere& _sphere);
///
void draw(const Triangle& _triangle);
///
void draw(const Cone& _cone);
///
void draw(GeometryHandle _handle);
///
void drawLineList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
///
void drawTriList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices = 0, const uint16_t* _indices = NULL);
///
void drawFrustum(const void* _viewProj);
///
void drawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees);
///
void drawCircle(const bx::Vec3& _normal, const bx::Vec3& _center, float _radius, float _weight = 0.0f);
///
void drawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight = 0.0f);
///
void drawQuad(const bx::Vec3& _normal, const bx::Vec3& _center, float _size);
///
void drawQuad(SpriteHandle _handle, const bx::Vec3& _normal, const bx::Vec3& _center, float _size);
///
void drawQuad(bgfx::TextureHandle _handle, const bx::Vec3& _normal, const bx::Vec3& _center, float _size);
///
void drawCone(const bx::Vec3& _from, const bx::Vec3& _to, float _radius);
///
void drawCylinder(const bx::Vec3& _from, const bx::Vec3& _to, float _radius);
///
void drawCapsule(const bx::Vec3& _from, const bx::Vec3& _to, float _radius);
///
void drawAxis(float _x, float _y, float _z, float _len = 1.0f, Axis::Enum _highlight = Axis::Count, float _thickness = 0.0f);
///
void drawGrid(const bx::Vec3& _normal, const bx::Vec3& _center, uint32_t _size = 20, float _step = 1.0f);
///
void drawGrid(Axis::Enum _axis, const bx::Vec3& _center, uint32_t _size = 20, float _step = 1.0f);
///
void drawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _highlight = Axis::Count);
BX_ALIGN_DECL_CACHE_LINE(uint8_t) m_internal[50<<10];
};
///
class DebugDrawEncoderScopePush
{
public:
///
DebugDrawEncoderScopePush(DebugDrawEncoder& _dde);
///
~DebugDrawEncoderScopePush();
private:
DebugDrawEncoder& m_dde;
};
#endif // DEBUGDRAW_H_HEADER_GUARD
|