read depth buffer of framebuffer object

I am trying to copy the depth buffer of a fbo to a vector.

I initially started with using renderbuffers and glreadpixels but this resulted in a vector full of zeros despite glGetErrors() not highlighting any issues.

I then switched to textures and drew these to the screen. The colour texture shows evidence of depth testing and the depth texture shows the depth buffer is populated with expected values.

I’ve trawled through the opengl pages on framebuffers, the common mistaked page, and read the docs on all the functions as well as read the first 2 pages of google search results of queries related to the problem but these don’t solve the problem and mostly use old opengl versions.

I’ve played with pixel pack buffers, packing, enabling/disabling random settings + binding/unbinding various buffers.

The code is roughly as follows:

std::vector<GLuint> someVector; //also tried unsigned int
someVector.resize( windowWidth * windowHeight ); //also tried .reserve

glBindFramebuffer( GL_FRAMEBUFFER, fbo );
glEnable( GL_DEPTH_TEST );

drawStuff(); //I know this works

//Ive also tried making the depth buffer a depth_stencil buffer and reading a GL_UNSIGNED_INT_24_8

//glReadPixels( 0, 0, width, height, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, &someVector[ 0 ] );
glBindTexture( GL_TEXTURE_2D, depthTexture );
glGetTexImage( GL_TEXTURE_2D, 0,
        GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, &someVector[ 0 ] );
glBindTexture( GL_TEXTURE_2D, 0 );


glBindeFrameBuffer( GL_FRAMEBUFFER, fbo );

wrapperForGlGetErrors(); //this indicates all is good

I’m on ubuntu 18.04, using opengl 3.3 and using the latest nvidia drivers.

Output of lspci | grep -i --color 'vga\|3d\|2d' is

00:02.0 VGA compatible controller: Intel Corporation HD Graphics 630 (rev 04)
01:00.0 3D controller: NVIDIA Corporation GP107M [GeForce GTX 1050 Mobile] (rev a1)

I’ve been stuck on this bug for around 30 hours now and would greatly appreciate some help.

I’ve also done this on NVidia GL drivers on Linux and it works fine (or at least did for me at the time).

Are you sure you’re rendering on the NVIDIA GPU via the NVIDIA GL drivers? Let’s see the output of:

echo $DISPLAY
glxinfo | grep ':'

in the same shell that you run your program from.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.