AnswerBun.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!

Related Questions

glutSolid* source code

1  Asked on November 22, 2021 by tado-mi

 

How to retrieve data from Compute Shader to CPU?

0  Asked on November 15, 2021 by ethan-ma

   

unwanted patterns in simplex noise

1  Asked on November 13, 2021 by sam-apostel

 

Procedural generation of biological models

1  Asked on November 13, 2021 by daniel-cooke

 

What method is used for baking grayscale curvature maps

1  Asked on November 10, 2021 by jummit

     

Why are texture coordinates often called UVs?

2  Asked on August 27, 2021 by samanthaj

 

Dynamic Ray-Triangle Intersection

1  Asked on August 27, 2021 by cemklkn

     

Draw Line on Arbitrary Surface

0  Asked on August 27, 2021 by valentin-molina

 

How to raytrace Bezier surfaces?

5  Asked on August 27, 2021 by luser-droog

   

Better Shadow Mapping Techniques

2  Asked on August 27, 2021 by arjan-singh

       

What does GPU assembly look like?

4  Asked on August 27, 2021 by sebastien-finor

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir