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 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Clear a single cubemap in a cubemap Array

  1. #1
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    11

    Clear a single cubemap in a cubemap Array

    I need to clear a specific cubemap layer within a cubemap array. I think this may be achievable with glFramebufferTextureLayer, and below is my attempt, but it is still clearing the entire cubemap array.

    Code :
    GL.BindFramebuffer(FramebufferTarget.Framebuffer, shadowMapArray.FBO_handle);
     
    FramebufferTarget target = FramebufferTarget.Framebuffer;
    FramebufferAttachment attachment = FramebufferAttachment.ColorAttachment0;
    int level = 0;
    int layer = currentShadowMap;
    int texture = shadowMapArray.FBO_handle;
     
    GL.FramebufferTextureLayer(target, attachment, texture, level, layer);
    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

    FBO/Cubemap Array creation and attachment:

    Code :
    public CubeMapArray()
    {
        // Create the FBO
        GL.GenFramebuffers(1, out FBO_handle);
     
        // Create and bind the CubeMap array
        GL.GenTextures(1, out cubeMapTextureHandle);
        GL.BindTexture(TextureTarget.TextureCubeMapArray, cubeMapTextureHandle);
     
        // Allocate storage space
        GL.TexImage3D(TextureTarget.TextureCubeMapArray, 0, PixelInternalFormat.Rg16, size, size, layers * 6, 0, PixelFormat.Red, PixelType.Float, IntPtr.Zero);
     
        // Set the suitable texture parameters
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureBaseLevel, 0);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureMaxLevel, 0);
     
        // Create and bind the CubeMap depth array
        GL.GenTextures(1, out cubeMapDepthHandle);
        GL.BindTexture(TextureTarget.TextureCubeMapArray, cubeMapDepthHandle);
     
        // Allocate storage space
        GL.TexImage3D(TextureTarget.TextureCubeMapArray, 0, PixelInternalFormat.DepthComponent, size, size, layers * 6, 0, PixelFormat.DepthComponent, PixelType.UnsignedByte, IntPtr.Zero);
     
        // Set the suitable texture parameters
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureBaseLevel, 0);
        GL.TexParameter(TextureTarget.TextureCubeMapArray, TextureParameterName.TextureMaxLevel, 0);
    }

  2. #2

  3. #3
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    11
    No, there is not some reason why I can't use glClearTexSubImage. I'll give it another try. I mentioned it on StackOverflow but nobody acknowledged it, instead referring me to glFramebufferTextureLayer, people even upvoted the answer. Still cleared the whole cubemap array for me.

  4. #4
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    11
    The cubemap array contains 8 cubemaps, I'm trying to clear only the one at index 2, except it's wiping the lot.

    Code :
    int layer = currentShadowMap;
    int texture = shadowMapArray.FBO_handle;
    int level = 2; // Attempting to clear cubemap at index 2
    int xoffset = 0;
    int yoffset = 0;
    int zoffset = 0;
    int width = shadowMapArray.size;
    int height = shadowMapArray.size;
    int depth = 6;
    PixelFormat format = PixelFormat.Red;
    PixelType type = PixelType.Float;
    IntPtr data = IntPtr.Zero;
     
    GL.BindFramebuffer(FramebufferTarget.Framebuffer, shadowMapArray.FBO_handle);
    GL.ClearTexSubImage(texture, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);

  5. #5
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    443
    Code :
    int level = 2; // Attempting to clear cubemap at index 2
     
    GL.ClearTexSubImage(texture, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);

    level means the "mipmap level" to clear, i guess that ought to be 0. and you dont have to bind a framebuffer to clear a (sub-) texture (attached to it)

  6. #6
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    428
    Quote Originally Posted by john_connor View Post
    Code :
    int level = 2; // Attempting to clear cubemap at index 2
     
    GL.ClearTexSubImage(texture, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);

    level means the "mipmap level" to clear, i guess that ought to be 0. and you dont have to bind a framebuffer to clear a (sub-) texture (attached to it)
    Yes as far as I understand it, it looks like the OP is mixing levels and layers.


    To the OP, also try to select the face you want first by calling glFramebufferTextureFace. You need ARB_geometry_shader4 to use it however.

  7. #7
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    11
    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?

    Code :
    FramebufferTarget target = FramebufferTarget.Framebuffer;
    FramebufferAttachment attachemnt = FramebufferAttachment.ColorAttachment0;
    int texture = shadowMapArray.cubeMapTextureHandle;
    int level = 0;
    TextureTarget face = TextureTarget.TextureCubeMap;
     
    int xoffset = 0;
    int yoffset = 0;
    int zoffset = 0;
    int width = shadowMapArray.size;
    int height = shadowMapArray.size;
    int depth = 6;
    PixelFormat format = PixelFormat.Red;
    PixelType type = PixelType.Float;
    IntPtr data = IntPtr.Zero;
     
    GL.Arb.FramebufferTextureFace(target, attachemnt, texture, level, face);
    GL.ClearTexSubImage(texture, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
    shadowMapArray.cubeMapTextureHandle is the actual texture handle, is this correct?

    Code :
    // Create the FBO
    GL.GenFramebuffers(1, out FBO_handle);
     
    // Create and bind the CubeMap array
    GL.GenTextures(1, out cubeMapTextureHandle);
    GL.BindTexture(TextureTarget.TextureCubeMapArray, cubeMapTextureHandle);
    Last edited by livin_amuk; 09-12-2017 at 04:17 AM.

  8. #8
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    428
    Well, I don't know if what I told above can be useful for you.

    In case it might, here are some links that might help further:

    https://www.khronos.org/opengl/wiki/...ered_Rendering
    https://www.khronos.org/opengl/wiki/...array_textures

  9. #9
    Junior Member Newbie
    Join Date
    May 2016
    Posts
    11
    I was slow at editing my reply above and didn't see this, I read through that documentation but couldn't see what I'm after however.

    The updated code above actually works, but only clears the first cubemap in the array, do you know where I make the change to indicate subsequent a cubemap? By changing depth from 6 to 7 it clears all the entire first cubemap and one face of the second cubemap, as expected. What I need to do obivously is specify the starting offset. Any value other than 0 for xoffset, yoffset, or zoffset and nothing is cleared at all, I guess they refer to regions within the individual cubemap faces.
    Last edited by livin_amuk; 09-12-2017 at 04:29 AM.

  10. #10
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,728
    Documentation: https://www.khronos.org/registry/Ope...ar_texture.txt

    Cube map textures are treated as an array of six slices in the z-dimension, where the value of <zoffset> is interpreted as specifying the cube map face for the corresponding <layer> in table 9.3 (Layer numbers for cube map texture faces) and <depth> is the number of faces to clear. For cube map array textures, <zoffset> is the first layer-face to clear, and <depth> is the number of layer-faces to clear. Each layer-face is translated into an array layer and a cube map face as described for layer-face numbers in section 8.5.3.

Posting Permissions

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