diff --git a/include/config.hpp b/include/config.hpp index 154e5e6..c97100d 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -45,42 +45,64 @@ #ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT + #define OUR_DICK_DEBUG_NULL_STATEMENT do{;}while(0) #include #include "util/source_location.hpp" - #define debug_print_impl(loc, ...) do{ std::fprintf(stderr, "%s:%s:%d: ", loc.file_name(), loc.function_name(), loc.line()); std::fprintf(stderr, __VA_ARGS__); }while(0) + #define debug_print_impl(location, ...) do{ auto loc = location; std::fprintf(stderr, "%s:%s:%d: ", loc.file_name(), loc.function_name(), loc.line()); std::fprintf(stderr, __VA_ARGS__); }while(0) #define debug_print(...) debug_print_impl(util::source_location::current(), __VA_ARGS__) - #ifdef OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT - #define debug_print_verbose(...) debug_print(__VA_ARGS__) - #else - #define debug_print_verbose(...) - #endif - #ifdef OUR_DICK_ENABLE_COLOR_DEBUG #define OUR_DICK_DEBUG_PRINT_RED "\033[38;5;9m" #define OUR_DICK_DEBUG_PRINT_YELLOW "\033[38;5;11m" #define OUR_DICK_DEBUG_PRINT_GREEN "\033[38;5;2m" + #define OUR_DICK_DEBUG_PRINT_BLUE "\033[38;5;12m" #define OUR_DICK_DEBUG_PRINT_CLEAR "\033[0m" #define debug_print_color_base(color, ...) do{ std::fprintf(stderr, color); debug_print(__VA_ARGS__); std::fprintf(stderr, OUR_DICK_DEBUG_PRINT_CLEAR); }while(0) #define debug_print_warn(...) debug_print_color_base(OUR_DICK_DEBUG_PRINT_YELLOW, __VA_ARGS__) #define debug_print_error(...) debug_print_color_base(OUR_DICK_DEBUG_PRINT_RED, __VA_ARGS__) #define debug_print_succ(...) debug_print_color_base(OUR_DICK_DEBUG_PRINT_GREEN, __VA_ARGS__) + #define debug_print_info(...) debug_print_color_base(OUR_DICK_DEBUG_PRINT_BLUE, __VA_ARGS__) #else #define debug_print_error(...) debug_print(__VA_ARGS__) #define debug_print_warn(...) debug_print(__VA_ARGS__) #define debug_print_succ(...) debug_print(__VA_ARGS__) + #define debug_print_info(...) debug_print(__VA_ARGS__) + #endif + + #ifdef OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT + #define debug_print_verbose(...) debug_print(__VA_ARGS__) + #define debug_print_verbose_warn(...) debug_print_warn(__VA_ARGS__) + #define debug_print_verbose_error(...) debug_print_error(__VA_ARGS__) + #define debug_print_verbose_succ(...) debug_print_succ(__VA_ARGS__) + #define debug_print_verbose_info(...) debug_print_info(__VA_ARGS__) + #else + #define debug_print_verbose(...) OUR_DICK_DEBUG_NULL_STATEMENT + #define debug_print_verbose_warn(...) OUR_DICK_DEBUG_NULL_STATEMENT + #define debug_print_verbose_error(...) OUR_DICK_DEBUG_NULL_STATEMENT + #define debug_print_verbose_succ(...) OUR_DICK_DEBUG_NULL_STATEMENT + #define debug_print_verbose_info(...) OUR_DICK_DEBUG_NULL_STATEMENT #endif #else - #define OUR_DICK_DEBUG_NULL_STATEMENT #define debug_print(...) OUR_DICK_DEBUG_NULL_STATEMENT #define debug_print_error(...) OUR_DICK_DEBUG_NULL_STATEMENT #define debug_print_warn(...) OUR_DICK_DEBUG_NULL_STATEMENT #define debug_print_succ(...) OUR_DICK_DEBUG_NULL_STATEMENT + #define debug_print_info(...) OUR_DICK_DEBUG_NULL_STATEMENT #define debug_print_verbose(...) OUR_DICK_DEBUG_NULL_STATEMENT + #define debug_print_verbose_warn(...) OUR_DICK_DEBUG_NULL_STATEMENT + #define debug_print_verbose_error(...) OUR_DICK_DEBUG_NULL_STATEMENT + #define debug_print_verbose_succ(...) OUR_DICK_DEBUG_NULL_STATEMENT + #define debug_print_verbose_info(...) OUR_DICK_DEBUG_NULL_STATEMENT #endif +#ifdef OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT + #include +#endif + +#include "util/demangle.hpp" + #endif diff --git a/include/egn/game.hpp b/include/egn/game.hpp index 914dfb0..8655d13 100644 --- a/include/egn/game.hpp +++ b/include/egn/game.hpp @@ -24,6 +24,7 @@ #include "gfx/ogl/window.hpp" #include "input.hpp" #include "math/vec.hpp" +#include "wip/renderer.hpp" #include @@ -33,6 +34,7 @@ namespace egn{ { protected: gfx::ogl::window m_window; + wip::gfx::renderer m_renderer; game_state_manager m_states_manager; std::queue m_event_queue; double m_last_time; @@ -52,8 +54,8 @@ namespace egn{ void on_notify(const game_state_event& e)override; - gfx::resource_manager& gfx_resource_manager(void); - const gfx::resource_manager& gfx_resource_manager(void)const; + wip::gfx::renderer& renderer(void); + const wip::gfx::renderer& renderer(void)const; void push_state(std::unique_ptr&&); void pop_state(void); diff --git a/include/egn/game_state.hpp b/include/egn/game_state.hpp index 71808ce..1937e2b 100644 --- a/include/egn/game_state.hpp +++ b/include/egn/game_state.hpp @@ -22,6 +22,8 @@ #include "observable.hpp" #include "input.hpp" +#include "wip/renderer.hpp" + #include #include #include @@ -71,6 +73,9 @@ namespace egn{ game_state_iface& operator=(const game_state_iface&) = default; game_state_iface& operator=(game_state_iface&&) = default; + wip::gfx::renderer& renderer(void); + const wip::gfx::renderer& renderer(void)const; + public: virtual ~game_state_iface(void) = default; diff --git a/include/gfx/ogl/fbo.hpp b/include/gfx/ogl/fbo.hpp index 4ecfa8e..4f979d8 100644 --- a/include/gfx/ogl/fbo.hpp +++ b/include/gfx/ogl/fbo.hpp @@ -27,39 +27,51 @@ namespace gfx::ogl{ + //Class representing a framebuffer object class fbo { private: GLuint m_buffer; - math::vec4f m_vp_coords; + math::vec4f m_vp_coords; //Opengl doesn't associate viewports with framebuffers, so i do public: + //Construct an object representing the default 'root' framebuffer fbo(void); + + //build a framebuffer object with given attachments of textures or render buffers template explicit fbo(Args&&... args); explicit fbo(util::no_initialize_t); - fbo(const fbo&) = delete; + fbo(const fbo&) = delete; //TODO fbo(fbo&& f); ~fbo(void); fbo& operator=(const fbo&) = delete; fbo& operator=(fbo&& f); + //Direct access to opengl handle GLuint raw(void)const; + //Remove attached textures or renderbuffers bool detach(GLenum point); + //Add a new texture or renderbuffer attachment bool attach(const texture& tex, GLenum point); bool attach(const rbo& r, GLenum point); + //Clear individual fields void clear_color_buffer(const math::vec4f& color = {0.0f, 0.0f, 0.0f, 1.0f}); void clear_depth_buffer(GLfloat value = 1.0f); void clear_stencil_buffer(GLint value = 0); + //Clear fields as by glClear void clear(GLbitfield mask); + //Assign this framebuffer's viewport void set_viewport(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); + //Activate this framebuffer's viewport. Calls glViewport void apply_viewport(void)const; const math::vec4f& get_viewport(void)const; + //Set this as the active framebuffer bool bind(void)const; private: template diff --git a/include/gfx/ogl/rbo.hpp b/include/gfx/ogl/rbo.hpp index 75f2ed7..435ebb3 100644 --- a/include/gfx/ogl/rbo.hpp +++ b/include/gfx/ogl/rbo.hpp @@ -23,6 +23,7 @@ namespace gfx::ogl{ + //Class representing a renderbuffer object class rbo { private: @@ -41,9 +42,12 @@ namespace gfx::ogl{ rbo& operator=(const rbo& r) = delete; rbo& operator=(rbo&& r); + //Raw access to opengl handle GLuint raw(void)const; + //Set this as the active renderbuffer void bind(void)const; + //Reset to default renderbuffer binding void unbind(void)const; void resize(GLsizei w, GLsizei h); diff --git a/include/gfx/ogl/shader_program.hpp b/include/gfx/ogl/shader_program.hpp index a89c625..e1265e4 100644 --- a/include/gfx/ogl/shader_program.hpp +++ b/include/gfx/ogl/shader_program.hpp @@ -117,7 +117,6 @@ namespace gfx::ogl{ //Texture void set(const texture&, GLuint tex_unit = 0); void set(const texture_array& t, GLuint tex_unit = 0); - void set(const weak_texture&, GLuint tex_unit = 0); //Float vectors void set(const vec2f&); diff --git a/include/gfx/ogl/texture.hpp b/include/gfx/ogl/texture.hpp index a7d03f4..2e91de6 100644 --- a/include/gfx/ogl/texture.hpp +++ b/include/gfx/ogl/texture.hpp @@ -25,31 +25,6 @@ namespace gfx::ogl{ - class texture; - - class weak_texture - { - private: - GLuint m_texture; - - public: - weak_texture(GLuint tex); - weak_texture(const texture& tex); - weak_texture(const weak_texture&) = default; - weak_texture(weak_texture&&) = default; - ~weak_texture(void) = default; - - weak_texture& operator=(const weak_texture&) = default; - weak_texture& operator=(weak_texture&&) = default; - - GLuint raw(void)const; - GLsizei get_width(void)const; - GLsizei get_height(void)const; - - void bind(GLuint target = GL_TEXTURE_2D)const; - void bind_unit(GLuint tunit)const; - }; - //class representing an opengl 2D texture class texture_base { @@ -153,14 +128,13 @@ namespace gfx::ogl{ //bind to given texture unit and load into given program uniform location void bind_unit(GLuint tunit)const; - weak_texture create_handle(void)const; - private: bool create_texture_storage_(void); }; class texture_array; + //Represents a single layer of a texture_array class texture_slice { private: diff --git a/include/gfx/ogl/ubo.hpp b/include/gfx/ogl/ubo.hpp index e0569a5..e90ca50 100644 --- a/include/gfx/ogl/ubo.hpp +++ b/include/gfx/ogl/ubo.hpp @@ -89,6 +89,8 @@ namespace gfx::ogl{ } + //Class for a uniform buffer object + //automatically sets alignments for std140 uniform blocks template class ubo { @@ -125,12 +127,14 @@ namespace gfx::ogl{ template void set(T&& t); + //Direct access to opengl handle GLuint raw(void)const; size_t get_size(void)const; size_t get_cap(void)const; buffer::usage get_usage(void)const; + //Bind to uniform block binding location void bind(size_t index)const; private: template diff --git a/include/gfx/ogl/ubo.tpp b/include/gfx/ogl/ubo.tpp index aa0a4d1..2536447 100644 --- a/include/gfx/ogl/ubo.tpp +++ b/include/gfx/ogl/ubo.tpp @@ -25,6 +25,8 @@ #include #include //memcpy, memset +#include "config.hpp" + namespace gfx::ogl{ template @@ -107,12 +109,14 @@ namespace gfx::ogl{ template void ubo::buffer(const void* data, size_t datasize, size_t start){ + debug_print_warn("Manually editing values of ubo!\n"); if(start > get_size()) return; glNamedBufferSubData(m_buffer, start, std::min(datasize, get_size() - start), data); } template void ubo::initialize(unsigned char value){ + debug_print_warn("Manually editing values of ubo!\n"); const size_t size = get_size(); auto m = map(buffer::maptype::WRITE); if(!m){ diff --git a/include/gfx/ogl/window.hpp b/include/gfx/ogl/window.hpp index acd2750..ceb4aac 100644 --- a/include/gfx/ogl/window.hpp +++ b/include/gfx/ogl/window.hpp @@ -23,8 +23,6 @@ #include "../init.hpp" #include "math/math.hpp" #include "util/init_constants.hpp" -#include "fbo.hpp" -#include "../resource_manager.hpp" namespace gfx::ogl{ @@ -45,8 +43,6 @@ namespace gfx::ogl{ private: GLFWwindow* m_window = nullptr; glfw_system m_glfw_handle; - fbo m_root_fbo{util::no_initialize}; - resource_manager m_resources; char* m_title = nullptr; int m_antialias_level = 0; int m_refresh_rate = GLFW_DONT_CARE; @@ -73,12 +69,6 @@ namespace gfx::ogl{ void destroy(void); - resource_manager& resource_man(void); - const resource_manager& resource_man(void)const; - - fbo& framebuffer(void); - const fbo& framebuffer(void)const; - void set_size(const math::vec2i&); void set_size(int w, int h); void set_width(int w); diff --git a/include/gfx/resource_container.hpp b/include/gfx/resource_container.hpp index 52054af..84ca9fd 100644 --- a/include/gfx/resource_container.hpp +++ b/include/gfx/resource_container.hpp @@ -27,6 +27,8 @@ #include "util/deferred.hpp" +#include "config.hpp" + namespace gfx{ template @@ -71,8 +73,21 @@ namespace gfx{ template template auto resource_container::emplace_value(const char* key, Args&&... args) -> std::pair{ +#ifdef OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT + //print out construction to check if things only get built once + //must enable rtti for typeid() which is disabled by default in the makefile + //add -frtti in the DEBUG_CXXFLAGS variable + if(node n = get_value(key);!n){ + debug_print_verbose("Constructing new %s in container\n", ::util::demangle(typeid(T).name()).c_str()); + auto p = m_map.emplace(key, util::deferred_function(std::make_shared, std::forward(args)...)); + return {(*p.first).second, p.second}; + }else{ + return {n, false}; + } +#else auto p = m_map.try_emplace(key, util::deferred_function(std::make_shared, std::forward(args)...)); return {(*p.first).second, p.second}; +#endif } template auto resource_container::get_value(const char* key) -> node{ diff --git a/include/gfx/resource_manager.hpp b/include/gfx/resource_manager.hpp deleted file mode 100644 index 89ac809..0000000 --- a/include/gfx/resource_manager.hpp +++ /dev/null @@ -1,97 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2022 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#ifndef OUR_DICK_GRAPHICS_RESOURCE_MANAGER_HPP -#define OUR_DICK_GRAPHICS_RESOURCE_MANAGER_HPP - -#include "resource_container.hpp" -#include "ogl/texture.hpp" -#include "ogl/shader_program.hpp" - -#include "egn/font.hpp" - -#include //forward - -namespace gfx{ - - class resource_manager - { - public: - template - using container_type = resource_container; - private: - container_type m_textures; - container_type m_fonts; - container_type m_texture_arrays; - container_type m_shaders; - - public: - resource_manager(void) = default; - resource_manager(const resource_manager&) = default; - resource_manager(resource_manager&&) = default; - - ~resource_manager(void) = default; - - resource_manager& operator=(const resource_manager&) = default; - resource_manager& operator=(resource_manager&&) = default; - - bool has_texture_array(const char* key)const; - template - auto emplace_texture_array(const char* key, Args&&... args); - container_type::node get_texture_array(const char* file); - bool erase_texture_array(const char* key); - - bool has_texture(const char* key)const; - template - auto emplace_texture(const char* key, Args&&... args); - container_type::node get_texture(const char* file); - bool erase_texture(const char* key); - - bool has_font(const char* key)const; - template - auto emplace_font(const char* key, Args&&... args); - container_type::node get_font(const char* file); - bool erase_font(const char* key); - - bool has_shader(const char* key)const; - template - auto emplace_shader(const char* key, Args&&... args); - container_type::node get_shader(const char* key); - bool erase_shader(const char* key); - }; - - template - auto resource_manager::emplace_texture_array(const char* key, Args&&... args){ - return m_texture_arrays.emplace_value(key, std::forward(args)...); - } - template - auto resource_manager::emplace_texture(const char* key, Args&&... args){ - return m_textures.emplace_value(key, std::forward(args)...); - } - template - auto resource_manager::emplace_font(const char* key, Args&&... args){ - return m_fonts.emplace_value(key, std::forward(args)...); - } - template - auto resource_manager::emplace_shader(const char* key, Args&&... args){ - return m_shaders.emplace_value(key, std::forward(args)...); - } - -} - -#endif diff --git a/include/math/mat.hpp b/include/math/mat.hpp index e9eeb60..1b5bf6e 100644 --- a/include/math/mat.hpp +++ b/include/math/mat.hpp @@ -29,7 +29,7 @@ namespace math{ //Common stuff shared by all types of matrices - template + template class matrix_base { static_assert(C > 0, "Cannot have 0 columns matrix"); @@ -61,19 +61,19 @@ namespace math{ //Value initializing constructors constexpr explicit matrix_base(value_type v); - template && ...),int> = 0> + template && ...),int> = 0> constexpr matrix_base(Args&&... args); //Copying constructors constexpr matrix_base(const matrix_base&) = default; constexpr matrix_base(matrix_base&&) = default; - template + template constexpr matrix_base(const matrix_base& m); ~matrix_base(void) = default; constexpr matrix_base& operator=(const matrix_base&) = default; constexpr matrix_base& operator=(matrix_base&&) = default; - template + template constexpr matrix_base& operator=(const matrix_base& m); //Getters/Setters @@ -95,7 +95,7 @@ namespace math{ }; //Non square matrices - template + template class matrix : public matrix_base { private: @@ -113,7 +113,7 @@ namespace math{ template = 0> constexpr matrix(const matrix_base& other); - template + template constexpr matrix(const matrix& other); constexpr matrix(const matrix&) = default; constexpr matrix(matrix&&) = default; @@ -122,12 +122,12 @@ namespace math{ //Assignement constexpr matrix& operator=(const matrix&) = default; constexpr matrix& operator=(matrix&&) = default; - template + template constexpr matrix& operator=(const matrix& m); }; //Square matrices - template + template class matrix : public matrix_base { private: @@ -148,14 +148,14 @@ namespace math{ constexpr explicit matrix(detail::id_initialize_t); template = 0> constexpr matrix(const matrix_base& other); - template + template constexpr matrix(const matrix& other); ~matrix(void) = default; //Assignement constexpr matrix& operator=(const matrix&) = default; constexpr matrix& operator=(matrix&&) = default; - template + template constexpr matrix& operator=(const matrix& m); //square matrix arithmetic operations @@ -165,37 +165,11 @@ namespace math{ constexpr matrix inverse(void)const; }; - template - constexpr T determinate(const matrix& m); - template - constexpr matrix inverse(const matrix& m); - - template - matrix rotation2d_pure(T angle); - template - constexpr matrix rotation2d_pure(T sin, T cos); - template - constexpr matrix scale2d(T x, T y); - - template - matrix rotation2d(T angle); - template - constexpr matrix rotation2d(T sin, T cos); - template - matrix rotation2d(T x, T y, T z); - - template - constexpr matrix rotation3d(T angle_x, T angle_y, T angle_z); - template - constexpr matrix translation3d(T x, T y, T z); - template - constexpr matrix scale3d(T x, T y, T z); - namespace detail{ - template + template struct is_matrix_helper { - template + template static std::true_type test(matrix_base*); static std::false_type test(void*); @@ -205,65 +179,92 @@ namespace math{ } //Determine if a given list of tyes are all matrix types - template + template struct is_matrix { static constexpr bool value = (detail::is_matrix_helper::value && ...); }; + template + concept Matrix = is_matrix::value; - namespace detail{ + template + concept Compatible_Scalar = requires(T&& t, U&& u){ + requires !is_matrix::value; + requires std::is_convertible_v>; + requires std::is_convertible_v>; + requires std::is_convertible_v>; + requires std::is_convertible_v>; + u * t; + u / t; + u + t; + u - t; + }; - template - struct are_same_size_matrix { - using l = std::decay_t; - using r = std::decay_t; - static constexpr bool value = is_matrix::value && l::Columns == r::Columns && l::Rows == r::Rows; - }; - template - using enable_if_matrix = std::enable_if_t::value,int>; - template - using enable_if_eq_matrix = std::enable_if_t::value,int>; - } + template + constexpr T determinate(const matrix& m); + template + constexpr matrix inverse(const matrix& m); + + template + matrix rotation2d_pure(T angle); + template + constexpr matrix rotation2d_pure(T sin, T cos); + template + constexpr matrix scale2d(T x, T y); + + template + matrix rotation2d(T angle); + template + constexpr matrix rotation2d(T sin, T cos); + template + matrix rotation2d(T x, T y, T z); + + template + constexpr matrix rotation3d(T angle_x, T angle_y, T angle_z); + template + constexpr matrix translation3d(T x, T y, T z); + template + constexpr matrix scale3d(T x, T y, T z); //Logic operators - template + template constexpr bool operator==(const matrix_base& left, const matrix_base right); - template + template constexpr bool operator!=(const matrix_base& left, const matrix_base right); //Arithmetic operators - template + template constexpr auto operator*(const matrix& left, const matrix& right); - template>,int> = 0> + template requires Compatible_Scalar constexpr auto operator*(const matrix& left, U&& right); - template>,int> = 0> + template requires Compatible_Scalar constexpr auto operator*(U&& left, const matrix& right); - template>,int> = 0> + template requires Compatible_Scalar constexpr auto operator/(const matrix& left, U&& right); - template + template constexpr auto operator+(const matrix& left, const matrix& right); - template + template constexpr auto operator-(const matrix& left, const matrix& right); - template + template constexpr auto operator-(const matrix& left); - template + template constexpr auto abs(const matrix_base& left); - template + template constexpr bool fuzzy_eq(const matrix_base& left, const matrix_base& right, const V& epsilon); - template + template constexpr bool fuzzy_neq(const matrix_base& left, const matrix_base& right, const V& epsilon); //Arithmetic assignment operators - template + template constexpr decltype(auto) operator*=(matrix& left, const matrix& right); - template>,int> = 0> + template requires Compatible_Scalar constexpr decltype(auto) operator*=(matrix& left, U&& right); - template>,int> = 0> + template requires Compatible_Scalar constexpr decltype(auto) operator/=(matrix& left, U&& right); - template + template constexpr decltype(auto) operator+=(matrix& left, const matrix& right); - template + template constexpr decltype(auto) operator-=(matrix& left, const matrix& right); } diff --git a/include/math/mat.tpp b/include/math/mat.tpp index 00dde5d..fa69bad 100644 --- a/include/math/mat.tpp +++ b/include/math/mat.tpp @@ -28,47 +28,47 @@ namespace math{ namespace detail{ - template + template static constexpr const T& min(const T& l, const T& r){ return l < r ? l : r; } } - template + template template constexpr matrix_base::matrix_base(std::integer_sequence): m_data{Ss...}{} - template + template constexpr matrix_base::matrix_base(void): matrix_base(typename detail::default_initialization_matrix::tuple{}){} - template + template constexpr matrix_base::matrix_base(detail::zero_initialize_t): m_data{}{} - template + template constexpr matrix_base::matrix_base(detail::no_initialize_t){} - template + template constexpr matrix_base::matrix_base(value_type v){ for(size_type i = 0; i < Columns*Rows; ++i) m_data[i] = v; } - template - template && ...),int>> + template + template && ...),int>> constexpr matrix_base::matrix_base(Args&&... args): m_data{static_cast(std::forward(args))...}{} - template - template + template + template constexpr matrix_base::matrix_base(const matrix_base& m){ using mat = matrix_base; for(typename mat::size_type i = 0; i < mat::Columns*mat::Rows; ++i) m_data[i] = m.get(i); } - template - template + template + template constexpr matrix_base& matrix_base::operator=(const matrix_base& m){ constexpr auto cols = detail::min(TC, C); constexpr auto rws = detail::min(TR, R); @@ -81,62 +81,62 @@ namespace math{ } - template + template constexpr auto matrix_base::operator[](size_type x){ return detail::mat_ref_obj{m_data, x}; } - template + template constexpr auto matrix_base::operator[](size_type x)const{ return detail::mat_ref_obj{m_data, x}; } - template + template constexpr auto matrix_base::get(size_type x, size_type y) -> reference{ return m_data[(x*Rows)+y]; } - template + template constexpr auto matrix_base::get(size_type x, size_type y)const -> const_reference{ return m_data[(x*Rows)+y]; } - template + template constexpr auto matrix_base::get(size_type i) -> reference{ return m_data[i]; } - template + template constexpr auto matrix_base::get(size_type i)const -> const_reference{ return m_data[i]; } - template + template constexpr auto matrix_base::columns(void)const -> size_type{ return Columns; } - template + template constexpr auto matrix_base::rows(void)const -> size_type{ return Rows; } - template + template constexpr auto matrix_base::size(void)const -> size_type{ return Columns*Rows; } - template + template constexpr auto matrix_base::raw(void) -> pointer{ return m_data; } - template + template constexpr auto matrix_base::raw(void)const -> const_pointer{ return m_data; } - template + template constexpr matrix_base::operator pointer(void){ return m_data; } - template + template constexpr matrix_base::operator const_pointer(void)const{ return m_data; } - template + template template> constexpr matrix::matrix(const matrix_base& other){ for(size_type i = 0;i < TC;++i){ @@ -145,8 +145,8 @@ namespace math{ } } } - template - template + template + template constexpr matrix::matrix(const matrix& other){ for(size_type i = 0;i < C;++i){ for(size_type j = 0;j < R;++j){ @@ -155,17 +155,17 @@ namespace math{ } } - template - template + template + template constexpr matrix& matrix::operator=(const matrix& m){ base::operator=(m); return *this; } - template + template constexpr matrix::matrix(detail::id_initialize_t): base(){} - template + template template> constexpr matrix::matrix(const matrix_base& other): matrix(id_initialize) @@ -176,8 +176,8 @@ namespace math{ } } } - template - template + template + template constexpr matrix::matrix(const matrix& other){ for(size_type i = 0;i < R;++i){ for(size_type j = 0;j < R;++j){ @@ -187,18 +187,18 @@ namespace math{ } - template - template + template + template constexpr matrix& matrix::operator=(const matrix& m){ base::operator=(m); return *this; } - template + template constexpr auto matrix::determinate(void)const -> value_type{ return math::determinate(*this); } - template + template constexpr auto matrix::trace(void)const -> value_type{ value_type sum = 0; for(size_type i = 0; i < R; ++i){ @@ -206,7 +206,7 @@ namespace math{ } return sum; } - template + template constexpr matrix matrix::transpose(void)const{ matrix m(no_initialize); for(size_type i = 0; i < R; ++i){ @@ -216,63 +216,63 @@ namespace math{ } return m; } - template + template constexpr matrix matrix::inverse(void)const{ return math::inverse(*this); } - template + template constexpr T determinate(const matrix& m){ return detail::determinate_helper::perform(m); } - template + template constexpr matrix inverse(const matrix& m){ return detail::inverse_helper::perform(m); } - template + template matrix rotation2d_pure(T angle){ return rotation2d_pure(std::sin(angle), std::cos(angle)); } - template + template constexpr matrix rotation2d_pure(T sin, T cos){ return matrix(cos, sin, -sin, cos); } - template + template constexpr matrix scale2d(T x, T y){ return matrix(x, T{0}, T{0}, y); } - template + template matrix rotation2d(T angle){ return rotation2d(std::sin(angle), std::cos(angle)); } - template + template constexpr matrix rotation2d(T sin, T cos){ return matrix(cos, -sin, T{0}, sin, cos, T{0}, T{0}, T{0}, T{1}); } - template + template matrix rotation2d(T x, T y, T z){ quaternion q(x, y, z); return q.to_mat3(); } - template + template constexpr matrix rotation3d(T angle_x, T angle_y, T angle_z){ quaternion q(angle_x, angle_y, angle_z); return q.to_mat4(); } - template + template constexpr matrix translation3d(T x, T y, T z){ return matrix(T{1}, T{0}, T{0}, T{0}, T{0}, T{1}, T{0}, T{0}, T{0}, T{0}, T{1}, T{0}, x, y, z, T{1}); } - template + template constexpr matrix scale3d(T x, T y, T z){ return matrix(x, T{0}, T{0}, T{0}, T{0}, y, T{0}, T{0}, @@ -281,7 +281,7 @@ namespace math{ } - template + template constexpr bool operator==(const matrix_base& left, const matrix_base right){ for(size_t i = 0; i < left.size(); ++i){ if(left.get(i) != right.get(i)) @@ -289,12 +289,12 @@ namespace math{ } return true; } - template + template constexpr bool operator!=(const matrix_base& left, const matrix_base right){ return !(left == right); } - template + template constexpr auto operator*(const matrix& left, const matrix& right){ using res_t = decltype(std::declval() * std::declval()); matrix res(zero_initialize); @@ -309,7 +309,7 @@ namespace math{ } return res; } - template::value,int>> + template requires Compatible_Scalar constexpr auto operator*(const matrix& left, U&& right){ using res_t = decltype(std::declval() * std::declval()); matrix res(no_initialize); @@ -318,7 +318,7 @@ namespace math{ } return res; } - template::value,int>> + template requires Compatible_Scalar constexpr auto operator*(U&& left, const matrix& right){ using res_t = decltype(std::declval() * std::declval()); matrix res(no_initialize); @@ -327,7 +327,7 @@ namespace math{ } return res; } - template::value,int>> + template requires Compatible_Scalar constexpr auto operator/(const matrix& left, U&& right){ using res_t = decltype(std::declval() / std::declval()); matrix res(no_initialize); @@ -336,7 +336,7 @@ namespace math{ } return res; } - template + template constexpr auto operator+(const matrix& left, const matrix& right){ using res_t = decltype(std::declval() + std::declval()); matrix res(no_initialize); @@ -345,7 +345,7 @@ namespace math{ } return res; } - template + template constexpr auto operator-(const matrix& left, const matrix& right){ using res_t = decltype(std::declval() - std::declval()); matrix res(no_initialize); @@ -354,7 +354,7 @@ namespace math{ } return res; } - template + template constexpr auto operator-(const matrix& left){ using res_t = decltype(-std::declval()); matrix res(no_initialize); @@ -363,7 +363,7 @@ namespace math{ } return res; } - template + template constexpr auto abs(const matrix_base& left){ matrix res(no_initialize); for(size_t i = 0; i < left.size(); ++i){ @@ -371,7 +371,7 @@ namespace math{ } return res; } - template + template constexpr bool fuzzy_eq(const matrix_base& left, const matrix_base& right, const V& epsilon){ for(size_t i = 0;i < left.size();++i){ if(std::abs(left.get(i) - right.get(i)) > epsilon) @@ -379,39 +379,39 @@ namespace math{ } return true; } - template + template constexpr bool fuzzy_neq(const matrix_base& left, const matrix_base& right, const V& epsilon){ return !fuzzy_eq(left, right, epsilon); } - template + template constexpr decltype(auto) operator*=(matrix& left, const matrix& right){ //have to evaluate entire expression first since matrix multiplication depends on reusing many elements //cannot be expression templatized, TODO return (left = (left * right)); } - template::value,int>> + template requires Compatible_Scalar constexpr decltype(auto) operator*=(matrix& left, U&& right){ for(size_t i = 0; i < left.size(); ++i){ left.get(i) = left.get(i) * std::forward(right); } return left; } - template::value,int>> + template requires Compatible_Scalar constexpr decltype(auto) operator/=(matrix& left, U&& right){ for(size_t i = 0; i < left.size(); ++i){ left.get(i) = left.get(i) / std::forward(right); } return left; } - template + template constexpr decltype(auto) operator+=(matrix& left, const matrix& right){ for(size_t i = 0; i < left.size(); ++i){ left.get(i) = left.get(i) + right.get(i); } return left; } - template + template constexpr decltype(auto) operator-=(matrix& left, const matrix& right){ for(size_t i = 0; i < left.size(); ++i){ left.get(i) = left.get(i) - right.get(i); diff --git a/include/math/quat.hpp b/include/math/quat.hpp index c6b4050..c369d0b 100644 --- a/include/math/quat.hpp +++ b/include/math/quat.hpp @@ -29,7 +29,7 @@ namespace math{ //( ͡° ͜ʖ ͡°) - template + template class quaternion { public: @@ -113,7 +113,7 @@ namespace math{ namespace detail{ - template + template struct is_quat_helper { template static std::true_type test(quaternion*); @@ -121,39 +121,39 @@ namespace math{ static constexpr bool value = std::is_same*>(nullptr)))>::value; }; } - template + template struct is_quaternion { static constexpr bool value = (detail::is_quat_helper::value && ...); }; - template + template bool operator==(const quaternion& left, const quaternion& right); - template + template bool operator!=(const quaternion& left, const quaternion& right); - template + template auto operator-(const quaternion& left); - template + template auto operator-(const quaternion& left, const quaternion& right); - template + template auto operator+(const quaternion& left, const quaternion& right); - template + template auto operator*(const quaternion& left, const quaternion& right); - template + template auto operator*(const quaternion& left, const vec3& right); - template>,int> = 0> + template requires Compatible_Scalar auto operator*(const quaternion& left, U&& right); - template>,int> = 0> + template requires Compatible_Scalar auto operator/(const quaternion& left, U&& right); - template + template decltype(auto) operator+=(quaternion& left, const quaternion& right); - template + template decltype(auto) operator-=(quaternion& left, const quaternion& right); - template + template decltype(auto) operator*=(quaternion& left, const quaternion& right); - template>,int> = 0> + template requires Compatible_Scalar decltype(auto) operator*=(quaternion& left, U&& right); - template>,int> = 0> + template requires Compatible_Scalar decltype(auto) operator/=(quaternion& left, U&& right); } diff --git a/include/math/quat.tpp b/include/math/quat.tpp index d76e788..a557ae6 100644 --- a/include/math/quat.tpp +++ b/include/math/quat.tpp @@ -25,25 +25,25 @@ namespace math{ - template + template constexpr quaternion::quaternion(void): quaternion(id_initialize){} - template + template constexpr quaternion::quaternion(detail::zero_initialize_t): m_data{0, 0, 0, 0}{} - template + template constexpr quaternion::quaternion(detail::id_initialize_t): m_data{1, 0, 0, 0}{} - template + template constexpr quaternion::quaternion(detail::no_initialize_t){} - template + template constexpr quaternion::quaternion(detail::manual_initialize_t, value_type w, value_type x, value_type y, value_type z): m_data{w, x, y, z}{} - template + template quaternion::quaternion(const mat3& rotmat){ auto tr = rotmat.trace(); if(tr > 0){ @@ -72,12 +72,12 @@ namespace math{ m_data[3] = f * 0.25; } } - template + template quaternion::quaternion(const mat4& rotmat): quaternion(mat3{rotmat.get(0), rotmat.get(1), rotmat.get(2), rotmat.get(4), rotmat.get(5), rotmat.get(6), rotmat.get(8), rotmat.get(9), rotmat.get(10)}){} - template + template quaternion::quaternion(value_type bank, value_type heading, value_type attitude){ bank /= value_type{2}; heading /= value_type{2}; @@ -94,13 +94,13 @@ namespace math{ m_data[2] = (sin_heading * cos_attitude * cos_bank) + (cos_heading * sin_attitude * sin_bank); m_data[3] = (cos_heading * sin_attitude * cos_bank) - (sin_heading * cos_attitude * sin_bank); } - template + template quaternion::quaternion(const vec3& angles): quaternion(angles.x(), angles.y(), angles.z()){} - template + template quaternion::quaternion(value_type angle, const vec3& axis): quaternion(angle, axis.get_x(), axis.get_y(), axis.get_z()){} - template + template quaternion::quaternion(value_type angle, value_type x, value_type y, value_type z){ angle /= value_type{2.0}; value_type sin_angle = std::sin(angle); @@ -110,74 +110,74 @@ namespace math{ m_data[3] = sin_angle * z; } - template + template constexpr quaternion::operator pointer(void){ return m_data; } - template + template constexpr quaternion::operator const_pointer(void)const{ return m_data; } - template + template constexpr auto quaternion::operator[](size_type i) -> reference{ return m_data[i]; } - template + template constexpr auto quaternion::operator[](size_type i)const -> const_reference{ return m_data[i]; } - template + template constexpr auto quaternion::get(size_type i) -> reference{ return m_data[i]; } - template + template constexpr auto quaternion::get(size_type i)const -> const_reference{ return m_data[i]; } - template + template constexpr auto quaternion::w(void) -> reference{ return m_data[0]; } - template + template constexpr auto quaternion::w(void)const -> const_reference{ return m_data[0]; } - template + template constexpr auto quaternion::x(void) -> reference{ return m_data[1]; } - template + template constexpr auto quaternion::x(void)const -> const_reference{ return m_data[1]; } - template + template constexpr auto quaternion::y(void) -> reference{ return m_data[2]; } - template + template constexpr auto quaternion::y(void)const -> const_reference{ return m_data[2]; } - template + template constexpr auto quaternion::z(void) -> reference{ return m_data[3]; } - template + template constexpr auto quaternion::z(void)const -> const_reference{ return m_data[3]; } - template + template void quaternion::set_axis(value_type x, value_type y, value_type z){ value_type sin_angle = std::sin(std::acos(m_data[0])); m_data[1] = sin_angle * x; m_data[2] = sin_angle * y; m_data[3] = sin_angle * z; } - template + template void quaternion::set_axis(const vec3& v){ set_axis(v.x(), v.y(), v.z()); } - template + template auto quaternion::get_axis(void)const -> vec3{ quaternion tmp(*this); if(m_data[0] > value_type{1.0}) @@ -187,7 +187,7 @@ namespace math{ return vec3(1, 0, 0); return vec3(tmp.data[1] / s, tmp.data[2] / s, tmp.data[3] / s); } - template + template void quaternion::set_angle(value_type t){ t /= value_type{2.0}; value_type old_sin_angle = std::sin(std::acos(m_data[0])); @@ -197,58 +197,58 @@ namespace math{ m_data[2] = (m_data[2] / old_sin_angle) * sin_angle; m_data[3] = (m_data[3] / old_sin_angle) * sin_angle; } - template + template auto quaternion::get_angle(void)const -> value_type{ return 2.0 * std::acos(m_data[0]); } - template + template auto quaternion::norm(void)const -> value_type{ return m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2] + m_data[3] * m_data[3]; } - template + template quaternion quaternion::conjugate(void)const{ return quaternion(manual_initialize, m_data[0], -m_data[1], -m_data[2], -m_data[3]); } - template + template quaternion quaternion::inverse(void)const{ return conjugate() / norm(); } - template + template auto quaternion::magnitude(void)const -> value_type{ return std::sqrt(norm()); } - template + template quaternion quaternion::normalize(void)const{ value_type mag = magnitude(); return quaternion(manual_initialize, m_data[0] / mag, m_data[1] / mag, m_data[2] / mag, m_data[3] / mag); } - template + template auto quaternion::get_right(void)const -> vec3{ return vec3(1 - 2 * ((m_data[2] * m_data[2]) + (m_data[3] * m_data[3])), 2 * ((m_data[1] * m_data[2]) - (m_data[3] * m_data[0])), 2 * ((m_data[1] * m_data[3]) + (m_data[2] * m_data[0]))); } - template + template auto quaternion::get_up(void)const -> vec3{ return vec3( 2 * ((m_data[1] * m_data[2]) + (m_data[3] * m_data[0])), 1 - 2 * ((m_data[1] * m_data[1]) + (m_data[3] * m_data[3])), 2 * ((m_data[2] * m_data[3]) - (m_data[1] * m_data[0]))); } - template + template auto quaternion::get_forward(void)const -> vec3{ return vec3( 2 * ((m_data[1] * m_data[3]) - (m_data[2] * m_data[0])), 2 * ((m_data[2] * m_data[3]) + (m_data[1] * m_data[0])), 1 - 2 * ((m_data[1] * m_data[1]) + (m_data[2] * m_data[2]))); } - template + template auto quaternion::to_vec3(void)const -> vec3{ return vec3(m_data[1], m_data[2], m_data[3]); } - template + template auto quaternion::to_vec4(void)const -> vec4{ return vec4(m_data[1], m_data[2], m_data[3]); } - template + template auto quaternion::to_mat3(void)const -> mat3{ mat3 m; @@ -274,7 +274,7 @@ namespace math{ m.get(8) = 1 - 2 * (xx + yy); return m; } - template + template auto quaternion::to_mat4(void)const -> mat4{ mat4 m; @@ -307,7 +307,7 @@ namespace math{ m.get(15) = 1; return m; } - template + template auto quaternion::to_euler_angles(void)const -> vec3{ value_type ww = m_data[0] * m_data[0]; value_type xx = m_data[1] * m_data[1]; @@ -325,7 +325,7 @@ namespace math{ std::atan2((2 * m_data[2] * m_data[0]) - (2 * m_data[1] * m_data[3]), xx - yy - zz + ww), std::asin(2 * test / correction)); } - template + template auto quaternion::to_axis_angle(void)const -> std::pair>{ quaternion q(*this); if(m_data[0] > 1.0) @@ -338,35 +338,35 @@ namespace math{ return {2 * std::acos(q.m_data[0]), {q.m_data[1] / s, q.m_data[2] / s, q.m_data[3] / s}}; } - template + template bool operator==(const quaternion& left, const quaternion& right){ return left.w() == right.w() && left.x() == right.x() && left.y() == right.y() && left.z() == right.z(); } - template + template bool operator!=(const quaternion& left, const quaternion& right){ return !(left == right); } - template + template auto operator-(const quaternion& left){ using res_t = T; return quaternion(manual_initialize, -left.w(), -left.x(), -left.y(), -left.z()); } - template + template auto operator-(const quaternion& left, const quaternion& right){ using res_t = decltype(std::declval() - std::declval()); return quaternion(manual_initialize, left.w() - right.w(), left.x() - right.x(), left.y() - right.y(), left.z() - right.z()); } - template + template auto operator+(const quaternion& left, const quaternion& right){ using res_t = decltype(std::declval() + std::declval()); return quaternion(manual_initialize, left.w() + right.w(), left.x() + right.x(), left.y() + right.y(), left.z() + right.z()); } - template + template auto operator*(const quaternion& left, const quaternion& right){ using res_t = decltype(std::declval() * std::declval()); return quaternion(manual_initialize, @@ -379,21 +379,21 @@ namespace math{ (right.w() * left.z()) + (right.x() * left.y()) - (right.y() * left.x()) + (right.z() * left.w())); } - template + template auto operator*(const quaternion& left, const vec3& right){ return left.to_mat3() * right; } - template>,int>> + template requires Compatible_Scalar auto operator*(const quaternion& left, U&& right){ using res_t = decltype(std::declval() * std::declval()); return quaternion(manual_initialize, left.w() * right, left.x() * right, left.y() * right, left.z() * right); } - template>,int>> + template requires Compatible_Scalar auto operator/(const quaternion& left, U&& right){ using res_t = decltype(std::declval() / std::declval()); return quaternion(manual_initialize, left.w() / right, left.x() / right, left.y() / right, left.z() / right); } - template + template decltype(auto) operator+=(quaternion& left, const quaternion& right){ left.w() += right.w(); left.x() += right.x(); @@ -401,7 +401,7 @@ namespace math{ left.z() += right.z(); return left; } - template + template decltype(auto) operator-=(quaternion& left, const quaternion& right){ left.w() -= right.w(); left.x() -= right.x(); @@ -409,13 +409,13 @@ namespace math{ left.z() -= right.z(); return left; } - template + template decltype(auto) operator*=(quaternion& left, const quaternion& right){ left = left * right; return left; } - template>,int>> + template requires Compatible_Scalar decltype(auto) operator*=(quaternion& left, U&& right){ left.w() *= right; left.x() *= right; @@ -423,7 +423,7 @@ namespace math{ left.z() *= right; return left; } - template>,int>> + template requires Compatible_Scalar decltype(auto) operator/=(quaternion& left, U&& right){ left.w() /= right; left.x() /= right; diff --git a/include/math/vec.hpp b/include/math/vec.hpp index 4dc7b9e..9e71aac 100644 --- a/include/math/vec.hpp +++ b/include/math/vec.hpp @@ -25,7 +25,7 @@ namespace math{ //class representing vectors //inherit from matrix base because it also shared matrix attributes - template + template class vector : public matrix_base { private: @@ -41,9 +41,9 @@ namespace math{ public: using base::base; - template && ...),int> = 0> + template && ...),int> = 0> constexpr vector(const vector& other, Args&&... args); - template + template constexpr vector(const vector& other); constexpr vector(const vector&) = default; constexpr vector(vector&&) = default; @@ -52,7 +52,7 @@ namespace math{ //Assignement constexpr vector& operator=(const vector&) = default; constexpr vector& operator=(vector&&) = default; - template + template constexpr vector& operator=(const vector& m); constexpr reference operator[](size_type i); @@ -60,60 +60,80 @@ namespace math{ constexpr reference x(void); constexpr const_reference x(void)const; - template + template constexpr reference y(void); - template + template constexpr const_reference y(void)const; - template + template constexpr reference z(void); - template + template constexpr const_reference z(void)const; - template + template constexpr reference w(void); - template + template constexpr const_reference w(void)const; value_type magnitude(void)const; vector normalize(void); protected: - template + template constexpr void assign_(size_type offset, U&& u, Args&&... args); }; - template + namespace detail{ + + template + struct is_vector_helper { + template + static std::true_type test(vector*); + static std::false_type test(void*); + + static constexpr bool value = std::is_same*>(nullptr)))>::value; + }; + + } + + template + struct is_vector{ + static constexpr bool value = (detail::is_vector_helper::value && ...); + }; + template + concept Vector = is_vector::value; + + template constexpr auto perp(const vector& v); - template + template constexpr auto perp(const vector& left, const vector& right); - template + template constexpr auto cross(const vector& left, const vector& right); - template + template constexpr auto magnitude(const vector& v); - template + template constexpr auto operator*(const matrix& left, const vector& right); - template + template constexpr auto operator*(const vector& left, const vector& right); - template::value,int> = 0> + template requires Compatible_Scalar constexpr auto operator*(const vector& left, U&& right); - template::value,int> = 0> + template requires Compatible_Scalar constexpr auto operator*(U&& left, const vector& right); - template::value,int> = 0> + template requires Compatible_Scalar constexpr auto operator/(const vector& left, U&& right); - template + template constexpr auto operator+(const vector& left, const vector& right); - template + template constexpr auto operator-(const vector& left, const vector& right); - template + template constexpr auto operator-(const vector& left); - template::value,int> = 0> + template requires Compatible_Scalar constexpr decltype(auto) operator*=(vector& left, U&& right); - template::value,int> = 0> + template requires Compatible_Scalar constexpr decltype(auto) operator/=(vector& left, U&& right); - template + template constexpr decltype(auto) operator+=(vector& left, const vector& right); - template + template constexpr decltype(auto) operator-=(vector& left, const vector& right); } diff --git a/include/math/vec.tpp b/include/math/vec.tpp index 287ef48..6079135 100644 --- a/include/math/vec.tpp +++ b/include/math/vec.tpp @@ -23,8 +23,8 @@ namespace math{ - template - template && ...),int>> + template + template && ...),int>> constexpr vector::vector(const vector& other, Args&&... args){ static_assert(sizeof...(args) + TR <= R); size_type i = 0; @@ -35,81 +35,81 @@ namespace math{ assign_(i, std::forward(args)...); } } - template - template + template + template constexpr vector::vector(const vector& other){ for(size_type i = 0;i < R;++i){ this->m_data[i] = other[i]; } } - template - template + template + template constexpr void vector::assign_(size_type offset, U&& u, Args&&... args){ this->m_data[offset] = std::forward(u); if constexpr(sizeof...(args) > 0){ assign_(offset + 1, std::forward(args)...); } } - template - template + template + template constexpr vector& vector::operator=(const vector& m){ base::operator=(m); return *this; } - template + template constexpr auto vector::operator[](size_type i) -> reference{ return this->m_data[i]; } - template + template constexpr auto vector::operator[](size_type i)const -> const_reference{ return this->m_data[i]; } - template + template constexpr auto vector::x(void) -> reference{ return this->m_data[0]; } - template + template constexpr auto vector::x(void)const -> const_reference{ return this->m_data[0]; } - template - template + template + template constexpr auto vector::y(void) -> reference{ static_assert(R > 1, "Vector does not contain a 2nd element"); return this->m_data[1]; } - template - template + template + template constexpr auto vector::y(void)const -> const_reference{ static_assert(R > 1, "Vector does not contain a 2nd element"); return this->m_data[1]; } - template - template + template + template constexpr auto vector::z(void) -> reference{ static_assert(R > 2, "Vector does not contain a 3rd element"); return this->m_data[2]; } - template - template + template + template constexpr auto vector::z(void)const -> const_reference{ static_assert(R > 2, "Vector does not contain a 3rd element"); return this->m_data[2]; } - template - template + template + template constexpr auto vector::w(void) -> reference{ static_assert(R > 3, "Vector does not contain a 4th element"); return this->m_data[3]; } - template - template + template + template constexpr auto vector::w(void)const -> const_reference{ static_assert(R > 3, "Vector does not contain a 4th element"); return this->m_data[3]; } - template + template auto vector::magnitude(void)const -> value_type{ value_type sum = 0; for(size_type i = 0;i < R;++i){ @@ -117,32 +117,32 @@ namespace math{ } return sqrt(sum); } - template + template vector vector::normalize(void){ return (*this) / magnitude(); } - template + template constexpr auto perp(const vector& v){ return vec2(-v[1], v[0]); } - template + template constexpr auto perp(const vector& left, const vector& right){ return (left[0] * right[1]) - (left[1] * right[0]); } - template + template constexpr auto cross(const vector& left, const vector& right){ using res_t = decltype(left[0] * right[0]); return vec3((left[1] * right[2]) - (left[2] * right[1]), (left[2] * right[0]) - (left[0] * right[2]), (left[0] * right[1]) - (left[1] * right[0])); } - template + template constexpr auto magnitude(const vector& v){ return v.magnitude(); } - template + template constexpr auto operator*(const matrix& left, const vector& right){ using res_t = decltype(std::declval() * std::declval()); vector res(zero_initialize); @@ -156,7 +156,7 @@ namespace math{ } return res; } - template + template constexpr auto operator*(const vector& left, const vector& right){ using res_t = decltype(std::declval() * std::declval()); res_t res = 0; @@ -165,7 +165,7 @@ namespace math{ } return res; } - template::value,int>> + template requires Compatible_Scalar constexpr auto operator*(const vector& left, U&& right){ using res_t = decltype(std::declval() * std::declval()); vector res(zero_initialize); @@ -174,7 +174,7 @@ namespace math{ } return res; } - template::value,int>> + template requires Compatible_Scalar constexpr auto operator*(U&& left, const vector& right){ using res_t = decltype(std::declval() * std::declval()); vector res(zero_initialize); @@ -183,7 +183,7 @@ namespace math{ } return res; } - template::value,int>> + template requires Compatible_Scalar constexpr auto operator/(const vector& left, U&& right){ using res_t = decltype(std::declval() / std::declval()); vector res(zero_initialize); @@ -192,7 +192,7 @@ namespace math{ } return res; } - template + template constexpr auto operator+(const vector& left, const vector& right){ using res_t = decltype(std::declval() + std::declval()); vector res(zero_initialize); @@ -201,7 +201,7 @@ namespace math{ } return res; } - template + template constexpr auto operator-(const vector& left, const vector& right){ using res_t = decltype(std::declval() - std::declval()); vector res(zero_initialize); @@ -210,7 +210,7 @@ namespace math{ } return res; } - template + template constexpr auto operator-(const vector& left){ using res_t = decltype(-std::declval()); vector res(zero_initialize); @@ -220,28 +220,28 @@ namespace math{ return res; } - template::value,int>> + template requires Compatible_Scalar constexpr decltype(auto) operator*=(vector& left, U&& right){ for(size_t i = 0; i < R; ++i){ left[i] *= right; } return left; } - template::value,int>> + template requires Compatible_Scalar constexpr decltype(auto) operator/=(vector& left, U&& right){ for(size_t i = 0; i < R; ++i){ left[i] /= right; } return left; } - template + template constexpr decltype(auto) operator+=(vector& left, const vector& right){ for(size_t i = 0; i < R; ++i){ left[i] += right[i]; } return left; } - template + template constexpr decltype(auto) operator-=(vector& left, const vector& right){ for(size_t i = 0; i < R; ++i){ left[i] -= right[i]; diff --git a/include/ttt/board.hpp b/include/ttt/board.hpp index 4881abc..05cceba 100644 --- a/include/ttt/board.hpp +++ b/include/ttt/board.hpp @@ -22,7 +22,6 @@ #include "gfx/ogl/shader_program.hpp" #include "renderable.hpp" -#include "gfx/resource_manager.hpp" #include "math/vec.hpp" #include "config.hpp" @@ -33,6 +32,7 @@ #include "gfx/ogl/vbo.hpp" #include "gfx/ogl/vao.hpp" #include "gfx/ogl/texture.hpp" +#include "wip/renderer.hpp" class board_gfx; @@ -120,7 +120,7 @@ private: std::unique_ptr m_gfx; public: - board(gfx::resource_manager& r); + board(wip::gfx::renderer& r); ~board(void)override = default; tile::value check_winner(void)const; diff --git a/include/ttt/board_gfx.hpp b/include/ttt/board_gfx.hpp index 4ad9dbf..fc29aa3 100644 --- a/include/ttt/board_gfx.hpp +++ b/include/ttt/board_gfx.hpp @@ -23,7 +23,7 @@ #include "gfx/ogl/vbo.hpp" #include "gfx/ogl/vao.hpp" #include "gfx/ogl/shader_program.hpp" -#include "gfx/resource_manager.hpp" +#include "wip/renderer.hpp" #include //pair #include //shared_ptr @@ -38,7 +38,7 @@ private: gfx::ogl::vbo m_vbo; public: - board_gfx(gfx::resource_manager& resman); + board_gfx(wip::gfx::renderer& resman); ~board_gfx(void) = default; void set_uniforms(gfx::ogl::shader_program& sh); diff --git a/include/ttt/main_renderer.hpp b/include/ttt/main_renderer.hpp index 8ceff22..b805d0a 100644 --- a/include/ttt/main_renderer.hpp +++ b/include/ttt/main_renderer.hpp @@ -24,9 +24,10 @@ #include "gfx/ogl/vbo.hpp" #include "math/math.hpp" #include "scene.hpp" -#include "gfx/resource_manager.hpp" #include "basic_framebuffer.hpp" +#include "wip/renderer.hpp" + #include //shared_ptr class main_renderer @@ -55,7 +56,7 @@ private: gfx::ogl::vbo m_board_vbo; public: - main_renderer(gfx::resource_manager& res, int width, int height); + main_renderer(wip::gfx::renderer& res, int width, int height); void set_vp_matrix(const math::mat4f& vp); void render(scene&); diff --git a/include/ttt/pause_state.hpp b/include/ttt/pause_state.hpp index 56005fb..bb3a9b6 100644 --- a/include/ttt/pause_state.hpp +++ b/include/ttt/pause_state.hpp @@ -23,12 +23,17 @@ #include "egn/input.hpp" #include "gfx/ogl/texture.hpp" #include "screen_renderer.hpp" +#include "wip/renderer.hpp" +#include "wip/square.hpp" class pause_state : public egn::game_state_iface { private: egn::game_state_iface* m_under_state; screen_renderer m_screen_renderer; + std::shared_ptr m_square; + egn::ortho_camera m_main_camera; + double m_elapsed_time; public: pause_state(egn::game& owner, egn::game_state_iface* under); diff --git a/include/ttt/screen_renderer.hpp b/include/ttt/screen_renderer.hpp index 1f8443a..b91c27b 100644 --- a/include/ttt/screen_renderer.hpp +++ b/include/ttt/screen_renderer.hpp @@ -24,8 +24,8 @@ #include "gfx/ogl/texture.hpp" #include "math/math.hpp" #include "gfx/ogl/shader_program.hpp" -#include "gfx/resource_manager.hpp" #include "scene.hpp" +#include "wip/renderer.hpp" #include "egn/font.hpp" @@ -54,7 +54,7 @@ private: int m_screen_width, m_screen_height; public: - screen_renderer(gfx::resource_manager& res, int width, int height, const std::shared_ptr& base_tex); + screen_renderer(wip::gfx::renderer& res, int width, int height, const std::shared_ptr& base_tex); void render(scene&); void resize_viewport(int width, int height); diff --git a/include/util/demangle.hpp b/include/util/demangle.hpp new file mode 100644 index 0000000..4fe4c20 --- /dev/null +++ b/include/util/demangle.hpp @@ -0,0 +1,29 @@ +/** + This file is a part of our_dick + Copyright (C) 2022 rexy712 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#ifndef OUR_DICK_UTIL_DEMANGLE_HPP +#define OUR_DICK_UTIL_DEMANGLE_HPP + +#include + +namespace util{ + std::string demangle(const char* name); +} + +#endif + diff --git a/include/wip/base_shader.hpp b/include/wip/base_shader.hpp new file mode 100644 index 0000000..50a77c4 --- /dev/null +++ b/include/wip/base_shader.hpp @@ -0,0 +1,68 @@ +/** + This file is a part of our_dick + Copyright (C) 2022 rexy712 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#ifndef OUR_DICK_GRAPHICS_WIP_BASE_SHADER_HPP +#define OUR_DICK_GRAPHICS_WIP_BASE_SHADER_HPP + +namespace wip::gfx::base_shader{ + + static constexpr char vertex_shader_text[] = + R"glsl( + #version 430 core + + layout (location = 0) in vec3 position; + layout (location = 1) in vec2 tex_coords; + + + layout (std140) uniform mvp_matrix{ + mat4 vp_mat; + mat4 model_mat; + }; + + out VS_OUT{ + vec2 tex_coords; + }vs_out; + + const vec4 vertices[6] = vec4[](vec4(0,1,0,1), vec4(0,0,0,1), vec4(1,0,0,1), vec4(1,0,0,1), vec4(1,1,0,1), vec4(0,1,0,1)); + + void main(){ + gl_Position = vp_mat * model_mat * vec4(position, 1); + vs_out.tex_coords = tex_coords; + } + )glsl"; + + static constexpr char fragment_shader_text[] = + R"glsl( + #version 430 core + + in VS_OUT{ + vec2 tex_coords; + }fs_in; + + out vec4 frag_color; + + uniform sampler2D diffuse_texture; + + void main(){ + frag_color = texture(diffuse_texture, fs_in.tex_coords);; + } + )glsl"; + +} + +#endif diff --git a/include/wip/draw_command.hpp b/include/wip/draw_command.hpp index b229954..6b5f466 100644 --- a/include/wip/draw_command.hpp +++ b/include/wip/draw_command.hpp @@ -21,13 +21,18 @@ #include "mesh.hpp" #include "material.hpp" +#include "surface.hpp" +#include "renderable.hpp" namespace wip::gfx{ struct draw_command{ + renderable* instance; material* mat; mesh* msh; + surface* surf; float distance; + void* userptr; }; } diff --git a/include/wip/ogl_mesh.hpp b/include/wip/ogl_mesh.hpp index fda1270..8966109 100644 --- a/include/wip/ogl_mesh.hpp +++ b/include/wip/ogl_mesh.hpp @@ -45,7 +45,7 @@ namespace wip::gfx::ogl{ void bind(void); - void render(::wip::gfx::renderer& r, material&); + void render(::wip::gfx::renderer& r); }; } diff --git a/include/wip/ogl_renderer.hpp b/include/wip/ogl_renderer.hpp index 52eccb3..e762095 100644 --- a/include/wip/ogl_renderer.hpp +++ b/include/wip/ogl_renderer.hpp @@ -37,7 +37,7 @@ namespace wip::gfx::ogl{ using container_type = resource_manager::container_type; protected: - ::gfx::ogl::ubo m_camera_uniform; + ::gfx::ogl::ubo m_camera_uniform; public: renderer(void) = default; @@ -49,8 +49,12 @@ namespace wip::gfx::ogl{ renderer& operator=(renderer&&) = default; void set_viewport(const math::vec4f& vp); + void set_model_matrix(const math::mat4f& mat); void set_camera(const math::mat4f& view, const math::mat4f& proj); + void bind_default_surface(void); + void clear_current_surface(void); + void draw_tris(int offset, int vertex_count); void process_command(draw_command& c); diff --git a/include/wip/ogl_resource_manager.hpp b/include/wip/ogl_resource_manager.hpp index 21affd0..5ae89ac 100644 --- a/include/wip/ogl_resource_manager.hpp +++ b/include/wip/ogl_resource_manager.hpp @@ -22,6 +22,7 @@ #include "gfx/resource_container.hpp" #include "gfx/ogl/shader_program.hpp" #include "gfx/ogl/texture.hpp" +#include "gfx/ogl/fbo.hpp" namespace wip::gfx::ogl{ @@ -36,8 +37,11 @@ namespace wip::gfx::ogl{ container_type<::gfx::ogl::shader> m_shaders; container_type<::gfx::ogl::texture> m_textures; container_type<::gfx::ogl::texture_array> m_texture_arrays; + container_type<::gfx::ogl::fbo> m_framebuffers; public: + resource_manager(void); + const container_type<::gfx::ogl::shader_program>& shader_programs(void)const; container_type<::gfx::ogl::shader_program>& shader_programs(void); const container_type<::gfx::ogl::shader>& shaders(void)const; @@ -46,6 +50,8 @@ namespace wip::gfx::ogl{ container_type<::gfx::ogl::texture>& textures(void); const container_type<::gfx::ogl::texture_array>& texture_arrays(void)const; container_type<::gfx::ogl::texture_array>& texture_arrays(void); + const container_type<::gfx::ogl::fbo>& framebuffers(void)const; + container_type<::gfx::ogl::fbo>& framebuffers(void); }; } diff --git a/include/wip/ogl_surface.hpp b/include/wip/ogl_surface.hpp new file mode 100644 index 0000000..67c75ee --- /dev/null +++ b/include/wip/ogl_surface.hpp @@ -0,0 +1,42 @@ +/** + This file is a part of our_dick + Copyright (C) 2022 rexy712 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#ifndef OUR_DICK_GRAPHICS_WIP_OGL_SURFACE_HPP +#define OUR_DICK_GRAPHICS_WIP_OGL_SURFACE_HPP + +#include "gfx/ogl/fbo.hpp" + +#include //shared_ptr + +namespace wip::gfx::ogl{ + + class surface + { + public: + std::shared_ptr<::gfx::ogl::fbo> framebuffer; + + public: + surface(const std::shared_ptr<::gfx::ogl::fbo>& fb); + + void bind(void); + }; + +} + + +#endif diff --git a/include/wip/renderable.hpp b/include/wip/renderable.hpp new file mode 100644 index 0000000..dac73e7 --- /dev/null +++ b/include/wip/renderable.hpp @@ -0,0 +1,40 @@ +/** + This file is a part of our_dick + Copyright (C) 2022 rexy712 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#ifndef OUR_DICK_GRAPHICS_WIP_RENDERABLE_HPP +#define OUR_DICK_GRAPHICS_WIP_RENDERABLE_HPP + +#include "gfx/ogl/shader_program.hpp" + +namespace wip::gfx{ + + class renderer; + struct draw_command; + + class renderable + { + public: + virtual ~renderable(void) = default; + + virtual void submit_render(renderer& r) = 0; + virtual void render(renderer& r, draw_command& c) = 0; + }; + +} + +#endif diff --git a/include/wip/renderer.hpp b/include/wip/renderer.hpp index 7dc4b0d..8378f02 100644 --- a/include/wip/renderer.hpp +++ b/include/wip/renderer.hpp @@ -22,6 +22,7 @@ #include "ogl_renderer.hpp" #include "material.hpp" #include "mesh.hpp" +#include "surface.hpp" #include "draw_command.hpp" #include @@ -38,11 +39,12 @@ namespace wip::gfx{ protected: container_type m_materials; container_type m_meshs; + container_type m_surfaces; std::list m_commands; public: - renderer(void) = default; + renderer(void); renderer(const renderer&) = default; renderer(renderer&&) = default; ~renderer(void) = default; @@ -55,6 +57,8 @@ namespace wip::gfx{ container_type& meshs(void); const container_type& materials(void)const; container_type& materials(void); + const container_type& surfaces(void)const; + container_type& surfaces(void); void submit_command(const draw_command& c); void render(void); diff --git a/include/wip/square.hpp b/include/wip/square.hpp index 8b14ca6..c0d4eda 100644 --- a/include/wip/square.hpp +++ b/include/wip/square.hpp @@ -23,33 +23,33 @@ #include "mesh.hpp" #include "material.hpp" #include "renderer.hpp" +#include "renderable.hpp" #include //shared_ptr namespace wip{ - class square + class square : public gfx::renderable { public: static constexpr gfx::vertex mesh_vertices[] = { - {{0, 1, 0}, {0, 1}}, - {{0, 0, 0}, {0, 0}}, - {{1, 0, 0}, {1, 0}}, - {{1, 0, 0}, {1, 0}}, - {{1, 1, 0}, {1, 1}}, - {{0, 1, 0}, {0, 1}} + {{-1, 1, 0}, {0, 1}}, + {{-1, -1, 0}, {0, 0}}, + {{ 1, -1, 0}, {1, 0}}, + {{ 1, -1, 0}, {1, 0}}, + {{ 1, 1, 0}, {1, 1}}, + {{-1, 1, 0}, {0, 1}} }; - private: + public: std::shared_ptr m_mesh; std::shared_ptr m_material; public: square(const std::shared_ptr& msh, const std::shared_ptr& mat); - void render(gfx::renderer& r){ - r.submit_command({m_material.get(), m_mesh.get(), 0}); - } + void submit_render(gfx::renderer& r)override; + void render(gfx::renderer& r, gfx::draw_command&)override; }; } diff --git a/include/wip/surface.hpp b/include/wip/surface.hpp new file mode 100644 index 0000000..7a1f1d0 --- /dev/null +++ b/include/wip/surface.hpp @@ -0,0 +1,34 @@ +/** + This file is a part of our_dick + Copyright (C) 2022 rexy712 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#ifndef OUR_DICK_GRAPHICS_WIP_SURFACE_HPP +#define OUR_DICK_GRAPHICS_WIP_SURFACE_HPP + +#include "ogl_surface.hpp" + +namespace wip::gfx{ + + class surface : public ogl::surface + { + public: + using ogl::surface::surface; + }; + +} + +#endif diff --git a/makefile b/makefile index c72314c..9848eb0 100644 --- a/makefile +++ b/makefile @@ -19,7 +19,7 @@ ifeq ($(OS),Windows_NT) WINDOWS::=1 endif -SOURCE_DIRS::=src src/audio src/audio/impl src/gfx src/gfx/ogl src/egn src/ttt src/wip +SOURCE_DIRS::=src src/audio src/audio/impl src/gfx src/gfx/ogl src/egn src/ttt src/wip src/util SOURCES::= OBJDIR::=obj DEPDIR::=$(OBJDIR)/dep diff --git a/src/egn/collision.cpp b/src/egn/collision.cpp index dbb66d9..801bca3 100644 --- a/src/egn/collision.cpp +++ b/src/egn/collision.cpp @@ -108,7 +108,7 @@ namespace egn{ //contained within the rectangle. Otherwise, we must project the point onto the rectangle's border. //If not in the rectangle, we can have 1 or 2 candidate edges to project onto. We want the closest one //to the input point. - math::vec3f cand1, cand2; + //math::vec3f cand1, cand2; /* now we divide the plane into a voronoi diagram where each region is closest diff --git a/src/egn/game.cpp b/src/egn/game.cpp index b7beb5d..295dd40 100644 --- a/src/egn/game.cpp +++ b/src/egn/game.cpp @@ -71,10 +71,6 @@ namespace egn{ } void game::render(void){ m_window.make_current(); - m_window.framebuffer().bind(); - m_window.framebuffer().clear_color_buffer(); - m_window.framebuffer().clear_depth_buffer(); - m_states_manager.render(); m_window.swap_buffers(); @@ -101,12 +97,13 @@ namespace egn{ void game::on_notify(const game_state_event&){} - gfx::resource_manager& game::gfx_resource_manager(void){ - return m_window.resource_man(); + wip::gfx::renderer& game::renderer(void){ + return m_renderer; } - const gfx::resource_manager& game::gfx_resource_manager(void)const{ - return m_window.resource_man(); + const wip::gfx::renderer& game::renderer(void)const{ + return m_renderer; } + void game::push_state(std::unique_ptr&& state){ m_states_manager.push_state(std::move(state)); } diff --git a/src/egn/game_state.cpp b/src/egn/game_state.cpp index 01fdd42..1adc13a 100644 --- a/src/egn/game_state.cpp +++ b/src/egn/game_state.cpp @@ -17,6 +17,7 @@ */ #include "egn/game_state.hpp" +#include "egn/game.hpp" #include "egn/input.hpp" #include "config.hpp" @@ -72,4 +73,11 @@ namespace egn{ game_state_iface::game_state_iface(game* owner): m_owner(owner){} + wip::gfx::renderer& game_state_iface::renderer(void){ + return m_owner->renderer(); + } + const wip::gfx::renderer& game_state_iface::renderer(void)const{ + return m_owner->renderer(); + } + } diff --git a/src/gfx/ogl/buffer_map.cpp b/src/gfx/ogl/buffer_map.cpp index e31573b..e76be6c 100644 --- a/src/gfx/ogl/buffer_map.cpp +++ b/src/gfx/ogl/buffer_map.cpp @@ -27,7 +27,7 @@ namespace gfx::ogl{ scoped_buffer_map::scoped_buffer_map(GLuint bid, buffer::maptype m): m_buffer(bid) { - debug_print_verbose("Mapping vertex buffer object %u\n", bid); + debug_print_verbose("Mapping buffer object %u\n", bid); m_data = reinterpret_cast(glMapNamedBuffer(m_buffer, static_cast(m))); } scoped_buffer_map::scoped_buffer_map(scoped_buffer_map&& m): @@ -35,7 +35,7 @@ namespace gfx::ogl{ m_buffer(std::exchange(m.m_buffer, 0)){} scoped_buffer_map::~scoped_buffer_map(void){ if(m_data){ - debug_print_verbose("Unmapping vertex buffer object %u\n", m_buffer); + debug_print_verbose("Unmapping buffer object %u\n", m_buffer); glUnmapNamedBuffer(m_buffer); } } diff --git a/src/gfx/ogl/rbo.cpp b/src/gfx/ogl/rbo.cpp index a451c45..7913d00 100644 --- a/src/gfx/ogl/rbo.cpp +++ b/src/gfx/ogl/rbo.cpp @@ -19,6 +19,8 @@ #include "gfx/ogl/rbo.hpp" #include //swap, exchange +#include "config.hpp" + namespace gfx::ogl{ rbo::rbo(GLsizei width, GLsizei height, GLenum format, GLsizei samples): @@ -60,11 +62,13 @@ namespace gfx::ogl{ } void rbo::resize(GLsizei w, GLsizei h){ + debug_print_warn("Resizing rbo!\n"); m_width = w; m_height = h; glNamedRenderbufferStorageMultisample(m_buffer, m_samples, m_format, m_width, m_height); } void rbo::resize(GLsizei w, GLsizei h, GLenum format, GLsizei samples){ + debug_print_warn("Resizing rbo!\n"); m_width = w; m_height = h; m_format = format; @@ -72,6 +76,7 @@ namespace gfx::ogl{ glNamedRenderbufferStorageMultisample(m_buffer, m_samples, m_format, m_width, m_height); } void rbo::reformat(GLenum format){ + debug_print_warn("Changing rbo format!\n"); m_format = format; glNamedRenderbufferStorageMultisample(m_buffer, m_samples, m_format, m_width, m_height); } diff --git a/src/gfx/ogl/shader_program.cpp b/src/gfx/ogl/shader_program.cpp index 9f55e43..edfb4b4 100644 --- a/src/gfx/ogl/shader_program.cpp +++ b/src/gfx/ogl/shader_program.cpp @@ -368,10 +368,6 @@ namespace gfx::ogl{ t.bind_unit(tex_unit); glProgramUniform1i(m_shader_id, m_location, tex_unit); } - void uniform::set(const weak_texture& t, GLuint tex_unit){ - t.bind_unit(tex_unit); - glProgramUniform1i(m_shader_id, m_location, tex_unit); - } void uniform::set(const vec2f& v){ glProgramUniform2fv(m_shader_id, m_location, 1, v); diff --git a/src/gfx/ogl/texture.cpp b/src/gfx/ogl/texture.cpp index a40d074..dc9fa9c 100644 --- a/src/gfx/ogl/texture.cpp +++ b/src/gfx/ogl/texture.cpp @@ -301,9 +301,6 @@ namespace gfx::ogl{ void texture::bind_unit(GLuint tunit)const{ glBindTextureUnit(tunit, m_tex_id); } - weak_texture texture::create_handle(void)const{ - return weak_texture(*this); - } bool texture::create_texture_storage_(void){ switch(m_format){ @@ -524,32 +521,4 @@ namespace gfx::ogl{ return true; } - - - weak_texture::weak_texture(GLuint tex): - m_texture(tex){} - weak_texture::weak_texture(const texture& tex): - m_texture(tex.raw()){} - - GLuint weak_texture::raw(void)const{ - return m_texture; - } - GLsizei weak_texture::get_width(void)const{ - GLint retval; - glGetTextureLevelParameteriv(m_texture, 0, GL_TEXTURE_WIDTH, &retval); - return retval; - } - GLsizei weak_texture::get_height(void)const{ - GLint retval; - glGetTextureLevelParameteriv(m_texture, 0, GL_TEXTURE_HEIGHT, &retval); - return retval; - } - - void weak_texture::bind(GLuint target)const{ - glBindTexture(target, m_texture); - } - void weak_texture::bind_unit(GLuint tunit)const{ - glBindTextureUnit(tunit, m_texture); - } - } diff --git a/src/gfx/ogl/window.cpp b/src/gfx/ogl/window.cpp index c1e31e4..8668c37 100644 --- a/src/gfx/ogl/window.cpp +++ b/src/gfx/ogl/window.cpp @@ -140,15 +140,19 @@ static void enable_opengl_debug_context(void){ return false; } +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstringop-truncation" +#endif static char* copy_title(const char* src, size_t titlelen){ char* dest = new char[titlelen + 1]; strncpy(dest, src, titlelen); dest[titlelen] = 0; return dest; } +#if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop +#endif window::window(int width, int height, const char* title, bool makecurrent): window(s_default_cver_maj, s_default_cver_min, width, height, title, makecurrent){} @@ -209,7 +213,6 @@ static void enable_opengl_debug_context(void){ debug_print("OpenGL debug context is disabled\n"); #endif glfwMakeContextCurrent(m_window); - m_root_fbo.bind(); glViewport(0, 0, width, height); set_swap_interval(m_swap_interval); @@ -270,7 +273,6 @@ static void enable_opengl_debug_context(void){ #endif glfwMakeContextCurrent(m_window); - m_root_fbo.bind(); glViewport(0, 0, size.x(), size.y()); set_swap_interval(w.m_swap_interval); @@ -328,19 +330,6 @@ static void enable_opengl_debug_context(void){ m_title = nullptr; } - resource_manager& window::resource_man(void){ - return m_resources; - } - const resource_manager& window::resource_man(void)const{ - return m_resources; - } - fbo& window::framebuffer(void){ - return m_root_fbo; - } - const fbo& window::framebuffer(void)const{ - return m_root_fbo; - } - void window::set_size(const math::vec2i& v){ set_size(v.x(), v.y()); } diff --git a/src/gfx/resource_manager.cpp b/src/gfx/resource_manager.cpp deleted file mode 100644 index 325a962..0000000 --- a/src/gfx/resource_manager.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/** - This file is a part of our_dick - Copyright (C) 2022 rexy712 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -#include "gfx/resource_manager.hpp" - -namespace gfx{ - - bool resource_manager::has_texture_array(const char* key)const{ - return m_texture_arrays.has_value(key); - } - auto resource_manager::get_texture_array(const char* file) -> container_type::node{ - return m_texture_arrays.get_value(file); - } - bool resource_manager::erase_texture_array(const char* key){ - return m_texture_arrays.erase_value(key); - } - - bool resource_manager::has_texture(const char* key)const{ - return m_textures.has_value(key); - } - auto resource_manager::get_texture(const char* file) -> container_type::node{ - return m_textures.get_value(file); - } - bool resource_manager::erase_texture(const char* key){ - return m_textures.erase_value(key); - } - - bool resource_manager::has_font(const char* key)const{ - return m_fonts.has_value(key); - } - auto resource_manager::get_font(const char* file) -> container_type::node{ - return m_fonts.get_value(file); - } - bool resource_manager::erase_font(const char* key){ - return m_fonts.erase_value(key); - } - - bool resource_manager::has_shader(const char* key)const{ - return m_shaders.has_value(key); - } - auto resource_manager::get_shader(const char* key) -> container_type::node{ - return m_shaders.get_value(key); - } - bool resource_manager::erase_shader(const char* key){ - return m_shaders.erase_value(key); - } - -} diff --git a/src/ttt/board.cpp b/src/ttt/board.cpp index fcc0e01..5fc77dd 100644 --- a/src/ttt/board.cpp +++ b/src/ttt/board.cpp @@ -32,7 +32,7 @@ const math::vec4f& tile::get_color(void)const{ return m_color_filter; } -board::board(gfx::resource_manager& resman): +board::board(wip::gfx::renderer& resman): m_tiles(new tile[9]), m_gfx(new board_gfx(resman)) { diff --git a/src/ttt/board_gfx.cpp b/src/ttt/board_gfx.cpp index f928935..5a42606 100644 --- a/src/ttt/board_gfx.cpp +++ b/src/ttt/board_gfx.cpp @@ -19,10 +19,10 @@ #include "ttt/board_gfx.hpp" #include "ttt/board.hpp" -board_gfx::board_gfx(gfx::resource_manager& resman): +board_gfx::board_gfx(wip::gfx::renderer& resman): m_vbo((16 * sizeof(float) + 4 * sizeof(float) + 1 * sizeof(int)) * 9, gfx::ogl::buffer::usage::DYNAMIC_DRAW) { - auto result = resman.emplace_texture_array("board_textures", 3); + auto result = resman.texture_arrays().emplace_value("board_textures", 3); m_textures = std::move(result.first); if(result.second){ (*m_textures)[0].set_image(egn::image("assets/images/blank.jpg", true)); diff --git a/src/ttt/main_renderer.cpp b/src/ttt/main_renderer.cpp index a9855b0..8c03153 100644 --- a/src/ttt/main_renderer.cpp +++ b/src/ttt/main_renderer.cpp @@ -28,23 +28,26 @@ #define MAX_WIDTH 3840 #define MAX_HEIGHT 2160 -main_renderer::main_renderer(gfx::resource_manager& res, int width, int height): +main_renderer::main_renderer(wip::gfx::renderer& res, int width, int height): m_fb(MAX_WIDTH, MAX_HEIGHT), m_primary_fb(util::no_initialize), m_vbo(s_vertices, sizeof(s_vertices), gfx::ogl::buffer::usage::DYNAMIC_DRAW), m_board_vbo((16*sizeof(float)+sizeof(int)+4*sizeof(float)) * 9, gfx::ogl::buffer::usage::DYNAMIC_DRAW) { - m_square_shader = res.emplace_shader("square_shader", util::make_deferred(square_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT), - util::make_deferred(square_shader::geometry_shader_text, gfx::ogl::shader::type::GEOMETRY), - util::make_deferred(square_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX)).first; + auto vert = res.shaders().emplace_value("square_shader_vert", square_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX).first; + auto frag = res.shaders().emplace_value("square_shader_frag", square_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT).first; + auto geom = res.shaders().emplace_value("square_shader_geom", square_shader::geometry_shader_text, gfx::ogl::shader::type::GEOMETRY).first; + m_square_shader = res.shader_programs().emplace_value("square_shader", *vert, *frag, *geom).first; + if(m_square_shader->has_link_error()){ debug_print_error("%s\n", m_square_shader->get_error().c_str()); } m_square_shader->get_uniform("vp_mat").set(math::mat4f{}); - m_screen_shader = res.emplace_shader("screen_shader", util::make_deferred(screen_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT), - util::make_deferred(screen_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX)).first; + vert = res.shaders().emplace_value("screen_shader_vert", screen_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX).first; + frag = res.shaders().emplace_value("screen_shader_frag", screen_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT).first; + m_screen_shader = res.shader_programs().emplace_value("screen_shader", *vert, *frag).first; m_screen_shader->get_uniform("vp_mat").set(math::mat4f{}); m_vao.bind_buffer(m_vbo, 0, 0, sizeof(vertex)); diff --git a/src/ttt/pause_state.cpp b/src/ttt/pause_state.cpp index 1231439..8ae9e07 100644 --- a/src/ttt/pause_state.cpp +++ b/src/ttt/pause_state.cpp @@ -19,11 +19,17 @@ #include "ttt/pause_state.hpp" #include "egn/game.hpp" #include "util/deferred.hpp" +#include "egn/image.hpp" #include "gfx/ogl/gl_include.hpp" //TODO +#include "wip/base_shader.hpp" +#include "wip/square.hpp" #include "config.hpp" +#include +#include //pair + static egn::font_atlas generate_font_atlas_from_file(const char* file, int target_height){ egn::font f(file); return f.generate_atlas(0, target_height, std::pair{' ', ('~' - ' ')}); @@ -32,14 +38,34 @@ static egn::font_atlas generate_font_atlas_from_file(const char* file, int targe pause_state::pause_state(egn::game& owner, egn::game_state_iface* under): game_state_iface(&owner), m_under_state(under), - m_screen_renderer(owner.gfx_resource_manager(), owner.get_width(), owner.get_height(), owner.gfx_resource_manager().emplace_texture("pause_screen", util::make_deferred("assets/images/pause.png", true)).first){} + m_screen_renderer(owner.renderer(), owner.get_width(), owner.get_height(), owner.renderer().textures().emplace_value("pause_screen", util::make_deferred("assets/images/pause.png", true)).first), + m_main_camera(10, 10, 0.1, 50), + m_elapsed_time(0) +{ + //TODO hide GL implementation details somewhere else + auto vert = renderer().shaders().emplace_value("base_vert", wip::gfx::base_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX).first; + auto frag = renderer().shaders().emplace_value("base_frag", wip::gfx::base_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT).first; + auto shader = renderer().shader_programs().emplace_value("base_shader", *vert, *frag).first; + auto tex = renderer().textures().emplace_value("test_texture", util::make_deferred("assets/images/x.jpg", true)).first; + auto material = renderer().materials().emplace_value("test_material", shader).first; + material->diffuse_texture = tex; + tex = renderer().textures().emplace_value("test_texture2", util::make_deferred("assets/images/o.jpg", true)).first; + material = renderer().materials().emplace_value("test_material2", shader).first; + material->diffuse_texture = tex; + + auto mesh = renderer().meshs().emplace_value("square_mesh", std::vector(wip::square::mesh_vertices, wip::square::mesh_vertices+6)).first; + + m_square.reset(new wip::square(mesh, material)); + + m_main_camera.set_position({0, 0, 5}); + renderer().set_camera(m_main_camera.get_view_matrix(), m_main_camera.get_projection_matrix()); +} void pause_state::enter(){ const float w = m_owner->get_width(); const float h = m_owner->get_height(); - m_screen_renderer.resize_viewport(w, h); - + renderer().set_viewport({0, 0, w, h}); } void pause_state::leave(){} void pause_state::handle_input(const egn::input_event& event){ @@ -54,11 +80,20 @@ void pause_state::handle_input(const egn::input_event& event){ }else if(event.ev_type == egn::input_event::type::RESIZE){ m_under_state->handle_input(event); m_screen_renderer.resize_viewport(event.x, event.y); + renderer().set_viewport({0, 0, event.x, event.y}); + } +} +void pause_state::update(double dtime){ + m_elapsed_time += dtime; + if(m_elapsed_time > 1){ + m_elapsed_time -= 1; + m_square->m_material = renderer().materials().get_value(rand() % 2 == 0 ? "test_material" : "test_material2"); } } -void pause_state::update(double){} void pause_state::render(){ m_under_state->render(); - scene tmp; - m_screen_renderer.render(tmp); + renderer().bind_default_surface(); + //renderer().clear_current_surface(); + m_square->submit_render(renderer()); + renderer().render(); } diff --git a/src/ttt/play_state.cpp b/src/ttt/play_state.cpp index 4b9df8d..a4c9fc1 100644 --- a/src/ttt/play_state.cpp +++ b/src/ttt/play_state.cpp @@ -28,12 +28,12 @@ play_state::play_state(egn::game& owner, int width, int height): game_state_iface(&owner), - m_main_renderer(owner.gfx_resource_manager(), width, height), + m_main_renderer(owner.renderer(), width, height), m_current_player(rand() % 2) { debug_print("First player chosen is %c\n", m_current_player ? 'X' : 'O'); - m_scene.objects.emplace_back(new board(m_owner->gfx_resource_manager())); + m_scene.objects.emplace_back(new board(m_owner->renderer())); m_scene.renderables.emplace_back(static_cast(m_scene.objects[0].get())); m_scene.cameras.emplace_back(new egn::ortho_camera(10 * ((float)width / height), 10, 0.1, 50)); @@ -131,7 +131,7 @@ void play_state::handle_input(const egn::input_event& ev){ } } } -void play_state::update(double time_diff){ +void play_state::update(double /*time_diff*/){ } void play_state::render(){ m_main_renderer.set_vp_matrix(m_main_camera->get_projection_matrix() * m_main_camera->get_view_matrix()); diff --git a/src/ttt/screen_renderer.cpp b/src/ttt/screen_renderer.cpp index 935eede..20f49c1 100644 --- a/src/ttt/screen_renderer.cpp +++ b/src/ttt/screen_renderer.cpp @@ -28,14 +28,15 @@ #include "ttt/font_shader.hpp" #include "math/debug.hpp" -screen_renderer::screen_renderer(gfx::resource_manager& res, int width, int height, const std::shared_ptr& base_tex): +screen_renderer::screen_renderer(wip::gfx::renderer& res, int width, int height, const std::shared_ptr& base_tex): m_vbo(s_vertices, sizeof(s_vertices), gfx::ogl::buffer::usage::DYNAMIC_DRAW), m_texture(base_tex), m_screen_width(width), m_screen_height(height) { - m_screen_shader = res.emplace_shader("screen_shader", util::make_deferred(screen_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX), - util::make_deferred(screen_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT)).first; + auto vert = res.shaders().emplace_value("screen_shader_vert", screen_shader::vertex_shader_text, gfx::ogl::shader::type::VERTEX).first; + auto frag = res.shaders().emplace_value("screen_shader_frag", screen_shader::fragment_shader_text, gfx::ogl::shader::type::FRAGMENT).first; + m_screen_shader = res.shader_programs().emplace_value("screen_shader", *vert, *frag).first; if(m_screen_shader->has_link_error()){ debug_print_error("%s\n", m_screen_shader->get_error().c_str()); } diff --git a/src/util/demangle.cpp b/src/util/demangle.cpp new file mode 100644 index 0000000..b930e0f --- /dev/null +++ b/src/util/demangle.cpp @@ -0,0 +1,48 @@ +/** + This file is a part of our_dick + Copyright (C) 2022 rexy712 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#include "config.hpp" + +#if defined(OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT) && (defined(__GNUC__) && !defined(_MSC_VER)) + + #include //free + #include + #include + #include + + namespace util{ + std::string demangle(const char* name){ + int status = 0; + std::unique_ptr res{ + abi::__cxa_demangle(name, nullptr, nullptr, &status), + std::free + }; + return (status == 0) ? res.get() : name; + } + } + +#else + + #include + namespace util{ + std::string demangle(const char* name){ + return name; + } + } + +#endif diff --git a/src/wip/ogl_mesh.cpp b/src/wip/ogl_mesh.cpp index e3bfbfb..49d653c 100644 --- a/src/wip/ogl_mesh.cpp +++ b/src/wip/ogl_mesh.cpp @@ -25,7 +25,7 @@ namespace wip::gfx::ogl{ static constexpr size_t vertex_position_loc = 0; - static constexpr size_t vertex_tex_coord_loc = 0; + static constexpr size_t vertex_tex_coord_loc = 1; static void setup_mesh_attributes_(::gfx::ogl::vao& v){ auto attrib = v.get_attribute(vertex_position_loc); @@ -44,12 +44,15 @@ namespace wip::gfx::ogl{ m_buffer(sizeof(vertex) * m_num_vertices, ::gfx::ogl::buffer::usage::STATIC_DRAW), m_attributes() { + m_buffer.buffer(vertices.data(), vertices.size() * sizeof(vertex)); + m_attributes.bind_buffer(m_buffer, 0, 0, sizeof(vertex)); + setup_mesh_attributes_(m_attributes); } void mesh::bind(void){ m_attributes.bind(); } - void mesh::render(::wip::gfx::renderer& r, material&){ + void mesh::render(::wip::gfx::renderer& r){ r.draw_tris(0, m_num_vertices); } diff --git a/src/wip/ogl_renderer.cpp b/src/wip/ogl_renderer.cpp index 65b5eea..c83fee3 100644 --- a/src/wip/ogl_renderer.cpp +++ b/src/wip/ogl_renderer.cpp @@ -24,24 +24,39 @@ namespace wip::gfx::ogl{ void renderer::set_viewport(const math::vec4f& vp){ glViewport(vp.x(), vp.y(), vp.z(), vp.w()); } + void renderer::set_model_matrix(const math::mat4f& mat){ + m_camera_uniform.set<1>(mat); + } void renderer::set_camera(const math::mat4f& view, const math::mat4f& proj){ m_camera_uniform.set<0>(proj * view); } + void renderer::bind_default_surface(void){ + glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + void renderer::clear_current_surface(void){ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + + void renderer::draw_tris(int offset, int vertex_count){ glDrawArrays(GL_TRIANGLES, offset, vertex_count); } void renderer::process_command(draw_command& c){ + if(!c.surf){ + bind_default_surface(); + }else{ + c.surf->bind(); + } if(c.msh){ c.msh->bind(); } if(c.mat){ ::gfx::ogl::shader_program& shade = *c.mat->shader; shade.use(); - shade.get_uniform_block("vp_matrix").set_binding(0, m_camera_uniform); + shade.get_uniform_block("mvp_matrix").set_binding(0, m_camera_uniform); c.mat->bind(); - - //static_cast is fine; we know this is always the base class of renderer if we made it to this point - c.msh->render(static_cast<::wip::gfx::renderer&>(*this), *c.mat); } + //static_cast is fine; we know this is always the base class of renderer if we made it to this point + c.instance->render(static_cast<::wip::gfx::renderer&>(*this), c); } } diff --git a/src/wip/ogl_resource_manager.cpp b/src/wip/ogl_resource_manager.cpp index 3b68736..2d69304 100644 --- a/src/wip/ogl_resource_manager.cpp +++ b/src/wip/ogl_resource_manager.cpp @@ -20,6 +20,10 @@ namespace wip::gfx::ogl{ + resource_manager::resource_manager(void){ + m_framebuffers.emplace_value("default"); + } + auto resource_manager::shader_programs(void)const -> const container_type<::gfx::ogl::shader_program>&{ return m_shader_programs; } @@ -44,5 +48,11 @@ namespace wip::gfx::ogl{ auto resource_manager::texture_arrays(void) -> container_type<::gfx::ogl::texture_array>&{ return m_texture_arrays; } + auto resource_manager::framebuffers(void)const -> const container_type<::gfx::ogl::fbo>&{ + return m_framebuffers; + } + auto resource_manager::framebuffers(void) -> container_type<::gfx::ogl::fbo>&{ + return m_framebuffers; + } } diff --git a/src/wip/ogl_surface.cpp b/src/wip/ogl_surface.cpp new file mode 100644 index 0000000..8e605af --- /dev/null +++ b/src/wip/ogl_surface.cpp @@ -0,0 +1,29 @@ +/** + This file is a part of our_dick + Copyright (C) 2022 rexy712 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#include "wip/ogl_surface.hpp" + +namespace wip::gfx::ogl{ + + surface::surface(const std::shared_ptr<::gfx::ogl::fbo>& fb): + framebuffer(fb){} + + void surface::bind(void){ + framebuffer->bind(); + } +} diff --git a/src/wip/renderer.cpp b/src/wip/renderer.cpp index b44dfde..3a4bd11 100644 --- a/src/wip/renderer.cpp +++ b/src/wip/renderer.cpp @@ -18,8 +18,16 @@ #include "wip/renderer.hpp" +#include "gfx/ogl/gl_include.hpp" //TODO + namespace wip::gfx{ + renderer::renderer(void): + ogl::renderer() + { + m_surfaces.emplace_value("default", m_framebuffers.get_value("default")); + } + void renderer::submit_command(const draw_command& c){ m_commands.push_back(c); } @@ -35,6 +43,12 @@ namespace wip::gfx{ auto renderer::materials(void) -> container_type&{ return m_materials; } + auto renderer::surfaces(void)const -> const container_type&{ + return m_surfaces; + } + auto renderer::surfaces(void) -> container_type&{ + return m_surfaces; + } void renderer::render(void){ for(auto& command : m_commands){ process_command(command); diff --git a/src/wip/square.cpp b/src/wip/square.cpp new file mode 100644 index 0000000..2b95478 --- /dev/null +++ b/src/wip/square.cpp @@ -0,0 +1,38 @@ +/** + This file is a part of our_dick + Copyright (C) 2022 rexy712 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#include "wip/square.hpp" + +#include "math/mat.hpp" + +namespace wip{ + + square::square(const std::shared_ptr& msh, const std::shared_ptr& mat): + m_mesh(msh), + m_material(mat){} + + void square::submit_render(gfx::renderer& r){ + r.submit_command({this, m_material.get(), m_mesh.get(), nullptr, 0, nullptr}); + } + void square::render(gfx::renderer& r, gfx::draw_command&){ + r.set_model_matrix(math::mat4f(math::id_initialize)); + m_mesh->render(r); + } + + +}