mirror of
https://github.com/Kbz-8/Pulse.git
synced 2026-01-11 15:33:34 +00:00
yes
This commit is contained in:
33
Examples/OpenGL/main.c
git.filemode.normal_file
33
Examples/OpenGL/main.c
git.filemode.normal_file
@@ -0,0 +1,33 @@
|
||||
#include <Pulse.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define WGSL_SOURCE(...) #__VA_ARGS__
|
||||
|
||||
void DebugCallBack(PulseDebugMessageSeverity severity, const char* message)
|
||||
{
|
||||
if(severity == PULSE_DEBUG_MESSAGE_SEVERITY_ERROR)
|
||||
{
|
||||
fprintf(stderr, "Pulse Error: %s\n", message);
|
||||
exit(1);
|
||||
}
|
||||
else if(severity == PULSE_DEBUG_MESSAGE_SEVERITY_WARNING)
|
||||
fprintf(stderr, "Pulse Warning: %s\n", message);
|
||||
else
|
||||
printf("Pulse: %s\n", message);
|
||||
}
|
||||
|
||||
int main(int ac, char** av)
|
||||
{
|
||||
PulseBackendFlags backend_type = PULSE_BACKEND_OPENGL;
|
||||
if(ac >= 2 && strcmp(av[1], "--opengl-es") == 0)
|
||||
backend_type = PULSE_BACKEND_OPENGL_ES;
|
||||
PulseBackend backend = PulseLoadBackend(backend_type, PULSE_SHADER_FORMAT_GLSL_BIT, PULSE_HIGH_DEBUG);
|
||||
PulseSetDebugCallback(backend, DebugCallBack);
|
||||
|
||||
PulseUnloadBackend(backend);
|
||||
puts("Successfully executed Pulse example using OpenGL !");
|
||||
return 0;
|
||||
}
|
||||
7
Examples/OpenGL/xmake.lua
git.filemode.normal_file
7
Examples/OpenGL/xmake.lua
git.filemode.normal_file
@@ -0,0 +1,7 @@
|
||||
target("OpenGLExample")
|
||||
add_deps("pulse_gpu")
|
||||
if is_plat("linux") then
|
||||
set_extension(".x86_64")
|
||||
end
|
||||
add_files("*.c")
|
||||
target_end()
|
||||
@@ -8,6 +8,9 @@ if has_config("examples") then
|
||||
if has_config("webgpu") then
|
||||
includes("WebGPU/xmake.lua")
|
||||
end
|
||||
if has_config("opengl") then
|
||||
includes("OpenGL/xmake.lua")
|
||||
end
|
||||
if has_config("software") then
|
||||
includes("Software/xmake.lua")
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@ extern "C" {
|
||||
|
||||
#include "PulseProfile.h"
|
||||
|
||||
#define PULSE_VERSION PULSE_MAKE_VERSION(0, 0, 1)
|
||||
#define PULSE_VERSION PULSE_MAKE_VERSION(0, 1, 0)
|
||||
|
||||
// Types
|
||||
typedef uint64_t PulseDeviceSize;
|
||||
@@ -34,12 +34,14 @@ PULSE_DEFINE_NULLABLE_HANDLE(PulseComputePass);
|
||||
// Flags
|
||||
typedef enum PulseBackendBits
|
||||
{
|
||||
PULSE_BACKEND_INVALID = PULSE_BIT(1),
|
||||
PULSE_BACKEND_ANY = PULSE_BIT(2),
|
||||
PULSE_BACKEND_VULKAN = PULSE_BIT(3),
|
||||
PULSE_BACKEND_METAL = PULSE_BIT(4),
|
||||
PULSE_BACKEND_WEBGPU = PULSE_BIT(5),
|
||||
PULSE_BACKEND_SOFTWARE = PULSE_BIT(6),
|
||||
PULSE_BACKEND_INVALID = PULSE_BIT(1),
|
||||
PULSE_BACKEND_ANY = PULSE_BIT(2),
|
||||
PULSE_BACKEND_VULKAN = PULSE_BIT(3),
|
||||
PULSE_BACKEND_METAL = PULSE_BIT(4),
|
||||
PULSE_BACKEND_WEBGPU = PULSE_BIT(5),
|
||||
PULSE_BACKEND_SOFTWARE = PULSE_BIT(6),
|
||||
PULSE_BACKEND_OPENGL = PULSE_BIT(7),
|
||||
PULSE_BACKEND_OPENGL_ES = PULSE_BIT(8),
|
||||
} PulseBackendBits;
|
||||
typedef PulseFlags PulseBackendFlags;
|
||||
|
||||
@@ -72,6 +74,7 @@ typedef enum PulseShaderFormatsBits
|
||||
PULSE_SHADER_FORMAT_MSL_BIT = PULSE_BIT(2), // Can be used by Metal backend
|
||||
PULSE_SHADER_FORMAT_METALLIB_BIT = PULSE_BIT(3), // Can be used by Metal backend
|
||||
PULSE_SHADER_FORMAT_WGSL_BIT = PULSE_BIT(4), // Can be used by WebGPU backend
|
||||
PULSE_SHADER_FORMAT_GLSL_BIT = PULSE_BIT(5), // Can be used by OpenGL / OpenGL_ES backend
|
||||
// More to come
|
||||
} PulseShaderFormatsBits;
|
||||
typedef PulseFlags PulseShaderFormatsFlags;
|
||||
|
||||
0
Sources/Backends/OpenGL/EGL/EGLContext.c
git.filemode.normal_file
0
Sources/Backends/OpenGL/EGL/EGLContext.c
git.filemode.normal_file
19
Sources/Backends/OpenGL/EGL/EGLContext.h
git.filemode.normal_file
19
Sources/Backends/OpenGL/EGL/EGLContext.h
git.filemode.normal_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
24
Sources/Backends/OpenGL/EGL/EGLFunctions.h
git.filemode.normal_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
76
Sources/Backends/OpenGL/OpenGL.c
git.filemode.normal_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
23
Sources/Backends/OpenGL/OpenGL.h
git.filemode.normal_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
0
Sources/Backends/OpenGL/OpenGLContext.h
git.filemode.normal_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;
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
|
||||
15
xmake.lua
15
xmake.lua
@@ -34,7 +34,20 @@ local backends = {
|
||||
option = "software",
|
||||
default = true,
|
||||
packages = { "spirv-vm", "cpuinfo" }
|
||||
}
|
||||
},
|
||||
OpenGL = {
|
||||
option = "opengl",
|
||||
default = not is_plat("macosx", "iphoneos", "wasm", "appletvos"),
|
||||
packages = { "opengl-headers", "egl-headers" },
|
||||
custom = function()
|
||||
add_defines("EGL_NO_X11")
|
||||
if is_plat("windows", "mingw") then
|
||||
add_syslinks("User32")
|
||||
else
|
||||
remove_files("Sources/Backends/OpenGL/WGL/**.c")
|
||||
end
|
||||
end
|
||||
},
|
||||
}
|
||||
|
||||
local sanitizers = {
|
||||
|
||||
Reference in New Issue
Block a user