I am having problems reading using glReadPixels on Intel Hardware (see separate post) and thought I would give mapping a try.
I have attempted to map the Color buffer of my framebuffer but it always returns zeros (even if I clear with buffer with 1).
Can anyone spot my error in code below?? I do have a valid FrameBuffer and Color Buffers and the MapData structure is an Array of Array of vec4 as I have an RGBA color buffer. Is it my interpretation of the data pointer returned??
The code fails on Intel, NVIDEA and AMD hardware so I think not a Hardware issue.
Procedure ReadAtLocation (X,Y:Integer);
if MapData<>Nil then
If a buffer object is bound as pixel pack buffer, it is used as the destination for glReadPixels, the pointer parameter becoming an offset into the buffer. This is useful when you want to do asynchronous pixel reads, i.e. not having the glReadPixels call block until the GPU has finished rendering.
Binding a pixel pack buffer does not magically transfer contents from the framebuffer to it, you have to explicitly call glReadPixels. Also, you can’t bind anything other than a buffer object (your fColorBuffer looks suspiciously like it could be a handle to the renderbuffer or texture you’re using as the first FBO attachment).
I think I now get it. See below for my code. I need another buffer to use as the PACK PIXEL target and then I can read pixels into it then extract from it using the glMap…
// Create the FBO
// Create the texture object for the primitive information buffer
for I := 0 to fColBufSize-1 do
glRenderBufferStorage( GL_RENDERBUFFER, GL_RGBA32F, SizeX, SizeY );
glFramebufferRenderBuffer (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + I, GL_RENDERBUFFER, fColorTexture[i] );
fBuffer[i] := GL_COLOR_ATTACHMENT0 + I;
if fIncDepthBuffer then
glRenderBufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, SizeX, SizeY );
glFramebufferRenderBuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fDepthBuff);
// Verify that the FBO is correct
aStatus := glCheckFramebufferStatus(GL_FRAMEBUFFER);
CheckForGLErrors('Float Buffer Set Size');
// Restore the default framebuffer