diff --git a/LICENSE b/LICENSE index ce2069a..21124e8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 1999-2019 Hartmut Seichter +Copyright (c) 1999-2021 Hartmut Seichter Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/binding/include/pw/scripting/script.hpp b/src/binding/include/pw/scripting/script.hpp index 7110ecc..ac1c504 100644 --- a/src/binding/include/pw/scripting/script.hpp +++ b/src/binding/include/pw/scripting/script.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/binding/src/script_core.cpp b/src/binding/src/script_core.cpp index a9e6173..1731768 100644 --- a/src/binding/src/script_core.cpp +++ b/src/binding/src/script_core.cpp @@ -103,15 +103,17 @@ void register_core_function(sol::state& lua,sol::table& ns) "elapsed",sol::readonly_property(&time::elapsed), "reset",&time::reset ); + ns.new_usertype("geometry" - , sol::constructors() + , sol::constructors() , "topology", sol::property(&geometry::topology,&geometry::set_topology) , "vertices", sol::property(&geometry::vertices,&geometry::set_vertices) , "indices", sol::property(&geometry::indices,&geometry::set_indices) - ).new_enum("topology_type" + ).new_enum("type" ,"points", geometry::topology_type::points , "lines", geometry::topology_type::lines - , "line_strip", geometry::topology_type::line_strip); + , "line_strip", geometry::topology_type::line_strip + , "triangles", geometry::topology_type::triangles); // SOL3 diff --git a/src/binding/src/script_visual.cpp b/src/binding/src/script_visual.cpp index 4ca6170..1e36554 100644 --- a/src/binding/src/script_visual.cpp +++ b/src/binding/src/script_visual.cpp @@ -15,16 +15,32 @@ void register_visual_function(sol::state&,sol::table &ns) ,"draw",&pipeline::draw ); + + ns.new_usertype("shader" + ,sol::constructors() ,"ready",sol::readonly_property(&shader::ready) ,"use",&shader::use - ,"build",&shader::build - ,"set_source",&shader::set_source - ,"source",&shader::source - ); -// .new_enum("shader_type" -// ,"fragment",shader::code_type::fragment -// ,"vertex",shader::code_type::vertex); + ,"build",&shader::build + ,"source",&shader::source + ,"set_source",&shader::set_source + ,"set_uniforms",&shader::set_uniforms + ).new_enum("shader_type" + ,"fragment",shader::code_type::fragment + ,"vertex",shader::code_type::vertex + ,"geometry",shader::code_type::geometry + ,"compute",shader::code_type::compute); + + + ns.new_usertype("render_pass" + ,"submit",&render_pass::submit + ); + + ns.new_usertype("material" + ,"color",sol::property(&material::_color)); + + + ns.new_usertype("mesh_renderer"); } PW_REGISTER_LUA(visual) diff --git a/src/core/include/pw/core/aabb.hpp b/src/core/include/pw/core/aabb.hpp index 684da4f..ada4cd1 100644 --- a/src/core/include/pw/core/aabb.hpp +++ b/src/core/include/pw/core/aabb.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/axisangle.hpp b/src/core/include/pw/core/axisangle.hpp index 211aade..06378fc 100644 --- a/src/core/include/pw/core/axisangle.hpp +++ b/src/core/include/pw/core/axisangle.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/color.hpp b/src/core/include/pw/core/color.hpp index 4d9857f..ec1010a 100644 --- a/src/core/include/pw/core/color.hpp +++ b/src/core/include/pw/core/color.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/core.hpp b/src/core/include/pw/core/core.hpp index 5c99aca..60c4361 100644 --- a/src/core/include/pw/core/core.hpp +++ b/src/core/include/pw/core/core.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/debug.hpp b/src/core/include/pw/core/debug.hpp index d20ec0f..3350453 100644 --- a/src/core/include/pw/core/debug.hpp +++ b/src/core/include/pw/core/debug.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/geometry.hpp b/src/core/include/pw/core/geometry.hpp index b3a2519..0a87328 100644 --- a/src/core/include/pw/core/geometry.hpp +++ b/src/core/include/pw/core/geometry.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -52,6 +52,7 @@ public: using vertex3array_t = std::vector ; geometry() = default; + geometry(topology_type t); void set_indices(const indexarray_t& v) { _indices = v; } const indexarray_t& indices() const { return _indices; } @@ -65,7 +66,7 @@ public: void set_topology(topology_type t) { _topology = t; } topology_type topology() { return _topology; } - void apply(const matrix4x4& m); + void transform(const matrix4x4& m); void reset(); @@ -84,7 +85,7 @@ protected: vertex3array_t _normals; //!< normal data vertex3array_t _colors; //!< color data - std::vector _uvs; //!< storing multiple UV sets + std::vector _uvs; //!< storing multiple UV sets struct aabb _aabb; diff --git a/src/core/include/pw/core/globals.hpp b/src/core/include/pw/core/globals.hpp index 877cb9b..eba17a7 100644 --- a/src/core/include/pw/core/globals.hpp +++ b/src/core/include/pw/core/globals.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/image.hpp b/src/core/include/pw/core/image.hpp index 555c09c..f5d05b9 100644 --- a/src/core/include/pw/core/image.hpp +++ b/src/core/include/pw/core/image.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/math.hpp b/src/core/include/pw/core/math.hpp index 0c039b4..61cd9e3 100644 --- a/src/core/include/pw/core/math.hpp +++ b/src/core/include/pw/core/math.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index 03e9685..533040f 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/matrix_transform.hpp b/src/core/include/pw/core/matrix_transform.hpp index 80cd0aa..194d7f1 100644 --- a/src/core/include/pw/core/matrix_transform.hpp +++ b/src/core/include/pw/core/matrix_transform.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/matrixbase.hpp b/src/core/include/pw/core/matrixbase.hpp index b2b46cb..e666be4 100644 --- a/src/core/include/pw/core/matrixbase.hpp +++ b/src/core/include/pw/core/matrixbase.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/point.hpp b/src/core/include/pw/core/point.hpp index dd02833..724c8a0 100644 --- a/src/core/include/pw/core/point.hpp +++ b/src/core/include/pw/core/point.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/quaternion.hpp b/src/core/include/pw/core/quaternion.hpp index 7252a23..b645bf2 100644 --- a/src/core/include/pw/core/quaternion.hpp +++ b/src/core/include/pw/core/quaternion.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/rectangle.hpp b/src/core/include/pw/core/rectangle.hpp index fc37d17..700a183 100644 --- a/src/core/include/pw/core/rectangle.hpp +++ b/src/core/include/pw/core/rectangle.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/resource.hpp b/src/core/include/pw/core/resource.hpp index 3158690..52007ea 100644 --- a/src/core/include/pw/core/resource.hpp +++ b/src/core/include/pw/core/resource.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/serialize.hpp b/src/core/include/pw/core/serialize.hpp index 37343fd..f9b10ec 100644 --- a/src/core/include/pw/core/serialize.hpp +++ b/src/core/include/pw/core/serialize.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/size.hpp b/src/core/include/pw/core/size.hpp index e00992a..2c52d94 100644 --- a/src/core/include/pw/core/size.hpp +++ b/src/core/include/pw/core/size.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/include/pw/core/time.hpp b/src/core/include/pw/core/time.hpp index 22c5f63..ec95cac 100644 --- a/src/core/include/pw/core/time.hpp +++ b/src/core/include/pw/core/time.hpp @@ -30,17 +30,21 @@ namespace pw { /** - * @brief A simple timer + * @brief A simple high resolution timer */ class time { public: using tick_t = std::chrono::time_point ; - time(); /// c'tor - ~time(); /// d'tor + time() = default; + time(const time&) = default; + ~time() = default; /// d'tor - void reset(); /// reset the timer + /** + * @brief reset timer to current system time + */ + void reset(); /** * @brief elapsed time based on the scale @@ -56,7 +60,7 @@ public: protected: - tick_t _start; + tick_t _start = std::chrono::high_resolution_clock::now(); }; } diff --git a/src/core/include/pw/core/vector.hpp b/src/core/include/pw/core/vector.hpp index 73b494c..91a6d84 100644 --- a/src/core/include/pw/core/vector.hpp +++ b/src/core/include/pw/core/vector.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/core/src/geometry.cpp b/src/core/src/geometry.cpp index 30e59e1..eea386f 100644 --- a/src/core/src/geometry.cpp +++ b/src/core/src/geometry.cpp @@ -55,6 +55,11 @@ void geometry::compute_normals() // now set back } +geometry::geometry(geometry::topology_type t) + : _topology(t) +{ +} + void geometry::set_vertices(const geometry::vertex3array_t &v) { // first set vertices @@ -74,7 +79,7 @@ const geometry::vertex3array_t &geometry::normals() const return _normals; } -void geometry::apply(const matrix4x4 &m) +void geometry::transform(const matrix4x4 &m) { // apply transformation to all vertices for (auto &v : _vertices) diff --git a/src/core/src/time.cpp b/src/core/src/time.cpp index 2e56aac..65289b2 100644 --- a/src/core/src/time.cpp +++ b/src/core/src/time.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,18 +24,9 @@ namespace pw { -time::time() -{ - reset(); -} - -time::~time() -{ -} - void time::reset() { - _start = std::chrono::high_resolution_clock::now(); + *this = time(); } double time::elapsed() const diff --git a/src/core/tests/pwcore_test_mesh.cpp b/src/core/tests/pwcore_test_mesh.cpp index 382922b..8c94818 100644 --- a/src/core/tests/pwcore_test_mesh.cpp +++ b/src/core/tests/pwcore_test_mesh.cpp @@ -19,7 +19,7 @@ int main(int argc,char **argv) { auto scale = pw::matrix_transform::scale_matrix({2,2,2}); - amesh.apply(scale); + amesh.transform(scale); std::cout << "after scale" << std::endl; @@ -34,7 +34,7 @@ int main(int argc,char **argv) { auto rot_mat = aa.to_matrix(); - amesh.apply(rot_mat); + amesh.transform(rot_mat); std::cout << "after rotate" << std::endl; diff --git a/src/io/include/pw/io/image_io.hpp b/src/io/include/pw/io/image_io.hpp index 909b845..53e1df4 100644 --- a/src/io/include/pw/io/image_io.hpp +++ b/src/io/include/pw/io/image_io.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index 772e306..071457d 100644 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -2,6 +2,7 @@ set(scripts_demo ${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_000.lua ${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_001.lua + ${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_002.lua ) set(scripts_test diff --git a/src/scene/include/pw/scene/entity.hpp b/src/scene/include/pw/scene/entity.hpp index 29e6f0c..3e5d8b1 100644 --- a/src/scene/include/pw/scene/entity.hpp +++ b/src/scene/include/pw/scene/entity.hpp @@ -34,6 +34,7 @@ namespace pw { + class entity { public: entity() = default; @@ -135,7 +136,7 @@ public: std::string name(); private: - std::shared_ptr _registry; + std::shared_ptr _registry; entt::entity _entity { entt::null }; }; diff --git a/src/scene/include/pw/scene/scene.hpp b/src/scene/include/pw/scene/scene.hpp index 50fa22c..64d2a8a 100644 --- a/src/scene/include/pw/scene/scene.hpp +++ b/src/scene/include/pw/scene/scene.hpp @@ -33,6 +33,8 @@ namespace pw { class entity; +using entt::registry; + class scene { public: @@ -46,7 +48,7 @@ public: protected: - std::shared_ptr _registry; + std::shared_ptr _registry; friend class entity; }; diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index 956c5ba..0e5c9da 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -19,7 +19,7 @@ w.size = pw.size.new(640,480) -- move window w.position = pw.point.new(100,100) -print("Lines",pw.geometry.type.lines) +--print("Lines",pw.geometry.type.lines) print("client size after resize: ",w.client_size.width,w.client_size.height) @@ -46,6 +46,8 @@ local t = pw.time.new() w.visible = true +-- sr = pw:scene_renderer.new() + while w:update() do -- somehow works if (pw.input.get().input_string == 'f') then @@ -59,12 +61,14 @@ while w:update() do -- just to check if (pw.input:get().mouse_button == 1) then + print("elapsed",t.elapsed) t:reset() print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y,w.client_size.width,w.client_size.height) end - -- print("update") + + end --local scene = pw:scene.new() diff --git a/src/system/include/pw/system/path.hpp b/src/system/include/pw/system/path.hpp index ab1748b..21376ea 100644 --- a/src/system/include/pw/system/path.hpp +++ b/src/system/include/pw/system/path.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/visual/CMakeLists.txt b/src/visual/CMakeLists.txt index 1c566c0..d3ff145 100644 --- a/src/visual/CMakeLists.txt +++ b/src/visual/CMakeLists.txt @@ -3,7 +3,8 @@ set(hdrs include/pw/visual/shader.hpp include/pw/visual/pipeline.hpp include/pw/visual/texture.hpp - include/pw/visual/vertex_array.hpp + include/pw/visual/mesh_renderer.hpp + include/pw/visual/material.hpp ) set(srcs @@ -13,7 +14,8 @@ set(srcs src/pipeline.cpp src/target.cpp src/texture.cpp - src/vertex_array.cpp + src/mesh_renderer.cpp + src/material.cpp ) diff --git a/src/visual/include/pw/visual/context.hpp b/src/visual/include/pw/visual/context.hpp index a8aeb64..c64fae0 100644 --- a/src/visual/include/pw/visual/context.hpp +++ b/src/visual/include/pw/visual/context.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2019 Hartmut Seichter + * Copyright (c) 1999-2021 Hartmut Seichter * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/visual/include/pw/visual/material.hpp b/src/visual/include/pw/visual/material.hpp new file mode 100644 index 0000000..14bc499 --- /dev/null +++ b/src/visual/include/pw/visual/material.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include + + +namespace pw { + +struct material { + vector4f _color = vector4f {0xFF,0x00,0xFF,0xFF}; + material() = default; +}; + +} diff --git a/src/visual/include/pw/visual/vertex_array.hpp b/src/visual/include/pw/visual/mesh_renderer.hpp similarity index 100% rename from src/visual/include/pw/visual/vertex_array.hpp rename to src/visual/include/pw/visual/mesh_renderer.hpp diff --git a/src/visual/include/pw/visual/pipeline.hpp b/src/visual/include/pw/visual/pipeline.hpp index 7178a3c..3a5f17f 100644 --- a/src/visual/include/pw/visual/pipeline.hpp +++ b/src/visual/include/pw/visual/pipeline.hpp @@ -4,18 +4,27 @@ #include #include #include +#include + +#include +#include +#include + #include namespace pw { + + + class pipeline { public: pipeline(); ~pipeline(); - void draw(); + void draw(); bool create(size s); @@ -25,6 +34,21 @@ protected: }; + + +struct render_pass { + + void submit(const geometry& g, + const matrix4x4& model_mat, + const matrix4x4& view_mat, + const matrix4x4& projection_mat, + const material& mat); + + shader _shader; + mesh_renderer _renderer; +}; + + } #endif diff --git a/src/visual/include/pw/visual/shader.hpp b/src/visual/include/pw/visual/shader.hpp index 11a5435..226582f 100644 --- a/src/visual/include/pw/visual/shader.hpp +++ b/src/visual/include/pw/visual/shader.hpp @@ -29,7 +29,7 @@ public: bool ready() const; - shader& set(int location,float v); + shader& set(int location,float v); shader& set(int location,matrix4x4f const & v); shader& set(int location,vector4f const & v); @@ -42,7 +42,7 @@ public: if (location >= 0) return set(location, std::forward(value)); else - debug::e() << "missing uniform: '" << name << "'"; + debug::w() << "missing uniform: '" << name << "'"; return *this; } @@ -57,7 +57,7 @@ public: void set_uniforms(uniform_cache_t c); - unsigned int native_handle() const; + uint32_t native_handle() const; protected: @@ -68,6 +68,7 @@ protected: }; + } #endif diff --git a/src/visual/src/material.cpp b/src/visual/src/material.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/visual/src/vertex_array.cpp b/src/visual/src/mesh_renderer.cpp similarity index 84% rename from src/visual/src/vertex_array.cpp rename to src/visual/src/mesh_renderer.cpp index dfb9a87..2bbe01c 100644 --- a/src/visual/src/vertex_array.cpp +++ b/src/visual/src/mesh_renderer.cpp @@ -1,4 +1,4 @@ -#include "pw/visual/vertex_array.hpp" +#include "pw/visual/mesh_renderer.hpp" #include "pw/core/geometry.hpp" #include "pw/core/size.hpp" @@ -14,10 +14,7 @@ namespace pw { struct mesh_renderer::impl { GLuint _vao = 0; - - std::vector _vbos; - GLint _mesh_elements = {0}; impl() @@ -84,10 +81,6 @@ struct mesh_renderer::impl { if (error != GL_NO_ERROR) { debug::e() << "GL error: " << error; } - - debug::d() << "Vertices: " << m.vertices().size(); - debug::d() << "Indices " << m.indices().size(); - } @@ -102,15 +95,16 @@ struct mesh_renderer::impl { void draw() { - glBindVertexArray(_vao); - glDrawElements(GL_TRIANGLES, _mesh_elements, GL_UNSIGNED_INT, nullptr); - glBindVertexArray(0); + if (glIsVertexArray(_vao)) { + glBindVertexArray(_vao); + glDrawElements(GL_TRIANGLES, _mesh_elements, GL_UNSIGNED_INT, nullptr); + glBindVertexArray(0); - auto error = glGetError(); - if (error != GL_NO_ERROR) { - debug::e() << "GL error: " << error; + auto error = glGetError(); + if (error != GL_NO_ERROR) { + debug::e() << "GL error: " << error; + } } - } // GLint get_mode(vertex_array::) diff --git a/src/visual/src/pass.cpp b/src/visual/src/pass.cpp index c4be354..098ca25 100644 --- a/src/visual/src/pass.cpp +++ b/src/visual/src/pass.cpp @@ -2,11 +2,21 @@ // a pass combines meshes, states and targets // +#include +#include + +#include +#include +#include + namespace pw { class pass { - virtual void submit(); + virtual void submit(); }; + + + } diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp index 96ec433..ce8191f 100644 --- a/src/visual/src/pipeline.cpp +++ b/src/visual/src/pipeline.cpp @@ -9,7 +9,8 @@ #include "pw/core/debug.hpp" #include "pw/visual/pipeline.hpp" #include "pw/visual/shader.hpp" -#include "pw/visual/vertex_array.hpp" +#include "pw/visual/mesh_renderer.hpp" +#include "pw/visual/material.hpp" #include "glad/glad.h" @@ -32,15 +33,47 @@ class queue { // vector ... }; + + + +void render_pass::submit(const geometry &g, + const matrix4x4 &model_mat, + const matrix4x4 &view_mat, + const matrix4x4 &projection_mat, + const material &mat) +{ + if (!_shader.ready()) + { // + _shader.build(); + } + + // create the renderer + if (!_renderer.ready()) { + _renderer.create(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)); + + _shader.set_uniforms(us); + + _shader.use(); + _renderer.draw(); + +} + + struct triangle_renderer { - // GLuint vbo = 0; - // GLuint vao = 0; - // GLuint shader_programme = 0; + shader shader_p; geometry amesh; - mesh_renderer amesh_renderer; + mesh_renderer renderer; time::tick_t tick; triangle_renderer() @@ -53,20 +86,6 @@ struct triangle_renderer const float z_val = -5.f; const float s = 1.0f; - -#if 0 - geometry::vertex3array_t vertices = { - { 0.0f, 0.5f, z_val} // 0 - ,{ 0.5f, 0.0f, z_val} // 1 - ,{-0.5f, 0.0f, z_val} // 2 - }; - - // actual indices - geometry::indexarray_t indices = { 0, 1, 2}; - -#else - - // // 0 -- 1 // | / | @@ -74,7 +93,7 @@ struct triangle_renderer // geometry geometry::vertex3array_t vertices = { - {-s, s, z_val} // 0 + {-s, s, z_val} // 0 ,{ s, s, z_val} // 1 ,{-s, -s, z_val} // 2 ,{ s, -s, z_val} // 3 @@ -85,14 +104,11 @@ struct triangle_renderer 2, 3, 1}; -#endif - amesh.set_indices(indices); amesh.set_vertices(vertices); amesh.compute_normals(); - amesh_renderer.create(amesh); const char* vertex_shader_2 = R"( #version 400 @@ -125,6 +141,9 @@ struct triangle_renderer void draw() { + if (!renderer.ready()) + renderer.create(amesh); + // input needed here - // model view projection @@ -187,7 +206,7 @@ struct triangle_renderer #endif - amesh_renderer.draw(); + renderer.draw(); auto error = glGetError(); if (error != GL_NO_ERROR){ diff --git a/src/visual/src/shader.cpp b/src/visual/src/shader.cpp index f4d077c..11d0b2b 100644 --- a/src/visual/src/shader.cpp +++ b/src/visual/src/shader.cpp @@ -25,16 +25,18 @@ struct shader::impl bool is_valid() { - return glIsProgram(_shader_program); + // we potentially haul in is_valid while no context is given + return glIsProgram != nullptr && glIsProgram(_shader_program); } bool build() { + if (!is_valid()) return false; - for (auto s : _shader._source) + for (const auto & [type,code] : _shader._source) { GLuint shader_type = 0; - switch (s.first) { + switch (type) { case shader::code_type::vertex: shader_type = GL_VERTEX_SHADER; break; @@ -51,8 +53,8 @@ struct shader::impl GLuint shaderId = glCreateShader(shader_type); - char* src = const_cast(s.second.c_str()); - GLint size = static_cast(s.second.length()); + char* src = const_cast(code.c_str()); + GLint size = static_cast(code.length()); glShaderSource(shaderId , 1, &src, &size); @@ -131,15 +133,16 @@ struct shader::impl } void clear() - { - if (is_valid()) { + { + // potentially the GL driver hasn't been loaded + if (is_valid()) { glDeleteProgram(_shader_program); for (auto s : _shader_stages) { glDeleteShader(s); } - } + } } int uniform_location(std::string const& name) const @@ -211,6 +214,8 @@ void shader::use() void shader::set_uniforms(uniform_cache_t c) { + // TODO rewrite in proper C++17 + for (auto& u : c) { // get name std::string name = std::get<0>(u); @@ -227,20 +232,22 @@ void shader::set_uniforms(uniform_cache_t c) std::visit([this,loc](auto&& arg) { - using T = std::decay_t; + using T = std::decay_t; + + // TODO query the std::variant of uniform_t if constexpr ((std::is_same_v) || (std::is_same_v) || (std::is_same_v) ) { set(loc, std::forward(arg)); } else { - std::cout << "can't" << std::endl; + debug::e() << "unknown uniform type"; } }, var); } } -unsigned int shader::native_handle() const +uint32_t shader::native_handle() const { return _impl->_shader_program; }