summaryrefslogtreecommitdiff
path: root/Runtime/GUI/UILine.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-20 14:10:24 +0800
committerchai <chaifix@163.com>2021-11-20 14:10:24 +0800
commit74ca8143a7c2352425d549b681b2838bda5ee218 (patch)
tree5aad35e7312b7c1b54769091b30f47d8ad747acb /Runtime/GUI/UILine.cpp
parent850d9c034792b96e2ff5ff3bbfbcc30661757aed (diff)
*misc
Diffstat (limited to 'Runtime/GUI/UILine.cpp')
-rw-r--r--Runtime/GUI/UILine.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/Runtime/GUI/UILine.cpp b/Runtime/GUI/UILine.cpp
new file mode 100644
index 0000000..8db681e
--- /dev/null
+++ b/Runtime/GUI/UILine.cpp
@@ -0,0 +1,48 @@
+#include "UILine.h"
+
+struct UILineLayout
+{
+ Vector2 position;
+};
+
+static CustomVertexLayout layout;
+
+InitializeStaticVariables([]() {
+ VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(UILineLayout));
+
+ layout.attributes.push_back(POSITION);
+});
+
+void UILine::Draw()
+{
+ const int nVerts = 2;
+ const int nIndices = 2;
+
+ float pos[] = {
+ m_From.x, m_From.y,
+ m_To.x, m_To.y,
+ };
+
+ uint16 indices[] = {
+ 0, 1
+ };
+
+
+ uint8* vb;
+ uint16* ib;
+
+ g_SharedVBO.GetChunk(sizeof(UILineLayout), sizeof(uint16), nVerts, nIndices, Primitive_Line, (void**)&vb, (void**)&ib);
+
+ UILineLayout* dst = (UILineLayout*)vb;
+
+ for (int i = 0; i < nVerts; ++i)
+ {
+ dst[i].position.Set(pos[2 * i], pos[2 * i + 1]);
+ }
+
+ for (int i = 0; i < nIndices; ++i)
+ ib[i] = indices[i];
+
+ g_SharedVBO.ReleaseChunk(nVerts, nIndices);
+ g_SharedVBO.DrawChunk(layout);
+} \ No newline at end of file