Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8587407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:33:45+00:00 2026-06-11T22:33:45+00:00

I render to a floating point texture in a FBO and need the average

  • 0

I render to a floating point texture in a FBO and need the average value of all pixels of that texture on the CPU. So I thought using mipmapping to calculate the average into the 1×1 mipmap is pretty convenient because I save CPU computation time and I only need to transfer 1 pixel to the CPU instad of lets say 1024×1024 pixels.

So I use this line:

glGetTexImage(GL_TEXTURE_2D, variableHighestMipMapLevel, GL_RGBA, GL_FLOAT, fPixel);

But despite the fact that i specifically request only the highest mipmap level, which is always 1×1 pixel in size, the time it takes for that line of code to complete depends on the size of the level 0 mipmap of the texture. Which makes no sense to me. In my tests, for example, this line takes around 12 times longer for a 1024×1024 base texture than for a 32×32 base texture.

The result in fPixel is correct and only contains the wanted pixel, but the time clearly tells that the whole texture set is transferred, which kills the main reason for me, because the transfer to the CPU is clearly the bottleneck for me.

I use Win7 and opengl and tested this on an ATI Radeon HD 4800 and a GeForce 8800 GTS.

Does anybody know anything about that problem or has a smart way to only transfer the one pixel of the highest mipmap to the CPU?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:33:46+00:00Added an answer on June 11, 2026 at 10:33 pm
    glGenerateMipmap( GL_TEXTURE_2D );
    float *fPixel = new float[4];
    Timer.resume();
    glGetTexImage(GL_TEXTURE_2D, highestMipMapLevel, GL_RGBA, GL_FLOAT, fPixel);
    Timer.stop();
    

    Let this be a lesson to you: always provide complete information.

    The reason it takes 12x longer is because you’re measuring the time it takes to generate the mipmaps, not the time it takes to transfer the mipmap to the CPU. glGenerateMipmap, like most rendering commands, will not actually have finished by the time it returns. Indeed, odds are good that it won’t have even started. This is good, because it allows OpenGL to run independently of the CPU. You issue a rendering command, and it completes sometime later.

    However, the moment you start reading from that texture, OpenGL has to stall the CPU and wait until everything that will touch that texture has finished. Therefore, your timing is measuring the time it takes to perform all operations on the texture as well as the time to transfer the data back.

    If you want a more accurate measurement, issue a glFinish before you start your timer.

    More importantly, if you want to perform an asynchronous read of pixel data, you will need to do the read into a buffer object. This allows OpenGL to avoid the CPU stall, but it is only helpful if you have other work you could be doing in the meantime.

    For example, if you’re doing this to figure out the overall lighting for a scene for HDR tone mapping, you should be doing this for the previous frame’s scene data, not the current one. Nobody will notice. So you render a scene, generate mipmaps, read into a buffer object, then render the next frame’s scene, generate mipmaps, read into a different buffer object, then start reading from the previous scene’s buffer.

    That way, by the time you start reading the previous read’s results, they will actually be there and no CPU stall will happen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use RenderAction to render a partial that is used all over my site.
I've created a couple of floating point RGBA texture... glBindTexture( GL_TEXTURE_2D, texid[k] ); glTexParameteri(GL_TEXTURE_2D,
I currently have a R8G8B8 floating point render target and want to use it
I render all my surfaces to a buffer, then at the end of the
How to render partial view in some specific div without using ajax in asp.net
I want to render the partial view using ajax. When I submit the button,
How do you render a different .js.erb file while using Ajax? For example: <%
The application loads terrain elevation data into floating point textures. Textures are then rendered
I am using StringTemplate in Java. I would like to render decimal number with
I work with a lot of floating-point images, and would find it extremely useful

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.