update copyright notice
This commit is contained in:
parent
8253756e4c
commit
77e254872f
44 changed files with 213 additions and 116 deletions
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -103,15 +103,17 @@ void register_core_function(sol::state& lua,sol::table& ns)
|
||||||
"elapsed",sol::readonly_property(&time::elapsed),
|
"elapsed",sol::readonly_property(&time::elapsed),
|
||||||
"reset",&time::reset
|
"reset",&time::reset
|
||||||
);
|
);
|
||||||
|
|
||||||
ns.new_usertype<geometry>("geometry"
|
ns.new_usertype<geometry>("geometry"
|
||||||
, sol::constructors<geometry()>()
|
, sol::constructors<geometry(),geometry(geometry::topology_type)>()
|
||||||
, "topology", sol::property(&geometry::topology,&geometry::set_topology)
|
, "topology", sol::property(&geometry::topology,&geometry::set_topology)
|
||||||
, "vertices", sol::property(&geometry::vertices,&geometry::set_vertices)
|
, "vertices", sol::property(&geometry::vertices,&geometry::set_vertices)
|
||||||
, "indices", sol::property(&geometry::indices,&geometry::set_indices)
|
, "indices", sol::property(&geometry::indices,&geometry::set_indices)
|
||||||
).new_enum<false>("topology_type"
|
).new_enum<false>("type"
|
||||||
,"points", geometry::topology_type::points
|
,"points", geometry::topology_type::points
|
||||||
, "lines", geometry::topology_type::lines
|
, "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
|
// SOL3
|
||||||
|
|
|
@ -15,16 +15,32 @@ void register_visual_function(sol::state&,sol::table &ns)
|
||||||
,"draw",&pipeline::draw
|
,"draw",&pipeline::draw
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ns.new_usertype<shader>("shader"
|
ns.new_usertype<shader>("shader"
|
||||||
|
,sol::constructors<shader()>()
|
||||||
,"ready",sol::readonly_property(&shader::ready)
|
,"ready",sol::readonly_property(&shader::ready)
|
||||||
,"use",&shader::use
|
,"use",&shader::use
|
||||||
,"build",&shader::build
|
,"build",&shader::build
|
||||||
,"set_source",&shader::set_source
|
,"source",&shader::source
|
||||||
,"source",&shader::source
|
,"set_source",&shader::set_source
|
||||||
);
|
,"set_uniforms",&shader::set_uniforms
|
||||||
// .new_enum("shader_type"
|
).new_enum<false>("shader_type"
|
||||||
// ,"fragment",shader::code_type::fragment
|
,"fragment",shader::code_type::fragment
|
||||||
// ,"vertex",shader::code_type::vertex);
|
,"vertex",shader::code_type::vertex
|
||||||
|
,"geometry",shader::code_type::geometry
|
||||||
|
,"compute",shader::code_type::compute);
|
||||||
|
|
||||||
|
|
||||||
|
ns.new_usertype<render_pass>("render_pass"
|
||||||
|
,"submit",&render_pass::submit
|
||||||
|
);
|
||||||
|
|
||||||
|
ns.new_usertype<material>("material"
|
||||||
|
,"color",sol::property(&material::_color));
|
||||||
|
|
||||||
|
|
||||||
|
ns.new_usertype<mesh_renderer>("mesh_renderer");
|
||||||
}
|
}
|
||||||
|
|
||||||
PW_REGISTER_LUA(visual)
|
PW_REGISTER_LUA(visual)
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -52,6 +52,7 @@ public:
|
||||||
using vertex3array_t = std::vector<vector3> ;
|
using vertex3array_t = std::vector<vector3> ;
|
||||||
|
|
||||||
geometry() = default;
|
geometry() = default;
|
||||||
|
geometry(topology_type t);
|
||||||
|
|
||||||
void set_indices(const indexarray_t& v) { _indices = v; }
|
void set_indices(const indexarray_t& v) { _indices = v; }
|
||||||
const indexarray_t& indices() const { return _indices; }
|
const indexarray_t& indices() const { return _indices; }
|
||||||
|
@ -65,7 +66,7 @@ public:
|
||||||
void set_topology(topology_type t) { _topology = t; }
|
void set_topology(topology_type t) { _topology = t; }
|
||||||
topology_type topology() { return _topology; }
|
topology_type topology() { return _topology; }
|
||||||
|
|
||||||
void apply(const matrix4x4& m);
|
void transform(const matrix4x4& m);
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ protected:
|
||||||
vertex3array_t _normals; //!< normal data
|
vertex3array_t _normals; //!< normal data
|
||||||
vertex3array_t _colors; //!< color data
|
vertex3array_t _colors; //!< color data
|
||||||
|
|
||||||
std::vector<vertex2array_t> _uvs; //!< storing multiple UV sets
|
std::vector<vertex2array_t> _uvs; //!< storing multiple UV sets
|
||||||
|
|
||||||
struct aabb _aabb;
|
struct aabb _aabb;
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -30,17 +30,21 @@
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A simple timer
|
* @brief A simple high resolution timer
|
||||||
*/
|
*/
|
||||||
class time {
|
class time {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using tick_t = std::chrono::time_point<std::chrono::high_resolution_clock> ;
|
using tick_t = std::chrono::time_point<std::chrono::high_resolution_clock> ;
|
||||||
|
|
||||||
time(); /// c'tor
|
time() = default;
|
||||||
~time(); /// d'tor
|
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
|
* @brief elapsed time based on the scale
|
||||||
|
@ -56,7 +60,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
tick_t _start;
|
tick_t _start = std::chrono::high_resolution_clock::now();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -55,6 +55,11 @@ void geometry::compute_normals()
|
||||||
// now set back
|
// now set back
|
||||||
}
|
}
|
||||||
|
|
||||||
|
geometry::geometry(geometry::topology_type t)
|
||||||
|
: _topology(t)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void geometry::set_vertices(const geometry::vertex3array_t &v)
|
void geometry::set_vertices(const geometry::vertex3array_t &v)
|
||||||
{
|
{
|
||||||
// first set vertices
|
// first set vertices
|
||||||
|
@ -74,7 +79,7 @@ const geometry::vertex3array_t &geometry::normals() const
|
||||||
return _normals;
|
return _normals;
|
||||||
}
|
}
|
||||||
|
|
||||||
void geometry::apply(const matrix4x4 &m)
|
void geometry::transform(const matrix4x4 &m)
|
||||||
{
|
{
|
||||||
// apply transformation to all vertices
|
// apply transformation to all vertices
|
||||||
for (auto &v : _vertices)
|
for (auto &v : _vertices)
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -24,18 +24,9 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
time::time()
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
time::~time()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void time::reset()
|
void time::reset()
|
||||||
{
|
{
|
||||||
_start = std::chrono::high_resolution_clock::now();
|
*this = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
double time::elapsed() const
|
double time::elapsed() const
|
||||||
|
|
|
@ -19,7 +19,7 @@ int main(int argc,char **argv) {
|
||||||
|
|
||||||
auto scale = pw::matrix_transform<float>::scale_matrix({2,2,2});
|
auto scale = pw::matrix_transform<float>::scale_matrix({2,2,2});
|
||||||
|
|
||||||
amesh.apply(scale);
|
amesh.transform(scale);
|
||||||
|
|
||||||
std::cout << "after scale" << std::endl;
|
std::cout << "after scale" << std::endl;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ int main(int argc,char **argv) {
|
||||||
|
|
||||||
auto rot_mat = aa.to_matrix();
|
auto rot_mat = aa.to_matrix();
|
||||||
|
|
||||||
amesh.apply(rot_mat);
|
amesh.transform(rot_mat);
|
||||||
|
|
||||||
std::cout << "after rotate" << std::endl;
|
std::cout << "after rotate" << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
set(scripts_demo
|
set(scripts_demo
|
||||||
${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_000.lua
|
${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_001.lua
|
||||||
|
${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_002.lua
|
||||||
)
|
)
|
||||||
|
|
||||||
set(scripts_test
|
set(scripts_test
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
|
||||||
class entity {
|
class entity {
|
||||||
public:
|
public:
|
||||||
entity() = default;
|
entity() = default;
|
||||||
|
@ -135,7 +136,7 @@ public:
|
||||||
std::string name();
|
std::string name();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::shared_ptr<entt::registry> _registry;
|
std::shared_ptr<registry> _registry;
|
||||||
entt::entity _entity { entt::null };
|
entt::entity _entity { entt::null };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,6 +33,8 @@ namespace pw {
|
||||||
|
|
||||||
class entity;
|
class entity;
|
||||||
|
|
||||||
|
using entt::registry;
|
||||||
|
|
||||||
class scene {
|
class scene {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -46,7 +48,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std::shared_ptr<entt::registry> _registry;
|
std::shared_ptr<registry> _registry;
|
||||||
friend class entity;
|
friend class entity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ w.size = pw.size.new(640,480)
|
||||||
-- move window
|
-- move window
|
||||||
w.position = pw.point.new(100,100)
|
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)
|
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
|
w.visible = true
|
||||||
|
|
||||||
|
-- sr = pw:scene_renderer.new()
|
||||||
|
|
||||||
while w:update() do
|
while w:update() do
|
||||||
-- somehow works
|
-- somehow works
|
||||||
if (pw.input.get().input_string == 'f') then
|
if (pw.input.get().input_string == 'f') then
|
||||||
|
@ -59,12 +61,14 @@ while w:update() do
|
||||||
|
|
||||||
-- just to check
|
-- just to check
|
||||||
if (pw.input:get().mouse_button == 1) then
|
if (pw.input:get().mouse_button == 1) then
|
||||||
|
|
||||||
print("elapsed",t.elapsed)
|
print("elapsed",t.elapsed)
|
||||||
t:reset()
|
t:reset()
|
||||||
print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y,w.client_size.width,w.client_size.height)
|
print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y,w.client_size.width,w.client_size.height)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- print("update")
|
-- print("update")
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--local scene = pw:scene.new()
|
--local scene = pw:scene.new()
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -3,7 +3,8 @@ set(hdrs
|
||||||
include/pw/visual/shader.hpp
|
include/pw/visual/shader.hpp
|
||||||
include/pw/visual/pipeline.hpp
|
include/pw/visual/pipeline.hpp
|
||||||
include/pw/visual/texture.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
|
set(srcs
|
||||||
|
@ -13,7 +14,8 @@ set(srcs
|
||||||
src/pipeline.cpp
|
src/pipeline.cpp
|
||||||
src/target.cpp
|
src/target.cpp
|
||||||
src/texture.cpp
|
src/texture.cpp
|
||||||
src/vertex_array.cpp
|
src/mesh_renderer.cpp
|
||||||
|
src/material.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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
13
src/visual/include/pw/visual/material.hpp
Normal file
13
src/visual/include/pw/visual/material.hpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pw/core/vector.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace pw {
|
||||||
|
|
||||||
|
struct material {
|
||||||
|
vector4f _color = vector4f {0xFF,0x00,0xFF,0xFF};
|
||||||
|
material() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -4,18 +4,27 @@
|
||||||
#include <pw/core/size.hpp>
|
#include <pw/core/size.hpp>
|
||||||
#include <pw/core/matrix.hpp>
|
#include <pw/core/matrix.hpp>
|
||||||
#include <pw/core/geometry.hpp>
|
#include <pw/core/geometry.hpp>
|
||||||
|
#include <pw/core/color.hpp>
|
||||||
|
|
||||||
|
#include <pw/visual/shader.hpp>
|
||||||
|
#include <pw/visual/mesh_renderer.hpp>
|
||||||
|
#include <pw/visual/material.hpp>
|
||||||
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class pipeline {
|
class pipeline {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
pipeline();
|
pipeline();
|
||||||
~pipeline();
|
~pipeline();
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
bool create(size s);
|
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
|
#endif
|
||||||
|
|
|
@ -29,7 +29,7 @@ public:
|
||||||
|
|
||||||
bool ready() const;
|
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,matrix4x4f const & v);
|
||||||
shader& set(int location,vector4f const & v);
|
shader& set(int location,vector4f const & v);
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public:
|
||||||
if (location >= 0)
|
if (location >= 0)
|
||||||
return set(location, std::forward<T>(value));
|
return set(location, std::forward<T>(value));
|
||||||
else
|
else
|
||||||
debug::e() << "missing uniform: '" << name << "'";
|
debug::w() << "missing uniform: '" << name << "'";
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
|
|
||||||
void set_uniforms(uniform_cache_t c);
|
void set_uniforms(uniform_cache_t c);
|
||||||
|
|
||||||
unsigned int native_handle() const;
|
uint32_t native_handle() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
0
src/visual/src/material.cpp
Normal file
0
src/visual/src/material.cpp
Normal file
|
@ -1,4 +1,4 @@
|
||||||
#include "pw/visual/vertex_array.hpp"
|
#include "pw/visual/mesh_renderer.hpp"
|
||||||
|
|
||||||
#include "pw/core/geometry.hpp"
|
#include "pw/core/geometry.hpp"
|
||||||
#include "pw/core/size.hpp"
|
#include "pw/core/size.hpp"
|
||||||
|
@ -14,10 +14,7 @@ namespace pw {
|
||||||
struct mesh_renderer::impl {
|
struct mesh_renderer::impl {
|
||||||
|
|
||||||
GLuint _vao = 0;
|
GLuint _vao = 0;
|
||||||
|
|
||||||
|
|
||||||
std::vector<GLuint> _vbos;
|
std::vector<GLuint> _vbos;
|
||||||
|
|
||||||
GLint _mesh_elements = {0};
|
GLint _mesh_elements = {0};
|
||||||
|
|
||||||
impl()
|
impl()
|
||||||
|
@ -84,10 +81,6 @@ struct mesh_renderer::impl {
|
||||||
if (error != GL_NO_ERROR) {
|
if (error != GL_NO_ERROR) {
|
||||||
debug::e() << "GL error: " << 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()
|
void draw()
|
||||||
{
|
{
|
||||||
glBindVertexArray(_vao);
|
if (glIsVertexArray(_vao)) {
|
||||||
glDrawElements(GL_TRIANGLES, _mesh_elements, GL_UNSIGNED_INT, nullptr);
|
glBindVertexArray(_vao);
|
||||||
glBindVertexArray(0);
|
glDrawElements(GL_TRIANGLES, _mesh_elements, GL_UNSIGNED_INT, nullptr);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
auto error = glGetError();
|
auto error = glGetError();
|
||||||
if (error != GL_NO_ERROR) {
|
if (error != GL_NO_ERROR) {
|
||||||
debug::e() << "GL error: " << error;
|
debug::e() << "GL error: " << error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLint get_mode(vertex_array::)
|
// GLint get_mode(vertex_array::)
|
|
@ -2,11 +2,21 @@
|
||||||
// a pass combines meshes, states and targets
|
// a pass combines meshes, states and targets
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <pw/core/geometry.hpp>
|
||||||
|
#include <pw/core/buffer.hpp>
|
||||||
|
|
||||||
|
#include <pw/visual/material.hpp>
|
||||||
|
#include <pw/visual/shader.hpp>
|
||||||
|
#include <pw/visual/mesh_renderer.hpp>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
|
||||||
class pass {
|
class pass {
|
||||||
virtual void submit();
|
virtual void submit();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
#include "pw/core/debug.hpp"
|
#include "pw/core/debug.hpp"
|
||||||
#include "pw/visual/pipeline.hpp"
|
#include "pw/visual/pipeline.hpp"
|
||||||
#include "pw/visual/shader.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"
|
#include "glad/glad.h"
|
||||||
|
|
||||||
|
@ -32,15 +33,47 @@ class queue {
|
||||||
// vector<commands> ...
|
// vector<commands> ...
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
struct triangle_renderer
|
||||||
{
|
{
|
||||||
// GLuint vbo = 0;
|
|
||||||
// GLuint vao = 0;
|
|
||||||
// GLuint shader_programme = 0;
|
|
||||||
|
|
||||||
shader shader_p;
|
shader shader_p;
|
||||||
geometry amesh;
|
geometry amesh;
|
||||||
mesh_renderer amesh_renderer;
|
mesh_renderer renderer;
|
||||||
time::tick_t tick;
|
time::tick_t tick;
|
||||||
|
|
||||||
triangle_renderer()
|
triangle_renderer()
|
||||||
|
@ -53,20 +86,6 @@ struct triangle_renderer
|
||||||
const float z_val = -5.f;
|
const float z_val = -5.f;
|
||||||
const float s = 1.0f;
|
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
|
// 0 -- 1
|
||||||
// | / |
|
// | / |
|
||||||
|
@ -74,7 +93,7 @@ struct triangle_renderer
|
||||||
|
|
||||||
// geometry
|
// geometry
|
||||||
geometry::vertex3array_t vertices = {
|
geometry::vertex3array_t vertices = {
|
||||||
{-s, s, z_val} // 0
|
{-s, s, z_val} // 0
|
||||||
,{ s, s, z_val} // 1
|
,{ s, s, z_val} // 1
|
||||||
,{-s, -s, z_val} // 2
|
,{-s, -s, z_val} // 2
|
||||||
,{ s, -s, z_val} // 3
|
,{ s, -s, z_val} // 3
|
||||||
|
@ -85,14 +104,11 @@ struct triangle_renderer
|
||||||
2, 3, 1};
|
2, 3, 1};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
amesh.set_indices(indices);
|
amesh.set_indices(indices);
|
||||||
amesh.set_vertices(vertices);
|
amesh.set_vertices(vertices);
|
||||||
|
|
||||||
amesh.compute_normals();
|
amesh.compute_normals();
|
||||||
|
|
||||||
amesh_renderer.create(amesh);
|
|
||||||
|
|
||||||
const char* vertex_shader_2 = R"(
|
const char* vertex_shader_2 = R"(
|
||||||
#version 400
|
#version 400
|
||||||
|
@ -125,6 +141,9 @@ struct triangle_renderer
|
||||||
|
|
||||||
void draw()
|
void draw()
|
||||||
{
|
{
|
||||||
|
if (!renderer.ready())
|
||||||
|
renderer.create(amesh);
|
||||||
|
|
||||||
|
|
||||||
// input needed here -
|
// input needed here -
|
||||||
// model view projection
|
// model view projection
|
||||||
|
@ -187,7 +206,7 @@ struct triangle_renderer
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
amesh_renderer.draw();
|
renderer.draw();
|
||||||
|
|
||||||
auto error = glGetError();
|
auto error = glGetError();
|
||||||
if (error != GL_NO_ERROR){
|
if (error != GL_NO_ERROR){
|
||||||
|
|
|
@ -25,16 +25,18 @@ struct shader::impl
|
||||||
|
|
||||||
bool is_valid()
|
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()
|
bool build()
|
||||||
{
|
{
|
||||||
|
if (!is_valid()) return false;
|
||||||
|
|
||||||
for (auto s : _shader._source)
|
for (const auto & [type,code] : _shader._source)
|
||||||
{
|
{
|
||||||
GLuint shader_type = 0;
|
GLuint shader_type = 0;
|
||||||
switch (s.first) {
|
switch (type) {
|
||||||
case shader::code_type::vertex:
|
case shader::code_type::vertex:
|
||||||
shader_type = GL_VERTEX_SHADER;
|
shader_type = GL_VERTEX_SHADER;
|
||||||
break;
|
break;
|
||||||
|
@ -51,8 +53,8 @@ struct shader::impl
|
||||||
|
|
||||||
GLuint shaderId = glCreateShader(shader_type);
|
GLuint shaderId = glCreateShader(shader_type);
|
||||||
|
|
||||||
char* src = const_cast<char*>(s.second.c_str());
|
char* src = const_cast<char*>(code.c_str());
|
||||||
GLint size = static_cast<GLint>(s.second.length());
|
GLint size = static_cast<GLint>(code.length());
|
||||||
|
|
||||||
glShaderSource(shaderId , 1, &src, &size);
|
glShaderSource(shaderId , 1, &src, &size);
|
||||||
|
|
||||||
|
@ -131,15 +133,16 @@ struct shader::impl
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
if (is_valid()) {
|
// potentially the GL driver hasn't been loaded
|
||||||
|
if (is_valid()) {
|
||||||
glDeleteProgram(_shader_program);
|
glDeleteProgram(_shader_program);
|
||||||
|
|
||||||
for (auto s : _shader_stages)
|
for (auto s : _shader_stages)
|
||||||
{
|
{
|
||||||
glDeleteShader(s);
|
glDeleteShader(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int uniform_location(std::string const& name) const
|
int uniform_location(std::string const& name) const
|
||||||
|
@ -211,6 +214,8 @@ void shader::use()
|
||||||
|
|
||||||
void shader::set_uniforms(uniform_cache_t c)
|
void shader::set_uniforms(uniform_cache_t c)
|
||||||
{
|
{
|
||||||
|
// TODO rewrite in proper C++17
|
||||||
|
|
||||||
for (auto& u : c) {
|
for (auto& u : c) {
|
||||||
// get name
|
// get name
|
||||||
std::string name = std::get<0>(u);
|
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) {
|
std::visit([this,loc](auto&& arg) {
|
||||||
|
|
||||||
using T = std::decay_t<decltype(arg)>;
|
using T = std::decay_t<decltype(arg)>;
|
||||||
|
|
||||||
|
// TODO query the std::variant of uniform_t
|
||||||
|
|
||||||
if constexpr ((std::is_same_v<T, vector4f>) ||
|
if constexpr ((std::is_same_v<T, vector4f>) ||
|
||||||
(std::is_same_v<T, matrix4x4f>) ||
|
(std::is_same_v<T, matrix4x4f>) ||
|
||||||
(std::is_same_v<T, float>) ) {
|
(std::is_same_v<T, float>) ) {
|
||||||
set(loc, std::forward<T>(arg));
|
set(loc, std::forward<T>(arg));
|
||||||
} else {
|
} else {
|
||||||
std::cout << "can't" << std::endl;
|
debug::e() << "unknown uniform type";
|
||||||
}
|
}
|
||||||
}, var);
|
}, var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int shader::native_handle() const
|
uint32_t shader::native_handle() const
|
||||||
{
|
{
|
||||||
return _impl->_shader_program;
|
return _impl->_shader_program;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue