Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: ReadPixel 'odd' framebuffer sizes throws memory exceptions

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2015
    Posts
    9

    ReadPixel 'odd' framebuffer sizes throws memory exceptions

    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?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,169
    Are you changing the pack alignment to 1?

    * 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?

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2015
    Posts
    9
    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)

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,728
    The BMP format requires row width to be a multiple of 4 bytes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •