diff --git a/gryphn_utils.h b/gryphn_utils.h index a67fa6f..ebd2f11 100644 --- a/gryphn_utils.h +++ b/gryphn_utils.h @@ -13,6 +13,7 @@ #include "utils/gryphn_color.h" #include "utils/gryphn_color_format.h" #include "utils/gryphn_image_format.h" +#include "utils/lists/gryphn_array_list.h" typedef uint32_t gnUInt; typedef char gnByte; diff --git a/utils/gryphn_error_code.h b/utils/gryphn_error_code.h index 6849445..0962090 100644 --- a/utils/gryphn_error_code.h +++ b/utils/gryphn_error_code.h @@ -15,6 +15,7 @@ typedef enum gnReturnCode_t { GN_NO_SUPPORTED_PRESENT_MODES, GN_UNKNOWN_IMAGE_FORMAT, GN_FAILED_TO_CREATE_PRESENTATION_QUEUE, + GN_WINDOW_IN_USE, GN_UNSUPPORTED_IMAGE_COUNT, GN_FAILED_TO_CREATE_IMAGE_VIEW, GN_FAILED_TO_CREATE_SHADER_MODULE, @@ -38,7 +39,8 @@ typedef enum gnReturnCode_t { GN_SUBOPTIMAL_PRESENTATION_QUEUE, GN_FAILED_TO_CREATE_BUFFER, GN_FAILED_TO_ALLOCATE_MEMORY, - GN_FAILED_TO_CREATE_IMAGE + GN_FAILED_TO_CREATE_IMAGE, + GN_FAILED_TO_CREATE_SAMPLER } gnReturnCode; typedef gnReturnCode gnErrorCode; @@ -58,6 +60,7 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) { case GN_NO_SUPPORTED_PRESENT_MODES: return "GN_NO_SUPPORTED_PRESENT_MODES"; case GN_UNKNOWN_IMAGE_FORMAT: return "GN_UNKNOWN_IMAGE_FORMAT"; case GN_FAILED_TO_CREATE_PRESENTATION_QUEUE: return "GN_FAILED_TO_CREATE_PRESENTATION_QUEUE"; + case GN_WINDOW_IN_USE: return "GN_WINDOW_IN_USE"; case GN_UNSUPPORTED_IMAGE_COUNT: return "GN_UNSUPPORTED_IMAGE_COUNT"; case GN_FAILED_TO_CREATE_IMAGE_VIEW: return "GN_FAILED_TO_CREATE_IMAGE_VIEW"; case GN_FAILED_TO_CREATE_SHADER_MODULE: return "GN_FAILED_TO_CREATE_SHADER_MODULE"; @@ -82,5 +85,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) { case GN_FAILED_TO_ALLOCATE_MEMORY: return "GN_FAILED_TO_ALLOCATE_MEMORY"; case GN_FAILED_TO_CREATE_BUFFER: return "GN_FAILED_TO_CREATE_BUFFER"; case GN_FAILED_TO_CREATE_IMAGE: return "GN_FAILED_TO_CREATE_IMAGE"; + case GN_FAILED_TO_CREATE_SAMPLER: return "GN_FAILED_TO_CREATE_SAMPLER"; } } diff --git a/utils/gryphn_image_format.h b/utils/gryphn_image_format.h index 7f54953..0cd410e 100644 --- a/utils/gryphn_image_format.h +++ b/utils/gryphn_image_format.h @@ -2,7 +2,8 @@ typedef enum gnImageFormat { GN_FORMAT_NONE, - GN_FORMAT_BGRA8_SRGB + GN_FORMAT_BGRA8_SRGB, + GN_FORMAT_RGBA8_SRGB } gnImageFormat; typedef enum gnColorSpace { diff --git a/utils/lists/gryphn_array_list.h b/utils/lists/gryphn_array_list.h index 467fd18..09b8997 100644 --- a/utils/lists/gryphn_array_list.h +++ b/utils/lists/gryphn_array_list.h @@ -1,49 +1,30 @@ #pragma once +#include "stdint.h" #include "stdlib.h" -typedef struct gnArrayList { - int count; - int maxCount; - void* data; -} 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 gnArrayList gnCreateArrayList(int count) { - gnArrayList newList; - - if (count == 0) { - - } else { - newList.count = count; - newList.maxCount = count; - newList.data = malloc(sizeof(void*) * count); - } - - return newList; +#define GN_ARRAY_LIST(type)\ +typedef struct type##ArrayList { \ +uint32_t count; \ +uint32_t maxSize; \ +type* data; \ +} type##ArrayList; \ +inline static type##ArrayList type##ArrayListCreate() { \ +type##ArrayList list;\ +list.maxSize = 2; \ +list.count = 0;\ +list.data = malloc(sizeof(type) * list.maxSize); \ +return list; \ +}\ +inline static void type##ArrayListReserve(type##ArrayList* list, int count) { \ +int newCount = count - (list->maxSize - list->count);\ +list->data = realloc(list->data, sizeof(type) * (newCount + list->maxSize)); \ +list->maxSize += newCount; \ +}\ +inline static void type##ArrayListResize(type##ArrayList* list, int count) { \ +int newCount = count - (list->maxSize - list->count);\ +list->data = realloc(list->data, sizeof(type) * (newCount + list->maxSize)); \ +list->maxSize += newCount; \ +list->count += count; \ } -inline void gnArrayListResize(gnArrayList* cList, int count) { - cList->count = count; - while (cList->count > cList->maxCount) { - int oldMaxCount = cList->maxCount; - cList->maxCount *= GROWTH_RATE; - if (cList->count == oldMaxCount) { - cList->maxCount += 1; - } - } - - cList->data = realloc(cList->data, cList->maxCount); -} - -inline void gnArrayListReserve(gnArrayList* cList, int count) { - while (cList->count > cList->maxCount) { - int oldMaxCount = cList->maxCount; - cList->maxCount *= GROWTH_RATE; - if (cList->count == oldMaxCount) { - cList->maxCount += 1; - } - } - - cList->data = realloc(cList->data, cList->maxCount); -} +GN_ARRAY_LIST(int); diff --git a/utils/math/gryphn_mat4.h b/utils/math/gryphn_mat4.h index f857aa8..2a0b1d1 100644 --- a/utils/math/gryphn_mat4.h +++ b/utils/math/gryphn_mat4.h @@ -34,16 +34,14 @@ static inline const gnMat4x4 gnOrthographic( static inline const gnMat4x4 gnProjection( float fov, float aspect, float near, float far ) { + float f = 1.0f / tan(fov * 0.5f); + return (gnMat4x4){ .mat = { - { 1/(aspect * tan(fov/2)), 0.0f, 0.0f, 0.0f }, - { 0.0f, 1/tan(fov/2), 0.0f, 0.0f }, - { 0.0f, 0.0f, -((far+near)/(far-near)), -((2*far*near)/(far-near)) }, - { 0.0f, 0.0f, -1.0f, 1.0f } - // { 1/(aspect * tan(fov/2)), 0.0f, 0.0f, 0.0f }, - // { 0.0f, 1/tan(fov/2), 0.0f, 0.0f }, - // { 0.0f, 0.0f, -((far+near)/(far-near)), -((2*far*near)/(far-near)) }, - // { 0.0f, 0.0f, -1.0f, 0.0f } + { f / aspect, 0.0f, 0.0f, 0.0f }, + { 0.0f , f , 0.0f, 0.0f }, + { 0.0f , 0.0f, (far + near) / (near - far), -1.0f }, + { 0.0f , 0.0f, (2 * far * near) / (near - far), 0.0f } } }; }