diff --git a/include/gryphn/gryphn_utils.h b/include/gryphn/gryphn_utils.h index 2e479ce..6483b0d 100644 --- a/include/gryphn/gryphn_utils.h +++ b/include/gryphn/gryphn_utils.h @@ -10,6 +10,7 @@ #include #include #include +#include #include typedef uint32_t gnUInt; diff --git a/rendering_api/metal/src/core/devices/metal_physical_device.cpp b/rendering_api/metal/src/core/devices/metal_physical_device.cpp index c014ad1..e9ef91e 100644 --- a/rendering_api/metal/src/core/devices/metal_physical_device.cpp +++ b/rendering_api/metal/src/core/devices/metal_physical_device.cpp @@ -2,17 +2,17 @@ #include #include "metal_output_devices.h" -GN_EXPORT gnList gnGetPhysicalOutputDevicesFn(const gnInstance& instance) { - gnList physicalOutputDevices = gnCreateList(); +GN_EXPORT gnPhysicalOutputDevice* gnGetPhysicalOutputDevicesFn(const gnInstance& instance, uint32_t* count) { + // gnList physicalOutputDevices = gnCreateList(); NS::Array *devices = MTL::CopyAllDevices(); + gnPhysicalOutputDevice* devicesList = (gnPhysicalOutputDevice*)malloc(sizeof(gnPhysicalOutputDevice) * devices->count()); for (int i = 0; i < devices->count(); i++) { - gnPhysicalOutputDevice physicalOutputDevice; - physicalOutputDevice.outputDeviceName = reinterpret_cast(devices->object(0))->name()->cString(NS::StringEncoding::UTF8StringEncoding); - physicalOutputDevice.physicalOutputDevice = new gnPlatformPhysicalOutputDevice(); - physicalOutputDevice.physicalOutputDevice->device = reinterpret_cast(devices->object(0)); - gnListAdd(physicalOutputDevices, physicalOutputDevice); + devicesList[i].outputDeviceName = reinterpret_cast(devices->object(0))->name()->cString(NS::StringEncoding::UTF8StringEncoding); + devicesList[i].physicalOutputDevice = new gnPlatformPhysicalOutputDevice(); + devicesList[i].physicalOutputDevice->device = reinterpret_cast(devices->object(0)); } - return physicalOutputDevices; + *count = devices->count(); + return devicesList; } GN_EXPORT gnBool gnDeviceSupportsAPIFn(const gnPhysicalOutputDevice& device) { diff --git a/rendering_api/vulkan/src/instance/vulkan_instance.cpp b/rendering_api/vulkan/src/instance/vulkan_instance.cpp index 3d2dc61..cd381ef 100644 --- a/rendering_api/vulkan/src/instance/vulkan_instance.cpp +++ b/rendering_api/vulkan/src/instance/vulkan_instance.cpp @@ -105,6 +105,11 @@ GN_EXPORT gnReturnCode gnCreateInstanceFn(gnInstance* instance) { return gnReturnError(GN_FAILED_CREATE_INSTANCE, "im to lazy to query vulkan why"); } + uint32_t deviceCount; + vkEnumeratePhysicalDevices(instance->instance->vk_instance, &deviceCount, nullptr); + if (deviceCount == 0) + return gnReturnError(GN_FAILED_CREATE_INSTANCE, "no devices support vulkan"); + if (instance->debugger->debugger == nullptr) instance->debugger->debugger = new gnPlatformDebugger(); instance->debugger->debugger->instance = &instance->instance->vk_instance; return GN_SUCCESS; diff --git a/rendering_api/vulkan/src/instance/vulkan_surfance.cpp b/rendering_api/vulkan/src/instance/vulkan_surfance.cpp index 046e47b..4d901e5 100644 --- a/rendering_api/vulkan/src/instance/vulkan_surfance.cpp +++ b/rendering_api/vulkan/src/instance/vulkan_surfance.cpp @@ -13,7 +13,7 @@ GN_EXPORT gnReturnCode gnCreateX11WindowSurfaceFn(gnInstance& instance, Display* VkResult result = vkCreateXlibSurfaceKHR(instance.instance->vk_instance, &info, nullptr, &instance.instance->window_surface); if (result != VK_SUCCESS) - return gnReturnError(GN_FAILED_CREATE_WINDOW_SURFACE, result); + return gnReturnError(GN_FAILED_TO_ATTACH_WINDOW, result); return GN_SUCCESS; } #endif @@ -30,7 +30,7 @@ GN_EXPORT gnReturnCode gnCreateWaylandWindowSurfaceFn(gnInstance& instance, wl_d VkSurfaceKHR surface; VkResult result = vkCreateWaylandSurfaceKHR(instance.instance->vk_instance, &info, nullptr, &instance.instance->window_surface); if (result != VK_SUCCESS) - return gnReturnError(GN_FAILED_CREATE_WINDOW_SURFACE, result); + return gnReturnError(GN_FAILED_TO_ATTACH_WINDOW, result); return GN_SUCCESS; } #endif @@ -47,7 +47,7 @@ GN_EXPORT gnReturnCode gnCreateWindowsWindowSurfaceFn(gnInstance& instance, HWND VkSurfaceKHR surface; VkResult result = vkCreateWin32SurfaceKHR(instance.instance->vk_instance, &info, nullptr, &instance.instance->window_surface); if (result != VK_SUCCESS) - return gnReturnError(GN_FAILED_CREATE_WINDOW_SURFACE, result); + return gnReturnError(GN_FAILED_TO_ATTACH_WINDOW, result); return GN_SUCCESS; } #endif @@ -55,10 +55,6 @@ GN_EXPORT gnReturnCode gnCreateWindowsWindowSurfaceFn(gnInstance& instance, HWND #ifdef GN_PLATFORM_MACOS GN_EXPORT gnReturnCode gnCreateMacOSWindowSurfaceFn(gnInstance& instance, NS::Window* window, NS::View* view) { - // VkMacOSSurfaceCreateInfoMVK info{}; - // info.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK; - // info.pView = (void*)view; - VkMetalSurfaceCreateInfoEXT surfaceCreateInfo = {}; surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT; surfaceCreateInfo.pNext = nullptr; @@ -68,7 +64,7 @@ GN_EXPORT gnReturnCode gnCreateMacOSWindowSurfaceFn(gnInstance& instance, NS::Wi VkSurfaceKHR surface; VkResult result = vkCreateMetalSurfaceEXT(instance.instance->vk_instance, &surfaceCreateInfo, nullptr, &instance.instance->window_surface); if (result != VK_SUCCESS) - return gnReturnError(GN_FAILED_CREATE_WINDOW_SURFACE, result); + return gnReturnError(GN_FAILED_TO_ATTACH_WINDOW, result); return GN_SUCCESS; } #endif diff --git a/rendering_api/vulkan/src/output_device/vulkan_physical_device.cpp b/rendering_api/vulkan/src/output_device/vulkan_physical_device.cpp index 8586b60..68c170a 100644 --- a/rendering_api/vulkan/src/output_device/vulkan_physical_device.cpp +++ b/rendering_api/vulkan/src/output_device/vulkan_physical_device.cpp @@ -5,37 +5,24 @@ #include "vulkan_output_devices.h" #include "presentation_queue/vulkan_swapchain.h" -// gnPhysicalOutputDevice::gnPhysicalOutputDevice() { -// physicalOutputDevice = new gnPlatformPhysicalOutputDevice(); -// } +GN_EXPORT gnPhysicalOutputDevice* gnGetPhysicalOutputDevicesFn(const gnInstance& instance, uint32_t* deviceCount) { + vkEnumeratePhysicalDevices(instance.instance->vk_instance, deviceCount, nullptr); + if (deviceCount == 0) + return nullptr; -GN_EXPORT gnList gnGetPhysicalOutputDevicesFn(const gnInstance& instance) { - uint32_t deviceCount = 0; - vkEnumeratePhysicalDevices(instance.instance->vk_instance, &deviceCount, nullptr); + std::vector devices(*deviceCount); + vkEnumeratePhysicalDevices(instance.instance->vk_instance, deviceCount, devices.data()); - if (deviceCount == 0) { - // throw std::runtime_error("failed to find any physical devices"); - // TODO: why am I error checking for myself I can read the size of a list can't I - return gnCreateList(); - } + gnPhysicalOutputDevice* outputDevices = (gnPhysicalOutputDevice*)malloc(sizeof(gnPhysicalOutputDevice) * *deviceCount); - std::vector devices(deviceCount); - vkEnumeratePhysicalDevices(instance.instance->vk_instance, &deviceCount, devices.data()); - - - gnList outputDevices = gnCreateList(); - - for (int i = 0; i < deviceCount; i++) { - gnPhysicalOutputDevice newOutputDevice = gnPhysicalOutputDevice(); - newOutputDevice.physicalOutputDevice = new gnPlatformPhysicalOutputDevice(); - newOutputDevice.physicalOutputDevice->device = devices[i]; - newOutputDevice.physicalOutputDevice->instance = const_cast(&instance); + for (int i = 0; i < *deviceCount; i++) { + outputDevices[i].physicalOutputDevice = new gnPlatformPhysicalOutputDevice(); + outputDevices[i].physicalOutputDevice->device = devices[i]; + outputDevices[i].physicalOutputDevice->instance = const_cast(&instance); VkPhysicalDeviceProperties deviceProperties; vkGetPhysicalDeviceProperties(devices[i], &deviceProperties); - newOutputDevice.outputDeviceName = gnCreateString(deviceProperties.deviceName); - - gnListAdd(outputDevices, newOutputDevice); + outputDevices[i].outputDeviceName = gnCreateString(deviceProperties.deviceName); } return outputDevices; diff --git a/src/core/output_device/gryphn_physical_output_device.h b/src/core/output_device/gryphn_physical_output_device.h index 4097478..78b7ae8 100644 --- a/src/core/output_device/gryphn_physical_output_device.h +++ b/src/core/output_device/gryphn_physical_output_device.h @@ -16,4 +16,4 @@ public: gnString gnGetPhysicalOutputDeviceName(const gnPhysicalOutputDevice& device); inline bool (*gnDeviceSupportsAPI)(const gnPhysicalOutputDevice& device); -inline gnList (*gnGetPhysicalOutputDevices)(const gnInstance& instance); +inline gnPhysicalOutputDevice* (*gnGetPhysicalOutputDevices)(const gnInstance& instance, uint32_t* count); diff --git a/src/utils/gryphn_error_code.h b/src/utils/gryphn_error_code.h index 8e70d32..a206712 100644 --- a/src/utils/gryphn_error_code.h +++ b/src/utils/gryphn_error_code.h @@ -1,12 +1,10 @@ -#include "utils/strings/gryphn_string.h" +#pragma once typedef enum gnReturnCode { - GN_SUCCESS, GN_FAILED, GN_FATAL, + GN_SUCCESS, GN_WARNING, GN_FAILED, GN_ERROR = GN_FAILED } gnReturnCode; -typedef gnReturnCode gnErrorCode; - typedef enum gnReturnMessage { GN_UNKNOWN_ERROR, GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, @@ -24,18 +22,8 @@ typedef enum gnReturnMessage { GN_FAILED_CREATE_RENDERPASS, GN_FAILED_CREATE_INSTANCE, GN_FAILED_TO_ATTACH_WINDOW, - GN_FAILED_TO_CREATE_IMAGE, - GN_FAILED_CREATE_WINDOW_SURFACE + GN_FAILED_TO_CREATE_IMAGE } gnReturnMessage; -inline gnString lastReturnAPIMessage = gnCreateEmptyString(); -inline gnReturnMessage lastReturnMessage = GN_UNKNOWN_ERROR; - -static const gnString gnGetErrorString() { return lastReturnAPIMessage; } -static const gnReturnMessage gnGetErrorMessage() { return lastReturnMessage; } - -static gnReturnCode gnReturnError(gnReturnMessage message, gnString errorMessage) { - lastReturnAPIMessage = errorMessage; - lastReturnMessage = message; - return GN_ERROR; -} +typedef gnReturnCode gnErrorCode; +typedef gnReturnMessage gnErrorMessage; diff --git a/src/utils/math/gryphn_vec3.h b/src/utils/math/gryphn_vec3.h index f0b096e..f2b7d4d 100644 --- a/src/utils/math/gryphn_vec3.h +++ b/src/utils/math/gryphn_vec3.h @@ -1,37 +1,80 @@ #pragma once - -// very shitty vec3 class -// i really want to write some math for this shit but im a lazy little cunt and im not doing all that shit - #include "stdint.h" -template -struct gnType3 { +typedef struct gnVec3 { union { - struct { T a, b, c; }; - struct { T x, y, z; }; + struct { float a, b, c; }; + struct { float x, y, z; }; }; -public: - gnType3(T a, T b, T c) { this->a = a; this->b = b; this->c = c; } - gnType3() {}; - bool operator==(const gnType3& other) const { +#ifdef GN_UTILS_CPP + gnVec3(float x, float y, float z) { this->x = x; this->y = y; this->z = z; } + gnVec3(float s) { this->x = s; this->y = s; this->z = s; } + gnVec3() {}; + + gnVec3 operator-(const gnVec3& other) { + gnVec3 returnGnVec3; + returnGnVec3.x = this->x - other.x; + returnGnVec3.y = this->y - other.y; + returnGnVec3.z = this->z - other.z; + return returnGnVec3; + } + + bool operator==(const gnVec3& other) const { return this->a == other.a && this->b == other.b && this->c == other.c; } -}; +#endif +} gnVec3; -template -struct gnMultiType3 { - union { - struct { T1 a; T2 b; T3 c; }; - struct { T1 x; T2 y; T3 z; }; - }; -public: - gnMultiType3(T1 a, T2 b, T3 c) { this->a = a; this->b = b; this->c = c; } - gnMultiType3() {}; -}; - -typedef gnType3 gnVec3; +typedef gnVec3 gnFVec3; typedef gnVec3 gnFloat3; -typedef gnType3 gnUInt3; -typedef gnType3 gnInt3; + +typedef struct gnUInt3 { + union { + struct { uint32_t a, b, c; }; + struct { uint32_t x, y, z; }; + }; + +#ifdef GN_UTILS_CPP + gnUInt3(uint32_t x, uint32_t y) { this->x = x; this->y = y; this->z = z; } + gnUInt3(uint32_t s) { this->x = s; this->y = s; this->z = s; } + gnUInt3() {}; + + gnUInt3 operator-(const gnUInt3& other) { + gnUInt3 returnGnVec3; + returnGnVec3.x = this->x - other.x; + returnGnVec3.y = this->y - other.y; + returnGnVec3.z = this->z - other.z; + return returnGnVec3; + } + + bool operator==(const gnUInt3& other) const { + return this->a == other.a && this->b == other.b && this->c == other.c; + } +#endif +} gnUInt3; + +typedef struct gnInt3 { + union { + struct { int a, b, c; }; + struct { int x, y, z; }; + }; + +#ifdef GN_UTILS_CPP + gnInt3(int x, int y, int z) { this->x = x; this->y = y; this->z = z; } + gnInt3(int s) { this->x = s; this->y = s; this->z = s; } + gnInt3() {}; + + gnInt3 operator-(const gnInt3& other) { + gnInt3 returnGnVec3; + returnGnVec3.x = this->x - other.x; + returnGnVec3.y = this->y - other.y; + returnGnVec3.z = this->z - other.z; + return returnGnVec3; + } + + bool operator==(const gnInt3& other) const { + return this->a == other.a && this->b == other.b && this->c == other.c; + } +#endif +} gnInt3; diff --git a/src/utils/math/gryphn_vec4.h b/src/utils/math/gryphn_vec4.h index 3ac1e3b..80edac9 100644 --- a/src/utils/math/gryphn_vec4.h +++ b/src/utils/math/gryphn_vec4.h @@ -1,33 +1,87 @@ +// typedef gnType4 gnUInt4; +// typedef gnType4 gnInt4; + + #pragma once - -// very shitty vec4 class -// I also use this same thing to make my color class dont worry abt it - #include "stdint.h" -template -struct gnType4 { +typedef struct gnVec4 { union { - struct { T a, b, c, d; }; - struct { T x, y, z, w; }; + struct { float a, b, c, d; }; + struct { float x, y, z, w; }; }; -public: - gnType4(T a, T b, T c, T d) { this->a = a; this->b = b; this->c = c; this->d = d; } - gnType4() {}; -}; -template -struct gnMultiType4 { - union { - struct { T1 r; T2 g; T3 b; T4 a; }; - struct { T1 x; T2 y; T3 z; T4 w; }; - }; -public: - gnMultiType4(T1 r, T2 g, T3 b, T4 a) { this->r = r; this->g = g; this->b = b; this->a = a; } - gnMultiType4() {}; -}; +#ifdef GN_UTILS_CPP + gnVec4(float x, float y, float z, float w) { this->x = x; this->y = y; this->z = z; this->w = w; } + gnVec4(float s) { this->x = s; this->y = s; this->z = s; this->w = w; } + gnVec4() {}; -typedef gnType4 gnVec4; + gnVec4 operator-(const gnVec4& other) { + gnVec4 returnGnVec4; + returnGnVec4.x = this->x - other.x; + returnGnVec4.y = this->y - other.y; + returnGnVec4.z = this->z - other.z; + returnGnVec4.w = this->w - other.w; + return returnGnVec4; + } + + bool operator==(const gnVec4& other) const { + return this->a == other.a && this->b == other.b && this->c == other.c && this->d == other.d; + } +#endif +} gnVec4; + +typedef gnVec4 gnFVec4; typedef gnVec4 gnFloat4; -typedef gnType4 gnUInt4; -typedef gnType4 gnInt4; + +typedef struct gnUInt4 { + union { + struct { uint32_t a, b, c, d; }; + struct { uint32_t x, y, z, w; }; + }; + +#ifdef GN_UTILS_CPP + gnUInt4(uint32_t x, uint32_t y, uint32_t z, uint32_t w) { this->x = x; this->y = y; this->z = z; this->w = w; } + gnUInt4(uint32_t s) { this->x = s; this->y = s; this->z = s; this->w = s; } + gnUInt4() {}; + + gnUInt4 operator-(const gnUInt4& other) { + gnUInt4 returnGnVec4; + returnGnVec4.x = this->x - other.x; + returnGnVec4.y = this->y - other.y; + returnGnVec4.z = this->z - other.z; + returnGnVec4.w = this->w - other.w; + return returnGnVec4; + } + + bool operator==(const gnUInt4& other) const { + return this->a == other.a && this->b == other.b && this->c == other.c && this->d == other.d; + } +#endif +} gnUInt4; + +typedef struct gnInt4 { + union { + struct { int a, b, c, d; }; + struct { int x, y, z, w; }; + }; + +#ifdef GN_UTILS_CPP + gnInt4(int x, int y, int z, int w) { this->x = x; this->y = y; this->z = z; this->w = w; } + gnInt4(int s) { this->x = s; this->y = s; this->z = s; this->w = s; } + gnInt4() {}; + + gnInt4 operator-(const gnInt4& other) { + gnInt4 returnGnVec4; + returnGnVec4.x = this->x - other.x; + returnGnVec4.y = this->y - other.y; + returnGnVec4.z = this->z - other.z; + returnGnVec4.w = this->w - other.w; + return returnGnVec4; + } + + bool operator==(const gnInt4& other) const { + return this->a == other.a && this->b == other.b && this->c == other.c; + } +#endif +} gnInt4; diff --git a/src/utils/types/gryphn_color.h b/src/utils/types/gryphn_color.h index ca757b0..63132fd 100644 --- a/src/utils/types/gryphn_color.h +++ b/src/utils/types/gryphn_color.h @@ -1,3 +1,29 @@ -#include "../math/gryphn_vec4.h" +typedef struct gnColor { + union { + struct { + int r, g, b; + float a; + }; -typedef gnMultiType4 gnColor; + struct { + int red, green, blue; + float alpha; + }; + }; + +#ifdef GN_UTILS_CPP + gnColor(int red, int green, int blue, float alpha = 1.0) { + this->red = red; + this->green = green; + this->blue = blue; + this->alpha = alpha; + } + + gnColor(int color = 0, float alpha = 1.0) { + this->red = color; + this->green = color; + this->blue = color; + this->alpha = alpha; + } +#endif +} gnColor;