From a4166ae5c2dd2811b45f7b99579b45611c4351b2 Mon Sep 17 00:00:00 2001 From: Greg Wells Date: Tue, 20 May 2025 17:39:40 -0400 Subject: [PATCH] take a bulldozer to some code --- include/gryphn/gryphn.h | 51 ++--- include/gryphn/gryphn_utils.h | 33 ++-- src/core/debugger/gryphn_debugger.c | 17 ++ src/core/debugger/gryphn_debugger.cpp | 9 - src/core/debugger/gryphn_debugger.h | 33 ++-- src/core/debugger/gryphn_layers.h | 6 - src/core/gryphn_platform_functions.h | 10 + src/core/gryphn_rendering_api.h | 8 +- src/core/init/gryphn_init.cpp | 174 ------------------ src/core/init/gryphn_init.h | 10 - .../application_information/gryphn_app_info.h | 9 - src/core/instance/gryphn_instance.c | 15 ++ src/core/instance/gryphn_instance.cpp | 9 - src/core/instance/gryphn_instance.h | 76 ++++---- .../instance/init/gryphn_dynamic_library.h | 14 ++ src/core/instance/init/gryphn_init.c | 168 +++++++++++++++++ src/core/instance/init/gryphn_init.h | 15 ++ .../gryphn_presentation_queue.h | 2 +- src/platform/gryphn_platform_include.h | 22 +-- .../platform_macos/gryphn_platform_macos.c | 33 ++++ .../platform_macos/gryphn_platform_macos.cpp | 17 -- .../platform_macos/gryphn_platform_macos.h | 8 - src/utils/gryphn_error_code.h | 46 +++-- .../{gryphn_c_list.h => gryphn_array_list.h} | 12 +- src/utils/lists/gryphn_linked_list.h | 22 +++ src/utils/lists/gryphn_list.h | 85 --------- src/utils/math/gryphn_vec2.h | 89 ++++++--- src/utils/math/gryphn_vec3.h | 2 +- src/utils/strings/gryphn_string.h | 2 +- src/utils/types/gryphn_color.h | 1 + 30 files changed, 495 insertions(+), 503 deletions(-) create mode 100644 src/core/debugger/gryphn_debugger.c delete mode 100644 src/core/debugger/gryphn_debugger.cpp delete mode 100644 src/core/debugger/gryphn_layers.h create mode 100644 src/core/gryphn_platform_functions.h delete mode 100644 src/core/init/gryphn_init.cpp delete mode 100644 src/core/init/gryphn_init.h delete mode 100644 src/core/instance/application_information/gryphn_app_info.h create mode 100644 src/core/instance/gryphn_instance.c delete mode 100644 src/core/instance/gryphn_instance.cpp create mode 100644 src/core/instance/init/gryphn_dynamic_library.h create mode 100644 src/core/instance/init/gryphn_init.c create mode 100644 src/core/instance/init/gryphn_init.h create mode 100644 src/platform/platform_macos/gryphn_platform_macos.c delete mode 100644 src/platform/platform_macos/gryphn_platform_macos.cpp rename src/utils/lists/{gryphn_c_list.h => gryphn_array_list.h} (80%) create mode 100644 src/utils/lists/gryphn_linked_list.h delete mode 100644 src/utils/lists/gryphn_list.h diff --git a/include/gryphn/gryphn.h b/include/gryphn/gryphn.h index a5313e4..e051755 100644 --- a/include/gryphn/gryphn.h +++ b/include/gryphn/gryphn.h @@ -1,27 +1,32 @@ #pragma once - -#include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + +// #pragma once + +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include diff --git a/include/gryphn/gryphn_utils.h b/include/gryphn/gryphn_utils.h index 6483b0d..955fec9 100644 --- a/include/gryphn/gryphn_utils.h +++ b/include/gryphn/gryphn_utils.h @@ -1,23 +1,20 @@ #pragma once -#include -#include +// #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +// #include +// #include +// #include +// #include +// #include +// #include +// #include -#include -typedef uint32_t gnUInt; -typedef gnChar gnByte; -typedef unsigned char gnUByte; -typedef int gnInt; -typedef float gnFloat; -typedef size_t gnSize; +// typedef uint32_t gnUInt; +// typedef gnChar gnByte; +// typedef unsigned char gnUByte; +// typedef int gnInt; +// typedef float gnFloat; +// typedef size_t gnSize; -#define GN_EXPORT extern "C" +// #define GN_EXPORT extern "C" diff --git a/src/core/debugger/gryphn_debugger.c b/src/core/debugger/gryphn_debugger.c new file mode 100644 index 0000000..ad80572 --- /dev/null +++ b/src/core/debugger/gryphn_debugger.c @@ -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& gnDebuggerGetDebugLayers(gnDebugger& debugger) { +// return debugger.debug_layers; +// } diff --git a/src/core/debugger/gryphn_debugger.cpp b/src/core/debugger/gryphn_debugger.cpp deleted file mode 100644 index 810c0a6..0000000 --- a/src/core/debugger/gryphn_debugger.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "gryphn_debugger.h" - -void gnAddDebugLayer(gnDebugger& debugger, const gnString& layer) { - gnListAdd(debugger.debug_layers, layer); -} - -const gnList& gnDebuggerGetDebugLayers(gnDebugger& debugger) { - return debugger.debug_layers; -} diff --git a/src/core/debugger/gryphn_debugger.h b/src/core/debugger/gryphn_debugger.h index c33ba35..f835408 100644 --- a/src/core/debugger/gryphn_debugger.h +++ b/src/core/debugger/gryphn_debugger.h @@ -1,28 +1,17 @@ #pragma once -#include -#include -#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 debug_layers = gnCreateList(); -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& 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); diff --git a/src/core/debugger/gryphn_layers.h b/src/core/debugger/gryphn_layers.h deleted file mode 100644 index 4391b55..0000000 --- a/src/core/debugger/gryphn_layers.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -#include - -inline gnString (*gnGetPlatformLayerName)(const gnString& gnName); - -#define GN_DEFAULT_DEBUG_LAYER gnGetPlatformLayerName("GN_DEFAULT_DEBUG_LAYER") diff --git a/src/core/gryphn_platform_functions.h b/src/core/gryphn_platform_functions.h new file mode 100644 index 0000000..6ec4b87 --- /dev/null +++ b/src/core/gryphn_platform_functions.h @@ -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; diff --git a/src/core/gryphn_rendering_api.h b/src/core/gryphn_rendering_api.h index bf3d05b..7c84888 100644 --- a/src/core/gryphn_rendering_api.h +++ b/src/core/gryphn_rendering_api.h @@ -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"); diff --git a/src/core/init/gryphn_init.cpp b/src/core/init/gryphn_init.cpp deleted file mode 100644 index d062c48..0000000 --- a/src/core/init/gryphn_init.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include -#include -#include -#include -#include - -bool RenderingAPISupported(gnRenderingAPI api) { - std::vector 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); -} diff --git a/src/core/init/gryphn_init.h b/src/core/init/gryphn_init.h deleted file mode 100644 index 4b8328b..0000000 --- a/src/core/init/gryphn_init.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include -#include - -gnErrorCode gnInit(gnRenderingAPI RenderingAPI); -void gnDestroy(); - -inline gnString cachePath; -static void gnSetCachePath(const gnString& path) { cachePath = path; } -static const gnString& gnGetCachePath() { return cachePath; } diff --git a/src/core/instance/application_information/gryphn_app_info.h b/src/core/instance/application_information/gryphn_app_info.h deleted file mode 100644 index bb6ba10..0000000 --- a/src/core/instance/application_information/gryphn_app_info.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -struct gnAppInfo { - gnString ApplicationName; - gnString EngineName; - gnVersion ApplicationVersion; - gnVersion EngineVersion; -}; diff --git a/src/core/instance/gryphn_instance.c b/src/core/instance/gryphn_instance.c new file mode 100644 index 0000000..d76f62c --- /dev/null +++ b/src/core/instance/gryphn_instance.c @@ -0,0 +1,15 @@ +#include "gryphn_instance.h" +#include "init/gryphn_init.h" +#include + +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); +} diff --git a/src/core/instance/gryphn_instance.cpp b/src/core/instance/gryphn_instance.cpp deleted file mode 100644 index 44ad3cd..0000000 --- a/src/core/instance/gryphn_instance.cpp +++ /dev/null @@ -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; -} diff --git a/src/core/instance/gryphn_instance.h b/src/core/instance/gryphn_instance.h index a4f0235..07ab608 100644 --- a/src/core/instance/gryphn_instance.h +++ b/src/core/instance/gryphn_instance.h @@ -1,47 +1,51 @@ #pragma once #include -#include "application_information/gryphn_app_info.h" -#include "core/debugger/gryphn_debugger.h" -#include -#include +#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 diff --git a/src/core/instance/init/gryphn_dynamic_library.h b/src/core/instance/init/gryphn_dynamic_library.h new file mode 100644 index 0000000..6bde80d --- /dev/null +++ b/src/core/instance/init/gryphn_dynamic_library.h @@ -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) diff --git a/src/core/instance/init/gryphn_init.c b/src/core/instance/init/gryphn_init.c new file mode 100644 index 0000000..131930e --- /dev/null +++ b/src/core/instance/init/gryphn_init.c @@ -0,0 +1,168 @@ +// #undef GN_UTILS_CPP +#include "gryphn_init.h" +#include +#include "gryphn_dynamic_library.h" +// #include + +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); +// } diff --git a/src/core/instance/init/gryphn_init.h b/src/core/instance/init/gryphn_init.h new file mode 100644 index 0000000..058f657 --- /dev/null +++ b/src/core/instance/init/gryphn_init.h @@ -0,0 +1,15 @@ +#pragma once +#include +#include +#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 diff --git a/src/core/presentation_queue/gryphn_presentation_queue.h b/src/core/presentation_queue/gryphn_presentation_queue.h index 66d37af..0736387 100644 --- a/src/core/presentation_queue/gryphn_presentation_queue.h +++ b/src/core/presentation_queue/gryphn_presentation_queue.h @@ -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); diff --git a/src/platform/gryphn_platform_include.h b/src/platform/gryphn_platform_include.h index fcdf65b..1b85afc 100644 --- a/src/platform/gryphn_platform_include.h +++ b/src/platform/gryphn_platform_include.h @@ -1,8 +1,8 @@ #pragma once - +#include "core/gryphn_rendering_api.h" #ifdef GN_PLATFORM_LINUX -#include +#include "platform_linux/gryphn_platform_linux.h" #endif #ifdef GN_PLATFORM_MACOS @@ -10,16 +10,14 @@ #endif #ifdef GN_PLATFORM_WINDOWS -#include +#include "platform_windows/gryphn_platform_windows.h" #endif -#include +gnRenderingAPI* gnGetSupportedRenderingAPIs(int* count); -std::vector gnGetSupportedRenderingAPIS(); -void* gnPlatformLoadDLL(gnString name); -void* gnLoadFunctionPtr(void* dll, gnString name); - -template -void gnPlatformLoadDLLFunction(void *dll, function& func, gnString name) { - func = (function)gnLoadFunctionPtr(dll, name); -} +// #ifdef __cplusplus +// template +// void gnPlatformLoadDLLFunction(void *dll, function& func, gnString name) { +// func = (function)gnLoadFunctionPtr(dll, name); +// } +// #endif diff --git a/src/platform/platform_macos/gryphn_platform_macos.c b/src/platform/platform_macos/gryphn_platform_macos.c new file mode 100644 index 0000000..673d89f --- /dev/null +++ b/src/platform/platform_macos/gryphn_platform_macos.c @@ -0,0 +1,33 @@ +#ifdef GN_PLATFORM_MACOS +#undef GN_UTILS_CPP +#include "core/gryphn_rendering_api.h" +#include "core/instance/init/gryphn_dynamic_library.h" +#include "dlfcn.h" + +gnRenderingAPI renderingAPIs[3] = { + GN_RENDERINGAPI_METAL, + GN_RENDERINGAPI_VULKAN, + GN_RENDERINGAPI_SOFTWARE +}; + +gnRenderingAPI* gnGetSupportedRenderingAPIs(int* count) { + *count = 3; + return renderingAPIs; +} + +struct gnDynamicLibrary_t* gnLoadDynamicLibrary(const gnString path) { + struct gnDynamicLibrary_t* dll = malloc(sizeof(struct gnDynamicLibrary_t)); + dll->dllPtr = dlopen(gnToCString(gnCombineStrings(path, ".dylib")), RTLD_LAZY), + dll->isValid = true + if (dll->dllPtr == NULL) dll->isValid = false; + return dll; +} +void* gnLoadFunctionPtr(struct gnDynamicLibrary_t* dll, const char* name) { + if (dll->isValid == false) return NULL; + return dlsym(dll->dllPtr, name); +} +void gnUnloadDynamicLibrary(struct gnDynamicLibrary_t* dll) { + if (dll->isValid) dlclose(dll->dllPtr); +} + +#endif diff --git a/src/platform/platform_macos/gryphn_platform_macos.cpp b/src/platform/platform_macos/gryphn_platform_macos.cpp deleted file mode 100644 index 80a149c..0000000 --- a/src/platform/platform_macos/gryphn_platform_macos.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifdef GN_PLATFORM_MACOS -#include -#include - -std::vector gnGetSupportedRenderingAPIS() { - return { GN_RENDERINGAPI_METAL, GN_RENDERINGAPI_VULKAN }; -} - -void* gnPlatformLoadDLL(gnString name) { - return dlopen(gnToCString(name + ".dylib"), RTLD_LAZY); -} - -void* gnLoadFunctionPtr(void *dll, gnString name) { - return dlsym(dll, gnToCString(name)); -} - -#endif diff --git a/src/platform/platform_macos/gryphn_platform_macos.h b/src/platform/platform_macos/gryphn_platform_macos.h index d670fb5..43b4fea 100644 --- a/src/platform/platform_macos/gryphn_platform_macos.h +++ b/src/platform/platform_macos/gryphn_platform_macos.h @@ -1,11 +1,3 @@ #pragma once -#include #include -#include #include - -namespace NS { - struct Window; - struct View; -} -// #include "AppKit/NSView.hpp" diff --git a/src/utils/gryphn_error_code.h b/src/utils/gryphn_error_code.h index a206712..88e3234 100644 --- a/src/utils/gryphn_error_code.h +++ b/src/utils/gryphn_error_code.h @@ -1,29 +1,27 @@ #pragma once -typedef enum gnReturnCode { - GN_SUCCESS, GN_WARNING, GN_FAILED, - GN_ERROR = GN_FAILED +typedef enum gnReturnCode_t { + GN_SUCCESS, + GN_UNKNOWN_RENDERINGAPI, + GN_UNSUPPORTED_RENDERING_API, + GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY + + // GN_UNKNOWN_ERROR, + // GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, + // GN_UNKNOWN_SHADER_MODULE, + // GN_UNKNOWN_FUNCTION, + // GN_SHADER_FAILED_TO_COMPILE, + // GN_UNSUPPORTED_COLOR_FORMAT, + // GN_UNKNOWN_COLOR_FORMAT, + // GN_FUNCTION_NOT_FOUND, + // GN_FAILED_CREATE_DEVICE, + // GN_FAILED_CREATE_GRAPHICS_PIPELINE, + // GN_FAILED_CREATE_PRESENTATION_QUEUE, + // GN_FAILED_TO_CREATE_FRAMEBUFFER, + // GN_FAILED_CREATE_RENDERPASS, + // GN_FAILED_CREATE_INSTANCE, + // GN_FAILED_TO_ATTACH_WINDOW, + // GN_FAILED_TO_CREATE_IMAGE } gnReturnCode; -typedef enum gnReturnMessage { - GN_UNKNOWN_ERROR, - GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, - GN_UNKNOWN_SHADER_MODULE, - GN_SHADER_FAILED_TO_COMPILE, - GN_UNSUPPORTED_COLOR_FORMAT, - GN_UNKNOWN_COLOR_FORMAT, - GN_UNSUPPORTED_RENDERING_API, - GN_FUNCTION_NOT_FOUND, - GN_UNABLE_TO_LOAD_DLL, - GN_FAILED_CREATE_DEVICE, - GN_FAILED_CREATE_GRAPHICS_PIPELINE, - GN_FAILED_CREATE_PRESENTATION_QUEUE, - GN_FAILED_TO_CREATE_FRAMEBUFFER, - GN_FAILED_CREATE_RENDERPASS, - GN_FAILED_CREATE_INSTANCE, - GN_FAILED_TO_ATTACH_WINDOW, - GN_FAILED_TO_CREATE_IMAGE -} gnReturnMessage; - typedef gnReturnCode gnErrorCode; -typedef gnReturnMessage gnErrorMessage; diff --git a/src/utils/lists/gryphn_c_list.h b/src/utils/lists/gryphn_array_list.h similarity index 80% rename from src/utils/lists/gryphn_c_list.h rename to src/utils/lists/gryphn_array_list.h index 3c344ae..467fd18 100644 --- a/src/utils/lists/gryphn_c_list.h +++ b/src/utils/lists/gryphn_array_list.h @@ -1,16 +1,16 @@ #pragma once #include "stdlib.h" -typedef struct gnCList { +typedef struct gnArrayList { int count; int maxCount; void* data; -} gnCList; +} gnArrayList; const int GROWTH_RATE = 2; // i heard somewhere that 1.5 is better but imma use 2 because I also heard that its better somewhere else -inline gnCList gnCreateCList(int count) { - gnCList newList; +inline gnArrayList gnCreateArrayList(int count) { + gnArrayList newList; if (count == 0) { @@ -23,7 +23,7 @@ inline gnCList gnCreateCList(int count) { return newList; } -inline void gnCListResize(gnCList* cList, int count) { +inline void gnArrayListResize(gnArrayList* cList, int count) { cList->count = count; while (cList->count > cList->maxCount) { int oldMaxCount = cList->maxCount; @@ -36,7 +36,7 @@ inline void gnCListResize(gnCList* cList, int count) { cList->data = realloc(cList->data, cList->maxCount); } -inline void gnCListReserve(gnCList* cList, int count) { +inline void gnArrayListReserve(gnArrayList* cList, int count) { while (cList->count > cList->maxCount) { int oldMaxCount = cList->maxCount; cList->maxCount *= GROWTH_RATE; diff --git a/src/utils/lists/gryphn_linked_list.h b/src/utils/lists/gryphn_linked_list.h new file mode 100644 index 0000000..799b912 --- /dev/null +++ b/src/utils/lists/gryphn_linked_list.h @@ -0,0 +1,22 @@ +#pragma once +#include "stdlib.h" + +// why would one use a linked list +typedef struct gnLinkedList { + void* data; + gnLinkedList* nextNode; +} gnLinkedList; + +static gnLinkedList gnCreateLinkedList(int count) { + gnLinkedList list; + + gnLinkedList* currentNode = &list; + for (int i = 0; i < count; i++) { + if ((i + 1) < count) { + currentNode->nextNode = (gnLinkedList*)malloc(sizeof(gnLinkedList)); + currentNode = currentNode->nextNode; + } + } + + return list; +} diff --git a/src/utils/lists/gryphn_list.h b/src/utils/lists/gryphn_list.h deleted file mode 100644 index 99fce45..0000000 --- a/src/utils/lists/gryphn_list.h +++ /dev/null @@ -1,85 +0,0 @@ -#pragma once -#include "math.h" -#include "stdio.h" - -// TODO: Wack ass list class, needs some serious refactoring, buttttt it works for what I need it to do -// Imma touch this later cuz like I dont like working with C code cuz its wierd but like its also fun -// who needs std::vector when you've got malloc, calloc, and free -// shit just forgot that I dont clean any of this up, imma do this later cuz like its boring -// ive decided to do it now, I hate this, I hate coding, C is fun, this is a Cpp file, what am I doing with life -// I never did it id be super easy just like one anitconstructor????? i dont remeber what is called its the one with the squigly bracked -// TODO: future me rewirte these comments to be less stupid -// TODO: Add insert function, also remove function, orrrrrr i could have people copy lists whever they wanna remove stuff, nah thats gunna piss me off too - -#define GRYPHN_LIST_GROWTH_RATE 2 // number straight from my ass I wanted to use 1.5f cuz thats what STL does but like it complained - // im in an abbusive relationship with the compiler, I need to get out of this - // but like I also kinda like it imma pick of drinking (not actually imma just play minecraft) - -template // fuck templates -struct gnList { -protected: - Type* items = nullptr; - int size = 0, max_size = 0; -public: - gnList() {} - - // why did I make shit protected - // theres gotta be a better way to do this with compiler macros but like that sounds hard - // im never touching this wack ass code ever again - template - friend gnList gnCreateList(int size); - template - friend void gnListAdd(gnList& list, T item); - template - friend int gnListLength(const gnList& list); - template - friend T& gnListGet(const gnList& list, int index); - template - friend T* gnListGetPtr(const gnList& list, int index); - template - friend void gnListSet(const gnList& list, int index, T item); - template - friend T* gnListData(const gnList& list); -public: - Type operator[](int index) const { return items[index]; } // idfk what that const is doin there but the compiler complained I was tryna change a const value - // .... I was not, I really am in an abusive relationship - Type& operator[](int index) { return items[index]; } -}; - -template -gnList gnCreateList(int size = 0) { - gnList new_list = gnList(); - new_list.size = size; - if (size == 0) size = round(GRYPHN_LIST_GROWTH_RATE); - new_list.items = (T*)malloc(sizeof(T) * size); - new_list.max_size = size; - return new_list; -} - -template -void gnListAdd(gnList& list, T item) { - if (gnListLength(list) == list.max_size) { - list.max_size = list.max_size * GRYPHN_LIST_GROWTH_RATE; - list.items = (T*)realloc(list.items, sizeof(T) * list.max_size); - } - - list.items[list.size] = item; - list.size++; -} - -template -int gnListLength(const gnList& list) { return list.size; } - -template -T& gnListGet(const gnList& list, int index) { return list.items[index]; } - -template -T* gnListGetPtr(const gnList& list, int index) { return &list.items[index]; } - -template -void gnListSet(const gnList& list, int index, T item) { list.items[index] = item; } - -template -T* gnListData(const gnList& list) { return list.items; } // wack ass function for binary shit - // if this ever breaks change it to return &list.items[0] cuz that might work - // I have zero clue what any of this shit does diff --git a/src/utils/math/gryphn_vec2.h b/src/utils/math/gryphn_vec2.h index d3aff05..c3c8541 100644 --- a/src/utils/math/gryphn_vec2.h +++ b/src/utils/math/gryphn_vec2.h @@ -1,44 +1,77 @@ #pragma once -#include -#include - -// very shitty vec2 class - #include "stdint.h" -template -struct gnType2 { +typedef struct gnVec2 { union { - struct { T a, b; }; - struct { T x, y; }; + struct { float a, b; }; + struct { float x, y; }; }; -public: - gnType2(T a, T b) { this->a = a; this->b = b; } - gnType2() {}; - gnType2 operator-(const gnType2& other) { - gnType2 returnGnVec2; +#ifdef GN_UTILS_CPP + gnVec2(float x, float y) { this->x = x; this->y = y; } + gnVec2(float s) { this->x = s; this->y = s; } + gnVec2() {}; + + gnVec2 operator-(const gnVec2& other) { + gnVec2 returnGnVec2; returnGnVec2.x = this->x - other.x; returnGnVec2.y = this->y - other.y; return returnGnVec2; } - bool operator==(const gnType2& other) const { + bool operator==(const gnVec2& other) const { return this->a == other.a && this->b == other.b; } -}; +#endif +} gnVec2; +typedef gnVec2 gnFVec2; +typedef gnVec2 gnFloat2; -typedef gnType2 gnVec2; -typedef gnType2 gnFloat2; -typedef gnType2 gnUInt2; -typedef gnType2 gnInt2; - -namespace std { - template<> - struct hash { - std::size_t operator()(const gnUInt2& k) const { - return std::hash()(k.x) ^ (std::hash()(k.y) << 1); - } +typedef struct gnUInt2 { + union { + struct { uint32_t a, b; }; + struct { uint32_t x, y; }; }; -} + +#ifdef GN_UTILS_CPP + gnUInt2(uint32_t x, uint32_t y) { this->x = x; this->y = y; } + gnUInt2(uint32_t s) { this->x = s; this->y = s; } + gnUInt2() {}; + + gnUInt2 operator-(const gnUInt2& other) { + gnUInt2 returnGnVec2; + returnGnVec2.x = this->x - other.x; + returnGnVec2.y = this->y - other.y; + return returnGnVec2; + } + + bool operator==(const gnUInt2& other) const { + return this->a == other.a && this->b == other.b; + } +#endif +} gnUInt2; + +typedef struct gnInt2 { + union { + struct { int a, b; }; + struct { int x, y; }; + }; + +#ifdef GN_UTILS_CPP + gnInt2(int x, int y) { this->x = x; this->y = y; } + gnInt2(int s) { this->x = s; this->y = s; } + gnInt2() {}; + + gnInt2 operator-(const gnInt2& other) { + gnInt2 returnGnVec2; + returnGnVec2.x = this->x - other.x; + returnGnVec2.y = this->y - other.y; + return returnGnVec2; + } + + bool operator==(const gnInt2& other) const { + return this->a == other.a && this->b == other.b; + } +#endif +} gnInt2; diff --git a/src/utils/math/gryphn_vec3.h b/src/utils/math/gryphn_vec3.h index f2b7d4d..7f424e1 100644 --- a/src/utils/math/gryphn_vec3.h +++ b/src/utils/math/gryphn_vec3.h @@ -36,7 +36,7 @@ typedef struct gnUInt3 { }; #ifdef GN_UTILS_CPP - gnUInt3(uint32_t x, uint32_t y) { this->x = x; this->y = y; this->z = z; } + gnUInt3(uint32_t x, uint32_t y, uint32_t z) { this->x = x; this->y = y; this->z = z; } gnUInt3(uint32_t s) { this->x = s; this->y = s; this->z = s; } gnUInt3() {}; diff --git a/src/utils/strings/gryphn_string.h b/src/utils/strings/gryphn_string.h index 8da48b2..7a58d47 100644 --- a/src/utils/strings/gryphn_string.h +++ b/src/utils/strings/gryphn_string.h @@ -25,7 +25,7 @@ typedef char gnChar; typedef struct gnString { gnChar* value; -#ifdef GN_UTILS_CPP +#ifdef __cplusplus gnString(const gnChar* input) { this->value = new gnChar[strlen(input) + 1]; // so like my dumbass forgot to put this earlier and some shit was broken but now it fixed // I was wondering why one specific string crashed my program, it was my fault diff --git a/src/utils/types/gryphn_color.h b/src/utils/types/gryphn_color.h index 63132fd..53c1803 100644 --- a/src/utils/types/gryphn_color.h +++ b/src/utils/types/gryphn_color.h @@ -1,3 +1,4 @@ +#pragma once typedef struct gnColor { union { struct {