summaryrefslogtreecommitdiff
path: root/Runtime/Rendering
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Rendering')
-rw-r--r--Runtime/Rendering/DynamicMesh.h10
-rw-r--r--Runtime/Rendering/Quad.cpp61
-rw-r--r--Runtime/Rendering/Quad.h26
-rw-r--r--Runtime/Rendering/UIQuad.cpp63
-rw-r--r--Runtime/Rendering/UIQuad.h21
5 files changed, 181 insertions, 0 deletions
diff --git a/Runtime/Rendering/DynamicMesh.h b/Runtime/Rendering/DynamicMesh.h
new file mode 100644
index 0000000..3cbb6f6
--- /dev/null
+++ b/Runtime/Rendering/DynamicMesh.h
@@ -0,0 +1,10 @@
+#pragma once
+#include "Runtime/Utilities/StaticInitiator.h"
+
+// Ìî³äg_SharedVBOµÄ¶¯Ì¬mesh
+class DynamicMesh
+{
+public:
+ virtual void Draw() = 0;
+
+};
diff --git a/Runtime/Rendering/Quad.cpp b/Runtime/Rendering/Quad.cpp
new file mode 100644
index 0000000..b4f81ee
--- /dev/null
+++ b/Runtime/Rendering/Quad.cpp
@@ -0,0 +1,61 @@
+#include "../Math/Vector2.h"
+#include "../Math/Vector3.h"
+#include "Quad.h"
+#include "../Graphics/GfxDevice.h"
+
+struct QuadVBOLayout
+{
+ Internal::Vector3 position;
+ Internal::Vector2 uv;
+};
+
+static CustomVertexLayout layout;
+
+InitializeStaticVariables([]() {
+ VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 3, VertexAttrFormat_Float, sizeof(QuadVBOLayout));
+ VertexAttributeDescriptor UV = VertexAttributeDescriptor(sizeof(Internal::Vector3), 2, VertexAttrFormat_Float, sizeof(QuadVBOLayout));
+
+ layout.attributes.push_back(POSITION);
+ layout.attributes.push_back(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;
+
+ g_SharedVBO.GetChunk(sizeof(QuadVBOLayout), sizeof(uint16), 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(layout);
+} \ No newline at end of file
diff --git a/Runtime/Rendering/Quad.h b/Runtime/Rendering/Quad.h
new file mode 100644
index 0000000..ee6c5be
--- /dev/null
+++ b/Runtime/Rendering/Quad.h
@@ -0,0 +1,26 @@
+#ifndef QUAD_H
+#define QUAD_H
+
+#include "../Utilities/UtilMacros.h"
+#include "DynamicMesh.h"
+
+class Quad : public DynamicMesh
+{
+public:
+ Quad(float l, float r, float t, float b);
+
+ void Set(float l, float r, float t, float b);
+
+ GET_SET(float, Left, m_Left);
+ GET_SET(float, Right, m_Right);
+ GET_SET(float, Top, m_Top);
+ GET_SET(float, Bottom, m_Bottom);
+
+ void Draw() override;
+
+private:
+ float m_Left, m_Right, m_Top, m_Bottom;
+
+};
+
+#endif \ No newline at end of file
diff --git a/Runtime/Rendering/UIQuad.cpp b/Runtime/Rendering/UIQuad.cpp
new file mode 100644
index 0000000..35dcf7e
--- /dev/null
+++ b/Runtime/Rendering/UIQuad.cpp
@@ -0,0 +1,63 @@
+#include "../Math/Vector2.h"
+#include "../Graphics/GfxDevice.h"
+#include "UIQuad.h"
+
+struct UIQuadLayout
+{
+ Internal::Vector2 position;
+ Internal::Vector2 uv;
+};
+
+static CustomVertexLayout layout;
+
+InitializeStaticVariables([](){
+ VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(UIQuadLayout));
+ VertexAttributeDescriptor UV = VertexAttributeDescriptor(sizeof(Internal::Vector2), 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,
+ };
+
+ 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[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(4, 6);
+ g_SharedVBO.DrawChunk(layout);
+} \ No newline at end of file
diff --git a/Runtime/Rendering/UIQuad.h b/Runtime/Rendering/UIQuad.h
new file mode 100644
index 0000000..f6d3a98
--- /dev/null
+++ b/Runtime/Rendering/UIQuad.h
@@ -0,0 +1,21 @@
+#pragma once
+#include "DynamicMesh.h"
+#include "../Utilities/StaticInitiator.h"
+
+class UIQuad : public DynamicMesh
+{
+public :
+ UIQuad(float l, float r, float t, float b)
+ {
+ m_Left = l;
+ m_Right = r;
+ m_Top = t;
+ m_Bottom = b;
+ }
+
+ void Draw() override;
+
+private:
+ float m_Left, m_Right, m_Top, m_Bottom;
+
+};