Alternative to glFramebufferTexture for OpenGL version 3.1 and Oculus Rift

醉酒当歌 提交于 2019-12-13 06:51:47

问题


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?


回答1:


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().



来源:https://stackoverflow.com/questions/23593162/alternative-to-glframebuffertexture-for-opengl-version-3-1-and-oculus-rift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!