Alternative to glFramebufferTexture for OpenGL version 3.1 and Oculus Rift

StackOverflow https://stackoverflow.com/questions/23593162

  •  20-07-2023
  •  | 
  •  

Вопрос

So the Oculus Rift SDK accepts a framebuffer texture ID which is created with the glFramebufferTexture function.

Example:

    [...]

GLuint l_FBOId;
glGenFramebuffers(1, &l_FBOId);
glBindFramebuffer(GL_FRAMEBUFFER, l_FBOId);

// The texture we're going to render to...
GLuint l_TextureId;
glGenTextures(1, &l_TextureId);
// "Bind" the newly created texture : all future texture functions will modify this texture...
glBindTexture(GL_TEXTURE_2D, l_TextureId);
// Give an empty image to OpenGL (the last "0")
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, l_TextureSize.w, l_TextureSize.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
// Linear filtering...
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

// Create Depth Buffer...
GLuint l_DepthBufferId;
glGenRenderbuffers(1, &l_DepthBufferId);
glBindRenderbuffer(GL_RENDERBUFFER, l_DepthBufferId);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, l_TextureSize.w, l_TextureSize.h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, l_DepthBufferId);

[...]

/*

Oculus Rift API

*/

ovrGLTexture l_EyeTexture[2];
l_EyeTexture[0].OGL.Header.API = ovrRenderAPI_OpenGL;
l_EyeTexture[0].OGL.Header.TextureSize.w = l_TextureSize.w;
l_EyeTexture[0].OGL.Header.TextureSize.h = l_TextureSize.h;
l_EyeTexture[0].OGL.Header.RenderViewport = l_Eyes[0].RenderViewport;
l_EyeTexture[0].OGL.TexId = l_TextureId;

[...]

However, the glFramebufferTexture function is only available in OpenGL 3.2+.

Is it possible to create a workaround that will be functionally equivalent and acceptable to the Oculus Rift SDK?

Это было полезно?

Решение

Use glFramebufferTexture2D(). That function has been available since OpenGL 3.0, when the original framebuffer object (FBO) functionality was introduced.

glFramebufferTexture() was added later for more advanced FBO use cases involving cube maps and texture arrays. For simple 2D textures, it's mostly equivalent to glFramebufferTexture2D().

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top