mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 13:48:30 +09:00
[Improvement] (MG_Backend): Separate Initialize and InitCapabilities.
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
#include <Includes.h>
|
#include <Includes.h>
|
||||||
|
|
||||||
namespace MobileGL {
|
namespace MobileGL {
|
||||||
|
|
||||||
enum class BackendType {
|
enum class BackendType {
|
||||||
DirectGLES,
|
DirectGLES,
|
||||||
BackendTypeCount,
|
BackendTypeCount,
|
||||||
@@ -91,6 +90,7 @@ namespace MobileGL {
|
|||||||
virtual ~BackendObject() = default;
|
virtual ~BackendObject() = default;
|
||||||
|
|
||||||
virtual void Initialize() = 0;
|
virtual void Initialize() = 0;
|
||||||
|
virtual void InitCapabilities() = 0;
|
||||||
virtual void InitWindowSurface() = 0;
|
virtual void InitWindowSurface() = 0;
|
||||||
|
|
||||||
void SetWindowHandle(const WindowHandle& handle);
|
void SetWindowHandle(const WindowHandle& handle);
|
||||||
|
|||||||
@@ -38,8 +38,15 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
|
|
||||||
DirectGLES::SetEGLFuncsTable(m_EGLFunctions);
|
DirectGLES::SetEGLFuncsTable(m_EGLFunctions);
|
||||||
DirectGLES::SetGLESFuncsTable(m_GLESFunctions);
|
DirectGLES::SetGLESFuncsTable(m_GLESFunctions);
|
||||||
|
}
|
||||||
|
|
||||||
if (!MG_Util::BackendLoader::FillInGLESCapabilities(m_GLESCapabilities, m_GLESFunctions, m_EGLFunctions)) {
|
void BackendObject_DirectGLES::InitCapabilities() {
|
||||||
|
if (!m_initialized) {
|
||||||
|
MGLOG_E("DirectGLES backend not initialized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!MG_Util::BackendLoader::FillInGLESCapabilities(m_GLESCapabilities, m_GLESFunctions)) {
|
||||||
MGLOG_E("Failed to fill in GLES capabilities for DirectGLES backend");
|
MGLOG_E("Failed to fill in GLES capabilities for DirectGLES backend");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
class BackendObject_DirectGLES : public BackendObject {
|
class BackendObject_DirectGLES : public BackendObject {
|
||||||
public:
|
public:
|
||||||
~BackendObject_DirectGLES() override;
|
~BackendObject_DirectGLES() override;
|
||||||
|
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
|
void InitCapabilities() override;
|
||||||
void InitWindowSurface() override;
|
void InitWindowSurface() override;
|
||||||
|
|
||||||
const RendererInfo& GetRendererInfo() const override;
|
const RendererInfo& GetRendererInfo() const override;
|
||||||
|
|||||||
@@ -59,6 +59,13 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EGLBoolean MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) {
|
EGLBoolean MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) {
|
||||||
|
MGLOG_D("EGLImpl::CreateWindowSurface called with window=%p", window);
|
||||||
|
const auto& activeBackendObject = MG_Backend::pActiveBackendObject;
|
||||||
|
if (!activeBackendObject) {
|
||||||
|
MGLOG_E("activeBackendObject not initialized!");
|
||||||
|
return EGL_FALSE;
|
||||||
|
}
|
||||||
|
activeBackendObject->InitCapabilities();
|
||||||
return EGL_TRUE;
|
return EGL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -496,114 +496,11 @@ namespace MobileGL::MG_Util::BackendLoader {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static EGLDisplay eglDisplay = EGL_NO_DISPLAY;
|
Bool FillInGLESCapabilities(MG_External::GLESCapabilities& caps, const MG_External::GLESFunctionsTable& glesFuncs) {
|
||||||
static EGLSurface eglSurface = EGL_NO_SURFACE;
|
|
||||||
static EGLContext eglContext = EGL_NO_CONTEXT;
|
|
||||||
inline void DestroyTempEGLCtx(const MG_External::EGLFunctionsTable& eglFuncs) {
|
|
||||||
if (eglSurface != EGL_NO_SURFACE) {
|
|
||||||
eglFuncs.eglDestroySurface(eglDisplay, eglSurface);
|
|
||||||
eglSurface = EGL_NO_SURFACE;
|
|
||||||
}
|
|
||||||
if (eglContext != EGL_NO_CONTEXT) {
|
|
||||||
eglFuncs.eglDestroyContext(eglDisplay, eglContext);
|
|
||||||
eglContext = EGL_NO_CONTEXT;
|
|
||||||
}
|
|
||||||
if (eglDisplay != EGL_NO_DISPLAY) {
|
|
||||||
eglFuncs.eglTerminate(eglDisplay);
|
|
||||||
eglDisplay = EGL_NO_DISPLAY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inline Bool InitTmpEGLContext(const MG_External::EGLFunctionsTable& eglFuncs) {
|
|
||||||
EGLint configAttribs[] = {EGL_RED_SIZE,
|
|
||||||
8,
|
|
||||||
EGL_GREEN_SIZE,
|
|
||||||
8,
|
|
||||||
EGL_BLUE_SIZE,
|
|
||||||
8,
|
|
||||||
EGL_ALPHA_SIZE,
|
|
||||||
8,
|
|
||||||
EGL_SURFACE_TYPE,
|
|
||||||
EGL_PBUFFER_BIT,
|
|
||||||
EGL_RENDERABLE_TYPE,
|
|
||||||
EGL_OPENGL_ES2_BIT,
|
|
||||||
EGL_NONE};
|
|
||||||
|
|
||||||
EGLint ctxAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
|
|
||||||
|
|
||||||
EGLint pbAttribs[] = {EGL_WIDTH, 32, EGL_HEIGHT, 32, EGL_NONE};
|
|
||||||
|
|
||||||
EGLConfig pbufConfig;
|
|
||||||
EGLint configsFound = 0;
|
|
||||||
|
|
||||||
eglDisplay = eglFuncs.eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
||||||
if (eglDisplay == EGL_NO_DISPLAY) {
|
|
||||||
DestroyTempEGLCtx(eglFuncs);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eglFuncs.eglInitialize(eglDisplay, nullptr, nullptr) != EGL_TRUE) {
|
|
||||||
DestroyTempEGLCtx(eglFuncs);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eglFuncs.eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE) {
|
|
||||||
DestroyTempEGLCtx(eglFuncs);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eglFuncs.eglChooseConfig(eglDisplay, configAttribs, &pbufConfig, 1, &configsFound) != EGL_TRUE) {
|
|
||||||
DestroyTempEGLCtx(eglFuncs);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (configsFound == 0) {
|
|
||||||
configAttribs[6] = 0;
|
|
||||||
if (eglFuncs.eglChooseConfig(eglDisplay, configAttribs, &pbufConfig, 1, &configsFound) != EGL_TRUE) {
|
|
||||||
DestroyTempEGLCtx(eglFuncs);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!configsFound) {
|
|
||||||
DestroyTempEGLCtx(eglFuncs);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eglContext = eglFuncs.eglCreateContext(eglDisplay, pbufConfig, EGL_NO_CONTEXT, ctxAttribs);
|
|
||||||
if (eglContext == EGL_NO_CONTEXT) {
|
|
||||||
DestroyTempEGLCtx(eglFuncs);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
eglSurface = eglFuncs.eglCreatePbufferSurface(eglDisplay, pbufConfig, pbAttribs);
|
|
||||||
if (eglSurface == EGL_NO_SURFACE) {
|
|
||||||
DestroyTempEGLCtx(eglFuncs);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eglFuncs.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) != EGL_TRUE) {
|
|
||||||
DestroyTempEGLCtx(eglFuncs);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bool FillInGLESCapabilities(MG_External::GLESCapabilities& caps, const MG_External::GLESFunctionsTable& glesFuncs,
|
|
||||||
const MG_External::EGLFunctionsTable& eglFuncs) {
|
|
||||||
if (!glesFuncs.glGetString || !glesFuncs.glGetIntegerv) {
|
if (!glesFuncs.glGetString || !glesFuncs.glGetIntegerv) {
|
||||||
MGLOG_E("Required GLES functions are not loaded, cannot query capabilities");
|
MGLOG_E("Required GLES functions are not loaded, cannot query capabilities");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!eglFuncs.eglGetDisplay || !eglFuncs.eglInitialize || !eglFuncs.eglChooseConfig ||
|
|
||||||
!eglFuncs.eglCreateContext || !eglFuncs.eglCreatePbufferSurface || !eglFuncs.eglMakeCurrent) {
|
|
||||||
MGLOG_E("Required EGL functions are not loaded, cannot create temporary EGL context");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bool eglCtxCreated = InitTmpEGLContext(eglFuncs);
|
|
||||||
if (!eglCtxCreated) {
|
|
||||||
MGLOG_E("Failed to create temporary EGL context, cannot query GLES capabilities");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* vendorName = glesFuncs.glGetString(GL_VENDOR);
|
auto* vendorName = glesFuncs.glGetString(GL_VENDOR);
|
||||||
MGLOG_I("GL_VENDOR: %s", vendorName);
|
MGLOG_I("GL_VENDOR: %s", vendorName);
|
||||||
@@ -637,7 +534,6 @@ namespace MobileGL::MG_Util::BackendLoader {
|
|||||||
glesFuncs.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &caps.UniformBufferOffsetAlignment);
|
glesFuncs.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &caps.UniformBufferOffsetAlignment);
|
||||||
MGLOG_I(" GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: %d", caps.UniformBufferOffsetAlignment);
|
MGLOG_I(" GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: %d", caps.UniformBufferOffsetAlignment);
|
||||||
|
|
||||||
DestroyTempEGLCtx(eglFuncs);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} // namespace MobileGL::MG_Util::BackendLoader
|
} // namespace MobileGL::MG_Util::BackendLoader
|
||||||
|
|||||||
@@ -1020,8 +1020,7 @@ namespace MobileGL {
|
|||||||
MG_External::EGL::eglGetProcAddress_PTR procAddress);
|
MG_External::EGL::eglGetProcAddress_PTR procAddress);
|
||||||
Bool AcquireEGLFunctions(MG_External::EGLFunctionsTable& funcs);
|
Bool AcquireEGLFunctions(MG_External::EGLFunctionsTable& funcs);
|
||||||
Bool FillInGLESCapabilities(MG_External::GLESCapabilities& caps,
|
Bool FillInGLESCapabilities(MG_External::GLESCapabilities& caps,
|
||||||
const MG_External::GLESFunctionsTable& glesFuncs,
|
const MG_External::GLESFunctionsTable& glesFuncs);
|
||||||
const MG_External::EGLFunctionsTable& eglFuncs);
|
|
||||||
} // namespace MG_Util::BackendLoader
|
} // namespace MG_Util::BackendLoader
|
||||||
} // namespace MobileGL
|
} // namespace MobileGL
|
||||||
#undef MOBILEGL_EXTERNAL_GLES
|
#undef MOBILEGL_EXTERNAL_GLES
|
||||||
|
|||||||
Reference in New Issue
Block a user