native service, EGL, native test client

This commit is contained in:
2025-12-28 20:30:55 +01:00
parent de82e50bd5
commit 19400fd2b2
27 changed files with 13683 additions and 23 deletions

View File

@@ -0,0 +1,78 @@
#include "egl_context.h"
#include "logger.h"
#include <glad/gles2.h>
#include <glad/egl.h>
bool egl::Context::create()
{
int version = gladLoaderLoadEGL(EGL_NO_DISPLAY);
if (version == 0)
{
Logger::Log("glad failed to load EGL");
return false;
}
if (m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
m_display == EGL_NO_DISPLAY)
{
Logger::Log("eglGetDisplay failed");
return false;
}
EGLint major, minor;
if (!eglInitialize(m_display, &major, &minor))
{
Logger::Log("eglInitialize failed");
return false;
}
version = gladLoaderLoadEGL(EGL_DEFAULT_DISPLAY);
const EGLint config_attribs[] =
{
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
EGL_NONE,
};
EGLint num_configs;
if (!eglChooseConfig(m_display, config_attribs, &m_config, 1, &num_configs) || num_configs == 0)
{
Logger::Log("eglChooseConfig failed");
return false;
}
const EGLint context_attribs[] =
{
EGL_CONTEXT_MAJOR_VERSION, 3,
EGL_CONTEXT_MINOR_VERSION, 2,
EGL_NONE,
};
if (m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, context_attribs);
m_context == EGL_NO_CONTEXT)
{
Logger::Log("eglCreateContext failed");
return false;
}
if (!eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, m_context))
{
Logger::Log("eglMakeCurrent failed");
return false;
}
return true;
}
void egl::Context::destroy()
{
if (m_display != EGL_NO_DISPLAY)
{
eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (m_context != EGL_NO_CONTEXT)
{
eglDestroyContext(m_display, m_context);
}
eglTerminate(m_display);
}
m_display = EGL_NO_DISPLAY;
m_context = EGL_NO_CONTEXT;
}
egl::Context::Context()
: m_display(EGL_NO_DISPLAY), m_config(EGL_NO_CONFIG_KHR), m_context(EGL_NO_CONTEXT)
{
Logger::Log("egl::Context::Context");
}