summaryrefslogtreecommitdiff
path: root/Client/Source/GUI/UIQuad.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-12-13 00:07:19 +0800
committerchai <chaifix@163.com>2021-12-13 00:07:19 +0800
commit60cbbdec07ab7a5636eac5b3c024ae44e937f4d4 (patch)
treeb2c7b0a868f18159dbc43d8954e1bd7668549a88 /Client/Source/GUI/UIQuad.cpp
+init
Diffstat (limited to 'Client/Source/GUI/UIQuad.cpp')
-rw-r--r--Client/Source/GUI/UIQuad.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/Client/Source/GUI/UIQuad.cpp b/Client/Source/GUI/UIQuad.cpp
new file mode 100644
index 0000000..d3c7825
--- /dev/null
+++ b/Client/Source/GUI/UIQuad.cpp
@@ -0,0 +1,64 @@
+#include "../Math/Math.h"
+#include "../Graphics/GfxDevice.h"
+
+#include "UIQuad.h"
+
+struct UIQuadLayout
+{
+ Vector2f position;
+ Vector2f uv;
+};
+
+static CustomVertexLayout layout;
+
+InitializeStaticVariables([]() {
+ VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(UIQuadLayout));
+ VertexAttributeDescriptor UV = VertexAttributeDescriptor(sizeof(Vector2f), 2, VertexAttrFormat_Float, sizeof(UIQuadLayout));
+
+ layout.attributes.push_back(POSITION);
+ layout.attributes.push_back(UV);
+});
+
+void UIQuad::Draw()
+{
+ const int nVerts = 4;
+ const int nIndices = 6;
+
+ float pos[] = {
+ m_Left, m_Bottom, // left-bottom
+ m_Right, m_Bottom, // right-bottom
+ m_Right, m_Top, // right-top
+ m_Left, m_Top, // top-left
+ };
+
+ float uv[] = {
+ 0, 0,
+ 1, 0,
+ 1, 1,
+ 0, 1,
+ };
+
+ uint16 indices[] = {
+ 0, 1, 3, // right-top
+ 1, 2, 3, // left-bottom
+ };
+
+ uint8* vb;
+ uint16* ib;
+
+ g_SharedVBO.GetChunk(sizeof(UIQuadLayout), sizeof(uint16), nVerts, nIndices, Primitive_Triangle, (void**)&vb, (void**)&ib);
+
+ UIQuadLayout* dst = (UIQuadLayout*)vb;
+
+ for (int i = 0; i < nVerts; ++i)
+ {
+ dst[i].position.Set(pos[2 * i], pos[2 * i + 1]);
+ dst[i].uv.Set(uv[2 * i], uv[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