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 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Occlusion Culling by the Cryengine way: understanding

  1. #11
    Intern Contributor
    Join Date
    Nov 2017
    Posts
    80
    Quote Originally Posted by GClements View Post
    Render a quad with the source depth buffer bound to a texture image unit and the destination depth buffer attached to the framebuffer.

    Should I bind VBO to texture with screen resolution and the same time I bind VBO with low (downscaled) resolution to framebuffer?
    Can I render to two destinations at the same time?




    Also I have another problem
    if I use next code, then buffer is filled ok:
    Code :
      ByteBuffer buffer = BufferUtils.createByteBuffer(display.getWidth() * display.getHeight() * 4);  // create buffer on CPU side
      glReadPixels(0, 0, display.getWidth(), display.getHeight(), GL_DEPTH_COMPONENT, GL_FLOAT, buffer);  // reading depth data directly from framebuffer to buffer on CPU side.
      // have here filled buffer.


    but if I trying do that as GClements wrote, then buffer is empty:
    Code :
      int devicePBO = glGenBuffers();  // init buffer on GPU
      glBindBuffer(GL_PIXEL_PACK_BUFFER, devicePBO);  // bing buffer
      glReadPixels(0, 0, display.getWidth(), display.getHeight(), GL_DEPTH_COMPONENT, GL_FLOAT, devicePBO);  // reading depth data from framebuffer to GPU buffer.
      ByteBuffer buffer = BufferUtils.createByteBuffer(display.getWidth() * display.getHeight() * 4);  // create buffer on CPU side
      glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE, buffer);  // map GPU buffer to CPU buffer
      // have here empty data in CPU buffer.

    May be I'm completely wrong with my interpretation of:
    Quote Originally Posted by GClements View Post
    glBindBuffer(GL_PIXEL_PACK_BUFFER)
    glReadPixels() or glGetTexImage()
    Wait
    glMapBuffer() or glGetBufferSubData()

  2. #12
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,003
    Quote Originally Posted by nimelord View Post
    Should I bind VBO to texture with screen resolution and the same time I bind VBO with low (downscaled) resolution to framebuffer?
    Can I render to two destinations at the same time?
    You're simply rendering a quad (two triangles). The destination FBO will have the low-resolution depth texture as its depth attachment (and no colour attachment). The high-resolution depth texture will just be a texture. The fragment shader will just sample that texture and write the result to gl_FragDepth.


    Quote Originally Posted by nimelord View Post
    Code :
      glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE, buffer);  // map GPU buffer to CPU buffer
      // have here empty data in CPU buffer.
    glMapBuffer takes two arguments, and returns a pointer to the mapped region. If you want a copy in CPU memory, you'd memcpy() (or similar) from the mapped region into the CPU-side buffer. But in that case you may as well use glGetBufferSubData().

  3. #13
    Intern Contributor
    Join Date
    Nov 2017
    Posts
    80
    Quote Originally Posted by GClements View Post
    You're simply rendering a quad (two triangles). The destination FBO will have the low-resolution depth texture as its depth attachment (and no colour attachment). The high-resolution depth texture will just be a texture. The fragment shader will just sample that texture and write the result to gl_FragDepth.
    It seems I understood what do you mean.
    So there is an algorithm:

    1 - Render a scene into high-resolution texture instead of framebuffer.
    2 - Render result texture as a quad to the low-resolution texture with depth attachment only.
    3 - Copy (or render?) high-resolution texture to framebuffer to show it. (I'm not sure here how to show on display prepared texture.)
    4 - Use low-resolution depth texture for "Coverage buffering".

    It is correct?

    Next step will be "Coverage buffering" itself. But here I need additional investigation for details.

    You wrote:
    Quote Originally Posted by GClements View Post
    glMapBuffer takes two arguments, and returns a pointer to the mapped region. If you want a copy in CPU memory, you'd memcpy() (or similar) from the mapped region into the CPU-side buffer. But in that case you may as well use glGetBufferSubData().
    I read before "Coverage buffering" requires software rasterization.
    I thought depth texture must located on CPU memory for doing that, because I need to keep relations of rasterazed meshes with fact of visibility of them. (Or may be exist some way to do this process on GPU side?)
    Last edited by nimelord; 01-07-2018 at 03:55 AM.

Tags for this Thread

Posting Permissions

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