TransWikia.com

OpenGL Framebuffer with multiple Depthbuffers inside

Computer Graphics Asked on August 27, 2021

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!

One 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.

Correct answer by Nicol Bolas on August 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP