diff --git a/src/core/src/image.cpp b/src/core/src/image.cpp index 91a75ff..4cd44db 100644 --- a/src/core/src/image.cpp +++ b/src/core/src/image.cpp @@ -18,10 +18,13 @@ bool image::create(const sizei &s, image::pixel_layout t, void *ptr) auto a = reinterpret_cast(ptr); _data.assign(a,a + n); + _size = s; + _layout = t; } else { _data.resize(n,0); + _size = sizei(0,0); } return !_data.empty(); diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index 53af65b..734e8ba 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -5,7 +5,8 @@ set(scripts_demo set(scripts_test ${CMAKE_SOURCE_DIR}/src/scripts/tests/test_core.lua - ${CMAKE_SOURCE_DIR}/src/scripts/tests/test_io.lua + ${CMAKE_SOURCE_DIR}/src/scripts/tests/test_system.lua + ${CMAKE_SOURCE_DIR}/src/scripts/tests/test_io.lua ) add_executable(pixwerx WIN32 MACOSX_BUNDLE diff --git a/src/io/src/image_io.cpp b/src/io/src/image_io.cpp index f0ebc84..6ae8e1e 100644 --- a/src/io/src/image_io.cpp +++ b/src/io/src/image_io.cpp @@ -1,13 +1,15 @@ #include "pw/io/image_io.hpp" +#include + #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 { @@ -19,7 +21,8 @@ struct image_io::impl if (data) { - image r; + 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; } diff --git a/src/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index 12cc383..e257c45 100644 --- a/src/scripting/src/script_system.cpp +++ b/src/scripting/src/script_system.cpp @@ -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" + ,"new", sol::no_constructor + ,"get",&path::get + ,"separator",sol::readonly_property(&path::separator) + ,"executable_path",sol::readonly_property(&path::executable_path) + ); } diff --git a/src/scripting/src/script_visual.cpp b/src/scripting/src/script_visual.cpp index 5d3b66e..d51c347 100644 --- a/src/scripting/src/script_visual.cpp +++ b/src/scripting/src/script_visual.cpp @@ -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", - "create",&pipeline::create, - "draw",&pipeline::draw + ns.new_usertype("pipeline" + ,"create",&pipeline::create + ,"draw",&pipeline::draw ); + ns.new_usertype("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) diff --git a/src/scripts/tests/test_io.lua b/src/scripts/tests/test_io.lua index bbe4838..e18ec1c 100644 --- a/src/scripts/tests/test_io.lua +++ b/src/scripts/tests/test_io.lua @@ -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) diff --git a/src/scripts/tests/test_system.lua b/src/scripts/tests/test_system.lua new file mode 100644 index 0000000..2cd2ab0 --- /dev/null +++ b/src/scripts/tests/test_system.lua @@ -0,0 +1,9 @@ +-- +-- pixwerx - test - io +-- + +-- loading our libraries +pw.script:load_all() + + +print(pw.path:get().executable_path) diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt index 08b2781..8e10e8f 100644 --- a/src/system/CMakeLists.txt +++ b/src/system/CMakeLists.txt @@ -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 diff --git a/src/system/include/pw/system/path.hpp b/src/system/include/pw/system/path.hpp new file mode 100644 index 0000000..2812c45 --- /dev/null +++ b/src/system/include/pw/system/path.hpp @@ -0,0 +1,38 @@ +#ifndef PW_SYSTEM_PATH_HPP +#define PW_SYSTEM_PATH_HPP + +#include + +namespace pw { + + +class path { +public: + + static path& get(); + ~path(); + + std::string separator(); + + std::string executable_path(); + + typedef std::vector path_list; + + + +protected: + + path_list _plugin_paths; + path_list _resource_paths; + + path(); + + struct impl; + std::unique_ptr _impl; + + +}; + +} + +#endif diff --git a/src/system/src/path.cpp b/src/system/src/path.cpp new file mode 100644 index 0000000..bbeca09 --- /dev/null +++ b/src/system/src/path.cpp @@ -0,0 +1,94 @@ +#include "pw/system/path.hpp" + +#if defined(_WIN32) || defined(_WIN64) || defined(_WIN32_WCE) + #define WIN32_LEAN_AND_MEAN + #include + #include + #include +#elif defined(__APPLE__) + #include + #include + #if defined(__MACH__) + #include + #endif +// #include "_host/helpers_osx.h" +#elif defined(TP_HAVE_UNISTD_H) + #include +#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(*this); +} + +} diff --git a/src/visual/CMakeLists.txt b/src/visual/CMakeLists.txt index bd8f4c5..9fe9742 100644 --- a/src/visual/CMakeLists.txt +++ b/src/visual/CMakeLists.txt @@ -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 ) diff --git a/src/visual/include/pw/visual/texture.hpp b/src/visual/include/pw/visual/texture.hpp index 9df412c..2391b72 100644 --- a/src/visual/include/pw/visual/texture.hpp +++ b/src/visual/include/pw/visual/texture.hpp @@ -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 i,texture_shape s,texture_type = color); diff --git a/src/visual/include/pw/visual/mesh_renderer.hpp b/src/visual/include/pw/visual/vertex_array.hpp similarity index 60% rename from src/visual/include/pw/visual/mesh_renderer.hpp rename to src/visual/include/pw/visual/vertex_array.hpp index 2c67cbc..363849d 100644 --- a/src/visual/include/pw/visual/mesh_renderer.hpp +++ b/src/visual/include/pw/visual/vertex_array.hpp @@ -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; diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp index 8293d6e..c7ec474 100644 --- a/src/visual/src/pipeline.cpp +++ b/src/visual/src/pipeline.cpp @@ -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 ... @@ -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() diff --git a/src/visual/src/mesh_renderer.cpp b/src/visual/src/vertex_array.cpp similarity index 79% rename from src/visual/src/mesh_renderer.cpp rename to src/visual/src/vertex_array.cpp index 4a5730d..13cd436 100644 --- a/src/visual/src/mesh_renderer.cpp +++ b/src/visual/src/vertex_array.cpp @@ -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 _vbos; @@ -85,31 +84,37 @@ struct mesh_renderer::impl { // // -mesh_renderer::mesh_renderer() - : _impl(std::make_unique()) +vertex_array::vertex_array() + : _impl(std::make_unique()) { } -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(); }