diff options
author | chai <chaifix@163.com> | 2021-11-18 19:14:35 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-18 19:14:35 +0800 |
commit | 2ab7fad7b308debba0aacbf76831569f360d19a0 (patch) | |
tree | a28f4b6ed64ef9782be0f009ca9e458a709e34ca /Runtime/GUI/UISquare.cpp | |
parent | 6198d0c32b5416b328b55c4c4e5b760c745952c7 (diff) |
*misc
Diffstat (limited to 'Runtime/GUI/UISquare.cpp')
-rw-r--r-- | Runtime/GUI/UISquare.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Runtime/GUI/UISquare.cpp b/Runtime/GUI/UISquare.cpp new file mode 100644 index 0000000..214435e --- /dev/null +++ b/Runtime/GUI/UISquare.cpp @@ -0,0 +1,52 @@ +#include "../Graphics/GfxDevice.h" +#include "UISquare.h" +#include "Runtime/Math/Math.h" + +struct UISquareLayout +{ + Vector2 position; +}; + +static CustomVertexLayout layout; + +InitializeStaticVariables([]() { + VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(UISquareLayout)); + + layout.attributes.push_back(POSITION); +}); + +void UISquare::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 + }; + + int indices[] = { + 0, 1, 3, // right-top + 1, 2, 3, // left-bottom + }; + + uint8* vb; + uint16* ib; + + g_SharedVBO.GetChunk(sizeof(UISquareLayout), sizeof(uint16), 4, 6, Primitive_Triangle, (void**)&vb, (void**)&ib); + + UISquareLayout* dst = (UISquareLayout*)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(4, 6); + g_SharedVBO.DrawChunk(layout); +}
\ No newline at end of file |