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
|
||||
|
||||
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
|
||||
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
|
||||
* 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),
|
||||
"reset",&time::reset
|
||||
);
|
||||
|
||||
ns.new_usertype<geometry>("geometry"
|
||||
, sol::constructors<geometry()>()
|
||||
, sol::constructors<geometry(),geometry(geometry::topology_type)>()
|
||||
, "topology", sol::property(&geometry::topology,&geometry::set_topology)
|
||||
, "vertices", sol::property(&geometry::vertices,&geometry::set_vertices)
|
||||
, "indices", sol::property(&geometry::indices,&geometry::set_indices)
|
||||
).new_enum<false>("topology_type"
|
||||
).new_enum<false>("type"
|
||||
,"points", geometry::topology_type::points
|
||||
, "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
|
||||
|
|
|
@ -15,16 +15,32 @@ void register_visual_function(sol::state&,sol::table &ns)
|
|||
,"draw",&pipeline::draw
|
||||
);
|
||||
|
||||
|
||||
|
||||
ns.new_usertype<shader>("shader"
|
||||
,sol::constructors<shader()>()
|
||||
,"ready",sol::readonly_property(&shader::ready)
|
||||
,"use",&shader::use
|
||||
,"build",&shader::build
|
||||
,"set_source",&shader::set_source
|
||||
,"source",&shader::source
|
||||
,"set_source",&shader::set_source
|
||||
,"set_uniforms",&shader::set_uniforms
|
||||
).new_enum<false>("shader_type"
|
||||
,"fragment",shader::code_type::fragment
|
||||
,"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
|
||||
);
|
||||
// .new_enum("shader_type"
|
||||
// ,"fragment",shader::code_type::fragment
|
||||
// ,"vertex",shader::code_type::vertex);
|
||||
|
||||
ns.new_usertype<material>("material"
|
||||
,"color",sol::property(&material::_color));
|
||||
|
||||
|
||||
ns.new_usertype<mesh_renderer>("mesh_renderer");
|
||||
}
|
||||
|
||||
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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -52,6 +52,7 @@ public:
|
|||
using vertex3array_t = std::vector<vector3> ;
|
||||
|
||||
geometry() = default;
|
||||
geometry(topology_type t);
|
||||
|
||||
void set_indices(const indexarray_t& v) { _indices = v; }
|
||||
const indexarray_t& indices() const { return _indices; }
|
||||
|
@ -65,7 +66,7 @@ public:
|
|||
void set_topology(topology_type t) { _topology = t; }
|
||||
topology_type topology() { return _topology; }
|
||||
|
||||
void apply(const matrix4x4& m);
|
||||
void transform(const matrix4x4& m);
|
||||
|
||||
void reset();
|
||||
|
||||
|
|
|
@ -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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* 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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -30,17 +30,21 @@
|
|||
namespace pw {
|
||||
|
||||
/**
|
||||
* @brief A simple timer
|
||||
* @brief A simple high resolution timer
|
||||
*/
|
||||
class time {
|
||||
public:
|
||||
|
||||
using tick_t = std::chrono::time_point<std::chrono::high_resolution_clock> ;
|
||||
|
||||
time(); /// c'tor
|
||||
~time(); /// d'tor
|
||||
time() = default;
|
||||
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
|
||||
|
@ -56,7 +60,7 @@ public:
|
|||
|
||||
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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -55,6 +55,11 @@ void geometry::compute_normals()
|
|||
// now set back
|
||||
}
|
||||
|
||||
geometry::geometry(geometry::topology_type t)
|
||||
: _topology(t)
|
||||
{
|
||||
}
|
||||
|
||||
void geometry::set_vertices(const geometry::vertex3array_t &v)
|
||||
{
|
||||
// first set vertices
|
||||
|
@ -74,7 +79,7 @@ const geometry::vertex3array_t &geometry::normals() const
|
|||
return _normals;
|
||||
}
|
||||
|
||||
void geometry::apply(const matrix4x4 &m)
|
||||
void geometry::transform(const matrix4x4 &m)
|
||||
{
|
||||
// apply transformation to all 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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -24,18 +24,9 @@
|
|||
|
||||
namespace pw {
|
||||
|
||||
time::time()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
time::~time()
|
||||
{
|
||||
}
|
||||
|
||||
void time::reset()
|
||||
{
|
||||
_start = std::chrono::high_resolution_clock::now();
|
||||
*this = time();
|
||||
}
|
||||
|
||||
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});
|
||||
|
||||
amesh.apply(scale);
|
||||
amesh.transform(scale);
|
||||
|
||||
std::cout << "after scale" << std::endl;
|
||||
|
||||
|
@ -34,7 +34,7 @@ int main(int argc,char **argv) {
|
|||
|
||||
auto rot_mat = aa.to_matrix();
|
||||
|
||||
amesh.apply(rot_mat);
|
||||
amesh.transform(rot_mat);
|
||||
|
||||
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
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
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
|
||||
)
|
||||
|
||||
set(scripts_test
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
namespace pw {
|
||||
|
||||
|
||||
class entity {
|
||||
public:
|
||||
entity() = default;
|
||||
|
@ -135,7 +136,7 @@ public:
|
|||
std::string name();
|
||||
private:
|
||||
|
||||
std::shared_ptr<entt::registry> _registry;
|
||||
std::shared_ptr<registry> _registry;
|
||||
entt::entity _entity { entt::null };
|
||||
|
||||
};
|
||||
|
|
|
@ -33,6 +33,8 @@ namespace pw {
|
|||
|
||||
class entity;
|
||||
|
||||
using entt::registry;
|
||||
|
||||
class scene {
|
||||
public:
|
||||
|
||||
|
@ -46,7 +48,7 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
std::shared_ptr<entt::registry> _registry;
|
||||
std::shared_ptr<registry> _registry;
|
||||
friend class entity;
|
||||
};
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ w.size = pw.size.new(640,480)
|
|||
-- move window
|
||||
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)
|
||||
|
||||
|
@ -46,6 +46,8 @@ local t = pw.time.new()
|
|||
|
||||
w.visible = true
|
||||
|
||||
-- sr = pw:scene_renderer.new()
|
||||
|
||||
while w:update() do
|
||||
-- somehow works
|
||||
if (pw.input.get().input_string == 'f') then
|
||||
|
@ -59,12 +61,14 @@ while w:update() do
|
|||
|
||||
-- just to check
|
||||
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,w.client_size.width,w.client_size.height)
|
||||
end
|
||||
|
||||
-- print("update")
|
||||
|
||||
|
||||
end
|
||||
|
||||
--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
|
||||
* 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/pipeline.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
|
||||
|
@ -13,7 +14,8 @@ set(srcs
|
|||
src/pipeline.cpp
|
||||
src/target.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
|
||||
* 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,11 +4,20 @@
|
|||
#include <pw/core/size.hpp>
|
||||
#include <pw/core/matrix.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>
|
||||
|
||||
namespace pw {
|
||||
|
||||
|
||||
|
||||
|
||||
class pipeline {
|
||||
|
||||
public:
|
||||
|
@ -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
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
if (location >= 0)
|
||||
return set(location, std::forward<T>(value));
|
||||
else
|
||||
debug::e() << "missing uniform: '" << name << "'";
|
||||
debug::w() << "missing uniform: '" << name << "'";
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
void set_uniforms(uniform_cache_t c);
|
||||
|
||||
unsigned int native_handle() const;
|
||||
uint32_t native_handle() const;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -68,6 +68,7 @@ protected:
|
|||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#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/size.hpp"
|
||||
|
@ -14,10 +14,7 @@ namespace pw {
|
|||
struct mesh_renderer::impl {
|
||||
|
||||
GLuint _vao = 0;
|
||||
|
||||
|
||||
std::vector<GLuint> _vbos;
|
||||
|
||||
GLint _mesh_elements = {0};
|
||||
|
||||
impl()
|
||||
|
@ -84,10 +81,6 @@ struct mesh_renderer::impl {
|
|||
if (error != GL_NO_ERROR) {
|
||||
debug::e() << "GL error: " << error;
|
||||
}
|
||||
|
||||
debug::d() << "Vertices: " << m.vertices().size();
|
||||
debug::d() << "Indices " << m.indices().size();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,6 +95,7 @@ struct mesh_renderer::impl {
|
|||
|
||||
void draw()
|
||||
{
|
||||
if (glIsVertexArray(_vao)) {
|
||||
glBindVertexArray(_vao);
|
||||
glDrawElements(GL_TRIANGLES, _mesh_elements, GL_UNSIGNED_INT, nullptr);
|
||||
glBindVertexArray(0);
|
||||
|
@ -110,7 +104,7 @@ struct mesh_renderer::impl {
|
|||
if (error != GL_NO_ERROR) {
|
||||
debug::e() << "GL error: " << error;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// GLint get_mode(vertex_array::)
|
|
@ -2,6 +2,13 @@
|
|||
// 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 {
|
||||
|
||||
|
||||
|
@ -9,4 +16,7 @@ class pass {
|
|||
virtual void submit();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
#include "pw/core/debug.hpp"
|
||||
#include "pw/visual/pipeline.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"
|
||||
|
||||
|
@ -32,15 +33,47 @@ class queue {
|
|||
// 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
|
||||
{
|
||||
// GLuint vbo = 0;
|
||||
// GLuint vao = 0;
|
||||
// GLuint shader_programme = 0;
|
||||
|
||||
|
||||
shader shader_p;
|
||||
geometry amesh;
|
||||
mesh_renderer amesh_renderer;
|
||||
mesh_renderer renderer;
|
||||
time::tick_t tick;
|
||||
|
||||
triangle_renderer()
|
||||
|
@ -53,20 +86,6 @@ struct triangle_renderer
|
|||
const float z_val = -5.f;
|
||||
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
|
||||
// | / |
|
||||
|
@ -85,14 +104,11 @@ struct triangle_renderer
|
|||
2, 3, 1};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
amesh.set_indices(indices);
|
||||
amesh.set_vertices(vertices);
|
||||
|
||||
amesh.compute_normals();
|
||||
|
||||
amesh_renderer.create(amesh);
|
||||
|
||||
const char* vertex_shader_2 = R"(
|
||||
#version 400
|
||||
|
@ -125,6 +141,9 @@ struct triangle_renderer
|
|||
|
||||
void draw()
|
||||
{
|
||||
if (!renderer.ready())
|
||||
renderer.create(amesh);
|
||||
|
||||
|
||||
// input needed here -
|
||||
// model view projection
|
||||
|
@ -187,7 +206,7 @@ struct triangle_renderer
|
|||
|
||||
#endif
|
||||
|
||||
amesh_renderer.draw();
|
||||
renderer.draw();
|
||||
|
||||
auto error = glGetError();
|
||||
if (error != GL_NO_ERROR){
|
||||
|
|
|
@ -25,16 +25,18 @@ struct shader::impl
|
|||
|
||||
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()
|
||||
{
|
||||
if (!is_valid()) return false;
|
||||
|
||||
for (auto s : _shader._source)
|
||||
for (const auto & [type,code] : _shader._source)
|
||||
{
|
||||
GLuint shader_type = 0;
|
||||
switch (s.first) {
|
||||
switch (type) {
|
||||
case shader::code_type::vertex:
|
||||
shader_type = GL_VERTEX_SHADER;
|
||||
break;
|
||||
|
@ -51,8 +53,8 @@ struct shader::impl
|
|||
|
||||
GLuint shaderId = glCreateShader(shader_type);
|
||||
|
||||
char* src = const_cast<char*>(s.second.c_str());
|
||||
GLint size = static_cast<GLint>(s.second.length());
|
||||
char* src = const_cast<char*>(code.c_str());
|
||||
GLint size = static_cast<GLint>(code.length());
|
||||
|
||||
glShaderSource(shaderId , 1, &src, &size);
|
||||
|
||||
|
@ -132,6 +134,7 @@ struct shader::impl
|
|||
|
||||
void clear()
|
||||
{
|
||||
// potentially the GL driver hasn't been loaded
|
||||
if (is_valid()) {
|
||||
glDeleteProgram(_shader_program);
|
||||
|
||||
|
@ -211,6 +214,8 @@ void shader::use()
|
|||
|
||||
void shader::set_uniforms(uniform_cache_t c)
|
||||
{
|
||||
// TODO rewrite in proper C++17
|
||||
|
||||
for (auto& u : c) {
|
||||
// get name
|
||||
std::string name = std::get<0>(u);
|
||||
|
@ -229,18 +234,20 @@ void shader::set_uniforms(uniform_cache_t c)
|
|||
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
|
||||
// TODO query the std::variant of uniform_t
|
||||
|
||||
if constexpr ((std::is_same_v<T, vector4f>) ||
|
||||
(std::is_same_v<T, matrix4x4f>) ||
|
||||
(std::is_same_v<T, float>) ) {
|
||||
set(loc, std::forward<T>(arg));
|
||||
} else {
|
||||
std::cout << "can't" << std::endl;
|
||||
debug::e() << "unknown uniform type";
|
||||
}
|
||||
}, var);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int shader::native_handle() const
|
||||
uint32_t shader::native_handle() const
|
||||
{
|
||||
return _impl->_shader_program;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue