diff options
Diffstat (limited to 'src/GFX')
| -rw-r--r-- | src/GFX/Binder.cpp | 20 | ||||
| -rw-r--r-- | src/GFX/Binder.hpp | 26 | ||||
| -rw-r--r-- | src/GFX/Image/PPMParser.cpp | 24 | ||||
| -rw-r--r-- | src/GFX/Image/PPMParser.hpp | 18 | ||||
| -rw-r--r-- | src/GFX/Image/RawImage.cpp | 14 | ||||
| -rw-r--r-- | src/GFX/Image/RawImage.hpp | 17 | ||||
| -rw-r--r-- | src/GFX/Mesh.cpp | 2 | ||||
| -rw-r--r-- | src/GFX/Mesh.hpp | 22 | ||||
| -rw-r--r-- | src/GFX/Mouse.cpp | 4 | ||||
| -rw-r--r-- | src/GFX/Mouse.hpp | 6 | ||||
| -rw-r--r-- | src/GFX/Shading/Program.cpp | 6 | ||||
| -rw-r--r-- | src/GFX/Shading/Program.hpp | 4 | ||||
| -rw-r--r-- | src/GFX/Shading/Shader.cpp | 6 | ||||
| -rw-r--r-- | src/GFX/Shading/Shader.hpp | 8 | ||||
| -rw-r--r-- | src/GFX/Shading/Uniform.cpp | 4 | ||||
| -rw-r--r-- | src/GFX/Shading/Uniform.hpp | 10 | ||||
| -rw-r--r-- | src/GFX/Texture.hpp | 2 | ||||
| -rw-r--r-- | src/GFX/Window.cpp | 11 | ||||
| -rw-r--r-- | src/GFX/Window.hpp | 14 |
19 files changed, 109 insertions, 109 deletions
diff --git a/src/GFX/Binder.cpp b/src/GFX/Binder.cpp index e8fc559..905ba24 100644 --- a/src/GFX/Binder.cpp +++ b/src/GFX/Binder.cpp @@ -10,7 +10,7 @@ BindableMesh Binder::load(const Mesh& mesh) { store_indices(mesh.indices().data(), mesh.indices().size()); } - int attribute_index = 0; + Int attribute_index = 0; for (const auto& attribute : mesh.attributes()) { store_in_attribute_list( attribute_index++, @@ -25,7 +25,7 @@ BindableMesh Binder::load(const Mesh& mesh) { return {vao, mesh.indices().size(), mesh.attributes().size()}; } -uint32_t Binder::create_vao() { +U32 Binder::create_vao() { GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); @@ -37,17 +37,17 @@ void Binder::unbind_vao() { glBindVertexArray(0); } -void Binder::store_indices(const uint32_t* indices, size_t indices_size) { +void Binder::store_indices(const U32* indices, USize indices_size) { GLuint ebo; glGenBuffers(1, &ebo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_size * sizeof(float), indices, GL_STATIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_size * sizeof(U32), indices, GL_STATIC_DRAW); } -void Binder::store_in_attribute_list(uint32_t attribute, int attribute_size, int type_size, const void* data, long data_size) { - assert(type_size == sizeof(float)); +void Binder::store_in_attribute_list(U32 attribute, Int attribute_size, Int type_size, const void* data, long data_size) { + assert(type_size == sizeof(F32)); GLuint vbo; glGenBuffers(1, &vbo); @@ -60,23 +60,23 @@ void Binder::store_in_attribute_list(uint32_t attribute, int attribute_size, int void BindableMesh::bind() const { glBindVertexArray(m_vao); - for (int i = 0; i < m_attribute_count; i++) { + for (Int i = 0; i < m_attribute_count; i++) { glEnableVertexAttribArray(i); } } void BindableMesh::unbind() const { glBindVertexArray(0); - for (int i = 0; i < m_attribute_count; i++) { + for (Int i = 0; i < m_attribute_count; i++) { glDisableVertexAttribArray(i); } } -bool BindableMesh::has_indices() const { +Bool BindableMesh::has_indices() const { return m_has_indices; } -size_t BindableMesh::size() const { +USize BindableMesh::size() const { return m_vertex_count; } diff --git a/src/GFX/Binder.hpp b/src/GFX/Binder.hpp index 773518d..6103e09 100644 --- a/src/GFX/Binder.hpp +++ b/src/GFX/Binder.hpp @@ -1,6 +1,6 @@ #pragma once -#include <cstdint> +#include "../Common/Sizes.hpp" #include "Mesh.hpp" namespace MC::GFX { @@ -10,23 +10,23 @@ public: void bind() const; void unbind() const; - bool has_indices() const; - size_t size() const; + Bool has_indices() const; + USize size() const; private: BindableMesh( - uint32_t vao, - size_t vertex_count, - size_t attribute_count + U32 vao, + USize vertex_count, + USize attribute_count ) : m_vao(vao), m_vertex_count(vertex_count), m_has_indices(vertex_count > 0), m_attribute_count(attribute_count) {} - uint32_t m_vao; - size_t m_vertex_count; - bool m_has_indices; - size_t m_attribute_count; + U32 m_vao; + USize m_vertex_count; + Bool m_has_indices; + USize m_attribute_count; friend class Binder; }; @@ -38,11 +38,11 @@ public: static BindableMesh load(const Mesh& mesh); private: - static uint32_t create_vao(); + static U32 create_vao(); static void unbind_vao(); - static void store_in_attribute_list(uint32_t attribute, int attribute_size, int type_size, const void* data, long data_size); - static void store_indices(const uint32_t* indices, size_t indices_size); + static void store_in_attribute_list(U32 attribute, Int attribute_size, Int type_size, const void* data, long data_size); + static void store_indices(const U32* indices, USize indices_size); }; } \ No newline at end of file diff --git a/src/GFX/Image/PPMParser.cpp b/src/GFX/Image/PPMParser.cpp index 1f62871..3c95bba 100644 --- a/src/GFX/Image/PPMParser.cpp +++ b/src/GFX/Image/PPMParser.cpp @@ -18,7 +18,7 @@ RawImage PPMParser::parse() { auto pixel_count = header.width * header.height; RawImage image(header.width, header.height); - for (uint64_t pixel_index = 0; pixel_index < pixel_count; pixel_index++) { + for (U64 pixel_index = 0; pixel_index < pixel_count; pixel_index++) { RawImage::Pixel pixel = parse_pixel(header.max_color); image.add(pixel); } @@ -57,7 +57,7 @@ PPMParser::PPMHeader PPMParser::parse_header() { return header; } -RawImage::Pixel PPMParser::parse_pixel(uint8_t max_color) { +RawImage::Pixel PPMParser::parse_pixel(U8 max_color) { auto r_sample = parse_sample(); auto g_sample = parse_sample(); auto b_sample = parse_sample(); @@ -66,7 +66,7 @@ RawImage::Pixel PPMParser::parse_pixel(uint8_t max_color) { throw std::runtime_error("Sample can not be greater than Maxval."); } - auto map_to_range = [=](uint64_t s) -> uint8_t { return s * 255 / max_color; }; + auto map_to_range = [=](U64 s) -> U8 { return s * 255 / max_color; }; RawImage::Pixel p{ map_to_range(r_sample), @@ -82,23 +82,23 @@ RawImage::Pixel PPMParser::parse_pixel(uint8_t max_color) { return p; } -uint64_t PPMParser::parse_sample() { +U64 PPMParser::parse_sample() { skip_whitespace(); auto sample = chomp_number(); skip_whitespace(); return sample; } -uint64_t PPMParser::chomp_number() { +U64 PPMParser::chomp_number() { auto raw = chomp_part(); - uint64_t number = 0; - for (uint8_t digit_ascii : raw) { + U64 number = 0; + for (U8 digit_ascii : raw) { if (digit_ascii < '0' || digit_ascii > '9') { throw std::runtime_error("Number contains non ASCII digits."); } - uint8_t digit = digit_ascii - '0'; + U8 digit = digit_ascii - '0'; number *= 10; number += digit; @@ -108,7 +108,7 @@ uint64_t PPMParser::chomp_number() { } std::string_view PPMParser::chomp_part() { - uint64_t length = 0; + U64 length = 0; while (!is_eof()) { auto c = m_source[m_cursor + length]; @@ -127,7 +127,7 @@ std::string_view PPMParser::chomp_part() { void PPMParser::skip_whitespace() { while (!is_eof()) { - uint8_t c = m_source[m_cursor]; + U8 c = m_source[m_cursor]; if (c == '#') { skip_comment(); continue; @@ -142,7 +142,7 @@ void PPMParser::skip_whitespace() { } void PPMParser::skip_comment() { - uint8_t c = m_source[m_cursor]; + U8 c = m_source[m_cursor]; if (c != '#') { return; } @@ -152,7 +152,7 @@ void PPMParser::skip_comment() { } } -bool PPMParser::is_eof() const { +Bool PPMParser::is_eof() const { return m_cursor >= m_source.size(); } diff --git a/src/GFX/Image/PPMParser.hpp b/src/GFX/Image/PPMParser.hpp index a7e9b41..77f1cec 100644 --- a/src/GFX/Image/PPMParser.hpp +++ b/src/GFX/Image/PPMParser.hpp @@ -1,6 +1,6 @@ #pragma once -#include <cstdint> +#include "../../Common/Sizes.hpp" #include <string_view> #include "RawImage.hpp" @@ -20,27 +20,27 @@ private: struct PPMHeader { PPMType type; - uint32_t width; - uint32_t height; - uint8_t max_color; + U32 width; + U32 height; + U8 max_color; }; PPMHeader parse_header(); - RawImage::Pixel parse_pixel(uint8_t max_color); - uint64_t parse_sample(); + RawImage::Pixel parse_pixel(U8 max_color); + U64 parse_sample(); - uint64_t chomp_number(); + U64 chomp_number(); std::string_view chomp_part(); void skip_whitespace(); void skip_comment(); - bool is_eof() const; + Bool is_eof() const; static constexpr RawImage::Pixel alpha_color{192, 0, 255}; std::string_view m_source; - uint64_t m_cursor = 0; + U64 m_cursor = 0; }; } diff --git a/src/GFX/Image/RawImage.cpp b/src/GFX/Image/RawImage.cpp index 0bd2947..9f156b8 100644 --- a/src/GFX/Image/RawImage.cpp +++ b/src/GFX/Image/RawImage.cpp @@ -7,30 +7,30 @@ void RawImage::add(Pixel pixel) { m_pixels.push_back(pixel); } -size_t RawImage::size() const { +USize RawImage::size() const { return m_pixels.size(); } -uint8_t* RawImage::raw() const { - return (uint8_t*)m_pixels.data(); +U8* RawImage::raw() const { + return (U8*)m_pixels.data(); } -uint32_t RawImage::width() const { +U32 RawImage::width() const { return m_width; } -uint32_t RawImage::height() const { +U32 RawImage::height() const { return m_height; } std::string RawImage::string() const { std::stringstream str{}; - bool comma = false; + Bool comma = false; str << "["; for (const auto [r, g, b, a] : m_pixels) { if (comma) { str << ", "; } - str << "{r=" << (uint)r << ", g=" << (uint)g << ", b=" << (uint)b << ", a=" << (uint)a << "}"; + str << "{r=" << (UInt)r << ", g=" << (UInt)g << ", b=" << (UInt)b << ", a=" << (UInt)a << "}"; comma = true; } str << "]"; diff --git a/src/GFX/Image/RawImage.hpp b/src/GFX/Image/RawImage.hpp index 809ddd9..5a95dad 100644 --- a/src/GFX/Image/RawImage.hpp +++ b/src/GFX/Image/RawImage.hpp @@ -1,7 +1,6 @@ #pragma once -#include <cstdint> -#include <cstddef> +#include "../../Common/Sizes.hpp" #include <string> #include <vector> @@ -11,26 +10,26 @@ class RawImage { public: RawImage() : m_width(0), m_height(0) {} - RawImage(uint32_t width, uint32_t height) : m_width(width), m_height(height) { + RawImage(U32 width, U32 height) : m_width(width), m_height(height) { m_pixels.reserve(width * height); } struct Pixel { - uint8_t r, g, b, a; + U8 r, g, b, a; }; void add(Pixel pixel); - size_t size() const; - uint8_t* raw() const; + USize size() const; + U8* raw() const; - uint32_t width() const; - uint32_t height() const; + U32 width() const; + U32 height() const; std::string string() const; private: std::vector<Pixel> m_pixels; - uint32_t m_width, m_height; + U32 m_width, m_height; }; } diff --git a/src/GFX/Mesh.cpp b/src/GFX/Mesh.cpp index 1869622..c45b5c9 100644 --- a/src/GFX/Mesh.cpp +++ b/src/GFX/Mesh.cpp @@ -2,7 +2,7 @@ namespace MC::GFX { -const std::vector<uint32_t>& Mesh::indices() const { +const std::vector<U32>& Mesh::indices() const { return m_indices; } diff --git a/src/GFX/Mesh.hpp b/src/GFX/Mesh.hpp index ec21e53..1c39941 100644 --- a/src/GFX/Mesh.hpp +++ b/src/GFX/Mesh.hpp @@ -2,7 +2,7 @@ #include <utility> #include <vector> -#include <cstdint> +#include "../Common/Sizes.hpp" #include "../Math/Common.hpp" namespace MC::GFX { @@ -10,7 +10,7 @@ namespace MC::GFX { class Mesh { public: struct Attribute { - template<size_t S = 3, typename T = float> + template<uint S = 3, typename T = float> Attribute( std::vector<Vector<S, T>> v ) : data_size(v.size()), @@ -26,21 +26,21 @@ public: attribute_size(other.attribute_size), type_size(other.type_size) {} - static void* copy(void* ptr, uint32_t size) { - auto* buffer = new uint8_t[size]; - std::copy_n((uint8_t*)ptr, size, buffer); + static void* copy(void* ptr, U32 size) { + auto* buffer = new U8[size]; + std::copy_n((U8*)ptr, size, buffer); return buffer; } void* data; - long data_size; - int attribute_size; - int type_size; + USize data_size; + USize attribute_size; + USize type_size; }; Mesh( std::vector<Attribute> attributes, - std::vector<uint32_t> indices + std::vector<U32> indices ) : m_attributes(std::move(attributes)), m_indices(std::move(indices)) {} @@ -48,12 +48,12 @@ public: std::vector<Attribute> attributes ) : m_attributes(std::move(attributes)) {} - const std::vector<uint32_t>& indices() const; + const std::vector<U32>& indices() const; const std::vector<Attribute>& attributes() const; private: std::vector<Attribute> m_attributes; - std::vector<uint32_t> m_indices; + std::vector<U32> m_indices; }; } \ No newline at end of file diff --git a/src/GFX/Mouse.cpp b/src/GFX/Mouse.cpp index 5cd2698..49f6972 100644 --- a/src/GFX/Mouse.cpp +++ b/src/GFX/Mouse.cpp @@ -3,7 +3,7 @@ namespace MC::GFX { Vector<2> Mouse::update(GLFWwindow* window) { - double x, y; + Real x, y; glfwGetCursorPos(window, &x, &y); if (m_first_event) { @@ -13,7 +13,7 @@ Vector<2> Mouse::update(GLFWwindow* window) { m_first_event = false; } - Vector<2> movement{static_cast<float>(x) - m_last_x, static_cast<float>(y) - m_last_y}; + Vector<2> movement{static_cast<Real>(x) - m_last_x, static_cast<Real>(y) - m_last_y}; m_last_x = x; m_last_y = y; diff --git a/src/GFX/Mouse.hpp b/src/GFX/Mouse.hpp index 1e2111e..ad940d4 100644 --- a/src/GFX/Mouse.hpp +++ b/src/GFX/Mouse.hpp @@ -11,10 +11,10 @@ public: Vector<2> update(GLFWwindow* window); private: - bool m_first_event = true; + Bool m_first_event = true; - float m_last_x = 0.0f; - float m_last_y = 0.0f; + Real m_last_x = 0.0f; + Real m_last_y = 0.0f; }; } \ No newline at end of file diff --git a/src/GFX/Shading/Program.cpp b/src/GFX/Shading/Program.cpp index 6efb30b..ff10012 100644 --- a/src/GFX/Shading/Program.cpp +++ b/src/GFX/Shading/Program.cpp @@ -18,7 +18,7 @@ Program::Program(Shader vertex, Shader fragment) { GLint success; glGetProgramiv(m_program, GL_LINK_STATUS, &success); if(!success) { - char message[512] = {}; + Char message[512] = {}; glGetProgramInfoLog(m_program, 512, nullptr, message); throw std::runtime_error(message); @@ -36,10 +36,10 @@ void Program::unbind() const { Uniform Program::uniform(const std::string& name) const { auto index = glGetUniformLocation(m_program, name.c_str()); - return {name, static_cast<uint32_t>(index)}; + return {name, static_cast<U32>(index)}; } -uint32_t Program::get() const { +U32 Program::get() const { return m_program; } diff --git a/src/GFX/Shading/Program.hpp b/src/GFX/Shading/Program.hpp index 8a50617..2f48698 100644 --- a/src/GFX/Shading/Program.hpp +++ b/src/GFX/Shading/Program.hpp @@ -10,7 +10,7 @@ class Program { public: Program(Shader vertex, Shader fragment); - uint32_t get() const; + U32 get() const; Uniform uniform(const std::string& name) const; @@ -18,7 +18,7 @@ public: void unbind() const; private: - uint32_t m_program; + U32 m_program; }; } \ No newline at end of file diff --git a/src/GFX/Shading/Shader.cpp b/src/GFX/Shading/Shader.cpp index 6dfac34..54f8ad1 100644 --- a/src/GFX/Shading/Shader.cpp +++ b/src/GFX/Shading/Shader.cpp @@ -4,8 +4,8 @@ namespace MC::GFX::Shading { -Shader::Shader(Type type, const char* source) { - uint32_t gl_type = 0; +Shader::Shader(Type type, const Char* source) { + U32 gl_type = 0; switch (type) { case Type::Vertex: gl_type = GL_VERTEX_SHADER; @@ -23,7 +23,7 @@ Shader::Shader(Type type, const char* source) { GLint success; glGetShaderiv(m_shader, GL_COMPILE_STATUS, &success); if(!success) { - char message[512] = {}; + Char message[512] = {}; glGetShaderInfoLog(m_shader, 512, nullptr, message); throw std::runtime_error(message); diff --git a/src/GFX/Shading/Shader.hpp b/src/GFX/Shading/Shader.hpp index 15450cb..21fd899 100644 --- a/src/GFX/Shading/Shader.hpp +++ b/src/GFX/Shading/Shader.hpp @@ -1,6 +1,6 @@ #pragma once -#include <cstdint> +#include "../../Common/Sizes.hpp" #include "../../Assets.hpp" namespace MC::GFX::Shading { @@ -13,9 +13,9 @@ public: Fragment, }; - Shader(Type type, const char* source); + Shader(Type type, const Char* source); - uint32_t get() const { + U32 get() const { return m_shader; } @@ -28,7 +28,7 @@ public: } private: - uint32_t m_shader; + U32 m_shader; }; } \ No newline at end of file diff --git a/src/GFX/Shading/Uniform.cpp b/src/GFX/Shading/Uniform.cpp index 71786ef..a9c9854 100644 --- a/src/GFX/Shading/Uniform.cpp +++ b/src/GFX/Shading/Uniform.cpp @@ -3,11 +3,11 @@ namespace MC::GFX::Shading { -void Uniform::set(const Matrix<4, 4>& value) const { +void Uniform::set(const Matrix<4, 4, F32>& value) const { glUniformMatrix4fv(m_index, 1, GL_TRUE, value.elements); } -void Uniform::set(const Vector<3>& value) const { +void Uniform::set(const Vector<3, F32>& value) const { glUniform3f(m_index, value.x(), value.y(), value.z()); } diff --git a/src/GFX/Shading/Uniform.hpp b/src/GFX/Shading/Uniform.hpp index a270e65..c8ab6fe 100644 --- a/src/GFX/Shading/Uniform.hpp +++ b/src/GFX/Shading/Uniform.hpp @@ -1,22 +1,22 @@ #pragma once -#include <cstdint> #include <string> +#include "../../Common/Sizes.hpp" #include "../../Math/Common.hpp" namespace MC::GFX::Shading { class Uniform { public: - Uniform(std::string name, uint32_t index) + Uniform(std::string name, U32 index) : m_name(std::move(name)), m_index(index) {} - void set(const Matrix<4, 4>& value) const; - void set(const Vector<3>& value) const; + void set(const Matrix<4, 4, F32>& value) const; + void set(const Vector<3, F32>& value) const; private: std::string m_name; - uint32_t m_index; + U32 m_index; }; } diff --git a/src/GFX/Texture.hpp b/src/GFX/Texture.hpp index 2981b2c..11fd430 100644 --- a/src/GFX/Texture.hpp +++ b/src/GFX/Texture.hpp @@ -11,7 +11,7 @@ public: void bind() const; void unbind() const; private: - uint32_t m_texture = 0; + U32 m_texture = 0; }; } \ No newline at end of file diff --git a/src/GFX/Window.cpp b/src/GFX/Window.cpp index ea1fde4..bbe2ba7 100644 --- a/src/GFX/Window.cpp +++ b/src/GFX/Window.cpp @@ -1,9 +1,10 @@ #include <stdexcept> +#include "../Common/Sizes.hpp" #include "Window.hpp" namespace MC::GFX { -Window::Window(const char *title, uint32_t width, uint32_t height) { +Window::Window(const Char* title, U32 width, U32 height) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); @@ -23,7 +24,7 @@ Window::~Window() { glfwDestroyWindow(m_window); } -bool Window::should_close() const { +Bool Window::should_close() const { return glfwWindowShouldClose(m_window); } @@ -39,11 +40,11 @@ Vector<2> Window::mouse_delta() { return m_mouse.update(m_window); } -bool Window::key(int key, int type) const { +Bool Window::key(I32 key, I32 type) const { return glfwGetKey(m_window, key) == type; } -bool Window::mouse(int key, int type) const { +Bool Window::mouse(I32 key, I32 type) const { return glfwGetMouseButton(m_window, key) == type; } @@ -52,7 +53,7 @@ void Window::start_frame() { glfwPollEvents(); } -void Window::on_size_change(void (callback)(GLFWwindow*, int, int)) { +void Window::on_size_change(void (callback)(GLFWwindow*, I32, I32)) { glfwSetFramebufferSizeCallback(m_window, callback); } diff --git a/src/GFX/Window.hpp b/src/GFX/Window.hpp index 966925c..ac0efd2 100644 --- a/src/GFX/Window.hpp +++ b/src/GFX/Window.hpp @@ -1,28 +1,28 @@ #pragma once -#include <cstdint> -#include <GLFW/glfw3.h> +#include "../Common/Sizes.hpp" #include "../Math/Vector.hpp" +#include <GLFW/glfw3.h> #include "Mouse.hpp" namespace MC::GFX { class Window { public: - Window(const char* title, uint32_t width, uint32_t height); + Window(const Char* title, U32 width, U32 height); ~Window(); GLFWwindow* get() const; - void on_size_change(void (* callback)(GLFWwindow*, int, int)); + void on_size_change(void (* callback)(GLFWwindow*, I32, I32)); void close(); void start_frame(); Vector<2> mouse_delta(); - bool key(int key, int type) const; - bool mouse(int key, int type) const; - bool should_close() const; + Bool key(I32 key, I32 type) const; + Bool mouse(I32 key, I32 type) const; + Bool should_close() const; private: GLFWwindow* m_window; Mouse m_mouse; |
