diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index eb0be27..0ad654b 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -1,20 +1,20 @@ find_package(mkdocs 1.0) # if(MKDOCS_FOUND) -# configure_file(mkdocs.yml "${CMAKE_CURRENT_BINARY_DIR}/mkdocs.yml" COPYONLY) -# set(MKDOCS_FLAGS -# --site-dir "${CMAKE_CURRENT_BINARY_DIR}/docs/user/" -# --config-file "${CMAKE_CURRENT_BINARY_DIR}/mkdocs.yml" -# ) -# if(DEBUG_MODE) -# list(APPEND MKDOCS_FLAGS --clean --verbose) -# endif() -# add_custom_target(docs-user -# ${MKDOCS_EXECUTABLE} build ${MKDOCS_FLAGS} -# WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" -# COMMENT "Generating user documentation" -# ) -# add_dependencies(docs docs-user) +# configure_file(mkdocs.yml "${CMAKE_CURRENT_BINARY_DIR}/mkdocs.yml" COPYONLY) +# set(MKDOCS_FLAGS +# --site-dir "${CMAKE_CURRENT_BINARY_DIR}/docs/user/" +# --config-file "${CMAKE_CURRENT_BINARY_DIR}/mkdocs.yml" +# ) +# if(DEBUG_MODE) +# list(APPEND MKDOCS_FLAGS --clean --verbose) +# endif() +# add_custom_target(docs-user +# ${MKDOCS_EXECUTABLE} build ${MKDOCS_FLAGS} +# WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" +# COMMENT "Generating user documentation" +# ) +# add_dependencies(docs docs-user) # else() -# message(STATUS "SKIPPING generation of user documentation (mkdocs not found)") +# message(STATUS "SKIPPING generation of user documentation (mkdocs not found)") # endif() diff --git a/share/doc/pixwerx.xmind b/share/doc/pixwerx.xmind index 6e061eb..5c96f0f 100644 Binary files a/share/doc/pixwerx.xmind and b/share/doc/pixwerx.xmind differ diff --git a/src/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index d5629e2..7ef8d35 100644 --- a/src/scripting/src/script_system.cpp +++ b/src/scripting/src/script_system.cpp @@ -2,6 +2,7 @@ #include "pw/system/window.hpp" #include "pw/system/input.hpp" +#include "pw/system/display.hpp" namespace pw { @@ -11,8 +12,8 @@ void script_system::load(sol::table &ns) "update",&window::update, "title",sol::writeonly_property(&window::set_title), "size",sol::property(&window::size,&window::set_size), - "position",sol::property(&window::position,&window::set_position), - "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen) + "position",sol::property(&window::position,&window::set_position), + "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen) ); ns.new_usertype("input", @@ -20,9 +21,14 @@ void script_system::load(sol::table &ns) "get",&input::get, "mouse_position",sol::readonly_property(&input::mouse_position), "mouse_button",sol::readonly_property(&input::mouse_button), - "mouse_pressed",sol::readonly_property(&input::mouse_pressed), + "mouse_pressed",sol::readonly_property(&input::mouse_pressed), "input_string",sol::readonly_property(&input::input_string) ); + + ns.new_usertype("display", + "all",&display::all, + "name",sol::readonly_property(&display::name) + ); } } diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index 3f69c1e..9b83a59 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -73,6 +73,11 @@ w.title = "pixwerx 0.1" -- set size w.size = pw.size.new(1200,800) +local ds = pw.display:all() +for i = 1,#ds do + print("display ",i,ds[i].name) +end + while w:update() do diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt index f475113..08b2781 100644 --- a/src/system/CMakeLists.txt +++ b/src/system/CMakeLists.txt @@ -2,9 +2,11 @@ set(hdrs include/pw/system/window.hpp include/pw/system/input.hpp + include/pw/system/display.hpp ) set(srcs + src/display.cpp src/window.cpp src/input.cpp ) diff --git a/src/system/include/pw/system/display.hpp b/src/system/include/pw/system/display.hpp new file mode 100644 index 0000000..e85fafc --- /dev/null +++ b/src/system/include/pw/system/display.hpp @@ -0,0 +1,29 @@ +#ifndef PW_SYSTEM_DISPLAY_HPP +#define PW_SYSTEM_DISPLAY_HPP + +#include +#include + +namespace pw { + +class display { +public: + + typedef std::vector list; + + static const list& all() { return _displays; } + + std::string name() const { return _name; } + +protected: + friend class window; + + std::string _name; + + static list _displays; + +}; + +} + +#endif diff --git a/src/system/src/display.cpp b/src/system/src/display.cpp new file mode 100644 index 0000000..d722399 --- /dev/null +++ b/src/system/src/display.cpp @@ -0,0 +1,10 @@ +#include "pw/system/display.hpp" + + + +namespace pw { + + +display::list display::_displays; + +} diff --git a/src/system/src/window.cpp b/src/system/src/window.cpp index 80e3aea..fd3b180 100644 --- a/src/system/src/window.cpp +++ b/src/system/src/window.cpp @@ -1,10 +1,12 @@ #include "pw/system/window.hpp" +#include "glad/glad.h" #include "GLFW/glfw3.h" -//#include "glad/glad.h" #include "pw/visual/context.hpp" #include "pw/system/input.hpp" +#include "pw/system/display.hpp" + #include "pw/core/debug.hpp" #include @@ -97,37 +99,65 @@ struct window::impl { // glViewport(0, 0, width, height); } + void update_display_list() + { + display::_displays.clear(); + + // fetch all monitors + int monitor_count = 0; + GLFWmonitor** monitors = glfwGetMonitors(&monitor_count); + + for (int i = 0; i < monitor_count;i++) { + display d; + d._name = std::string(glfwGetMonitorName(monitors[i])); + + display::_displays.push_back(d); + +// debug::d() << + } + +// GLFWvidmode +// glfwGetVideoModes() ... get all +// glfwGetVideoMode( . get current +// glfwGetMonitorPos( +// glfwGetMonitorPhysicalSize( +// glfwGetMonitorName(); + + } + impl() { // initialize glfwInit(); + update_display_list(); + // request specific version 3.2 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - // _window = glfwCreateWindow(640, 480, "pixwerxs", nullptr, nullptr); + // make window current + glfwMakeContextCurrent(_window); + + // load opengl + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) + { + debug::e() << "glad couldn't get OpenGL API"; + } + // check Version int major, minor, rev; major = glfwGetWindowAttrib(_window, GLFW_CONTEXT_VERSION_MAJOR); minor = glfwGetWindowAttrib(_window, GLFW_CONTEXT_VERSION_MINOR); rev = glfwGetWindowAttrib(_window, GLFW_CONTEXT_REVISION); - // maybe something to pass to the outside -// debug::d() << "OpenGL " << major << "." << minor << "." << rev; - - -// if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) -// { -// debug::e() << "G"; -// return -1; -// } + debug::d() << "OpenGL " << major << "." << minor << "." << rev; glfwSetWindowUserPointer(_window,this); @@ -142,14 +172,6 @@ struct window::impl { glfwSetCursorPosCallback(_window, cursor_pos_callback); glfwSetMouseButtonCallback(_window, mouse_button_callback); glfwSetScrollCallback(_window, scroll_callback); - - -#if 0 - glfwMakeContextCurrent(_window); - - gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); - -#endif } ~impl() diff --git a/src/visual/CMakeLists.txt b/src/visual/CMakeLists.txt index 3e89d52..6d48f62 100644 --- a/src/visual/CMakeLists.txt +++ b/src/visual/CMakeLists.txt @@ -2,13 +2,14 @@ set(hdrs include/pw/visual/mesh_renderer.hpp include/pw/visual/shader.hpp - include/pw/visual/context.hpp + include/pw/visual/pipeline.hpp ) set(srcs src/mesh_renderer.cpp src/shader.cpp src/context.cpp + src/pipeline.cpp ) add_library(pwvisual diff --git a/src/visual/include/pw/visual/mesh_renderer.hpp b/src/visual/include/pw/visual/mesh_renderer.hpp index f923321..76ba99d 100644 --- a/src/visual/include/pw/visual/mesh_renderer.hpp +++ b/src/visual/include/pw/visual/mesh_renderer.hpp @@ -1,5 +1,5 @@ -#ifndef PW_VISUAL_RENDERER_HPP -#define PW_VISUAL_RENDERER_HPP +#ifndef PW_VISUAL_MESH_RENDERER_HPP +#define PW_VISUAL_MESH_RENDERER_HPP #include #include diff --git a/src/visual/include/pw/visual/pipeline.hpp b/src/visual/include/pw/visual/pipeline.hpp new file mode 100644 index 0000000..a591b87 --- /dev/null +++ b/src/visual/include/pw/visual/pipeline.hpp @@ -0,0 +1,13 @@ +#ifndef PW_VISUAL_PIPELINE_HPP +#define PW_VISUAL_PIPELINE_HPP + +#include +#include + +#include + +namespace pw { + +} + +#endif diff --git a/src/visual/src/mesh_renderer.cpp b/src/visual/src/mesh_renderer.cpp index 163dee4..a4051ef 100644 --- a/src/visual/src/mesh_renderer.cpp +++ b/src/visual/src/mesh_renderer.cpp @@ -65,114 +65,6 @@ struct mesh_renderer::impl { }; -struct renderer { - - sizei _size; - - GLuint _fbo_draw; - GLuint _fbo_msaa; - - GLuint rboColorId; - GLuint rboDepthId; - - bool create() - { - int max_msaa; - - // query actual maximum MSAA - glGetIntegerv(GL_MAX_SAMPLES,&max_msaa); - - // create a 4x MSAA renderbuffer object for colorbuffer - int msaa = 4; - -// msaa = std::clamp(msaa,max_msaa); - - glGenRenderbuffers(1, &rboColorId); - glBindRenderbuffer(GL_RENDERBUFFER, rboColorId); - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGB8, _size.width, _size.height); - - // create a 4x MSAA renderbuffer object for depthbuffer - - glGenRenderbuffers(1, &rboDepthId); - glBindRenderbuffer(GL_RENDERBUFFER, rboDepthId); - glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_DEPTH_COMPONENT, _size.width, _size.height); - - // create a 4x MSAA framebuffer object - glGenFramebuffers(1, &_fbo_msaa); - glBindFramebuffer(GL_FRAMEBUFFER, _fbo_msaa); - - // attach colorbuffer image to FBO - glFramebufferRenderbuffer(GL_FRAMEBUFFER, // 1. fbo target: GL_FRAMEBUFFER - GL_COLOR_ATTACHMENT0, // 2. color attachment point - GL_RENDERBUFFER, // 3. rbo target: GL_RENDERBUFFER - rboColorId); // 4. rbo ID - - // attach depthbuffer image to FBO - glFramebufferRenderbuffer(GL_FRAMEBUFFER, // 1. fbo target: GL_FRAMEBUFFER - GL_DEPTH_ATTACHMENT, // 2. depth attachment point - GL_RENDERBUFFER, // 3. rbo target: GL_RENDERBUFFER - rboDepthId); // 4. rbo ID - - // check FBO status - if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) - return false; - - return true; - } - - void draw() - { - /* We are going to blit into the window (default framebuffer) */ - glBindFramebuffer (GL_DRAW_FRAMEBUFFER, 0); - glDrawBuffer (GL_BACK); /* Use backbuffer as color dst. */ - - /* Read from your FBO */ - glBindFramebuffer (GL_READ_FRAMEBUFFER, _fbo_draw ); - glReadBuffer (GL_COLOR_ATTACHMENT0); /* Use Color Attachment 0 as color src. */ - - /* Copy the color and depth buffer from your FBO to the default framebuffer */ - glBlitFramebuffer (0,0, _size.width, _size.height, - 0,0, _size.width, _size.height, - GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, - GL_NEAREST); - } - -}; - - -class pipeline; - -class pass -{ -public: - virtual void apply(pipeline& p); -}; - -class pipeline -{ - -public: - void apply() - { - for (auto p : _passes) p.apply(*this); - } - -protected: - std::vector _passes; -}; - - - -//pipeline > -// n*pass -// shadow_pass -// lighting_pass -// mesh_pass -// compositor_pass - -//compositor -// render to fbo > add a -// glBlitFramebuffer .. https://stackoverflow.com/questions/29254574/using-glblitframebuffer-to-display-a-texture } diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp new file mode 100644 index 0000000..2bb725c --- /dev/null +++ b/src/visual/src/pipeline.cpp @@ -0,0 +1,124 @@ +#include "pw/core/size.hpp" +#include "pw/core/matrix.hpp" + +#include "glad/glad.h" + +namespace pw { + +struct pipeline { + + sizei _size; + + GLuint _fbo_draw; + GLuint _fbo_msaa; + + GLuint rboColorId; + GLuint rboDepthId; + + bool create() + { + int max_msaa; + + // query actual maximum MSAA + glGetIntegerv(GL_MAX_SAMPLES,&max_msaa); + + // create a 4x MSAA renderbuffer object for colorbuffer + int msaa = 4; + +// msaa = std::clamp(msaa,max_msaa); + + glGenRenderbuffers(1, &rboColorId); + glBindRenderbuffer(GL_RENDERBUFFER, rboColorId); + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGB8, _size.width, _size.height); + + // create a 4x MSAA renderbuffer object for depthbuffer + + glGenRenderbuffers(1, &rboDepthId); + glBindRenderbuffer(GL_RENDERBUFFER, rboDepthId); + glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_DEPTH_COMPONENT, _size.width, _size.height); + + // create a 4x MSAA framebuffer object + glGenFramebuffers(1, &_fbo_msaa); + glBindFramebuffer(GL_FRAMEBUFFER, _fbo_msaa); + + // attach colorbuffer image to FBO + glFramebufferRenderbuffer(GL_FRAMEBUFFER, // 1. fbo target: GL_FRAMEBUFFER + GL_COLOR_ATTACHMENT0, // 2. color attachment point + GL_RENDERBUFFER, // 3. rbo target: GL_RENDERBUFFER + rboColorId); // 4. rbo ID + + // attach depthbuffer image to FBO + glFramebufferRenderbuffer(GL_FRAMEBUFFER, // 1. fbo target: GL_FRAMEBUFFER + GL_DEPTH_ATTACHMENT, // 2. depth attachment point + GL_RENDERBUFFER, // 3. rbo target: GL_RENDERBUFFER + rboDepthId); // 4. rbo ID + + // check FBO status + if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) + return false; + + return true; + } + + void draw() + { + /* We are going to blit into the window (default framebuffer) */ + glBindFramebuffer (GL_DRAW_FRAMEBUFFER, 0); + glDrawBuffer (GL_BACK); /* Use backbuffer as color dst. */ + + /* Read from your FBO */ + glBindFramebuffer (GL_READ_FRAMEBUFFER, _fbo_draw ); + glReadBuffer (GL_COLOR_ATTACHMENT0); /* Use Color Attachment 0 as color src. */ + + /* Copy the color and depth buffer from your FBO to the default framebuffer */ + glBlitFramebuffer (0,0, _size.width, _size.height, + 0,0, _size.width, _size.height, + GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, + GL_NEAREST); + } + +}; + + +} + + + + +//class pipeline; + +//class pass +//{ +//public: +// virtual void apply(pipeline& p); +//}; + +//class pipeline +//{ + +//public: +// void apply() +// { +// for (auto p : _passes) p.apply(*this); +// } + +//protected: +// std::vector _passes; +//}; + + + + + + + +//pipeline > +// n*pass +// shadow_pass +// lighting_pass +// mesh_pass +// compositor_pass + +//compositor +// render to fbo > add a +// glBlitFramebuffer .. https://stackoverflow.com/questions/29254574/using-glblitframebuffer-to-display-a-texture