diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ecb5d30..2528ad2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ if (MSVC) set(CMAKE_CXX_FLAGS "/EHsc ${CMAKE_CXX_FLAGS}") endif() -# Generate MGLGitHash.h +# Generate MGGitHash.h execute_process( COMMAND git rev-parse HEAD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} @@ -50,8 +50,8 @@ execute_process( string(SUBSTRING "${GIT_COMMIT_HASH_FULL}" 0 7 GIT_COMMIT_HASH_SHORT) configure_file( - ${CMAKE_SOURCE_DIR}/MobileGL/MG_Util/Miscellany/MGLGitHash.h.in - ${CMAKE_BINARY_DIR}/generated/MGLGitHash.h + ${CMAKE_SOURCE_DIR}/MobileGL/MG_Util/Miscellany/MGGitHash.h.in + ${CMAKE_BINARY_DIR}/generated/MGGitHash.h @ONLY ) diff --git a/MobileGL/Config.h b/MobileGL/Config.h index 1c82addd..cb6c5e6c 100644 --- a/MobileGL/Config.h +++ b/MobileGL/Config.h @@ -7,7 +7,8 @@ namespace MobileGL { inline const String ProjectName = "MobileGL"; inline const String CoreName = "MobileGL Core"; inline const String CoreVendor = "MobileGL-Dev"; - inline const Version CoreVersion = {1, 0, 0, "-Dev"}; + inline const Version CoreVersion = {25, 12, 0, "-dev", VersionType::Development}; + inline const VersionStringFormatAttrib DefaultVersionStringFormatAttrib = {2, 2, 0, true, true}; extern UniquePtr RendererInfoPtr; namespace Backend { diff --git a/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp b/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp index a6abe28b..2c46f84b 100644 --- a/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp +++ b/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp @@ -1,6 +1,6 @@ #include "GL_Getter.h" #include -#include +#include #include #include #include @@ -69,15 +69,15 @@ namespace MobileGL { return (const GLubyte*)vendorString.c_str(); case GL_VERSION: { if (versionStr.empty()) { - versionStr = - std::format("{} {} {}, {} Backend, GIT@" GIT_COMMIT_HASH_SHORT, - MG_Config::RendererInfoPtr->RendererGLInfo.TargetGLVersion.toString().c_str(), - MG_Config::ProjectName.c_str(), MG_Config::CoreVersion.toString().c_str(), - MG_Config::RendererInfoPtr->BackendName.c_str()); + versionStr = std::format( + "{} {} {}, {} Backend, GIT@" GIT_COMMIT_HASH_SHORT, + MG_Config::RendererInfoPtr->RendererGLInfo.TargetGLVersion.toString().c_str(), + MG_Config::ProjectName.c_str(), + MG_Config::CoreVersion.toFormattedString(MG_Config::DefaultVersionStringFormatAttrib).c_str(), + MG_Config::RendererInfoPtr->BackendName.c_str()); } return (const GLubyte*)versionStr.c_str(); } - case GL_RENDERER: { if (rendererString.empty()) { const char* backendStr = (const char*)GetString_Backend(GL_RENDERER); diff --git a/MobileGL/MG_Util/Miscellany/MGLGitHash.h.in b/MobileGL/MG_Util/Miscellany/MGGitHash.h.in similarity index 100% rename from MobileGL/MG_Util/Miscellany/MGLGitHash.h.in rename to MobileGL/MG_Util/Miscellany/MGGitHash.h.in diff --git a/MobileGL/MG_Util/Types.h b/MobileGL/MG_Util/Types.h index 3fc05b61..6be5dee5 100644 --- a/MobileGL/MG_Util/Types.h +++ b/MobileGL/MG_Util/Types.h @@ -170,11 +170,26 @@ namespace MobileGL { Range1D m_range; }; + enum class VersionType { + Release, + Unstable, + Development + }; + + struct VersionStringFormatAttrib { + Int majorWidth = 0; // 0 = no formatting + Int minorWidth = 0; + Int patchWidth = 0; + Bool useSuffix = true; + Bool autoPatch = false; // If patch == 0, skip the patch part; else add normally + }; + struct Version { Int Major; Int Minor; Int Patch; Optional Suffix; + Optional Type; String toString(Pair dots = {true, true}, Bool useSuffix = true) const { StringStream result; @@ -182,6 +197,39 @@ namespace MobileGL { << (useSuffix && Suffix.has_value() ? *Suffix : ""); return result.str(); } + + String toFormattedString(const VersionStringFormatAttrib& fmt) const { + auto formatNumber = [](Int value, Int width) { + String s = std::to_string(value); + if (width <= 0) return s; + + if ((Int)s.size() > width) { + return s.substr(s.size() - width); + } else if ((Int)s.size() < width) { + return String(width - s.size(), '0') + s; + } + return s; + }; + + StringStream result; + + result << formatNumber(Major, fmt.majorWidth) << "." << formatNumber(Minor, fmt.minorWidth); + + Bool shouldShowPatch = true; + if (fmt.autoPatch) { + shouldShowPatch = (Patch != 0) || (Type != VersionType::Release); + } + + if (shouldShowPatch) { + result << "." << formatNumber(Patch, fmt.patchWidth); + } + + if (fmt.useSuffix && Suffix.has_value()) { + result << *Suffix; + } + + return result.str(); + } }; struct BackendCap {};