OpenGL rendering operations involve modifying a 2D grid of pixels. You can’t directly render primitives into a voxel grid. So you can either:
- render each layer as a separate operation,
- attach an entire 3D (or 2D array) texture as a layered framebuffer and select the target layer with a geometry shader which assigns to [var]gl_Layer[/var], or
- modify the texture directly using image store operations, either in a compute shader or some other shader.
As to whether to use a 3D texture or a 2D array texture, it depends upon what you’re going to do with the resulting texture. The two texture types differ in how they’re accessed (3D textures use texture coordinates with 3 normalised (0…1) components, array textures use 2 normalised components and an non-normalised layer index) and how filtering is handled (3D textures apply linear filtering and mipmapping in all 3 dimensions, array textures only in 2 dimensions).