proper blitting without texture attachment added - need to redo and refactor the stuff in pipeline

This commit is contained in:
Hartmut Seichter 2019-01-16 18:52:39 +01:00
parent 351d29cd54
commit 075d18b4b8
7 changed files with 153 additions and 97 deletions

View file

@ -59,8 +59,8 @@ public:
stream(const stream& other);
stream &operator << (const bool &value);
stream &operator << (const char *value);
stream& operator << (const bool &value);
stream& operator << (const char *value);
stream& operator << (const std::string& value); ///! log a string
stream& operator << (const float &value); ///! log a float value
@ -80,8 +80,6 @@ public:
std::string _line;
};
/** sets the logging level */
void set_level(level level) {_level = level;}

View file

@ -10,13 +10,12 @@ namespace pw {
void script_system::load(sol::table &ns)
{
ns.new_usertype<window>("window",
"update",&window::update,
"on_update",sol::writeonly_property(&window::set_on_update),
"title",sol::writeonly_property(&window::set_title),
"size",sol::property(&window::size,&window::set_size),
"client_size",sol::readonly_property(&window::client_size),
"position",sol::property(&window::position,&window::set_position),
"fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen)
);

View file

@ -70,13 +70,20 @@ local w = pw.window.new()
-- set title
w.title = "pixwerx 0.1"
-- set size
w.size = pw.size.new(800,600)
-- move window
w.position = pw.point.new(100,100)
local pl = pw.pipeline.new()
if pl:create(pw.size.new(800,600)) then
if pl:create(w.client_size) then
print("pipeline ok")
else
print("pipeline failed")
end
-- setup a lua callback function
w.on_update = function(self)
@ -84,11 +91,6 @@ w.on_update = function(self)
-- print("test on update",w.position.x,w.position.y,pw.timer.now)
end
-- set size
w.size = pw.size.new(800,600)
-- move window
w.position = pw.point.new(100,100)
local ds = pw.display:all()
for i = 1,#ds do
print("display ",i,ds[i].name)

View file

@ -23,6 +23,7 @@ public:
void set_size(const size& s);
pw::size size() const;
pw::size client_size() const;
void set_position(const point& p);
point position() const;

View file

@ -95,6 +95,9 @@ struct window::impl {
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
window::impl* impl = static_cast<window::impl*>(glfwGetWindowUserPointer(window));
debug::d() << "window::frame_buffer_size_callback " << width << "x" << height;
// impl->on_resize(width,height);
// std::cout << "framebuffer " << width << "x" << height << std::endl;
@ -218,9 +221,9 @@ struct window::impl {
glfwSetWindowTitle(_window,title.c_str());
}
void set_size(int w,int h)
void set_size(const ::pw::sizei& s)
{
glfwSetWindowSize(_window,w,h);
glfwSetWindowSize(_window,s.width,s.height);
}
::pw::size size() const
@ -230,6 +233,14 @@ struct window::impl {
return ::pw::size(w,h);
}
::pw::size client_size() const
{
int w,h;
glfwGetFramebufferSize(_window,&w,&h);
return ::pw::size(w,h);
}
::pw::point position() const
{
int x,y;
@ -237,9 +248,9 @@ struct window::impl {
return ::pw::point(x,y);
}
void set_position(int x,int y)
void set_position(const pointi& p)
{
glfwSetWindowPos(_window,x,y);
glfwSetWindowPos(_window,p.x,p.y);
}
void set_fullscreen(bool use_fullscreen)
@ -299,7 +310,7 @@ void window::set_title(const std::string& title)
void window::set_size(const ::pw::size& s)
{
_impl->set_size(static_cast<int>(std::round(s.width)),static_cast<int>(std::round(s.height)));
_impl->set_size(s.cast<int>());
}
size window::size() const
@ -307,9 +318,14 @@ size window::size() const
return _impl->size();
}
size window::client_size() const
{
return _impl->client_size();
}
void window::set_position(const point &p)
{
_impl->set_position(p.x,p.y);
_impl->set_position(p.cast<int>());
}
point window::position() const

View file

@ -83,9 +83,6 @@ struct triangle_renderer
void draw()
{
// glUseProgram(shader_programme);
shader_p.use();
glBindVertexArray(vao);
// draw points 0-3 from the currently bound VAO with current in-use shader
@ -101,8 +98,8 @@ struct pipeline::impl {
GLuint _fbo_draw;
GLuint _fbo_msaa;
GLuint rboColorId;
GLuint rboDepthId;
GLuint _rbo_color;
GLuint _rbo_depth;
//testing
triangle_renderer tr;
@ -116,6 +113,18 @@ struct pipeline::impl {
};
GLuint generate_multisample_texture(const sizei& s,int samples)
{
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGB8, s.width, s.height, GL_TRUE);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
return texture;
}
bool pipeline::impl::create(sizei size)
{
@ -133,16 +142,14 @@ bool pipeline::impl::create(sizei size)
debug::d() << "OpenGL multisampling: " << max_msaa << " choosen:" << msaa;
// msaa = std::clamp(msaa,max_msaa);
glGenRenderbuffers(1, &rboColorId);
glBindRenderbuffer(GL_RENDERBUFFER, rboColorId);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGB8, _size.width, _size.height);
glGenRenderbuffers(1, &_rbo_color);
glBindRenderbuffer(GL_RENDERBUFFER, _rbo_color);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_RGBA8, _size.width, _size.height);
// create a 4x MSAA renderbuffer object for depthbuffer
glGenRenderbuffers(1, &rboDepthId);
glBindRenderbuffer(GL_RENDERBUFFER, rboDepthId);
glGenRenderbuffers(1, &_rbo_depth);
glBindRenderbuffer(GL_RENDERBUFFER, _rbo_depth);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, msaa, GL_DEPTH_COMPONENT, _size.width, _size.height);
// create a 4x MSAA framebuffer object
@ -153,32 +160,32 @@ bool pipeline::impl::create(sizei size)
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
_rbo_color); // 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
_rbo_depth); // 4. rbo ID
// check FBO status
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
return false;
// reset
glBindFramebuffer(GL_FRAMEBUFFER, 0);
tr.setup();
return true;
}
void pipeline::impl::draw()
{
glBindBuffer(GL_DRAW_FRAMEBUFFER, _fbo_draw);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo_msaa);
glClearColor(1,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
@ -186,11 +193,13 @@ void pipeline::impl::draw()
tr.draw();
// reset
glBindBuffer(GL_DRAW_FRAMEBUFFER, 0);
// actuall blitting
#if 0
/* We are going to blit into the window (default framebuffer) */
glBindFramebuffer (GL_DRAW_FRAMEBUFFER, 0);
glDrawBuffer (GL_BACK); /* Use backbuffer as color dst. */
@ -203,7 +212,40 @@ void pipeline::impl::draw()
glBlitFramebuffer (0,0, _size.width, _size.height,
0,0, _size.width, _size.height,
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
GL_LINEAR);
GL_NEAREST);
#else
glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo_msaa); // src FBO (multi-sample)
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo_draw); // dst FBO (single-sample)
glBlitFramebuffer(0, 0, _size.width, _size.height, // src rect
0, 0, _size.width, _size.height, // dst rect
GL_COLOR_BUFFER_BIT, // buffer mask
GL_LINEAR); // scale filter
debug::d() << _size.width << "x" << _size.height;
#endif
GLenum err;
while((err = glGetError()) != GL_NO_ERROR)
{
std::string error;
switch(err) {
case GL_INVALID_OPERATION: error="INVALID_OPERATION"; break;
case GL_INVALID_ENUM: error="INVALID_ENUM"; break;
case GL_INVALID_VALUE: error="INVALID_VALUE"; break;
case GL_OUT_OF_MEMORY: error="OUT_OF_MEMORY"; break;
case GL_INVALID_FRAMEBUFFER_OPERATION: error="INVALID_FRAMEBUFFER_OPERATION"; break;
}
debug::e() << "OpenGL error:" << err << " " << error;
}
}

View file

@ -1,8 +1,6 @@
#include "pw/visual/shader.hpp"
#include "pw/core/debug.hpp"
#include "glad/glad.h"
namespace pw {
@ -91,7 +89,7 @@ struct shader::impl
glAttachShader(_shader_program,s);
// attribute binding ...
// TODO attribute binding ...
/* Bind attribute index 0 (coordinates) to in_Position and attribute index 1 (color) to in_Color */
/* Attribute locations must be setup before calling glLinkProgram. */