PDA

View Full Version : ReadPixel 'odd' framebuffer sizes throws memory exceptions



karatire
08-09-2017, 04:11 AM
Hi,

I'm trying to read pixels from an offscreen framebuffer.
For the most part all works fine.

However when certain sizes of the frame buffer opengl (or in my case openTK) throws memory errors not being able to read out the memory.
It seems that for the larger pixel sizes mostly with odd sizes this happens.

91x91: ok
911x911: ok
1501x1501: exception
1501x1500: ok
2121x2121: exception
2122x2122: exception
3620x3620: ok

It seems opengl is drawing fine.
There are no opengl errors thrown.

But the exception is thrown when calling ReadPixels with above sizes.

My question; is there any limitation on ReadPixels that i'm not seeing?
Should for ReadPixels to work there be a multiple of 2 or 4 inside the sizing? and why?

Dark Photon
08-09-2017, 05:32 AM
Are you changing the pack alignment to 1?

* Common_Mistakes#Texture_upload_and_pixel_reads (https://www.khronos.org/opengl/wiki/Common_Mistakes#Texture_upload_and_pixel_reads) (GL Wiki)

Have you verified that the pointer to the buffer you're providing will hold that much data?

karatire
08-09-2017, 05:47 AM
Hi Dark Photon,

Thanks! The pack alignment setting works! It was indeed this problem.

However; in the further processing of the images in .NET it seems to generate the same problem.
Trying to store it as an 8bitperpixel Bitmap yields similar strange exceptions when the with is not a multiple of 4.

So i decided to stick with a multiple of 4 for now.
(it has speed benefits compared to doing 32bits readpixels and storing those images)

mhagain
08-10-2017, 01:03 AM
The BMP format requires row width to be a multiple of 4 bytes.