- switched from GLEW to GLAD and now dynamically links EGL & OpenGL

This commit is contained in:
2025-12-28 02:14:45 -05:00
parent ecf1cfc29c
commit c1be5385d3
24 changed files with 32002 additions and 35 deletions

View File

@@ -16,11 +16,13 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#include <fennec/core/logger.h>
#include <fennec/format/format.h>
#include <GL/gl.h>
#include <fennec/platform/opengl/egl/context.h>
#include <fennec/platform/opengl/glad/gl.h>
namespace fennec
{
@@ -44,7 +46,7 @@ eglcontext::eglcontext(display_server* display)
, _eglconfig(nullptr)
, _eglvmajor(0)
, _eglvminor(0)
, _eglctype(0){
, _eglctype(0) {
EGLint config_attrs[] = {
EGL_SURFACE_TYPE,
@@ -54,21 +56,31 @@ eglcontext::eglcontext(display_server* display)
EGL_OPENGL_BIT, // 4
EGL_NONE
};
static constexpr size_t api_index = 4;
EGLint context_attrs[] = {
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR,
EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR,
EGL_NONE
};
// Load EGL bindings
assertf(gladLoaderLoadEGL(_egldisplay), "Unable to load EGL Bindings.");
// Get the EGL display from the display server
_egldisplay = eglGetDisplay(display->get_native_handle());
assertf(_egldisplay, "Failed to connect to egl display.");
// Initialize EGL
assertf(eglInitialize(_egldisplay, &_eglvmajor, &_eglvminor), "Failed to initialize egl.");
logger::log(format("Initialized EGL v{}.{}", _eglvmajor, _eglvminor));
// Reload EGL bindings
assertf(gladLoaderLoadEGL(_egldisplay), "Unable to load EGL Bindings.");
// Attempt to bind to OpenGL or GLES
if (not eglBindAPI(EGL_OPENGL_API)) {
config_attrs[4] = EGL_OPENGL_ES_BIT;
config_attrs[api_index] = EGL_OPENGL_ES_BIT;
assertf(eglBindAPI(EGL_OPENGL_ES_API), "Failed to find suitable OpenGL API.");
}
@@ -83,6 +95,9 @@ eglcontext::eglcontext(display_server* display)
// Make the created context the current context to query some info
eglMakeCurrent(_egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, _eglcontext);
// Load OpenGL bindings
assertf(gladLoaderLoadGL(), "Unable to load OpenGL Bindings.");
// Query version information
eglQueryContext(_egldisplay, _eglcontext, EGL_CONTEXT_CLIENT_TYPE, &_eglctype);
glGetIntegerv(GL_MAJOR_VERSION, &_eglvmajor);
@@ -93,20 +108,33 @@ eglcontext::eglcontext(display_server* display)
version.minor = _eglvminor;
version.patch = 0;
version.str = format("{} v{}.{}", egl_translate_type(_eglctype), _eglvmajor, _eglvminor);
logger::log(format("Created OpenGL Context: {}", version.str));
}
eglcontext::~eglcontext() {
// Ensure we are in the correct context
eglMakeCurrent(_egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, _eglcontext);
// Unload GL bindings
gladLoaderUnloadGL();
// Cleanup the context
eglMakeCurrent(_egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(_egldisplay, _eglcontext);
eglTerminate(_egldisplay);
eglReleaseThread();
// Unload EGL bindings
gladLoaderUnloadEGL();
// Reset data members
_egldisplay = nullptr;
_eglconfig = nullptr;
_eglcontext = nullptr;
_eglvmajor = 0;
_eglvminor = 0;
// Reset version
version.major = 0;
version.minor = 0;
version.patch = 0;