utils stuff
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#include "utils/gryphn_color.h"
|
#include "utils/gryphn_color.h"
|
||||||
#include "utils/gryphn_color_format.h"
|
#include "utils/gryphn_color_format.h"
|
||||||
#include "utils/gryphn_image_format.h"
|
#include "utils/gryphn_image_format.h"
|
||||||
|
#include "utils/lists/gryphn_array_list.h"
|
||||||
|
|
||||||
typedef uint32_t gnUInt;
|
typedef uint32_t gnUInt;
|
||||||
typedef char gnByte;
|
typedef char gnByte;
|
||||||
|
@@ -15,6 +15,7 @@ typedef enum gnReturnCode_t {
|
|||||||
GN_NO_SUPPORTED_PRESENT_MODES,
|
GN_NO_SUPPORTED_PRESENT_MODES,
|
||||||
GN_UNKNOWN_IMAGE_FORMAT,
|
GN_UNKNOWN_IMAGE_FORMAT,
|
||||||
GN_FAILED_TO_CREATE_PRESENTATION_QUEUE,
|
GN_FAILED_TO_CREATE_PRESENTATION_QUEUE,
|
||||||
|
GN_WINDOW_IN_USE,
|
||||||
GN_UNSUPPORTED_IMAGE_COUNT,
|
GN_UNSUPPORTED_IMAGE_COUNT,
|
||||||
GN_FAILED_TO_CREATE_IMAGE_VIEW,
|
GN_FAILED_TO_CREATE_IMAGE_VIEW,
|
||||||
GN_FAILED_TO_CREATE_SHADER_MODULE,
|
GN_FAILED_TO_CREATE_SHADER_MODULE,
|
||||||
@@ -38,7 +39,8 @@ typedef enum gnReturnCode_t {
|
|||||||
GN_SUBOPTIMAL_PRESENTATION_QUEUE,
|
GN_SUBOPTIMAL_PRESENTATION_QUEUE,
|
||||||
GN_FAILED_TO_CREATE_BUFFER,
|
GN_FAILED_TO_CREATE_BUFFER,
|
||||||
GN_FAILED_TO_ALLOCATE_MEMORY,
|
GN_FAILED_TO_ALLOCATE_MEMORY,
|
||||||
GN_FAILED_TO_CREATE_IMAGE
|
GN_FAILED_TO_CREATE_IMAGE,
|
||||||
|
GN_FAILED_TO_CREATE_SAMPLER
|
||||||
} gnReturnCode;
|
} gnReturnCode;
|
||||||
|
|
||||||
typedef gnReturnCode gnErrorCode;
|
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_NO_SUPPORTED_PRESENT_MODES: return "GN_NO_SUPPORTED_PRESENT_MODES";
|
||||||
case GN_UNKNOWN_IMAGE_FORMAT: return "GN_UNKNOWN_IMAGE_FORMAT";
|
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_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_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_IMAGE_VIEW: return "GN_FAILED_TO_CREATE_IMAGE_VIEW";
|
||||||
case GN_FAILED_TO_CREATE_SHADER_MODULE: return "GN_FAILED_TO_CREATE_SHADER_MODULE";
|
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_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_BUFFER: return "GN_FAILED_TO_CREATE_BUFFER";
|
||||||
case GN_FAILED_TO_CREATE_IMAGE: return "GN_FAILED_TO_CREATE_IMAGE";
|
case GN_FAILED_TO_CREATE_IMAGE: return "GN_FAILED_TO_CREATE_IMAGE";
|
||||||
|
case GN_FAILED_TO_CREATE_SAMPLER: return "GN_FAILED_TO_CREATE_SAMPLER";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
typedef enum gnImageFormat {
|
typedef enum gnImageFormat {
|
||||||
GN_FORMAT_NONE,
|
GN_FORMAT_NONE,
|
||||||
GN_FORMAT_BGRA8_SRGB
|
GN_FORMAT_BGRA8_SRGB,
|
||||||
|
GN_FORMAT_RGBA8_SRGB
|
||||||
} gnImageFormat;
|
} gnImageFormat;
|
||||||
|
|
||||||
typedef enum gnColorSpace {
|
typedef enum gnColorSpace {
|
||||||
|
@@ -1,49 +1,30 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "stdint.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
|
||||||
typedef struct gnArrayList {
|
#define GN_ARRAY_LIST(type)\
|
||||||
int count;
|
typedef struct type##ArrayList { \
|
||||||
int maxCount;
|
uint32_t count; \
|
||||||
void* data;
|
uint32_t maxSize; \
|
||||||
} gnArrayList;
|
type* data; \
|
||||||
|
} type##ArrayList; \
|
||||||
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 static type##ArrayList type##ArrayListCreate() { \
|
||||||
|
type##ArrayList list;\
|
||||||
inline gnArrayList gnCreateArrayList(int count) {
|
list.maxSize = 2; \
|
||||||
gnArrayList newList;
|
list.count = 0;\
|
||||||
|
list.data = malloc(sizeof(type) * list.maxSize); \
|
||||||
if (count == 0) {
|
return list; \
|
||||||
|
}\
|
||||||
} else {
|
inline static void type##ArrayListReserve(type##ArrayList* list, int count) { \
|
||||||
newList.count = count;
|
int newCount = count - (list->maxSize - list->count);\
|
||||||
newList.maxCount = count;
|
list->data = realloc(list->data, sizeof(type) * (newCount + list->maxSize)); \
|
||||||
newList.data = malloc(sizeof(void*) * count);
|
list->maxSize += newCount; \
|
||||||
}
|
}\
|
||||||
|
inline static void type##ArrayListResize(type##ArrayList* list, int count) { \
|
||||||
return newList;
|
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) {
|
GN_ARRAY_LIST(int);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
@@ -34,16 +34,14 @@ static inline const gnMat4x4 gnOrthographic(
|
|||||||
static inline const gnMat4x4 gnProjection(
|
static inline const gnMat4x4 gnProjection(
|
||||||
float fov, float aspect, float near, float far
|
float fov, float aspect, float near, float far
|
||||||
) {
|
) {
|
||||||
|
float f = 1.0f / tan(fov * 0.5f);
|
||||||
|
|
||||||
return (gnMat4x4){
|
return (gnMat4x4){
|
||||||
.mat = {
|
.mat = {
|
||||||
{ 1/(aspect * tan(fov/2)), 0.0f, 0.0f, 0.0f },
|
{ f / aspect, 0.0f, 0.0f, 0.0f },
|
||||||
{ 0.0f, 1/tan(fov/2), 0.0f, 0.0f },
|
{ 0.0f , f , 0.0f, 0.0f },
|
||||||
{ 0.0f, 0.0f, -((far+near)/(far-near)), -((2*far*near)/(far-near)) },
|
{ 0.0f , 0.0f, (far + near) / (near - far), -1.0f },
|
||||||
{ 0.0f, 0.0f, -1.0f, 1.0f }
|
{ 0.0f , 0.0f, (2 * far * near) / (near - far), 0.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 }
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user