Support render-to-self on GLES2.

This commit is contained in:
Unknown W. Brackets 2014-05-30 08:53:22 -07:00
parent c2778d9a2a
commit aecd5bf250

View File

@ -1028,49 +1028,27 @@ void FramebufferManager::BindFramebufferColor(VirtualFramebuffer *framebuffer, b
// currentRenderVfb_ will always be set when this is called, except from the GE debugger.
// Let's just not bother with the copy in that case.
if (!skipCopy && currentRenderVfb_ && MaskedEqual(framebuffer->fb_address, gstate.getFrameBufRawAddress())) {
#ifndef USING_GLES2
if (gl_extensions.FBO_ARB) {
bool useNV = false;
#else
if (gl_extensions.GLES3 || gl_extensions.NV_framebuffer_blit) {
bool useNV = !gl_extensions.GLES3;
#endif
#ifdef MAY_HAVE_GLES3
// TODO: Maybe merge with bvfbs_? Not sure if those could be packing, and they're created at a different size.
FBO *renderCopy = NULL;
std::pair<int, int> copySize = std::make_pair((int)framebuffer->renderWidth, (int)framebuffer->renderHeight);
for (auto it = renderCopies_.begin(), end = renderCopies_.end(); it != end; ++it) {
if (it->first == copySize) {
renderCopy = it->second;
break;
}
// TODO: Maybe merge with bvfbs_? Not sure if those could be packing, and they're created at a different size.
FBO *renderCopy = NULL;
std::pair<int, int> copySize = std::make_pair((int)framebuffer->renderWidth, (int)framebuffer->renderHeight);
for (auto it = renderCopies_.begin(), end = renderCopies_.end(); it != end; ++it) {
if (it->first == copySize) {
renderCopy = it->second;
break;
}
if (!renderCopy) {
renderCopy = fbo_create(framebuffer->renderWidth, framebuffer->renderHeight, 1, true, framebuffer->colorDepth);
renderCopies_[copySize] = renderCopy;
}
fbo_bind_as_render_target(renderCopy);
glViewport(0, 0, framebuffer->renderWidth, framebuffer->renderHeight);
glDisable(GL_SCISSOR_TEST);
fbo_bind_for_read(framebuffer->fbo);
#if defined(USING_GLES2) && (defined(ANDROID) || defined(BLACKBERRY)) // We only support this extension on Android, it's not even available on PC.
if (useNV) {
glBlitFramebufferNV(0, 0, framebuffer->renderWidth, framebuffer->renderHeight, 0, 0, framebuffer->renderWidth, framebuffer->renderHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} else
#endif // defined(USING_GLES2) && (defined(ANDROID) || defined(BLACKBERRY))
glBlitFramebuffer(0, 0, framebuffer->renderWidth, framebuffer->renderHeight, 0, 0, framebuffer->renderWidth, framebuffer->renderHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
fbo_bind_as_render_target(currentRenderVfb_->fbo);
fbo_bind_color_as_texture(renderCopy, 0);
glstate.viewport.restore();
glstate.scissorTest.restore();
#endif
} else {
fbo_bind_color_as_texture(framebuffer->fbo, 0);
}
if (!renderCopy) {
renderCopy = fbo_create(framebuffer->renderWidth, framebuffer->renderHeight, 1, true, framebuffer->colorDepth);
renderCopies_[copySize] = renderCopy;
}
VirtualFramebuffer copyInfo = *framebuffer;
copyInfo.fbo = renderCopy;
BlitFramebuffer_(&copyInfo, 0, 0, framebuffer, 0, 0, framebuffer->width, framebuffer->height, 0, false);
fbo_bind_as_render_target(currentRenderVfb_->fbo);
fbo_bind_color_as_texture(renderCopy, 0);
glstate.viewport.restore();
} else {
fbo_bind_color_as_texture(framebuffer->fbo, 0);
}