added some more utils stuff
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "utils/math/gryphn_vec2.h"
|
||||
#include "utils/math/gryphn_vec3.h"
|
||||
#include "utils/math/gryphn_vec4.h"
|
||||
#include "utils/math/gryphn_mat4.h"
|
||||
#include "utils/gryphn_color.h"
|
||||
#include "utils/gryphn_color_format.h"
|
||||
#include "utils/gryphn_image_format.h"
|
||||
|
@@ -37,7 +37,8 @@ typedef enum gnReturnCode_t {
|
||||
GN_OUT_OF_DATE_PRESENTATION_QUEUE,
|
||||
GN_SUBOPTIMAL_PRESENTATION_QUEUE,
|
||||
GN_FAILED_TO_CREATE_BUFFER,
|
||||
GN_FAILED_TO_ALLOCATE_MEMORY
|
||||
GN_FAILED_TO_ALLOCATE_MEMORY,
|
||||
GN_FAILED_TO_CREATE_IMAGE
|
||||
} gnReturnCode;
|
||||
|
||||
typedef gnReturnCode gnErrorCode;
|
||||
@@ -80,5 +81,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) {
|
||||
case GN_SUBOPTIMAL_PRESENTATION_QUEUE: return "GN_SUBOPTIMAL_PRESENTATION_QUEUE";
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum gnImageFormat_e {
|
||||
typedef enum gnImageFormat {
|
||||
GN_FORMAT_NONE,
|
||||
GN_FORMAT_BGRA8_SRGB
|
||||
} gnImageFormat;
|
||||
|
||||
typedef enum gnColorSpace_e {
|
||||
typedef enum gnColorSpace {
|
||||
GN_COLOR_SPACE_SRGB_NONLINEAR
|
||||
} gnColorSpace;
|
||||
|
||||
typedef enum gnImageSharingMode_e {
|
||||
typedef enum gnImageSharingMode {
|
||||
GN_SHARING_MODE_EXCLUSIVE, GN_SHARING_MODE_CONCURRENT
|
||||
} gnImageSharingMode;
|
||||
|
||||
typedef enum gnImageLayout_e {
|
||||
typedef enum gnImageLayout {
|
||||
GN_LAYOUT_UNDEFINED, GN_LAYOUT_PRESENTATION_QUEUE_IMAGE, GN_LAYOUT_TRANSFER_DESTINATION, GN_COLOR_ATTACHMENT
|
||||
} gnImageLayout;
|
||||
|
@@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
#include "math.h"
|
||||
|
||||
typedef struct gnMat4x4 {
|
||||
float mat[4][4];
|
||||
} gnMat4x4;
|
||||
typedef gnMat4x4 gnMat4;
|
||||
|
||||
gnMat4x4 gnIdentity() {
|
||||
static inline const gnMat4x4 gnIdentity() {
|
||||
return (gnMat4x4){
|
||||
.mat = {
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
@@ -15,3 +16,34 @@ gnMat4x4 gnIdentity() {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
static inline const gnMat4x4 gnOrthographic(
|
||||
float left, float right, float top, float bottom, float near, float far
|
||||
) {
|
||||
return (gnMat4x4){
|
||||
.mat = {
|
||||
{ (2)/(right-left), 0.0f, 0.0f, -((right+left)/(right-left)) },
|
||||
{ 0.0f, 2/(top-bottom), 0.0f, -((top+bottom)/(top-bottom)) },
|
||||
{ 0.0f, 0.0f, -2/(far-near), -((far+near)/(far-near)) },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static inline const gnMat4x4 gnProjection(
|
||||
float fov, float aspect, float near, float far
|
||||
) {
|
||||
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 }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user