moving to a structure in visual representing the underlying APIs first and then layering on top the scene graph. Various other additions and fixes.
This commit is contained in:
parent
7037abbcb6
commit
40e8c43e01
15 changed files with 217 additions and 37 deletions
|
@ -18,10 +18,13 @@ bool image::create(const sizei &s, image::pixel_layout t, void *ptr)
|
|||
auto a = reinterpret_cast<uint8_t*>(ptr);
|
||||
|
||||
_data.assign(a,a + n);
|
||||
_size = s;
|
||||
_layout = t;
|
||||
|
||||
} else {
|
||||
|
||||
_data.resize(n,0);
|
||||
_size = sizei(0,0);
|
||||
}
|
||||
|
||||
return !_data.empty();
|
||||
|
|
|
@ -5,6 +5,7 @@ set(scripts_demo
|
|||
|
||||
set(scripts_test
|
||||
${CMAKE_SOURCE_DIR}/src/scripts/tests/test_core.lua
|
||||
${CMAKE_SOURCE_DIR}/src/scripts/tests/test_system.lua
|
||||
${CMAKE_SOURCE_DIR}/src/scripts/tests/test_io.lua
|
||||
)
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
#include "pw/io/image_io.hpp"
|
||||
|
||||
#include <pw/core/debug.hpp>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
// #include "stb_image_write.h"
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h"
|
||||
|
||||
namespace pw {
|
||||
|
||||
|
||||
struct image_io::impl
|
||||
{
|
||||
|
||||
|
@ -20,6 +22,7 @@ struct image_io::impl
|
|||
if (data) {
|
||||
|
||||
image r;
|
||||
|
||||
r.create(sizei(x,y),image::pixel_layout::RGBA8,data);
|
||||
return r;
|
||||
}
|
||||
|
@ -29,6 +32,7 @@ struct image_io::impl
|
|||
|
||||
bool write(const std::string& uri, uint32_t flags)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "pw/system/window.hpp"
|
||||
#include "pw/system/input.hpp"
|
||||
#include "pw/system/display.hpp"
|
||||
#include "pw/system/path.hpp"
|
||||
|
||||
#include "runtime_lua.hpp"
|
||||
|
||||
|
@ -38,6 +39,12 @@ void register_system_function(sol::state&, sol::table &ns)
|
|||
"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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include "pw/core/debug.hpp"
|
||||
#include "pw/visual/pipeline.hpp"
|
||||
#include "pw/visual/shader.hpp"
|
||||
|
||||
#include "runtime_lua.hpp"
|
||||
|
||||
|
@ -9,11 +10,20 @@ namespace pw {
|
|||
void register_visual_function(sol::state&,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"
|
||||
,"ready",sol::readonly_property(&shader::ready)
|
||||
,"use",&shader::use
|
||||
,"build",&shader::build
|
||||
,"set_source",&shader::set_source
|
||||
,"source",&shader::source
|
||||
).new_enum("shader_type"
|
||||
,"fragment",shader::fragment
|
||||
,"vertex",shader::vertex);
|
||||
}
|
||||
|
||||
PW_REGISTER_LUA(visual)
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
-- loading our libraries
|
||||
pw.script:load_all()
|
||||
|
||||
local img = pw.imageio:get():read("/home/hartmut/Development/pixwerx/share/assets/textures/checkerboard-512-32.png",0)
|
||||
local img = pw.imageio:get():read("/Users/hartmut/Code/pixwerx/share/assets/textures/checkerboard-512-32.png",0)
|
||||
|
||||
-- pw.imageio:get():read("/home/hartmut/Development/pixwerx/share/assets/textures/checkerboard-512-32.png",0)
|
||||
|
||||
print(img.size.width,img.size.height)
|
||||
|
||||
|
|
9
src/scripts/tests/test_system.lua
Normal file
9
src/scripts/tests/test_system.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
--
|
||||
-- pixwerx - test - io
|
||||
--
|
||||
|
||||
-- loading our libraries
|
||||
pw.script:load_all()
|
||||
|
||||
|
||||
print(pw.path:get().executable_path)
|
|
@ -1,14 +1,16 @@
|
|||
|
||||
set(hdrs
|
||||
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
|
||||
)
|
||||
|
||||
set(srcs
|
||||
src/display.cpp
|
||||
src/window.cpp
|
||||
src/path.cpp
|
||||
src/input.cpp
|
||||
src/window.cpp
|
||||
)
|
||||
|
||||
add_library(pwsystem
|
||||
|
|
38
src/system/include/pw/system/path.hpp
Normal file
38
src/system/include/pw/system/path.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef PW_SYSTEM_PATH_HPP
|
||||
#define PW_SYSTEM_PATH_HPP
|
||||
|
||||
#include <pw/core/globals.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
|
||||
class path {
|
||||
public:
|
||||
|
||||
static path& get();
|
||||
~path();
|
||||
|
||||
std::string separator();
|
||||
|
||||
std::string executable_path();
|
||||
|
||||
typedef std::vector<std::string> path_list;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
path_list _plugin_paths;
|
||||
path_list _resource_paths;
|
||||
|
||||
path();
|
||||
|
||||
struct impl;
|
||||
std::unique_ptr<impl> _impl;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
94
src/system/src/path.cpp
Normal file
94
src/system/src/path.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
#include "pw/system/path.hpp"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64) || defined(_WIN32_WCE)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <direct.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <unistd.h>
|
||||
#if defined(__MACH__)
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
// #include "_host/helpers_osx.h"
|
||||
#elif defined(TP_HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
// Unknown platform
|
||||
#endif
|
||||
|
||||
namespace pw {
|
||||
|
||||
|
||||
struct path::impl {
|
||||
|
||||
path &host;
|
||||
|
||||
impl(path &host_) : host(host_) {}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
path &path::get()
|
||||
{
|
||||
static path instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
path::~path()
|
||||
{
|
||||
}
|
||||
|
||||
std::string path::separator()
|
||||
{
|
||||
#if defined(WIN32)
|
||||
return std::string("\");
|
||||
#else
|
||||
return std::string("/");
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string path::executable_path()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
const unsigned int MAXPATHLEN = 2048;
|
||||
static char path[MAXPATHLEN];
|
||||
memset(&path[0],0,MAXPATHLEN);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
CFURLRef bundleURL;
|
||||
CFStringRef pathStr;
|
||||
CFBundleRef mainBundle = CFBundleGetMainBundle();
|
||||
|
||||
bundleURL = CFBundleCopyExecutableURL(mainBundle);
|
||||
pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
|
||||
CFStringGetCString(pathStr, path, MAXPATHLEN, kCFStringEncodingASCII);
|
||||
|
||||
result.assign(&path[0]);
|
||||
|
||||
CFRelease(pathStr);
|
||||
CFRelease(bundleURL);
|
||||
|
||||
#elif defined(_WIN32) || defined(_WIN64) || defined(_WIN32_WCE)
|
||||
static TCHAR lpFname[MAXPATHLEN];
|
||||
DWORD ret = GetModuleFileName( NULL, &lpFname[0], MAXPATHLEN );
|
||||
result.assign(&lpFname[0]);
|
||||
#else
|
||||
readlink("/proc/self/exe", path, sizeof(path));
|
||||
result.assign(path);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
path::path()
|
||||
{
|
||||
_impl = std::make_unique<impl>(*this);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
|
||||
set(hdrs
|
||||
include/pw/visual/mesh_renderer.hpp
|
||||
include/pw/visual/shader.hpp
|
||||
include/pw/visual/pipeline.hpp
|
||||
include/pw/visual/texture.hpp
|
||||
include/pw/visual/vertex_array.hpp
|
||||
)
|
||||
|
||||
set(srcs
|
||||
src/mesh_renderer.cpp
|
||||
src/shader.cpp
|
||||
src/context.cpp
|
||||
src/pipeline.cpp
|
||||
src/texture.cpp
|
||||
src/vertex_array.cpp
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,12 @@ class texture {
|
|||
shape_3d
|
||||
};
|
||||
|
||||
enum texture_dimension {
|
||||
dimension_s,
|
||||
dimension_t,
|
||||
dimension_r
|
||||
};
|
||||
|
||||
enum wrap_mode {
|
||||
wrap_repeat,
|
||||
wrap_clamp,
|
||||
|
@ -26,7 +32,6 @@ class texture {
|
|||
wrap_clamp_to_repeat
|
||||
};
|
||||
|
||||
|
||||
texture();
|
||||
|
||||
texture(shared_ptr<image> i,texture_shape s,texture_type = color);
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
|
||||
namespace pw {
|
||||
|
||||
class mesh_renderer {
|
||||
class vertex_array {
|
||||
public:
|
||||
vertex_array();
|
||||
vertex_array(const mesh& m);
|
||||
|
||||
|
||||
mesh_renderer();
|
||||
~mesh_renderer();
|
||||
~vertex_array();
|
||||
|
||||
bool ready() const;
|
||||
|
||||
|
@ -22,13 +22,6 @@ public:
|
|||
|
||||
void draw();
|
||||
|
||||
|
||||
// void render(const mesh& mesh,
|
||||
// const matrix4x4& model_matrix,
|
||||
// const matrix4x4& view_matrix,
|
||||
// const matrix4x4& projection_matrix
|
||||
// );
|
||||
|
||||
protected:
|
||||
|
||||
struct impl;
|
|
@ -6,12 +6,19 @@
|
|||
#include "pw/core/debug.hpp"
|
||||
#include "pw/visual/pipeline.hpp"
|
||||
#include "pw/visual/shader.hpp"
|
||||
#include "pw/visual/mesh_renderer.hpp"
|
||||
#include "pw/visual/vertex_array.hpp"
|
||||
|
||||
#include "glad/glad.h"
|
||||
|
||||
namespace pw {
|
||||
|
||||
class command {
|
||||
|
||||
// shader
|
||||
// vertexarray
|
||||
|
||||
};
|
||||
|
||||
class queue {
|
||||
|
||||
// vector<commands> ...
|
||||
|
@ -25,7 +32,7 @@ struct triangle_renderer
|
|||
|
||||
shader shader_p;
|
||||
mesh amesh;
|
||||
mesh_renderer amesh_renderer;
|
||||
vertex_array amesh_renderer;
|
||||
timer::tick_t tick;
|
||||
|
||||
triangle_renderer()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "pw/visual/mesh_renderer.hpp"
|
||||
#include "pw/visual/vertex_array.hpp"
|
||||
|
||||
#include "pw/core/mesh.hpp"
|
||||
#include "pw/core/size.hpp"
|
||||
|
@ -9,8 +9,7 @@
|
|||
|
||||
namespace pw {
|
||||
|
||||
|
||||
struct mesh_renderer::impl {
|
||||
struct vertex_array::impl {
|
||||
|
||||
GLuint _vao = 0;
|
||||
std::vector<GLuint> _vbos;
|
||||
|
@ -85,31 +84,37 @@ struct mesh_renderer::impl {
|
|||
//
|
||||
//
|
||||
|
||||
mesh_renderer::mesh_renderer()
|
||||
: _impl(std::make_unique<mesh_renderer::impl>())
|
||||
vertex_array::vertex_array()
|
||||
: _impl(std::make_unique<vertex_array::impl>())
|
||||
{
|
||||
}
|
||||
|
||||
mesh_renderer::~mesh_renderer()
|
||||
vertex_array::vertex_array(const mesh &m)
|
||||
{
|
||||
vertex_array();
|
||||
_impl->create(m);
|
||||
}
|
||||
|
||||
vertex_array::~vertex_array()
|
||||
{
|
||||
}
|
||||
|
||||
bool mesh_renderer::ready() const
|
||||
bool vertex_array::ready() const
|
||||
{
|
||||
return _impl->ready();
|
||||
}
|
||||
|
||||
void mesh_renderer::create(const mesh &m)
|
||||
void vertex_array::create(const mesh &m)
|
||||
{
|
||||
_impl->create(m);
|
||||
}
|
||||
|
||||
void mesh_renderer::destroy()
|
||||
void vertex_array::destroy()
|
||||
{
|
||||
_impl->destroy();
|
||||
}
|
||||
|
||||
void mesh_renderer::draw()
|
||||
void vertex_array::draw()
|
||||
{
|
||||
_impl->draw();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue