start using C based classes

This commit is contained in:
Greg Wells
2025-05-20 12:02:44 -04:00
parent daef5e4858
commit 74689a86ef
10 changed files with 213 additions and 113 deletions

View File

@@ -10,6 +10,7 @@
#include <utils/types/gryphn_color_format.h>
#include <utils/types/gryphn_image_format.h>
#include <utils/gryphn_access_level.h>
#include <utils/strings/gryphn_string.h>
#include <cstdint>
typedef uint32_t gnUInt;

View File

@@ -2,17 +2,17 @@
#include <Metal/Metal.hpp>
#include "metal_output_devices.h"
GN_EXPORT gnList<gnPhysicalOutputDevice> gnGetPhysicalOutputDevicesFn(const gnInstance& instance) {
gnList<gnPhysicalOutputDevice> physicalOutputDevices = gnCreateList<gnPhysicalOutputDevice>();
GN_EXPORT gnPhysicalOutputDevice* gnGetPhysicalOutputDevicesFn(const gnInstance& instance, uint32_t* count) {
// gnList<gnPhysicalOutputDevice> physicalOutputDevices = gnCreateList<gnPhysicalOutputDevice>();
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<MTL::Device*>(devices->object(0))->name()->cString(NS::StringEncoding::UTF8StringEncoding);
physicalOutputDevice.physicalOutputDevice = new gnPlatformPhysicalOutputDevice();
physicalOutputDevice.physicalOutputDevice->device = reinterpret_cast<MTL::Device*>(devices->object(0));
gnListAdd(physicalOutputDevices, physicalOutputDevice);
devicesList[i].outputDeviceName = reinterpret_cast<MTL::Device*>(devices->object(0))->name()->cString(NS::StringEncoding::UTF8StringEncoding);
devicesList[i].physicalOutputDevice = new gnPlatformPhysicalOutputDevice();
devicesList[i].physicalOutputDevice->device = reinterpret_cast<MTL::Device*>(devices->object(0));
}
return physicalOutputDevices;
*count = devices->count();
return devicesList;
}
GN_EXPORT gnBool gnDeviceSupportsAPIFn(const gnPhysicalOutputDevice& device) {

View File

@@ -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;

View File

@@ -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

View File

@@ -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<gnPhysicalOutputDevice> gnGetPhysicalOutputDevicesFn(const gnInstance& instance) {
uint32_t deviceCount = 0;
vkEnumeratePhysicalDevices(instance.instance->vk_instance, &deviceCount, nullptr);
std::vector<VkPhysicalDevice> 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>();
}
gnPhysicalOutputDevice* outputDevices = (gnPhysicalOutputDevice*)malloc(sizeof(gnPhysicalOutputDevice) * *deviceCount);
std::vector<VkPhysicalDevice> devices(deviceCount);
vkEnumeratePhysicalDevices(instance.instance->vk_instance, &deviceCount, devices.data());
gnList<gnPhysicalOutputDevice> outputDevices = gnCreateList<gnPhysicalOutputDevice>();
for (int i = 0; i < deviceCount; i++) {
gnPhysicalOutputDevice newOutputDevice = gnPhysicalOutputDevice();
newOutputDevice.physicalOutputDevice = new gnPlatformPhysicalOutputDevice();
newOutputDevice.physicalOutputDevice->device = devices[i];
newOutputDevice.physicalOutputDevice->instance = const_cast<gnInstance*>(&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<gnInstance*>(&instance);
VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(devices[i], &deviceProperties);
newOutputDevice.outputDeviceName = gnCreateString(deviceProperties.deviceName);
gnListAdd(outputDevices, newOutputDevice);
outputDevices[i].outputDeviceName = gnCreateString(deviceProperties.deviceName);
}
return outputDevices;

View File

@@ -16,4 +16,4 @@ public:
gnString gnGetPhysicalOutputDeviceName(const gnPhysicalOutputDevice& device);
inline bool (*gnDeviceSupportsAPI)(const gnPhysicalOutputDevice& device);
inline gnList<gnPhysicalOutputDevice> (*gnGetPhysicalOutputDevices)(const gnInstance& instance);
inline gnPhysicalOutputDevice* (*gnGetPhysicalOutputDevices)(const gnInstance& instance, uint32_t* count);

View File

@@ -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;

View File

@@ -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 <typename T>
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 <typename T1, typename T2, typename T3>
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<float> gnVec3;
typedef gnVec3 gnFVec3;
typedef gnVec3 gnFloat3;
typedef gnType3<uint32_t> gnUInt3;
typedef gnType3<int32_t> 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;

View File

@@ -1,33 +1,87 @@
// typedef gnType4<uint32_t> gnUInt4;
// typedef gnType4<int32_t> 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 <typename T>
struct gnType4 {
typedef struct gnVec4 {
union {
struct { T a, b, c, d; };
struct { T 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() {};
struct { float a, b, c, d; };
struct { float x, y, z, w; };
};
template <typename T1, typename T2, typename T3, typename T4>
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<float> 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<uint32_t> gnUInt4;
typedef gnType4<int32_t> 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;

View File

@@ -1,3 +1,29 @@
#include "../math/gryphn_vec4.h"
typedef struct gnColor {
union {
struct {
int r, g, b;
float a;
};
typedef gnMultiType4<int, int, int, float> 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;