mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-09 04:38:30 +09:00
MG_Config::FeaturesTable snapshots every MOBILEGL_* toggle once in ConfigLoader::Init with a single truthy rule (non-empty, not '0', not 'false' case-insensitively), replacing 13 scattered std::getenv sites that used four different parsing conventions. Renderer-derived bits (IsAngleRenderer/IsAngleLlvmpipeRenderer/AvoidSamplerMipmapMinFilter) move into GLESCapabilities, set once in FillInGLESCapabilities, so hot paths (glMemoryBarrier ANGLE flush, sampler min-filter sync) stop doing per-call string scans. MOBILEGL_PRESENT_DUMP_CALL/_CURRENT_CALL stay live getenv (the retrace harness mutates them at runtime) and MOBILEGL_LOG_FILE_PATH stays in Log.cpp (log init precedes config init); both are documented in Config.h. Known semantic unification: MOBILEGL_DISABLE_SUBGROUP previously required exactly 'true' and MOBILEGL_PRESENT_STATS exactly '1'; both now follow the shared rule (CI's 0/1 values parse identically). Also bumps CoreVersion to 26.07. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
104 lines
2.9 KiB
C++
104 lines
2.9 KiB
C++
// MobileGL - MobileGL/Init.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 "Init.h"
|
|
#include "Config.h"
|
|
#include <MG_Backend/BackendObjects.h>
|
|
#include <MG_State/GLState/Core.h>
|
|
#include <MG_State/EGLState/Core.h>
|
|
#include <MG_Impl/GLImpl/Texture/ProxyTexture.h>
|
|
#include <MG_Impl/GLImpl/Framebuffer/GL_Framebuffer.h>
|
|
|
|
namespace MobileGL {
|
|
namespace {
|
|
Bool g_isInitialized = false;
|
|
|
|
void DestroyImpl(Bool logLifecycle) {
|
|
if (!g_isInitialized) {
|
|
return;
|
|
}
|
|
|
|
if (logLifecycle) {
|
|
MGLOG_I("MobileGL closing...");
|
|
}
|
|
glslang::FinalizeProcess();
|
|
MG_Backend::pActiveBackendObject.reset();
|
|
MG_State::pGLContext.reset();
|
|
MG_State::pEGLContext.reset();
|
|
MG_Impl::GLImpl::TextureImpl::pProxyTextureManager.reset();
|
|
MG_Impl::GLImpl::FramebufferImpl::pDefaultFramebufferInfo.reset();
|
|
MG_Backend::gBackendFunctionsTable = {};
|
|
g_isInitialized = false;
|
|
if (logLifecycle) {
|
|
MG_Util::Debug::Close();
|
|
}
|
|
|
|
// TODO: add and use Destroy functions for other subsystems
|
|
}
|
|
}
|
|
|
|
void Initialize() {
|
|
if (g_isInitialized) {
|
|
MGLOG_D("MobileGL already initialized; skipping duplicate Initialize()");
|
|
return;
|
|
}
|
|
|
|
MG_Util::Debug::InitFile();
|
|
MGLOG_I("Initializing MobileGL...");
|
|
MG_ConfigLoader::Init();
|
|
MGLOG_I("Config loaded");
|
|
MG_State::Init();
|
|
MGLOG_D("MG_State initialized");
|
|
MG_Backend::Init();
|
|
MGLOG_D("MG_Backend initialized");
|
|
MG_Impl::Init();
|
|
MGLOG_D("MG_Impl initialized");
|
|
glslang::InitializeProcess();
|
|
MGLOG_D("glslang initialized");
|
|
g_isInitialized = true;
|
|
MGLOG_I("MobileGL initialized");
|
|
}
|
|
|
|
void Destroy() {
|
|
DestroyImpl(true);
|
|
}
|
|
|
|
#if defined(__linux__) || defined(__APPLE__)
|
|
__attribute__((constructor)) static void AutoInit() {
|
|
Initialize();
|
|
}
|
|
|
|
__attribute__((destructor)) static void AutoDestroy() {
|
|
if (MG_Config::Features.TraceSkipAutodestroy) {
|
|
return;
|
|
}
|
|
#if defined(__APPLE__)
|
|
// macOS injected dylibs can run destructors after logging/backend static state is already torn down.
|
|
return;
|
|
#else
|
|
DestroyImpl(false);
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
|
switch (ul_reason_for_call) {
|
|
case DLL_PROCESS_ATTACH:
|
|
Initialize();
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
Destroy();
|
|
break;
|
|
}
|
|
return TRUE;
|
|
}
|
|
#endif
|
|
} // namespace MobileGL
|