mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-07 19:58:32 +09:00
[Feat] (Core): Add env config loader and refactor initialization entrypoints.
This commit is contained in:
@@ -128,6 +128,7 @@ endif ()
|
||||
set(SOURCE_FILES
|
||||
MobileGL/Init.cpp
|
||||
MobileGL/GlobalObjects.cpp
|
||||
MobileGL/ConfigLoader.cpp
|
||||
|
||||
MobileGL/MG_Util/Debug/Log.cpp
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// MobileGL - MobileGL/ConfigLoader.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
namespace MobileGL::MG_ConfigLoader {
|
||||
static UnorderedMap<String, String> acceptedEnvVariablesMap;
|
||||
|
||||
static Bool IsAcceptedPrefix(const String& key) {
|
||||
return (key.compare(0, 6, "LIBGL_") == 0 || key.compare(0, 9, "MOBILEGL_") == 0);
|
||||
}
|
||||
|
||||
inline void InitializeAcceptedEnvVariables() {
|
||||
acceptedEnvVariablesMap.clear();
|
||||
char** envPtr = nullptr;
|
||||
|
||||
#ifdef _WIN32
|
||||
envPtr = _environ;
|
||||
#else // POSIX
|
||||
envPtr = ::environ;
|
||||
#endif
|
||||
|
||||
if (envPtr == nullptr) return;
|
||||
|
||||
for (char** env = envPtr; *env != nullptr; ++env) {
|
||||
String entry(*env);
|
||||
SizeT pos = entry.find('=');
|
||||
if (pos != String::npos) {
|
||||
String key = entry.substr(0, pos);
|
||||
String value = entry.substr(pos + 1);
|
||||
|
||||
if (IsAcceptedPrefix(key)) {
|
||||
acceptedEnvVariablesMap[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void QueryEnvVariable(const String& key, String& outValue, const String& defaultValue) {
|
||||
auto it = acceptedEnvVariablesMap.find(key);
|
||||
if (it != acceptedEnvVariablesMap.end()) {
|
||||
outValue = it->second;
|
||||
} else {
|
||||
outValue = defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
inline void InitBackendType() {
|
||||
String backendTypeStr;
|
||||
QueryEnvVariable("MOBILEGL_BACKEND_TYPE", backendTypeStr, "DirectGLES");
|
||||
#define ENTRY(backendType) \
|
||||
if (backendTypeStr == #backendType) { \
|
||||
MG_Config::ActiveBackendType = BackendType::backendType; \
|
||||
MGLOG_I("Config: Active backend type set to " #backendType); \
|
||||
return; \
|
||||
}
|
||||
ENTRY(DirectGLES)
|
||||
ENTRY(DirectVulkan)
|
||||
ENTRY(Unknown)
|
||||
MG_Config::ActiveBackendType = BackendType::Unknown;
|
||||
#undef ENTRY
|
||||
}
|
||||
|
||||
void Init() {
|
||||
MGLOG_D("Loading configuration from environment variables...");
|
||||
InitializeAcceptedEnvVariables();
|
||||
|
||||
InitBackendType();
|
||||
}
|
||||
} // namespace MobileGL::MG_ConfigLoader
|
||||
+1
-1
@@ -36,7 +36,7 @@
|
||||
// ====================== MobileGL configurations ======================= //
|
||||
#define MOBILEGL_LOG_ACTIVE_LEVEL MOBILEGL_LOG_LEVEL_INFO
|
||||
|
||||
#define MOBILEGL_LOG_ENABLE_CONSOLE 1
|
||||
#define MOBILEGL_LOG_ENABLE_CONSOLE 0
|
||||
#define MOBILEGL_LOG_ENABLE_FILE 1
|
||||
#define MOBILEGL_LOG_ENABLE_ANDROID 1
|
||||
#define MOBILEGL_ENABLE_SCOPE_MARKER 0
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_Config {
|
||||
BackendType ActiveBackendType = BackendType::DirectVulkan;
|
||||
BackendType ActiveBackendType;
|
||||
} // namespace MG_Config
|
||||
|
||||
namespace MG_Backend {
|
||||
|
||||
+11
-10
@@ -8,28 +8,29 @@
|
||||
|
||||
#include "Init.h"
|
||||
#include "Config.h"
|
||||
#include <MG_Impl/Init.h>
|
||||
#include <MG_Backend/BackendObjects.h>
|
||||
#include <MG_State/GLState/Core.h>
|
||||
#include <MG_Impl/GLImpl/Texture/ProxyTexture.h>
|
||||
#include <MG_Impl/GLImpl/Framebuffer/GL_Framebuffer.h>
|
||||
|
||||
namespace MobileGL {
|
||||
void MG_Initialize() {
|
||||
void Initialize() {
|
||||
MG_Util::Debug::InitFile();
|
||||
MGLOG_I("Initializing MobileGL...");
|
||||
MG_ConfigLoader::Init();
|
||||
MGLOG_I("Config loaded");
|
||||
MG_State::Init();
|
||||
MGLOG_D("MobileGL State initialized");
|
||||
MGLOG_D("MG_State initialized");
|
||||
MG_Backend::Init();
|
||||
MGLOG_D("MobileGL Backend initialized");
|
||||
MGLOG_D("MG_Backend initialized");
|
||||
MG_Impl::Init();
|
||||
MGLOG_D("MobileGL Implementation initialized");
|
||||
MGLOG_D("MG_Impl initialized");
|
||||
glslang::InitializeProcess();
|
||||
MGLOG_D("glslang initialized");
|
||||
MGLOG_I("MobileGL initialized");
|
||||
}
|
||||
|
||||
void MG_Destroy() {
|
||||
void Destroy() {
|
||||
MGLOG_I("MobileGL closing...");
|
||||
glslang::FinalizeProcess();
|
||||
delete MG_State::pGLContext;
|
||||
@@ -42,11 +43,11 @@ namespace MobileGL {
|
||||
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
__attribute__((constructor)) static void AutoInit() {
|
||||
MG_Initialize();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
__attribute__((destructor)) static void AutoDestroy() {
|
||||
MG_Destroy();
|
||||
Destroy();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -54,11 +55,11 @@ namespace MobileGL {
|
||||
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
||||
switch (ul_reason_for_call) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
MG_Initialize();
|
||||
Initialize();
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
MG_Destroy();
|
||||
Destroy();
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
+19
-3
@@ -10,6 +10,22 @@
|
||||
#include "Includes.h"
|
||||
|
||||
namespace MobileGL {
|
||||
void MG_Initialize();
|
||||
void MG_Destroy();
|
||||
} // namespace MobileGL
|
||||
void Initialize();
|
||||
void Destroy();
|
||||
|
||||
namespace MG_Util::Debug {
|
||||
void InitFile();
|
||||
} // namespace MG_Util::Debug
|
||||
|
||||
namespace MG_ConfigLoader {
|
||||
void Init();
|
||||
} // namespace MG_ConfigLoader
|
||||
|
||||
namespace MG_Backend {
|
||||
void Init();
|
||||
} // namespace MG_Backend
|
||||
|
||||
namespace MG_Impl {
|
||||
void Init();
|
||||
} // namespace MG_Impl
|
||||
} // namespace MobileGL
|
||||
|
||||
@@ -15,6 +15,4 @@
|
||||
namespace MobileGL::MG_Backend {
|
||||
extern UniquePtr<BackendObject> pActiveBackendObject;
|
||||
extern GlobalBackendFunctionsTable gBackendFunctionsTable;
|
||||
|
||||
void Init();
|
||||
} // namespace MobileGL::MG_Backend
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "Init.h"
|
||||
#include <Includes.h>
|
||||
|
||||
#include "GLImpl/Texture/ProxyTexture.h"
|
||||
#include "GLImpl/Framebuffer/GL_Framebuffer.h"
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Impl/Init.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include <Includes.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_Impl {
|
||||
void Init();
|
||||
} // namespace MG_Impl
|
||||
} // namespace MobileGL
|
||||
@@ -59,7 +59,6 @@ namespace MobileGL {
|
||||
namespace MG_Util {
|
||||
namespace Debug {
|
||||
void Log(const char* levelTag, android_LogPriority androidLogLevel, const char* fmt, ...);
|
||||
void InitFile();
|
||||
void WriteToFile(const char* msg);
|
||||
std::string GetCurrentTime();
|
||||
constexpr char* GetOSName();
|
||||
|
||||
Reference in New Issue
Block a user