How can I debug what is being rendered to a Frame Buffer Object in OpenGL?

15

1

I have a point cloud that is being rendered to the screen. Each point has its position and color as well as an ID.

I was asked to render the IDs for each point to a texture so I created a FBO and attached two textures, one for color and one for depth. I created the necessary VAO and VBO for this off-screen rendering and uploaded for each point its position and ID.

Once the rendering to the FBO is done, I read the pixels of the color-texture with glReadPixels() to see what the values are, but they seem to be all cleared out, i.e., the value they have is the same as glClearColor().

Is there a way I can debug what it is being render to the color texture of my FBO? Any tips that you may provide are very welcomed.

BRabbit27

Posted 2015-08-04T20:05:43.820

Reputation: 454

Answers

20

Generally to see what is being rendered in the various steps of your pipeline I'd suggest the use of a tool for frame analysis. These usually provide you with a view on the content of each buffer for each API call and this can help you in your situation.

A very good one is Renderdoc which is both completely free and opensource. Also it is actively supported.

Another one is Intel GPA that unfortunately, according to its webpage, support up to OGL 3.3 Core.

Just for the sake of adding one more, I used to use gDEBugger, but it has passed long since the last update. This has evolved into AMD CodeXL that unfortunately I never used.

cifz

Posted 2015-08-04T20:05:43.820

Reputation: 1 953

It's also probably a good idea to make sure you have the right depth test setup, for the rendering going into your visualisation FBO. – rys – 2015-08-07T23:18:31.293

I will check those right away ! Thanks ! – BRabbit27 – 2015-08-04T20:27:28.023

Additionally I also sometimes have a command that will dump a specified fbo out to an image when I press a key. It's the low-tech way. – Jorge Rodriguez – 2015-08-04T20:33:29.797

I still use gDEbugger from time to time for older GL versions. CodeXL is the more modern version of it and can be found here: https://github.com/GPUOpen-Tools/CodeXL Note that there's a comprehensive list of graphics debugging tools on the apitrace page here: https://apitrace.github.io/#links

– Bim – 2017-01-23T13:52:24.060

11

I tested several applications/APIs/libraries to get data from FBOs in applications which use gbuffer for example. After months of suffering I discovered apitrace available on Github to debug OpenGL, Direct3D and WebGL. I used in Windows and Linux without problems.

I hope that could be useful for you.

esmitt

Posted 2015-08-04T20:05:43.820

Reputation: 111

6

In addition to cifz's response, another way to visualise FBOs which doesn't cost very much code is to use glBlitFramebuffer() to transfer pixels from a framebuffer to a window.

// XXX WARNING: Untested code follows

// Blit from fbo...
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
// ...to the front buffer.
glBindFramebuffer(GL_WRITE_FRAMEBUFFER, GL_FRONT);

GLsizei HalfWindowWidth = (GLsizei)(WindowWidth / 2.0f);
GLsizei HalfWindowHeight = (GLsizei)(WindowHeight / 2.0f);

// Blit attachment 0 to the lower-left quadrant of the window
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0, 0, FboWidth, FboHeight,
                  0, 0, HalfWindowWidth, HalfWindowHeight,
                  GL_COLOR_BUFFER_BIT, GL_LINEAR);

// Blit attachment 1 to the lower-right quadrant of the window
glReadBuffer(GL_COLOR_ATTACHMENT1);
glBlitFramebuffer(0, 0, FboWidth, FboHeight,
                  HalfWindowWidth, 0, WindowWidth, HalfWindowHeight,
                  GL_COLOR_BUFFER_BIT, GL_LINEAR);

// ...and so on. You can switch FBOs if you have more than one to read from.

There are a few obvious "gotchas", in that HDR buffers probably won't visualise the way you expect them to, you probably can't "see" depth/stencil buffers in the obvious way, and if the size of the FBO doesn't match the area being blitted to, the magnification/minification method might be extremely naive.

But as quick 'n dirty hacks go, it's pretty good.

Pseudonym

Posted 2015-08-04T20:05:43.820

Reputation: 511