Merge remote branch 'origin/master'

This commit is contained in:
Hartmut Seichter 2019-01-17 14:16:50 +01:00
commit 7c424b713e
13 changed files with 131 additions and 49 deletions

View file

@ -48,6 +48,11 @@ public:
matrix_& operator = (const matrix_& other);
matrix_(std::initializer_list<T> il)
{
// for (int i = 0;i < il.size();i++) (*this).at(i) = il[i];
}
matrix_ transposed() const;
inline matrix_& operator *= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) *= b; return *this; }
@ -102,7 +107,7 @@ public:
matrix_<R,C,T>& copy_from_data(const T* src) { for (unsigned int i = 0; i < R*C; ++i) { (*this).at(i) = src[i]; } return *this; }
matrix_<R,C,T> operator * (const matrix_<R,C,T>& rhs) const {
return mul(*this,rhs);
return mul(rhs);
}
const matrix_<C,R,T> reshape() const {
@ -124,6 +129,26 @@ public:
}
void normalize();
template <unsigned int bC>
matrix_<R,bC,T> mul(const matrix_<R,bC,T>& B) const
{
// aC == bR
// set all null
matrix_<R,bC,T> res;
res.fill(0);
// compute all resulting cells
for (unsigned int r = 0; r < R; ++r) {
for (unsigned int c = 0; c < bC; ++c) {
// building inner product
for (unsigned int iI = 0; iI < R;iI++) {
res.at(r,c) += (*this).at(r,iI) * B.at(iI,c);
}
}
}
return res;
}
};
/////////////////////////////////////////////////////////////////////////////
@ -176,28 +201,32 @@ inline matrix_<R,C,T> operator - (const matrix_<R,C,T>& a, const matrix_<R,C,T>&
return res;
}
//template <unsigned int aR,unsigned int aCbR, unsigned int bC, typename T>
//matrix_<aR,bC,T> static inline
//mul(const matrix_<aR,aCbR,T>& A, const matrix_<aCbR,bC,T>& B)
//{
// // aC == bR
// // set all null
// matrix_<aR,bC,T> res;
// res.fill(0);
// // compute all resulting cells
// for (unsigned int r = 0; r < aR; ++r) {
// for (unsigned int c = 0; c < bC; ++c) {
// // building inner product
// for (unsigned int iI = 0; iI < aCbR;iI++) {
// res.at(r,c) += A.at(r,iI) * B.at(iI,c);
// }
// }
// }
// return res;
//}
/////////////////////////////////////////////////////////////////////////////
template <unsigned int aR,unsigned int aCbR, unsigned int bC, typename T>
matrix_<aR,bC,T> static inline
mul(const matrix_<aR,aCbR,T>& A, const matrix_<aCbR,bC,T>& B)
{
// aC == bR
// set all null
matrix_<aR,bC,T> res;
res.fill(0);
// compute all resulting cells
for (unsigned int r = 0; r < aR; ++r) {
for (unsigned int c = 0; c < bC; ++c) {
// building inner product
for (unsigned int iI = 0; iI < aCbR;iI++) {
res.at(r,c) += A.at(r,iI) * B.at(iI,c);
}
}
}
return res;
}
@ -206,7 +235,7 @@ mul(const matrix_<aR,aCbR,T>& A, const matrix_<aCbR,bC,T>& B)
template <unsigned int R, unsigned int C,typename T>
matrix_<R,C,T>& matrix_<R,C,T>::operator *= (const matrix_& rhs)
{
*this = mul(*this,rhs);
*this = mul(rhs);
return *this;
}

View file

@ -23,6 +23,9 @@
#ifndef PW_CORE_MATRIXBASE_HPP
#define PW_CORE_MATRIXBASE_HPP
#include <initializer_list>
namespace pw {
/**
@ -36,6 +39,9 @@ public:
typedef unsigned int size_type;
matrixbase() {}
//! assignment constructor
explicit matrixbase(int rows, int cols,T* ptr,bool row_major,int data_offset = 0)
: _data(ptr)
@ -47,6 +53,11 @@ public:
{
}
// matrixbase(std::initializer_list<T> il)
// {
// for (int i = 0;i < il.size();i++) this->at(i) = il[i];
// }
inline const T& get_element(int e) const { return this->at(e); }
inline void set_element(int e,const T &v) { this->at(e) = v; }

View file

@ -51,6 +51,8 @@ public:
const indexarray_t& indices() const { return _indices; }
const vertex3array_t& vertices() const { return _vertices; }
void apply(const matrix4x4& m);
void reset();
protected:

View file

@ -38,7 +38,7 @@ struct rect_ {
rect_(point_<T_> const & p,size_<T_> const & s) : size(s), position(p) {}
bool contains(const point_<T_>& p)
bool contains(const point_<T_>& p) const
{
return p.x >= position.x && p.x <= position.x + size.width &&
p.y >= position.y && p.y <= position.y + size.height;

View file

@ -98,8 +98,8 @@ public:
T& z() { return (*this)(2); }
const vector_<4,T> project(const T& w) const {
return vector_<4,T>(x(),y(),z(),w);
vector_<4,T> project(const T& w) const {
return vector_<4,T>({ x(),y(),z(),w } );
}
const vector_<2,T> unproject() const {

View file

@ -3,6 +3,17 @@
namespace pw {
void mesh::apply(const matrix4x4 &m)
{
for (auto &v : _vertices)
{
// v = m * v.project(1);
auto vh = v.project(1);
m.mul(vh);
}
}
}

View file

@ -24,8 +24,6 @@
namespace pw {
static timer global_timer;
timer::timer()
{
reset();
@ -48,6 +46,7 @@ double timer::elapsed() const
double timer::now()
{
static timer global_timer;
return global_timer.elapsed();
}

View file

@ -17,7 +17,8 @@ void script_system::load(sol::table &ns)
"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)
"fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen),
"visible",sol::property(&window::visible,&window::set_visible)
);

View file

@ -66,6 +66,7 @@ end
--n_1:add_child()
local w = pw.window.new()
w.visible = false
-- set title
w.title = "pixwerx 0.1"
@ -75,6 +76,8 @@ w.size = pw.size.new(800,600)
-- move window
w.position = pw.point.new(100,100)
print("client size after resize: ",w.client_size.width,w.client_size.height)
local pl = pw.pipeline.new()
if pl:create(w.client_size) then
@ -83,12 +86,11 @@ else
print("pipeline failed")
end
-- setup a lua callback function
-- setup a lua callback function as callback
w.on_update = function(self)
pl:draw()
-- print("test on update",w.position.x,w.position.y,pw.timer.now)
end
local ds = pw.display:all()
@ -98,8 +100,9 @@ end
local t = pw.timer.new()
while w:update()
do
w.visible = true
while w:update() do
-- somehow works
if (pw.input.get().input_string == 'f') then
w.fullscreen = not w.fullscreen
@ -109,7 +112,7 @@ do
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)
print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y,w.client_size.width,w.client_size.height)
end
-- print("update")

View file

@ -40,6 +40,9 @@ private:
int _mouse_button;
bool _mouse_pressed;
int _key_code;
bool _key_pressed;
std::string _input_string;

View file

@ -35,6 +35,8 @@ public:
void set_on_update(on_update_t f) { _on_update = f; }
bool visible() const;
void set_visible(bool is_visible);
protected:
on_update_t _on_update;

View file

@ -70,12 +70,15 @@ struct window::impl {
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos)
{
input::get()._mouse_position = point(xpos,ypos);
input::get()._mouse_position = pointd(xpos,ypos).cast<float>();
}
static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods)
{
std::cout << __FUNCTION__ << std::endl;
input::get()._key_code = scancode;
input::get()._key_pressed = action;
// action 0,1,2
// std::cout << __FUNCTION__ << action << std::endl;
}
// static void character_callback(GLFWwindow* window, unsigned int codepoint)
@ -167,7 +170,7 @@ struct window::impl {
glfwSetWindowUserPointer(_window,this);
glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback);
//glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback);
glfwSetKeyCallback(_window, window::impl::key_callback);
// glfwSetCharCallback(_window, character_callback);
glfwSetCharModsCallback(_window, charmods_callback);
@ -200,13 +203,6 @@ struct window::impl {
_parent._on_update(_parent);
// do other stuff
#if 0
glClearColor(1,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
#endif
glfwSwapBuffers(_window);
return true;
@ -280,6 +276,14 @@ struct window::impl {
bool fullscreen() const {
return glfwGetWindowMonitor(_window) != nullptr;
}
void set_visible(bool show) {
(show) ? glfwShowWindow(_window) : glfwHideWindow(_window);
}
bool visible() const {
return glfwGetWindowAttrib(_window, GLFW_VISIBLE) > 0;
}
};
@ -343,6 +347,15 @@ void window::set_fullscreen(bool use_fullscreen)
_impl->set_fullscreen(use_fullscreen);
}
bool window::visible() const
{
return _impl->visible();
}
void window::set_visible(bool is_visible)
{
_impl->set_visible(is_visible);
}

View file

@ -42,7 +42,7 @@ struct triangle_renderer
glBindVertexArray(vao);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
const char* vertex_shader =
"#version 400\n"
@ -56,7 +56,7 @@ struct triangle_renderer
"#version 400\n"
"out vec4 frag_colour;"
"void main() {"
" frag_colour = vec4(0.5, 0.0, 0.5, 1.0);"
" frag_colour = vec4(0.1, 0.0, 0.5, 1.0);"
"}";
#if 0
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
@ -185,10 +185,13 @@ bool pipeline::impl::create(sizei size)
void pipeline::impl::draw()
{
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo_msaa);
glClearColor(1,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
tr.draw();
@ -225,7 +228,12 @@ void pipeline::impl::draw()
GL_COLOR_BUFFER_BIT, // buffer mask
GL_LINEAR); // scale filter
debug::d() << _size.width << "x" << _size.height;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
// debug::d() << _size.width << "x" << _size.height;
#endif