Layered Rendering

When rendering into a framebuffer object, it is possible to use a 2D array texture as a color attachment and render into the slices of the array using a geometry shader. To create a 2D array texture and attach it to a framebuffer object, use code such as that shown in Example 10.24.

Example 10.24. Example Code to Create an FBO with an Array Texture Attachment

// Declare variablesGLuint tex;        // This will be the 2D array textureGLuint fbo;        // The framebuffer object// Create and allocate a 1024x1024x32 2D array textureglGenTextures(1, &tex);glBindTexture(GL_TEXTURE_2D_ARRAY, tex);glTexImage3D(GL_TEXTURE_2D_ARRAY,             0,             GL_RGBA,             1024,             1024, ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.