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/input.hpp"
|
||||
#include "pw/system/path.hpp"
|
||||
#include "pw/system/window.hpp"
|
||||
|
||||
#include "runtime_lua.hpp"
|
||||
|
||||
|
@ -13,49 +13,37 @@
|
|||
|
||||
namespace pw {
|
||||
|
||||
void register_system_function(sol::state&, sol::table &ns)
|
||||
{
|
||||
ns.new_usertype<window>("window",
|
||||
"update",&window::update,
|
||||
"on_update",sol::writeonly_property(&window::set_on_update),
|
||||
"on_resize",sol::writeonly_property(&window::set_on_resize),
|
||||
"title",sol::writeonly_property(&window::set_title),
|
||||
"size",sol::property(&window::size,&window::set_size),
|
||||
"client_size",sol::readonly_property(&window::client_size),
|
||||
"position",sol::property(&window::position,&window::set_position),
|
||||
"fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen),
|
||||
"visible",sol::property(&window::visible,&window::set_visible)
|
||||
);
|
||||
void register_system_function(sol::state&, sol::table& ns) {
|
||||
ns.new_usertype<window>(
|
||||
"window", "update", &window::update, "on_update",
|
||||
sol::writeonly_property(&window::set_on_update), "on_resize",
|
||||
sol::writeonly_property(&window::set_on_resize), "title",
|
||||
sol::writeonly_property(&window::set_title), "size",
|
||||
sol::property(&window::size, &window::set_size), "client_size",
|
||||
sol::readonly_property(&window::client_size), "position",
|
||||
sol::property(&window::position, &window::set_position), "fullscreen",
|
||||
sol::property(&window::fullscreen, &window::set_fullscreen), "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",
|
||||
"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<display>("display", "all", &display::all, "name",
|
||||
sol::readonly_property(&display::name));
|
||||
|
||||
ns.new_usertype<display>("display",
|
||||
"all",&display::all,
|
||||
"name",sol::readonly_property(&display::name)
|
||||
);
|
||||
|
||||
ns.new_usertype<path>("path"
|
||||
,"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());})
|
||||
);
|
||||
ns.new_usertype<path>(
|
||||
"path", "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)
|
||||
|
||||
|
||||
}
|
||||
} // namespace pw
|
||||
|
|
|
@ -1,92 +1,76 @@
|
|||
|
||||
#include "pw/core/debug.hpp"
|
||||
#include "pw/visual/context.hpp"
|
||||
#include "pw/visual/framebuffer.hpp"
|
||||
#include "pw/visual/pipeline.hpp"
|
||||
#include "pw/visual/shader.hpp"
|
||||
#include "pw/visual/framebuffer.hpp"
|
||||
#include "pw/visual/texture.hpp"
|
||||
#include "pw/visual/context.hpp"
|
||||
|
||||
#include "pw/core/size.hpp"
|
||||
|
||||
|
||||
#include "runtime_lua.hpp"
|
||||
|
||||
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"
|
||||
// ,"create",&pipeline::create
|
||||
// ,"draw",&pipeline::draw
|
||||
// );
|
||||
// ns.new_usertype<pipeline>("pipeline"
|
||||
// ,"create",&pipeline::create
|
||||
// ,"draw",&pipeline::draw
|
||||
// );
|
||||
|
||||
ns.new_usertype<shader>("shader"
|
||||
,sol::call_constructor,sol::constructors<shader()>()
|
||||
,"ready",sol::readonly_property(&shader::ready)
|
||||
,"use",&shader::use
|
||||
,"build",&shader::build
|
||||
,"source",&shader::source
|
||||
,"set_source",&shader::set_source
|
||||
,"set_uniforms",&shader::set_uniforms
|
||||
,"set_uniform_float",&shader::set_uniform<float>
|
||||
,"set_uniform_uint",&shader::set_uniform<uint32_t>
|
||||
,"set_uniform_int",&shader::set_uniform<int32_t>
|
||||
,"set_uniform_mat4",&shader::set_uniform<matrix4x4&>
|
||||
,"set_uniform_vec4",&shader::set_uniform<vector4&>
|
||||
,"set_uniform_texture",&shader::set_uniform<texture&>
|
||||
ns.new_usertype<shader>(
|
||||
"shader", sol::call_constructor, sol::constructors<shader()>(), "ready",
|
||||
sol::readonly_property(&shader::ready), "use", &shader::use, "build",
|
||||
&shader::build, "source", &shader::source, "set_source",
|
||||
&shader::set_source, "set_uniforms", &shader::set_uniforms,
|
||||
"set_uniform_float", &shader::set_uniform<float>, "set_uniform_uint",
|
||||
&shader::set_uniform<uint32_t>, "set_uniform_int",
|
||||
&shader::set_uniform<int32_t>, "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"
|
||||
,"fragment",shader::code_type::fragment
|
||||
,"vertex",shader::code_type::vertex
|
||||
,"geometry",shader::code_type::geometry
|
||||
,"compute",shader::code_type::compute);
|
||||
// new_enum<false>(
|
||||
|
||||
// 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"
|
||||
// ,"submit",&render_pass::submit
|
||||
// );
|
||||
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<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<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
|
||||
);
|
||||
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)
|
||||
|
||||
}
|
||||
} // namespace pw
|
||||
|
|
|
@ -31,6 +31,30 @@
|
|||
|
||||
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
|
||||
* geometry Some ideas are drafted down there to separate out the attribute
|
||||
|
@ -109,7 +133,6 @@ struct attribute final {
|
|||
|
||||
};
|
||||
|
||||
|
||||
} // namespace pw
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -69,7 +69,9 @@ struct matrix final {
|
|||
//
|
||||
template <size_type idx> auto get(this auto&& self) -> decltype(auto) {
|
||||
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 {
|
||||
|
|
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) {
|
||||
std::stringstream ss;
|
||||
ss << to_string(v.rgba);
|
||||
return ss.str();
|
||||
return to_string(v.rgba);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -91,8 +91,8 @@ template <typename Scalar, std::size_t N> struct vector final {
|
|||
}
|
||||
|
||||
template <typename T, T... indices>
|
||||
constexpr auto slice(std::integer_sequence<T, indices...>,T offset = T{0}) const noexcept
|
||||
-> vector<Scalar, sizeof...(indices)> {
|
||||
constexpr auto slice(std::integer_sequence<T, indices...>, T offset = T{0})
|
||||
const noexcept -> vector<Scalar, sizeof...(indices)> {
|
||||
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) {
|
||||
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(m22_slice);
|
||||
|
||||
// octave style output
|
||||
// octave/matlab style output
|
||||
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/serialize.hpp>
|
||||
#include <pw/core/vector.hpp>
|
||||
// #include <pw/core/geometry.hpp>
|
||||
#include <pw/core/axisangle.hpp>
|
||||
|
||||
#include <print>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace pw {
|
||||
struct geometry_n {
|
||||
|
||||
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
|
||||
struct attribute final {
|
||||
using mask_type = std::vector<bool>;
|
||||
using int8_type = std::vector<int8_t>;
|
||||
using int32_type = std::vector<int32_t>;
|
||||
using float_type = std::vector<float>;
|
||||
using vector2_type = std::vector<vector2<float>>;
|
||||
using vector3_type = std::vector<vector3<float>>;
|
||||
using vector4_type = std::vector<vector4<float>>;
|
||||
|
||||
using attribute_data =
|
||||
std::variant<std::monostate, mask_type, int8_type, int32_type,
|
||||
float_type, vector2_type, vector3_type, vector4_type>;
|
||||
|
||||
enum attribute_type {
|
||||
normals,
|
||||
texture_coordinates,
|
||||
};
|
||||
|
||||
std::vector<vector<float, 3>> vertices{};
|
||||
std::vector<std::size_t> indices{};
|
||||
using data_type = std::tuple<attribute_type,attribute_data>;
|
||||
};
|
||||
|
||||
struct mesh_n {
|
||||
geometry_n geometry{};
|
||||
geometry data{};
|
||||
};
|
||||
|
||||
} // namespace pw
|
||||
|
||||
auto main() -> int {
|
||||
|
||||
auto geom = pw::geometry_n{.vertices = {{1.2f, 2.4f, 4.8f},
|
||||
{2.4f, 1.2f, 4.8f},
|
||||
{1.2f, 4.8f, 2.4f}},
|
||||
.indices = {0, 1, 2}};
|
||||
auto geom = pw::geometry{.vertices = {{1.2f, 2.4f, 4.8f},
|
||||
{2.4f, 1.2f, 4.8f},
|
||||
{1.2f, 4.8f, 2.4f}},
|
||||
.indices = {0, 1, 2}};
|
||||
|
||||
for (auto i : geom.indices) {
|
||||
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("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);
|
||||
|
||||
auto min_ab{vec3f.min(pw::vector{1.3f, 0.9f, 2.3f})};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue