Results 1 to 3 of 3

Thread: glDepthRange()

  1. #1
    Senior Member Regular Contributor
    Join Date
    Apr 2012


    I am bit confused with working of glDepthRange(). I have following doubts:
    1. does it specify the accuracy or resolution of depth buffer values. for example, range 0..2000 will have more accurate depth values than range 0..200 ? and these mapping will finally transform values from 0..1.?

    2. does it provide any sort of clipping? range 0..0.3 will clip if depth value is > 0.3 ?

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Well, almost all your assumptions are wrong, except one. glDepthRange does affect precision.

    Near and far clip-planes are set with projection matrix. Parameters of glDepthRange just say how to map near and far distances to [0..1] range, and they cannot be greater than 1.0.
    Therefore, if you call glDepthRange(0.1, 0.6), near clip-plane distance will be mapped to 0.1 and far to 0.6. You'll use just 50% of the range.

    Answer to your second question is obvious; glDepthRange() does not perform any clipping. It is used just to manage how depth buffer values are calculated.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    The depth range is just a final affine transformation applied to the z coordinate after the model-view and projection transformations and after clipping. The values after the depth range transformation (which will always be between 0 and 1) are converted to the fixed-point representation used by the depth buffer.

    glDepthRange() allows you to allocate a portion of the depth range to a particular rendering phase. So if you were rendering a view from inside a building with scenery visible through a window, you might render the scenery with glDepthRange(0.5, 1.0) and render the interior with glDepthRange(0.0, 0.5), so the interior is always in front of the scenery. Or if you wanted a 3D GUI overlay, you could render the scene with glDepthRange(0.1, 1.0) and use glDepthRange(0.0, 0.1) for the GUI, so that the scene never intersects or obscures the GUI

    Alternatively, you could just clear the depth buffer between phases, but this requires that the phases are disjoint, i.e. you complete one before starting the next, which may not always be straightforward. Also, clearing the depth buffer used to have a non-trivial cost (to the extent that programs would sometimes use a fraction of the depth range for each frame, only clearing the depth buffer once every N frames).

Similar Threads

  1. glPolygonOffset() vs glDepthRange()?
    By ugluk in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 01-09-2011, 07:12 AM
  2. Tweak glDepthRange
    By kRogue in forum OpenGL: General
    Replies: 0
    Last Post: 07-08-2010, 01:30 AM
  3. glDepthRange problem
    By imported_Adrian in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 11-20-2003, 02:03 AM
  4. glDepthRange Madness!
    By amendola in forum OpenGL: Advanced Coding
    Replies: 11
    Last Post: 11-29-2002, 09:06 AM
  5. glDepthRange()
    By radde in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 05-24-2001, 08:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean