替代glFramebufferTexture for OpenGL 3.1和Oculus Rift

时间:2014-05-11 13:25:43

标签: opengl oculus

所以Oculus Rift SDK接受使用 glFramebufferTexture 函数创建的帧缓冲纹理ID。

示例:

    [...]

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;

[...]

但是,glFramebufferTexture函数仅在OpenGL 3.2 +中可用。

是否有可能创建一个在功能上等效且Oculus Rift SDK可接受的解决方法?

1 个答案:

答案 0 :(得分:6)

使用glFramebufferTexture2D()。自从引入原始帧缓冲对象(FBO)功能以来,OpenGL 3.0就可以使用该功能。

之后添加了

glFramebufferTexture()以获取涉及立方体贴图和纹理数组的更高级FBO用例。对于简单的2D纹理,它大部分等同于glFramebufferTexture2D()