Turn instance into a handle

This commit is contained in:
Greg Wells
2025-06-03 13:23:28 -04:00
parent cbfd6743f6
commit ed781c1d63
22 changed files with 56 additions and 52 deletions

View File

@@ -47,7 +47,7 @@ typedef struct gnDebuggerInfo_t {
typedef struct gnDebugger_t {
struct gnPlatformDebugger_t* debugger;
struct gnDebuggerInfo_t info;
gnInstance* instance;
gnInstanceHandle instance;
} gnDebugger;
gnReturnCode gnCreateDebugger(gnDebugger* debugger, const struct gnDebuggerInfo_t info);

View File

@@ -20,37 +20,37 @@
#include "core/present/gryphn_present.h"
typedef struct gnFunctions_t {
gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info);
void (*_gnDestroyInstance)(gnInstance* instance);
gnReturnCode (*_gnCreateInstance)(gnInstanceHandle instance, struct gnInstanceInfo_t info);
void (*_gnDestroyInstance)(gnInstanceHandle instance);
gnReturnCode (*_gnCreateDebugger)(gnDebugger* debugger, gnInstance* instance, const struct gnDebuggerInfo_t info);
gnReturnCode (*_gnCreateDebugger)(gnDebugger* debugger, gnInstanceHandle instance, const struct gnDebuggerInfo_t info);
void (*_gnDestroyDebugger)(gnDebugger* debugger);
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstance* instance, uint32_t* count);
gnPhysicalDevice* (*_gnGetPhysicalDevices)(gnInstanceHandle instance, uint32_t* count);
gnBool (*_gnQueueCanPresentToSurface)(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const struct gnWindowSurface_t windowSurface);
gnReturnCode (*_gnCreateOutputDevoce)(gnOutputDevice* device, gnInstance* instance, struct gnOutputDeviceInfo_t deviceInfo);
gnReturnCode (*_gnCreateOutputDevoce)(gnOutputDevice* device, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo);
void (*_gnDestroyOutputDevice)(gnOutputDevice* device);
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
gnReturnCode (*_gnCreateX11WindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnX11WindowSurfaceInfo_t createInfo);
gnReturnCode (*_gnCreateX11WindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnX11WindowSurfaceInfo_t createInfo);
#endif
#ifdef GN_WINDOW_WAYLAND
gnReturnCode (*_gnCreateWaylandWindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
gnReturnCode (*_gnCreateWaylandWindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
#endif
#endif
#ifdef GN_PLATFORM_WIN32
gnReturnCode (*_gnCreateWin32WindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWin32WindowSurfaceInfo_t createInfo);
gnReturnCode (*_gnCreateWin32WindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo);
#endif
#ifdef GN_PLATFORM_MACOS
gnReturnCode (*_gnCreateMacOSWindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
gnReturnCode (*_gnCreateMacOSWindowSurface)(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
#endif
void (*_gnDestroyWindowSurface)(struct gnWindowSurface_t* windowSurface);

View File

@@ -3,7 +3,10 @@
#include <core/gryphn_platform_functions.h>
#include "core/debugger/gryphn_debugger.h"
gnReturnCode gnCreateInstance(gnInstance* instance, struct gnInstanceInfo_t info) {
gnReturnCode gnCreateInstance(gnInstanceHandle* instanceHandlePtr, struct gnInstanceInfo_t info) {
*instanceHandlePtr = malloc(sizeof(struct gnInstance_t));
gnInstanceHandle instance = *instanceHandlePtr;
if (!gnIsAPISupported(info.renderingAPI)) return GN_UNSUPPORTED_RENDERING_API;
instance->loadDeviceFunctions = gnFalse;
instance->debugger = NULL;
@@ -13,8 +16,7 @@ gnReturnCode gnCreateInstance(gnInstance* instance, struct gnInstanceInfo_t info
gnLoadFunctions(instance->dynamicLib, instance->functions);
return instance->functions->_gnCreateInstance(instance, info);
}
void gnInstanceAttachDebugger(gnInstance *instance, struct gnDebugger_t *debugger) {
void gnInstanceAttachDebugger(gnInstanceHandle instance, struct gnDebugger_t *debugger) {
if (instance->debugger != NULL) {
gnDebuggerSetErrorMessage(debugger, (gnMessageData){
.message = gnCreateString("Debugger already attached to instance")
@@ -31,13 +33,13 @@ void gnInstanceAttachDebugger(gnInstance *instance, struct gnDebugger_t *debugge
}
#include "stdio.h"
void gnDestroyInstance(gnInstance* instance) {
void gnDestroyInstance(gnInstanceHandle instance) {
if (instance->debugger) {
instance->functions->_gnDestroyDebugger(instance->debugger);
}
instance->functions->_gnDestroyInstance(instance);
}
void gnInstanceReleaseDebugger(gnInstance* instance) {
void gnInstanceReleaseDebugger(gnInstanceHandle instance) {
instance->debugger = NULL;
}

View File

@@ -17,7 +17,7 @@ typedef struct gnInstanceInfo_t {
gnRenderingAPI renderingAPI;
} gnInstanceInfo;
typedef struct gnInstance_t {
struct gnInstance_t {
struct gnPlatformInstance_t* instance;
gnBool valid,
loadDeviceFunctions,
@@ -30,9 +30,11 @@ typedef struct gnInstance_t {
struct gnCommandFunctions_t* commandFunctions;
struct gnDebugger_t* debugger;
} gnInstance;
} gnInstance_t;
gnReturnCode gnCreateInstance(gnInstance* instance, struct gnInstanceInfo_t info);
void gnInstanceAttachDebugger(gnInstance* istance, struct gnDebugger_t* debugger);
void gnInstanceReleaseDebugger(gnInstance* instance);
void gnDestroyInstance(gnInstance* instance);
typedef struct gnInstance_t* gnInstanceHandle;
gnReturnCode gnCreateInstance(gnInstanceHandle* instance, struct gnInstanceInfo_t info);
void gnInstanceAttachDebugger(gnInstanceHandle istance, struct gnDebugger_t* debugger);
void gnInstanceReleaseDebugger(gnInstanceHandle instance);
void gnDestroyInstance(gnInstanceHandle instance);

View File

@@ -3,7 +3,7 @@
#include "core/gryphn_platform_functions.h"
#include "core/instance/init/gryphn_init.h"
gnReturnCode gnCreateOutputDevice(gnOutputDevice* outputDevice, gnInstance* instance, struct gnOutputDeviceInfo_t deviceInfo) {
gnReturnCode gnCreateOutputDevice(gnOutputDevice* outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo) {
if (instance->loadDeviceFunctions == gnFalse) {
instance->deviceFunctions = malloc(sizeof(struct gnDeviceFunctions_t));
gnLoadDeviceFunctions(instance->dynamicLib, instance->deviceFunctions);

View File

@@ -21,10 +21,10 @@ typedef struct gnOutputDevice_t {
struct gnPlatformOutputDevice_t* outputDevice;
struct gnDeviceFunctions_t* deviceFunctions;
struct gnOutputDeviceInfo_t deviceInfo;
gnInstance* instance;
gnInstanceHandle instance;
gnPhysicalDevice physicalDevice;
} gnOutputDevice;
gnReturnCode gnCreateOutputDevice(gnOutputDevice* outputDevice, gnInstance* instance, struct gnOutputDeviceInfo_t deviceInfo);
gnReturnCode gnCreateOutputDevice(gnOutputDevice* outputDevice, gnInstanceHandle instance, struct gnOutputDeviceInfo_t deviceInfo);
void gnWaitForDevice(gnOutputDevice* device);
void gnDestroyOutputDevice(gnOutputDevice* device);

View File

@@ -3,7 +3,7 @@
#include "core/window_surface/gryphn_surface.h"
#include "stdio.h"
gnPhysicalDevice* gnGetPhyscialDevices(gnInstance* instance, uint32_t* count) {
gnPhysicalDevice* gnGetPhyscialDevices(gnInstanceHandle instance, uint32_t* count) {
gnPhysicalDevice* devices = instance->functions->_gnGetPhysicalDevices(instance, count);
for (int i = 0; i < *count; i++) {
devices[i].instance = instance;

View File

@@ -40,10 +40,10 @@ typedef struct gnPhysicalDevice_t {
struct gnPhysicalDeviceFeatures_t features;
struct gnPhysicalDeviceQueueProperties_t queueProperties;
gnInstance* instance;
gnInstanceHandle instance;
} gnPhysicalDevice;
gnPhysicalDevice* gnGetPhyscialDevices(gnInstance* instance, uint32_t* count);
gnPhysicalDevice* gnGetPhyscialDevices(gnInstanceHandle instance, uint32_t* count);
gnBool gnQueueCanPresentToSurface(const struct gnPhysicalDevice_t device, uint32_t queueIndex, const struct gnWindowSurface_t windowSurface);
gnBool gnHasGraphicsQueue(const struct gnPhysicalDevice_t device);

View File

@@ -20,7 +20,7 @@ typedef struct gnSurfaceDetails_t {
typedef struct gnWindowSurface_t {
struct gnPlatformWindowSurface_t* windowSurface;
gnInstance* instance;
gnInstanceHandle instance;
} gnWindowSurface;
void gnDestroyWindowSurface(struct gnWindowSurface_t* windowSurface);
struct gnSurfaceFormat_t* gnGetSupportedSurfaceFormats(

View File

@@ -4,12 +4,12 @@
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
gnReturnCode gnCreateX11WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnX11WindowSurfaceInfo_t createInfo) {
gnReturnCode gnCreateX11WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnX11WindowSurfaceInfo_t createInfo) {
return instance->functions->_gnCreateX11WindowSurface(windowSurface, instance, createInfo);
}
#endif
#ifdef GN_WINDOW_WAYLAND
gnReturnCode gnCreateWaylandWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWaylandWindowSurfaceInfo_t createInfo) {
gnReturnCode gnCreateWaylandWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo) {
return instance->functions->_gnCreateWaylandWindowSurface(windowSurface, instance, createInfo);
}
#endif
@@ -17,13 +17,13 @@
#ifdef GN_PLATFORM_WIN32
gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWin32WindowSurfaceInfo_t createInfo) {
gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo) {
return instance->functions->_gnCreateWin32WindowSurface(windowSurface, instance, createInfo);
}
#endif
#ifdef GN_PLATFORM_MACOS
gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo) {
gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo) {
windowSurface->instance = instance;
return instance->functions->_gnCreateMacOSWindowSurface(windowSurface, instance, createInfo);
}

View File

@@ -8,7 +8,7 @@
Window* window;
} gnX11WindowSurfaceCreateInfo;
gnReturnCode gnCreateX11WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnX11WindowSurfaceInfo_t createInfo);
gnReturnCode gnCreateX11WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnX11WindowSurfaceInfo_t createInfo);
#endif
#ifdef GN_WINDOW_WAYLAND
typedef struct gnWaylandWindowSurfaceInfo_t {
@@ -16,7 +16,7 @@
wl_surface* surface;
} gnWaylandWindowSurfaceInfo;
gnReturnCode gnCreateWaylandWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
gnReturnCode gnCreateWaylandWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWaylandWindowSurfaceInfo_t createInfo);
#endif
#endif
@@ -27,7 +27,7 @@
HINSTANCE* instance;
} gnWin32WindowSurfaceInfo;
gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnWin32WindowSurfaceInfo_t createInfo);
gnReturnCode gnCreateWin32WindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnWin32WindowSurfaceInfo_t createInfo);
#endif
#ifdef GN_PLATFORM_MACOS
@@ -35,5 +35,5 @@
CAMetalLayer* layer;
} gnMacOSWindowSurfaceInfo;
gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstance* instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
gnReturnCode gnCreateMacOSWindowSurface(struct gnWindowSurface_t* windowSurface, gnInstanceHandle instance, struct gnMacOSWindowSurfaceInfo_t createInfo);
#endif