wiggling around with the whole notion of what a renderer does and what not. Added simple wrapper for GLFWmonitor named display

This commit is contained in:
Hartmut Seichter 2019-01-13 22:14:41 +01:00
parent 3cc0fde1e1
commit 9773103a18
13 changed files with 252 additions and 148 deletions

View file

@ -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>("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>("display",
"all",&display::all,
"name",sol::readonly_property(&display::name)
);
}
}

View file

@ -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

View file

@ -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
)

View file

@ -0,0 +1,29 @@
#ifndef PW_SYSTEM_DISPLAY_HPP
#define PW_SYSTEM_DISPLAY_HPP
#include <pw/core/globals.hpp>
#include <pw/core/point.hpp>
namespace pw {
class display {
public:
typedef std::vector<display> list;
static const list& all() { return _displays; }
std::string name() const { return _name; }
protected:
friend class window;
std::string _name;
static list _displays;
};
}
#endif

View file

@ -0,0 +1,10 @@
#include "pw/system/display.hpp"
namespace pw {
display::list display::_displays;
}

View file

@ -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 <cmath>
@ -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()

View file

@ -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

View file

@ -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 <pw/core/matrix.hpp>
#include <pw/core/mesh.hpp>

View file

@ -0,0 +1,13 @@
#ifndef PW_VISUAL_PIPELINE_HPP
#define PW_VISUAL_PIPELINE_HPP
#include <pw/core/matrix.hpp>
#include <pw/core/mesh.hpp>
#include <map>
namespace pw {
}
#endif

View file

@ -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<pass> _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
}

124
src/visual/src/pipeline.cpp Normal file
View file

@ -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<pass> _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