some experimentation

This commit is contained in:
Hartmut Seichter 2019-01-14 09:42:28 +01:00
parent 9773103a18
commit 665a9a4078
8 changed files with 135 additions and 79 deletions

View file

@ -1,6 +1,7 @@
#ifndef PW_VISUAL_PIPELINE_HPP
#define PW_VISUAL_PIPELINE_HPP
#include <pw/core/size.hpp>
#include <pw/core/matrix.hpp>
#include <pw/core/mesh.hpp>
@ -8,6 +9,22 @@
namespace pw {
class pipeline {
public:
pipeline();
~pipeline() = default;
void draw();
bool create(size s);
protected:
struct impl;
std::unique_ptr<impl> _impl;
};
}
#endif

View file

@ -1,11 +1,14 @@
#include "pw/core/size.hpp"
#include "pw/core/matrix.hpp"
#include "pw/visual/pipeline.hpp"
#include "glad/glad.h"
namespace pw {
struct pipeline {
struct pipeline::impl {
sizei _size;
@ -15,70 +18,91 @@ struct pipeline {
GLuint rboColorId;
GLuint rboDepthId;
bool create()
{
int max_msaa;
bool create(sizei size);
// query actual maximum MSAA
glGetIntegerv(GL_MAX_SAMPLES,&max_msaa);
void draw();
// 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);
}
impl() = default;
~impl() = default;
};
bool pipeline::impl::create(sizei size)
{
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 pipeline::impl::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);
}
//
//
//
pipeline::pipeline()
: _impl(std::make_unique<pipeline::impl>())
{
}
bool pipeline::create(size s)
{
return _impl->create(sizei(s.width,s.height));
}
}