wrote c compatible return code structure

This commit is contained in:
Greg Wells
2025-05-06 18:29:46 -04:00
parent a3fd0e1579
commit 07624bc93d
17 changed files with 94 additions and 112 deletions

View File

@@ -20,4 +20,3 @@ typedef float gnFloat;
typedef size_t gnSize; typedef size_t gnSize;
#define GN_EXPORT extern "C" #define GN_EXPORT extern "C"
#define GN_RETURN_ERROR(errorString) return { GN_FAILED, errorString }

View File

@@ -62,7 +62,7 @@ GN_EXPORT gnReturnCode gnRegisterOutputDeviceFn(gnOutputDevice* outputDevice, co
MTL::CompileOptions* options = nullptr; MTL::CompileOptions* options = nullptr;
MTL::Library* library = physicalDevice.physicalOutputDevice->device->newLibrary(NS::String::string(shaderSrc, NS::UTF8StringEncoding), options, &error); MTL::Library* library = physicalDevice.physicalOutputDevice->device->newLibrary(NS::String::string(shaderSrc, NS::UTF8StringEncoding), options, &error);
if (!library) { if (!library) {
GN_RETURN_ERROR(error->localizedDescription()->utf8String()); return gnReturnError(GN_FAILED_CREATE_DEVICE, error->localizedDescription()->utf8String());
} }
MTL::Function* vs = library->newFunction(NS::String::string("vs_main", NS::UTF8StringEncoding)); MTL::Function* vs = library->newFunction(NS::String::string("vs_main", NS::UTF8StringEncoding));
MTL::Function* fs = library->newFunction(NS::String::string("fs_main", NS::UTF8StringEncoding)); MTL::Function* fs = library->newFunction(NS::String::string("fs_main", NS::UTF8StringEncoding));
@@ -74,61 +74,7 @@ GN_EXPORT gnReturnCode gnRegisterOutputDeviceFn(gnOutputDevice* outputDevice, co
instance.instance->framebufferRenderer = outputDevice->outputDevice->device->newRenderPipelineState(pipelineDesc, &error); instance.instance->framebufferRenderer = outputDevice->outputDevice->device->newRenderPipelineState(pipelineDesc, &error);
if (!instance.instance->framebufferRenderer) { if (!instance.instance->framebufferRenderer) {
GN_RETURN_ERROR(error->localizedDescription()->utf8String()); return gnReturnError(GN_FAILED_CREATE_DEVICE, error->localizedDescription()->utf8String());
}
}
{
const char* shaderSrc = R"metal(
#include <metal_stdlib>
using namespace metal;
struct VertexIn {
float3 position;
float2 uv;
};
struct VertexOut {
float4 position [[position]];
};
vertex VertexOut vs_main(uint vertexID [[vertex_id]]) {
float2 positions[6] = {
{-0.5, -0.5},
{ 0.5, -0.5},
{-0.5, 0.5},
{ 0.5, -0.5},
{-0.5, 0.5},
{ 0.5, 0.5}
};
VertexOut out;
out.position = float4(positions[vertexID], 0.0, 1.0);
return out;
}
fragment float4 fs_main(VertexOut in [[stage_in]]) {
return float4(1.0, 1.0, 1.0, 1.0);
}
)metal";
NS::Error* error = nullptr;
MTL::CompileOptions* options = nullptr;
MTL::Library* library = physicalDevice.physicalOutputDevice->device->newLibrary(NS::String::string(shaderSrc, NS::UTF8StringEncoding), options, &error);
if (!library) {
GN_RETURN_ERROR(error->localizedDescription()->utf8String());
}
MTL::Function* vs = library->newFunction(NS::String::string("vs_main", NS::UTF8StringEncoding));
MTL::Function* fs = library->newFunction(NS::String::string("fs_main", NS::UTF8StringEncoding));
MTL::RenderPipelineDescriptor* pipelineDesc = MTL::RenderPipelineDescriptor::alloc()->init();
pipelineDesc->setVertexFunction(vs);
pipelineDesc->setFragmentFunction(fs);
pipelineDesc->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatBGRA8Unorm);
instance.instance->testSquareRenderer = outputDevice->outputDevice->device->newRenderPipelineState(pipelineDesc, &error);
if (!instance.instance->framebufferRenderer) {
GN_RETURN_ERROR(error->localizedDescription()->utf8String());
} }
} }

View File

@@ -42,7 +42,7 @@ GN_EXPORT gnReturnCode gnCreateFramebufferFn(gnFramebuffer* framebuffer, const g
stencilAttachment->setStoreAction(MTL::StoreActionStore); stencilAttachment->setStoreAction(MTL::StoreActionStore);
stencilAttachment->release(); stencilAttachment->release();
} else { } else {
GN_RETURN_ERROR("fuck you (line 46 in metal_framebuffer.cpp)"); return gnReturnError(GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, "GN_DEPTH_ATTACHMENT and GN_STENCIL_ATTACHMENT are unsupported on metal for now");
} }
} }
return GN_SUCCESS; return GN_SUCCESS;

View File

@@ -117,12 +117,12 @@ GN_EXPORT void gnGraphicsPipelineAddPushConstantFn(gnGraphicsPipeline& graphicsP
} }
GN_EXPORT gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline* graphicsPipeline, gnOutputDevice& outputDevice) { GN_EXPORT gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline* graphicsPipeline, gnOutputDevice& outputDevice) {
if (graphicsPipeline->graphicsPipeline == nullptr) GN_RETURN_ERROR("Need to call one gnGraphicsPipeline function to create a graphics pipeline"); if (graphicsPipeline->graphicsPipeline == nullptr) graphicsPipeline->graphicsPipeline = new gnPlatformGraphicsPipeline();
NS::Error* error = nullptr; NS::Error* error = nullptr;
graphicsPipeline->graphicsPipeline->renderPipelineDescriptor->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatBGRA8Unorm); graphicsPipeline->graphicsPipeline->renderPipelineDescriptor->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatBGRA8Unorm);
graphicsPipeline->graphicsPipeline->renderPipelineState = outputDevice.outputDevice->device->newRenderPipelineState(graphicsPipeline->graphicsPipeline->renderPipelineDescriptor, &error); graphicsPipeline->graphicsPipeline->renderPipelineState = outputDevice.outputDevice->device->newRenderPipelineState(graphicsPipeline->graphicsPipeline->renderPipelineDescriptor, &error);
if (!graphicsPipeline->graphicsPipeline->renderPipelineState) if (!graphicsPipeline->graphicsPipeline->renderPipelineState)
GN_RETURN_ERROR(error->localizedDescription()->utf8String()); return gnReturnError(GN_FAILED_CREATE_GRAPHICS_PIPELINE, error->localizedDescription()->utf8String());
graphicsPipeline->graphicsPipeline->depthStencilState = outputDevice.outputDevice->device->newDepthStencilState(graphicsPipeline->graphicsPipeline->depthStateDescriptor); graphicsPipeline->graphicsPipeline->depthStencilState = outputDevice.outputDevice->device->newDepthStencilState(graphicsPipeline->graphicsPipeline->depthStateDescriptor);
graphicsPipeline->graphicsPipeline->outputDevice = &outputDevice; graphicsPipeline->graphicsPipeline->outputDevice = &outputDevice;

View File

@@ -24,7 +24,7 @@ GN_EXPORT gnReturnCode gnCreateRenderPassFn(gnRenderPass* renderPass, const gnOu
else if (renderPass->attachments[i].colorMode == GN_DEPTH8_STENCIL24) {} else if (renderPass->attachments[i].colorMode == GN_DEPTH8_STENCIL24) {}
else { else {
std::string return_code = "GN_RENDERPASS_ATTATCHMENT_(" + std::to_string(i) + ")" + "_UNSUPPORTED_COLOR_MODE"; std::string return_code = "GN_RENDERPASS_ATTATCHMENT_(" + std::to_string(i) + ")" + "_UNSUPPORTED_COLOR_MODE";
GN_RETURN_ERROR(return_code.c_str()); return gnReturnError(GN_UNKNOWN_COLOR_FORMAT, return_code.c_str());
} }
} }

View File

@@ -1,7 +1,7 @@
#include "metal_shader_module.h" #include "metal_shader_module.h"
#include "metal_shader.h"
#include "spirv_msl.hpp" #include "spirv_msl.hpp"
#include "core/devices/metal_output_devices.h" #include "core/devices/metal_output_devices.h"
#include "core/shaders/gryphn_shader.h"
static uint32_t* chars_to_uint32s(const char* chars, size_t num_chars) { static uint32_t* chars_to_uint32s(const char* chars, size_t num_chars) {
if (chars == NULL || num_chars == 0) { if (chars == NULL || num_chars == 0) {
@@ -93,7 +93,7 @@ GN_EXPORT gnReturnCode gnBuildShaderModuleFn(gnShaderModule* shaderModule, const
shaderModule->shaderModule->uniformBufferOffset = 0; shaderModule->shaderModule->uniformBufferOffset = 0;
shaderModule->shaderModule->pushConstantOffset = largestBinding + 1; shaderModule->shaderModule->pushConstantOffset = largestBinding + 1;
} else { } else {
GN_RETURN_ERROR("GN_UNKNOWN_SHADER_MODULE_TYPE_(I prolly lazy)"); return gnReturnError(GN_UNKNOWN_SHADER_MODULE, "unknown shader module type (vertex and fragment are the only supported ones for now)");
} }
// std::cout << shaderSource << "\n"; // std::cout << shaderSource << "\n";
@@ -103,9 +103,9 @@ GN_EXPORT gnReturnCode gnBuildShaderModuleFn(gnShaderModule* shaderModule, const
NS::String* sourceCode = NS::String::string(shaderSource.c_str(), NS::StringEncoding::UTF8StringEncoding); NS::String* sourceCode = NS::String::string(shaderSource.c_str(), NS::StringEncoding::UTF8StringEncoding);
MTL::Library* shaderLib = outputDeviec.outputDevice->device->newLibrary(sourceCode, mtloptions, &error); MTL::Library* shaderLib = outputDeviec.outputDevice->device->newLibrary(sourceCode, mtloptions, &error);
if (!shaderLib) if (!shaderLib)
GN_RETURN_ERROR(error->localizedDescription()->utf8String()); return gnReturnError(GN_SHADER_FAILED_TO_COMPILE, error->localizedDescription()->utf8String());
if (shaderLib->functionNames()->count() > 1) if (shaderLib->functionNames()->count() > 1)
GN_RETURN_ERROR("More than one shader function in shader"); return gnReturnError(GN_SHADER_FAILED_TO_COMPILE, "More than one shader function in shader");
shaderModule->shaderModule->shaderFunction = shaderLib->newFunction(reinterpret_cast<NS::String*>(shaderLib->functionNames()->object(0))); shaderModule->shaderModule->shaderFunction = shaderLib->newFunction(reinterpret_cast<NS::String*>(shaderLib->functionNames()->object(0)));
return GN_SUCCESS; return GN_SUCCESS;

View File

@@ -49,14 +49,14 @@ GN_EXPORT gnErrorCode gnCreateTextureFn(gnTexture* texture, const gnOutputDevice
if (texture->textureColorFormat == GN_RED) if (texture->textureColorFormat == GN_RED)
textureDescriptor->setPixelFormat(MTL::PixelFormatR8Unorm); textureDescriptor->setPixelFormat(MTL::PixelFormatR8Unorm);
else if (texture->textureColorFormat == GN_RGB8) else if (texture->textureColorFormat == GN_RGB8)
return gnReturnError("GN_RGB8_UNSUPPORTED"); return gnReturnError(GN_UNSUPPORTED_COLOR_FORMAT, "GN_RGB8_UNSUPPORTED");
else if (texture->textureColorFormat == GN_RGBA8) else if (texture->textureColorFormat == GN_RGBA8)
textureDescriptor->setPixelFormat(MTL::PixelFormatRGBA8Unorm); textureDescriptor->setPixelFormat(MTL::PixelFormatRGBA8Unorm);
else if (texture->textureColorFormat == GN_BGRA8) else if (texture->textureColorFormat == GN_BGRA8)
textureDescriptor->setPixelFormat(MTL::PixelFormatBGRA8Unorm); textureDescriptor->setPixelFormat(MTL::PixelFormatBGRA8Unorm);
else if (texture->textureColorFormat == GN_DEPTH_STENCIL) else if (texture->textureColorFormat == GN_DEPTH_STENCIL)
textureDescriptor->setPixelFormat(MTL::PixelFormatDepth32Float_Stencil8); textureDescriptor->setPixelFormat(MTL::PixelFormatDepth32Float_Stencil8);
else return gnReturnError("GN_UNSUPPORTED_PIXEL_FORMAT"); else return gnReturnError(GN_UNKNOWN_COLOR_FORMAT, "unknown pixel format");
textureDescriptor->setWidth(texture->textureExtent.x); textureDescriptor->setWidth(texture->textureExtent.x);
textureDescriptor->setHeight(texture->textureExtent.y); textureDescriptor->setHeight(texture->textureExtent.y);

View File

@@ -30,7 +30,7 @@ GN_EXPORT gnReturnCode gnCreateFramebufferFn(gnFramebuffer* framebuffer, const g
if (vkCreateFramebuffer(renderpass.renderpass->outputDevice->outputDevice->device, &framebufferInfo, nullptr, &framebuffer->framebuffer->framebuffer) != VK_SUCCESS) { if (vkCreateFramebuffer(renderpass.renderpass->outputDevice->outputDevice->device, &framebufferInfo, nullptr, &framebuffer->framebuffer->framebuffer) != VK_SUCCESS) {
GN_RETURN_ERROR("Failed to create framebuffer"); return gnReturnError(GN_FAILED_TO_CREATE_FRAMEBUFFER, "im to lazy to query vulkan why");
} }
return GN_SUCCESS; return GN_SUCCESS;

View File

@@ -60,7 +60,7 @@ GN_EXPORT gnReturnCode gnCreateRenderPassFn(gnRenderPass* renderPass, const gnOu
colorAttachmentRef.attachment = i; colorAttachmentRef.attachment = i;
if (renderPass->presentationQueue == nullptr) { if (renderPass->presentationQueue == nullptr) {
GN_RETURN_ERROR("the presentation queue has not been set"); return gnReturnError(GN_FAILED_CREATE_RENDERPASS, "the presentation queue has not been set");
} }
if (renderPass->attachments[i].colorMode == GN_RGBA8) { if (renderPass->attachments[i].colorMode == GN_RGBA8) {

View File

@@ -70,7 +70,7 @@ void gnInstanceSetAppInfoFn(gnInstance& instance, gnAppInfo& info) {
GN_EXPORT gnReturnCode gnCreateInstanceFn(gnInstance* instance) { GN_EXPORT gnReturnCode gnCreateInstanceFn(gnInstance* instance) {
if (instance->debugger != nullptr && !checkValidationLayerSupport(instance->debugger->debug_layers)) { if (instance->debugger != nullptr && !checkValidationLayerSupport(instance->debugger->debug_layers)) {
GN_RETURN_ERROR("validation layers requested, but not available!"); return gnReturnError(GN_FAILED_CREATE_INSTANCE, "validation layers requested, but not available!");
} }
gnInstanceSetAppInfoFn(*instance, instance->AppInfo); gnInstanceSetAppInfoFn(*instance, instance->AppInfo);
@@ -103,7 +103,7 @@ GN_EXPORT gnReturnCode gnCreateInstanceFn(gnInstance* instance) {
} }
if (vkCreateInstance(&createInfo, nullptr, &instance->instance->vk_instance) != VK_SUCCESS) { if (vkCreateInstance(&createInfo, nullptr, &instance->instance->vk_instance) != VK_SUCCESS) {
return GN_FAILED; return gnReturnError(GN_FAILED_CREATE_INSTANCE, "im to lazy to query vulkan why");
} }
if (instance->debugger->debugger == nullptr) instance->debugger->debugger = new gnPlatformDebugger(); if (instance->debugger->debugger == nullptr) instance->debugger->debugger = new gnPlatformDebugger();
@@ -121,11 +121,11 @@ GN_EXPORT gnReturnCode gnInstanceSetWindowFn(gnInstance& instance, GLFWwindow* w
instance.instance->window = window; instance.instance->window = window;
if (glfwVulkanSupported() != GLFW_TRUE) { if (glfwVulkanSupported() != GLFW_TRUE) {
GN_RETURN_ERROR("vulkan is not actually supported\n"); return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "vulkan is not actually supported\n");
} }
VkResult result = glfwCreateWindowSurface(instance.instance->vk_instance, window, nullptr, &instance.instance->window_surface);\ VkResult result = glfwCreateWindowSurface(instance.instance->vk_instance, window, nullptr, &instance.instance->window_surface);\
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
GN_RETURN_ERROR(std::to_string(result).c_str()); return gnReturnError(GN_FAILED_TO_ATTACH_WINDOW, std::to_string(result).c_str());
return GN_SUCCESS; return GN_SUCCESS;
} }

View File

@@ -56,7 +56,7 @@ GN_EXPORT gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presenta
createInfo.oldSwapchain = VK_NULL_HANDLE; createInfo.oldSwapchain = VK_NULL_HANDLE;
if (vkCreateSwapchainKHR(device.outputDevice->device, &createInfo, nullptr, &presentationQueue->presentationQueue->swapChain) != VK_SUCCESS) { if (vkCreateSwapchainKHR(device.outputDevice->device, &createInfo, nullptr, &presentationQueue->presentationQueue->swapChain) != VK_SUCCESS) {
GN_RETURN_ERROR("failed to create swap chain!"); gnReturnError(GN_FAILED_CREATE_PRESENTATION_QUEUE, "too lazy to query vulkan why");
} }
std::vector<VkImage> swapChainImages; std::vector<VkImage> swapChainImages;

View File

@@ -179,11 +179,11 @@ GN_EXPORT gnReturnCode gnCreateTextureFn(gnTexture* texture, const gnOutputDevic
if (vulkanCreateImage(outputDevice, texture->textureExtent.x, texture->textureExtent.y, if (vulkanCreateImage(outputDevice, texture->textureExtent.x, texture->textureExtent.y,
depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
texture->texture->textureImage, texture->texture->textureImageMemory) != GN_SUCCESS) { texture->texture->textureImage, texture->texture->textureImageMemory) != GN_SUCCESS) {
GN_RETURN_ERROR("Failed to create depth image"); return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, "Failed to create depth image");
} }
gnReturnCode errorCode = createImageView(outputDevice, texture->texture->textureImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT, &texture->texture->textureImageView); gnReturnCode errorCode = createImageView(outputDevice, texture->texture->textureImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT, &texture->texture->textureImageView);
if (transitionImageLayout(outputDevice, texture->texture->textureImage, depthFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) != GN_FAILED) GN_RETURN_ERROR("Failed to transition image layout"); if (transitionImageLayout(outputDevice, texture->texture->textureImage, depthFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) != GN_SUCCESS) return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, "Failed to transition image layout");
} }
} else { } else {
if (vulkanCreateCubeMap(outputDevice, texture->textureExtent.x, texture->textureExtent.y, texture->texture->textureImage, texture->texture->textureImageMemory) != GN_SUCCESS) if (vulkanCreateCubeMap(outputDevice, texture->textureExtent.x, texture->textureExtent.y, texture->texture->textureImage, texture->texture->textureImageMemory) != GN_SUCCESS)
@@ -217,7 +217,7 @@ GN_EXPORT gnReturnCode gnCreateTextureFn(gnTexture* texture, const gnOutputDevic
samplerInfo.maxLod = 0.0f; samplerInfo.maxLod = 0.0f;
if (vkCreateSampler(outputDevice.outputDevice->device, &samplerInfo, nullptr, &texture->texture->textureSampler) != VK_SUCCESS) if (vkCreateSampler(outputDevice.outputDevice->device, &samplerInfo, nullptr, &texture->texture->textureSampler) != VK_SUCCESS)
GN_RETURN_ERROR("Failed to create texture sampler"); return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, "Failed to create texture sampler");
} }
return GN_SUCCESS; return GN_SUCCESS;

View File

@@ -182,7 +182,7 @@ gnReturnCode vulkanCreateImage(const gnOutputDevice& outputDevice,
VkResult result = vkCreateImage(outputDevice.outputDevice->device, &imageInfo, nullptr, &image); VkResult result = vkCreateImage(outputDevice.outputDevice->device, &imageInfo, nullptr, &image);
if (result != VK_SUCCESS) { if (result != VK_SUCCESS) {
GN_RETURN_ERROR(std::to_string(result).c_str()); return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, std::to_string(result).c_str());
} }
VkMemoryRequirements memRequirements; VkMemoryRequirements memRequirements;
@@ -197,12 +197,12 @@ gnReturnCode vulkanCreateImage(const gnOutputDevice& outputDevice,
outputDevice.physicalOutputDevice->physicalOutputDevice->device, outputDevice.physicalOutputDevice->physicalOutputDevice->device,
memRequirements.memoryTypeBits, properties, memRequirements.memoryTypeBits, properties,
&memoryTypeIndex) != GN_SUCCESS) { &memoryTypeIndex) != GN_SUCCESS) {
GN_RETURN_ERROR("Failed to find memory type"); return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, "Failed to find memory type");
} }
allocInfo.memoryTypeIndex = memoryTypeIndex; allocInfo.memoryTypeIndex = memoryTypeIndex;
if (vkAllocateMemory(outputDevice.outputDevice->device, &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) { if (vkAllocateMemory(outputDevice.outputDevice->device, &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) {
GN_RETURN_ERROR("Failed to allocate memory"); return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, "Failed to allocate memory");
} }
vkBindImageMemory(outputDevice.outputDevice->device, image, imageMemory, 0); vkBindImageMemory(outputDevice.outputDevice->device, image, imageMemory, 0);

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include <gryphn/gryphn_utils.h> #include <gryphn/gryphn_utils.h>
#include "vector"
struct gnPlatformCommandBuffer; struct gnPlatformCommandBuffer;
struct gnOutputDevice; struct gnOutputDevice;

View File

@@ -15,41 +15,41 @@ static void* gnRenderingAPILIB;
#define gnLoadDLLFunction(dll, func, func_name) \ #define gnLoadDLLFunction(dll, func, func_name) \
gnPlatformLoadDLLFunction(dll, func, func_name); \ gnPlatformLoadDLLFunction(dll, func, func_name); \
if (func == nullptr) return gnReturnError(gnString("GN_FUNC_(") + gnString(#func) + ")_NOT_LOADED") if (func == nullptr) return gnReturnError(GN_FUNCTION_NOT_FOUND, gnString("GN_FUNC_(") + gnString(#func) + ")_NOT_LOADED")
gnReturnCode gnInit(gnRenderingAPI RenderingAPI) { gnReturnCode gnInit(gnRenderingAPI RenderingAPI) {
gnString libName = ""; gnString libName = "";
switch (RenderingAPI) { switch (RenderingAPI) {
case GN_RENDERINGAPI_NONE: { case GN_RENDERINGAPI_NONE: {
return { GN_FAILED, "GN_ERROR_RENDERINGAPI_NONE_UNSUPPORTED" }; return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api_none unsupported");
} }
case GN_RENDERINGAPI_SOFTWARE: { case GN_RENDERINGAPI_SOFTWARE: {
return { GN_FAILED, "GN_ERROR_SOFRWARE_UNSUPPORTED" }; return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api_software unsupported");
} }
case GN_RENDERINGAPI_OPENGL: { case GN_RENDERINGAPI_OPENGL: {
return { GN_FAILED, "GN_ERROR_OPENGL_UNSUPPORTED" }; return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api_opengl unsupported");
} }
case GN_RENDERINGAPI_VULKAN: { case GN_RENDERINGAPI_VULKAN: {
if (!RenderingAPISupported(GN_RENDERINGAPI_VULKAN)) return { GN_FAILED, "GN_ERROR_VUKAN_UNSUPPORTED" }; if (!RenderingAPISupported(GN_RENDERINGAPI_VULKAN)) return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api vulkan unsupported");
libName = "GryphnVulkanImpl"; libName = "GryphnVulkanImpl";
break; break;
} }
case GN_RENDERINGAPI_DIRECTX11: { case GN_RENDERINGAPI_DIRECTX11: {
return { GN_FAILED, "GN_ERROR_DIRECTX11_UNSUPPORTED" }; return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api directx11 unsupported");
} }
case GN_RENDERINGAPI_DIRECTX12: { case GN_RENDERINGAPI_DIRECTX12: {
return { GN_FAILED, "GN_ERROR_DIRECTX12_UNSUPPORTED" }; return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api directx12 unsupported");
} }
case GN_RENDERINGAPI_METAL: { case GN_RENDERINGAPI_METAL: {
if (!RenderingAPISupported(GN_RENDERINGAPI_METAL)) return { GN_FAILED, "GN_ERROR_METAL_UNSUPPORTED" }; if (!RenderingAPISupported(GN_RENDERINGAPI_METAL)) return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api metal unsupported");
libName = "GryphnMetalImpl"; libName = "GryphnMetalImpl";
break; break;
} }
} }
gnRenderingAPILIB = gnPlatformLoadDLL(gnString("gryphn/rendering_apis/") + libName); gnRenderingAPILIB = gnPlatformLoadDLL(gnString("gryphn/rendering_apis/") + libName);
if (!gnRenderingAPILIB) { return gnReturnError("GN_ERROR_UNABLE_TO_LOAD_DLL"); } if (!gnRenderingAPILIB) { return gnReturnError(GN_UNABLE_TO_LOAD_DLL, "GN_ERROR_UNABLE_TO_LOAD_DLL"); }
gnLoadDLLFunction(gnRenderingAPILIB, gnCreateInstance, "gnCreateInstanceFn"); gnLoadDLLFunction(gnRenderingAPILIB, gnCreateInstance, "gnCreateInstanceFn");
gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyInstance, "gnDestroyInstanceFn"); gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyInstance, "gnDestroyInstanceFn");

View File

@@ -1,5 +0,0 @@
#include <utils/gryphn_error_code.h>
gnString gnGetErrorString() {
return lastReturnCode;
}

View File

@@ -1,22 +1,63 @@
#include <utils/gryphn_bool.h> // #include <utils/gryphn_bool.h>
#include <utils/gryphn_access_level.h> // #include <utils/gryphn_access_level.h>
#include <vector> // #include <vector>
#include <utils/strings/gryphn_string.h> // #include <utils/strings/gryphn_string.h>
enum gnReturnCodeLevel { GN_FAILED = 0, GN_SUCCESS = 1 }; // enum gnReturnCodeLevel { GN_FAILED = 0, GN_SUCCESS = 1 };
inline gnString lastReturnCode = gnCreateString(); // inline gnString lastReturnCode = gnCreateString();
typedef struct gnReturnCode { // typedef struct gnReturnCode {
ACCESS_LEVEL: // ACCESS_LEVEL:
gnBool success; // gnBool success;
gnString returnCodeMessage = ""; // gnString returnCodeMessage = "";
public: // public:
bool operator==(gnReturnCodeLevel level) { return success; } // bool operator==(gnReturnCodeLevel level) { return success; }
gnReturnCode(gnReturnCodeLevel level, gnString message) : success(level), returnCodeMessage(message) { lastReturnCode = returnCodeMessage; } // gnReturnCode(gnReturnCodeLevel level, gnString message) : success(level), returnCodeMessage(message) { lastReturnCode = returnCodeMessage; }
gnReturnCode(gnReturnCodeLevel level) : success(level) { lastReturnCode = returnCodeMessage; } // gnReturnCode(gnReturnCodeLevel level) : success(level) { lastReturnCode = returnCodeMessage; }
gnReturnCode() { lastReturnCode = returnCodeMessage; } // gnReturnCode() { lastReturnCode = returnCodeMessage; }
} gnErrorCode; // } gnErrorCode;
gnString gnGetErrorString(); // gnString gnGetErrorString();
static gnReturnCode gnReturnError(gnString errorMessage) { return { GN_FAILED, errorMessage }; } // static gnReturnCode gnReturnError(gnString errorMessage) { return { GN_FAILED, errorMessage }; }
#include "utils/strings/gryphn_string.h"
typedef enum gnReturnCode {
GN_SUCCESS, GN_FAILED, GN_FATAL,
GN_ERROR = GN_FAILED
} gnReturnCode;
typedef gnReturnCode gnErrorCode;
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;
inline gnString lastReturnAPIMessage = "";
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;
}