问题描述
我的渲染纹理iPhone代码仅在禁用MSAA的情况下有效,否则,我得到的只是黑色纹理.是什么原因引起的?
My render to texture iPhone code only works if I disable MSAA, otherwise all I get is a black texture. What could be the cause of the problem?
这是我的代码:
glViewport(0,0, target->_Width, target->_Height);
glClear(GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT Or GL_STENCIL_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, target->_Handle);
// render stuff here
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, target->_Width, target->_Height, 0);
glBindTexture(GL_TEXTURE_2D, 0);
推荐答案
显然,当您将MSAA用作主帧缓冲区时,还必须将其用于要渲染的其他任何FBO.由于 GL_TEXTURE_2D_MULTISAMPLE
在OpenGL ES 2上不可用,我发现的解决方案非常简单,就是将常规渲染到MSAA渲染所需的修改应用到渲染到纹理的代码中,好吧.
Apparently, when you are using MSAA for your main framebuffer, you have to use it for any other FBOs you want to render to as well. Since GL_TEXTURE_2D_MULTISAMPLE
is not available on OpenGL ES 2, the solution I have found is quite simply to apply the same modifications you need to go from regular rendering to MSAA rendering, to your render-to-texture code as well.
您需要3个额外的缓冲区:一个多采样的颜色渲染缓冲区,一个多采样深度的渲染缓冲区以及一个新的FBO来附加它们.在渲染之前,绑定新的FBO而不是纹理FBO.渲染之后,将新的MSAA FBO解析为纹理FBO,就像使用 glResolveMultisampleFramebufferAPPLE()
在主渲染代码中所做的一样.
You need 3 additional buffers: a multi-sampled color renderbuffer, a multi-sampled depth renderbuffer, and a new FBO to attach them to. Bind the new FBO instead of the texture FBO before rendering. After rendering, resolve the new MSAA FBO into the texture FBO, the same way you do in your main rendering code using glResolveMultisampleFramebufferAPPLE()
.
请注意,由于某些原因,启用了MSAA的纹理渲染在模拟器中无需进行这些修改即可工作.也许它会自动使用 GL_TEXTURE_2D_MULTISAMPLE
?
Note that for some reason, texture rendering with enabled MSAA works without these modifications in the simulator. Maybe it uses GL_TEXTURE_2D_MULTISAMPLE
automatically?
这篇关于启用MSAA后,iPhone中的openGL渲染到纹理失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!