take a bulldozer to some code

This commit is contained in:
Greg Wells
2025-05-20 17:39:40 -04:00
parent 43c6f88d18
commit a4166ae5c2
30 changed files with 495 additions and 503 deletions

View File

@@ -0,0 +1,17 @@
#undef GN_UTILS_CPP
#include "gryphn_debugger.h"
static gnReturnCode (*_gnCreateDebugger)(gnDebugger* debugger, const struct gnDebuggerInfo_t info);
static void (*_gnDestroyDebugger)(gnDebugger* debugger);
void gn_load_functions() {
}
// void gnAddDebugLayer(gnDebugger& debugger, const gnString& layer) {
// gnListAdd(debugger.debug_layers, layer);
// }
// const gnList<gnString>& gnDebuggerGetDebugLayers(gnDebugger& debugger) {
// return debugger.debug_layers;
// }

View File

@@ -1,9 +0,0 @@
#include "gryphn_debugger.h"
void gnAddDebugLayer(gnDebugger& debugger, const gnString& layer) {
gnListAdd(debugger.debug_layers, layer);
}
const gnList<gnString>& gnDebuggerGetDebugLayers(gnDebugger& debugger) {
return debugger.debug_layers;
}

View File

@@ -1,28 +1,17 @@
#pragma once
#include <gryphn/gryphn_utils.h>
#include <iostream>
#include "gryphn_layers.h"
#include "utils/strings/gryphn_string.h"
#include "utils/gryphn_error_code.h"
struct gnPlatformDebugger;
struct gnDebugger;
static gnDebugger* gnDebuggerInstance = nullptr;
inline void gnDebugError(gnString error);
typedef struct gnDebuggerInfo_t {
int layerCount;
gnString* layerNames;
} gnDebuggerInfo;
struct gnDebugger {
ACCESS_LEVEL:
gnPlatformDebugger* debugger;
gnList<gnString> debug_layers = gnCreateList<gnString>();
public:
gnDebugger() {
if (debugger) gnDebugError(gnCreateString("Debugger instance already created (you can only have one debugger)"));
gnDebuggerInstance = this;
}
};
typedef struct gnDebugger_t {
struct gnPlatformDebugger* debugger;
} gnDebugger;
inline void gnDebugError(gnString error) { std::cout << gnToCString(error) << "\n"; }
void gnAddDebugLayer(gnDebugger& debugger, const gnString& layer);
const gnList<gnString>& gnDebuggerGetDebugLayers(gnDebugger& debugger);
inline gnReturnCode (*gnCreateDebugger)(gnDebugger* instance);
inline void (*gnDestroyDebugger)(gnDebugger& instance);
gnReturnCode gnCreateDebugger(gnDebugger* debugger, const struct gnDebuggerInfo_t info);
gnReturnCode gnDestroyDebugger(gnDebugger* debugger);

View File

@@ -1,6 +0,0 @@
#pragma once
#include <gryphn/gryphn_utils.h>
inline gnString (*gnGetPlatformLayerName)(const gnString& gnName);
#define GN_DEFAULT_DEBUG_LAYER gnGetPlatformLayerName("GN_DEFAULT_DEBUG_LAYER")

View File

@@ -0,0 +1,10 @@
#pragma once
// theoretically you could have multible gryphn instances running in one application,
// why I dont know
#include "utils/gryphn_error_code.h"
#include "instance/gryphn_instance.h"
typedef struct gnFunctions_t {
gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info);
void (*_gnDestroyInstance)(gnInstance* instance);
} gnFunctions;

View File

@@ -1,7 +1,7 @@
#pragma once
#include "gryphn/gryphn_utils.h"
#include "utils/strings/gryphn_string.h"
enum gnRenderingAPI {
typedef enum gnRenderingAPI_t {
GN_RENDERINGAPI_NONE, // idk why im putting this
GN_RENDERINGAPI_SOFTWARE, // i kinda wanna write a software renderer
@@ -9,9 +9,9 @@ enum gnRenderingAPI {
GN_RENDERINGAPI_VULKAN,
GN_RENDERINGAPI_DIRECTX11, GN_RENDERINGAPI_DIRECTX12,
GN_RENDERINGAPI_METAL
};
} gnRenderingAPI;
inline gnString gnRenderingAPIName(gnRenderingAPI api) {
static gnString gnRenderingAPIName(gnRenderingAPI api) {
switch (api) {
case GN_RENDERINGAPI_NONE: return gnCreateString("GN_RENDERINGAPI_NONE");
case GN_RENDERINGAPI_SOFTWARE: return gnCreateString("GN_RENDERINGAPI_SOFTWARE");

View File

@@ -1,174 +0,0 @@
#include <core/init/gryphn_init.h>
#include <dlfcn.h>
#include <platform/gryphn_platform_include.h>
#include <algorithm>
#include <gryphn/gryphn.h>
bool RenderingAPISupported(gnRenderingAPI api) {
std::vector<gnRenderingAPI> supportedRenderingAPIS = gnGetSupportedRenderingAPIS();
return std::find(supportedRenderingAPIS.begin(), supportedRenderingAPIS.end(), api) != supportedRenderingAPIS.end();
}
static void* gnRenderingAPILIB;
//#define LOAD_FUNC(dll, func) gnPlatformLoadDLLFunction(dll, func, gnString(#func) + "Fn")
#define gnLoadDLLFunction(dll, func, func_name) \
gnPlatformLoadDLLFunction(dll, func, func_name); \
if (func == nullptr) return gnReturnError(GN_FUNCTION_NOT_FOUND, gnString("GN_FUNC_(") + gnString(#func) + ")_NOT_LOADED")
gnReturnCode gnInit(gnRenderingAPI RenderingAPI) {
gnString libName = "";
switch (RenderingAPI) {
case GN_RENDERINGAPI_NONE: {
return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api_none unsupported");
}
case GN_RENDERINGAPI_SOFTWARE: {
return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api_software unsupported");
}
case GN_RENDERINGAPI_OPENGL: {
return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api_opengl unsupported");
}
case GN_RENDERINGAPI_VULKAN: {
if (!RenderingAPISupported(GN_RENDERINGAPI_VULKAN)) return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api vulkan unsupported");
libName = "GryphnVulkanImpl";
break;
}
case GN_RENDERINGAPI_DIRECTX11: {
return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api directx11 unsupported");
}
case GN_RENDERINGAPI_DIRECTX12: {
return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api directx12 unsupported");
}
case GN_RENDERINGAPI_METAL: {
if (!RenderingAPISupported(GN_RENDERINGAPI_METAL)) return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api metal unsupported");
libName = "GryphnMetalImpl";
break;
}
}
gnRenderingAPILIB = gnPlatformLoadDLL(gnString("gryphn/rendering_apis/") + libName);
if (!gnRenderingAPILIB) { return gnReturnError(GN_UNABLE_TO_LOAD_DLL, "GN_ERROR_UNABLE_TO_LOAD_DLL"); }
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateInstance, "gnCreateInstanceFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyInstance, "gnDestroyInstanceFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGetPlatformLayerName, "gnGetPlatformLayerNameFn");
// LOAD THE SET WINDOW FUNCTIONS
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateX11WindowSurface, "gnCreateX11WindowSurfaceFn");
#endif
#ifdef GN_WINDOW_WAYLAND
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateWaylandWindowSurface, "gnCreateWaylandWindowSurfaceFn");
#endif
#endif
#ifdef GN_PLATFORM_WIN32
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateWindowsWindowSurface, "gnCreateWindowsWindowSurfaceFn");
#endif
#ifdef GN_PLATFORM_MACOS
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateMacOSWindowSurface, "gnCreateMacOSWindowSurfaceFn");
#endif
// This is stupid
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateDebugger, "gnCreateDebuggerFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyDebugger, "gnDestroyDebuggerFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGetPhysicalOutputDevices, "gnGetPhysicalOutputDevicesFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDeviceSupportsAPI, "gnDeviceSupportsAPIFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnRegisterOutputDevice, "gnRegisterOutputDeviceFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnWaitForDevice, "gnWaitForDeviceFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyOutputDevice, "gnDestroyOutputDeviceFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGetDevicePresentationDetails, "gnGetDevicePresentationDetailsFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnPresentationQueueGetNextImageAsync, "gnPresentationQueueGetNextImageAsyncFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnPresentationQueueGetState, "gnPresentationQueueGetStateFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreatePresentationQueue, "gnCreatePresentationQueueFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyPresentationQueue, "gnDestroyPresentationQueueFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnVertexDescriptionSetBindingDescription, "gnVertexDescriptionSetBindingDescriptionFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnVertexDescriptionSetPropertiesCount, "gnVertexDescriptionSetPropertiesCountFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnVertexDescriptionSetProperty, "gnVertexDescriptionSetPropertyFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateBuffer, "gnCreateBufferFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnBufferData, "gnBufferDataFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnBufferMapData, "gnBufferMapDataFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyBuffer, "gnDestroyBufferFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnBufferSubData, "gnBufferSubDataFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnBufferClearData, "gnBufferClearDataFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnTextureData, "gnTextureDataFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnTextureCubeMapData, "gnTextureCubeMapDataFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateTexture, "gnCreateTextureFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyTexture, "gnDestroyTextureFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateUniformLayout, "gnCreateUniformLayoutFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyUniformLayout, "gnDestroyUniformLayoutFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateRenderPass, "gnCreateRenderPassFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyRenderPass, "gnDestroyRenderPassFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateFence, "gnCreateFenceFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnWaitForFence, "gnWaitForFenceFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnResetFence, "gnResetFenceFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyFence, "gnDestroyFenceFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateCommandBuffer, "gnCreateCommandBufferFn");
gnLoadDLLFunction(gnRenderingAPILIB, _gnCreateCommandBuffers, "_gnCreateCommandBuffersFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBufferReset, "gnCommandBufferResetFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyCommandBuffer, "gnDestroyCommandBufferFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnBuildShaderModule, "gnBuildShaderModuleFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyShaderModule, "gnDestroyShaderModuleFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnBuildShader, "gnBuildShaderFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateUniform, "gnCreateUniformFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyUniform, "gnDestroyUniformFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnUpdateSamplerUniform, "gnUpdateSamplerUniformFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnUpdateBufferUniform, "gnUpdateBufferUniformFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnAPISupports, "gnAPISupportsFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetPrimative, "gnGraphicsPipelineSetPrimativeFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineEnableDynamicStates, "gnGraphicsPipelineEnableDynamicStatesFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineEnableDynamicState, "gnGraphicsPipelineEnableDynamicStateFn");
gnLoadDLLFunction(gnRenderingAPILIB, _gnGraphicsPipelineSetViewport, "_gnGraphicsPipelineSetViewportFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetCrop, "gnGraphicsPipelineSetCropFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetDepthClamp, "gnGraphicsPipelineSetDepthClampFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetFillMode, "gnGraphicsPipelineSetFillModeFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetLineWidth, "gnGraphicsPipelineSetLineWidthFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetCullMode, "gnGraphicsPipelineSetCullModeFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetMultisampling, "gnGraphicsPipelineSetMultisamplingFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineEnableDepthTest, "gnGraphicsPipelineEnableDepthTestFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetColorBlend, "gnGraphicsPipelineSetColorBlendFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetVertexDescription, "gnGraphicsPipelineSetVertexDescriptionFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineBindShader, "gnGraphicsPipelineBindShaderFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetRenderPass, "gnGraphicsPipelineSetRenderPassFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineAddUniformLayout, "gnGraphicsPipelineAddUniformLayoutFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineAddPushConstant, "gnGraphicsPipelineAddPushConstantFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateGraphicsPipeline, "gnCreateGraphicsPipelineFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyGraphicsPipeline, "gnDestroyGraphicsPipelineFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateFramebuffer, "gnCreateFramebufferFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyFramebuffer, "gnDestroyFramebufferFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateFramebufferAttachment, "gnCreateFramebufferAttachmentFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateSyncSemaphore, "gnCreateSyncSemaphoreFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroySyncSemaphore, "gnDestroySyncSemaphoreFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBufferStart, "gnCommandBufferStartFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBufferEnd, "gnCommandBufferEndFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBeginRenderPass, "gnCommandBeginRenderPassFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSetGraphicsPipeline, "gnCommandSetGraphicsPipelineFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBindSamplerUniform, "gnCommandBindSamplerUniformFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBindBuffer, "gnCommandBindBufferFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBindBufferUniform, "gnCommandBindBufferUniformFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandPushConstant, "gnCommandPushConstantFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandDrawIndexed, "gnCommandDrawIndexedFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSetViewport, "gnCommandSetViewportFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSetScissor, "gnCommandSetScissorFn");
gnLoadDLLFunction(gnRenderingAPILIB, _gnCommandDraw, "gnCommandDrawFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandEndRenderPass, "gnCommandEndRenderPassFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSubmitGetValidPresentationQueue, "gnCommandSubmitGetValidPresentationQueueFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSubmit, "gnCommandSubmitFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandPresentGetValidPresentationQueue, "gnCommandPresentGetValidPresentationQueueFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnCommandPresent, "gnCommandPresentFn");
// fucking hell I just realized that I do have to load in all the commands
// I hate the way I chose to do this
return GN_SUCCESS;
}
void gnDestroy() {
dlclose(gnRenderingAPILIB);
}

View File

@@ -1,10 +0,0 @@
#pragma once
#include <gryphn/gryphn_utils.h>
#include <core/gryphn_rendering_api.h>
gnErrorCode gnInit(gnRenderingAPI RenderingAPI);
void gnDestroy();
inline gnString cachePath;
static void gnSetCachePath(const gnString& path) { cachePath = path; }
static const gnString& gnGetCachePath() { return cachePath; }

View File

@@ -1,9 +0,0 @@
#pragma once
#include <gryphn/gryphn_utils.h>
struct gnAppInfo {
gnString ApplicationName;
gnString EngineName;
gnVersion ApplicationVersion;
gnVersion EngineVersion;
};

View File

@@ -0,0 +1,15 @@
#include "gryphn_instance.h"
#include "init/gryphn_init.h"
#include <core/gryphn_platform_functions.h>
gnReturnCode gnCreateInstance(gnInstance* instance, struct gnInstanceInfo_t info) {
if (!gnIsAPISupported(info.renderingAPI)) return GN_UNSUPPORTED_RENDERING_API;
instance->dynamicLib = gnLoadRenderingDLL(info.renderingAPI);
if (instance->dynamicLib == NULL) return GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY;
gnLoadFunctions(instance->dynamicLib, instance->functions);
return instance->functions->_gnCreateInstance(instance, info);
}
void gnDestroyInstance(gnInstance* instance) {
instance->functions->_gnDestroyInstance(instance);
}

View File

@@ -1,9 +0,0 @@
#include "gryphn_instance.h"
void gnInstanceSetDebugger(gnInstance& instance, gnDebugger& debugger) {
instance.debugger = &debugger;
}
void gnInstanceSetAppInfo(gnInstance& instance, const gnAppInfo info) {
instance.AppInfo = info;
}

View File

@@ -1,47 +1,51 @@
#pragma once
#include <gryphn/gryphn_utils.h>
#include "application_information/gryphn_app_info.h"
#include "core/debugger/gryphn_debugger.h"
#include <core/output_device/gryphn_output_device.h>
#include <platform/gryphn_platform_include.h>
#include "core/gryphn_rendering_api.h"
struct gnPlatformInstanceData;
struct gnPlatformInstance;
struct gnFunctions_t;
struct gnDynamicLibrary_t;
struct gnInstance {
ACCESS_LEVEL:
bool valid = false;
gnPlatformInstanceData* instance = nullptr;
gnAppInfo AppInfo;
gnDebugger* debugger;
public:
gnInstance() {}
};
typedef struct gnInstanceInfo_t {
gnString applicationName;
gnVersion applicationVersion;
void gnInstanceSetAppInfo(gnInstance& instance, const gnAppInfo info);
void gnInstanceSetDebugger(gnInstance& instance, gnDebugger& debugger);
gnString engineName;
gnVersion engineVersion;
inline gnReturnCode (*gnCreateInstance)(gnInstance* instance);
inline void (*gnDestroyInstance)(gnInstance& instance);
// inline gnReturnCode (*gnInstanceSetWindow)(gnInstance& instance, GLFWwindow* window);
gnRenderingAPI renderingAPI;
} gnInstanceInfo;
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
inline gnReturnCode (*gnCreateX11WindowSurface)(gnInstance& instance, Display* display, Window* window);
#endif
#ifdef GN_WINDOW_WAYLAND
inline gnReturnCode (*gnCreateWaylandWindowSurface)(gnInstance& instance, wl_display* display, wl_surface* surface);
#endif
#endif
typedef struct gnInstance_t {
struct gnPlatformInstance* instance;
gnBool valid;
struct gnFunctions_t* functions;
struct gnDynamicLibrary_t* dynamicLib;
} gnInstance;
gnReturnCode gnCreateInstance(gnInstance* instance, struct gnInstanceInfo_t info);
void gnDestroyInstance(gnInstance* instance);
// // inline gnReturnCode (*gnInstanceSetWindow)(gnInstance& instance, GLFWwindow* window);
// #ifdef GN_PLATFORM_LINUX
// #ifdef GN_WINDOW_X11
// inline gnReturnCode (*gnCreateX11WindowSurface)(gnInstance& instance, Display* display, Window* window);
// #endif
// #ifdef GN_WINDOW_WAYLAND
// inline gnReturnCode (*gnCreateWaylandWindowSurface)(gnInstance& instance, wl_display* display, wl_surface* surface);
// #endif
// #endif
#ifdef GN_PLATFORM_WIN32
inline gnReturnCode (*gnCreateWindowsWindowSurface)(gnInstance& instance, HWND* window, HINSTANCE* instance);
#endif
// #ifdef GN_PLATFORM_WIN32
// inline gnReturnCode (*gnCreateWindowsWindowSurface)(gnInstance& instance, HWND* window, HINSTANCE* instance);
// #endif
#ifdef GN_PLATFORM_MACOS
inline gnReturnCode (*gnCreateMacOSWindowSurface)(gnInstance& instance, NS::Window* window, NS::View* view);
#endif
// #ifdef GN_PLATFORM_MACOS
// typedef void* NSWindow;
// typedef void* NSView;
// TODO: if instance creation fails add in a query to why the instance creation failed
// Lowkey thats a lot of work tho and I dont really want to do alllllll that
// inline gnReturnCode (*gnCreateMacOSWindowSurface)(gnInstance& instance, NSWindow window, NSView view);
// #endif

View File

@@ -0,0 +1,14 @@
#pragma once
#include "utils/strings/gryphn_string.h"
#include "utils/gryphn_bool.h"
typedef struct gnDynamicLibrary_t {
void* dllPtr;
gnBool isValid;
} gnDynamicLibrary;
struct gnDynamicLibrary_t* gnLoadDynamicLibrary(const gnString path);
void gnUnloadDynamicLibrary(struct gnDynamicLibrary_t* dll);
void* gnLoadFunctionPtr(struct gnDynamicLibrary_t* dll, const char* name);
#define gnLoadDLLFunction(dll, function, name) function = (typeof(function))gnLoadFunctionPtr(dll, name)

View File

@@ -0,0 +1,168 @@
// #undef GN_UTILS_CPP
#include "gryphn_init.h"
#include <platform/gryphn_platform_include.h>
#include "gryphn_dynamic_library.h"
// #include <dlfcn.h>
gnBool gnIsAPISupported(gnRenderingAPI api) {
int renderingAPICount = 0;
gnRenderingAPI* supportedRenderingAPIS = gnGetSupportedRenderingAPIs(&renderingAPICount);
for (int i = 0; i < renderingAPICount; i++) if (supportedRenderingAPIS[i] == api) return true;
return false;
}
struct gnDynamicLibrary_t* gnLoadRenderingDLL(gnRenderingAPI renderingAPI) {
gnString libName = gnCreateEmptyString();
switch (renderingAPI) {
case GN_RENDERINGAPI_NONE: return NULL;
case GN_RENDERINGAPI_SOFTWARE: return NULL;
case GN_RENDERINGAPI_OPENGL: return NULL;
case GN_RENDERINGAPI_VULKAN: {
if (!gnIsAPISupported(GN_RENDERINGAPI_VULKAN)) return NULL;
libName = gnCreateString("GryphnVulkanImpl");
break;
}
case GN_RENDERINGAPI_DIRECTX11: return NULL;
case GN_RENDERINGAPI_DIRECTX12: return NULL;
case GN_RENDERINGAPI_METAL: {
if (!gnIsAPISupported(GN_RENDERINGAPI_METAL)) return NULL;
libName = gnCreateString("GryphnMetalImpl");
break;
}
}
return gnLoadDynamicLibrary(gnCombineStrings(gnCreateString("gryphn/rendering_apis/"), libName));
}
void gnLoadFunctions(struct gnDynamicLibrary_t* lib, struct gnFunctions_t* functions) {
gnLoadDLLFunction(lib, functions->_gnCreateInstance, "gnCreateInstanceFn");
gnLoadDLLFunction(lib, functions->_gnDestroyInstance, "gnDestroyInstanceFn");
}
// gnReturnCode gnInit(gnRenderingAPI RenderingAPI) {
// gnRenderingAPILIB = gnLoadDLL(gnCombineStrings(gnCreateString("gryphn/rendering_apis/"), libName));
// if (!gnRenderingAPILIB.isValid) { return GN_UNABLE_TO_LOAD_DLL; }
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateInstance, "gnCreateInstanceFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyInstance, "gnDestroyInstanceFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGetPlatformLayerName, "gnGetPlatformLayerNameFn");
// // LOAD THE SET WINDOW FUNCTIONS
// // #ifdef GN_PLATFORM_LINUX
// // #ifdef GN_WINDOW_X11
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateX11WindowSurface, "gnCreateX11WindowSurfaceFn");
// // #endif
// // #ifdef GN_WINDOW_WAYLAND
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateWaylandWindowSurface, "gnCreateWaylandWindowSurfaceFn");
// // #endif
// // #endif
// // #ifdef GN_PLATFORM_WIN32
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateWindowsWindowSurface, "gnCreateWindowsWindowSurfaceFn");
// // #endif
// // #ifdef GN_PLATFORM_MACOS
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateMacOSWindowSurface, "gnCreateMacOSWindowSurfaceFn");
// // #endif
// // This is stupid
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateDebugger, "gnCreateDebuggerFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyDebugger, "gnDestroyDebuggerFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGetPhysicalOutputDevices, "gnGetPhysicalOutputDevicesFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDeviceSupportsAPI, "gnDeviceSupportsAPIFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnRegisterOutputDevice, "gnRegisterOutputDeviceFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnWaitForDevice, "gnWaitForDeviceFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyOutputDevice, "gnDestroyOutputDeviceFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGetDevicePresentationDetails, "gnGetDevicePresentationDetailsFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnPresentationQueueGetNextImageAsync, "gnPresentationQueueGetNextImageAsyncFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnPresentationQueueGetState, "gnPresentationQueueGetStateFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreatePresentationQueue, "gnCreatePresentationQueueFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyPresentationQueue, "gnDestroyPresentationQueueFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnVertexDescriptionSetBindingDescription, "gnVertexDescriptionSetBindingDescriptionFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnVertexDescriptionSetPropertiesCount, "gnVertexDescriptionSetPropertiesCountFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnVertexDescriptionSetProperty, "gnVertexDescriptionSetPropertyFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateBuffer, "gnCreateBufferFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnBufferData, "gnBufferDataFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnBufferMapData, "gnBufferMapDataFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyBuffer, "gnDestroyBufferFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnBufferSubData, "gnBufferSubDataFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnBufferClearData, "gnBufferClearDataFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnTextureData, "gnTextureDataFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnTextureCubeMapData, "gnTextureCubeMapDataFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateTexture, "gnCreateTextureFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyTexture, "gnDestroyTextureFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateUniformLayout, "gnCreateUniformLayoutFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyUniformLayout, "gnDestroyUniformLayoutFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateRenderPass, "gnCreateRenderPassFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyRenderPass, "gnDestroyRenderPassFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateFence, "gnCreateFenceFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnWaitForFence, "gnWaitForFenceFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnResetFence, "gnResetFenceFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyFence, "gnDestroyFenceFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateCommandBuffer, "gnCreateCommandBufferFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, _gnCreateCommandBuffers, "_gnCreateCommandBuffersFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBufferReset, "gnCommandBufferResetFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyCommandBuffer, "gnDestroyCommandBufferFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnBuildShaderModule, "gnBuildShaderModuleFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyShaderModule, "gnDestroyShaderModuleFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnBuildShader, "gnBuildShaderFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateUniform, "gnCreateUniformFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyUniform, "gnDestroyUniformFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnUpdateSamplerUniform, "gnUpdateSamplerUniformFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnUpdateBufferUniform, "gnUpdateBufferUniformFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnAPISupports, "gnAPISupportsFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetPrimative, "gnGraphicsPipelineSetPrimativeFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineEnableDynamicStates, "gnGraphicsPipelineEnableDynamicStatesFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineEnableDynamicState, "gnGraphicsPipelineEnableDynamicStateFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, _gnGraphicsPipelineSetViewport, "_gnGraphicsPipelineSetViewportFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetCrop, "gnGraphicsPipelineSetCropFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetDepthClamp, "gnGraphicsPipelineSetDepthClampFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetFillMode, "gnGraphicsPipelineSetFillModeFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetLineWidth, "gnGraphicsPipelineSetLineWidthFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetCullMode, "gnGraphicsPipelineSetCullModeFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetMultisampling, "gnGraphicsPipelineSetMultisamplingFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineEnableDepthTest, "gnGraphicsPipelineEnableDepthTestFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetColorBlend, "gnGraphicsPipelineSetColorBlendFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetVertexDescription, "gnGraphicsPipelineSetVertexDescriptionFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineBindShader, "gnGraphicsPipelineBindShaderFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetRenderPass, "gnGraphicsPipelineSetRenderPassFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineAddUniformLayout, "gnGraphicsPipelineAddUniformLayoutFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineAddPushConstant, "gnGraphicsPipelineAddPushConstantFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateGraphicsPipeline, "gnCreateGraphicsPipelineFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyGraphicsPipeline, "gnDestroyGraphicsPipelineFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateFramebuffer, "gnCreateFramebufferFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyFramebuffer, "gnDestroyFramebufferFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateFramebufferAttachment, "gnCreateFramebufferAttachmentFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateSyncSemaphore, "gnCreateSyncSemaphoreFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroySyncSemaphore, "gnDestroySyncSemaphoreFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBufferStart, "gnCommandBufferStartFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBufferEnd, "gnCommandBufferEndFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBeginRenderPass, "gnCommandBeginRenderPassFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSetGraphicsPipeline, "gnCommandSetGraphicsPipelineFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBindSamplerUniform, "gnCommandBindSamplerUniformFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBindBuffer, "gnCommandBindBufferFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBindBufferUniform, "gnCommandBindBufferUniformFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandPushConstant, "gnCommandPushConstantFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandDrawIndexed, "gnCommandDrawIndexedFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSetViewport, "gnCommandSetViewportFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSetScissor, "gnCommandSetScissorFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, _gnCommandDraw, "gnCommandDrawFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandEndRenderPass, "gnCommandEndRenderPassFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSubmitGetValidPresentationQueue, "gnCommandSubmitGetValidPresentationQueueFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSubmit, "gnCommandSubmitFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandPresentGetValidPresentationQueue, "gnCommandPresentGetValidPresentationQueueFn");
// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandPresent, "gnCommandPresentFn");
// return GN_SUCCESS;
// }
// void* gnLoadFunction(gnString name) {
// return gnLoadFunctionPtr(gnRenderingAPILIB, name);
// }
// void gnDestroy() {
// gnUnloadDLL(&gnRenderingAPILIB);
// }

View File

@@ -0,0 +1,15 @@
#pragma once
#include <gryphn/gryphn_utils.h>
#include <core/gryphn_rendering_api.h>
#include "core/gryphn_platform_functions.h"
// #include "utils/gryphn_error_code.h"
gnBool gnIsAPISupported(gnRenderingAPI RenderingAPI);
struct gnDynamicLibrary_t* gnLoadRenderingDLL(gnRenderingAPI RenderingAPI);
void gnLoadFunctions(struct gnDynamicLibrary_t* lib, struct gnFunctions_t* functions);
// #ifdef GN_REVEAL_IMPL
// gnErrorCode gnInit(gnRenderingAPI RenderingAPI);
// void gnDestroy();
// void* gnLoadFunction(gnString name);
// #endif

View File

@@ -24,7 +24,7 @@ inline gnReturnCode (*gnCreatePresentationQueue)(gnPresentationQueue* presentati
inline void (*gnDestroyPresentationQueue)(gnPresentationQueue& queue);
inline gnImageFormat (*_gnPresentationQueueGetImageFormat)(gnPresentationQueue& presentationQueue);
inline gnImageFormat gnPresentationQueueGetImageFormat(gnPresentationQueue& presentationQueue) {
std::cout << "gnPresentationQueueGetImageFormat should lowkey become supported\n";
// std::cout << "gnPresentationQueueGetImageFormat should lowkey become supported\n";
return _gnPresentationQueueGetImageFormat(presentationQueue);
}
inline gnPresentationQueueState (*gnPresentationQueueGetState)(gnPresentationQueue& presentationQueue);