This commit is contained in:
2025-03-21 21:31:15 +01:00
parent d18a38f928
commit 35d1c0ff7f
13 changed files with 225 additions and 9 deletions

0
Sources/Backends/OpenGL/EGL/EGLContext.c git.filemode.normal_file
View File

19
Sources/Backends/OpenGL/EGL/EGLContext.h git.filemode.normal_file
View File

@@ -0,0 +1,19 @@
// 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

24
Sources/Backends/OpenGL/EGL/EGLFunctions.h git.filemode.normal_file
View File

@@ -0,0 +1,24 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
// No header guards
#ifndef PULSE_EGL_FUNCTION
#error "You must define PULSE_EGL_FUNCTION before including this file"
#endif
PULSE_EGL_FUNCTION(eglBindAPI, PFNEGLBINDAPIPROC)
PULSE_EGL_FUNCTION(eglChooseConfig, PFNEGLCHOOSECONFIGPROC)
PULSE_EGL_FUNCTION(eglCreateContext, PFNEGLCREATECONTEXTPROC)
PULSE_EGL_FUNCTION(eglCreatePbufferSurface, PFNEGLCREATEPBUFFERSURFACEPROC)
PULSE_EGL_FUNCTION(eglDestroyContext, PFNEGLDESTROYCONTEXTPROC)
PULSE_EGL_FUNCTION(eglDestroySurface, PFNEGLDESTROYSURFACEPROC)
PULSE_EGL_FUNCTION(eglGetConfigAttrib, PFNEGLGETCONFIGATTRIBPROC)
PULSE_EGL_FUNCTION(eglGetDisplay, PFNEGLGETDISPLAYPROC)
PULSE_EGL_FUNCTION(eglGetError, PFNEGLGETERRORPROC)
PULSE_EGL_FUNCTION(eglGetProcAddress, PFNEGLGETPROCADDRESSPROC)
PULSE_EGL_FUNCTION(eglInitialize, PFNEGLINITIALIZEPROC)
PULSE_EGL_FUNCTION(eglMakeCurrent, PFNEGLMAKECURRENTPROC)
PULSE_EGL_FUNCTION(eglQueryString, PFNEGLQUERYSTRINGPROC)
PULSE_EGL_FUNCTION(eglTerminate, PFNEGLTERMINATEPROC)

76
Sources/Backends/OpenGL/OpenGL.c git.filemode.normal_file
View File

@@ -0,0 +1,76 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#include "../../PulseInternal.h"
#include "OpenGL.h"
PulseBackendFlags OpenGLCheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used)
{
if(candidates != PULSE_BACKEND_ANY && (candidates & PULSE_BACKEND_OPENGL) == 0)
return PULSE_BACKEND_INVALID;
if((shader_formats_used & PULSE_SHADER_FORMAT_GLSL_BIT) == 0)
return PULSE_BACKEND_INVALID;
return PULSE_BACKEND_OPENGL;
}
bool OpenGLLoadBackend(PulseBackend backend, PulseDebugLevel debug_level)
{
PULSE_UNUSED(backend);
PULSE_UNUSED(debug_level);
OpenGLDriverData* driver_data = (OpenGLDriverData*)calloc(1, sizeof(OpenGLDriverData));
PULSE_CHECK_ALLOCATION_RETVAL(driver_data, false);
OpenGLDriver.driver_data = driver_data;
return true;
}
void OpenGLUnloadBackend(PulseBackend backend)
{
free(backend->driver_data);
}
PulseBackendFlags OpenGLESCheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used)
{
if(candidates != PULSE_BACKEND_ANY && (candidates & PULSE_BACKEND_OPENGL) == 0)
return PULSE_BACKEND_INVALID;
if((shader_formats_used & PULSE_SHADER_FORMAT_GLSL_BIT) == 0)
return PULSE_BACKEND_INVALID;
return PULSE_BACKEND_OPENGL;
}
bool OpenGLESLoadBackend(PulseBackend backend, PulseDebugLevel debug_level)
{
PULSE_UNUSED(backend);
PULSE_UNUSED(debug_level);
OpenGLDriverData* driver_data = (OpenGLDriverData*)calloc(1, sizeof(OpenGLDriverData));
PULSE_CHECK_ALLOCATION_RETVAL(driver_data, false);
OpenGLDriver.driver_data = driver_data;
return true;
}
void OpenGLESUnloadBackend(PulseBackend backend)
{
free(backend->driver_data);
}
PulseBackendHandler OpenGLDriver = {
.PFN_LoadBackend = OpenGLLoadBackend,
.PFN_UnloadBackend = OpenGLUnloadBackend,
.PFN_CreateDevice = PULSE_NULLPTR,
.backend = PULSE_BACKEND_OPENGL,
.supported_shader_formats = PULSE_SHADER_FORMAT_GLSL_BIT,
.driver_data = PULSE_NULLPTR
};
PulseBackendHandler OpenGLESDriver = {
.PFN_LoadBackend = OpenGLESLoadBackend,
.PFN_UnloadBackend = OpenGLESUnloadBackend,
.PFN_CreateDevice = PULSE_NULLPTR,
.backend = PULSE_BACKEND_OPENGL_ES,
.supported_shader_formats = PULSE_SHADER_FORMAT_GLSL_BIT,
.driver_data = PULSE_NULLPTR
};

23
Sources/Backends/OpenGL/OpenGL.h git.filemode.normal_file
View File

@@ -0,0 +1,23 @@
// Copyright (C) 2025 kanel
// This file is part of "Pulse"
// For conditions of distribution and use, see copyright notice in LICENSE
#include <Pulse.h>
#ifdef PULSE_ENABLE_OPENGL_BACKEND
#ifndef PULSE_OPENGL_H_
#define PULSE_OPENGL_H_
#define OPENGL_RETRIEVE_DRIVER_DATA_AS(handle, cast) ((cast)handle->driver_data)
typedef struct OpenGLDriverData
{
} OpenGLDriverData;
PulseBackendFlags OpenGLCheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used); // Return PULSE_BACKEND_OPENGL in case of success and PULSE_BACKEND_INVALID otherwise
PulseBackendFlags OpenGLESCheckSupport(PulseBackendFlags candidates, PulseShaderFormatsFlags shader_formats_used); // Return PULSE_BACKEND_OPENGL_ES in case of success and PULSE_BACKEND_INVALID otherwise
#endif // PULSE_OPENGL_H_
#endif // PULSE_ENABLE_OPENGL_BACKEND

0
Sources/Backends/OpenGL/OpenGLContext.h git.filemode.normal_file
View File

View File

@@ -20,6 +20,9 @@
#ifdef PULSE_ENABLE_SOFTWARE_BACKEND
#include "Backends/Software/Soft.h"
#endif
#ifdef PULSE_ENABLE_OPENGL_BACKEND
#include "Backends/OpenGL/OpenGL.h"
#endif
// Ordered by default preference
static const PulseCheckBackendSupportPFN backends_supports[] = {
@@ -32,6 +35,10 @@ static const PulseCheckBackendSupportPFN backends_supports[] = {
#ifdef PULSE_ENABLE_WEBGPU_BACKEND
WebGPUCheckSupport,
#endif
#ifdef PULSE_ENABLE_OPENGL_BACKEND
OpenGLCheckSupport,
OpenGLESCheckSupport,
#endif
#ifdef PULSE_ENABLE_SOFTWARE_BACKEND
SoftCheckSupport,
#endif
@@ -49,7 +56,7 @@ void PulseSetInternalError(PulseErrorType error)
void PulseLogBackend(PulseBackend backend, PulseDebugMessageSeverity type, const char* message, const char* file, const char* function, int line, ...)
{
(void)file; // May be used later
PULSE_UNUSED(file); // May be used later
if(backend == PULSE_NULL_HANDLE)
return;
if(!backend->PFN_UserDebugCallback)
@@ -108,6 +115,10 @@ static PulseBackend PulseGetBackendFromFlag(PulseBackendBits flag)
#ifdef PULSE_ENABLE_SOFTWARE_BACKEND
case PULSE_BACKEND_SOFTWARE: return &SoftwareDriver;
#endif
#ifdef PULSE_ENABLE_OPENGL_BACKEND
case PULSE_BACKEND_OPENGL: return &OpenGLDriver;
case PULSE_BACKEND_OPENGL_ES: return &OpenGLESDriver;
#endif
default: break;
}

View File

@@ -181,5 +181,9 @@ void PulseLogBackend(PulseBackend backend, PulseDebugMessageSeverity type, const
#ifdef PULSE_ENABLE_SOFTWARE_BACKEND
extern PulseBackendHandler SoftwareDriver;
#endif // PULSE_ENABLE_SOFTWARE_BACKEND
#ifdef PULSE_ENABLE_OPENGL_BACKEND
extern PulseBackendHandler OpenGLDriver;
extern PulseBackendHandler OpenGLESDriver;
#endif // PULSE_ENABLE_OPENGL_BACKEND
#endif // PULSE_INTERNAL_H_