diff options
author | chai <chaifix@163.com> | 2021-10-28 01:52:12 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-28 01:52:12 +0800 |
commit | 80dca084b568e4e77d2a4031ce8625cdabc660ab (patch) | |
tree | d8c0172aeddca648ec89cbbbda72a938f3ef7433 /Runtime/Graphics/UIQuad.cpp | |
parent | 1b6f71b2777bdc74d63f988346a8cfee766718b0 (diff) |
+ custom vertex buffer
Diffstat (limited to 'Runtime/Graphics/UIQuad.cpp')
-rw-r--r-- | Runtime/Graphics/UIQuad.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Runtime/Graphics/UIQuad.cpp b/Runtime/Graphics/UIQuad.cpp new file mode 100644 index 0000000..5f1a54d --- /dev/null +++ b/Runtime/Graphics/UIQuad.cpp @@ -0,0 +1,61 @@ +#include "../Math/Vector2.h" +#include "GfxDevice.h" +#include "UIQuad.h" + +struct UIQuadLayout +{ + Vector2 position; + Vector2 uv; +}; + +void UIQuad::Draw() +{ + CustomVertexLayout layout; + + VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(UIQuadLayout)); + VertexAttributeDescriptor UV = VertexAttributeDescriptor(sizeof(Vector2), 2, VertexAttrFormat_Float, sizeof(UIQuadLayout)); + + layout.attributes.push_back(POSITION); + layout.attributes.push_back(UV); + + 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, + }; + + int indices[] = { + 0, 1, 3, // right-top + 1, 2, 3, // left-bottom + }; + + uint8* vb; + uint16* ib; + + g_SharedVBO.GetChunk(sizeof(UIQuadLayout), sizeof(uint16), 4, 6, Primitive_Triangle, (void**)&vb, (void**)&ib); + + UIQuadLayout* dst = (UIQuadLayout*)vb; + + for (int i = 0; i < nVerts; ++i) + { + dst[i].position.Set(pos[3 * i], pos[3 * 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(4, 6); + g_SharedVBO.DrawChunk(layout); +}
\ No newline at end of file |