Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: glreadpixels too slow

Hybrid View

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    May 2000
    Location
    London, UK
    Posts
    548

    glreadpixels too slow

    I know this question has cropped up before but maybe something is now possible that wasn't previously...

    Is there a faster alternative to glreadpixels? It is currently taking 75% of my processing.

    I am calculating the average amount of colour in an image (for my radiosity engine). glReadPixels seems faster than using glGetTexImage.

    Is there some way of doing it on the GPU since it seems that getting the image back to system RAM is what is causing the slowness.

    I am not familiar with pixel shaders or cg and I was wondering if they would allow me to read the frame buffer (or a texture) and perform the necessary calculation on the GPU.

    Thanks for any help.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: glreadpixels too slow

    You can effectively down-sample a 4x4 area to a 1x1 output pixel using a fragment program, pixel shader, or register combiner quite easily. On more advanced hardware, you can probably go from 16x16 to 1x1. You can use this a few times to drop the size of your frame buffer (using render-to-pbuffer and pbuffer-as-texture, say) until it's small enough that reading it is no longer a speed problem.

    Also, when reading pixels, the driver may convert the data using the CPU, if you don't read it in exactly the same format as the card uses. Thus, if your frame buffer is 24/32 bits, you should probably read as GL_BGRA; if it's 16 bits, you should probably read it as GL_BGR5_A1.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  3. #3
    Member Regular Contributor
    Join Date
    May 2001
    Posts
    255

    Re: glreadpixels too slow

    out of interest - can you benchmark at 16bit colour and 32(24) bit colour and post the results here ?

    Thanks.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    May 2000
    Location
    London, UK
    Posts
    548

    Re: glreadpixels too slow

    Thanks jwatte,

    here are some benchmarks with most of the code apart from the glReadPixels removed.

    16bit - 1.41
    32bit(RGB) - 2.18
    32bit(BGRA) - 2.12

    The figures show the number of seconds to render one frame. It is an unoptimised radiosity engine

    I couldn't find information as to how to use BGR5_A1.

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: glreadpixels too slow

    EXT_packed_pixels

    It actually got folded into the OpenGL spec a while back (1.2 perhaps?) so the glspec14.pdf file that's available on this web site should give you all you need (except for the enumerant values).
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  6. #6
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: glreadpixels too slow

    >>16bit - 1.41
    32bit(RGB) - 2.18
    32bit(BGRA) - 2.12<<

    one frame!, (unless the windows 4,000 x 4,000 it sounds as if youre doing something wrong)
    my old tnt2 (+ my gf2mx) could do at least 20million RGB pixels a second (glReadPixels)

    theres about 30 different methods of reading pixels (including packed pixels which often gives best results esp in 16bit color) i suggest u benchmark them all + choose then.

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    May 2000
    Location
    London, UK
    Posts
    548

    Re: glreadpixels too slow

    Hehe, it's a radioisity engine so the lighting is calculated by rendering the scene thousands of times (for each frame) and reading back the light values. I'm actually getting about 170 million pixels per second. (GF4600)

    Edit: Correction 60 million pixels per second.

    [This message has been edited by Adrian (edited 11-28-2002).]

    [This message has been edited by Adrian (edited 11-28-2002).]

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    San Diego, CA, USA
    Posts
    769

    Re: glreadpixels too slow

    I have an idea similar to what jwatte suggested, but I don't know if it's good enough for your purposes:

    What if you turned on SGIS_GENERATE_MIPMAPS, uploaded your scene to a texture, and then read back the smallest mipmap (a single pixel)? That way there's only one copyTexSubImage involved and you're reading back only 1 pixel, plus you get hardware accelerated reduced-size filtering.

    -- Zeno

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    May 2000
    Location
    London, UK
    Posts
    548

    Re: glreadpixels too slow

    Thanks Zeno, I'll try that out.

    I've just found out that you can call readpixels asynchronously. It looks like it only recently became possible. http://www.nvidia.com/dev_content/nv...data_range.txt

  10. #10
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: glreadpixels too slow

    very nice to see, this is big, more important (IMHO) than render_to_texture etc

Posting Permissions

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