From 601442f94fc0dcfdc5a117c5f87d90b156d53045 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 31 Oct 2021 14:27:26 +0800 Subject: +static initiator --- .../Libraries/GameLab/Engine/Rendering/Shader.lua | 11 + Data/Resources/Shaders/Editor-Text.glsl | 34 +++ Data/Scripts/Editor/AssetBrowser.lua | 3 +- .../\351\242\240\345\200\222.png" | Bin 0 -> 2675 bytes Editor/EditorMain.cpp | 14 +- Projects/VisualStudio/Editor/Editor.vcxproj | 10 +- .../VisualStudio/Editor/Editor.vcxproj.filters | 33 +-- 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 +++ .../StaticConstructorSample/MyClass.cpp | 43 ++++ .../StaticConstructorSample/MyClass.h | 36 ++++ .../StaticConstructorSample/MyTemplate.h | 48 +++++ .../StaticConstructorSample.cpp | 76 +++++++ .../StaticConstructorSample.sln | 20 ++ .../StaticConstructorSample.vcproj | 229 +++++++++++++++++++++ .../StaticConstructorSample/stdafx.cpp | 8 + .../StaticConstructorSample/stdafx.h | 24 +++ .../StaticConstructor/include/StaticConstructor.h | 126 ++++++++++++ 33 files changed, 962 insertions(+), 211 deletions(-) create mode 100644 Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Shader.lua create mode 100644 Data/Resources/Shaders/Editor-Text.glsl create mode 100644 "Documents/\345\233\276\347\211\207/\346\226\207\345\255\227\346\270\262\346\237\223/\351\242\240\345\200\222.png" 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 create mode 100644 ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp create mode 100644 ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h create mode 100644 ThirdParty/StaticConstructor/StaticConstructorSample/MyTemplate.h create mode 100644 ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.cpp create mode 100644 ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.sln create mode 100644 ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.vcproj create mode 100644 ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.cpp create mode 100644 ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.h create mode 100644 ThirdParty/StaticConstructor/include/StaticConstructor.h diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Shader.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Shader.lua new file mode 100644 index 0000000..c64d526 --- /dev/null +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Shader.lua @@ -0,0 +1,11 @@ +local Shader = GameLab.Engine.Rendering.Shader or {} + +-- @Shader.CreateFromFile +-- 从文件中创建Shader +-- @param path:string 路径 +-- @return shader 创建的shader +Shader.CreateFromFile = function( path ) + +end + +return Shader \ No newline at end of file diff --git a/Data/Resources/Shaders/Editor-Text.glsl b/Data/Resources/Shaders/Editor-Text.glsl new file mode 100644 index 0000000..7a88fcf --- /dev/null +++ b/Data/Resources/Shaders/Editor-Text.glsl @@ -0,0 +1,34 @@ +#version 330 core + +uniform mat4 gamelab_mat_mvp; +uniform sampler2D uiTex; +uniform vec2 uiText_ST; + +VSH_BEGIN +layout (location = 0) in vec2 vPos; +layout (location = 1) in vec2 vUV; + +out vec2 uv; + +void main() +{ + vec4 clip = gamelab_mat_mvp * vec4(vPos, -1, 1.0); + gl_Position = clip; + uv = vUV; +} + +VSH_END + +FSH_BEGIN +in vec2 uv; + +out vec4 FragColor; + +void main() +{ + vec2 uv = vec2(uv.x, 1 - uv.y); + vec4 sampled = vec4(1,1,1,texture(uiTex, uv).r); + FragColor = sampled; +} + +FSH_END \ No newline at end of file diff --git a/Data/Scripts/Editor/AssetBrowser.lua b/Data/Scripts/Editor/AssetBrowser.lua index 68f0483..5f00dc1 100644 --- a/Data/Scripts/Editor/AssetBrowser.lua +++ b/Data/Scripts/Editor/AssetBrowser.lua @@ -42,7 +42,8 @@ out vec4 FragColor; void main() { - vec4 sampled = vec4(texture(uiTex, uv).r, 0, 0, 1.0); + vec2 uv = vec2(uv.x, 1 - uv.y); + vec4 sampled = vec4(1,1,1,texture(uiTex, uv).r); FragColor = sampled; // FragColor = texture(uiTex, uv); // FragColor.rgb = vec3(1,0,0); diff --git "a/Documents/\345\233\276\347\211\207/\346\226\207\345\255\227\346\270\262\346\237\223/\351\242\240\345\200\222.png" "b/Documents/\345\233\276\347\211\207/\346\226\207\345\255\227\346\270\262\346\237\223/\351\242\240\345\200\222.png" new file mode 100644 index 0000000..6cbe043 Binary files /dev/null and "b/Documents/\345\233\276\347\211\207/\346\226\207\345\255\227\346\270\262\346\237\223/\351\242\240\345\200\222.png" differ diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp index e31da28..289eed4 100644 --- a/Editor/EditorMain.cpp +++ b/Editor/EditorMain.cpp @@ -22,15 +22,13 @@ void TestFont() { TextGeneratingSettings setting; setting.margin = 5; - setting.padding = 3; - setting.atlasSize = Internal::Vector2(256, 256); + setting.padding = 5; + setting.atlasSize = Internal::Vector2(512, 512); + TextGenerator::Instance()->Setup(setting); - TextGenerator::Instance()->RenderCharacter(L'ºÃ', 14); - TextGenerator::Instance()->RenderCharacter(L'´ó', 14); - TextGenerator::Instance()->RenderCharacter(L'¼Ò', 14); - TextGenerator::Instance()->RenderCharacter(L'Íí', 14); - TextGenerator::Instance()->RenderCharacter(L'ÉÏ', 14); - TextGenerator::Instance()->RenderCharacter(L'¿ì', 14); + auto content = L"abcdfÓëµç×Ó¼ÆËã»úµÄÇø±ð Óëµç×Ó¼ÆËã»úµÄ×î´óÇø±ðÔÚÓÚ: Ö»ÊǼòµ¥µÄ¼ÆË㹤¾ß,ÓÐЩ»úÐ;߱¸º¯Êý¼ÆË㹦ÄÜ,ÓÐЩ»úÐ;߱¸Ò»¶¨µÄÖü´æ¹¦ÄÜ,µ«Ò»°ãÖ»ÄÜ´æ´¢¼¸×éÊý¾Ý¡£¼ÆËã»úÔò¾ß±¸¸´ÔÓ´æÖü¹¦ÄÜ¡¢¿ØÖƹ¦ÄÜ,¸ü¼Ó"; + TextGenerator::Instance()->RenderCharacters((character::Codepoint*)content, wcslen(content), 14); + } int BeforeMainLoop(lua_State* L) diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj index d845f72..d35cb10 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj +++ b/Projects/VisualStudio/Editor/Editor.vcxproj @@ -191,13 +191,11 @@ - - @@ -217,6 +215,8 @@ + + @@ -274,13 +274,11 @@ - - @@ -315,6 +313,9 @@ + + + @@ -328,6 +329,7 @@ + diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters index e816c60..3f35125 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters +++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters @@ -112,6 +112,9 @@ {2e933d36-b374-4029-a210-1e38f81886b8} + + {c87ed6d9-48d6-4c07-8b94-d33e8f5a5f9c} + @@ -270,9 +273,6 @@ Runtime\Graphics - - Runtime\Graphics - Runtime\Graphics @@ -372,9 +372,6 @@ Runtime\Graphics - - Runtime\Graphics - Runtime\Math @@ -387,6 +384,12 @@ Runtime\GUI + + Runtime\Rendering + + + Runtime\Rendering + @@ -563,9 +566,6 @@ Runtime\Graphics - - Runtime\Graphics - Runtime\Graphics @@ -638,9 +638,6 @@ Runtime\Graphics - - Runtime\Graphics - Runtime\Utilities @@ -668,6 +665,18 @@ Runtime\Math + + Runtime\Rendering + + + Runtime\Rendering + + + Runtime\Rendering + + + Runtime\Utilities + 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); + diff --git a/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp b/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp new file mode 100644 index 0000000..3ea12a3 --- /dev/null +++ b/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.cpp @@ -0,0 +1,43 @@ +// MyClass.cpp +// +#include "stdafx.h" +#include "MyClass.h" + + +// Initialization of protected static data members: +void* MyClass::mpStaticMemory = NULL; +const double MyClass::mPI = 3.141592; +std::string MyClass::mStaticStr = "Init Value"; + + +// Invoke the StaticConstructor & StaticDestructor of the class: +// Make sure you put this AFTER the initialization of the static data members! +INVOKE_STATIC_CONSTRUCTOR(MyClass); + + +// Default Constructor: +MyClass::MyClass() +{ +// PI = 5.0; // Cannot be done, as PI is const + mStaticStr = "Modified by Default Constructor"; +} + +// Destructor: +MyClass::~MyClass() +{ + mStaticStr = "Modified by Default Destructor"; +} + +// Static Constructor: +void MyClass::StaticConstructor() +{ + mStaticStr = "Modified by Static Constructor"; + mpStaticMemory = new double[10]; +} + +// Static Destructor: +void MyClass::StaticDestructor() +{ + delete[] mpStaticMemory; +} + diff --git a/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h b/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h new file mode 100644 index 0000000..5f86f22 --- /dev/null +++ b/ThirdParty/StaticConstructor/StaticConstructorSample/MyClass.h @@ -0,0 +1,36 @@ +// MyClass.h +// +#include +#include + + +class MyClass +{ +protected: + // Declaration of protected static data members: + // Cannot be initialized here (C++ language limitation) + static void* mpStaticMemory; + static const double mPI; + static std::string mStaticStr; + +public: + // Static function members to get the static data members (to unify the Tests): + static const double& PI() { return mPI; }; + static std::string& StaticStr() { return mStaticStr; }; + +public: + // Default Constructor: + MyClass(); + + // Destructor: + virtual ~MyClass(); + + // Static Constructor: + // (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in the CPP file) + STATIC_CONSTRUCTOR(); + + // Static Destructor: + // (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in the CPP file) + STATIC_DESTRUCTOR(); +}; + diff --git a/ThirdParty/StaticConstructor/StaticConstructorSample/MyTemplate.h b/ThirdParty/StaticConstructor/StaticConstructorSample/MyTemplate.h new file mode 100644 index 0000000..a0a147c --- /dev/null +++ b/ThirdParty/StaticConstructor/StaticConstructorSample/MyTemplate.h @@ -0,0 +1,48 @@ +// MyTemplate.h +// +#include +#include + + +template +class MyTemplate +{ +protected: + // Declaration and initialization of protected static Data-Function member: + STATIC_DF_MEMBER(Type*, pStaticMemory, NULL); + +public: + // Declaration and initialization of public static Data-Function members: + STATIC_DF_MEMBER(const double, PI, 3.141592); + STATIC_DF_MEMBER(std::string, StaticStr, "Init Value"); + +public: + // Default Constructor: + MyTemplate() + { + // PI() = 5.0; // Cannot be done, as PI is const + StaticStr() = "Modified by Default Constructor"; + } + + // Destructor: + virtual ~MyTemplate() + { + StaticStr() = "Modified by Default Destructor"; + } + + // Static Constructor: + // (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in one CPP file) + STATIC_CONSTRUCTOR() + { + StaticStr() = "Modified by Static Constructor"; + pStaticMemory() = new Type[10]; + } + + // Static Destructor: + // (Should be called by INVOKE_STATIC_CONSTRUCTOR macro in one CPP file) + STATIC_DESTRUCTOR() + { + delete[] pStaticMemory(); + } +}; + diff --git a/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.cpp b/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.cpp new file mode 100644 index 0000000..26ff046 --- /dev/null +++ b/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.cpp @@ -0,0 +1,76 @@ +// StaticConstructorSample.cpp : Defines the entry point for the console application. +// +#include "stdafx.h" +#include +#include + +// Sample Files: +#include "MyClass.h" +#include "MyTemplate.h" + + +// Sample code for StartUp +STATIC_STARTUP_CODE() +{ + std::cout << "Starting up..." << std::endl; +} + +// Sample code for FinishUp +STATIC_FINISHUP_CODE() +{ + std::cout << "Finishing up..." << std::endl; +} + + +// Template for testing each Type: +template +void TestType(const std::string& strType) +{ + using namespace std; + + // Static Constructor should have been already invoked: + cout << "Show static data members before creating any instance of " << strType << ":" << endl; + cout << "String: " << Type::StaticStr() << endl; + cout << "PI: " << Type::PI() << endl; + + // Temporary block: + // Destructor of local variable will be called at the end of this block. + { + Type myObj; + cout << "Show static data members after creating an instance of " << strType << ":" << endl; + cout << "String: " << myObj.StaticStr() << endl; + cout << "PI: " << myObj.PI() << endl; + } + + cout << "Show static data members after destroying the instance of " << strType << ":" << endl; + cout << "String: " << Type::StaticStr() << endl; + cout << "PI: " << Type::PI() << endl; + cout << endl; +} + + +// Declaration of alias (class names) for the template instaces: +typedef MyTemplate MyTemplateInt; +typedef MyTemplate MyTemplateDouble; + +// Invoke the StaticConstructor & StaticDestructor for each one of the template instances: +// Should be called with alias (class names) for the template instaces. +INVOKE_STATIC_CONSTRUCTOR(MyTemplateInt); +INVOKE_STATIC_CONSTRUCTOR(MyTemplateDouble); + + +// Main: +int _tmain(int argc, _TCHAR* argv[]) +{ + // Static Constructors have already been called before entering this function... + + // Run the same tests for each one of the classes: + TestType("MyClass"); + TestType("MyTemplateInt"); + TestType("MyTemplateDouble"); + + // Static Destructors will be called after exiting this function... + return 0; +} + + diff --git a/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.sln b/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.sln new file mode 100644 index 0000000..265f06c --- /dev/null +++ b/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StaticConstructorSample", "StaticConstructorSample.vcproj", "{41329043-C008-486E-99A9-BC1A0B4DF9A5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {41329043-C008-486E-99A9-BC1A0B4DF9A5}.Debug|Win32.ActiveCfg = Debug|Win32 + {41329043-C008-486E-99A9-BC1A0B4DF9A5}.Debug|Win32.Build.0 = Debug|Win32 + {41329043-C008-486E-99A9-BC1A0B4DF9A5}.Release|Win32.ActiveCfg = Release|Win32 + {41329043-C008-486E-99A9-BC1A0B4DF9A5}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.vcproj b/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.vcproj new file mode 100644 index 0000000..0f66ceb --- /dev/null +++ b/ThirdParty/StaticConstructor/StaticConstructorSample/StaticConstructorSample.vcproj @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.cpp b/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.cpp new file mode 100644 index 0000000..88d97ab --- /dev/null +++ b/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// StaticConstructorSample.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.h b/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.h new file mode 100644 index 0000000..022bc3b --- /dev/null +++ b/ThirdParty/StaticConstructor/StaticConstructorSample/stdafx.h @@ -0,0 +1,24 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +// STL includes +#include +#include + + +// TODO: reference additional headers your program requires here diff --git a/ThirdParty/StaticConstructor/include/StaticConstructor.h b/ThirdParty/StaticConstructor/include/StaticConstructor.h new file mode 100644 index 0000000..22310bd --- /dev/null +++ b/ThirdParty/StaticConstructor/include/StaticConstructor.h @@ -0,0 +1,126 @@ +////////////////////////////////////////////////////////////////////////////// +// AUTHOR: Hugo González Castro +// TITLE: Static Constructor in C++ +// DESCRIPTION: An easy way to implement static constructors and +// static destructors in standard C++. +// VERSION: v1.2 - 2011/11/27 +// LICENSE: CPOL (Code Project Open License). +// Please, do not remove nor modify this header. +// URL: http://www.codeproject.com/KB/cpp/StaticConstructor.aspx +////////////////////////////////////////////////////////////////////////////// +#ifndef _STATIC_CONSTRUCTOR_H_ +#define _STATIC_CONSTRUCTOR_H_ + + + +////////////////////////////////////////////////////////////////////////////// +// DECLARATIONS (macros to use): +////////////////////////////////////////////////////////////////////////////// + + +// REQUIRED macro to invoke the static constructor/destructor of a class: +// place the call to this macro out of the definition of the class, in a .CPP file +// (avoid using it in .H files unless they are included only once). +// Make sure you put this AFTER the initialization of the static data members! +// For templates, should be called with alias (typedef) for the template instaces. +////////////////////////////////////////////////////////////////////////////// +#define INVOKE_STATIC_CONSTRUCTOR(ClassName) \ + INVOKE_STATIC_CONSTRUCTOR_EXPANDED(ClassName) + + +// OPTIONAL macros to help to declare the header of the static constructor/destructor: +// place the calls to these macros inside the definition of the class/template, in a .H file +////////////////////////////////////////////////////////////////////////////// +#define STATIC_CONSTRUCTOR() static void StaticConstructor() +#define STATIC_DESTRUCTOR() static void StaticDestructor() + + +// OPTIONAL macro to declare static Data-Function members with inline initialization: +// place the call to this macro inside the definition of the class/template. +////////////////////////////////////////////////////////////////////////////// +// STATIC DF MEMBER (static Data-Function member): +// "a static function member with a static local (data) variable declared inside". +// The TypeName can be or not a CONST type. +////////////////////////////////////////////////////////////////////////////// +#define STATIC_DF_MEMBER(TypeName, DFMemberName, InitValue) \ + STATIC_DF_MEMBER_EXPANDED(TypeName, DFMemberName, InitValue) + + +// OPTIONAL macros to run code at startup and finishup. Place outside classes. +// Place the static code inside {} after one of these macros. +////////////////////////////////////////////////////////////////////////////// +#define STATIC_STARTUP_CODE() STATIC_STARTUP_CODE_EXPANDED() +#define STATIC_FINISHUP_CODE() STATIC_FINISHUP_CODE_EXPANDED() + + + +////////////////////////////////////////////////////////////////////////////// +// IMPLEMENTATION (do not directly use these macros): +////////////////////////////////////////////////////////////////////////////// + + +// Definition of special class to invoke +// the static constructor/destructor from +// its own non-static constructor/destructor. +template +class StaticInvoker +{ +public: + // Default Constructor: + StaticInvoker() + { + // Call to the static constructor of ClassName: + ClassName::StaticConstructor(); + } + + // Destructor: + virtual ~StaticInvoker() + { + // Call to the static destructor of ClassName: + ClassName::StaticDestructor(); + } +}; + + +// Macro with expanded name: +#define INVOKE_STATIC_CONSTRUCTOR_EXPANDED(ClassName) \ + /* Single instance of this invoker class, so its constructor is called only once */ \ + StaticInvoker staticInvokerOf_##ClassName; + + +// STATIC DF MEMBER (static Data-Function member): +// "a static function member with a static local (data) variable declared inside". +// The TypeName can be or not a CONST type. +#define STATIC_DF_MEMBER_EXPANDED(TypeName, DFMemberName, InitValue) \ + static TypeName& DFMemberName() \ + { \ + static TypeName DFMemberName(InitValue); \ + return DFMemberName; \ + } + + +// Expanded macro to run code at startup. +#define STATIC_STARTUP_CODE_EXPANDED() \ + class StartUpCode \ + { \ + public: \ + StartUpCode(); \ + }; \ + StartUpCode myStartUpCode; \ + StartUpCode::StartUpCode() + + +// Expanded macro to run code at finishup. +#define STATIC_FINISHUP_CODE_EXPANDED() \ + class FinishUpCode \ + { \ + public: \ + FinishUpCode() {}; \ + virtual ~FinishUpCode(); \ + }; \ + FinishUpCode myFinishUpCode; \ + FinishUpCode::~FinishUpCode() + + + +#endif // _STATIC_CONSTRUCTOR_H_ -- cgit v1.1-26-g67d0