diff options
author | chai <chaifix@163.com> | 2021-10-27 23:37:24 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-27 23:37:24 +0800 |
commit | 305ca0a09d4e750186b5190432de47f3493e806a (patch) | |
tree | d82f9ef73191abc2acbcbfdca4b184a28e6c381b /Runtime/Graphics/Quad.cpp | |
parent | 51ced5a191078ce4ef08d57e343e91db007f556f (diff) |
*GfxDevice
Diffstat (limited to 'Runtime/Graphics/Quad.cpp')
-rw-r--r-- | Runtime/Graphics/Quad.cpp | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/Runtime/Graphics/Quad.cpp b/Runtime/Graphics/Quad.cpp index aa4c9f5..b98f4f2 100644 --- a/Runtime/Graphics/Quad.cpp +++ b/Runtime/Graphics/Quad.cpp @@ -1,52 +1,52 @@ -//#include "../Math/Vector2.h" -//#include "../Math/Vector3.h" -//#include "Quad.h" -//#include "Device.h" -// -//struct QuadVBOLayout -//{ -// Vector3 position; -// Vector2 uv; -//}; -// -//void Quad::Draw() -//{ -// const int nVerts = 4; -// const int nIndices = 6; -// -// float pos[] = { -// m_Left, m_Bottom, 0, // left-bottom -// m_Right, m_Bottom, 0, // right-bottom -// m_Right, m_Top, 0, // right-top -// m_Left, m_Top, 0, // 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; -// -// uint attrs = Mask(VertexAttr_Position) | Mask(VertexAttr_TexCoord0); -// g_SharedVBO.GetChunk(attrs, 4, 6, RenderMode_Triangle, (void**)&vb, (void**)&ib); -// -// QuadVBOLayout* dst = (QuadVBOLayout*)vb; -// for (int i = 0; i < nVerts; ++i) -// { -// dst[i].position.Set(pos[3 * i], pos[3 * i + 1], pos[3 * i + 2]); -// 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(); -//}
\ No newline at end of file +#include "../Math/Vector2.h" +#include "../Math/Vector3.h" +#include "Quad.h" +#include "GfxDevice.h" + +struct QuadVBOLayout +{ + Vector3 position; + Vector2 uv; +}; + +void Quad::Draw() +{ + const int nVerts = 4; + const int nIndices = 6; + + float pos[] = { + m_Left, m_Bottom, 0, // left-bottom + m_Right, m_Bottom, 0, // right-bottom + m_Right, m_Top, 0, // right-top + m_Left, m_Top, 0, // 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; + + uint attrs = Mask(VertexAttr_Position) | Mask(VertexAttr_UV); + g_SharedVBO.GetChunk(attrs, 4, 6, Primitive_Triangle, (void**)&vb, (void**)&ib); + + QuadVBOLayout* dst = (QuadVBOLayout*)vb; + for (int i = 0; i < nVerts; ++i) + { + dst[i].position.Set(pos[3 * i], pos[3 * i + 1], pos[3 * i + 2]); + 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(); +}
\ No newline at end of file |