diff options
Diffstat (limited to 'Runtime/GUI')
-rw-r--r-- | Runtime/GUI/UILine.cpp | 48 | ||||
-rw-r--r-- | Runtime/GUI/UILine.h | 21 | ||||
-rw-r--r-- | Runtime/GUI/UIMesh.h | 1 | ||||
-rw-r--r-- | Runtime/GUI/UIQuad.cpp | 8 |
4 files changed, 73 insertions, 5 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 diff --git a/Runtime/GUI/UILine.h b/Runtime/GUI/UILine.h new file mode 100644 index 0000000..a47b1f1 --- /dev/null +++ b/Runtime/GUI/UILine.h @@ -0,0 +1,21 @@ +#pragma once + +#include "../Utilities/StaticInitiator.h" +#include "UIMesh.h" + +class UILine : public UIMesh +{ +public: + UILine(Vector2f from, Vector2f to) + { + m_From = from; + m_To = to; + } + + void Draw() override; + +private: + Vector2f m_From; + Vector2f m_To; + +}; diff --git a/Runtime/GUI/UIMesh.h b/Runtime/GUI/UIMesh.h index 8b6b56d..1de111b 100644 --- a/Runtime/GUI/UIMesh.h +++ b/Runtime/GUI/UIMesh.h @@ -9,6 +9,7 @@ #include "Runtime/Graphics/Color.h" #include "Runtime/Graphics/GfxDevice.h" +// UI默认的顶点布局 struct UIVertexLayout { UIVertexLayout(Vector2 pos = Vector2::zero, Vector2 texCoord = Vector2::zero, Color32 col = Color32()) diff --git a/Runtime/GUI/UIQuad.cpp b/Runtime/GUI/UIQuad.cpp index c57685c..269b805 100644 --- a/Runtime/GUI/UIQuad.cpp +++ b/Runtime/GUI/UIQuad.cpp @@ -30,8 +30,6 @@ void UIQuad::Draw() m_Left, m_Top, // top-left }; - int n = sizeof(Vector2); - float uv[] = { 0, 0, 1, 0, @@ -39,7 +37,7 @@ void UIQuad::Draw() 0, 1, }; - int indices[] = { + uint16 indices[] = { 0, 1, 3, // right-top 1, 2, 3, // left-bottom }; @@ -47,7 +45,7 @@ void UIQuad::Draw() uint8* vb; uint16* ib; - g_SharedVBO.GetChunk(sizeof(UIQuadLayout), sizeof(uint16), 4, 6, Primitive_Triangle, (void**)&vb, (void**)&ib); + g_SharedVBO.GetChunk(sizeof(UIQuadLayout), sizeof(uint16), nVerts, nIndices, Primitive_Triangle, (void**)&vb, (void**)&ib); UIQuadLayout* dst = (UIQuadLayout*)vb; @@ -60,6 +58,6 @@ void UIQuad::Draw() for (int i = 0; i < nIndices; ++i) ib[i] = indices[i]; - g_SharedVBO.ReleaseChunk(4, 6); + g_SharedVBO.ReleaseChunk(nVerts, nIndices); g_SharedVBO.DrawChunk(layout); }
\ No newline at end of file |