proper blitting without texture attachment added - need to redo and refactor the stuff in pipeline
This commit is contained in:
parent
351d29cd54
commit
075d18b4b8
7 changed files with 153 additions and 97 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue