Hi.
So, i am doing my first framebuffer
glCreateFramebuffers( 1, &m_framebuffer );
bind( GL_DRAW_FRAMEBUFFER );
if( GL_TRUE != glIsFramebuffer( m_framebuffer ) ) {
....
with a color
glCreateRenderbuffers( 1, &m_colorAttachment );
if( GL_TRUE != glIsRenderbuffer( m_colorAttachment ) )
std::cerr << "Error creating color renderbuffer.\n";
glNamedRenderbufferStorage( m_colorAttachment, colorFormat, m_sizeX, m_sizeY );
glNamedFramebufferRenderbuffer( m_framebuffer, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorAttachment );
and depth
glCreateRenderbuffers( 1, &m_depthAttachment );
if( GL_TRUE != glIsRenderbuffer( m_depthAttachment ) )
std::cerr << "Error creating depth renderbuffer.\n";
glNamedRenderbufferStorage( m_depthAttachment, depthFormat, m_sizeX, m_sizeY );
glNamedFramebufferRenderbuffer( m_framebuffer, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthAttachment );
attachment. Execute the "how we are we today"
if( GL_FRAMEBUFFER_COMPLETE != glCheckNamedFramebufferStatus( m_framebuffer, GL_FRAMEBUFFER ) )
...
and in the renderloop i bind the framebuffer, render into, bind it to read, the window buffer to draw, and copy the rendered image over.
This works (example taken from the Red Book):
// Render in the framebuffer first
m_framebuffer->bind( GL_DRAW_FRAMEBUFFER );
glClearColor( 1.0f, 0.0f, 0.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
//m_framebuffer->invalidateData();
// ... renderrenderrender...
m_framebuffer->bind( GL_READ_FRAMEBUFFER );
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); // or m_framebuffer->unbind()
glClearColor( 0.0f, 0.0f, 1.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glBlitFramebuffer( 0, 0, m_window->getWidth(), m_window->getHeight(),
0, 0, m_window->getWidth(), m_window->getHeight(),
GL_COLOR_BUFFER_BIT, GL_NEAREST );
// poll() and swap() and start all ove again ...
But if i stray from the tutorial path and use glInvalidate..() instead of glClear() i get an "invalid enum, <attachment> does not specify an attachment".
The method is trivial:
if( GL_TRUE == glIsRenderbuffer( m_colorAttachment ) )
glInvalidateNamedFramebufferData( m_framebuffer, 1, &m_colorAttachment );
if( GL_TRUE == glIsRenderbuffer( m_depthAttachment ) )
glInvalidateNamedFramebufferData( m_framebuffer, 1, &m_depthAttachment );
glInvaliate... cause the error.
Debug message (1280): Source: API; Type: Error; Severity: high; GL_INVALID_ENUM error generated. <attachment> does not specify a valid attachment.
What have i done wrong ? It is just, i read, invalidate may be faster than actually clearing the buffers to a colour.