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 21

Thread: Clear a single cubemap in a cubemap Array

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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
    445
    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
    429
    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.

Posting Permissions

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