From b564c2b87cbd817af3d0a82428edc9216056bb5e Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 31 Jul 2024 23:34:25 +0200 Subject: [PATCH] minor cleanup --- .clang-format | 3 +- src/CMakeLists.txt | 4 +- src/binding/CMakeLists.txt | 8 +- src/binding/src/script_core.cpp | 31 +-- src/core/include/pw/core/aabb.hpp | 1 + src/core/include/pw/core/matrix.hpp | 5 +- src/core/include/pw/core/matrix_transform.hpp | 14 +- src/core/include/pw/core/point.hpp | 1 + src/core/include/pw/core/primitives.hpp | 7 +- src/core/include/pw/core/vector.hpp | 13 +- src/core/tests/CMakeLists.txt | 1 + src/core/tests/pwcore_test_image.cpp | 16 ++ src/core/tests/pwcore_test_matrix.cpp | 5 + src/core/tests/pwcore_test_mesh.cpp | 71 +---- .../include/pw/geometry/primitives.hpp | 17 +- src/system/src/window.cpp | 12 +- src/visual/include/pw/visual/pipeline.hpp | 36 +-- src/visual/src/context.cpp | 71 ++--- src/visual/src/pipeline.cpp | 243 +++++++----------- 19 files changed, 229 insertions(+), 330 deletions(-) create mode 100644 src/core/tests/pwcore_test_image.cpp diff --git a/.clang-format b/.clang-format index 7917bc4..a730bb5 100644 --- a/.clang-format +++ b/.clang-format @@ -8,5 +8,6 @@ Language: Cpp # Force pointers to the type for C++. DerivePointerAlignment: false PointerAlignment: Left -AlignConsecutiveAssignments: true LambdaBodyIndentation: OuterScope +AlignArrayOfStructures: Left +AlignConsecutiveAssignments: true diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ccd9945..4dab9d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,9 +3,9 @@ add_subdirectory(deps) # build internal core add_subdirectory(core) -add_subdirectory(scene) +# add_subdirectory(scene) # add_subdirectory(system) -# add_subdirectory(io) +add_subdirectory(io) #add_subdirectory(ui) # add_subdirectory(binding) diff --git a/src/binding/CMakeLists.txt b/src/binding/CMakeLists.txt index 4c8b598..acb882a 100644 --- a/src/binding/CMakeLists.txt +++ b/src/binding/CMakeLists.txt @@ -6,10 +6,10 @@ set(hdrs set(srcs src/script.cpp src/script_core.cpp - # src/script_system.cpp - # src/script_io.cpp - # src/script_scene.cpp - # src/script_visual.cpp + src/script_system.cpp + src/script_io.cpp + src/script_scene.cpp + src/script_visual.cpp src/runtime_lua.hpp src/runtime_lua.cpp ) diff --git a/src/binding/src/script_core.cpp b/src/binding/src/script_core.cpp index 84541de..3fa9997 100644 --- a/src/binding/src/script_core.cpp +++ b/src/binding/src/script_core.cpp @@ -41,26 +41,19 @@ void register_core_function(sol::state& lua, sol::table& ns) { ns.set("pi", pw::pi()); - // clang-format off - ns.new_usertype( - "color", sol::call_constructor,sol::constructors(), - "rgba", &color::rgba, - "data", sol::property([](color& c) { return c.rgba.data(); }), - "table", - sol::property( - [](const color& c) { - return sol::as_table( - std::array{ - c.rgba.x(), c.rgba.y(), c.rgba.z(), c.rgba.w()}); - }, - [](color& c,const sol::table& t) { - c = color{.rgba = vector4f{t[0], t[1], t[2], t[3]}}; - }) - - ); - - // clang-format on + "color", sol::call_constructor, sol::constructors(), // + "rgba", &color::rgba, // + "data", sol::property([](color& c) { return c.rgba.data(); }), // + "table", + sol::property([](const color& c) { // + return sol::as_table(std::array{ + c.rgba.x(), c.rgba.y(), c.rgba.z(), c.rgba.w()}); + }, [](color& c, const sol::table& t) { + c = color{ + .rgba = vector4f{t[0], t[1], t[2], t[3]} + }; + })); #if 0 diff --git a/src/core/include/pw/core/aabb.hpp b/src/core/include/pw/core/aabb.hpp index 9ebbcba..f1ea3c3 100644 --- a/src/core/include/pw/core/aabb.hpp +++ b/src/core/include/pw/core/aabb.hpp @@ -23,6 +23,7 @@ #ifndef PW_CORE_AABB_HPP #define PW_CORE_AABB_HPP +#include "primitives.hpp" #include #include diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index 57412ee..e22ff47 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -269,9 +269,12 @@ constexpr auto operator*(const matrix& A, } // -// type aliases +// deduction guides // +// +// type aliases +// template using matrix2x2 = matrix; template using matrix3x3 = matrix; template using matrix4x4 = matrix; diff --git a/src/core/include/pw/core/matrix_transform.hpp b/src/core/include/pw/core/matrix_transform.hpp index faa8bd8..f3ec0b9 100644 --- a/src/core/include/pw/core/matrix_transform.hpp +++ b/src/core/include/pw/core/matrix_transform.hpp @@ -23,10 +23,10 @@ #ifndef PW_CORE_MATRIX_TRANSFORM_HPP #define PW_CORE_MATRIX_TRANSFORM_HPP +#include #include #include #include -#include namespace pw { @@ -51,12 +51,12 @@ struct matrix_transform { const auto C{-(f.z_far + f.z_near) / (f.z_far - f.z_near)}; const auto D{-Scalar{2} * f.z_far * f.z_near / (f.z_far - f.z_near)}; - // clang-format off - return {vector{Sx, 0, A, 0}, - vector{0, Sy, B, 0}, - vector{0, 0, C, D}, - vector{0, 0, -1, Scalar{1}}}; - // clang-format on + return { + vector{Sx, 0, A, 0 }, // + vector{0, Sy, B, 0 }, // + vector{0, 0, C, D }, // + vector{0, 0, -1, Scalar{1}} // + }; } template diff --git a/src/core/include/pw/core/point.hpp b/src/core/include/pw/core/point.hpp index b5cdc5d..9b08bc8 100644 --- a/src/core/include/pw/core/point.hpp +++ b/src/core/include/pw/core/point.hpp @@ -23,6 +23,7 @@ #ifndef PW_CORE_POINT_HPP #define PW_CORE_POINT_HPP +#include #include #include diff --git a/src/core/include/pw/core/primitives.hpp b/src/core/include/pw/core/primitives.hpp index 0116cf3..ed2dc17 100644 --- a/src/core/include/pw/core/primitives.hpp +++ b/src/core/include/pw/core/primitives.hpp @@ -31,7 +31,7 @@ namespace pw { -struct primitives { +struct primitives final { enum struct topology_type { point_list, @@ -47,7 +47,10 @@ struct primitives { patch_list }; - std::vector> vertices{}; + using vertex_type = vector3; + using index_type = std::size_t; + + std::vector vertices{}; std::vector indices{}; topology_type topology{}; }; diff --git a/src/core/include/pw/core/vector.hpp b/src/core/include/pw/core/vector.hpp index 5f055b0..f01a120 100644 --- a/src/core/include/pw/core/vector.hpp +++ b/src/core/include/pw/core/vector.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include namespace pw { @@ -65,6 +66,13 @@ template struct vector final { return std::forward(self).v_[e]; } + template + constexpr auto cast() const noexcept -> vector { + return [this](std::index_sequence) { + return vector{ScalarOut((*this)[Ss])...}; + }(std::make_index_sequence{}); + } + static constexpr auto basis(const auto& d) noexcept { return [&d](std::index_sequence) { return vector{(d == Ss) ? Scalar(1) : Scalar(0)...}; @@ -295,8 +303,9 @@ template struct vector final { // // deduction guide // -template > -vector(T, U...) -> vector; +template +vector(Scalar&&... s) + -> vector, sizeof...(Scalar)>; // // type aliases diff --git a/src/core/tests/CMakeLists.txt b/src/core/tests/CMakeLists.txt index 44a87a2..372a981 100644 --- a/src/core/tests/CMakeLists.txt +++ b/src/core/tests/CMakeLists.txt @@ -13,3 +13,4 @@ make_test(pwcore_test_aabb) make_test(pwcore_test_frustum) make_test(pwcore_test_mesh) make_test(pwcore_test_serialize) +make_test(pwcore_test_image) diff --git a/src/core/tests/pwcore_test_image.cpp b/src/core/tests/pwcore_test_image.cpp new file mode 100644 index 0000000..fcf98df --- /dev/null +++ b/src/core/tests/pwcore_test_image.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +namespace pw { + +struct image_layout { + enum pixel_layout { RGB8, RGBA, LUM, DEPTH }; +}; + +} // namespace pw + +auto main() -> int { + + // pw::image +} diff --git a/src/core/tests/pwcore_test_matrix.cpp b/src/core/tests/pwcore_test_matrix.cpp index 73fa915..a7c5730 100644 --- a/src/core/tests/pwcore_test_matrix.cpp +++ b/src/core/tests/pwcore_test_matrix.cpp @@ -70,4 +70,9 @@ auto main() -> int { std::print("\nm44=[{}]\n", m44); + + // auto m_init_ded = pw::matrix{ + // {1, 2}, + // {3, 4} + // }; } diff --git a/src/core/tests/pwcore_test_mesh.cpp b/src/core/tests/pwcore_test_mesh.cpp index 308deef..0018e07 100644 --- a/src/core/tests/pwcore_test_mesh.cpp +++ b/src/core/tests/pwcore_test_mesh.cpp @@ -1,85 +1,40 @@ +#include #include +#include #include +#include #include #include #include -#include #include #include #include -namespace pw { - -} // namespace pw +namespace pw {} // namespace pw auto main() -> int { auto geom = pw::primitives{ .vertices = {{1.2f, 2.4f, 4.8f}, {2.4f, 1.2f, 4.8f}, - {1.2f, 4.8f, 2.4f}}, - .indices = {0, 1, 2}, - .topology = pw::primitives::topology_type::triangle_list}; + {1.2f, 4.8f, 2.4f} }, + .indices = {0, 1, 2}, + .topology = pw::primitives::topology_type::triangle_list + }; auto mesh = pw::mesh{.geometry = geom}; mesh.attributes.emplace_back( pw::attribute{.type = pw::attribute::normals, - .data = std::vector{ - pw::vector{1.2f, 2.4f, 4.8f}}}); + .data = std::vector{pw::vector{1.2f, 2.4f, 4.8f}}}); for (auto i : geom.indices) { - std::print("({}) ", pw::serialize::to_string(geom.vertices[i])); + std::print("vertex[{}]({})\n", i, geom.vertices[i]); } - // pw::geometry geo; + auto aabb = pw::aabb::make_from_indexed_vertices(geom.vertices, + geom.indices); - // pw::vector3_array vs = { - // { -1, 1, 0 }, - // { -1,-1, 0 }, - // { 1,-1, 0 }, - // { 1, 1, 0 } - // }; - - // pw::geometry::indices_t idx = { - // 0, 1, 2, - // 0, 2, 3 - // }; - - // geo.set_vertices(vs); - // geo.set_indices(idx); - - // geo.compute_normals(); - - // amesh.set_vertices(vs); - - // for (auto v : amesh.vertices()) { - // std::cout << pw::serialize::matrix(v.transposed()) << std::endl; - // } - - // auto scale = pw::matrix_transform::scale_matrix({2,2,2}); - - // amesh.transform(scale); - - // std::cout << "after scale" << std::endl; - - // for (auto v : amesh.vertices()) { - // std::cout << pw::serialize::matrix(v.transposed()) << std::endl; - // } - - // pw::axisangle aa; - - // aa.axis = pw::vector3({ 0, 0, 1 }); - // aa.angle = pw::deg_to_rad(90.0f); - - // auto rot_mat = aa.to_matrix(); - - // amesh.transform(rot_mat); - - // std::cout << "after rotate" << std::endl; - - // for (auto v : amesh.vertices()) { - // std::cout << pw::serialize::matrix(v.transposed()) << std::endl; - // } + std::print("aabb.max = ({}) aabb.min=({})\n", aabb.max, aabb.min); } diff --git a/src/geometry/include/pw/geometry/primitives.hpp b/src/geometry/include/pw/geometry/primitives.hpp index 7df5bce..4d03787 100644 --- a/src/geometry/include/pw/geometry/primitives.hpp +++ b/src/geometry/include/pw/geometry/primitives.hpp @@ -1,21 +1,22 @@ #ifndef PW_GEOMETRY_PRIMITIVES_HPP #define PW_GEOMETRY_PRIMITIVES_HPP -#include +#include namespace pw { - struct primitives { +struct primitives { - static geometry box(real_t size_x, real_t size_y, real_t size_z); + static geometry box(real_t size_x, real_t size_y, real_t size_z); - static geometry sphere(real_t radius,int divisions_latitude,int divisions_longitude); + static geometry sphere(real_t radius, int divisions_latitude, + int divisions_longitude); - static geometry cone(); - - static geometry pyramid(); - }; + static geometry cone(); + static geometry pyramid(); }; +}; // namespace pw + #endif diff --git a/src/system/src/window.cpp b/src/system/src/window.cpp index 505ce04..e1f2616 100644 --- a/src/system/src/window.cpp +++ b/src/system/src/window.cpp @@ -16,7 +16,6 @@ #include #include - namespace pw { // struct window_context : context @@ -77,8 +76,7 @@ struct window::impl { static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos) { - input::get()._mouse_position = - point(xpos, ypos).cast(); + input::get()._mouse_position = vector{xpos, ypos}.cast(); } static void key_callback(GLFWwindow* window, int key, int scancode, @@ -255,11 +253,11 @@ struct window::impl { ::pw::point position() const { int x, y; glfwGetWindowPos(_window, &x, &y); - return ::pw::point(x, y); + return {x, y}; } void set_position(const point& p) { - glfwSetWindowPos(_window, p.x, p.y); + glfwSetWindowPos(_window, p.x(), p.y()); } void set_fullscreen(bool use_fullscreen) { @@ -267,7 +265,7 @@ struct window::impl { return; if (use_fullscreen) { - glfwGetWindowPos(_window, &_old_pos.x, &_old_pos.y); + glfwGetWindowPos(_window, &_old_pos.x(), &_old_pos.y()); glfwGetWindowSize(_window, &_old_size.width, &_old_size.height); GLFWmonitor* monitor = glfwGetPrimaryMonitor(); @@ -278,7 +276,7 @@ struct window::impl { } else { - glfwSetWindowMonitor(_window, nullptr, _old_pos.x, _old_pos.y, + glfwSetWindowMonitor(_window, nullptr, _old_pos.x(), _old_pos.y(), _old_size.width, _old_size.height, 0); } diff --git a/src/visual/include/pw/visual/pipeline.hpp b/src/visual/include/pw/visual/pipeline.hpp index c8a464f..486e4a5 100644 --- a/src/visual/include/pw/visual/pipeline.hpp +++ b/src/visual/include/pw/visual/pipeline.hpp @@ -1,52 +1,42 @@ #ifndef PW_VISUAL_PIPELINE_HPP #define PW_VISUAL_PIPELINE_HPP -#include -#include -#include #include +#include +#include +#include -#include #include - +#include #include namespace pw { - - - class pipeline { -public: - pipeline(); + public: + pipeline(); ~pipeline(); void draw(); - bool create(size s); - -protected: - struct impl; - std::unique_ptr _impl; + bool create(size s); + protected: + struct impl; + std::unique_ptr _impl; }; - - struct render_pass { - void submit(const geometry& g, - const matrix4x4& model_mat, - const matrix4x4& view_mat, - const matrix4x4& projection_mat); + void submit(const geometry& g, const matrix4x4& model_mat, + const matrix4x4& view_mat, const matrix4x4& projection_mat); shader _shader; renderer _renderer; }; - -} +} // namespace pw #endif diff --git a/src/visual/src/context.cpp b/src/visual/src/context.cpp index 801a670..44e2172 100644 --- a/src/visual/src/context.cpp +++ b/src/visual/src/context.cpp @@ -4,89 +4,58 @@ #include "glad/glad.h" #include - namespace pw { struct context::impl { - vector4f _clear_color { 0, 1, 0, 1}; + vector4f _clear_color{0, 1, 0, 1}; - void set_viewport(const rectangle& v) - { - glViewport(v.position.x,v.position.y,v.size.width,v.size.height); + void set_viewport(const rectangle& v) { + glViewport(v.position.x(), v.position.y(), v.size.width, v.size.height); } - const rectangle viewport() - { - auto vp = rectangle{0,0,1,1}; - glGetFloatv(GL_VIEWPORT,static_cast(&vp.position.x)); + const rectangle viewport() { + auto vp = rectangle{0, 0, 1, 1}; + glGetFloatv(GL_VIEWPORT, vp.position.data()); return vp.cast(); } - void clear() - { + void clear() { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); - glClearColor(_clear_color[0],_clear_color[1],_clear_color[2],_clear_color[3]); + glClearColor(_clear_color[0], _clear_color[1], _clear_color[2], + _clear_color[3]); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - } - - - - uint32_t get_error() const - { - return glGetError(); } + uint32_t get_error() const { return glGetError(); } }; -context::context() - : _impl(std::make_unique()) -{ -} +context::context() : _impl(std::make_unique()) {} -context::~context() -{ -} +context::~context() {} -void context::set_blend() -{ +void context::set_blend() {} -} - -void context::set_viewport(const rectangle& v) -{ +void context::set_viewport(const rectangle& v) { _impl->set_viewport(v); } -rectangle context::viewport() const -{ - return _impl->viewport(); -} +rectangle context::viewport() const { return _impl->viewport(); } -void context::clear() -{ - _impl->clear(); -} +void context::clear() { _impl->clear(); } -u_int32_t context::get_error() const -{ - return _impl->get_error(); -} +u_int32_t context::get_error() const { return _impl->get_error(); } -color context::clearcolor() const -{ +color context::clearcolor() const { // return _impl->_clear_color; return color{}; } -void context::set_clearcolor(const color& c) -{ +void context::set_clearcolor(const color& c) { // _impl->_clear_color = c; } - -} +} // namespace pw diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp index 064b075..2593c80 100644 --- a/src/visual/src/pipeline.cpp +++ b/src/visual/src/pipeline.cpp @@ -1,30 +1,26 @@ -#include "pw/core/size.hpp" -#include "pw/core/matrix.hpp" -#include "pw/core/geometry.hpp" -#include "pw/core/time.hpp" #include "pw/core/axisangle.hpp" -#include "pw/core/serialize.hpp" +#include "pw/core/geometry.hpp" +#include "pw/core/matrix.hpp" #include "pw/core/matrix_transform.hpp" +#include "pw/core/serialize.hpp" +#include "pw/core/size.hpp" +#include "pw/core/time.hpp" #include "pw/core/debug.hpp" -#include "pw/visual/pipeline.hpp" -#include "pw/visual/shader.hpp" -#include "pw/visual/renderer.hpp" #include "pw/visual/framebuffer.hpp" +#include "pw/visual/pipeline.hpp" +#include "pw/visual/renderer.hpp" +#include "pw/visual/shader.hpp" #include "pw/visual/texture.hpp" #include "glad/glad.h" namespace pw { - -void render_pass::submit(const geometry &g, - const matrix4x4 &model_mat, - const matrix4x4 &view_mat, - const matrix4x4 &projection_mat) -{ - if (!_shader.ready()) - { // +void render_pass::submit(const geometry& g, const matrix4x4& model_mat, + const matrix4x4& view_mat, + const matrix4x4& projection_mat) { + if (!_shader.ready()) { // _shader.build(); } @@ -35,22 +31,18 @@ void render_pass::submit(const geometry &g, // new version with ... shader::uniform_cache_t us; -// us.push_back(std::make_tuple("input_color",mat._color,-1)); - us.push_back(std::make_tuple("model",model_mat,-1)); - us.push_back(std::make_tuple("view",view_mat,-1)); - us.push_back(std::make_tuple("projection",projection_mat,-1)); + // us.push_back(std::make_tuple("input_color",mat._color,-1)); + us.push_back(std::make_tuple("model", model_mat, -1)); + us.push_back(std::make_tuple("view", view_mat, -1)); + us.push_back(std::make_tuple("projection", projection_mat, -1)); _shader.set_uniforms(us); _shader.use(); _renderer.draw(); - } - -struct triangle_renderer -{ - +struct triangle_renderer { texture tex; shader shader_p; @@ -58,15 +50,12 @@ struct triangle_renderer renderer r; time::tick_t tick; - triangle_renderer() - { - } + triangle_renderer() {} - void setup() - { + void setup() { const float z_val = -5.f; - const float s = 1.0f; + const float s = 1.0f; // // 0 -- 1 @@ -75,23 +64,23 @@ struct triangle_renderer // geometry vector3_array vertices = { - {-s, s, z_val} // 0 - ,{ s, s, z_val} // 1 - ,{-s, -s, z_val} // 2 - ,{ s, -s, z_val} // 3 + {-s, s, z_val} // 0 + , + {s, s, z_val} // 1 + , + {-s, -s, z_val} // 2 + , + {s, -s, z_val} // 3 }; // topology / indices - geometry::indices_t indices = { 2, 1, 0, - 2, 3, 1}; - + geometry::indices_t indices = {2, 1, 0, 2, 3, 1}; amesh.set_indices(indices); amesh.set_vertices(vertices); amesh.compute_normals(); - const char* vertex_shader_2 = R"( #version 400 uniform mat4 model; @@ -106,7 +95,7 @@ struct triangle_renderer } )"; - const char *fragment_shader_2 = R"( + const char* fragment_shader_2 = R"( #version 400 uniform vec4 input_color = vec4(1.0, 0.0, 0.0, 1.0); out vec4 frag_colour; @@ -114,38 +103,37 @@ struct triangle_renderer frag_colour = input_color; })"; - shader_p.set_source(shader::code_type::vertex,vertex_shader_2); - shader_p.set_source(shader::code_type::fragment,fragment_shader_2); + shader_p.set_source(shader::code_type::vertex, vertex_shader_2); + shader_p.set_source(shader::code_type::fragment, fragment_shader_2); if (!shader_p.build()) exit(-1); } - void draw() - { + void draw() { if (!r.ready()) r.create(amesh); - // input needed here - // model view projection shader_p.use(); - auto v_col = ping_pong(static_cast(time::now()),1.0f); + auto v_col = ping_pong(static_cast(time::now()), 1.0f); - vector4f col = {0.5f,1-v_col,v_col,1.0f}; + vector4f col = {0.5f, 1 - v_col, v_col, 1.0f}; - matrix4x4f model_mat; model_mat.set_identity(); + matrix4x4f model_mat; + model_mat.set_identity(); - auto v_angle = ping_pong(static_cast(time::now()),2 * ::pw::pi()); + auto v_angle = + ping_pong(static_cast(time::now()), 2 * ::pw::pi()); - axisangle rot(vector3::forward(),v_angle); + axisangle rot(vector3::forward(), v_angle); model_mat = rot.to_matrix(); - matrix4x4f view_mat = matrix_transform::look_at(vector3({0,0,0}), - vector3::forward(), - vector3::up()); + matrix4x4f view_mat = matrix_transform::look_at( + vector3({0, 0, 0}), vector3::forward(), vector3::up()); // materials should carry this #if 1 @@ -154,35 +142,31 @@ struct triangle_renderer glFrontFace(GL_CCW); #endif - // now bind textures #if 1 - auto proj_mat = matrix_transform::orthographic_projection(1.3,1.0, - 0.2f,100.f); - + auto proj_mat = matrix_transform::orthographic_projection( + 1.3, 1.0, 0.2f, 100.f); #else - auto proj_mat = matrix_transform::perspective_projection(deg_to_rad(60.f), - 1.3f, - 0.2f,1000.f); + auto proj_mat = matrix_transform::perspective_projection( + deg_to_rad(60.f), 1.3f, 0.2f, 1000.f); #endif - #if 1 // highly inefficient - should be cached - - shader_p.set_uniform("input_color",col); - shader_p.set_uniform("model",model_mat); - shader_p.set_uniform("view",view_mat); - shader_p.set_uniform("projection",proj_mat); + shader_p.set_uniform("input_color", col); + shader_p.set_uniform("model", model_mat); + shader_p.set_uniform("view", view_mat); + shader_p.set_uniform("projection", proj_mat); #else // new version with ... shader::uniform_cache_t us; - us.push_back(std::make_tuple("input_color",col,-1)); - us.push_back(std::make_tuple("model",model_mat,-1)); - us.push_back(std::make_tuple("view",view_mat,-1)); - us.push_back(std::make_tuple("projection",proj_mat,-1)); + us.push_back(std::make_tuple("input_color", col, -1)); + us.push_back(std::make_tuple("model", model_mat, -1)); + us.push_back(std::make_tuple("view", view_mat, -1)); + us.push_back(std::make_tuple("projection", proj_mat, -1)); shader_p.set_uniforms(us); @@ -191,7 +175,7 @@ struct triangle_renderer r.draw(); auto error = glGetError(); - if (error != GL_NO_ERROR){ + if (error != GL_NO_ERROR) { debug::e() << "GL error " << error; } @@ -199,7 +183,6 @@ struct triangle_renderer } }; - struct pipeline::impl { #if 0 @@ -214,35 +197,30 @@ struct pipeline::impl { framebuffer fb; - - //testing + // testing triangle_renderer tr; bool create(size s); void draw(); - - - impl() = default; + impl() = default; ~impl() = default; - }; -GLuint generate_multisample_texture(const size& s,int samples) -{ +GLuint generate_multisample_texture(const size& s, int samples) { GLuint texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture); - glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGB8, s.width, s.height, GL_TRUE); + glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGB8, + s.width, s.height, GL_TRUE); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); return texture; } -bool pipeline::impl::create(::pw::size s) -{ +bool pipeline::impl::create(::pw::size s) { #if 0 _size = s; @@ -293,23 +271,14 @@ bool pipeline::impl::create(::pw::size s) glBindFramebuffer(GL_FRAMEBUFFER, 0); #endif - - tr.setup(); - return true; } +void pipeline::impl::draw() { - - -void pipeline::impl::draw() -{ - - - - glClearColor(1.0,0,0,1); + glClearColor(1.0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // glViewport(0,0,800,600); @@ -320,12 +289,8 @@ void pipeline::impl::draw() tr.draw(); - - // reset - - // actuall blitting #if 0 @@ -346,7 +311,6 @@ void pipeline::impl::draw() #else - #if 0 glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo_msaa); // src FBO (multi-sample) @@ -372,87 +336,76 @@ void pipeline::impl::draw() // fb.unbind(); GLenum err; - while((err = glGetError()) != GL_NO_ERROR) - { + while ((err = glGetError()) != GL_NO_ERROR) { std::string error; - switch(err) { - case GL_INVALID_OPERATION: error="INVALID_OPERATION"; break; - case GL_INVALID_ENUM: error="INVALID_ENUM"; break; - case GL_INVALID_VALUE: error="INVALID_VALUE"; break; - case GL_OUT_OF_MEMORY: error="OUT_OF_MEMORY"; break; - case GL_INVALID_FRAMEBUFFER_OPERATION: error="INVALID_FRAMEBUFFER_OPERATION"; break; + switch (err) { + case GL_INVALID_OPERATION: + error = "INVALID_OPERATION"; + break; + case GL_INVALID_ENUM: + error = "INVALID_ENUM"; + break; + case GL_INVALID_VALUE: + error = "INVALID_VALUE"; + break; + case GL_OUT_OF_MEMORY: + error = "OUT_OF_MEMORY"; + break; + case GL_INVALID_FRAMEBUFFER_OPERATION: + error = "INVALID_FRAMEBUFFER_OPERATION"; + break; } debug::e() << "OpenGL error:" << err << " " << error; } - } - // // // -pipeline::pipeline() - : _impl(std::make_unique()) -{ -} +pipeline::pipeline() : _impl(std::make_unique()) {} -pipeline::~pipeline() -{ +pipeline::~pipeline() { // } -void pipeline::draw() -{ - _impl->draw(); -} +void pipeline::draw() { _impl->draw(); } -bool pipeline::create(size s) -{ - return _impl->create(s.cast()); -} +bool pipeline::create(size s) { return _impl->create(s.cast()); } -} +} // namespace pw +// class pipeline; - - -//class pipeline; - -//class pass +// class pass //{ -//public: +// public: // virtual void apply(pipeline& p); -//}; +// }; -//class pipeline +// class pipeline //{ -//public: +// public: // void apply() // { // for (auto p : _passes) p.apply(*this); // } -//protected: +// protected: // std::vector _passes; -//}; +// }; - - - - - - -//pipeline > +// pipeline > // n*pass // shadow_pass -// lighting_pass +// lighting_pass // mesh_pass // compositor_pass -//compositor -// render to fbo > add a -// glBlitFramebuffer .. https://stackoverflow.com/questions/29254574/using-glblitframebuffer-to-display-a-texture +// compositor +// render to fbo > add a +// glBlitFramebuffer .. +// https://stackoverflow.com/questions/29254574/using-glblitframebuffer-to-display-a-texture