Access to back buffer

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

You're supposed to expose it to IVideoDriver, it's the only way to access it... The other drivers can just do nothing.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

I'm running into further problems.

When I do my initial render to the frame buffer (to copy into my RT system), I don't call beginScene() or endScene() to avoid it from being actually synced to the screen. This works perfectly fine (see my beautiful screenshot below with bloom)...

Image

Except... calling ISceneManager::drawAll() causes this to appear in the MSVC output console:
First-chance exception at 0x75b49617 in Postprocessing.exe: Microsoft C++ exception: long at memory location 0x0028f090.
I'm positive that this is related to me not calling beginScene() and endScene() and not some other memory issue (putting begin and end scene back in gets rid of the problem right away).

Then, when I go to drop the device, calling drop() throws an access violation exception (again, I'm positive that this is directly related to the being/end scene issue, as putting those calls in solves the problem).

I'm half-tempted to just ignore these problems since everything else works perfectly, but why is this happening?
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

So, Is this actually working correctly?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

It turned out that the exception was due to me deleting a shader callback class, not realizing that it inherited IReferenceCounted. Everything else works, but I'm not copying the backbuffer anymore since you can't render in HDR using it (since the highest range format the backbuffer supports is A8R8G8B8).
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

So, no antialiasing under DX9 and HDR for the moment, unless you render to a bigger rendertarget?. This is a bit uncomfortable, to be honest.

In DX the rendertargets can be created with multisample and in floating point precison, the only issue seems to be that the RT isn't lockable, probably because it will only exist in the graphics card.

I don't know, this confuses me. Some places say RTT can't have multisample, other say it is posible.

At least, the MSDN says it is possible.
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

I'm using MRT for deferred shading, so I can't use MSAA anyways.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

I've been seeing the sources, and i've got a question regarding the back buffer and the usage of the textures and rendertargets. What is the diference between creating the RTT with the "CreateTexture" call, with the usage "RENDERTARGET TEXTURE" and the "CreateRenderTarget" call?

CreateTexture doesn't have multisampling, but CreateRenderTarget indeed seems to suport it.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
dzordz
Posts: 6
Joined: Sun Dec 26, 2010 5:36 pm
Location: Poland

Re: Access to back buffer

Post by dzordz »

I rebuilt irrlicht and libs, but now I don't know what to do. What code should I use for make AA works with postprocessing?
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Access to back buffer

Post by Mel »

Search for a function in the forums which is able to copy and downsample the backbuffer to a rendertarget. This only works in DirectX, but it allows for multisampled postprocessing. Or else, look for a postprocessing that is able to make antialiasing, like FXAA or MLAA, or similar.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Access to back buffer

Post by robmar »

Just tried the opengl version of copyBackBufferTo with 1.7.3. and the blit fails with GL_INVALID_FRAMEBUFFER_OPERATION

Checked FBO status and its complete, so why should this error occur?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Access to back buffer

Post by robmar »

I had to change the code to get it to work:-

Code: Select all

bool COpenGLDriver::copyBackBufferTo(ITexture* dest)        // To render target (which has a FB and texture)
{
    GLenum error = 0;
    error = glGetError();       // Clear any old error
   //if (dest->getDriverType() != EDT_OPENGL)
   //   return false;
 
    GLenum status = extGlCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
    if ( status != GL_FRAMEBUFFER_COMPLETE )
        goto returnFALSE;
 
#ifdef _DEBUG
static bool bDo = false;
if ( bDo )
{
    glDisable(GL_BLEND);
    error = glGetError();
    if ( error != GL_NO_ERROR )
        goto returnFALSE;
    glDisable(GL_DEPTH_TEST);
    error = glGetError();
    if ( error != GL_NO_ERROR )
        goto returnFALSE;
    glDisable(GL_ALPHA_TEST);
    error = glGetError();
    if ( error != GL_NO_ERROR )
        goto returnFALSE;
    glDisable(GL_MULTISAMPLE_ARB);
    error = glGetError();
    if ( error != GL_NO_ERROR )
        goto returnFALSE;
    glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
    error = glGetError();
    if ( error != GL_NO_ERROR )
        goto returnFALSE;
//  glEnable(GL_DEPTH_TEST);
//  glDisable(GL_TEXTURE_2D);
}
#endif
 
    GLint oldFBO = 0;
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO);
    error = glGetError();
 
    COpenGLTexture* tex = (COpenGLTexture*)dest;
    GLuint name =  tex->getOpenGLTextureName();
 
    core::dimension2du bSize = this->getScreenSize();
 
    glReadBuffer(GL_BACK);   // Moved to here else error, Robmar
    error = glGetError();
    extGlBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
    error = glGetError();
    extGlBindFramebuffer(GL_DRAW_FRAMEBUFFER, name);
    error = glGetError();
 
    extGlFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, name, 0);  // Added this, Robmar
    error = glGetError();
    glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
    error = glGetError();
 
    extGlBlitFramebuffer(   0, 0, bSize.Width, bSize.Height,
        0, 0, bSize.Width, bSize.Height,
        GL_COLOR_BUFFER_BIT, GL_NEAREST);
    error = glGetError();
 
    extGlBindFramebuffer(GL_FRAMEBUFFER, oldFBO);
    error = glGetError();
   
    return true;
returnFALSE:
    return false;
 
} 
Post Reply