Major update to revamp development
This commit is contained in:
parent
df12d68b22
commit
7479bfd625
12 changed files with 133 additions and 45 deletions
|
@ -9,6 +9,7 @@
|
|||
#include "pw/core/image.hpp"
|
||||
#include "pw/core/matrix_transform.hpp"
|
||||
#include "pw/core/rectangle.hpp"
|
||||
#include "pw/core/color.hpp"
|
||||
|
||||
#include "runtime_lua.hpp"
|
||||
|
||||
|
@ -49,6 +50,17 @@ void register_core_function(sol::state& lua,sol::table& ns)
|
|||
ns.set("pi",pw::pi<real_t>());
|
||||
|
||||
|
||||
|
||||
ns.new_usertype<color>("color",
|
||||
sol::call_constructor,sol::constructors<color(),color(real_t,real_t,real_t,real_t)>(),
|
||||
"rgba",&color::rgba,
|
||||
"data",sol::property([](color& c) { return std::ref(c.rgba.data);} ),
|
||||
"table",sol::property([](const color& c){ return sol::as_table(std::array<vector4::value_type,4>{c.rgba.x(),c.rgba.y(),c.rgba.z(),c.rgba.w()}); },
|
||||
[](color& c,const sol::table& t) { c = color((real_t)t[0],t[1],t[2],t[3]);})
|
||||
|
||||
);
|
||||
|
||||
|
||||
ns.new_usertype<matrix4x4>("matrix4x4",
|
||||
sol::call_constructor,sol::constructors<matrix4x4()>(),
|
||||
"row",&matrix4x4::row,
|
||||
|
@ -170,6 +182,7 @@ void register_core_function(sol::state& lua,sol::table& ns)
|
|||
sol::call_constructor,sol::constructors<geometry(),geometry(geometry::primitive_topology_type,vector3_array,geometry::indices_t)>(),
|
||||
"primitive_topology", sol::property(&geometry::primitive_topology,&geometry::set_primitive_topology),
|
||||
"compute_normals", &geometry::compute_normals,
|
||||
"change_count",sol::property(&geometry::change_count,&geometry::set_change_count),
|
||||
"indices",sol::property( [](const geometry& g){ return sol::as_table(g.indices());},
|
||||
[](geometry& g,sol::table t){
|
||||
std::vector<uint32_t> vals;
|
||||
|
|
|
@ -55,8 +55,9 @@ void register_visual_function(sol::state& lua,sol::table &ns)
|
|||
|
||||
ns.new_usertype<renderer>("renderer"
|
||||
,sol::call_constructor,sol::constructors<renderer(),renderer(const geometry&)>()
|
||||
,"create",&renderer::create
|
||||
,"update",&renderer::update
|
||||
,"ready",sol::readonly_property(&renderer::ready)
|
||||
,"change_count",sol::readonly_property(&renderer::change_count)
|
||||
,"release",&renderer::release
|
||||
,"draw",&renderer::draw
|
||||
);
|
||||
|
@ -80,6 +81,7 @@ void register_visual_function(sol::state& lua,sol::table &ns)
|
|||
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
|
||||
);
|
||||
|
|
|
@ -29,7 +29,10 @@
|
|||
namespace pw {
|
||||
|
||||
struct color {
|
||||
vector4 components;
|
||||
|
||||
vector4 rgba {0, 0, 0, 1};
|
||||
|
||||
color() = default;
|
||||
|
||||
color(uint8_t r8,uint8_t g8,uint8_t b8,uint8_t a8)
|
||||
: color(static_cast<real_t>(r8 / std::numeric_limits<uint8_t>::max()),
|
||||
|
@ -40,10 +43,14 @@ struct color {
|
|||
}
|
||||
|
||||
color(real_t r,real_t g,real_t b,real_t a)
|
||||
: components({r,g,b,a})
|
||||
: rgba({r,g,b,a})
|
||||
{
|
||||
}
|
||||
|
||||
color(const vector4& v) : rgba(v) { }
|
||||
|
||||
operator vector4() const { return rgba; }
|
||||
|
||||
uint32_t to_rgb8888() const {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -82,6 +82,10 @@ public:
|
|||
|
||||
aabb bounds() const;
|
||||
|
||||
uint64_t change_count() const { return _change_count; }
|
||||
void set_change_count(uint64_t n) { _change_count = n; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
primitive_topology_type _primitive_topology = primitive_topology_type::point_list;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
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
|
||||
${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_003.lua
|
||||
${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_002.lua
|
||||
${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_003.lua
|
||||
)
|
||||
|
||||
set(scripts_test
|
||||
|
@ -26,8 +26,8 @@ target_include_directories(pixwerx
|
|||
${CMAKE_SOURCE_DIR}/src/scripting/include
|
||||
)
|
||||
|
||||
target_link_libraries(pixwerx
|
||||
pwbinding
|
||||
# -Wl,--whole-archive -lpwscripting -Wl,--no-whole-archive
|
||||
pwcore
|
||||
pwsystem)
|
||||
target_link_libraries(pixwerx
|
||||
pwbinding
|
||||
pwcore
|
||||
pwsystem
|
||||
)
|
||||
|
|
|
@ -15,19 +15,12 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
//PW_RUNTIME_LUA_USE(core)
|
||||
|
||||
|
||||
int main(int argc,const char** argv) {
|
||||
|
||||
argagg::parser argparser {{
|
||||
{ "help", {"-h", "--help"},
|
||||
"shows this help message", 0},
|
||||
{ "file", {"-f", "--file"},
|
||||
"load file to run", 1}
|
||||
}
|
||||
};
|
||||
{ "help", {"-h", "--help"}, "shows this help message", 0},
|
||||
{ "file", {"-f", "--file"}, "load file to run", 1}
|
||||
}};
|
||||
|
||||
argagg::parser_results args;
|
||||
|
||||
|
|
|
@ -122,21 +122,26 @@ end
|
|||
-- the renderer for a geometry
|
||||
local renderer = pw.renderer()
|
||||
|
||||
if not renderer:create(g) then
|
||||
print("couldn't create renderer")
|
||||
end
|
||||
|
||||
-- camera position
|
||||
local cam_pos = pw.vector3(0,0,0)
|
||||
|
||||
-- model position
|
||||
local model_pos = pw.vector3(0,0,0)
|
||||
|
||||
|
||||
-- create new context (should move into a scene later)
|
||||
local ctx = pw.context()
|
||||
|
||||
-- create a texture
|
||||
local tx = pw.texture()
|
||||
|
||||
-- create texture from an image
|
||||
tx:create(img)
|
||||
|
||||
-- show how to unload it here
|
||||
|
||||
|
||||
-- set function to
|
||||
w.on_resize = function(self)
|
||||
-- use client_size to resize the viewport
|
||||
ctx:set_viewport(pw.rectangle(pw.point(0,0),self.client_size:cast_to_float()))
|
||||
|
@ -146,6 +151,9 @@ end
|
|||
-- setup a lua callback function as callback
|
||||
w.on_update = function(self)
|
||||
|
||||
ctx.clearcolor = pw.color(pw.mathf.ping_pong(pw.time.now,1.0),0,1,1)
|
||||
ctx:clear()
|
||||
|
||||
-- set view matrix with look_at - view matrix is moving the world - hence inverse!
|
||||
mv = pw.matrixtransform.look_at(cam_pos,cam_pos + pw.vector3.forward,pw.vector3.up).inverse
|
||||
|
||||
|
@ -153,7 +161,11 @@ w.on_update = function(self)
|
|||
aspect_ratio = self.client_size.width / self.client_size.height
|
||||
|
||||
-- create a view frustum for a perspective projection
|
||||
mp = pw.matrixtransform.perspective_projection(1.3,aspect_ratio,0.2,100)
|
||||
mp = pw.matrixtransform.perspective_projection(math.rad(45),aspect_ratio,0.2,100)
|
||||
|
||||
--
|
||||
-- this code is raw rendering mode
|
||||
--
|
||||
|
||||
-- just some toying around
|
||||
local color_red = pw.mathf.ping_pong(pw.time.now,1.0)
|
||||
|
@ -173,12 +185,16 @@ w.on_update = function(self)
|
|||
s:set_uniform_mat4("projection",mp)
|
||||
s:set_uniform_vec4("color",cl)
|
||||
|
||||
-- specific to our shader
|
||||
s:set_uniform_int("tex_color",0)
|
||||
|
||||
tx:bind()
|
||||
|
||||
-- update renderer from geometry
|
||||
renderer:update(g)
|
||||
|
||||
-- draw
|
||||
renderer:draw()
|
||||
renderer:draw()
|
||||
|
||||
local e = ctx:get_error()
|
||||
if e ~= 0 then
|
||||
|
@ -190,12 +206,16 @@ end
|
|||
-- before entering the update loop make the window visible
|
||||
w.visible = true
|
||||
|
||||
-- some fluffyness
|
||||
local speed = 0
|
||||
|
||||
-- main update loop
|
||||
while w:update() do
|
||||
|
||||
-- only check if get a new input
|
||||
if pw.input.get().has_input then
|
||||
|
||||
|
||||
-- somehow works
|
||||
if pw.input.get().input_string == 'f' then
|
||||
w.fullscreen = not w.fullscreen
|
||||
|
@ -207,7 +227,8 @@ while w:update() do
|
|||
end
|
||||
|
||||
-- just to quickly modify speed
|
||||
local move_step = 0.05
|
||||
local move_step = 0.05
|
||||
|
||||
|
||||
-- camera
|
||||
if pw.input.get().input_string == 'w' then
|
||||
|
@ -222,7 +243,9 @@ while w:update() do
|
|||
cam_pos.y = cam_pos.y + move_step
|
||||
elseif pw.input.get().input_string == 'x' then
|
||||
cam_pos.y = cam_pos.y - move_step
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- just some debugging
|
||||
print(cam_pos.x,cam_pos.y,cam_pos.z)
|
||||
|
|
|
@ -3,7 +3,7 @@ set(hdrs
|
|||
include/pw/visual/context.hpp
|
||||
include/pw/visual/framebuffer.hpp
|
||||
include/pw/visual/shader.hpp
|
||||
include/pw/visual/pipeline.hpp
|
||||
# include/pw/visual/pipeline.hpp
|
||||
include/pw/visual/texture.hpp
|
||||
include/pw/visual/renderer.hpp
|
||||
)
|
||||
|
@ -13,8 +13,8 @@ set(srcs
|
|||
src/framebuffer.cpp
|
||||
src/shader.cpp
|
||||
src/pass.cpp
|
||||
src/pipeline.cpp
|
||||
src/target.cpp
|
||||
# src/pipeline.cpp
|
||||
# src/target.cpp
|
||||
src/texture.cpp
|
||||
src/renderer.cpp
|
||||
)
|
||||
|
@ -39,5 +39,3 @@ target_include_directories(
|
|||
)
|
||||
|
||||
target_link_libraries(pwvisual pwscene glad)
|
||||
|
||||
#add_subdirectory(tests)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <pw/core/size.hpp>
|
||||
#include <pw/core/vector.hpp>
|
||||
#include <pw/core/rectangle.hpp>
|
||||
#include <pw/core/color.hpp>
|
||||
|
||||
|
||||
namespace pw {
|
||||
|
@ -47,11 +48,12 @@ public:
|
|||
size viewport_size() const;
|
||||
point viewport_origin() const;
|
||||
|
||||
void set_clearcolor(vector4f const& c);
|
||||
void set_clearcolor(const color &c);
|
||||
color clearcolor() const;
|
||||
|
||||
void clear();
|
||||
|
||||
u_int32_t get_error() const;
|
||||
uint32_t get_error() const;
|
||||
|
||||
protected:
|
||||
struct impl;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#ifndef PW_VISUAL_MESH_RENDERER_HPP
|
||||
#define PW_VISUAL_MESH_RENDERER_HPP
|
||||
|
||||
#include <pw/core/matrix.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
namespace pw {
|
||||
|
@ -14,17 +13,20 @@ class geometry;
|
|||
*/
|
||||
class renderer {
|
||||
public:
|
||||
|
||||
renderer();
|
||||
renderer(const geometry& m);
|
||||
|
||||
~renderer();
|
||||
|
||||
bool create(const geometry &m);
|
||||
bool update(const geometry &m);
|
||||
void release();
|
||||
|
||||
void draw();
|
||||
bool ready() const;
|
||||
|
||||
uint64_t change_count() const;
|
||||
void set_change_count(uint64_t n);
|
||||
protected:
|
||||
|
||||
struct impl;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "pw/visual/context.hpp"
|
||||
#include "pw/core/vector.hpp"
|
||||
|
||||
#include "glad/glad.h"
|
||||
|
||||
|
@ -7,6 +8,8 @@ namespace pw {
|
|||
|
||||
struct context::impl {
|
||||
|
||||
vector4f _clear_color { 0, 1, 0, 1};
|
||||
|
||||
void set_viewport(const rectangle& v)
|
||||
{
|
||||
glViewport(v.position.x,v.position.y,v.size.width,v.size.height);
|
||||
|
@ -21,9 +24,17 @@ struct context::impl {
|
|||
|
||||
void clear()
|
||||
{
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glFrontFace(GL_CCW);
|
||||
|
||||
glClearColor(_clear_color[0],_clear_color[1],_clear_color[2],_clear_color[3]);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t get_error() const
|
||||
{
|
||||
return glGetError();
|
||||
|
@ -65,6 +76,17 @@ u_int32_t context::get_error() const
|
|||
return _impl->get_error();
|
||||
}
|
||||
|
||||
color context::clearcolor() const
|
||||
{
|
||||
return _impl->_clear_color;
|
||||
}
|
||||
|
||||
void context::set_clearcolor(const color& c)
|
||||
{
|
||||
_impl->_clear_color = c;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "pw/core/geometry.hpp"
|
||||
#include "pw/core/size.hpp"
|
||||
#include "pw/core/debug.hpp"
|
||||
#include "pw/core/matrix.hpp"
|
||||
|
||||
#include "glad/glad.h"
|
||||
|
||||
|
@ -13,10 +14,13 @@ namespace pw {
|
|||
|
||||
struct renderer::impl {
|
||||
|
||||
uint64_t _change_count { 0 };
|
||||
|
||||
uint32_t _vao { 0 };
|
||||
uint32_t _ebo { 0 };
|
||||
std::vector<uint32_t> _vbos { };
|
||||
|
||||
|
||||
GLint _mesh_elements = { 0 };
|
||||
|
||||
impl() = default;
|
||||
|
@ -31,12 +35,14 @@ struct renderer::impl {
|
|||
return glIsVertexArray != nullptr && GL_TRUE == glIsVertexArray(_vao);
|
||||
}
|
||||
|
||||
bool create(const geometry& m)
|
||||
bool update(const geometry& m)
|
||||
{
|
||||
if (_change_count == m.change_count())
|
||||
return false;
|
||||
|
||||
// reset if the renderer already in use
|
||||
if (ready()) {
|
||||
if (ready())
|
||||
release();
|
||||
}
|
||||
|
||||
_mesh_elements = m.indices().size();
|
||||
|
||||
|
@ -115,6 +121,9 @@ struct renderer::impl {
|
|||
glBindVertexArray(0);
|
||||
|
||||
|
||||
this->_change_count = m.change_count();
|
||||
|
||||
|
||||
#if 0
|
||||
// get errors
|
||||
auto error = glGetError();
|
||||
|
@ -141,7 +150,8 @@ struct renderer::impl {
|
|||
void draw()
|
||||
{
|
||||
|
||||
#if 1
|
||||
// following code has no business being here ;)
|
||||
#if 0
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glFrontFace(GL_CCW);
|
||||
|
@ -181,7 +191,8 @@ renderer::renderer()
|
|||
renderer::renderer(const geometry &m)
|
||||
{
|
||||
renderer();
|
||||
_impl->create(m);
|
||||
// directly update
|
||||
_impl->update(m);
|
||||
}
|
||||
|
||||
renderer::~renderer()
|
||||
|
@ -193,9 +204,9 @@ bool renderer::ready() const
|
|||
return _impl->ready();
|
||||
}
|
||||
|
||||
bool renderer::create(const geometry &m)
|
||||
bool renderer::update(const geometry &m)
|
||||
{
|
||||
return _impl->create(m);
|
||||
return _impl->update(m);
|
||||
}
|
||||
|
||||
void renderer::release()
|
||||
|
@ -208,6 +219,17 @@ void renderer::draw()
|
|||
_impl->draw();
|
||||
}
|
||||
|
||||
uint64_t renderer::change_count() const
|
||||
{
|
||||
return _impl->_change_count;
|
||||
}
|
||||
|
||||
void renderer::set_change_count(uint64_t n)
|
||||
{
|
||||
_impl->_change_count = n;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//class viewport {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue