diff --git a/include/engine/flat_object.hpp b/include/engine/flat_object.hpp deleted file mode 100644 index 1192e5e..0000000 --- a/include/engine/flat_object.hpp +++ /dev/null @@ -1,62 +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_ENGINE_FLAT_OBJECT_HPP -#define OUR_DICK_ENGINE_FLAT_OBJECT_HPP - -#include "math/vec.hpp" - -namespace egn{ - - namespace flat{ - - class object_base - { - protected: - math::vec2f m_position; - math::vec2f m_scale; - float m_orientation; - - public: - object_base(void) = default; - object_base(const math::vec2f& position, float orientation = 0); - object_base(const object_base&) = default; - object_base(object_base&&) = default; - ~object_base(void) = default; - - object_base& operator=(const object_base&) = default; - object_base& operator=(object_base&&) = default; - - void translate(const math::vec2f& distance); - void rotate(float distance); - void scale(const math::vec2f& distance); - void look_at(const math::vec2f& target); - - void set_position(const math::vec2f& pos); - void set_orientation(float orient); - void set_scale(const math::vec2f& scale); - - const math::vec2f& position(void)const; - float orientation(void)const; - const math::vec2f& scale(void)const; - }; - } - -} - -#endif diff --git a/include/engine/menu.hpp b/include/engine/menu.hpp deleted file mode 100644 index 701ac61..0000000 --- a/include/engine/menu.hpp +++ /dev/null @@ -1,105 +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_ENGINE_MENU_HPP -#define OUR_DICK_ENGINE_MENU_HPP - -#include "camera.hpp" -#include "font.hpp" -#include "menu_renderer.hpp" - -#include "math/vec.hpp" - -#include -#include //unique_ptr, shared_ptr - -namespace egn::gui{ - - class menu; - - class menu_item - { - protected: - menu* m_owner = nullptr; - protected: - menu_item(menu* owner); - public: - menu_item(const menu_item&) = default; - menu_item(menu_item&&) = default; - virtual ~menu_item(void) = default; - - menu_item& operator=(const menu_item&) = default; - menu_item& operator=(menu_item&&) = default; - - void set_owner(menu* owner); - - virtual void render(menu_renderer& r) = 0; - - virtual menu_item* clone(void)const = 0; - }; - - struct menu_node{ - math::vec2f scale; - }; - - struct position_node : public menu_node{ - std::unique_ptr item; - math::vec2f position; - }; - - class menu - { - private: - std::vector m_items; - std::shared_ptr m_default_font; - flat_camera m_camera; - - public: - menu(void); - menu(const menu&) = default; - menu(menu&&) = default; - ~menu(void) = default; - - menu& operator=(const menu&) = default; - menu& operator=(menu&&) = default; - - position_node& add_item(const menu_item& m); - template - position_node& emplace_item(Args&&... args); - - void set_default_font(const std::shared_ptr& font); - const std::shared_ptr& get_default_font(void)const; - - void resize(float w, float h); - - void render(menu_renderer& r); - }; - - - template - position_node& menu::emplace_item(Args&&... args){ - position_node tmp; - tmp.scale = math::vec2f{1, 1}; - tmp.item = std::unique_ptr(new T{this, std::forward(args)...}); - tmp.position = math::vec2f{0, 0}; - return m_items.emplace_back(std::move(tmp)); - } - -} - -#endif diff --git a/include/engine/menu_renderer.hpp b/include/engine/menu_renderer.hpp deleted file mode 100644 index bbd4410..0000000 --- a/include/engine/menu_renderer.hpp +++ /dev/null @@ -1,69 +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_ENGINE_MENU_RENDERER_HPP -#define OUR_DICK_ENGINE_MENU_RENDERER_HPP - -#include "math/vec.hpp" - -#include "graphics/resource_manager.hpp" -#include "graphics/shader_program.hpp" -#include "graphics/fbo.hpp" -#include "graphics/ubo.hpp" - -namespace egn{ - - class renderer - { - private: - math::vec4f m_saved_viewport{0, 0, 0, 0}; - - public: - void set_viewport(float x, float y, float w, float h); - void resize_viewport(float w, float h); - void reposition_viewport(float x, float y); - void apply_viewport(void); - }; - - class menu_renderer : public renderer - { - private: - gfx::ubo m_vp_matrix; - std::shared_ptr m_font_shader; - public: - menu_renderer(gfx::resource_manager& resman); - menu_renderer(const menu_renderer&) = default; - menu_renderer(menu_renderer&&) = default; - ~menu_renderer(void) = default; - - menu_renderer& operator=(const menu_renderer&) = default; - menu_renderer& operator=(menu_renderer&&) = default; - - void set_font(const gfx::texture& atlas); - void set_position(const math::vec2f& pos); - void set_vp_matrix(const math::mat4f& matrix); - - void begin(void); - void draw_text(int count); - void draw_text_to(gfx::fbo& target, int count); - void end(void); - }; - -} - -#endif diff --git a/include/engine/text.hpp b/include/engine/text.hpp deleted file mode 100644 index 6d2bc72..0000000 --- a/include/engine/text.hpp +++ /dev/null @@ -1,76 +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_ENGINE_TEXT_HPP -#define OUR_DICK_ENGINE_TEXT_HPP - -#include "graphics/vbo.hpp" -#include "graphics/vao.hpp" -#include "graphics/texture.hpp" -#include "font.hpp" -#include "math/vec.hpp" -#include "flat_object.hpp" - -#include -#include -#include - -class font_renderer; - -namespace egn{ - - class text_gfx - { - private: - static constexpr int s_size_per_char = sizeof(GLfloat) * 12; - private: - gfx::weak_texture m_atlas; - egn::font_atlas::map_type m_font; - gfx::vbo m_vbo; - gfx::vao m_vao; - size_t m_original_height; - float m_scale; - - public: - text_gfx(const egn::font_atlas& font, int target_px, size_t initsize = 0); - text_gfx(const egn::font_atlas& font, int target_px, const char* t); - - void set_text(const char* string); - - void render(font_renderer& sh, const math::vec2f& pos); - }; - - - - class text : public flat::object_base - { - private: - text_gfx m_gfx; - std::string m_text; - - public: - text(const egn::font_atlas& font, const char* string, int target_px, float target_x, float target_y); - - void set_text(const char* string); - - void render(font_renderer& sh); - }; - -} - -#endif diff --git a/include/engine/text_field.hpp b/include/engine/text_field.hpp deleted file mode 100644 index ea0067e..0000000 --- a/include/engine/text_field.hpp +++ /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 . -*/ - -#ifndef OUR_DICK_ENGINE_TEXT_FIELD_HPP -#define OUR_DICK_ENGINE_TEXT_FIELD_HPP - -#include "menu.hpp" - -#include "graphics/text_field_view.hpp" - -#include "engine/font.hpp" - -#include -#include //shared_ptr - -namespace egn::gui{ - - struct text_field_model{ - std::string text; - std::shared_ptr font; - }; - - class text_field : public menu_item - { - private: - text_field_model m_model; - gfx::text_field_view m_view; - - public: - text_field(menu* m); - text_field(menu* m, const char* data); - text_field(const text_field&); - text_field(text_field&&); - - text_field& operator=(const text_field&) = default; - text_field& operator=(text_field&&) = default; - - const std::string& get_text(void)const; - void set_font(const std::shared_ptr& f); - const std::shared_ptr& get_font(void)const; - - void render(menu_renderer& r)override; - text_field* clone(void)const override; - }; - -} - -#endif diff --git a/include/graphics/text_field_view.hpp b/include/graphics/text_field_view.hpp deleted file mode 100644 index dba86f1..0000000 --- a/include/graphics/text_field_view.hpp +++ /dev/null @@ -1,68 +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_TEXT_FIELD_VIEW_HPP -#define OUR_DICK_GRAPHICS_TEXT_FIELD_VIEW_HPP - -#include "engine/font.hpp" -#include "engine/menu_renderer.hpp" - -#include "vao.hpp" -#include "vbo.hpp" - -#include //shared_ptr - -namespace egn::gui{ - struct text_field_model; -} - -namespace gfx{ - - class text_field_view - { - private: - static constexpr int s_size_per_char = sizeof(float) * 12; - private: - egn::gui::text_field_model* m_model; - gfx::vbo m_buffer; - gfx::vao m_vao; - mutable unsigned char m_dirty_bit:1 = 0; - - public: - text_field_view(egn::gui::text_field_model& m); - text_field_view(egn::gui::text_field_model& m, const char* data); - text_field_view(const text_field_view&); - text_field_view(text_field_view&&) = default; - ~text_field_view(void) = default; - - text_field_view& operator=(const text_field_view&); - text_field_view& operator=(text_field_view&&) = default; - - bool set_text(const char* text); - - void set_model(egn::gui::text_field_model& t); - - void render(egn::menu_renderer& r); - - private: - void init_arrays_(void); - }; - -} - -#endif diff --git a/include/ttt/font_renderer.hpp b/include/ttt/font_renderer.hpp deleted file mode 100644 index a477c25..0000000 --- a/include/ttt/font_renderer.hpp +++ /dev/null @@ -1,53 +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_FONT_RENDERER_HPP -#define OUR_DICK_FONT_RENDERER_HPP - -#include "graphics/vbo.hpp" -#include "graphics/vao.hpp" -#include "graphics/texture.hpp" -#include "math/math.hpp" -#include "graphics/shader_program.hpp" -#include "graphics/resource_manager.hpp" -#include "scene.hpp" - -#include "engine/font.hpp" -#include "engine/text.hpp" - -#include //shared_ptr - -class font_renderer -{ -private: - std::shared_ptr m_font_shader; - int m_screen_width, m_screen_height; - -public: - font_renderer(gfx::resource_manager& res, int width, int height); - - void set_position(const math::vec2f& pos); - void use_texture(const gfx::texture& tex); - void use_texture(const gfx::weak_texture& tex); - void set_aspect(float aspect); - - void begin(void); - void resize_viewport(int width, int height); -}; - -#endif diff --git a/include/ttt/pause_state.hpp b/include/ttt/pause_state.hpp index 6d57e64..1fd027a 100644 --- a/include/ttt/pause_state.hpp +++ b/include/ttt/pause_state.hpp @@ -24,16 +24,11 @@ #include "graphics/texture.hpp" #include "screen_renderer.hpp" -#include "engine/menu.hpp" -#include "engine/menu_renderer.hpp" - class pause_state : public egn::game_state_iface { private: egn::game_state_iface* m_under_state; screen_renderer m_screen_renderer; - egn::menu_renderer m_menu_renderer; - egn::gui::menu m_menu; public: pause_state(egn::game& owner, egn::game_state_iface* under); diff --git a/include/ttt/play_state.hpp b/include/ttt/play_state.hpp index c118307..a09a174 100644 --- a/include/ttt/play_state.hpp +++ b/include/ttt/play_state.hpp @@ -20,7 +20,6 @@ #define OUR_DICK_PLAY_STATE_HPP #include "engine/game_state.hpp" -#include #include "scene.hpp" #include "main_renderer.hpp" diff --git a/include/ttt/text_renderer.hpp b/include/ttt/text_renderer.hpp deleted file mode 100644 index 3d835ed..0000000 --- a/include/ttt/text_renderer.hpp +++ /dev/null @@ -1,28 +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_TEXT_RENDERER_HPP -#define OUR_DICK_TEXT_RENDERER_HPP - -#include "graphics/shader_program.hpp" -#include "graphics/vao.hpp" -#include "graphics/vbo.hpp" -#include "scene.hpp" -#include "engine/resource_manager.hpp" - -#endif diff --git a/include/wip_renderer.hpp b/include/wip_renderer.hpp new file mode 100644 index 0000000..b804558 --- /dev/null +++ b/include/wip_renderer.hpp @@ -0,0 +1,89 @@ +/** + 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_RENDERER_HPP +#define OUR_DICK_RENDERER_HPP + +#include +#include +#include //pair, forward +#include + +#include "math/vec.hpp" + +#include "graphics/gl_include.hpp" + +struct draw_command{ +private: + using uniform_variant = std::variant; + +public: + using framebuffer_type = GLuint; + using shader_type = GLuint; + using vao_type = GLuint; + using uniform_type = GLint; + using uniform_block_type = GLuint; + using binding_type = GLuint; + using shape_type = GLenum; + using texture_type = GLuint; + +public: + framebuffer_type framebuffer; + math::vec4f viewport; + + shader_type shader; + vao_type vertex_arrays; + + shape_type shape; + size_t shape_count; + + std::vector> uniforms; + std::vector> uniform_blocks; + std::vector> texture_binds; + + GLuint clear = 0; +}; + +class wip_renderer +{ +private: + std::queue m_draws; + +public: + wip_renderer(void) = default; + wip_renderer(const wip_renderer&) = default; + wip_renderer(wip_renderer&&) = default; + ~wip_renderer(void) = default; + + wip_renderer& operator=(const wip_renderer&) = default; + wip_renderer& operator=(wip_renderer&&) = default; + + void add_command(const draw_command&); + void add_command(draw_command&&); + template + void emplace_command(Args&&... args); + + void render(void); +}; + +template +void wip_renderer::emplace_command(Args&&... args){ + m_draws.emplace(std::forward(args)...); +} + +#endif diff --git a/src/engine/flat_object.cpp b/src/engine/flat_object.cpp deleted file mode 100644 index 9cf3855..0000000 --- a/src/engine/flat_object.cpp +++ /dev/null @@ -1,74 +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 "engine/flat_object.hpp" -#include "math/math_common.hpp" -#include //signbit, atan - -namespace egn::flat{ - - object_base::object_base(const math::vec2f& position, float orientation): - m_position(position), - m_orientation(orientation){} - - void object_base::translate(const math::vec2f& distance){ - m_position += distance; - } - void object_base::rotate(float distance){ - m_orientation += distance; - } - void object_base::scale(const math::vec2f& distance){ - m_scale += distance; - } - void object_base::look_at(const math::vec2f& target){ - const math::vec2f rel_target = target - m_position; - const float angle = std::atan(rel_target.y() / rel_target.x()); - const int x_sign = std::signbit(rel_target.x()); - const int y_sign = std::signbit(rel_target.y()); - const int quadrant = (x_sign ^ y_sign) + (2 * y_sign); - - //quadrants: - // | - // 1 | 0 - //----------------- - // 2 | 3 - // | - m_orientation = angle + (90.0_deg * quadrant); - } - - void object_base::set_position(const math::vec2f& pos){ - m_position = pos; - } - void object_base::set_orientation(float orient){ - m_orientation = orient; - } - void object_base::set_scale(const math::vec2f& scale){ - m_scale = scale; - } - - const math::vec2f& object_base::position(void)const{ - return m_position; - } - float object_base::orientation(void)const{ - return m_orientation; - } - const math::vec2f& object_base::scale(void)const{ - return m_scale; - } - -} diff --git a/src/engine/menu.cpp b/src/engine/menu.cpp deleted file mode 100644 index 0b90a95..0000000 --- a/src/engine/menu.cpp +++ /dev/null @@ -1,58 +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 "engine/menu.hpp" - -namespace egn::gui{ - - menu_item::menu_item(menu* owner): - m_owner(owner){} - - void menu_item::set_owner(menu* owner){ - m_owner = owner; - } - - - menu::menu(void): - m_camera(100, 100){} - - position_node& menu::add_item(const menu_item& m){ - return m_items.emplace_back(position_node{{math::vec2f{1, 1}}, std::unique_ptr(m.clone()), math::vec2f{0, 0}}); - } - - void menu::set_default_font(const std::shared_ptr& font){ - m_default_font = font; - } - const std::shared_ptr& menu::get_default_font(void)const{ - return m_default_font; - } - - void menu::resize(float w, float h){ - m_camera.set_projection_box(w, h); - } - - void menu::render(menu_renderer& r){ - math::mat4f tmp = m_camera.get_projection_matrix() * m_camera.get_view_matrix(); - r.set_vp_matrix(tmp); - for(auto& node : m_items){ - menu_item& item = (*node.item); - item.render(r); - } - } - -} diff --git a/src/engine/menu_renderer.cpp b/src/engine/menu_renderer.cpp deleted file mode 100644 index c38ef8d..0000000 --- a/src/engine/menu_renderer.cpp +++ /dev/null @@ -1,88 +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 "engine/menu_renderer.hpp" - -#include "graphics/gl_include.hpp" - -#include "ttt/font_shader.hpp" - -namespace egn{ - - void renderer::set_viewport(float x, float y, float w, float h){ - m_saved_viewport[0] = x; - m_saved_viewport[1] = y; - m_saved_viewport[2] = w; - m_saved_viewport[3] = h; - } - void renderer::resize_viewport(float w, float h){ - m_saved_viewport[2] = w; - m_saved_viewport[3] = h; - } - void renderer::reposition_viewport(float x, float y){ - m_saved_viewport[0] = x; - m_saved_viewport[1] = y; - } - - void renderer::apply_viewport(void){ - glViewport(m_saved_viewport[0], m_saved_viewport[1], m_saved_viewport[2], m_saved_viewport[3]); - } - - menu_renderer::menu_renderer(gfx::resource_manager& resman): - m_font_shader(resman.emplace_shader("font_shader", - util::make_deferred(font_shader::vertex_shader_text, gfx::shader::type::VERTEX), - util::make_deferred(font_shader::geometry_shader_text, gfx::shader::type::GEOMETRY), - util::make_deferred(font_shader::fragment_shader_text, gfx::shader::type::FRAGMENT)).first) - { - m_font_shader->get_uniform_block("view_proj_matrix").set_binding(0, m_vp_matrix); - } - - void menu_renderer::set_font(const gfx::texture& atlas){ - m_font_shader->get_uniform("texture1").set(atlas); - } - - void menu_renderer::set_vp_matrix(const math::mat4f& matrix){ - m_vp_matrix.set<0>(matrix); - } - void menu_renderer::set_position(const math::vec2f& pos){ - m_font_shader->get_uniform("start_pos").set(pos); - } - - void menu_renderer::begin(void){ - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glDisable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - apply_viewport(); - } - - void menu_renderer::draw_text(int count){ - m_font_shader->use(); - glDrawArrays(GL_POINTS, 0, count); - } - void menu_renderer::draw_text_to(gfx::fbo& target, int count){ - target.bind(); - target.apply_viewport(); - draw_text(count); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - } - void menu_renderer::end(void){ - } - -} diff --git a/src/engine/text.cpp b/src/engine/text.cpp deleted file mode 100644 index 95026eb..0000000 --- a/src/engine/text.cpp +++ /dev/null @@ -1,107 +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 "engine/text.hpp" -#include "ttt/font_renderer.hpp" - -namespace egn{ - - text_gfx::text_gfx(const egn::font_atlas& font, int target_px, size_t initsize): - m_atlas(font), - m_font(font.metadata()), - m_vbo(initsize * s_size_per_char, gfx::buffer::usage::DYNAMIC_DRAW), - m_original_height(font.glyph_size().y()), - m_scale(((float)target_px) / m_original_height){} - text_gfx::text_gfx(const egn::font_atlas& font, int target_px, const char* string): - text_gfx(font, target_px, strlen(string)) - { - set_text(string); - - //attach a vbo to the vao and assign attribute specs - m_vao.bind_buffer(m_vbo, 0, 0, s_size_per_char); - - auto attrib = m_vao.get_attribute(0); - attrib.set_float_array(4, 0); - attrib.associate_with(0); - attrib.enable(); - - attrib = m_vao.get_attribute(1); - attrib.set_float_array(4, sizeof(GLfloat) * 4); - attrib.associate_with(0); - attrib.enable(); - - attrib = m_vao.get_attribute(2); - attrib.set_float_array(2, sizeof(GLfloat) * 8); - attrib.associate_with(0); - attrib.enable(); - - attrib = m_vao.get_attribute(3); - attrib.set_float_array(2, sizeof(GLfloat) * 10); - attrib.associate_with(0); - attrib.enable(); - } - void text_gfx::set_text(const char* string){ - m_vbo.clear(); - constexpr float tmp_color[] = {1,1,1,1}; - - math::vec2f pos_offset = {0, 0}; - - for(int i = 0;string[i] != 0;++i){ - if(string[i] == '\n'){ - pos_offset.x() = 0; - pos_offset.y() -= m_original_height * m_scale; - continue; - } - const auto ch = m_font[string[i]]; - const math::vec2 letter_size = ch.size * m_scale; - const math::vec2f char_offset = {(ch.bearing.x() * m_scale) + pos_offset.x(), - ((ch.bearing.y() * m_scale) - letter_size.y()) + pos_offset.y()}; - - m_vbo.buffer(ch.texture_coords[1], sizeof(GLfloat) * 2); - m_vbo.buffer(ch.texture_coords[2], sizeof(GLfloat) * 2); - m_vbo.buffer(tmp_color, sizeof(GLfloat) * 4); - m_vbo.buffer(char_offset, sizeof(GLfloat) * 2); - m_vbo.buffer(letter_size, sizeof(GLfloat) * 2); - - pos_offset.x() += (m_scale * ch.advance.x()); - } - } - void text_gfx::render(font_renderer& sh, const math::vec2f& pos){ - m_vao.bind(); - sh.use_texture(m_atlas); - sh.set_position(pos); - glDrawArrays(GL_POINTS, 0, m_vbo.get_size() / s_size_per_char); - } - - - - text::text(const egn::font_atlas& font, const char* string, int target_px, float target_x, float target_y): - flat::object_base(math::vec2f{target_x, target_y}), - m_gfx(font, target_px, string), - m_text(string){} - - void text::set_text(const char* string){ - m_text = string; - m_gfx.set_text(string); - } - - void text::render(font_renderer& f){ - m_gfx.render(f, m_position); - } - -} diff --git a/src/engine/text_field.cpp b/src/engine/text_field.cpp deleted file mode 100644 index 64d27df..0000000 --- a/src/engine/text_field.cpp +++ /dev/null @@ -1,65 +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 "engine/text_field.hpp" - -namespace egn::gui{ - - text_field::text_field(menu* m): - menu_item(m), - m_model{nullptr, m->get_default_font()}, - m_view(m_model){} - - text_field::text_field(menu* m, const char* data): - menu_item(m), - m_model{data, m->get_default_font()}, - m_view(m_model, data){} - text_field::text_field(const text_field& t): - menu_item(t), - m_model(t.m_model), - m_view(t.m_view) - { - m_view.set_model(m_model); - } - text_field::text_field(text_field&& t): - menu_item(std::move(t)), - m_model(std::move(t.m_model)), - m_view(std::move(t.m_view)) - { - m_view.set_model(m_model); - } - - const std::string& text_field::get_text(void)const{ - return m_model.text; - } - void text_field::set_font(const std::shared_ptr& f){ - m_model.font = f; - } - const std::shared_ptr& text_field::get_font(void)const{ - return m_model.font; - } - - void text_field::render(menu_renderer& r){ - m_view.render(r); - } - - text_field* text_field::clone(void)const{ - return new text_field(*this); - } - -} diff --git a/src/graphics/text_field_view.cpp b/src/graphics/text_field_view.cpp deleted file mode 100644 index 8d0c19c..0000000 --- a/src/graphics/text_field_view.cpp +++ /dev/null @@ -1,124 +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 "graphics/text_field_view.hpp" -#include "engine/text_field.hpp" - -#include //strlen - -namespace gfx{ - - text_field_view::text_field_view(egn::gui::text_field_model& m): - m_model(&m), - m_buffer(s_size_per_char * 10, buffer::usage::DYNAMIC_DRAW), - m_dirty_bit(0) - { - init_arrays_(); - } - text_field_view::text_field_view(egn::gui::text_field_model& m, const char* data): - m_model(&m), - m_buffer(s_size_per_char * strlen(data), buffer::usage::DYNAMIC_DRAW) - { - init_arrays_(); - set_text(data); - } - text_field_view::text_field_view(const text_field_view& f): - m_model(nullptr), - m_buffer(f.m_buffer), - m_dirty_bit(f.m_dirty_bit) - { - init_arrays_(); - } - - text_field_view& text_field_view::operator=(const text_field_view& f){ - return (*this = text_field_view(f)); - } - - bool text_field_view::set_text(const char* text){ - m_dirty_bit = 1; - const auto& font = m_model->font; - if(!font){ - m_buffer.initialize(0); - return false; - } - m_buffer.clear(); - constexpr float tmp_color[] = {1, 1, 1, 1}; - - math::vec2f pos_offset = {0, 0}; - - for(int i = 0;text[i] != 0;++i){ - if(text[i] == '\n'){ - pos_offset.x() = 0; - pos_offset.y() -= font->glyph_size().y(); - } - const auto ch = (*font)[text[i]]; - const math::vec2f char_size = ch.size; //convert from size_t to float - const math::vec2f char_offset = {ch.bearing.x() + pos_offset.x(), - ch.bearing.y() - ch.size.y() + pos_offset.y()}; - m_buffer.buffer(ch.texture_coords[1], sizeof(float) * 2); - m_buffer.buffer(ch.texture_coords[2], sizeof(float) * 2); - m_buffer.buffer(tmp_color, sizeof(float) * 4); - m_buffer.buffer(char_offset, sizeof(float) * 2); - m_buffer.buffer(char_size, sizeof(float) * 2); - - pos_offset.x() += ch.advance.x(); - } - m_dirty_bit = 0; - return true; - } - - void text_field_view::set_model(egn::gui::text_field_model& t){ - m_model = &t; - } - - - void text_field_view::render(egn::menu_renderer& r){ - if(m_dirty_bit){ - set_text(m_model->text.c_str()); - } - m_vao.bind(); - r.set_position({10, 10}); - r.set_font(*m_model->font); - r.draw_text(m_model->text.length()); - } - - - void text_field_view::init_arrays_(void){ - m_vao.bind_buffer(m_buffer, 0, 0, s_size_per_char); - - auto attrib = m_vao.get_attribute(0); - attrib.set_float_array(4, 0); - attrib.associate_with(0); - attrib.enable(); - - attrib = m_vao.get_attribute(1); - attrib.set_float_array(4, sizeof(float) * 4); - attrib.associate_with(0); - attrib.enable(); - - attrib = m_vao.get_attribute(2); - attrib.set_float_array(2, sizeof(float) * 8); - attrib.associate_with(0); - attrib.enable(); - - attrib = m_vao.get_attribute(3); - attrib.set_float_array(2, sizeof(float) * 10); - attrib.associate_with(0); - attrib.enable(); - } -} diff --git a/src/ttt/font_renderer.cpp b/src/ttt/font_renderer.cpp deleted file mode 100644 index 14b9041..0000000 --- a/src/ttt/font_renderer.cpp +++ /dev/null @@ -1,70 +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 "ttt/font_renderer.hpp" - -#include "graphics/shader.hpp" -#include "ttt/font_shader.hpp" -#include "util/deferred.hpp" - -#include "engine/font.hpp" - -font_renderer::font_renderer(gfx::resource_manager& res, int width, int height): - m_screen_width(width), m_screen_height(height) -{ - - m_font_shader = res.emplace_shader("font_shader", util::make_deferred(font_shader::vertex_shader_text, gfx::shader::type::VERTEX), - util::make_deferred(font_shader::geometry_shader_text, gfx::shader::type::GEOMETRY), - util::make_deferred(font_shader::fragment_shader_text, gfx::shader::type::FRAGMENT)).first; - - if(m_font_shader->has_link_error()){ - debug_print_error("%s\n", m_font_shader->get_error().c_str()); - } - - resize_viewport(width, height); -} - -void font_renderer::begin(void){ - //Clear the global state to that which this renderer prefers - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glDisable(GL_DEPTH_TEST); - glViewport(0, 0, m_screen_width, m_screen_height); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - m_font_shader->use(); - set_aspect(((float)m_screen_width) / m_screen_height); -} - -void font_renderer::set_position(const math::vec2f& pos){ - m_font_shader->get_uniform("start_pos").set(pos); -} -void font_renderer::use_texture(const gfx::texture& tex){ - m_font_shader->get_uniform("texture1").set(tex); -} -void font_renderer::use_texture(const gfx::weak_texture& tex){ - m_font_shader->get_uniform("texture1").set(tex); -} -void font_renderer::set_aspect(float aspect){ - m_font_shader->get_uniform("aspect").set(aspect); -} - -void font_renderer::resize_viewport(int width, int height){ - m_screen_width = width; - m_screen_height = height; -} diff --git a/src/ttt/pause_state.cpp b/src/ttt/pause_state.cpp index e49cb8f..205e6ab 100644 --- a/src/ttt/pause_state.cpp +++ b/src/ttt/pause_state.cpp @@ -22,8 +22,6 @@ #include "graphics/gl_include.hpp" //TODO -#include "engine/text_field.hpp" - #include "config.hpp" static egn::font_atlas generate_font_atlas_from_file(const char* file, int target_height){ @@ -34,20 +32,13 @@ 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_menu_renderer(owner.gfx_resource_manager()), - m_menu() -{ - m_menu.set_default_font(owner.gfx_resource_manager().emplace_font("pause_screen_font", util::deferred_function(generate_font_atlas_from_file, "assets/hinted-RosaSans-Regular.ttf", 50)).first); - [[maybe_unused]] auto& item = m_menu.emplace_item("test text"); -} + 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){} 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); - //m_menu_renderer.resize_viewport(w, h); } void pause_state::leave(){} @@ -63,7 +54,6 @@ 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); - //m_menu_renderer.resize_viewport(event.x, event.y); } } void pause_state::update(double){} @@ -71,8 +61,4 @@ void pause_state::render(){ m_under_state->render(); scene tmp; m_screen_renderer.render(tmp); - -// m_menu_renderer.begin(); -// m_menu.render(m_menu_renderer); -// m_menu_renderer.end(); } diff --git a/src/ttt/play_state.cpp b/src/ttt/play_state.cpp index c42e362..1b55225 100644 --- a/src/ttt/play_state.cpp +++ b/src/ttt/play_state.cpp @@ -18,7 +18,6 @@ #include "ttt/play_state.hpp" -#include #include "ttt/pause_state.hpp" #include "graphics/gl_include.hpp" //TODO: separate key definitions from GLFW #include "engine/image.hpp" //TODO: move image to engine namespace diff --git a/src/wip_renderer.cpp b/src/wip_renderer.cpp new file mode 100644 index 0000000..7071e2b --- /dev/null +++ b/src/wip_renderer.cpp @@ -0,0 +1,59 @@ +/** + 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_renderer.hpp" + +#include "graphics/shader_program.hpp" +#include "graphics/gl_include.hpp" + +void wip_renderer::add_command(const draw_command& c){ + m_draws.push(c); +} +void wip_renderer::add_command(draw_command&& c){ + m_draws.push(std::move(c)); +} + +void wip_renderer::render(void){ + while(!m_draws.empty()){ + auto& command = m_draws.front(); + + glBindFramebuffer(GL_FRAMEBUFFER, command.framebuffer); + glViewport(command.viewport[0], command.viewport[1], + command.viewport[2], command.viewport[3]); + if(command.clear) + glClear(command.clear); + + glUseProgram(command.shader); + glBindVertexArray(command.vertex_arrays); + for(auto& uniform_pair : command.uniforms){ + gfx::uniform tmp{command.shader, uniform_pair.first}; + std::visit([&](const auto& i){tmp.set(i);}, uniform_pair.second); + } + for(auto& uniform_block_pair : command.uniform_blocks){ + gfx::uniform_block tmp{command.shader, uniform_block_pair.first}; + tmp.set_binding(uniform_block_pair.second); + } + for(auto& texture_bind_pair : command.texture_binds){ + glBindTextureUnit(texture_bind_pair.second, texture_bind_pair.first); + } + glDrawArrays(command.shape, 0, command.shape_count); + + m_draws.pop(); + } +} +