mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
[Feat] (Diligent/EGL_Init, MG_State/Getter): separates engine init and swapchain creation
This commit is contained in:
@@ -12,6 +12,7 @@ typedef Diligent::IEngineFactoryVk* (*Diligent_GetEngineFactoryVk_t)();
|
|||||||
typedef Diligent::IEngineFactoryOpenGL* (*Diligent_GetEngineFactoryOpenGL_t)();
|
typedef Diligent::IEngineFactoryOpenGL* (*Diligent_GetEngineFactoryOpenGL_t)();
|
||||||
|
|
||||||
namespace MG_Diligent {
|
namespace MG_Diligent {
|
||||||
|
Diligent::IEngineFactory* g_pFactory;
|
||||||
Diligent::IRenderDevice* g_pDevice;
|
Diligent::IRenderDevice* g_pDevice;
|
||||||
Diligent::IDeviceContext* g_pContext;
|
Diligent::IDeviceContext* g_pContext;
|
||||||
Diligent::ISwapChain* g_pSwapChain;
|
Diligent::ISwapChain* g_pSwapChain;
|
||||||
@@ -668,7 +669,7 @@ namespace MG_Diligent {
|
|||||||
using namespace Diligent;
|
using namespace Diligent;
|
||||||
|
|
||||||
namespace MG_EGL::Diligent {
|
namespace MG_EGL::Diligent {
|
||||||
void LoadDiligentCoreOpenGL(NativeWindowType window) {
|
void CreateWindowDiligentCoreOpenGL(NativeWindowType window) {
|
||||||
void *handle = dlopen("libGraphicsEngineOpenGL.so", RTLD_LAZY);
|
void *handle = dlopen("libGraphicsEngineOpenGL.so", RTLD_LAZY);
|
||||||
auto Diligent_GetEngineFactoryOpenGL =
|
auto Diligent_GetEngineFactoryOpenGL =
|
||||||
(Diligent_GetEngineFactoryOpenGL_t) dlsym(handle,
|
(Diligent_GetEngineFactoryOpenGL_t) dlsym(handle,
|
||||||
@@ -692,26 +693,53 @@ namespace MG_EGL::Diligent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadDiligentCoreVulkan(NativeWindowType window) {
|
void CreateWindowDiligentCoreVulkan(NativeWindowType window) {
|
||||||
|
AndroidNativeWindow nativeWindow{window};
|
||||||
|
auto* pFactoryVk = static_cast<IEngineFactoryVk*>(MG_Diligent::g_pFactory);
|
||||||
|
MG_Util::Debug::LogD("Creating Vulkan swap chain");
|
||||||
|
|
||||||
|
::Diligent::SwapChainDesc SCDesc;
|
||||||
|
SCDesc.ColorBufferFormat = TEX_FORMAT_RGBA8_UNORM;
|
||||||
|
SCDesc.PreTransform = SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180;
|
||||||
|
|
||||||
|
pFactoryVk->CreateSwapChainVk(
|
||||||
|
MG_Diligent::g_pDevice, MG_Diligent::g_pContext, SCDesc, nativeWindow, &MG_Diligent::g_pSwapChain);
|
||||||
|
if (MG_Diligent::g_pSwapChain) {
|
||||||
|
MG_Util::Debug::LogD("Vulkan swap chain created: %p", MG_Diligent::g_pSwapChain);
|
||||||
|
} else {
|
||||||
|
MG_Util::Debug::LogE("Failed to create Vulkan swap chain");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateWindowDiligentCore(NativeWindowType window) {
|
||||||
|
switch (MG_Diligent::DILIGENT_BACKEND_TYPE) {
|
||||||
|
case MG_Constants::Backend::BACKEND_DILIGENT_VULKAN:
|
||||||
|
CreateWindowDiligentCoreVulkan(window);
|
||||||
|
break;
|
||||||
|
case MG_Constants::Backend::BACKEND_DILIGENT_OPENGL:
|
||||||
|
default:
|
||||||
|
CreateWindowDiligentCoreOpenGL(window);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadDiligentCoreVulkan() {
|
||||||
void *handle = dlopen("libGraphicsEngineVk.so", RTLD_LAZY);
|
void *handle = dlopen("libGraphicsEngineVk.so", RTLD_LAZY);
|
||||||
auto Diligent_GetEngineFactoryVk =
|
auto Diligent_GetEngineFactoryVk =
|
||||||
(Diligent_GetEngineFactoryVk_t) dlsym(handle,
|
(Diligent_GetEngineFactoryVk_t) dlsym(handle,
|
||||||
"Diligent_GetEngineFactoryVk");
|
"Diligent_GetEngineFactoryVk");
|
||||||
|
|
||||||
auto *pFactoryVk = Diligent_GetEngineFactoryVk();
|
auto *pFactoryVk = Diligent_GetEngineFactoryVk();
|
||||||
|
MG_Diligent::g_pFactory = pFactoryVk;
|
||||||
::Diligent::EngineVkCreateInfo EngineCI;
|
::Diligent::EngineVkCreateInfo EngineCI;
|
||||||
EngineCI.DynamicHeapSize = 512 << 20;
|
EngineCI.DynamicHeapSize = 512 << 20;
|
||||||
|
|
||||||
::Diligent::SwapChainDesc SCDesc;
|
|
||||||
SCDesc.ColorBufferFormat = TEX_FORMAT_RGBA8_UNORM;
|
|
||||||
SCDesc.PreTransform = SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180;
|
|
||||||
|
|
||||||
MG_Util::Debug::LogD("Creating Vulkan device and contexts");
|
MG_Util::Debug::LogD("Creating Vulkan device and contexts");
|
||||||
pFactoryVk->CreateDeviceAndContextsVk(
|
pFactoryVk->CreateDeviceAndContextsVk(
|
||||||
EngineCI, &MG_Diligent::g_pDevice, &MG_Diligent::g_pContext);
|
EngineCI, &MG_Diligent::g_pDevice, &MG_Diligent::g_pContext);
|
||||||
|
|
||||||
if (MG_Diligent::g_pDevice && MG_Diligent::g_pContext) {
|
if (MG_Diligent::g_pDevice && MG_Diligent::g_pContext) {
|
||||||
MG_Util::Debug::LogD("Vulkan device created: device=%p, context=%p",
|
MG_Util::Debug::LogD("Vulkan device created: device=%p, context=%p",
|
||||||
MG_Diligent::g_pDevice, MG_Diligent::g_pContext);
|
MG_Diligent::g_pDevice, MG_Diligent::g_pContext);
|
||||||
auto version = MG_Diligent::g_pDevice->GetDeviceInfo().APIVersion;
|
auto version = MG_Diligent::g_pDevice->GetDeviceInfo().APIVersion;
|
||||||
std::string apiVersion;
|
std::string apiVersion;
|
||||||
@@ -733,28 +761,18 @@ namespace MG_EGL::Diligent {
|
|||||||
MG_Util::Debug::LogE("Failed to create Vulkan device");
|
MG_Util::Debug::LogE("Failed to create Vulkan device");
|
||||||
}
|
}
|
||||||
|
|
||||||
AndroidNativeWindow nativeWindow{window};
|
|
||||||
MG_Util::Debug::LogD("Creating Vulkan swap chain");
|
|
||||||
pFactoryVk->CreateSwapChainVk(
|
|
||||||
MG_Diligent::g_pDevice, MG_Diligent::g_pContext, SCDesc, nativeWindow, &MG_Diligent::g_pSwapChain);
|
|
||||||
if (MG_Diligent::g_pSwapChain) {
|
|
||||||
MG_Util::Debug::LogD("Vulkan swap chain created: %p", MG_Diligent::g_pSwapChain);
|
|
||||||
} else {
|
|
||||||
MG_Util::Debug::LogE("Failed to create Vulkan swap chain");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadDiligentCore(NativeWindowType window) {
|
void LoadDiligentCore() {
|
||||||
switch (MG_Diligent::DILIGENT_BACKEND_TYPE) {
|
switch (MG_Diligent::DILIGENT_BACKEND_TYPE) {
|
||||||
case MG_Constants::Backend::BACKEND_DILIGENT_VULKAN:
|
case MG_Constants::Backend::BACKEND_DILIGENT_VULKAN:
|
||||||
LoadDiligentCoreVulkan(window);
|
LoadDiligentCoreVulkan();
|
||||||
break;
|
break;
|
||||||
case MG_Constants::Backend::BACKEND_DILIGENT_OPENGL:
|
case MG_Constants::Backend::BACKEND_DILIGENT_OPENGL:
|
||||||
default:
|
default:
|
||||||
LoadDiligentCoreOpenGL(window);
|
// CreateWindowDiligentCoreOpenGL(window);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateDefaultRenderPass() {
|
void CreateDefaultRenderPass() {
|
||||||
@@ -797,7 +815,7 @@ namespace MG_EGL::Diligent {
|
|||||||
|
|
||||||
EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||||
const EGLint *attrib_list) {
|
const EGLint *attrib_list) {
|
||||||
LoadDiligentCore(window);
|
CreateWindowDiligentCore(window);
|
||||||
MG_GL::GL::UpdateDefaultFramebuffer();
|
MG_GL::GL::UpdateDefaultFramebuffer();
|
||||||
return (EGLSurface) 1;
|
return (EGLSurface) 1;
|
||||||
}
|
}
|
||||||
@@ -814,6 +832,9 @@ namespace MG_EGL::Diligent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) {
|
EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) {
|
||||||
|
LoadDiligentCore();
|
||||||
|
if (major) *major = 1;
|
||||||
|
if (minor) *minor = 5;
|
||||||
return EGL_TRUE;
|
return EGL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -929,8 +950,8 @@ namespace MG_EGL::Diligent {
|
|||||||
);
|
);
|
||||||
MG_Diligent::IsInRenderPass = true;
|
MG_Diligent::IsInRenderPass = true;
|
||||||
}
|
}
|
||||||
const auto& SCDesc = MG_Diligent::g_pSwapChain->GetDesc();
|
// const auto& SCDesc = MG_Diligent::g_pSwapChain->GetDesc();
|
||||||
MG_Util::Debug::LogD("Setting viewport: width=%d, height=%d", SCDesc.Width, SCDesc.Height);
|
// MG_Util::Debug::LogD("Setting viewport: width=%d, height=%d", SCDesc.Width, SCDesc.Height);
|
||||||
|
|
||||||
// ::Diligent::Viewport viewport;
|
// ::Diligent::Viewport viewport;
|
||||||
// viewport.TopLeftX = 0.f;
|
// viewport.TopLeftX = 0.f;
|
||||||
|
|||||||
@@ -76,7 +76,10 @@ namespace MG_GL::Getter {
|
|||||||
|
|
||||||
const std::string GetGPUName() {
|
const std::string GetGPUName() {
|
||||||
#if BACKEND_TYPE == BACKEND_DILIGENT
|
#if BACKEND_TYPE == BACKEND_DILIGENT
|
||||||
return MG_Diligent::g_pDevice->GetAdapterInfo().Description;
|
if (MG_Diligent::g_pDevice)
|
||||||
|
return MG_Diligent::g_pDevice->GetAdapterInfo().Description;
|
||||||
|
|
||||||
|
return "<not set yet>";
|
||||||
#else
|
#else
|
||||||
return "<unknown GPU>";
|
return "<unknown GPU>";
|
||||||
#endif
|
#endif
|
||||||
@@ -84,7 +87,10 @@ namespace MG_GL::Getter {
|
|||||||
|
|
||||||
const uint32_t GetBackendGfxAPIVersionMajor() {
|
const uint32_t GetBackendGfxAPIVersionMajor() {
|
||||||
#if BACKEND_TYPE == BACKEND_DILIGENT
|
#if BACKEND_TYPE == BACKEND_DILIGENT
|
||||||
return MG_Diligent::g_pDevice->GetDeviceInfo().APIVersion.Major;
|
if (MG_Diligent::g_pDevice)
|
||||||
|
return MG_Diligent::g_pDevice->GetDeviceInfo().APIVersion.Major;
|
||||||
|
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -92,7 +98,10 @@ namespace MG_GL::Getter {
|
|||||||
|
|
||||||
const uint32_t GetBackendGfxAPIVersionMinor() {
|
const uint32_t GetBackendGfxAPIVersionMinor() {
|
||||||
#if BACKEND_TYPE == BACKEND_DILIGENT
|
#if BACKEND_TYPE == BACKEND_DILIGENT
|
||||||
return MG_Diligent::g_pDevice->GetDeviceInfo().APIVersion.Minor;
|
if (MG_Diligent::g_pDevice)
|
||||||
|
return MG_Diligent::g_pDevice->GetDeviceInfo().APIVersion.Minor;
|
||||||
|
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user