WiP for mesh and fixes for clang compilation
This commit is contained in:
parent
6a0c5c178d
commit
a4bb53ce8f
10 changed files with 173 additions and 141 deletions
|
@ -1,9 +1,9 @@
|
||||||
//#include "script_system.hpp"
|
// #include "script_system.hpp"
|
||||||
|
|
||||||
#include "pw/system/window.hpp"
|
|
||||||
#include "pw/system/input.hpp"
|
|
||||||
#include "pw/system/display.hpp"
|
#include "pw/system/display.hpp"
|
||||||
|
#include "pw/system/input.hpp"
|
||||||
#include "pw/system/path.hpp"
|
#include "pw/system/path.hpp"
|
||||||
|
#include "pw/system/window.hpp"
|
||||||
|
|
||||||
#include "runtime_lua.hpp"
|
#include "runtime_lua.hpp"
|
||||||
|
|
||||||
|
@ -13,49 +13,37 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
void register_system_function(sol::state&, sol::table &ns)
|
void register_system_function(sol::state&, sol::table& ns) {
|
||||||
{
|
ns.new_usertype<window>(
|
||||||
ns.new_usertype<window>("window",
|
"window", "update", &window::update, "on_update",
|
||||||
"update",&window::update,
|
sol::writeonly_property(&window::set_on_update), "on_resize",
|
||||||
"on_update",sol::writeonly_property(&window::set_on_update),
|
sol::writeonly_property(&window::set_on_resize), "title",
|
||||||
"on_resize",sol::writeonly_property(&window::set_on_resize),
|
sol::writeonly_property(&window::set_title), "size",
|
||||||
"title",sol::writeonly_property(&window::set_title),
|
sol::property(&window::size, &window::set_size), "client_size",
|
||||||
"size",sol::property(&window::size,&window::set_size),
|
sol::readonly_property(&window::client_size), "position",
|
||||||
"client_size",sol::readonly_property(&window::client_size),
|
sol::property(&window::position, &window::set_position), "fullscreen",
|
||||||
"position",sol::property(&window::position,&window::set_position),
|
sol::property(&window::fullscreen, &window::set_fullscreen), "visible",
|
||||||
"fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen),
|
sol::property(&window::visible, &window::set_visible));
|
||||||
"visible",sol::property(&window::visible,&window::set_visible)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
ns.new_usertype<input>(
|
||||||
|
"input", "new", sol::no_constructor, "get", &input::get,
|
||||||
|
"mouse_position", sol::readonly_property(&input::mouse_position),
|
||||||
|
"mouse_button", sol::readonly_property(&input::mouse_button),
|
||||||
|
"mouse_pressed", sol::readonly_property(&input::mouse_pressed),
|
||||||
|
"has_input", sol::readonly_property(&input::has_input), "input_string",
|
||||||
|
sol::readonly_property(&input::input_string));
|
||||||
|
|
||||||
ns.new_usertype<input>("input",
|
ns.new_usertype<display>("display", "all", &display::all, "name",
|
||||||
"new", sol::no_constructor,
|
sol::readonly_property(&display::name));
|
||||||
"get",&input::get,
|
|
||||||
"mouse_position",sol::readonly_property(&input::mouse_position),
|
|
||||||
"mouse_button",sol::readonly_property(&input::mouse_button),
|
|
||||||
"mouse_pressed",sol::readonly_property(&input::mouse_pressed),
|
|
||||||
"has_input",sol::readonly_property(&input::has_input),
|
|
||||||
"input_string",sol::readonly_property(&input::input_string)
|
|
||||||
);
|
|
||||||
|
|
||||||
ns.new_usertype<display>("display",
|
ns.new_usertype<path>(
|
||||||
"all",&display::all,
|
"path", "new", sol::no_constructor, "get", &path::get, "separator",
|
||||||
"name",sol::readonly_property(&display::name)
|
sol::readonly_property(&path::separator), "executable_path",
|
||||||
);
|
sol::readonly_property(&path::executable_path), "resource_paths",
|
||||||
|
sol::readonly_property(
|
||||||
ns.new_usertype<path>("path"
|
[](const path& p) { return sol::as_table(p.resource_paths()); }));
|
||||||
,"new",sol::no_constructor
|
|
||||||
,"get",&path::get
|
|
||||||
,"separator",sol::readonly_property(&path::separator)
|
|
||||||
,"executable_path",sol::readonly_property(&path::executable_path)
|
|
||||||
,"resource_paths",sol::readonly_property([](const path& p){return sol::as_table(p.resource_paths());})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PW_REGISTER_LUA(system)
|
PW_REGISTER_LUA(system)
|
||||||
|
|
||||||
|
} // namespace pw
|
||||||
}
|
|
||||||
|
|
|
@ -1,92 +1,76 @@
|
||||||
|
|
||||||
#include "pw/core/debug.hpp"
|
#include "pw/core/debug.hpp"
|
||||||
|
#include "pw/visual/context.hpp"
|
||||||
|
#include "pw/visual/framebuffer.hpp"
|
||||||
#include "pw/visual/pipeline.hpp"
|
#include "pw/visual/pipeline.hpp"
|
||||||
#include "pw/visual/shader.hpp"
|
#include "pw/visual/shader.hpp"
|
||||||
#include "pw/visual/framebuffer.hpp"
|
|
||||||
#include "pw/visual/texture.hpp"
|
#include "pw/visual/texture.hpp"
|
||||||
#include "pw/visual/context.hpp"
|
|
||||||
|
|
||||||
#include "pw/core/size.hpp"
|
#include "pw/core/size.hpp"
|
||||||
|
|
||||||
|
|
||||||
#include "runtime_lua.hpp"
|
#include "runtime_lua.hpp"
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
void register_visual_function(sol::state& lua,sol::table &ns)
|
void register_visual_function(sol::state& lua, sol::table& ns) {
|
||||||
{
|
|
||||||
|
|
||||||
// ns.new_usertype<pipeline>("pipeline"
|
// ns.new_usertype<pipeline>("pipeline"
|
||||||
// ,"create",&pipeline::create
|
// ,"create",&pipeline::create
|
||||||
// ,"draw",&pipeline::draw
|
// ,"draw",&pipeline::draw
|
||||||
// );
|
// );
|
||||||
|
|
||||||
ns.new_usertype<shader>("shader"
|
ns.new_usertype<shader>(
|
||||||
,sol::call_constructor,sol::constructors<shader()>()
|
"shader", sol::call_constructor, sol::constructors<shader()>(), "ready",
|
||||||
,"ready",sol::readonly_property(&shader::ready)
|
sol::readonly_property(&shader::ready), "use", &shader::use, "build",
|
||||||
,"use",&shader::use
|
&shader::build, "source", &shader::source, "set_source",
|
||||||
,"build",&shader::build
|
&shader::set_source, "set_uniforms", &shader::set_uniforms,
|
||||||
,"source",&shader::source
|
"set_uniform_float", &shader::set_uniform<float>, "set_uniform_uint",
|
||||||
,"set_source",&shader::set_source
|
&shader::set_uniform<uint32_t>, "set_uniform_int",
|
||||||
,"set_uniforms",&shader::set_uniforms
|
&shader::set_uniform<int32_t>, "set_uniform_mat4",
|
||||||
,"set_uniform_float",&shader::set_uniform<float>
|
&shader::set_uniform<matrix4x4&>, "set_uniform_vec4",
|
||||||
,"set_uniform_uint",&shader::set_uniform<uint32_t>
|
&shader::set_uniform<vector4&>, "set_uniform_texture",
|
||||||
,"set_uniform_int",&shader::set_uniform<int32_t>
|
&shader::set_uniform<texture&>
|
||||||
,"set_uniform_mat4",&shader::set_uniform<matrix4x4&>
|
|
||||||
,"set_uniform_vec4",&shader::set_uniform<vector4&>
|
|
||||||
,"set_uniform_texture",&shader::set_uniform<texture&>
|
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ns["shader_type"] = ns.create_named(
|
||||||
|
"shader_type", "fragment", shader::code_type::fragment, "vertex",
|
||||||
|
shader::code_type::vertex, "geometry", shader::code_type::geometry,
|
||||||
|
"compute", shader::code_type::compute);
|
||||||
|
|
||||||
ns["shader_type"] = ns.create_named("shader_type"
|
// new_enum<false>(
|
||||||
,"fragment",shader::code_type::fragment
|
|
||||||
,"vertex",shader::code_type::vertex
|
|
||||||
,"geometry",shader::code_type::geometry
|
|
||||||
,"compute",shader::code_type::compute);
|
|
||||||
|
|
||||||
// new_enum<false>(
|
// ns.new_usertype<render_pass>("render_pass"
|
||||||
|
// ,"submit",&render_pass::submit
|
||||||
|
// );
|
||||||
|
|
||||||
|
ns.new_usertype<renderer>(
|
||||||
|
"renderer", sol::call_constructor,
|
||||||
|
sol::constructors<renderer(), renderer(const geometry&)>(), "update",
|
||||||
|
&renderer::update, "ready", sol::readonly_property(&renderer::ready),
|
||||||
|
"change_count", sol::readonly_property(&renderer::change_count),
|
||||||
|
"release", &renderer::release, "draw", &renderer::draw);
|
||||||
|
|
||||||
// ns.new_usertype<render_pass>("render_pass"
|
ns.new_usertype<framebuffer>(
|
||||||
// ,"submit",&render_pass::submit
|
"framebuffer", sol::call_constructor,
|
||||||
// );
|
sol::constructors<framebuffer()>(), "create", &framebuffer::create,
|
||||||
|
"bind", &framebuffer::bind, "unbind", &framebuffer::unbind, "blit",
|
||||||
|
&framebuffer::blit);
|
||||||
|
|
||||||
|
ns.new_usertype<texture>("texture", sol::call_constructor,
|
||||||
|
sol::constructors<texture()>(), "create",
|
||||||
|
&texture::create, "update", &texture::update,
|
||||||
|
"bind", &texture::bind, "unbind", &texture::unbind,
|
||||||
|
"native_handle", &texture::native_handle);
|
||||||
|
|
||||||
ns.new_usertype<renderer>("renderer"
|
ns.new_usertype<context>(
|
||||||
,sol::call_constructor,sol::constructors<renderer(),renderer(const geometry&)>()
|
"context", sol::call_constructor, sol::constructors<context()>(),
|
||||||
,"update",&renderer::update
|
"clear", &context::clear, "clearcolor",
|
||||||
,"ready",sol::readonly_property(&renderer::ready)
|
sol::property(&context::clearcolor, &context::set_clearcolor),
|
||||||
,"change_count",sol::readonly_property(&renderer::change_count)
|
"set_viewport", &context::set_viewport, "get_error",
|
||||||
,"release",&renderer::release
|
&context::get_error);
|
||||||
,"draw",&renderer::draw
|
|
||||||
);
|
|
||||||
|
|
||||||
ns.new_usertype<framebuffer>("framebuffer"
|
|
||||||
,sol::call_constructor,sol::constructors<framebuffer()>()
|
|
||||||
,"create",&framebuffer::create
|
|
||||||
,"bind",&framebuffer::bind
|
|
||||||
,"unbind",&framebuffer::unbind
|
|
||||||
,"blit",&framebuffer::blit);
|
|
||||||
|
|
||||||
ns.new_usertype<texture>("texture"
|
|
||||||
,sol::call_constructor,sol::constructors<texture()>()
|
|
||||||
,"create",&texture::create
|
|
||||||
,"update",&texture::update
|
|
||||||
,"bind",&texture::bind
|
|
||||||
,"unbind",&texture::unbind
|
|
||||||
,"native_handle",&texture::native_handle
|
|
||||||
);
|
|
||||||
|
|
||||||
ns.new_usertype<context>("context"
|
|
||||||
,sol::call_constructor,sol::constructors<context()>()
|
|
||||||
,"clear",&context::clear
|
|
||||||
,"clearcolor",sol::property(&context::clearcolor,&context::set_clearcolor)
|
|
||||||
,"set_viewport",&context::set_viewport
|
|
||||||
,"get_error",&context::get_error
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PW_REGISTER_LUA(visual)
|
PW_REGISTER_LUA(visual)
|
||||||
|
|
||||||
}
|
} // namespace pw
|
||||||
|
|
|
@ -31,6 +31,30 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
struct geometry {
|
||||||
|
|
||||||
|
enum struct topology_type {
|
||||||
|
point_list,
|
||||||
|
line_list,
|
||||||
|
line_strip,
|
||||||
|
triange_list,
|
||||||
|
triangle_strip,
|
||||||
|
triangle_fan,
|
||||||
|
line_list_with_adjacency,
|
||||||
|
line_strip_with_adjacency,
|
||||||
|
triangle_list_with_adjacency,
|
||||||
|
triangle_strip_with_adjacency,
|
||||||
|
patch_list
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<vector3<float>> vertices{};
|
||||||
|
std::vector<std::size_t> indices{};
|
||||||
|
topology_type topology{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace pw
|
||||||
|
|
||||||
|
#if 0
|
||||||
/*
|
/*
|
||||||
* NOTE this needs to be rewritten to take into account for *any* kind of
|
* NOTE this needs to be rewritten to take into account for *any* kind of
|
||||||
* geometry Some ideas are drafted down there to separate out the attribute
|
* geometry Some ideas are drafted down there to separate out the attribute
|
||||||
|
@ -109,7 +133,6 @@ struct attribute final {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
} // namespace pw
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -69,7 +69,9 @@ struct matrix final {
|
||||||
//
|
//
|
||||||
template <size_type idx> auto get(this auto&& self) -> decltype(auto) {
|
template <size_type idx> auto get(this auto&& self) -> decltype(auto) {
|
||||||
static_assert(idx < Rows, "Out of bounds access to a member.");
|
static_assert(idx < Rows, "Out of bounds access to a member.");
|
||||||
return std::forward_like<decltype(self)>(self.m_[idx]);
|
// TODO: use forward_like when clang is catching up
|
||||||
|
// return std::forward_like<decltype(self)>(self.m_[idx]);
|
||||||
|
return std::forward<decltype(self)>(self).m_[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto diagonal() const noexcept -> diag_type {
|
constexpr auto diagonal() const noexcept -> diag_type {
|
||||||
|
|
32
src/core/include/pw/core/mesh.hpp
Normal file
32
src/core/include/pw/core/mesh.hpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef PW_CORE_MESH_HPP
|
||||||
|
#define PW_CORE_MESH_HPP
|
||||||
|
|
||||||
|
#include <pw/core/globals.hpp>
|
||||||
|
|
||||||
|
namespace pw {
|
||||||
|
|
||||||
|
} // namespace pw
|
||||||
|
|
||||||
|
#endif
|
|
@ -65,9 +65,7 @@ struct serialize {
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr static std::string to_string(const color& v) {
|
constexpr static std::string to_string(const color& v) {
|
||||||
std::stringstream ss;
|
return to_string(v.rgba);
|
||||||
ss << to_string(v.rgba);
|
|
||||||
return ss.str();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -91,8 +91,8 @@ template <typename Scalar, std::size_t N> struct vector final {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, T... indices>
|
template <typename T, T... indices>
|
||||||
constexpr auto slice(std::integer_sequence<T, indices...>,T offset = T{0}) const noexcept
|
constexpr auto slice(std::integer_sequence<T, indices...>, T offset = T{0})
|
||||||
-> vector<Scalar, sizeof...(indices)> {
|
const noexcept -> vector<Scalar, sizeof...(indices)> {
|
||||||
return {{Scalar{v_[indices + offset]}...}};
|
return {{Scalar{v_[indices + offset]}...}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +279,9 @@ template <typename Scalar, std::size_t N> struct vector final {
|
||||||
//
|
//
|
||||||
template <size_type idx> auto get(this auto&& self) -> decltype(auto) {
|
template <size_type idx> auto get(this auto&& self) -> decltype(auto) {
|
||||||
static_assert(idx < N, "Out of bounds access to a member.");
|
static_assert(idx < N, "Out of bounds access to a member.");
|
||||||
return std::forward_like<decltype(self)>(self.v_[idx]);
|
// TODO: use forward_like when clang is catching up
|
||||||
|
// return std::forward_like<decltype(self)>(self.v_[idx]);
|
||||||
|
return std::forward<decltype(self)>(self).v_[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -63,6 +63,6 @@ auto main() -> int {
|
||||||
<< pw::serialize::to_string(m33) << "\n to \n"
|
<< pw::serialize::to_string(m33) << "\n to \n"
|
||||||
<< pw::serialize::to_string(m22_slice);
|
<< pw::serialize::to_string(m22_slice);
|
||||||
|
|
||||||
// octave style output
|
// octave/matlab style output
|
||||||
std::print("\nm33=[{}]\n", m33);
|
std::print("\nm33=[{}]\n", m33);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,46 +1,49 @@
|
||||||
|
#include <cstdint>
|
||||||
|
#include <pw/core/axisangle.hpp>
|
||||||
|
#include <pw/core/geometry.hpp>
|
||||||
#include <pw/core/matrix_transform.hpp>
|
#include <pw/core/matrix_transform.hpp>
|
||||||
#include <pw/core/serialize.hpp>
|
#include <pw/core/serialize.hpp>
|
||||||
#include <pw/core/vector.hpp>
|
#include <pw/core/vector.hpp>
|
||||||
// #include <pw/core/geometry.hpp>
|
|
||||||
#include <pw/core/axisangle.hpp>
|
|
||||||
|
|
||||||
#include <print>
|
#include <print>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
struct geometry_n {
|
|
||||||
|
|
||||||
enum struct topology_type {
|
struct attribute final {
|
||||||
point_list,
|
using mask_type = std::vector<bool>;
|
||||||
line_list,
|
using int8_type = std::vector<int8_t>;
|
||||||
line_strip,
|
using int32_type = std::vector<int32_t>;
|
||||||
triange_list,
|
using float_type = std::vector<float>;
|
||||||
triangle_strip,
|
using vector2_type = std::vector<vector2<float>>;
|
||||||
triangle_fan,
|
using vector3_type = std::vector<vector3<float>>;
|
||||||
line_list_with_adjacency,
|
using vector4_type = std::vector<vector4<float>>;
|
||||||
line_strip_with_adjacency,
|
|
||||||
triangle_list_with_adjacency,
|
using attribute_data =
|
||||||
triangle_strip_with_adjacency,
|
std::variant<std::monostate, mask_type, int8_type, int32_type,
|
||||||
patch_list
|
float_type, vector2_type, vector3_type, vector4_type>;
|
||||||
|
|
||||||
|
enum attribute_type {
|
||||||
|
normals,
|
||||||
|
texture_coordinates,
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<vector<float, 3>> vertices{};
|
using data_type = std::tuple<attribute_type,attribute_data>;
|
||||||
std::vector<std::size_t> indices{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mesh_n {
|
struct mesh_n {
|
||||||
geometry_n geometry{};
|
geometry data{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pw
|
} // namespace pw
|
||||||
|
|
||||||
auto main() -> int {
|
auto main() -> int {
|
||||||
|
|
||||||
auto geom = pw::geometry_n{.vertices = {{1.2f, 2.4f, 4.8f},
|
auto geom = pw::geometry{.vertices = {{1.2f, 2.4f, 4.8f},
|
||||||
{2.4f, 1.2f, 4.8f},
|
{2.4f, 1.2f, 4.8f},
|
||||||
{1.2f, 4.8f, 2.4f}},
|
{1.2f, 4.8f, 2.4f}},
|
||||||
.indices = {0, 1, 2}};
|
.indices = {0, 1, 2}};
|
||||||
|
|
||||||
for (auto i : geom.indices) {
|
for (auto i : geom.indices) {
|
||||||
std::print("({}) ", pw::serialize::to_string(geom.vertices[i]));
|
std::print("({}) ", pw::serialize::to_string(geom.vertices[i]));
|
||||||
|
|
|
@ -69,7 +69,7 @@ auto main() -> int {
|
||||||
std::print("y: {}\n", vec3f.get<1>());
|
std::print("y: {}\n", vec3f.get<1>());
|
||||||
std::print("tuple size {}\n", std::tuple_size_v<decltype(vec3f)>);
|
std::print("tuple size {}\n", std::tuple_size_v<decltype(vec3f)>);
|
||||||
|
|
||||||
auto& [x, y, z] = vec3f;
|
const auto& [x, y, z] = vec3f;
|
||||||
std::print("x:{} y:{} z:{}\n", x, y, z);
|
std::print("x:{} y:{} z:{}\n", x, y, z);
|
||||||
|
|
||||||
auto min_ab{vec3f.min(pw::vector{1.3f, 0.9f, 2.3f})};
|
auto min_ab{vec3f.min(pw::vector{1.3f, 0.9f, 2.3f})};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue