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 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Clear a single cubemap in a cubemap Array

  1. #11
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,402
    Quote Originally Posted by livin_amuk View Post
    Ah right that clears it up, level is "mipmap level".

    I couldn't find any documentation for glFramebufferTextureFace. Despite returning an InvalidOperation error, this is actually working and clears the first cubemap. How would I for example clear the second in the array?
    Cube map array textures are often treated as an array of 6*N 2D textures ("layer-faces"), where N is the size of the array. I.e. each face of each layer is a separate 2D texture. This is certainly the case when binding a specific face as a non-layered framebuffer attachment, and appears to be the case for clearing. The glClearTexSubImage reference page says:
    For cube map array textures, zoffset is the first layer-face to clear, and depth is the number of layer-faces to clear.
    So to clear a given mipmap level for all six faces of the cube map corresponding to layer n, you'd use:
    Code :
    glClearTexSubImage(texture, level, 0, 0, 6*n, size, size, 6, format, type, data);
    To clear all mipmap levels, you'd need to call it in a loop, incrementing level and halving size at each step (cube map faces must be square, i.e. the width and height will always be equal).

  2. #12
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    11
    Thank you mhagain, that is working. It's clearing the color attachment, it seems I have to manually clear the attached depth buffer? Is this correct?

  3. #13
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,402
    glClear() should clear whichever buffers are indicated by the mask parameter, but note that write masks set by e.g. glColorMask() or glDepthMask() apply to glClear(). Obviously, the relevant textures need to be attached to the currently-bound FBO at the time of the call.

    glClearTexSubImage() only affects the specified texture.

  4. #14
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    11
    Unless I'm misunderstanding you, glClear() is useless for me here because it wipes the entire FBO, thus the entire cubemap array.

    glClearTexSubImage() is working for me, in other words it's clearing specific individual cubemap layers, but only the color texture and not the associated depth texture. Do I need a second glClearTexSubImage() call with different parameters to clear the depth?

  5. #15
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,906
    Quote Originally Posted by livin_amuk View Post
    Unless I'm misunderstanding you, glClear() is useless for me here because it wipes the entire FBO, thus the entire cubemap array.

    glClearTexSubImage() is working for me, in other words it's clearing specific individual cubemap layers, but only the color texture and not the associated depth texture. Do I need a second glClearTexSubImage() call with different parameters to clear the depth?
    It doesn't clear the framebuffer. It clears the texture you pass in. The framebuffer is completely irrelevant.

    If you have two textures you want to clear, then you need two calls to `glClearTexSubImage`.

  6. #16
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    11
    I think I need to back up a bit here...

    Currently I am:
    1. Using glClear() to clear an entire cubemap array.
    2. Rendering a bunch of cubemaps into the array.

    What I am trying to achieve is this:
    1. Use any method possible to clear a single cubemap from the array
    2. Render a single cubemap into the array.

    It is step 1 that I am struggling with. I need to perform the equivalent of glClear, except only on a single cubemap, not the entire array. How would you go about this Alfonse?
    Last edited by livin_amuk; 09-12-2017 at 09:45 AM.

  7. #17
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,683
    This is confusing us because your original question stated nothing about clearing a depth buffer: you asked, and only asked, about clearing a single cubemap, then when you got that working you started asking about a depth buffer too. If you had given us the full requirement in your original question you might have got a full answer.

    To clear a depth buffer the old-fashioned what you can use glClear (GL_DEPTH_BUFFER_BIT), having ensured that depth-writing is enabled and that your glClearDepth is set to the value you wish to clear to, and that will do the job for a good percentage of use cases. For more control use the modern way: glClearBuffer, making sure that you pay attention to the documentation because it describes the specific calls and parameters you need to use to successfully clear depth. Yes, this is an extra OpenGL call; you cannot clear both color and depth in a single call using this approach.

  8. #18
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,402
    Quote Originally Posted by livin_amuk View Post
    1. Use any method possible to clear a single cubemap from the array
    You can either

    1. bind individual layer-faces to the FBO and clear each one with glClear(), or
    2. clear a range of layer-faces with glClearTexSubImage()


    The first option can also clear any attached depth buffer. With the second option, you'll need to clear the depth buffer separately; either with glClear(GL_DEPTH_BUFFER_BIT), or glClearBuffer(), or by using glClearTexSubImage() on the depth texture (assuming that it's a texture and not a renderbuffer).

    You can't clear a subset of the layer-faces of a cube map array using a single glClear() call, as you can't bind a subset of the layer-faces to a FBO. You can only bind either a single layer-face (with glFramebufferTextureLayer()) or the entire array (with glFramebufferTexture()). The same restrictions apply to glClearBuffer().

  9. #19
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    11
    Quote Originally Posted by mhagain View Post
    This is confusing us because your original question stated nothing about clearing a depth buffer.
    I figured it'd be a safe assumption, guess I'm still a novice. Not here to screw around though, I'll be more explicit in the future.

    Quote Originally Posted by GClements View Post
    1. bind individual layer-faces to the FBO and clear each one with glClear()
    Thank you. Is this something that has to be done during the creation of the FBO or can it be done during the render pass?

    Code :
    GL.BindFramebuffer(FramebufferTarget.Framebuffer, shadowMapArray.FBO_handle);
     
    FramebufferTarget target = FramebufferTarget.Framebuffer;
    FramebufferAttachment attachment = FramebufferAttachment.ColorAttachment0;
    int level = 0;
    int layer = 2; // Trying to delete cubemap at array index 2
    int texture = shadowMapArray.cubeMapTextureHandle;
     
    GL.FramebufferTextureLayer(target, attachment, texture, level, layer);
    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

    Is glFramebufferTextureLayer the wrong choice here? Pretty sure, because there isn't an option to specify which face. I guess 'texture' needs to point to a layerface texture? This is clearing the whole cubemap array btw.

  10. #20
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    417
    Quote Originally Posted by livin_amuk View Post
    Is this something that has to be done during the creation of the FBO or can it be done during the render pass?
    you can modify your FBO (framebuffer object) whenever you want. usually it's a good choice to modify it once at initialization.


    Quote Originally Posted by livin_amuk View Post
    Is glFramebufferTextureLayer the wrong choice here? Pretty sure, because there isn't an option to specify which face. I guess 'texture' needs to point to a layerface texture? This is clearing the whole cubemap array btw.
    depends on what you want to do (couldnt figured that out):
    1. render to texture (cubemap array):
    glFramebufferTexture(...)

    2. render to texture layer (1 face [2D surface] of a cubemap OR cubemap array):
    glFramebufferTextureLayer(...)


    just read the description:
    https://www.khronos.org/registry/Ope...ureLayer.xhtml

    "layer" determines what cubemap index AND face
    set "layer" to 15 means:
    cubemap index = 15 / 6 = 2
    face = 15 % 6 = 3


    the same is true for "render to texture" (cubemap array): but layer is then the "gl_Layer" variable used in the geometry shader

Posting Permissions

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