From 601442f94fc0dcfdc5a117c5f87d90b156d53045 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 31 Oct 2021 14:27:26 +0800 Subject: +static initiator --- Runtime/GUI/TextGenerator.cpp | 36 +++++++++------ Runtime/GUI/TextGenerator.h | 12 +++-- Runtime/Graphics/CustomVertexLayout.h | 10 +++- Runtime/Graphics/Quad.cpp | 52 --------------------- Runtime/Graphics/Quad.h | 25 ---------- Runtime/Graphics/SharedVertexBuffer.cpp | 2 + Runtime/Graphics/Texture.cpp | 15 +++++- Runtime/Graphics/UIQuad.cpp | 61 ------------------------- Runtime/Graphics/UIQuad.h | 18 -------- Runtime/Graphics/VertexAttribute.h | 17 +++---- Runtime/Rendering/DynamicMesh.h | 10 ++++ Runtime/Rendering/Quad.cpp | 61 +++++++++++++++++++++++++ Runtime/Rendering/Quad.h | 26 +++++++++++ Runtime/Rendering/UIQuad.cpp | 63 ++++++++++++++++++++++++++ Runtime/Rendering/UIQuad.h | 21 +++++++++ Runtime/Scripting/Rendering/Rendering.bind.cpp | 2 +- Runtime/Utilities/StaticInitiator.h | 27 +++++++++++ 17 files changed, 272 insertions(+), 186 deletions(-) delete mode 100644 Runtime/Graphics/Quad.cpp delete mode 100644 Runtime/Graphics/Quad.h delete mode 100644 Runtime/Graphics/UIQuad.cpp delete mode 100644 Runtime/Graphics/UIQuad.h create mode 100644 Runtime/Rendering/DynamicMesh.h create mode 100644 Runtime/Rendering/Quad.cpp create mode 100644 Runtime/Rendering/Quad.h create mode 100644 Runtime/Rendering/UIQuad.cpp create mode 100644 Runtime/Rendering/UIQuad.h create mode 100644 Runtime/Utilities/StaticInitiator.h (limited to 'Runtime') diff --git a/Runtime/GUI/TextGenerator.cpp b/Runtime/GUI/TextGenerator.cpp index a518772..1b34d1b 100644 --- a/Runtime/GUI/TextGenerator.cpp +++ b/Runtime/GUI/TextGenerator.cpp @@ -38,7 +38,7 @@ character::Hash TextGenerator::GetHash(Codepoint codepoint, int pixelSize) return hash; } -Character TextGenerator::GetCharacter(character::Codepoint codepoint, int pixelSize) +const Character* TextGenerator::GetCharacter(character::Codepoint codepoint, int pixelSize) { character::Hash hash = GetHash(codepoint, pixelSize); auto iter = m_Characters.find(hash); @@ -48,14 +48,22 @@ Character TextGenerator::GetCharacter(character::Codepoint codepoint, int pixelS iter = m_Characters.find(hash); } Assert(iter != m_Characters.end()); - return iter->second; + return &iter->second; +} + +void TextGenerator::RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize) +{ + for (int i = 0; i < n; ++i) + { + RenderCharacter(codepoint[i], pixelSize); + } } void TextGenerator::RenderCharacter(character::Codepoint codepoint, int pixelSize) { character::Hash hash = GetHash(codepoint, pixelSize); -// if (m_Characters.count(hash) != 0) -// return; + if (m_Characters.count(hash) != 0) + return; FT_Set_Pixel_Sizes(m_FTFace, 0, pixelSize); if (FT_Load_Char(m_FTFace, codepoint, FT_LOAD_RENDER)) { @@ -88,12 +96,12 @@ void TextGenerator::RenderCharacter(character::Codepoint codepoint, int pixelSiz character.atlas = atlas->index; character.position = rect; character.bearing = Internal::Vector2(m_FTFace->glyph->bitmap_left, m_FTFace->glyph->bitmap_top); - character.advance = m_FTFace->glyph->advance.x; + character.advance = m_FTFace->glyph->advance.x * 1/64.f; m_Characters.insert(std::pair(hash, character)); } -GlyphAtals* TextGenerator::GetGlyphAtlas(int index) +const GlyphAtals* TextGenerator::GetGlyphAtlas(int index) { if (index >= m_Atlases.size()) return NULL; @@ -104,25 +112,25 @@ Internal::Rect TextGenerator::GetRenderChartAndMove(GlyphAtals* atlas, Internal: { Internal::Rect rect; Internal::Vector2 space; - space.x = atlas->width - m_AtlasMargin * 2 - m_GlyphPadding - atlas->cursor.x; - space.y = atlas->height - m_AtlasMargin * 2 - m_GlyphPadding - atlas->cursor.y; + space.x = atlas->width - atlas->cursor.x - m_AtlasMargin; + space.y = atlas->height - atlas->cursor.y - m_AtlasMargin; if (space.x > preferSize.x && space.y > preferSize.y) { rect.x = atlas->cursor.x; rect.y = atlas->cursor.y; rect.width = preferSize.x; rect.height = preferSize.y; - atlas->cursor.x += rect.width; + atlas->cursor.x += rect.width + m_GlyphPadding; atlas->rowHeight = max(atlas->rowHeight, preferSize.y); } - else if (space.y - atlas->rowHeight > preferSize.y) + else if (space.y - atlas->rowHeight - m_GlyphPadding - m_AtlasMargin > preferSize.y) { rect.x = m_AtlasMargin; rect.y = atlas->cursor.y + m_GlyphPadding + atlas->rowHeight; rect.width = preferSize.x; rect.height = preferSize.y; atlas->cursor.x = m_AtlasMargin; - atlas->cursor.y += atlas->rowHeight; + atlas->cursor.y += atlas->rowHeight + m_GlyphPadding; atlas->rowHeight = rect.height; } else @@ -178,11 +186,11 @@ bool TextGenerator::HasEnoughSpace(GlyphAtals* atlas, Internal::Vector2 preferSi if (atlas == NULL) return false; Internal::Vector2 space; - space.x = atlas->width - m_AtlasMargin * 2 - m_GlyphPadding - atlas->cursor.x; - space.y = atlas->height - m_AtlasMargin * 2 - m_GlyphPadding - atlas->cursor.y; + space.x = atlas->width - atlas->cursor.x - m_AtlasMargin; + space.y = atlas->height - atlas->cursor.y - m_AtlasMargin; if (space.x > preferSize.x && space.y > preferSize.y) return true; - if (space.y - atlas->rowHeight > preferSize.y) + if (space.y - atlas->rowHeight - m_GlyphPadding - m_AtlasMargin > preferSize.y) return true; return false; } diff --git a/Runtime/GUI/TextGenerator.h b/Runtime/GUI/TextGenerator.h index 1065acf..ef78eb6 100644 --- a/Runtime/GUI/TextGenerator.h +++ b/Runtime/GUI/TextGenerator.h @@ -51,6 +51,7 @@ struct GlyphAtals int index; Texture* altas; // 贴图 int width, height; // 尺寸 + Internal::Vector2 cursor; // 游标,从左上角(0,0)开始 int rowHeight; // 当前行的高度 }; @@ -67,9 +68,12 @@ class TextGenerator : public Singleton public: void Setup(TextGeneratingSettings settings); - Character GetCharacter(character::Codepoint codepoint, int pixelSize); + const Character* GetCharacter(character::Codepoint codepoint, int pixelSize); + const GlyphAtals* GetGlyphAtlas(int index); + + // pre-bake void RenderCharacter(character::Codepoint codepoint, int pixelSize); - GlyphAtals* GetGlyphAtlas(int index); + void RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize); private: @@ -79,6 +83,8 @@ private: Internal::Rect GetRenderChartAndMove(GlyphAtals* atlas, Internal::Vector2 preferSize); bool HasEnoughSpace(GlyphAtals* atlas, Internal::Vector2 preferSize); + character::Hash GetHash(character::Codepoint Codepoint, int pixelSize); + std::unordered_map m_Characters; // 渲染完的文字 std::vector m_Atlases; // 当前所有的atlas @@ -91,8 +97,6 @@ private: FT_Library m_FTLibrary; FT_Face m_FTFace; - character::Hash GetHash(character::Codepoint Codepoint, int pixelSize); - }; #define g_TextGenerator (*TextGenerator::Instance()) diff --git a/Runtime/Graphics/CustomVertexLayout.h b/Runtime/Graphics/CustomVertexLayout.h index 86dcf90..d72c71d 100644 --- a/Runtime/Graphics/CustomVertexLayout.h +++ b/Runtime/Graphics/CustomVertexLayout.h @@ -11,6 +11,15 @@ struct CustomVertexLayout { GLuint buffer; // 创建时留空 std::vector attributes; + + // 重置pointer(startOffset)为0 + void ResetPointer() + { + for (int i = 0; i < attributes.size(); ++i) + { + attributes[i].pointer = 0; + } + } }; namespace VertexLayout @@ -19,4 +28,3 @@ namespace VertexLayout extern void SetupCustomVertexLayout(CustomVertexLayout& layout); } - diff --git a/Runtime/Graphics/Quad.cpp b/Runtime/Graphics/Quad.cpp deleted file mode 100644 index d769dd4..0000000 --- a/Runtime/Graphics/Quad.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "../Math/Vector2.h" -#include "../Math/Vector3.h" -#include "Quad.h" -#include "GfxDevice.h" - -struct QuadVBOLayout -{ - Internal::Vector3 position; - Internal::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 diff --git a/Runtime/Graphics/Quad.h b/Runtime/Graphics/Quad.h deleted file mode 100644 index 0e38ec4..0000000 --- a/Runtime/Graphics/Quad.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef QUAD_H -#define QUAD_H - -#include "../Utilities/UtilMacros.h" - -class Quad -{ -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(); - -private: - float m_Left, m_Right, m_Top, m_Bottom; - -}; - -#endif \ No newline at end of file diff --git a/Runtime/Graphics/SharedVertexBuffer.cpp b/Runtime/Graphics/SharedVertexBuffer.cpp index 464a919..e787630 100644 --- a/Runtime/Graphics/SharedVertexBuffer.cpp +++ b/Runtime/Graphics/SharedVertexBuffer.cpp @@ -173,6 +173,8 @@ void SharedVertexBuffer::DrawChunk(CustomVertexLayout& layout) VertexLayout::SetupCustomVertexLayout(layout); + layout.ResetPointer(); + const void* indexPtr = m_CurIB ? 0 : (m_CurIBData.empty() ? 0 : &m_CurIBData[0]); if (m_CurIB) diff --git a/Runtime/Graphics/Texture.cpp b/Runtime/Graphics/Texture.cpp index f92c094..eed0b90 100644 --- a/Runtime/Graphics/Texture.cpp +++ b/Runtime/Graphics/Texture.cpp @@ -158,12 +158,13 @@ Texture::Texture(TextureSetting setting, int w, int h) if (m_Format == ETextureFormat::R8) { internalFormat = GL_RED; + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); } - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + CheckGLError( glDeleteTextures(1, &m_GPUID); glBindTexture(GL_TEXTURE_2D, 0); @@ -185,6 +186,12 @@ void Texture::UpdateSubImage(Internal::Rect rect, int format, int type, const vo throw TextureException(error); ); + int alignment = 4; + if (m_Format == ETextureFormat::R8) + { + alignment = 1; + } + GLenum fmt = GL_RED; switch (format) { @@ -205,8 +212,12 @@ void Texture::UpdateSubImage(Internal::Rect rect, int format, int type, const vo case EPixelElementType::PixelType_FLOAT: t = GL_FLOAT; break; } + glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); + glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x, rect.y, rect.width, rect.height, fmt, t, data); + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + CheckGLError( glBindTexture(GL_TEXTURE_2D, 0); throw TextureException(error); diff --git a/Runtime/Graphics/UIQuad.cpp b/Runtime/Graphics/UIQuad.cpp deleted file mode 100644 index 73cf645..0000000 --- a/Runtime/Graphics/UIQuad.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "../Math/Vector2.h" -#include "GfxDevice.h" -#include "UIQuad.h" - -struct UIQuadLayout -{ - Internal::Vector2 position; - Internal::Vector2 uv; -}; - -void UIQuad::Draw() -{ - CustomVertexLayout layout; - - 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); - - 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/Graphics/UIQuad.h b/Runtime/Graphics/UIQuad.h deleted file mode 100644 index a0d77a5..0000000 --- a/Runtime/Graphics/UIQuad.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -class UIQuad -{ -public : - UIQuad(float l, float r, float t, float b) - { - m_Left = l; - m_Right = r; - m_Top = t; - m_Bottom = b; - } - void Draw(); - -private: - float m_Left, m_Right, m_Top, m_Bottom; - -}; diff --git a/Runtime/Graphics/VertexAttribute.h b/Runtime/Graphics/VertexAttribute.h index 4e50a1a..2757c70 100644 --- a/Runtime/Graphics/VertexAttribute.h +++ b/Runtime/Graphics/VertexAttribute.h @@ -21,6 +21,15 @@ enum VertexAttrFormat struct VertexAttributeDescriptor { + //union { + const void* pointer; // 内存地址,刚创建时留空 + int startOffset; // 显存中相对VBO的偏移值 + //}; + uint componentNum; // 向量维度1,2,3,4 + uint componentFormat; // 每个分量的类型 + uint16 stride; // 间隔 + bool normalize; // 是否归一化,只用于CustomVertexLayout + // for default vertex layout VertexAttributeDescriptor() {} // for custom vertex layout @@ -33,14 +42,6 @@ struct VertexAttributeDescriptor normalize = normalized; } - union { - const void* pointer; // 内存地址或显存中相对VBO的偏移值 - int startOffset; - }; - uint componentNum; // 向量维度1,2,3,4 - uint componentFormat; // 每个分量的类型 - uint16 stride; // 间隔 - bool normalize; // 是否归一化,只用于CustomVertexLayout }; namespace VertexAttribute 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; + +}; diff --git a/Runtime/Scripting/Rendering/Rendering.bind.cpp b/Runtime/Scripting/Rendering/Rendering.bind.cpp index cb294a3..9fb9a48 100644 --- a/Runtime/Scripting/Rendering/Rendering.bind.cpp +++ b/Runtime/Scripting/Rendering/Rendering.bind.cpp @@ -1,8 +1,8 @@ #include "Runtime/Graphics/Shader.h" #include "Runtime/Graphics/Texture.h" #include "Runtime/Graphics/ImageData.h" -#include "Runtime/Graphics/UIQuad.h" #include "Runtime/Graphics/GfxDevice.h" +#include "Runtime/Rendering/UIQuad.h" // Rendering.DrawUIQuad({}) static int DrawUIQuad(lua_State* L) diff --git a/Runtime/Utilities/StaticInitiator.h b/Runtime/Utilities/StaticInitiator.h new file mode 100644 index 0000000..bbcdbee --- /dev/null +++ b/Runtime/Utilities/StaticInitiator.h @@ -0,0 +1,27 @@ +#pragma once + +// 静态构造函数 +#include "ThirdParty/StaticConstructor/include/StaticConstructor.h" + +typedef void(*StaticFunc) (); + +// 自动初始化静态数据 +class StaticFuncInvoker +{ +public: + // Default Constructor: + StaticFuncInvoker(StaticFunc func) + { + if (func) + func(); + } +}; + +// 调用具名的static函数 +#define InvokeStaticFunc(func)\ + static StaticFuncInvoker staticInvokerOf_##func(func); + +// 用来初始化当前cpp里的静态变量 +#define InitializeStaticVariables(lambda)\ + static StaticFuncInvoker staticInvoker(lambda); + -- cgit v1.1-26-g67d0