From aff94e108500e533db3346abef8373d8bd0d46ba Mon Sep 17 00:00:00 2001 From: Greg Wells Date: Fri, 6 Jun 2025 12:08:20 -0400 Subject: [PATCH] gryphn buffer API --- include/gryphn/gryphn.h | 1 + src/core/buffers/gryphn_buffer.c | 12 ++++++++++++ src/core/buffers/gryphn_buffer.h | 23 +++++++++++++++++++++++ src/core/gryphn_handles.h | 6 ++++++ src/core/gryphn_platform_functions.h | 4 ++++ 5 files changed, 46 insertions(+) create mode 100644 src/core/buffers/gryphn_buffer.c create mode 100644 src/core/buffers/gryphn_buffer.h diff --git a/include/gryphn/gryphn.h b/include/gryphn/gryphn.h index 8a426b4..2e9ed1f 100644 --- a/include/gryphn/gryphn.h +++ b/include/gryphn/gryphn.h @@ -21,3 +21,4 @@ #include #include #include +#include diff --git a/src/core/buffers/gryphn_buffer.c b/src/core/buffers/gryphn_buffer.c new file mode 100644 index 0000000..b29a8c2 --- /dev/null +++ b/src/core/buffers/gryphn_buffer.c @@ -0,0 +1,12 @@ +#include "gryphn_buffer.h" +#include "core/output_device/gryphn_output_device.h" +#include "core/gryphn_platform_functions.h" + +gnReturnCode gnCreateBuffer(gnBufferHandle* buffer, gnOutputDeviceHandle device, gnBufferInfo info) { + *buffer = malloc(sizeof(struct gnBuffer_t)); + (*buffer)->device = device; + return device->deviceFunctions->_gnCreateBuffer(*buffer, device, info); +} +void gnDestroyBuffer(gnBufferHandle buffer) { + buffer->device->deviceFunctions->_gnDestroyBuffer(buffer); +} diff --git a/src/core/buffers/gryphn_buffer.h b/src/core/buffers/gryphn_buffer.h new file mode 100644 index 0000000..f9ab54a --- /dev/null +++ b/src/core/buffers/gryphn_buffer.h @@ -0,0 +1,23 @@ +#pragma once +#include "stdlib.h" +#include "utils/gryphn_error_code.h" +#include + +typedef enum gnBufferType { + GN_VERTEX_BUFFER = 0x00000001 +} gnBufferType; + +typedef struct gnBufferInfo { + size_t size; + gnBufferType type; +} gnBufferInfo; + +#ifdef GN_REVEAL_IMPL +struct gnBuffer_t { + struct gnPlatformBuffer_t* buffer; + gnDeviceHandle device; +}; +#endif + +gnReturnCode gnCreateBuffer(gnBufferHandle* buffer, gnOutputDeviceHandle device, gnBufferInfo info); +void gnDestroyBuffer(gnBufferHandle buffer); diff --git a/src/core/gryphn_handles.h b/src/core/gryphn_handles.h index 9794775..78cc4e5 100644 --- a/src/core/gryphn_handles.h +++ b/src/core/gryphn_handles.h @@ -4,6 +4,10 @@ typedef struct type##_t* type##Handle; \ typedef struct type##_t* type +#define GN_HANDLE_ALIAS(alias, handle) \ +typedef struct handle##_t* alias##Handle; \ +typedef struct handle##_t* alias + GN_HANDLE(gnInstance); GN_HANDLE(gnDebugger); GN_HANDLE(gnWindowSurface); @@ -11,6 +15,7 @@ GN_HANDLE(gnPresentationQueue); GN_HANDLE(gnTexture); GN_HANDLE(gnRenderPassDescriptor); GN_HANDLE(gnOutputDevice); +GN_HANDLE_ALIAS(gnDevice, gnOutputDevice); GN_HANDLE(gnShaderModule); GN_HANDLE(gnGraphicsPipeline); GN_HANDLE(gnCommandPool); @@ -18,3 +23,4 @@ GN_HANDLE(gnCommandBuffer); GN_HANDLE(gnSemaphore); GN_HANDLE(gnFence); GN_HANDLE(gnFramebuffer); +GN_HANDLE(gnBuffer); diff --git a/src/core/gryphn_platform_functions.h b/src/core/gryphn_platform_functions.h index 7e6890a..659a976 100644 --- a/src/core/gryphn_platform_functions.h +++ b/src/core/gryphn_platform_functions.h @@ -18,6 +18,7 @@ #include "sync/semaphore/gryphn_semaphore.h" #include "core/submit/gryphn_submit.h" #include "core/present/gryphn_present.h" +#include "core/buffers/gryphn_buffer.h" typedef struct gnFunctions_t { gnReturnCode (*_gnCreateInstance)(gnInstanceHandle instance, gnInstanceInfo info); @@ -81,6 +82,9 @@ typedef struct gnDeviceFunctions_t { gnReturnCode (*_gnCreateSemaphore)(gnSemaphoreHandle semaphore, gnOutputDeviceHandle device); void (*_gnDestroySemaphore)(gnSemaphoreHandle semaphore); + gnReturnCode (*_gnCreateBuffer)(gnBufferHandle buffer, gnDeviceHandle device, gnBufferInfo info); + gnReturnCode(*_gnDestroyBuffer)(gnBufferHandle buffer); + gnReturnCode (*_gnCreateFence)(gnFenceHandle fence, gnOutputDeviceHandle device); void (*_gnSignalFence)(gnFenceHandle fence); void (*_gnWaitForFence)(gnFenceHandle fence, uint64_t timeout);