<p>FBOs can only use a single depth image, but that image <em>can</em> be layered. Broadly speaking, VR multi-eye rendering ought to be done through layered FBO images for both the color and depth buffers.</p>
<p>The problem with your code is that you can't use <code>glFramebufferTexture3D</code> to attach a layered image. You must use <code>glFramebufferTexture</code>.</p>
<p>Also, you need to use layers for the color image as well.</p>

CC BY-SA 4.0
2020-07-13T14:21:23.980Z
Thanks a lot! when layering both (color and depth) everything is working...
Thomas
CC BY-SA 4.0
2020-07-13T13:23:54.060Z
2020-07-13T13:23:54.060Z
Nicol Bolas
<p>I am trying to put multiple depthbuffers into one Framebuffer.
I want to use VR and render both eyes at the same time:</p>
<p>that means, in the geometry stage I want to clone the incoming triangle to two outgoing triangles with a shift of the eye offset for layered rendering. Therefore I would like to have two RGB textures / maybe one RGB texture 2d array and two depthbuffers / a depthbuffer array</p>
<p>here is my program code so far, the error occurred at the second last line of code and it is a GL_INVALID_ENUM error.</p>
<pre><code>GLError();
glGenFramebuffers(1, &amp;m_sFrameBufferInfo.m_nFrameBuffer);
GLError();
glBindFramebuffer(GL_FRAMEBUFFER, m_sFrameBufferInfo.m_nFrameBuffer);

//Left eye
GLuint textureLeft;
glGenTextures(1, &amp;textureLeft);
GLError();
glBindTexture(GL_TEXTURE_2D, textureLeft);
GLError();

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_nWindowWidth, m_nWindowHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
GLError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLError();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureLeft, 0);
GLError();

//right eye
GLuint textureRight;
glGenTextures(1, &amp;textureRight);
GLError();
glBindTexture(GL_TEXTURE_2D, textureRight);
GLError();

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_nWindowWidth, m_nWindowHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
GLError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLError();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textureRight, 0);
GLError();

//depth buffer
GLuint textureDepth;

glGenTextures(1, &amp;textureDepth);
GLError();
glBindTexture(GL_TEXTURE_2D_ARRAY, textureDepth);
GLError();

glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH24_STENCIL8, m_nWindowWidth, m_nWindowHeight,2 , 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
GLError();

glFramebufferTexture3D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D_ARRAY, textureDepth, 2, 0);
GLError();

glBindFramebuffer(GL_FRAMEBUFFER, 0);
GLError();
</code></pre>
<p>Thanks for your help!</p>

<opengl><frame-buffer><virtual-reality>
OpenGL Framebuffer with multiple Depthbuffers inside
Thomas
# OpenGL Framebuffer with multiple Depthbuffers inside

(Asked by: username_0 on 2020-07-13)

I am trying to put multiple depthbuffers into one Framebuffer.
I want to use VR and render both eyes at the same time:

that means, in the geometry stage I want to clone the incoming triangle to two outgoing triangles with a shift of the eye offset for layered rendering. Therefore I would like to have two RGB textures / maybe one RGB texture 2d array and two depthbuffers / a depthbuffer array

here is my program code so far, the error occurred at the second last line of code and it is a GL\_INVALID\_ENUM error.

```
GLError();
glGenFramebuffers(1, &m_sFrameBufferInfo.m_nFrameBuffer);
GLError();
glBindFramebuffer(GL_FRAMEBUFFER, m_sFrameBufferInfo.m_nFrameBuffer);

//Left eye
GLuint textureLeft;
glGenTextures(1, &textureLeft);
GLError();
glBindTexture(GL_TEXTURE_2D, textureLeft);
GLError();

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_nWindowWidth, m_nWindowHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
GLError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLError();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureLeft, 0);
GLError();

//right eye
GLuint textureRight;
glGenTextures(1, &textureRight);
GLError();
glBindTexture(GL_TEXTURE_2D, textureRight);
GLError();

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_nWindowWidth, m_nWindowHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
GLError();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GLError();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLError();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textureRight, 0);
GLError();

//depth buffer
GLuint textureDepth;

glGenTextures(1, &textureDepth);
GLError();
glBindTexture(GL_TEXTURE_2D_ARRAY, textureDepth);
GLError();

glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH24_STENCIL8, m_nWindowWidth, m_nWindowHeight,2 , 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
GLError();

glFramebufferTexture3D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D_ARRAY, textureDepth, 2, 0);
GLError();

glBindFramebuffer(GL_FRAMEBUFFER, 0);
GLError();

```

Thanks for your help!

**Tags:** opengl, frame-buffer, virtual-reality


---

## 1 answers

### Answer by username_1 on 2020-07-13. Score: 1 | Accepted answer

FBOs can only use a single depth image, but that image *can* be layered. Broadly speaking, VR multi-eye rendering ought to be done through layered FBO images for both the color and depth buffers.

The problem with your code is that you can't use `glFramebufferTexture3D` to attach a layered image. You must use `glFramebufferTexture`.

Also, you need to use layers for the color image as well.

> **Comments:**
> **username_0**: Thanks a lot! when layering both (color and depth) everything is working...  

---

