starting merge

This commit is contained in:
2025-03-22 03:43:35 +01:00
parent 35d1c0ff7f
commit 3e6aa18fbe
12 changed files with 245 additions and 84 deletions

View File

@@ -1,19 +0,0 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#ifdef PULSE_ENABLE_OPENGL_BACKEND
#ifndef PULSE_EGL_CONTEXT_H_
#define PULSE_EGL_CONTEXT_H_
typedef struct EGLContext
{
EGLDisplay display;
EGLSurface surface;
EGLContext handle;
} EGLContext;
#endif // PULSE_EGL_CONTEXT_H_
#endif // PULSE_ENABLE_OPENGL_BACKEND

107
Sources/Backends/OpenGL/EGL/EGLInstance.c git.filemode.normal_file
View File

@@ -0,0 +1,107 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include "EGLInstance.h"
#include "../../../PulseInternal.h"
static PulseLibModule egl_lib_module = PULSE_NULL_LIB_MODULE;
static uint32_t loader_references_count = 0;
static bool EGLLoadFunctions(EGLInstance* instance)
{
#ifdef PULSE_PLAT_WINDOWS
const char* libnames[] = {
"libEGL.dll"
};
#else
const char* libnames[] = {
"libEGL.so.1",
"libEGL.so"
};
#endif
for(size_t i = 0; i < sizeof(libnames) / sizeof(const char*); i++)
{
if(loader_references_count == 0)
egl_lib_module = PulseLoadLibrary(libnames[i]);
if(egl_lib_module)
{
instance->eglGetProcAddress = (PFNEGLGETPROCADDRESSPROC)PulseLoadSymbolFromLibModule(egl_lib_module, "eglGetProcAddress");
if(instance->eglGetProcAddress == PULSE_NULLPTR)
{
PulseUnloadLibrary(egl_lib_module);
egl_lib_module = PULSE_NULL_LIB_MODULE;
}
else
break;
}
}
if(!egl_lib_module)
{
PulseSetInternalError(PULSE_ERROR_INITIALIZATION_FAILED);
return false;
}
loader_references_count++;
#define PULSE_EGL_FUNCTION(fn, T) \
instance->fn = (T)instance->eglGetProcAddress(#fn); \
if(!instance->fn) \
return false;
#include "EGLFunctions.h"
#undef PULSE_EGL_FUNCTION
return true;
}
bool EGLLoadInstance(EGLInstance* instance, bool es_context)
{
PULSE_CHECK_PTR_RETVAL(instance, false);
if(!EGLLoadFunctions(instance))
return false;
instance->display = instance->eglGetDisplay(EGL_DEFAULT_DISPLAY);
PULSE_CHECK_PTR_RETVAL(instance->display, false);
instance->eglInitialize(instance->display, PULSE_NULLPTR, PULSE_NULLPTR);
EGLint attribs[] = {
EGL_RENDERABLE_TYPE, es_context ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_BIT,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE
};
EGLint num_configs;
instance->eglChooseConfig(instance->display, attribs, &instance->config, 1, &num_configs);
EGLint ctxAttribs[] = {
es_context ? EGL_CONTEXT_CLIENT_VERSION : EGL_CONTEXT_MAJOR_VERSION, 3,
EGL_NONE
};
instance->eglBindAPI(es_context ? EGL_OPENGL_ES_API : EGL_OPENGL_API);
instance->context = instance->eglCreateContext(instance->display, instance->config, EGL_NO_CONTEXT, ctxAttribs);
PULSE_CHECK_PTR_RETVAL(instance->context, false);
EGLint pbufferAttribs[] = {
EGL_WIDTH, 1,
EGL_HEIGHT, 1,
EGL_NONE
};
instance->surface = instance->eglCreatePbufferSurface(instance->display, instance->config, pbufferAttribs);
PULSE_CHECK_PTR_RETVAL(instance->surface, false);
return instance->eglMakeCurrent(instance->display, instance->surface, instance->surface, instance->context);
}
void EGLUnloadInstance(EGLInstance* instance)
{
PULSE_CHECK_PTR(instance);
instance->eglDestroySurface(instance->display, instance->surface);
instance->eglDestroyContext(instance->display, instance->context);
instance->eglTerminate(instance->display);
loader_references_count--;
if(loader_references_count != 0)
return;
PulseUnloadLibrary(egl_lib_module);
egl_lib_module = PULSE_NULL_LIB_MODULE;
}

31
Sources/Backends/OpenGL/EGL/EGLInstance.h git.filemode.normal_file
View File

@@ -0,0 +1,31 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#ifdef PULSE_ENABLE_OPENGL_BACKEND
#ifndef PULSE_EGL_CONTEXT_H_
#define PULSE_EGL_CONTEXT_H_
#define EGL_EGL_PROTOTYPES 0
#include <EGL/egl.h>
#include <Pulse.h>
typedef struct EGLInstance
{
EGLDisplay display;
EGLSurface surface;
EGLContext context;
EGLConfig config;
#define PULSE_EGL_FUNCTION(fn, T) T fn;
#include "EGLFunctions.h"
#undef PULSE_EGL_FUNCTION
} EGLInstance;
bool EGLLoadInstance(EGLInstance* instance, bool es_context);
void EGLUnloadInstance(EGLInstance* instance);
#endif // PULSE_EGL_CONTEXT_H_
#endif // PULSE_ENABLE_OPENGL_BACKEND

View File

@@ -9,11 +9,15 @@
PulseBackendFlags OpenGLCheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used)
{
if(candidates != PULSE_BACKEND_ANY && (candidates & PULSE_BACKEND_OPENGL) == 0)
if(candidates != PULSE_BACKEND_ANY && ((candidates & PULSE_BACKEND_OPENGL) == 0 || (candidates & PULSE_BACKEND_OPENGL_ES) == 0))
return PULSE_BACKEND_INVALID;
if((shader_formats_used & PULSE_SHADER_FORMAT_GLSL_BIT) == 0)
return PULSE_BACKEND_INVALID;
EGLInstance instance;
if(!EGLLoadInstance(&instance, candidates))
return PULSE_BACKEND_INVALID;
EGLUnloadInstance(&instance);
return PULSE_BACKEND_OPENGL;
}
@@ -23,12 +27,18 @@ bool OpenGLLoadBackend(PulseBackend backend, PulseDebugLevel debug_level)
PULSE_UNUSED(debug_level);
OpenGLDriverData* driver_data = (OpenGLDriverData*)calloc(1, sizeof(OpenGLDriverData));
PULSE_CHECK_ALLOCATION_RETVAL(driver_data, false);
#ifdef PULSE_PLAT_WINDOWS
// WGL support
#else
EGLLoadInstance(&driver_data->egl_instance, false);
#endif
OpenGLDriver.driver_data = driver_data;
return true;
}
void OpenGLUnloadBackend(PulseBackend backend)
{
EGLUnloadInstance(&OPENGL_RETRIEVE_DRIVER_DATA_AS(backend, OpenGLDriverData*)->egl_instance);
free(backend->driver_data);
}
@@ -48,12 +58,14 @@ bool OpenGLESLoadBackend(PulseBackend backend, PulseDebugLevel debug_level)
PULSE_UNUSED(debug_level);
OpenGLDriverData* driver_data = (OpenGLDriverData*)calloc(1, sizeof(OpenGLDriverData));
PULSE_CHECK_ALLOCATION_RETVAL(driver_data, false);
EGLLoadInstance(&driver_data->egl_instance, true);
OpenGLDriver.driver_data = driver_data;
return true;
}
void OpenGLESUnloadBackend(PulseBackend backend)
{
EGLUnloadInstance(&OPENGL_RETRIEVE_DRIVER_DATA_AS(backend, OpenGLDriverData*)->egl_instance);
free(backend->driver_data);
}

View File

@@ -11,8 +11,14 @@
#define OPENGL_RETRIEVE_DRIVER_DATA_AS(handle, cast) ((cast)handle->driver_data)
#include "EGL/EGLInstance.h"
typedef struct OpenGLDriverData
{
union
{
EGLInstance egl_instance;
};
} OpenGLDriverData;
PulseBackendFlags OpenGLCheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used); // Return PULSE_BACKEND_OPENGL in case of success and PULSE_BACKEND_INVALID otherwise