View Full Version : Using GL_TEXTURE_2D_ARRAY to store multiple shadowmaps.

07-01-2016, 08:09 AM
Hello everyone,
I am trying to figure out how use a texture array 2D to handle multiple shadowmaps, each one attached to its own FBO.

//texturearray2d used to store 2 textures with only one image in each of them (is this correct? I took it from the wiki)
mipLevelCount = 1;
layerCount = 2;
glTexStorage3D(GL_TEXTURE_2D_ARRAY, mipLevelCount, ->_DONT_KNOW_<-, myshadowWidth, myshadowHeight, layerCount);

My first issue is: which internal format should I specify up there?

Also, is this the correct way to create a complete fbo for a shadowmap in the previously created array?

int fbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowMapArray, 0, index_of_the_ith_shadowmap);
GLenum c = glCheckFramebufferStatus(GL_FRAMEBUFFER);
cout << "FBO ShadowMap " << index_of_the_ith_shadowmap << " is complete";
cout <<"Error in FBO ShadowMap " << index;
glBindFramebuffer(FramebufferTarget.Framebuffer, 0);

Alfonse Reinheart
07-01-2016, 09:21 AM
My first issue is: which internal format should I specify up there?

... the same internal format you would have specified if you used a regular 2D texture.

Array textures (https://www.opengl.org/wiki/Array_Texture) are not some magical form of texture. They're just a different use of texture; they can store the same stuff.

07-03-2016, 01:51 AM
Thanks for your answer Alfonse. I hope you'll understand my inexperience, this is still the beginners' section am I right? I am confused by the fact that the ArrayTexture's tutorial says one should use glTexStorage3D, while shadowmap's tutorials I am following (like this (http://learnopengl.com/#!Advanced-Lighting/Shadows/Shadow-Mapping) or this (http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/)) adopt a straight glTexImage2D. At the moment I'm trying to do the same with glTexImage3D, is my reasoning flawed? (Sorry, I am a beginner)

Edit1: I initialized the texture array with
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT, myshadowWidth, myshadowHeight, layerCount, 0, GL_DEPTH_COMPONENT, GL_FLOAT, null);
and the code is used for the fbo's setup printed out "FBO ShadowMap _right_number_ is complete". So I guess I'm good to go now :) or am I falling in a silly pitfall?

Edit2: It looks like my shadowmaps work! I colored a stanford bunny on account of which shadowmap test was resulting positive for each point and the colours were just right.