Add my own math library

GLM works only for C++ and I plan on moving to back to C. There is
a C port, but it would be good for me to figure out vertex math myself.
Hence, my own library has been created.
This commit is contained in:
Piotr Krygier committed 2023-08-10 09:43:26 +02:00
1 parent c22569cc48
commit bf31b96a2e
26 files changed
+542 -175

No files matched your search

-9
View File
@@ -1,9 +0,0 @@
set(GLM_DIR "${PROJECT_SOURCE_DIR}/third_party/GLM/")
find_library(
glm
NAMES glm glm_shared
HINTS ${GLM_DIR}/build/glm
)
set(glm_INCLUDE_DIR "${GLM_DIR}/include")
-5
View File
@@ -1,8 +1,3 @@
[GLM]
git_url = https://github.com/g-truc/glm.git
tag = 0.9.9.8
custom_commands = cd GLM && mkdir build && cd build && cmake .. -D BUILD_SHARED_LIBS=ON && make && cd .. && mkdir include && mv glm include
[GLFW] [GLFW]
git_url = https://github.com/glfw/glfw.git git_url = https://github.com/glfw/glfw.git
tag = 3.3.8 tag = 3.3.8
+1 -3
View File
@@ -1,7 +1,6 @@
find_package(Vulkan REQUIRED) find_package(Vulkan REQUIRED)
find_package(vma REQUIRED) find_package(vma REQUIRED)
find_package(glfw3 REQUIRED) find_package(glfw3 REQUIRED)
find_package(glm REQUIRED)
find_package(Vulkan COMPONENTS glslc) find_package(Vulkan COMPONENTS glslc)
find_program(glslc_executable NAMES glslc HINTS ${Vulkan_GLSLC_EXECUTABLE}/..) find_program(glslc_executable NAMES glslc HINTS ${Vulkan_GLSLC_EXECUTABLE}/..)
@@ -43,7 +42,6 @@ ${CMAKE_SOURCE_DIR}
${Vulkan_INCLUDE_DIR} ${Vulkan_INCLUDE_DIR}
${vma_INCLUDE_DIR} ${vma_INCLUDE_DIR}
${glfw3_INCLUDE_DIR} ${glfw3_INCLUDE_DIR}
${glm_INCLUDE_DIR}
) )
message("Vulkan_INCLUDE_DIR: ${Vulkan_INCLUDE_DIR}") message("Vulkan_INCLUDE_DIR: ${Vulkan_INCLUDE_DIR}")
@@ -54,6 +52,7 @@ target_sources(rse_graphics PRIVATE
src/vulkan_buffers.cpp src/vulkan_buffers.cpp
src/vulkan_descriptors.cpp src/vulkan_descriptors.cpp
src/rse_graphics.cpp src/rse_graphics.cpp
src/rse_math.c
src/mesh_controller.cpp src/mesh_controller.cpp
src/vulkan_commons.cpp src/vulkan_commons.cpp
) )
@@ -62,5 +61,4 @@ target_link_libraries(rse_graphics PRIVATE
rse_utilities rse_utilities
${Vulkan_LIBRARIES} ${Vulkan_LIBRARIES}
${glfw} ${glfw}
${glm}
) )
+3 -4
View File
@@ -2,11 +2,10 @@
#define RSE_GRAPHICS_HPP #define RSE_GRAPHICS_HPP
#include <cstdint> #include <cstdint>
struct VulkanState;
namespace rse::graphics namespace rse::graphics
{ {
namespace vulkanbase {
struct VulkanState;
};
class RseGraphics { class RseGraphics {
public: public:
RseGraphics(); RseGraphics();
@@ -24,7 +23,7 @@ class RseGraphics {
private: private:
/* Hold vulkan state. It is modified by function initializing and communicating with Vulkan API */ /* Hold vulkan state. It is modified by function initializing and communicating with Vulkan API */
vulkanbase::VulkanState* vulkan_state; VulkanState* vulkan_state;
}; };
@@ -9,15 +9,10 @@
* *
*/ */
#pragma once #ifndef LOCALE_VULKAN_H
#define LOCALE_VULKAN_H
#include <array> #include "utilities/localization.h"
#include <vector>
#include "utilities/localization.hpp"
namespace rse::locale::vulkan
{
#define vulkanErrorMesssages vulkanErrorMesssages_nolocale[SELECTED_LANGUAGE] #define vulkanErrorMesssages vulkanErrorMesssages_nolocale[SELECTED_LANGUAGE]
@@ -53,7 +48,7 @@ enum Errors
LAST_MESSAGE LAST_MESSAGE
}; };
inline std::array<std::array<const char*, LAST_MESSAGE>, rse::utils::locale::LAST_LANGUAGE> vulkanErrorMesssages_nolocale = { const char vulkanErrorMesssages_nolocale[LAST_LANGUAGE][LAST_MESSAGE][MAX_MESSAGE_LENGHT] = {
{/* EN_US */ {/* EN_US */
/* VULKAN_LAYER_NOT_SUPPORTED */ /* VULKAN_LAYER_NOT_SUPPORTED */
"Selected layer is not supported: ", "Selected layer is not supported: ",
@@ -112,4 +107,4 @@ inline std::array<std::array<const char*, LAST_MESSAGE>, rse::utils::locale::LAS
} }
}; };
} // namespace rse::locale::vulkan #endif /* LOCALE_VULKAN_H */
@@ -13,11 +13,7 @@
#include <array> #include <array>
#include "utilities/localization.hpp" #include "utilities/localization.h"
namespace rse::locale::window
{
#define windowErrorMesssages windowErrorMesssages_nolocale[SELECTED_LANGUAGE] #define windowErrorMesssages windowErrorMesssages_nolocale[SELECTED_LANGUAGE]
@@ -29,15 +25,13 @@ enum Errors
LAST_MESSAGE LAST_MESSAGE
}; };
std::array<std::array<const char*, rse::utils::locale::LAST_LANGUAGE>, LAST_MESSAGE> windowErrorMesssages_nolocale = { const char windowErrorMesssages_nolocale[LAST_LANGUAGE][LAST_MESSAGE][MAX_MESSAGE_LENGHT] = {
{/* EN_US */ {/* EN_US */
/* WINDOW_GLFW_INIT_FAILED */ /* WINDOW_GLFW_INIT_FAILED */
"GLFW init failed!" "GLFW init failed!",
/* WINDOW_VULKAN_NOT_SUPPORTED */ /* WINDOW_VULKAN_NOT_SUPPORTED */
"Unable to load Vulkan" "Unable to load Vulkan",
/*WINDOW_NOT_CREATED*/ /*WINDOW_NOT_CREATED*/
"Window context creation failed" "Window context creation failed"
} }
}; };
} // namespace rse::locale::window
+5 -11
View File
@@ -1,20 +1,16 @@
#include "mesh_controller.hpp" #include "mesh_controller.h"
#include <map>
#include <queue>
#include <memory>
#include "vulkan_buffers.hpp" #include "vulkan_buffers.hpp"
namespace rse::graphics::mesh #include <map>
{ #include <queue>
std::map<uint16_t, struct Mesh> g_meshes; std::map<uint16_t, struct Mesh> g_meshes;
std::queue<uint16_t> free_ids; std::queue<uint16_t> free_ids;
std::map<uint16_t, std::queue<uint16_t>> instance_free_ids; std::map<uint16_t, std::queue<uint16_t>> instance_free_ids;
uint16_t create_mesh(std::vector<rse::graphics::vulkanbase::Vertex> vertices, uint16_t create_mesh(std::vector<Vertex> vertices,
std::vector<uint16_t> indices) std::vector<uint16_t> indices)
{ {
static uint16_t last_id = 0U; static uint16_t last_id = 0U;
@@ -72,12 +68,10 @@ std::vector<InstanceData> get_instance_data_for_mesh(uint16_t mesh_id) {
} }
std::vector<rse::graphics::vulkanbase::Vertex> get_mesh_vertices(uint16_t mesh_id) { std::vector<Vertex> get_mesh_vertices(uint16_t mesh_id) {
return g_meshes[mesh_id].vertices; return g_meshes[mesh_id].vertices;
} }
std::vector<uint16_t> get_mesh_indices(uint16_t mesh_id) { std::vector<uint16_t> get_mesh_indices(uint16_t mesh_id) {
return g_meshes[mesh_id].indices; return g_meshes[mesh_id].indices;
} }
} // namespace rse::graphics::mesh
@@ -1,5 +1,5 @@
/** /**
* @file mesh_controller.hpp * @file mesh_controller.h
* @author Piotr Krygier (piotr.krygier@meshsystems.com) * @author Piotr Krygier (piotr.krygier@meshsystems.com)
* @brief * @brief
* @version 0.1 * @version 0.1
@@ -9,19 +9,15 @@
* *
*/ */
#ifndef RSE_MESH_CONTROLLER_HPP #ifndef RSE_MESH_CONTROLLER_H
#define RSE_MESH_CONTROLLER_HPP #define RSE_MESH_CONTROLLER_H
#include "vulkan_commons.h"
#include <map>
#include <vector>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <vector>
#include <map>
#include "vulkan_commons.hpp"
namespace rse::graphics::mesh
{
/* Forward declarations */ /* Forward declarations */
struct MeshInstance; struct MeshInstance;
@@ -34,7 +30,7 @@ struct MeshInstance
struct Mesh struct Mesh
{ {
uint32_t unique_id; uint32_t unique_id;
const std::vector<rse::graphics::vulkanbase::Vertex> vertices; const std::vector<Vertex> vertices;
std::vector<uint16_t> indices; std::vector<uint16_t> indices;
std::map<uint16_t, std::unique_ptr<MeshInstance>> instances; std::map<uint16_t, std::unique_ptr<MeshInstance>> instances;
}; };
@@ -47,7 +43,7 @@ struct Mesh
* @param indices indices for mesh * @param indices indices for mesh
* @return uint16_t Mesh identifier. Can be useful for getting vertices, indices and instances * @return uint16_t Mesh identifier. Can be useful for getting vertices, indices and instances
*/ */
uint16_t create_mesh(std::vector<rse::graphics::vulkanbase::Vertex> vertices, uint16_t create_mesh(std::vector<Vertex> vertices,
std::vector<uint16_t> indices); std::vector<uint16_t> indices);
/** /**
@@ -59,13 +55,9 @@ uint16_t create_mesh(std::vector<rse::graphics::vulkanbase::Vertex> vertices,
void create_mesh_instance(uint16_t mesh_id, void create_mesh_instance(uint16_t mesh_id,
InstanceData instance_data); InstanceData instance_data);
std::vector<rse::graphics::vulkanbase::Vertex> get_mesh_vertices(uint16_t mesh_id); std::vector<Vertex> get_mesh_vertices(uint16_t mesh_id);
std::vector<uint16_t> get_mesh_indices(uint16_t mesh_id); std::vector<uint16_t> get_mesh_indices(uint16_t mesh_id);
std::vector<InstanceData> get_instance_data_for_mesh(uint16_t mesh_id); std::vector<InstanceData> get_instance_data_for_mesh(uint16_t mesh_id);
} // namespace rse::graphics::mesh #endif /* RSE_MESH_CONTROLLER_H */
#endif
+18 -16
View File
@@ -2,14 +2,16 @@
#include "window.hpp" #include "window.hpp"
#include "vulkan_base.hpp" #include "vulkan_base.hpp"
#include "mesh_controller.hpp" #include "mesh_controller.h"
#include "vulkan_commons.hpp" #include "vulkan_commons.h"
#include "rse_math.h"
namespace rse::graphics namespace rse::graphics
{ {
RseGraphics::RseGraphics() RseGraphics::RseGraphics()
{ {
vulkan_state = new vulkanbase::VulkanState; vulkan_state = new VulkanState;
vulkan_state->graphicsQueue = VK_NULL_HANDLE; vulkan_state->graphicsQueue = VK_NULL_HANDLE;
vulkan_state->physicalDevice = VK_NULL_HANDLE; vulkan_state->physicalDevice = VK_NULL_HANDLE;
vulkan_state->currentFrame = 0U; vulkan_state->currentFrame = 0U;
@@ -44,11 +46,11 @@ uint8_t RseGraphics::graphics_run(void)
return -1; return -1;
// FIXME: Temporary array of vertices, for testing purposes // FIXME: Temporary array of vertices, for testing purposes
const std::vector<rse::graphics::vulkanbase::Vertex> vertices = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 1.0f}}, const std::vector<Vertex> vertices = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 1.0f}},
{{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 1.0f}}, {{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 1.0f}},
{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}}, {{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}},
{{-0.5f, 0.5f, 0.0f}, {1.0f, 0.0f, 1.0f}}}; {{-0.5f, 0.5f, 0.0f}, {1.0f, 0.0f, 1.0f}}};
const std::vector<rse::graphics::vulkanbase::Vertex> vertices2 = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 1.0f}}, const std::vector<Vertex> vertices2 = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 1.0f}},
{{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}}, {{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}},
{{0.5f, 0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}}, {{0.5f, 0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}},
@@ -57,23 +59,23 @@ uint8_t RseGraphics::graphics_run(void)
// FIXME: Temporary array of vertices, for testing purposes // FIXME: Temporary array of vertices, for testing purposes
std::vector<uint16_t> indices = {0, 1, 2, 2, 3, 0}; std::vector<uint16_t> indices = {0, 1, 2, 2, 3, 0};
uint16_t mesh_id = rse::graphics::mesh::create_mesh(vertices, indices); uint16_t mesh_id = create_mesh(vertices, indices);
rse::graphics::mesh::create_mesh_instance(mesh_id, rse::graphics::mesh::InstanceData( create_mesh_instance(mesh_id, InstanceData(
glm::vec3(0.0f, 0.0f, 0.0f), {0.0f, 0.0f, 0.0f},
glm::vec3(0.0f, 0.0f, glm::radians(45.0f)), {0.0f, 0.0f, rse_math_deg_to_radians(45.0f)},
1.0f 1.0f
)); ));
rse::graphics::mesh::create_mesh_instance(mesh_id, rse::graphics::mesh::InstanceData( create_mesh_instance(mesh_id, InstanceData(
glm::vec3(-1.0f, 0.0f, 0.0f), {-1.0f, 0.0f, 0.0f},
glm::vec3(0.0f, 0.0f, 0.0f), {0.0f, 0.0f, 0.0f},
1.0f 1.0f
)); ));
mesh_id = rse::graphics::mesh::create_mesh(vertices, indices); mesh_id = create_mesh(vertices, indices);
rse::graphics::mesh::create_mesh_instance(mesh_id, rse::graphics::mesh::InstanceData( create_mesh_instance(mesh_id, InstanceData(
glm::vec3(0.0f, 1.0f, 0.0f), {0.0f, 1.0f, 0.0f},
glm::vec3(0.0f, 0.0f, glm::radians(0.0f)), {0.0f, 0.0f, rse_math_deg_to_radians(0.0f)},
1.0f 1.0f
)); ));
+126
View File
@@ -0,0 +1,126 @@
#include "rse_math.h"
#include <math.h>
#define PI 3.14159265359f
static struct vec3_t substract_vec3(const struct vec3_t* vec1, const struct vec3_t* vec2)
{
struct vec3_t result;
result.x = vec1->x - vec2->x;
result.y = vec1->y - vec2->y;
result.z = vec1->z - vec2->z;
return result;
}
static float length_vec3(const struct vec3_t* vec)
{
return sqrt((vec->x * vec->x)
+(vec->y * vec->y)
+(vec->z * vec->z));
}
static float scalar_cross_vec3(const struct vec3_t* vec1, const struct vec3_t* vec2)
{
return (vec1->x * vec2->x)
+(vec1->y * vec2->y)
+(vec1->z * vec2->z);
}
float rse_math_deg_to_radians(float degrees)
{
return degrees * (PI/180.0f);
}
struct vec3_t rse_math_cross_vec3(const struct vec3_t* vec1, const struct vec3_t* vec2)
{
struct vec3_t result;
result.x = (vec1->y * vec2->z) - (vec1->z * vec2->y);
result.y = (vec1->z * vec2->x) - (vec1->x * vec2->z);
result.z = (vec1->x * vec2->y) - (vec1->y * vec2->x);
return result;
}
struct vec3_t rse_math_normalize_vec3(const struct vec3_t* vec)
{
struct vec3_t result = {0};
float vec_length = 0.0f;
vec_length = length_vec3(vec);
result.x = vec->x / vec_length;
result.y = vec->y / vec_length;
result.z = vec->z / vec_length;
return result;
}
struct mat4_t rse_math_uniform_mat4()
{
struct mat4_t result= {0.0f};
result.x_1 = 1.0f;
result.y_2 = 1.0f;
result.z_3 = 1.0f;
result.w_4 = 1.0f;
return result;
}
struct mat4_t rse_math_perspective(float fovy, float aspect_ratio, float z_near, float z_far)
{
float tan_half_fovy = 0;
struct mat4_t result = {0};
tan_half_fovy = tan(fovy / 2.0f);
result.x_1 = -1.0f / (aspect_ratio * tan_half_fovy);
result.y_2 = 1.0f / (tan_half_fovy);
result.z_3 = - (z_far + z_near) / (z_far - z_near);
result.w_3 = -1.0f;
result.z_4 = - (2.0f * z_far * z_near) / (z_far - z_near);
return result;
}
struct mat4_t rse_math_look_at(const struct vec3_t* eye, const struct vec3_t* center, const struct vec3_t* up)
{
struct mat4_t result = {0.0f};
struct vec3_t forward_vec = {0};
struct vec3_t right_vec = {0};
struct vec3_t up_vec = {0};
struct vec3_t tmp = substract_vec3(eye, center);
forward_vec = rse_math_normalize_vec3(&tmp);
tmp = rse_math_cross_vec3(up, &forward_vec);
right_vec = rse_math_normalize_vec3(&tmp);
up_vec = rse_math_cross_vec3(&forward_vec, &right_vec);
result.x_1 = right_vec.x;
result.x_2 = right_vec.y;
result.x_3 = right_vec.z;
result.y_1 = up_vec.x;
result.y_2 = up_vec.y;
result.y_3 = up_vec.z;
result.z_1 = forward_vec.x;
result.z_2 = forward_vec.y;
result.z_3 = forward_vec.z;
result.x_4 = -scalar_cross_vec3(&right_vec, eye);
result.y_4 = -scalar_cross_vec3(&up_vec, eye);
result.z_4 = -scalar_cross_vec3(&forward_vec, eye);
result.w_1 = 0;
result.w_2 = 0;
result.w_3 = 0;
result.w_4 = 1;
return result;
}
+120
View File
@@ -0,0 +1,120 @@
/**
* @file rse_math.h
* @author Piotr Krygier (piotr.krygier@)
* @brief RedScarfEngine math operations
* @version 0.1
* @date 2023-08-07
*
* @copyright Copyright (c) 2023
*
*/
#ifndef RSE_MATH_H
#define RSE_MATH_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Simple representation of vector
*
*/
struct vec3_t {
float x;
float y;
float z;
};
/* 4x4 matrix.
* [x_1 | x_2 | x_3 | x_4]
* [y_1 | y_2 | y_3 | y_4]
* [z_1 | x_2 | z_3 | z_4]
* [z_1 | w_2 | w_3 | w_4]
*
* Vulkan and OpenGL expects matrix to be passed by columns, this is why members are created in this order.
* */
struct mat4_t {
/* First column */
float x_1;
float y_1;
float z_1;
float w_1;
/* Second column */
float x_2;
float y_2;
float z_2;
float w_2;
/* Third column */
float x_3;
float y_3;
float z_3;
float w_3;
/* Fourth column */
float x_4;
float y_4;
float z_4;
float w_4;
};
/**
* @brief Calculate radians from provided degree
*
* @param degrees degrees
* @return float radians
*/
float rse_math_deg_to_radians(float degrees);
/**
* @brief Create an uniform matrix, the one with ones on diagonal
*
* @return struct mat4_t Diagonal matrix
*/
struct mat4_t rse_math_uniform_mat4();
/**
* @brief Normalizes provided vector. Changes the values inside the vector to range 0.0...1.0
*
* @param vec Vector to normalize
* @return struct vec3_t Normalized vector
*/
struct vec3_t rse_math_normalize_vec3(const struct vec3_t* vec);
/**
* @brief Creates vector cross product, a vector, using right hand rule. Note, that order of vectors is important
*
* @param vec1 Input vector
* @param vec2 Input vector
* @return struct vec3_t Resulting cross product vector
*/
struct vec3_t rse_math_cross_vec3(const struct vec3_t* vec1, const struct vec3_t* vec2);
/**
* @brief Calculates transformation matrix for viewing object from and eye cooridinates
*
* @param eye Location of the camera or the eye
* @param center Where are we looking at
* @param up Where "up" is located. Usually (0, 1, 0), since Y is up in most cases
* @return struct mat4_t Resulting lootAtMatrix
*/
struct mat4_t rse_math_look_at(const struct vec3_t* eye, const struct vec3_t* center, const struct vec3_t* up);
/**
* @brief Creates perspective matrix, used in projection
*
* @param fovy_rad Field of view, in radians
* @param aspect_ratio Aspect ratio (usally screen width / height)
* @param z_near How near objects we can see
* @param z_far How far objects we can see
* @return struct mat4_t Resulting perspective matrix
*/
struct mat4_t rse_math_perspective(float fovy_rad, float aspect_ratio, float z_near, float z_far);
#ifdef __cplusplus
}
#endif
#endif /* RSE_MATH_H */
+7 -5
View File
@@ -11,7 +11,7 @@
#include "vulkan_base.hpp" #include "vulkan_base.hpp"
#include "vulkan_errors.hpp" #include "vulkan_errors.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#pragma GCC diagnostic push #pragma GCC diagnostic push
@@ -27,11 +27,11 @@
#include "vk_mem_alloc.h" #include "vk_mem_alloc.h"
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#include "locale_vulkan.hpp" #include "locale_vulkan.h"
#include "utilities/logger.hpp" #include "utilities/logger.hpp"
#include "window.hpp" #include "window.hpp"
#include "vulkan_commons.hpp" #include "vulkan_commons.h"
#include "vulkan_buffers.hpp" #include "vulkan_buffers.hpp"
#include "vulkan_descriptors.hpp" #include "vulkan_descriptors.hpp"
#include "vulkan_pipeline.hpp" #include "vulkan_pipeline.hpp"
@@ -39,8 +39,6 @@
namespace rse::graphics::vulkanbase namespace rse::graphics::vulkanbase
{ {
using namespace locale::vulkan;
#define APPLICATION_NAME "RedScarfEngine PoC" #define APPLICATION_NAME "RedScarfEngine PoC"
#define ENGINE_NAME "RedScarf Engine" #define ENGINE_NAME "RedScarf Engine"
@@ -394,17 +392,21 @@ uint8_t createDevice()
{ {
size_t numberOfQueues = 0; size_t numberOfQueues = 0;
for (size_t familyIdx = 0; familyIdx < queueFamiliesPropertyCount; ++familyIdx) { for (size_t familyIdx = 0; familyIdx < queueFamiliesPropertyCount; ++familyIdx) {
LOGI << "Checking queue: " << familyIdx;
if (pQueueFamilyProperties[familyIdx].queueFlags & VK_QUEUE_GRAPHICS_BIT) { if (pQueueFamilyProperties[familyIdx].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
if (pQueueFamilyProperties[familyIdx].queueCount > numberOfQueues) { if (pQueueFamilyProperties[familyIdx].queueCount > numberOfQueues) {
graphicsFamilyIdx = familyIdx; graphicsFamilyIdx = familyIdx;
LOGI << "Setting graphics family idx to " << familyIdx;
numberOfQueues = pQueueFamilyProperties[familyIdx].queueCount; numberOfQueues = pQueueFamilyProperties[familyIdx].queueCount;
} }
} }
/* Check for family with surface support */ /* Check for family with surface support */
VkBool32 presentSupport = false; VkBool32 presentSupport = false;
vkGetPhysicalDeviceSurfaceSupportKHR(g_vulkan_state.physicalDevice, familyIdx, g_vulkan_state.surface, &presentSupport); vkGetPhysicalDeviceSurfaceSupportKHR(g_vulkan_state.physicalDevice, familyIdx, g_vulkan_state.surface, &presentSupport);
if (presentSupport) { if (presentSupport) {
presentationFamiliyIdx = familyIdx; presentationFamiliyIdx = familyIdx;
LOGI << "Setting present family idx to " << familyIdx;
} }
if (graphicsFamilyIdx > 0 && presentationFamiliyIdx > 0) { if (graphicsFamilyIdx > 0 && presentationFamiliyIdx > 0) {
+1 -1
View File
@@ -17,7 +17,7 @@
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include "vulkan_commons.hpp" #include "vulkan_commons.h"
namespace rse::graphics::vulkanbase namespace rse::graphics::vulkanbase
{ {
+28 -19
View File
@@ -3,21 +3,17 @@
#include <cstdint> #include <cstdint>
#define GLM_FORCE_RADIANS #include "vulkan_errors.h"
#include <glm/gtc/matrix_transform.hpp> #include "locale_vulkan.h"
#include "vulkan_errors.hpp"
#include "locale_vulkan.hpp"
#include "utilities/logger.hpp" #include "utilities/logger.hpp"
#include "mesh_controller.hpp" #include "mesh_controller.h"
#include "rse_math.h"
namespace rse::graphics::vulkanbase namespace rse::graphics::vulkanbase
{ {
#define MAX_VERTEX_BUFFER_SIZE 33554432 /* 32 MB*/ #define MAX_VERTEX_BUFFER_SIZE 33554432 /* 32 MB*/
using namespace locale::vulkan;
// // FIXME: Temporary array of vertices, for testing purposes // // FIXME: Temporary array of vertices, for testing purposes
// const std::vector<Vertex> vertices = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 1.0f}}, // const std::vector<Vertex> vertices = {{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 1.0f}},
// {{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 1.0f}}, // {{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 1.0f}},
@@ -320,19 +316,32 @@ uint8_t allocateCommandBuffers()
*/ */
void updateUniformBuffer() void updateUniformBuffer()
{ {
struct vec3_t eye = {0};
struct vec3_t center = {0};
struct vec3_t up = {0};
float fovy;
float z_near;
float z_far;
UniformBufferObject ubo{}; UniformBufferObject ubo{};
// ubo.model = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0.0f, 0.0f)) * glm::rotate(glm::mat4(1.0f), glm::radians(45.0f), glm::vec3(0.0f, 0.0f, 1.0f)) * glm::scale(glm::mat4(1.0f), glm::vec3(2, 1, 1));
ubo.model = glm::mat4(1.0f); eye.z = 5.0f;
ubo.view = glm::lookAt(glm::vec3(0.0f, 0.0f, 5.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
ubo.proj = glm::perspective(glm::radians(45.0f), up.y = 1.0f;
fovy = rse_math_deg_to_radians(45.0f);
z_near = 0.1f;
z_far = 20.0f;
ubo.model = rse_math_uniform_mat4();
ubo.view = rse_math_look_at(&eye, &center, &up);
ubo.proj = rse_math_perspective(fovy,
g_vulkan_state.swapchainExtent.width / (float)g_vulkan_state.swapchainExtent.height, g_vulkan_state.swapchainExtent.width / (float)g_vulkan_state.swapchainExtent.height,
0.1f, z_near,
20.0f); z_far);
ubo.proj[1][1] *= -1; /* GLM was developed for OpenGL, where Y coordinate of the clip is inverted */
memcpy(g_vulkan_state.uniformBuffers[g_vulkan_state.currentFrame].allocationInfo.pMappedData, &ubo, sizeof(ubo)); memcpy(g_vulkan_state.uniformBuffers[g_vulkan_state.currentFrame].allocationInfo.pMappedData, &ubo, sizeof(ubo));
} }
uint8_t update_mesh_buffers(const std::vector<rse::graphics::vulkanbase::Vertex>& vertices, uint8_t update_mesh_buffers(const std::vector<Vertex>& vertices,
const std::vector<uint16_t>& indices) const std::vector<uint16_t>& indices)
{ {
// void* mapped_data; // void* mapped_data;
@@ -375,7 +384,7 @@ uint8_t update_mesh_buffers(const std::vector<rse::graphics::vulkanbase::Vertex>
return VULKAN_ERROR_NO_ERROR; return VULKAN_ERROR_NO_ERROR;
} }
uint8_t update_mesh_instances(rse::graphics::mesh::InstanceData& instance_data) uint8_t update_mesh_instances(InstanceData& instance_data)
{ {
Buffer staging_buffer; Buffer staging_buffer;
@@ -460,8 +469,8 @@ uint8_t recordCommandBuffer(uint32_t imageIndex)
VkBuffer vertexBuffers[] = {gVertexBuffers[i].buffer}; VkBuffer vertexBuffers[] = {gVertexBuffers[i].buffer};
VkBuffer indexBuffer = {gIndexBuffers[i].buffer}; VkBuffer indexBuffer = {gIndexBuffers[i].buffer};
VkBuffer instanceBuffers[] = {gInstanceBuffers[i].buffer}; VkBuffer instanceBuffers[] = {gInstanceBuffers[i].buffer};
auto indices = rse::graphics::mesh::get_mesh_indices(0); auto indices = get_mesh_indices(0);
auto instances = rse::graphics::mesh::get_instance_data_for_mesh(0); auto instances = get_instance_data_for_mesh(0);
/* TODO: Figure out the offset */ /* TODO: Figure out the offset */
vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets); vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets);
+3 -3
View File
@@ -7,7 +7,7 @@
#include "vk_mem_alloc.h" #include "vk_mem_alloc.h"
#include "vulkan_commons.hpp" #include "vulkan_commons.h"
namespace rse::graphics::vulkanbase namespace rse::graphics::vulkanbase
{ {
@@ -27,10 +27,10 @@ uint8_t create_buffers();
*/ */
void updateUniformBuffer(); void updateUniformBuffer();
uint8_t update_mesh_buffers(const std::vector<rse::graphics::vulkanbase::Vertex>& vertices, uint8_t update_mesh_buffers(const std::vector<Vertex>& vertices,
const std::vector<uint16_t>& indices); const std::vector<uint16_t>& indices);
uint8_t update_mesh_instances(rse::graphics::mesh::InstanceData& instance_data); uint8_t update_mesh_instances(InstanceData& instance_data);
/** /**
* @brief Record commands for given image index * @brief Record commands for given image index
* *
+1 -5
View File
@@ -1,7 +1,3 @@
#include "vulkan_commons.hpp" #include "vulkan_commons.h"
namespace rse::graphics::vulkanbase {
VulkanState g_vulkan_state; VulkanState g_vulkan_state;
}
@@ -1,5 +1,5 @@
/** /**
* @file vulkan_global.hpp * @file vulkan_global.h
* @author Piotr Krygier (piotr.krygier@meshsystems.com) * @author Piotr Krygier (piotr.krygier@meshsystems.com)
* @brief Declaration of a structure holding Vulkan variables needed by different parts of the code * @brief Declaration of a structure holding Vulkan variables needed by different parts of the code
* @version 0.1 * @version 0.1
@@ -13,25 +13,20 @@
#define RSE_VULKAN_GLOBAL_HPP #define RSE_VULKAN_GLOBAL_HPP
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#pragma GCC diagnostic ignored "-Wvolatile" #include <vk_mem_alloc.h>
#include <glm/glm.hpp>
#pragma GCC diagnostic pop
#include "vk_mem_alloc.h" #include "rse_math.h"
#define SWAP_BUFFER_COUNT 2U #define SWAP_BUFFER_COUNT 2U
namespace rse::graphics::vulkanbase
{
/** /**
* @brief Represents single vertex on the screen * @brief Represents single vertex on the screen
* *
*/ */
struct Vertex struct Vertex
{ {
glm::vec3 pos; struct vec3_t pos;
glm::vec3 color; struct vec3_t color;
static VkVertexInputBindingDescription getBindingDescription() { static VkVertexInputBindingDescription getBindingDescription() {
VkVertexInputBindingDescription bindingDescription; VkVertexInputBindingDescription bindingDescription;
@@ -75,9 +70,9 @@ struct Buffer
struct UniformBufferObject struct UniformBufferObject
{ {
alignas(16) glm::mat4 model; alignas(16) mat4_t model;
alignas(16) glm::mat4 view; alignas(16) mat4_t view;
alignas(16) glm::mat4 proj; alignas(16) mat4_t proj;
}; };
struct VulkanState struct VulkanState
@@ -105,16 +100,10 @@ struct VulkanState
extern VulkanState g_vulkan_state; extern VulkanState g_vulkan_state;
} // namespace rse::graphics::vulkanbase
namespace rse::graphics::mesh
{
struct InstanceData { struct InstanceData {
glm::vec3 pos; struct vec3_t pos;
glm::vec3 rot; struct vec3_t rot;
float scale; float scale;
}; };
} // namespace rse::graphics::mesh
#endif #endif
+2 -4
View File
@@ -1,14 +1,12 @@
#include "vulkan_descriptors.hpp" #include "vulkan_descriptors.hpp"
#include "locale_vulkan.hpp" #include "locale_vulkan.h"
#include "utilities/logger.hpp" #include "utilities/logger.hpp"
#include "vulkan_errors.hpp" #include "vulkan_errors.h"
namespace rse::graphics::vulkanbase namespace rse::graphics::vulkanbase
{ {
using namespace locale::vulkan;
VkDescriptorPool gDescriptorPool = {}; VkDescriptorPool gDescriptorPool = {};
static uint8_t createDescriptorPool(); static uint8_t createDescriptorPool();
+1 -1
View File
@@ -5,7 +5,7 @@
#include <vector> #include <vector>
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include "vulkan_commons.hpp" #include "vulkan_commons.h"
namespace rse::graphics::vulkanbase namespace rse::graphics::vulkanbase
{ {
@@ -1,5 +1,5 @@
#ifndef VULKAN_ERRORS_HPP #ifndef VULKAN_ERRORS_H
#define VULKAN_ERRORS_HPP #define VULKAN_ERRORS_H
/* Macro for checking status of function execution in initVulkan. Created to avoid writing boilerplate code */ /* Macro for checking status of function execution in initVulkan. Created to avoid writing boilerplate code */
#define STATUS_CHECK(FUNC) \ #define STATUS_CHECK(FUNC) \
+7 -9
View File
@@ -1,10 +1,10 @@
#include "vulkan_pipeline.hpp" #include "vulkan_pipeline.hpp"
#include "locale_vulkan.hpp" #include "locale_vulkan.h"
#include "utilities/file_utils.hpp" #include "utilities/file_utils.hpp"
#include "utilities/logger.hpp" #include "utilities/logger.hpp"
#include "vulkan_errors.hpp" #include "vulkan_errors.h"
#include "mesh_controller.hpp" #include "mesh_controller.h"
#include <cstdint> #include <cstdint>
#include <map> #include <map>
@@ -14,8 +14,6 @@
namespace rse::graphics::vulkanbase namespace rse::graphics::vulkanbase
{ {
using namespace locale::vulkan;
enum class ShaderStage enum class ShaderStage
{ {
VERTEX, VERTEX,
@@ -505,7 +503,7 @@ void fillVertexInputInfo(VkPipelineVertexInputStateCreateInfo* vertexInputInfo)
bindingDescriptions[0] = vertexBindingDescription; bindingDescriptions[0] = vertexBindingDescription;
bindingDescriptions[1].binding = 1; bindingDescriptions[1].binding = 1;
bindingDescriptions[1].stride = sizeof(rse::graphics::mesh::InstanceData); //TODO: change bindingDescriptions[1].stride = sizeof(InstanceData); //TODO: change
bindingDescriptions[1].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE; bindingDescriptions[1].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
auto attributeDescriptions = new VkVertexInputAttributeDescription[5]; auto attributeDescriptions = new VkVertexInputAttributeDescription[5];
@@ -514,17 +512,17 @@ void fillVertexInputInfo(VkPipelineVertexInputStateCreateInfo* vertexInputInfo)
attributeDescriptions[2].binding = 1; attributeDescriptions[2].binding = 1;
attributeDescriptions[2].location = 2; attributeDescriptions[2].location = 2;
attributeDescriptions[2].format = VK_FORMAT_R32G32B32_SFLOAT; attributeDescriptions[2].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[2].offset = offsetof(rse::graphics::mesh::InstanceData, pos); attributeDescriptions[2].offset = offsetof(InstanceData, pos);
attributeDescriptions[3].binding = 1; attributeDescriptions[3].binding = 1;
attributeDescriptions[3].location = 3; attributeDescriptions[3].location = 3;
attributeDescriptions[3].format = VK_FORMAT_R32G32B32_SFLOAT; attributeDescriptions[3].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[3].offset = offsetof(rse::graphics::mesh::InstanceData, rot); attributeDescriptions[3].offset = offsetof(InstanceData, rot);
attributeDescriptions[4].binding = 1; attributeDescriptions[4].binding = 1;
attributeDescriptions[4].location = 4; attributeDescriptions[4].location = 4;
attributeDescriptions[4].format = VK_FORMAT_R32_SFLOAT; attributeDescriptions[4].format = VK_FORMAT_R32_SFLOAT;
attributeDescriptions[4].offset = offsetof(rse::graphics::mesh::InstanceData, scale); attributeDescriptions[4].offset = offsetof(InstanceData, scale);
// ************************ // ************************
vertexInputInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; vertexInputInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
+1 -1
View File
@@ -4,7 +4,7 @@
#include <vector> #include <vector>
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include "vulkan_commons.hpp" #include "vulkan_commons.h"
namespace rse::graphics::vulkanbase namespace rse::graphics::vulkanbase
{ {
+1 -3
View File
@@ -11,15 +11,13 @@
#include "window.hpp" #include "window.hpp"
#include "locale_window.hpp" #include "locale_window.h"
#include "utilities/logger.hpp" #include "utilities/logger.hpp"
#include "vulkan_base.hpp" #include "vulkan_base.hpp"
namespace rse::graphics::window namespace rse::graphics::window
{ {
using namespace locale::window;
/* Error codes */ /* Error codes */
typedef enum { typedef enum {
WINDOW_ERROR_NO_ERROR = 0U, WINDOW_ERROR_NO_ERROR = 0U,
+4 -4
View File
@@ -3,10 +3,10 @@ find_package(Criterion)
add_executable(tests add_executable(tests
src/rse_math_tests.c) src/rse_math_tests.c)
target_include_directories(tests PRIVATE target_include_directories(tests PRIVATE
${criterion_INCLUDE_DIR}) ${criterion_INCLUDE_DIR}
${CMAKE_SOURCE_DIR})
target_link_libraries(tests PRIVATE target_link_libraries(tests PRIVATE
${criterion}) ${criterion}
rse_graphics)
+175 -4
View File
@@ -1,8 +1,179 @@
#include <stdio.h>
#include "criterion/criterion.h" #include "criterion/criterion.h"
#include "graphics/src/rse_math.h"
Test(sampe, test)
#include <stdio.h>
#include <math.h>
/*-----------------RSE MATH TEST------------------------*/
TestSuite(rse_math);
Test(rse_math, normalize)
{ {
cr_expect(strlen("Tests") == 4, "Expected \"Test\" to have lenght of 4"); float res_x = 0.8017f;
float res_y = 0.2672f;
float res_z = 0.5345f;
struct vec3_t test_vec = {3.0f, 1.0f, 2.0f};
struct vec3_t result = rse_math_normalize_vec3(&test_vec);
cr_expect_float_eq(result.x, res_x, 0.0001, "Expected %f, got %f", res_x, result.x);
cr_expect_float_eq(result.y, res_y, 0.0001, "Expected %f, got %f", res_y, result.y);
cr_expect_float_eq(result.z, res_z, 0.0001, "Expected %f, got %f", res_z, result.z);
}
Test(rse_math, cross)
{
float res_x = -3.0f;
float res_y = 6.0f;
float res_z = -3.0f;
struct vec3_t test_vec1 = {2.0f, 3.0f, 4.0f};
struct vec3_t test_vec2 = {5.0f, 6.0f, 7.0f};
struct vec3_t result = rse_math_cross_vec3(&test_vec1, &test_vec2);
cr_expect_float_eq(result.x, res_x, 0.0001, "Expected %f, got %f", res_x, result.x);
cr_expect_float_eq(result.y, res_y, 0.0001, "Expected %f, got %f", res_y, result.y);
cr_expect_float_eq(result.z, res_z, 0.0001, "Expected %f, got %f", res_z, result.z);
}
Test(rse_math, look_at)
{
struct vec3_t eye;
struct vec3_t center;
struct vec3_t up;
struct mat4_t result;
struct mat4_t expected;
eye.x = 0.0f;
eye.y = 0.0f;
eye.z = 5.0f;
center.x = 0.0f;
center.y = 0.0f;
center.z = 0.0f;
up.x = 0.0f;
up.y = 0.1f;
up.z = 0.0f;
expected.x_1 = 1.0f;
expected.y_1 = 0.0f;
expected.z_1 = 0.0f;
expected.w_1 = 0.0f;
expected.x_2 = 0.0f;
expected.y_2 = 1.0f;
expected.z_2 = 0.0f;
expected.w_2 = 0.0f;
expected.x_3 = 0.0f;
expected.y_3 = 0.0f;
expected.z_3 = 1.0f;
expected.w_3 = 0.0f;
expected.x_4 = 0.0f;
expected.y_4 = 0.0f;
expected.z_4 = -5.0f;
expected.w_4 = 1.0f;
result = rse_math_look_at(&eye, &center, &up);
cr_expect_float_eq(result.x_1, expected.x_1, 0.0001, "Expected x_1 %f, got %f", expected.x_1, result.x_1);
cr_expect_float_eq(result.y_1, expected.y_1, 0.0001, "Expected y_1 %f, got %f", expected.y_1, result.y_1);
cr_expect_float_eq(result.z_1, expected.z_1, 0.0001, "Expected z_1 %f, got %f", expected.z_1, result.z_1);
cr_expect_float_eq(result.w_1, expected.w_1, 0.0001, "Expected w_1 %f, got %f", expected.w_1, result.w_1);
cr_expect_float_eq(result.x_2, expected.x_2, 0.0001, "Expected x_2 %f, got %f", expected.x_2, result.x_2);
cr_expect_float_eq(result.y_2, expected.y_2, 0.0001, "Expected y_2 %f, got %f", expected.y_2, result.y_2);
cr_expect_float_eq(result.z_2, expected.z_2, 0.0001, "Expected z_2 %f, got %f", expected.z_2, result.z_2);
cr_expect_float_eq(result.w_2, expected.w_2, 0.0001, "Expected w_2 %f, got %f", expected.w_2, result.w_2);
cr_expect_float_eq(result.x_3, expected.x_3, 0.0001, "Expected x_3 %f, got %f", expected.x_3, result.x_3);
cr_expect_float_eq(result.y_3, expected.y_3, 0.0001, "Expected y_3 %f, got %f", expected.y_3, result.y_3);
cr_expect_float_eq(result.z_3, expected.z_3, 0.0001, "Expected z_3 %f, got %f", expected.z_3, result.z_3);
cr_expect_float_eq(result.w_3, expected.w_3, 0.0001, "Expected w_3 %f, got %f", expected.w_3, result.w_3);
cr_expect_float_eq(result.x_4, expected.x_4, 0.0001, "Expected x_4 %f, got %f", expected.x_4, result.x_4);
cr_expect_float_eq(result.y_4, expected.y_4, 0.0001, "Expected y_4 %f, got %f", expected.y_4, result.y_4);
cr_expect_float_eq(result.z_4, expected.z_4, 0.0001, "Expected z_4 %f, got %f", expected.z_4, result.z_4);
cr_expect_float_eq(result.w_4, expected.w_4, 0.0001, "Expected w_4 %f, got %f", expected.w_4, result.w_4);
}
Test(rse_math, radians)
{
float degrees;
float radians;
float expected_radians;
degrees = 45.0f;
expected_radians = 0.7853;
radians = rse_math_deg_to_radians(degrees);
cr_expect_float_eq(radians, expected_radians, 0.0001, "Expected %f, got %f", expected_radians, radians);
}
Test(rse_math, perspective)
{
float fovy;
float width;
float height;
float z_near;
float z_far;
struct mat4_t result;
struct mat4_t expected;
fovy = rse_math_deg_to_radians(45.0f);
width = 640.0f;
height = 480.0f;
z_near = 0.1f;
z_far = 20.0f;
expected.x_1 = -1.81066012;
expected.y_1 = 0;
expected.z_1 = 0;
expected.w_1 = 0;
expected.x_2 = 0;
expected.y_2 = 2.41421342;
expected.z_2 = 0;
expected.w_2 = 0;
expected.x_3 = 0;
expected.y_3 = 0;
expected.z_3 = -1.0100503;
expected.w_3 = -1;
expected.x_4 = 0;
expected.y_4 = 0;
expected.z_4 = -0.201005027;
expected.w_4 = 0;
result = rse_math_perspective(fovy, width / height, z_near, z_far);
cr_expect_float_eq(result.x_1, expected.x_1, 0.0001, "Expected x_1 %f, got %f", expected.x_1, result.x_1);
cr_expect_float_eq(result.y_1, expected.y_1, 0.0001, "Expected y_1 %f, got %f", expected.y_1, result.y_1);
cr_expect_float_eq(result.z_1, expected.z_1, 0.0001, "Expected z_1 %f, got %f", expected.z_1, result.z_1);
cr_expect_float_eq(result.w_1, expected.w_1, 0.0001, "Expected w_1 %f, got %f", expected.w_1, result.w_1);
cr_expect_float_eq(result.x_2, expected.x_2, 0.0001, "Expected x_2 %f, got %f", expected.x_2, result.x_2);
cr_expect_float_eq(result.y_2, expected.y_2, 0.0001, "Expected y_2 %f, got %f", expected.y_2, result.y_2);
cr_expect_float_eq(result.z_2, expected.z_2, 0.0001, "Expected z_2 %f, got %f", expected.z_2, result.z_2);
cr_expect_float_eq(result.w_2, expected.w_2, 0.0001, "Expected w_2 %f, got %f", expected.w_2, result.w_2);
cr_expect_float_eq(result.x_3, expected.x_3, 0.0001, "Expected x_3 %f, got %f", expected.x_3, result.x_3);
cr_expect_float_eq(result.y_3, expected.y_3, 0.0001, "Expected y_3 %f, got %f", expected.y_3, result.y_3);
cr_expect_float_eq(result.z_3, expected.z_3, 0.0001, "Expected z_3 %f, got %f", expected.z_3, result.z_3);
cr_expect_float_eq(result.w_3, expected.w_3, 0.0001, "Expected w_3 %f, got %f", expected.w_3, result.w_3);
cr_expect_float_eq(result.x_4, expected.x_4, 0.0001, "Expected x_4 %f, got %f", expected.x_4, result.x_4);
cr_expect_float_eq(result.y_4, expected.y_4, 0.0001, "Expected y_4 %f, got %f", expected.y_4, result.y_4);
cr_expect_float_eq(result.z_4, expected.z_4, 0.0001, "Expected z_4 %f, got %f", expected.z_4, result.z_4);
cr_expect_float_eq(result.w_4, expected.w_4, 0.0001, "Expected w_4 %f, got %f", expected.w_4, result.w_4);
} }
@@ -1,5 +1,5 @@
/** /**
* @file localization.hpp * @file localization.h
* @author Piotr Krygier (everyonencancode@gmail.com) * @author Piotr Krygier (everyonencancode@gmail.com)
* @brief Simple localization header * @brief Simple localization header
* @version 0.1 * @version 0.1
@@ -9,11 +9,11 @@
* *
*/ */
#pragma once #ifndef LOCALIZATION_H
#define SELECTED_LANGUAGE rse::utils::locale::EN_US #define LOCALIZATION_H
namespace rse::utils::locale #define SELECTED_LANGUAGE EN_US
{ #define MAX_MESSAGE_LENGHT 128
/** /**
* @brief Available languages * @brief Available languages
@@ -25,4 +25,4 @@ enum Languages_t
LAST_LANGUAGE LAST_LANGUAGE
}; };
} // namespace rse::locale #endif /* LOCALIZATION_H */