Nebula
Loading...
Searching...
No Matches
im3d.h
Go to the documentation of this file.
1#pragma once
2
3#include "im3d_config.h"
4
5#define IM3D_VERSION "1.16"
6
7#ifndef IM3D_API
8 #define IM3D_API
9#endif
10
11#ifndef IM3D_ASSERT
12 #include <cassert>
13 #define IM3D_ASSERT(e) assert(e)
14#endif
15
16#ifndef IM3D_VERTEX_ALIGNMENT
17 #define IM3D_VERTEX_ALIGNMENT 4
18#endif
19
20#include <cstdarg> // va_list
21
22namespace Im3d {
23
24typedef unsigned int U32;
25struct Vec2;
26struct Vec3;
27struct Vec4;
28struct Mat3;
29struct Mat4;
30struct Color;
31struct VertexData;
32struct AppData;
33struct DrawList;
34struct TextDrawList;
35struct Context;
36
37typedef U32 Id;
38constexpr Id Id_Invalid = 0;
39
40// Get AppData struct from the current context, fill before calling NewFrame().
42
43// Call at the start of each frame, after filling the AppData struct.
44IM3D_API void NewFrame();
45// Call after all Im3d calls have been made for the current frame, before accessing draw data.
46IM3D_API void EndFrame();
47
48// Access draw data. Draw lists are valid after calling EndFrame() and before calling NewFrame().
51
52// Access to text draw data. Draw lists are valid after calling EndFrame() and before calling NewFrame().
55
56// DEPRECATED (use EndFrame() + GetDrawLists()).
57// Call after all Im3d calls have been made for the current frame.
58IM3D_API void Draw();
59
60
61// Begin/end primitive. End() must be called before starting each new primitive type.
63IM3D_API void BeginLines();
68IM3D_API void End();
69
70// Add a vertex to the current primitive (call between Begin*() and End()).
71IM3D_API void Vertex(const Vec3& _position);
72IM3D_API void Vertex(const Vec3& _position, Color _color);
73IM3D_API void Vertex(const Vec3& _position, float _size);
74IM3D_API void Vertex(const Vec3& _position, float _size, Color _color);
75IM3D_API void Vertex(float _x, float _y, float _z);
76IM3D_API void Vertex(float _x, float _y, float _z, Color _color);
77IM3D_API void Vertex(float _x, float _y, float _z, float _size);
78IM3D_API void Vertex(float _x, float _y, float _z, float _size, Color _color);
79
80// Color draw state (per vertex).
81IM3D_API void PushColor(); // push the stack top
82IM3D_API void PushColor(Color _color);
83IM3D_API void PopColor();
84IM3D_API void SetColor(Color _color);
85IM3D_API void SetColor(float _r, float _g, float _b, float _a = 1.0f);
87
88// Alpha draw state, multiplies the alpha set by the color draw state (per vertex).
89IM3D_API void PushAlpha(); // push the stack top
90IM3D_API void PushAlpha(float _alpha);
91IM3D_API void PopAlpha();
92IM3D_API void SetAlpha(float _alpha);
93IM3D_API float GetAlpha();
94
95// Size draw state, for points/lines this is the radius/width in pixels (per vertex).
96IM3D_API void PushSize(); // push the stack top
97IM3D_API void PushSize(float _size);
98IM3D_API void PopSize();
99IM3D_API void SetSize(float _size);
100IM3D_API float GetSize();
101
102// Sorting draw state, enable depth sorting between primitives (per primitive).
103IM3D_API void PushEnableSorting(); // push the stack top
104IM3D_API void PushEnableSorting(bool _enable);
106IM3D_API void EnableSorting(bool _enable);
107
108// Push/pop all draw states (color, alpha, size, sorting).
111
112// Transform state (per vertex).
113IM3D_API void PushMatrix(); // push stack top
114IM3D_API void PushMatrix(const Mat4& _mat4);
115IM3D_API void PopMatrix();
116IM3D_API void SetMatrix(const Mat4& _mat4);
117IM3D_API void SetIdentity();
118IM3D_API void MulMatrix(const Mat4& _mat4);
119IM3D_API void Translate(float _x, float _y, float _z);
120IM3D_API void Translate(const Vec3& _vec3);
121IM3D_API void Rotate(const Vec3& _axis, float _angle);
122IM3D_API void Rotate(const Mat3& _rotation);
123IM3D_API void Scale(float _x, float _y, float _z);
124
125// High order shapes. Where _detail = -1, an automatic level of detail is chosen based on the distance to the view origin (as specified via the AppData struct).
126IM3D_API void DrawXyzAxes();
127IM3D_API void DrawPoint(const Vec3& _position, float _size, Color _color);
128IM3D_API void DrawLine(const Vec3& _a, const Vec3& _b, float _size, Color _color);
129IM3D_API void DrawQuad(const Vec3& _a, const Vec3& _b, const Vec3& _c, const Vec3& _d);
130IM3D_API void DrawQuad(const Vec3& _origin, const Vec3& _normal, const Vec2& _size);
131IM3D_API void DrawQuadFilled(const Vec3& _a, const Vec3& _b, const Vec3& _c, const Vec3& _d);
132IM3D_API void DrawQuadFilled(const Vec3& _origin, const Vec3& _normal, const Vec2& _size);
133IM3D_API void DrawCircle(const Vec3& _origin, const Vec3& _normal, float _radius, int _detail = -1);
134IM3D_API void DrawCircleFilled(const Vec3& _origin, const Vec3& _normal, float _radius, int _detail = -1);
135IM3D_API void DrawSphere(const Vec3& _origin, float _radius, int _detail = -1);
136IM3D_API void DrawSphereFilled(const Vec3& _origin, float _radius, int _detail = -1);
137IM3D_API void DrawAlignedBox(const Vec3& _min, const Vec3& _max);
138IM3D_API void DrawAlignedBoxFilled(const Vec3& _min, const Vec3& _max);
139IM3D_API void DrawCylinder(const Vec3& _start, const Vec3& _end, float _radius, int _detail = -1);
140IM3D_API void DrawCapsule(const Vec3& _start, const Vec3& _end, float _radius, int _detail = -1);
141IM3D_API void DrawPrism(const Vec3& _start, const Vec3& _end, float _radius, int _sides);
142IM3D_API void DrawArrow(const Vec3& _start, const Vec3& _end, float _headLength = -1.0f, float _headThickness = -1.0f);
143
144// Add text. See TextFlags_ enum for _textFlags. _size is a hint to the application-side text rendering.
145IM3D_API void Text(const Vec3& _position, U32 _textFlags, const char* _text, ...); // use the current draw state for size/color
146IM3D_API void Text(const Vec3& _position, float _size, Color _color, U32 _textFlags, const char* _text, ...);
147
148// IDs are used to uniquely identify gizmos and layers. Gizmo should have a unique ID during a frame.
149// Note that ids are a hash of the whole ID stack, see PushId(), PopId().
150IM3D_API Id MakeId(const char* _str);
151IM3D_API Id MakeId(const void* _ptr);
152IM3D_API Id MakeId(int _i);
153
154// PushId(), PopId() affect the result of subsequent calls to MakeId(), use when creating gizmos in a loop.
155IM3D_API void PushId(); // push stack top
156IM3D_API void PushId(Id _id);
157IM3D_API void PushId(const char* _str);
158IM3D_API void PushId(const void* _ptr);
159IM3D_API void PushId(int _i);
160IM3D_API void PopId();
162
163// Layer id state, subsequent primitives are added to a separate draw list associated with the id (per primitive).
164IM3D_API void PushLayerId(Id _layer);
165IM3D_API void PushLayerId(const char* _str); // calls PushLayerId(MakeId(_str))
166IM3D_API void PopLayerId();
168
169// Manipulate translation/rotation/scale via a gizmo. Return true if the gizmo is 'active' (if it modified the output parameter).
170// If _local is true, the Gizmo* functions expect that the local matrix is on the matrix stack; in general the application should
171// push the local matrix before calling any of the following.
172IM3D_API bool GizmoTranslation(const char* _id, float _translation_[3], bool _local = false);
173IM3D_API bool GizmoRotation(const char* _id, float _rotation_[3*3], bool _local = false);
174IM3D_API bool GizmoScale(const char* _id, float _scale_[3]); // local scale only
175// Unified gizmo, selects local/global, translation/rotation/scale based on the context-global gizmo modes. Return true if the gizmo is active.
176IM3D_API bool Gizmo(const char* _id, float _translation_[3], float _rotation_[3*3], float _scale_[3]); // any of _translation_/_rotation_/_scale_ may be null.
177IM3D_API bool Gizmo(const char* _id, float _transform_[4*4]);
178
179// Gizmo* overloads which take an ID directly. In some cases the app may want to call MakeId() separately, usually to change the gizmo appearance if hot/active.
180IM3D_API bool GizmoTranslation(Id _id, float _translation_[3], bool _local = false);
181IM3D_API bool GizmoRotation(Id _id, float _rotation_[3*3], bool _local = false);
182IM3D_API bool GizmoScale(Id _id, float _scale_[3]);
183IM3D_API bool Gizmo(Id _id, float _transform_[4*4]);
184IM3D_API bool Gizmo(Id _id, float _translation_[3], float _rotation_[3*3], float _scale_[3]);
185
186// Active gizmo ID. This will match the _id parameter passed to a Gizmo* function. Return Id_Invalid if no gizmo is in use.
188// ID of the current current 'hot' gizmo (nearest intersecting gizmo along the cursor ray).
190
191// Visibility tests. The application must set a culling frustum via AppData.
192IM3D_API bool IsVisible(const Vec3& _origin, float _radius); // sphere
193IM3D_API bool IsVisible(const Vec3& _min, const Vec3& _max); // axis-aligned bounding box
194
195// Get/set the current context. All Im3d calls affect the currently bound context.
197IM3D_API void SetContext(Context& _ctx);
198
199// Merge vertex data from _src into _dst_. Layers are preserved. Call before EndFrame().
200IM3D_API void MergeContexts(Context& _dst_, const Context& _src);
201
202
204{
205 float x, y;
206
207 Vec2() {}
208 Vec2(float _xy): x(_xy), y(_xy) {}
209 Vec2(float _x, float _y): x(_x), y(_y) {}
210
211 operator float*() { return &x; }
212 operator const float*() const { return &x; }
213
214 #ifdef IM3D_VEC2_APP
216 #endif
217};
218
220{
221 float x, y, z;
222
223 Vec3() {}
224 Vec3(float _xyz): x(_xyz), y(_xyz), z(_xyz) {}
225 Vec3(float _x, float _y, float _z): x(_x), y(_y), z(_z) {}
226 Vec3(const Vec2& _xy, float _z): x(_xy.x), y(_xy.y), z(_z) {}
227 Vec3(const Vec4& _v); // discards w
228
229 operator float*() { return &x; }
230 operator const float*() const { return &x; }
231
232 #ifdef IM3D_VEC3_APP
234 #endif
235};
236
238{
239 float x, y, z, w;
240
241 Vec4() {}
242 Vec4(float _xyzw): x(_xyzw), y(_xyzw), z(_xyzw), w(_xyzw) {}
243 Vec4(float _x, float _y, float _z, float _w): x(_x), y(_y), z(_z), w(_w) {}
244 Vec4(const Vec3& _xyz, float _w): x(_xyz.x), y(_xyz.y), z(_xyz.z), w(_w) {}
245 Vec4(Color _rgba);
246
247 operator float*() { return &x; }
248 operator const float*() const { return &x; }
249
250 #ifdef IM3D_VEC4_APP
252 #endif
253};
254
256{
257 float m[3*3]; // column-major unless IM3D_MATRIX_ROW_MAJOR defined
258
259 Mat3() {}
260 Mat3(float _diagonal);
261 Mat3(
262 float m00, float m01, float m02,
263 float m10, float m11, float m12,
264 float m20, float m21, float m22
265 );
266 Mat3(const Vec3& _colX, const Vec3& _colY, const Vec3& _colZ);
267 Mat3(const Mat4& _mat4); // extract upper 3x3
268
269 operator float*() { return m; }
270 operator const float*() const { return m; }
271
272 Vec3 getCol(int _i) const;
273 Vec3 getRow(int _i) const;
274 void setCol(int _i, const Vec3& _v);
275 void setRow(int _i, const Vec3& _v);
276
277 Vec3 getScale() const;
278 void setScale(const Vec3& _scale);
279
280 float operator()(int _row, int _col) const
281 {
282 #ifdef IM3D_MATRIX_ROW_MAJOR
283 int i = _row * 3 + _col;
284 #else
285 int i = _col * 3 + _row;
286 #endif
287 return m[i];
288 }
289 float& operator()(int _row, int _col)
290 {
291 #ifdef IM3D_MATRIX_ROW_MAJOR
292 int i = _row * 3 + _col;
293 #else
294 int i = _col * 3 + _row;
295 #endif
296 return m[i];
297 }
298
299 #ifdef IM3D_MAT3_APP
301 #endif
302};
303
305{
306 float m[4*4]; // column-major unless IM3D_MATRIX_ROW_MAJOR defined
307
308 Mat4() {}
309 Mat4(float _diagonal);
310 Mat4(
311 float m00, float m01, float m02, float m03,
312 float m10, float m11, float m12, float m13,
313 float m20, float m21, float m22, float m23,
314 float m30 = 0.0f, float m31 = 0.0f, float m32 = 0.0f, float m33 = 1.0f
315 );
316 Mat4(const Mat3& _mat3);
317 Mat4(const Vec3& _translation, const Mat3& _rotation, const Vec3& _scale);
318
319 operator float*() { return m; }
320 operator const float*() const { return m; }
321
322 Vec4 getCol(int _i) const;
323 Vec4 getRow(int _i) const;
324 void setCol(int _i, const Vec4& _v);
325 void setRow(int _i, const Vec4& _v);
326
327 Vec3 getTranslation() const;
328 void setTranslation(const Vec3& _translation);
329 Mat3 getRotation() const;
330 void setRotation(const Mat3& _rotation);
331 Vec3 getScale() const;
332 void setScale(const Vec3& _scale);
333
334 float operator()(int _row, int _col) const
335 {
336 #ifdef IM3D_MATRIX_ROW_MAJOR
337 int i = _row * 4 + _col;
338 #else
339 int i = _col * 4 + _row;
340 #endif
341 return m[i];
342 }
343 float& operator()(int _row, int _col)
344 {
345 #ifdef IM3D_MATRIX_ROW_MAJOR
346 int i = _row * 4 + _col;
347 #else
348 int i = _col * 4 + _row;
349 #endif
350 return m[i];
351 }
352
353 #ifdef IM3D_MAT4_APP
355 #endif
356};
357
359{
360 U32 v; // rgba8 (MSB = r)
361
362 constexpr Color(): v(0) {}
363 constexpr Color(U32 _rgba): v(_rgba) {}
364 Color(const Vec4& _rgba);
365 Color(const Vec3& _rgb, float _alpha);
366 Color(float _r, float _g, float _b, float _a = 1.0f);
367
368 operator U32() const { return v; }
369
370 void set(int _i, float _val)
371 {
372 _i *= 8;
373 U32 mask = 0xff << _i;
374 v = (v & ~mask) | (U32(_val * 255.0f) << _i);
375 }
376 void setR(float _val) { set(3, _val); }
377 void setG(float _val) { set(2, _val); }
378 void setB(float _val) { set(1, _val); }
379 void setA(float _val) { set(0, _val); }
380
381 float get(int _i) const
382 {
383 _i *= 8;
384 U32 mask = 0xff << _i;
385 return float((v & mask) >> _i) / 255.0f;
386 }
387 float getR() const { return get(3); }
388 float getG() const { return get(2); }
389 float getB() const { return get(1); }
390 float getA() const { return get(0); }
391
392 U32 getABGR() const
393 {
394 return 0
395 | ((v & (0xff << 24)) >> 24) // r
396 | ((v & (0xff << 16)) >> 8) // g
397 | ((v & (0xff << 8)) << 8) // b
398 | ((v & (0xff )) << 24) // a
399 ;
400 }
401};
402
403constexpr Color Color_Black = Color(0x000000ff);
404constexpr Color Color_White = Color(0xffffffff);
405constexpr Color Color_Gray = Color(0x808080ff);
406constexpr Color Color_Red = Color(0xff0000ff);
407constexpr Color Color_Green = Color(0x00ff00ff);
408constexpr Color Color_Blue = Color(0x0000ffff);
409constexpr Color Color_Magenta = Color(0xff00ffff);
410constexpr Color Color_Yellow = Color(0xffff00ff);
411constexpr Color Color_Cyan = Color(0x00ffffff);
412
413constexpr Color Color_Pink = Color(0xffc0cbff);
414constexpr Color Color_Orange = Color(0xffa500ff);
415constexpr Color Color_Gold = Color(0xffd700ff);
416constexpr Color Color_Brown = Color(0x8b4513ff);
417constexpr Color Color_Purple = Color(0x800080ff);
418constexpr Color Color_Teal = Color(0x008080ff);
419constexpr Color Color_Navy = Color(0x000080ff);
420
421struct alignas(IM3D_VERTEX_ALIGNMENT) VertexData
422{
423 Vec4 m_positionSize; // xyz = position, w = size
424 Color m_color; // rgba8 (MSB = r)
425
427 VertexData(const Vec3& _position, float _size, Color _color): m_positionSize(_position, _size), m_color(_color) {}
428};
429
431{
432 // order here determines the order in which unsorted primitives are drawn
436
439
447typedef void (DrawPrimitivesCallback)(const DrawList& _drawList);
448
450{
452 TextFlags_AlignRight = (1 << 1),
454 TextFlags_AlignBottom = (1 << 4),
455
456 TextFlags_Default = 0 // align center
458
459struct alignas(IM3D_VERTEX_ALIGNMENT) TextData
460{
461 Vec4 m_positionSize; // xyz = position, w = size
462 Color m_color; // rgba8 (MSB = r)
463 U32 m_flags; // TextFlags
464 U32 m_textLength; // # chars in the text, excluding null terminator
465 U32 m_textBufferOffset; // start of the text in the draw list's text buffer
466};
467
475
495
507
509{
510 bool m_keyDown[Key_Count] = { false }; // Key states.
511 Vec4 m_cullFrustum[FrustumPlane_Count] = { Vec4(0.0f) }; // Frustum planes for culling (if culling enabled).
512 Vec3 m_cursorRayOrigin = Vec3(0.0f); // World space cursor ray origin.
513 Vec3 m_cursorRayDirection = Vec3(0.0f); // World space cursor ray direction.
514 Vec3 m_worldUp = Vec3(0.0f, 1.0f, 0.0f); // World space 'up' vector.
515 Vec3 m_viewOrigin = Vec3(0.0f); // World space render origin (camera position).
516 Vec3 m_viewDirection = Vec3(0.0f); // World space view direction.
517 Vec2 m_viewportSize = Vec2(0.0f); // Viewport size (pixels).
518 float m_projScaleY = 1.0f; // Scale factor used to convert from pixel size -> world scale; use tan(fov) for perspective projections, far plane height for ortho.
519 bool m_projOrtho = false; // If the projection matrix is orthographic.
520 float m_deltaTime = 0.0f; // Time since previous frame (seconds).
521 float m_snapTranslation = 0.0f; // Snap value for translation gizmos (world units). 0 = disabled.
522 float m_snapRotation = 0.0f; // Snap value for rotation gizmos (radians). 0 = disabled.
523 float m_snapScale = 0.0f; // Snap value for scale gizmos. 0 = disabled.
524 bool m_flipGizmoWhenBehind = true; // Flip gizmo axes when viewed from behind.
525 void* m_appData = nullptr; // App-specific data.
526
527 DrawPrimitivesCallback* drawCallback = nullptr; // e.g. void Im3d_Draw(const DrawList& _drawList)
528
529 // Extract cull frustum planes from the view-projection matrix.
530 // Set _ndcZNegativeOneToOne = true if the proj matrix maps z from [-1,1] (OpenGL style).
531 void setCullFrustum(const Mat4& _viewProj, bool _ndcZNegativeOneToOne);
532};
533
534// Minimal vector.
535template <typename T>
536struct Vector
537{
539 ~Vector();
540
541 T& operator[](U32 _i) { IM3D_ASSERT(_i < m_size); return m_data[_i]; }
542 const T& operator[](U32 _i) const { IM3D_ASSERT(_i < m_size); return m_data[_i]; }
543 T* data() { return m_data; }
544 const T* data() const { return m_data; }
545
546 T& push_back() { if (m_size == m_capacity) { reserve(m_capacity + m_capacity / 2); } return m_data[m_size++]; }
547 void push_back(const T& _v) { T tmp = _v; if (m_size == m_capacity) { reserve(m_capacity + m_capacity / 2); } m_data[m_size++] = tmp; }
548 void pop_back() { IM3D_ASSERT(m_size > 0); --m_size; }
549 void append(const T* _v, U32 _count);
550 void append(const Vector<T>& _other) { append(_other.data(), _other.size()); }
551
552 T* begin() { return m_data; }
553 const T* begin() const { return m_data; }
554 T* end() { return m_data + m_size; }
555 const T* end() const { return m_data + m_size; }
556 T& front() { IM3D_ASSERT(m_size > 0); return m_data[0]; }
557 const T& front() const { IM3D_ASSERT(m_size > 0); return m_data[0]; }
558 T& back() { IM3D_ASSERT(m_size > 0); return m_data[m_size - 1]; }
559 const T& back() const { IM3D_ASSERT(m_size > 0); return m_data[m_size - 1]; }
560
561 U32 size() const { return m_size; }
562 U32 capacity() const { return m_capacity; }
563 bool empty() const { return m_size == 0; }
564
565 void clear() { m_size = 0; }
566 void reserve(U32 _capacity);
567 void resize(U32 _size, const T& _val);
568 void resize(U32 _size);
569
570 static void swap(Vector<T>& _a_, Vector<T>& _b_);
571
572private:
573
574 T* m_data = nullptr;
575 U32 m_size = 0;
576 U32 m_capacity = 0;
577};
578
579
596
597// Context stores all relevant state - main interface affects the context currently bound via SetCurrentContext().
599{
600 Context();
601 ~Context();
602
603 void begin(PrimitiveMode _mode);
604 void end();
605
606 void vertex(const Vec3& _position, float _size, Color _color);
607 void vertex(const Vec3& _position ) { vertex(_position, getSize(), getColor()); }
608
609 void text(const Vec3& _position, float _size, Color _color, TextFlags _flags, const char* _textStart, const char* _textEnd);
610 void text(const Vec3& _position, float _size, Color _color, TextFlags _flags, const char* _text, va_list _args);
611
612 void reset();
613 void merge(const Context& _src);
614 void endFrame();
615 void draw(); // DEPRECATED (see Im3d::Draw)
616
617 const DrawList* getDrawLists() const { return m_drawLists.data(); }
618 U32 getDrawListCount() const { return m_drawLists.size(); }
619
620 const TextDrawList* getTextDrawLists() const { return m_textDrawLists.data(); }
621 U32 getTextDrawListCount() const { return m_textDrawLists.size(); }
622
623
624 void setColor(Color _color) { m_colorStack.back() = _color; }
625 Color getColor() const { return m_colorStack.back(); }
626 void pushColor(Color _color) { m_colorStack.push_back(_color); }
627 void popColor() { IM3D_ASSERT(m_colorStack.size() > 1); m_colorStack.pop_back(); }
628
629 void setAlpha(float _alpha) { m_alphaStack.back() = _alpha; }
630 float getAlpha() const { return m_alphaStack.back(); }
631 void pushAlpha(float _alpha) { m_alphaStack.push_back(_alpha); }
632 void popAlpha() { IM3D_ASSERT(m_alphaStack.size() > 1); m_alphaStack.pop_back(); }
633
634 void setSize(float _size) { m_sizeStack.back() = _size; }
635 float getSize() const { return m_sizeStack.back(); }
636 void pushSize(float _size) { m_sizeStack.push_back(_size); }
637 void popSize() { IM3D_ASSERT(m_sizeStack.size() > 1); m_sizeStack.pop_back(); }
638
639 void setEnableSorting(bool _enable);
640 bool getEnableSorting() const { return m_enableSortingStack.back(); }
641 void pushEnableSorting(bool _enable);
642 void popEnableSorting();
643
644 Id getLayerId() const { return m_layerIdStack.back(); }
645 void pushLayerId(Id _layer);
646 void popLayerId();
647
648 void setMatrix(const Mat4& _mat4) { m_matrixStack.back() = _mat4; }
649 const Mat4& getMatrix() const { return m_matrixStack.back(); }
650 void pushMatrix(const Mat4& _mat4) { m_matrixStack.push_back(_mat4); }
651 void popMatrix() { IM3D_ASSERT(m_matrixStack.size() > 1); m_matrixStack.pop_back(); }
652
653 void setId(Id _id) { m_idStack.back() = _id; }
654 Id getId() const { return m_idStack.back(); }
655 void pushId(Id _id) { m_idStack.push_back(_id); }
656 void popId() { IM3D_ASSERT(m_idStack.size() > 1); m_idStack.pop_back(); }
657
658 AppData& getAppData() { return m_appData; }
659
660 // Low-level interface for internal and app-defined gizmos. May be subject to breaking changes.
661
662 bool gizmoAxisTranslation_Behavior(Id _id, const Vec3& _origin, const Vec3& _axis, float _snap, float _worldHeight, float _worldSize, Vec3* _out_);
663 void gizmoAxisTranslation_Draw(Id _id, const Vec3& _origin, const Vec3& _axis, float _worldHeight, float _worldSize, Color _color);
664
665 bool gizmoPlaneTranslation_Behavior(Id _id, const Vec3& _origin, const Vec3& _normal, float _snap, float _worldSize, Vec3* _out_);
666 void gizmoPlaneTranslation_Draw(Id _id, const Vec3& _origin, const Vec3& _normal, float _worldSize, Color _color);
667
668 bool gizmoAxislAngle_Behavior(Id _id, const Vec3& _origin, const Vec3& _axis, float _snap, float _worldRadius, float _worldSize, float* _out_);
669 void gizmoAxislAngle_Draw(Id _id, const Vec3& _origin, const Vec3& _axis, float _worldRadius, float _angle, Color _color, float _minAlpha);
670
671 bool gizmoAxisScale_Behavior(Id _id, const Vec3& _origin, const Vec3& _axis, float _snap, float _worldHeight, float _worldSize, float *_out_);
672 void gizmoAxisScale_Draw(Id _id, const Vec3& _origin, const Vec3& _axis, float _worldHeight, float _worldSize, Color _color);
673
674 // Convert pixels -> world space size based on distance between _position and view origin.
675 float pixelsToWorldSize(const Vec3& _position, float _pixels);
676 // Convert world space size -> pixels based on distance between _position and view origin.
677 float worldSizeToPixels(const Vec3& _position, float _pixels);
678 // Blend between _min and _max based on distance betwen _position and view origin.
679 int estimateLevelOfDetail(const Vec3& _position, float _worldSize, int _min = 4, int _max = 256);
680
681 // Make _id hot if _depth < m_hotDepth && _intersects.
682 bool makeHot(Id _id, float _depth, bool _intersects);
683 // Make _id active.
684 void makeActive(Id _id);
685 // Reset the acive/hot ids and the hot depth.
686 void resetId();
687
688 // Interpret key state.
689 bool isKeyDown(Key _key) const { return m_keyDownCurr[_key]; }
690 bool wasKeyPressed(Key _key) const { return m_keyDownCurr[_key] && !m_keyDownPrev[_key]; }
691
692 // Visibiity tests for culling.
693 bool isVisible(const VertexData* _vdata, DrawPrimitiveType _prim); // per-vertex
694 bool isVisible(const Vec3& _origin, float _radius); // sphere
695 bool isVisible(const Vec3& _min, const Vec3& _max); // axis-aligned box
696
697 // Gizmo state.
698
699 bool m_gizmoLocal; // Global mode selection for gizmos.
701 Id m_activeId; // Currently active gizmo. If set, this is the same as m_hotId.
702 Id m_hotId; // ID of the current 'hot' gizmo (nearest intersecting gizmo along the cursor ray). NB this is the id of the *sub* gizmo, not the app-specified ID.
703 float m_hotDepth; // Depth of the current hot gizmo along the cursor ray, for handling occlusion.
704 Id m_appId; // Current ID *without* the hashing the ID stack (= _id arg to Gizmo* functions).
705 Id m_appActiveId; // Copied from m_appId for the current active gizmo.
706 Id m_appHotId; // Copied from m_appId for the current 'hot' gizmo.
707 Vec3 m_gizmoStateVec3; // Stored state for the active gizmo.
710 float m_gizmoHeightPixels; // Height/radius of gizmos.
711 float m_gizmoSizePixels; // Thickness of gizmo lines.
712
713
714 // Stats, debugging.
715
716 // Return the total number of primitives (sorted + unsorted) of the given _type in all layers.
717 U32 getPrimitiveCount(DrawPrimitiveType _type) const;
718
719 // Return the total number of text primitives in all layers.
720 U32 getTextCount() const;
721
722 // Return the number of layers.
723 U32 getLayerCount() const { return m_layerIdMap.size(); }
724
725private:
726
727 // State stacks.
735
736 // Vertex data: one list per layer, per primitive type, *2 for sorted/unsorted.
738 Vector<VertexList*> m_vertexData[2]; // Each layer is DrawPrimitive_Count consecutive lists.
739 int m_vertexDataIndex; // 0, or 1 if sorting enabled.
740 Vector<Id> m_layerIdMap; // Map Id -> vertex data index.
741 int m_layerIndex; // Index of the currently active layer in m_layerIdMap.
742 Vector<DrawList> m_drawLists; // All draw lists for the current frame, available after calling endFrame() before calling reset().
743 bool m_sortCalled; // Avoid calling sort() during every call to draw().
744 bool m_endFrameCalled; // For assert, if vertices are pushed after endFrame() was called.
745
746 // Text data: one list per layer.
751
752 // Primitive state.
755 U32 m_firstVertThisPrim; // Index of the first vertex pushed during this primitive.
756 U32 m_vertCountThisPrim; // # calls to vertex() since the last call to begin().
759
760 // App data.
762 bool m_keyDownCurr[Key_Count]; // Key state captured during reset().
763 bool m_keyDownPrev[Key_Count]; // Key state from previous frame.
764 Vec4 m_cullFrustum[FrustumPlane_Count]; // Optimized frustum planes from m_appData.m_cullFrustum.
765 int m_cullFrustumCount; // # valid frustum planes in m_cullFrustum.
766
767 // Sort primitive data.
768 void sort();
769
770 // Return -1 if _id not found.
771 int findLayerIndex(Id _id) const;
772
773 // Access the current vertex/text data based on m_layerIndex.
774 VertexList* getCurrentVertexList();
775 TextList* getCurrentTextList();
776};
777
778namespace internal {
779
780#if IM3D_THREAD_LOCAL_CONTEXT_PTR
781 #define IM3D_THREAD_LOCAL thread_local
782#else
783 #define IM3D_THREAD_LOCAL
784#endif
785
786extern IM3D_THREAD_LOCAL Context* g_CurrentContext;
787
788}
789
790inline AppData& GetAppData() { return GetContext().getAppData(); }
791inline void NewFrame() { GetContext().reset(); }
792inline void EndFrame() { GetContext().endFrame(); }
793inline void Draw() { GetContext().draw(); }
794
795inline const DrawList* GetDrawLists() { return GetContext().getDrawLists(); }
797
800
807inline void End() { GetContext().end(); }
808
809inline void Vertex(const Vec3& _position) { GetContext().vertex(_position, GetContext().getSize(), GetContext().getColor()); }
810inline void Vertex(const Vec3& _position, Color _color) { GetContext().vertex(_position, GetContext().getSize(), _color); }
811inline void Vertex(const Vec3& _position, float _size) { GetContext().vertex(_position, _size, GetContext().getColor()); }
812inline void Vertex(const Vec3& _position, float _size, Color _color) { GetContext().vertex(_position, _size, _color); }
813inline void Vertex(float _x, float _y, float _z) { Vertex(Vec3(_x, _y, _z)); }
814inline void Vertex(float _x, float _y, float _z, Color _color) { Vertex(Vec3(_x, _y, _z), _color); }
815inline void Vertex(float _x, float _y, float _z, float _size) { Vertex(Vec3(_x, _y, _z), _size); }
816inline void Vertex(float _x, float _y, float _z, float _size, Color _color) { Vertex(Vec3(_x, _y, _z), _size, _color); }
817
818inline void PushDrawState() { Context& ctx = GetContext(); ctx.pushColor(ctx.getColor()); ctx.pushAlpha(ctx.getAlpha()); ctx.pushSize(ctx.getSize()); ctx.pushEnableSorting(ctx.getEnableSorting()); }
819inline void PopDrawState() { Context& ctx = GetContext(); ctx.popColor(); ctx.popAlpha(); ctx.popSize(); ctx.popEnableSorting(); }
820
821inline void PushColor() { GetContext().pushColor(GetContext().getColor()); }
822inline void PushColor(Color _color) { GetContext().pushColor(_color); }
823inline void PopColor() { GetContext().popColor(); }
824inline void SetColor(Color _color) { GetContext().setColor(_color); }
825inline void SetColor(float _r, float _g, float _b, float _a) { GetContext().setColor(Color(_r, _g, _b, _a)); }
826inline Color GetColor() { return GetContext().getColor(); }
827
828inline void PushAlpha() { GetContext().pushAlpha(GetContext().getAlpha()); }
829inline void PushAlpha(float _alpha) { GetContext().pushAlpha(_alpha); }
830inline void PopAlpha() { GetContext().popAlpha(); }
831inline void SetAlpha(float _alpha) { GetContext().setAlpha(_alpha); }
832inline float GetAlpha() { return GetContext().getAlpha(); }
833
834inline void PushSize() { GetContext().pushSize(GetContext().getAlpha()); }
835inline void PushSize(float _size) { GetContext().pushSize(_size); }
836inline void PopSize() { GetContext().popSize(); }
837inline void SetSize(float _size) { GetContext().setSize(_size); }
838inline float GetSize() { return GetContext().getSize(); }
839
840inline void PushEnableSorting() { GetContext().pushEnableSorting(GetContext().getEnableSorting()); }
841inline void PushEnableSorting(bool _enable) { GetContext().pushEnableSorting(_enable); }
843inline void EnableSorting(bool _enable) { GetContext().setEnableSorting(_enable); }
844
845inline void PushMatrix() { GetContext().pushMatrix(GetContext().getMatrix()); }
846inline void PushMatrix(const Mat4& _mat4) { GetContext().pushMatrix(_mat4); }
847inline void PopMatrix() { GetContext().popMatrix(); }
848inline void SetMatrix(const Mat4& _mat4) { GetContext().setMatrix(_mat4); }
849inline void SetIdentity() { GetContext().setMatrix(Mat4(1.0f)); }
850
851inline void PushId() { GetContext().pushId(GetContext().getId()); }
852inline void PushId(Id _id) { GetContext().pushId(_id); }
853inline void PushId(const char* _str) { GetContext().pushId(MakeId(_str)); }
854inline void PushId(const void* _ptr) { GetContext().pushId(MakeId(_ptr)); }
855inline void PushId(int _i) { GetContext().pushId(MakeId(_i)); }
856inline void PopId() { GetContext().popId(); }
857inline Id GetId() { return GetContext().getId(); }
858
859inline void PushLayerId() { GetContext().pushLayerId(GetContext().getLayerId()); }
860inline void PushLayerId(Id _layer) { GetContext().pushLayerId(_layer); }
861inline void PushLayerId(const char* _str) { PushLayerId(MakeId(_str)); }
862inline void PopLayerId() { GetContext().popLayerId(); }
863inline Id GetLayerId() { return GetContext().getLayerId(); }
864
865inline bool GizmoTranslation(const char* _id, float _translation_[3], bool _local) { return GizmoTranslation(MakeId(_id), _translation_, _local); }
866inline bool GizmoRotation(const char* _id, float _rotation_[3*3], bool _local) { return GizmoRotation(MakeId(_id), _rotation_, _local);}
867inline bool GizmoScale(const char* _id, float _scale_[3]) { return GizmoScale(MakeId(_id), _scale_); }
868inline bool Gizmo(const char* _id, float _translation_[3], float _rotation_[3*3], float _scale_[3]) { return Gizmo(MakeId(_id), _translation_, _rotation_, _scale_); }
869inline bool Gizmo(const char* _id, float _transform_[4*4]) { return Gizmo(MakeId(_id), _transform_); }
871inline Id GetHotId() { return GetContext().m_appHotId; }
872
873inline bool IsVisible(const Vec3& _origin, float _radius) { return GetContext().isVisible(_origin, _radius); }
874inline bool IsVisible(const Vec3& _min, const Vec3& _max) { return GetContext().isVisible(_min, _max);}
875
876inline Context& GetContext() { return *internal::g_CurrentContext; }
877inline void SetContext(Context& _ctx) { internal::g_CurrentContext = &_ctx; }
878inline void MergeContexts(Context& _dst_, const Context& _src) { _dst_.merge(_src); }
879
880} // namespac Im3d
#define IM3D_API
Definition im3d.h:8
#define IM3D_THREAD_LOCAL
Definition im3d.h:783
#define IM3D_VEC4_APP
Definition im3d_config.h:47
#define IM3D_VEC2_APP
Definition im3d_config.h:37
#define IM3D_VEC3_APP
Definition im3d_config.h:40
#define IM3D_ASSERT(e)
Definition im3d_config.h:13
#define IM3D_MAT3_APP
Definition im3d_config.h:52
#define IM3D_MAT4_APP
Definition im3d_config.h:55
Definition im3d.h:22
IM3D_API void PushDrawState()
Definition im3d.h:818
IM3D_API AppData & GetAppData()
Definition im3d.h:790
IM3D_API void NewFrame()
Definition im3d.h:791
IM3D_API void DrawXyzAxes()
Definition im3d.cpp:144
IM3D_API void DrawCapsule(const Vec3 &_start, const Vec3 &_end, float _radius, int _detail=-1)
Definition im3d.cpp:502
IM3D_API void Vertex(const Vec3 &_position)
Definition im3d.h:809
IM3D_API void PushLayerId(Id _layer)
Definition im3d.h:860
IM3D_API void PopEnableSorting()
Definition im3d.h:842
IM3D_API void End()
Definition im3d.h:807
constexpr Color Color_Red
Definition im3d.h:406
IM3D_API void DrawArrow(const Vec3 &_start, const Vec3 &_end, float _headLength=-1.0f, float _headThickness=-1.0f)
Definition im3d.cpp:596
IM3D_API void BeginLines()
Definition im3d.h:802
constexpr Color Color_White
Definition im3d.h:404
IM3D_API void EnableSorting(bool _enable)
Definition im3d.h:843
IM3D_API void SetMatrix(const Mat4 &_mat4)
Definition im3d.h:848
GizmoMode
Definition im3d.h:591
@ GizmoMode_Rotation
Definition im3d.h:593
@ GizmoMode_Translation
Definition im3d.h:592
@ GizmoMode_Scale
Definition im3d.h:594
IM3D_API float GetSize()
Definition im3d.h:838
U32 Id
Definition im3d.h:37
constexpr Color Color_Orange
Definition im3d.h:414
IM3D_API Id GetLayerId()
Definition im3d.h:863
constexpr Color Color_Magenta
Definition im3d.h:409
IM3D_API void BeginTriangles()
Definition im3d.h:805
IM3D_API void BeginLineLoop()
Definition im3d.h:803
IM3D_API Id GetId()
Definition im3d.h:857
IM3D_API void Draw()
Definition im3d.h:793
constexpr Color Color_Purple
Definition im3d.h:417
IM3D_API Id GetHotId()
Definition im3d.h:871
IM3D_API void EndFrame()
Definition im3d.h:792
IM3D_API void MulMatrix(const Mat4 &_mat4)
Definition im3d.cpp:112
IM3D_API void DrawSphereFilled(const Vec3 &_origin, float _radius, int _detail=-1)
Definition im3d.cpp:322
IM3D_API void PushMatrix()
Definition im3d.h:845
IM3D_API void PopColor()
Definition im3d.h:823
IM3D_API U32 GetDrawListCount()
Definition im3d.h:796
IM3D_API void PopDrawState()
Definition im3d.h:819
IM3D_API U32 GetTextDrawListCount()
Definition im3d.h:799
IM3D_API void BeginPoints()
Definition im3d.h:801
IM3D_API void DrawCylinder(const Vec3 &_start, const Vec3 &_end, float _radius, int _detail=-1)
Definition im3d.cpp:459
IM3D_API void SetIdentity()
Definition im3d.h:849
IM3D_API void PushColor()
Definition im3d.h:821
constexpr Id Id_Invalid
Definition im3d.h:38
IM3D_API bool IsVisible(const Vec3 &_origin, float _radius)
Definition im3d.h:873
IM3D_API void SetContext(Context &_ctx)
Definition im3d.h:877
constexpr Color Color_Teal
Definition im3d.h:418
constexpr Color Color_Gold
Definition im3d.h:415
constexpr Color Color_Brown
Definition im3d.h:416
IM3D_API void DrawQuadFilled(const Vec3 &_a, const Vec3 &_b, const Vec3 &_c, const Vec3 &_d)
Definition im3d.cpp:196
IM3D_API Context & GetContext()
Definition im3d.h:876
IM3D_API void Translate(float _x, float _y, float _z)
Definition im3d.cpp:117
IM3D_API const DrawList * GetDrawLists()
Definition im3d.h:795
IM3D_API bool GizmoRotation(const char *_id, float _rotation_[3 *3], bool _local=false)
Definition im3d.h:866
constexpr Color Color_Pink
Definition im3d.h:413
constexpr Color Color_Green
Definition im3d.h:407
IM3D_API void BeginLineStrip()
Definition im3d.h:804
constexpr Color Color_Blue
Definition im3d.h:408
IM3D_API void PopAlpha()
Definition im3d.h:830
IM3D_API void PopMatrix()
Definition im3d.h:847
DrawPrimitiveType
Definition im3d.h:431
@ DrawPrimitive_Lines
Definition im3d.h:434
@ DrawPrimitive_Count
Definition im3d.h:437
@ DrawPrimitive_Points
Definition im3d.h:435
@ DrawPrimitive_Triangles
Definition im3d.h:433
IM3D_API void BeginTriangleStrip()
Definition im3d.h:806
IM3D_API void PushEnableSorting()
Definition im3d.h:840
constexpr Color Color_Yellow
Definition im3d.h:410
IM3D_API void SetAlpha(float _alpha)
Definition im3d.h:831
IM3D_API void DrawCircle(const Vec3 &_origin, const Vec3 &_normal, float _radius, int _detail=-1)
Definition im3d.cpp:220
IM3D_API Id GetActiveId()
Definition im3d.h:870
IM3D_API void DrawQuad(const Vec3 &_a, const Vec3 &_b, const Vec3 &_c, const Vec3 &_d)
Definition im3d.cpp:174
constexpr Color Color_Gray
Definition im3d.h:405
void PushLayerId()
Definition im3d.h:859
IM3D_API void PushId()
Definition im3d.h:851
IM3D_API void DrawLine(const Vec3 &_a, const Vec3 &_b, float _size, Color _color)
Definition im3d.cpp:166
PrimitiveMode
Definition im3d.h:581
@ PrimitiveMode_Triangles
Definition im3d.h:587
@ PrimitiveMode_None
Definition im3d.h:582
@ PrimitiveMode_LineLoop
Definition im3d.h:586
@ PrimitiveMode_Lines
Definition im3d.h:584
@ PrimitiveMode_Points
Definition im3d.h:583
@ PrimitiveMode_TriangleStrip
Definition im3d.h:588
@ PrimitiveMode_LineStrip
Definition im3d.h:585
IM3D_API bool GizmoTranslation(const char *_id, float _translation_[3], bool _local=false)
Definition im3d.h:865
constexpr Color Color_Black
Definition im3d.h:403
IM3D_API void PopSize()
Definition im3d.h:836
IM3D_API void DrawAlignedBoxFilled(const Vec3 &_min, const Vec3 &_max)
Definition im3d.cpp:404
IM3D_API void SetSize(float _size)
Definition im3d.h:837
IM3D_API void DrawPrism(const Vec3 &_start, const Vec3 &_end, float _radius, int _sides)
Definition im3d.cpp:560
constexpr Color Color_Cyan
Definition im3d.h:411
IM3D_API Id MakeId(const char *_str)
Definition im3d.cpp:662
IM3D_API void Rotate(const Vec3 &_axis, float _angle)
Definition im3d.cpp:127
IM3D_API bool GizmoScale(const char *_id, float _scale_[3])
Definition im3d.h:867
IM3D_API void PopLayerId()
Definition im3d.h:862
unsigned int U32
Definition im3d.h:24
TextFlags
Definition im3d.h:450
@ TextFlags_AlignLeft
Definition im3d.h:451
@ TextFlags_AlignTop
Definition im3d.h:453
@ TextFlags_Default
Definition im3d.h:456
IM3D_API void PushAlpha()
Definition im3d.h:828
FrustumPlane
Definition im3d.h:497
@ FrustumPlane_Right
Definition im3d.h:501
@ FrustumPlane_Near
Definition im3d.h:498
@ FrustumPlane_Count
Definition im3d.h:505
@ FrustumPlane_Bottom
Definition im3d.h:502
@ FrustumPlane_Top
Definition im3d.h:500
@ FrustumPlane_Left
Definition im3d.h:503
@ FrustumPlane_Far
Definition im3d.h:499
Key
Definition im3d.h:477
@ Action_GizmoTranslation
Definition im3d.h:491
@ Action_GizmoLocal
Definition im3d.h:488
@ Action_Select
Definition im3d.h:487
@ Action_GizmoRotation
Definition im3d.h:489
@ Key_Count
Definition im3d.h:484
@ Action_GizmoScale
Definition im3d.h:490
@ Key_S
Definition im3d.h:481
@ Key_R
Definition im3d.h:480
@ Key_L
Definition im3d.h:479
@ Mouse_Left
Definition im3d.h:478
@ Action_Count
Definition im3d.h:493
@ Key_T
Definition im3d.h:482
IM3D_API void PopId()
Definition im3d.h:856
IM3D_API Color GetColor()
Definition im3d.h:826
IM3D_API float GetAlpha()
Definition im3d.h:832
IM3D_API void DrawPoint(const Vec3 &_position, float _size, Color _color)
Definition im3d.cpp:159
constexpr Color Color_Navy
Definition im3d.h:419
IM3D_API void MergeContexts(Context &_dst_, const Context &_src)
Definition im3d.h:878
IM3D_API const TextDrawList * GetTextDrawLists()
Definition im3d.h:798
IM3D_API bool Gizmo(const char *_id, float _translation_[3], float _rotation_[3 *3], float _scale_[3])
Definition im3d.h:868
void DrawPrimitivesCallback(const DrawList &_drawList)
Definition im3d.h:447
IM3D_API void PushSize()
Definition im3d.h:834
IM3D_API void SetColor(Color _color)
Definition im3d.h:824
IM3D_API void DrawAlignedBox(const Vec3 &_min, const Vec3 &_max)
Definition im3d.cpp:372
IM3D_API void DrawSphere(const Vec3 &_origin, float _radius, int _detail=-1)
Definition im3d.cpp:281
IM3D_API void DrawCircleFilled(const Vec3 &_origin, const Vec3 &_normal, float _radius, int _detail=-1)
Definition im3d.cpp:247
IM3D_API void Scale(float _x, float _y, float _z)
Definition im3d.cpp:137
Definition im3d.h:509
Definition im3d.h:359
void set(int _i, float _val)
Definition im3d.h:370
float getB() const
Definition im3d.h:389
void setG(float _val)
Definition im3d.h:377
float getR() const
Definition im3d.h:387
void setB(float _val)
Definition im3d.h:378
constexpr Color(U32 _rgba)
Definition im3d.h:363
constexpr Color()
Definition im3d.h:362
void setR(float _val)
Definition im3d.h:376
float getA() const
Definition im3d.h:390
U32 getABGR() const
Definition im3d.h:392
U32 v
Definition im3d.h:360
float getG() const
Definition im3d.h:388
void setA(float _val)
Definition im3d.h:379
float get(int _i) const
Definition im3d.h:381
Definition im3d.h:599
bool getEnableSorting() const
Definition im3d.h:640
DrawPrimitiveType m_primType
Definition im3d.h:754
bool isKeyDown(Key _key) const
Definition im3d.h:689
Vector< char > m_textBuffer
Definition im3d.h:749
float getAlpha() const
Definition im3d.h:630
Vector< TextList * > m_textData
Definition im3d.h:748
bool m_sortCalled
Definition im3d.h:743
Vector< bool > m_enableSortingStack
Definition im3d.h:731
U32 m_vertCountThisPrim
Definition im3d.h:756
Vector< float > m_alphaStack
Definition im3d.h:729
void setColor(Color _color)
Definition im3d.h:624
void endFrame()
Definition im3d.cpp:1772
void popEnableSorting()
Definition im3d.cpp:1828
void popColor()
Definition im3d.h:627
void popLayerId()
Definition im3d.cpp:1862
void vertex(const Vec3 &_position, float _size, Color _color)
Definition im3d.cpp:1503
void popId()
Definition im3d.h:656
void setMatrix(const Mat4 &_mat4)
Definition im3d.h:648
void pushMatrix(const Mat4 &_mat4)
Definition im3d.h:650
Id m_appActiveId
Definition im3d.h:705
float m_gizmoHeightPixels
Definition im3d.h:710
void pushLayerId(Id _layer)
Definition im3d.cpp:1841
Vector< Mat4 > m_matrixStack
Definition im3d.h:732
void pushSize(float _size)
Definition im3d.h:636
void begin(PrimitiveMode _mode)
Definition im3d.cpp:1418
PrimitiveMode m_primMode
Definition im3d.h:753
float m_hotDepth
Definition im3d.h:703
U32 m_firstVertThisPrim
Definition im3d.h:755
void reset()
Definition im3d.cpp:1651
Id getLayerId() const
Definition im3d.h:644
U32 getTextDrawListCount() const
Definition im3d.h:621
void merge(const Context &_src)
Definition im3d.cpp:1728
Id getId() const
Definition im3d.h:654
void pushEnableSorting(bool _enable)
Definition im3d.cpp:1822
void setSize(float _size)
Definition im3d.h:634
int m_cullFrustumCount
Definition im3d.h:765
Vector< Id > m_layerIdMap
Definition im3d.h:740
Vec3 m_gizmoStateVec3
Definition im3d.h:707
int m_vertexDataIndex
Definition im3d.h:739
void setId(Id _id)
Definition im3d.h:653
Vector< TextDrawList > m_textDrawLists
Definition im3d.h:750
Vector< TextData > TextList
Definition im3d.h:747
Vec3 m_maxVertThisPrim
Definition im3d.h:758
void end()
Definition im3d.cpp:1444
void draw()
Definition im3d.cpp:1808
bool m_gizmoLocal
Definition im3d.h:699
const Mat4 & getMatrix() const
Definition im3d.h:649
Vector< float > m_sizeStack
Definition im3d.h:730
void pushColor(Color _color)
Definition im3d.h:626
float m_gizmoSizePixels
Definition im3d.h:711
AppData & getAppData()
Definition im3d.h:658
Id m_appId
Definition im3d.h:704
GizmoMode m_gizmoMode
Definition im3d.h:700
Vector< Id > m_idStack
Definition im3d.h:733
Mat3 m_gizmoStateMat3
Definition im3d.h:708
Id m_hotId
Definition im3d.h:702
void setAlpha(float _alpha)
Definition im3d.h:629
void vertex(const Vec3 &_position)
Definition im3d.h:607
float getSize() const
Definition im3d.h:635
Id m_appHotId
Definition im3d.h:706
bool isVisible(const VertexData *_vdata, DrawPrimitiveType _prim)
Definition im3d.cpp:2085
Vector< VertexData > VertexList
Definition im3d.h:737
Vector< Color > m_colorStack
Definition im3d.h:728
void popMatrix()
Definition im3d.h:651
Vector< DrawList > m_drawLists
Definition im3d.h:742
const DrawList * getDrawLists() const
Definition im3d.h:617
void popSize()
Definition im3d.h:637
void pushAlpha(float _alpha)
Definition im3d.h:631
Vector< Id > m_layerIdStack
Definition im3d.h:734
void pushId(Id _id)
Definition im3d.h:655
void setEnableSorting(bool _enable)
Definition im3d.cpp:1834
AppData m_appData
Definition im3d.h:761
bool wasKeyPressed(Key _key) const
Definition im3d.h:690
void popAlpha()
Definition im3d.h:632
float m_gizmoStateFloat
Definition im3d.h:709
U32 getLayerCount() const
Definition im3d.h:723
Color getColor() const
Definition im3d.h:625
bool m_endFrameCalled
Definition im3d.h:744
const TextDrawList * getTextDrawLists() const
Definition im3d.h:620
Id m_activeId
Definition im3d.h:701
U32 getDrawListCount() const
Definition im3d.h:618
Vec3 m_minVertThisPrim
Definition im3d.h:757
int m_layerIndex
Definition im3d.h:741
Definition im3d.h:441
const VertexData * m_vertexData
Definition im3d.h:444
Id m_layerId
Definition im3d.h:442
DrawPrimitiveType m_primType
Definition im3d.h:443
U32 m_vertexCount
Definition im3d.h:445
Definition im3d.h:256
Mat3()
Definition im3d.h:259
float operator()(int _row, int _col) const
Definition im3d.h:280
float & operator()(int _row, int _col)
Definition im3d.h:289
Definition im3d.h:305
Mat4()
Definition im3d.h:308
float & operator()(int _row, int _col)
Definition im3d.h:343
float operator()(int _row, int _col) const
Definition im3d.h:334
Definition im3d.h:460
Vec4 m_positionSize
Definition im3d.h:461
U32 m_flags
Definition im3d.h:463
U32 m_textLength
Definition im3d.h:464
Color m_color
Definition im3d.h:462
U32 m_textBufferOffset
Definition im3d.h:465
Definition im3d.h:469
Id m_layerId
Definition im3d.h:470
const TextData * m_textData
Definition im3d.h:471
const char * m_textBuffer
Definition im3d.h:473
U32 m_textDataCount
Definition im3d.h:472
Definition im3d.h:204
Vec2(float _xy)
Definition im3d.h:208
Vec2(float _x, float _y)
Definition im3d.h:209
Vec2()
Definition im3d.h:207
float x
Definition im3d.h:205
Definition im3d.h:220
Vec3(float _xyz)
Definition im3d.h:224
Vec3(const Vec2 &_xy, float _z)
Definition im3d.h:226
float x
Definition im3d.h:221
Vec3(float _x, float _y, float _z)
Definition im3d.h:225
Vec3()
Definition im3d.h:223
Definition im3d.h:238
Vec4()
Definition im3d.h:241
Vec4(float _x, float _y, float _z, float _w)
Definition im3d.h:243
Vec4(const Vec3 &_xyz, float _w)
Definition im3d.h:244
Vec4(float _xyzw)
Definition im3d.h:242
float w
Definition im3d.h:239
Definition im3d.h:537
U32 size() const
Definition im3d.h:561
bool empty() const
Definition im3d.h:563
const T & front() const
Definition im3d.h:557
T * end()
Definition im3d.h:554
void append(const Vector< T > &_other)
Definition im3d.h:550
T & push_back()
Definition im3d.h:546
void push_back(const T &_v)
Definition im3d.h:547
T * begin()
Definition im3d.h:552
T & front()
Definition im3d.h:556
const T * begin() const
Definition im3d.h:553
Vector()
Definition im3d.h:538
void pop_back()
Definition im3d.h:548
U32 capacity() const
Definition im3d.h:562
const T * data() const
Definition im3d.h:544
const T & back() const
Definition im3d.h:559
const T * end() const
Definition im3d.h:555
T & operator[](U32 _i)
Definition im3d.h:541
T & back()
Definition im3d.h:558
void clear()
Definition im3d.h:565
T * data()
Definition im3d.h:543
const T & operator[](U32 _i) const
Definition im3d.h:542
Definition im3d.h:422
VertexData()
Definition im3d.h:426
Color m_color
Definition im3d.h:424
VertexData(const Vec3 &_position, float _size, Color _color)
Definition im3d.h:427
Vec4 m_positionSize
Definition im3d.h:423