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 10 of 11

Thread: Occlusion culling with ARB_occlusion_query

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    51

    Occlusion culling with ARB_occlusion_query

    I've tried many ways but I can't execute a good occlusion culling using ARB_occlusion_query extension.

    - glClear(...)
    - BEGIN WHILE for each object....
    --- frustum culling check
    --- if not in frustum, continue to next object
    --- I turn off color mask
    ---
    glDisable(GL_CULL_FACE);
    --- I render bounding box
    ---
    glEnable(GL_CULL_FACE);
    --- check culling result with glGetQueryObjectuiv(...., &occlusion_result)
    --- I turn on color mask
    --- I render only visible object (visible = "occlusion_result" variable greater than 0)
    - END WHILE

    Using this way I have boundig_boxes drawn on screen!
    How I can "render" without print to screen?
    I've already tried to "render" to FBO but it seems not to work using occlusion_query...so I preferred to stay in the default "DRAW_FRAMEBUFFER" which give me some fragment_count greater than zero.

    Screenshot (UP: without occlusion_query):

  2. #2
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    445
    Did you disable writing to the depth buffer too? Otherwise you will get objects that are drawn after the bounding box that fail the depth test when they aren't meant to, including the object that is meant to be contained inside the bounding box.

  3. #3
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    51
    Nope, depth_test is always enabled...infact the "grey bounding box" (which is not shaded due to colorMask to FALSE) visible in my screenshot is placed well in its right place and moving camera it moves according to the movement.

    My problem seems to be just the "bounding box draw" during normal rendering.
    All online examples doesn't uses two passes....but in my engine a single pass produces that effect, and it's wrong.

    Maybe I could solve the problem with a second pass in this way:
    void Render(){
    - 1st glClear(color | depth)
    - BEGIN WHILE for each object
    - execute occlusion query
    - save occlusion query result in an object's internal variable
    - END WHILE
    - 2nd glClear(color | depth)
    - BEGIN WHILE for each object
    - render only object with previous internal variable to TRUE
    - END WHILE
    }

    But I want to know why I have always problems and I can't use any SIMPLE source code I found online.....I'm a bit angry about that hahahaha
    I always have to interpret it or completly rewrite from scratch with a lot of changes.

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    445
    You have to disable depth writes for your bounding boxes, since you don't want their depth value to be stored in the depth buffer - you only want the box to be tested to see if any values would be visible. Disable depth writing for your bounding box in a similar way to color writing:
    Code :
    glDepthMask(GL_FALSE);
    AFAICT, it isn't the bounding boxes that are being drawn to the color buffer, but the terrain that isn't being drawn in that position due to your bounding box having already written a nearer depth value to the depth buffer, so the sky is visible through it.

  5. #5
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    51
    Yes, I don't understand why but now it works, but I'm sure I've tested that way already before.
    However thx!

    Question: during async query waits (to get results), what "actions" are allowed meanwhile? gl* functions (glMapBuffer, glReadPixel, and so on) are allowed? or only CPU-side (frustum culling, front_to_back objects sorting, etc...)?

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    You usually use the stall to perform CPU tasks. You might want to check out CHC++ and follow up papers.

Posting Permissions

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