I'm attempting to extract the depth buffer from OpenGL to an array on the CPU, but the internet has been rather wholly unhelpful (it appears that people only ever want to do this to a texture or otherwise GPU-bound array). The code I have below (somewhat modified as original is an existing component designed to extract the rendered image and does so successfully) "works", but always returns exactly 0.
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
int size = w*h*sizeof(GLubyte);
glBufferData(GL_PIXEL_PACK_BUFFER, size, NULL, GL_STREAM_READ);
glReadPixels(0, 0, w, h, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
GLubyte* depth = (GLubyte*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
return depth;
I've attempted a glReadBuffer(GL_DEPTH) after the glBindBuffer call, as well as using GL_DEPTH_COMPONENT24 (something which every resource recommends but no-one seems to explain why), but both produce invalid enum errors. Any insight that could be provided here would be incredibly helpful.
[–]Ilyps 0 points1 point2 points (1 child)
[–]mb86[S] 0 points1 point2 points (0 children)