MRT for Texture2DArray

I’m trying to integrate deferred renders into the engine.
I want to write the following values: diffuse color, specular color, normal & tangent space quaternion.
I created a Texture2DArray with 4 slices of standard RGBA8 format. Then I assigned each slice to a different color attachment (0 to 3) of the FBO and set up DrawBuffers to draw to all these attachments.

However, I see the result only in the first layer when drawing them to the screen (for debug). There is garbage in other elayers…
Is there something not allowing to use MRT with texture arrays? Or it’s just my logical error somewhere?

I doubt it. NVidia specifically recommends you do this for PSSM in GPUGems3 (albeit in D3D). Though they used a geometry shader (translate: gl_Layer) to select which layer of the 2D array texture to write to.

Also, I believe that’s precisely the purpose of the glFramebufferTextureLayer API, which adds a “layer” parameter. Mentioned in EXT_texture_array.

AFAIS, Nvidia used not MRT but Layered Rendering. The latter designed to work in layers but it’s different from what I want to use. MRT seems to be faster (by not using Geometry Shader and transforming vertices twice) and better supported by older HW.

And yes, of course I’m using glFramebufferTextureLayer to select the layer for each color attachment. But in my case all layers belong to a single texture, so It might be a problem.

You could try it with 4 different textures rather than a single array texture.

BTW, did you query GL_MAX_DRAW_BUFFERS? You should not use more than that many buffers in a single draw call.

Yes, I could use 4 different textures… But… I’ll try to get it work straight with layers a little bit more.

I work with Radeon 2400 HD, my MaxDrawBuffers is 8.

Sorry, I didn’t realize there was a distinction in naming.

When reading D3D-centric articles like that, I tend to just ignore what they call things (because everything’s named differently or flipped backwards/upside down – just for the heck of it), and look at what they’re doing.

Actually, I read articles in the same manner as you, Dark Photon:)
However, it’s often required to know true names of things in order to communicate correctly.

Back to the topic: the problem is solved. I just failed to render the results correctly…
So there’s nothing blocking from using MRT for different layers of a single texture.

One more step - and I’ll have deferred renders :slight_smile:

Using an array texture for your gbuffer will prevent you from using different formats for different attachments. For instance, I like to store the normals as RGB10_A2 while albedo is stored as RGBA8.