1
0
Fork 0
forked from suyu/suyu

gl_texture_cache: Fix scaling blits

This commit is contained in:
ReinUsesLisp 2021-07-31 03:04:33 -03:00 committed by Fernando Sahmkow
parent cfeb161c7e
commit c9238555f7

View file

@ -478,6 +478,10 @@ TextureCacheRuntime::TextureCacheRuntime(const Device& device_, ProgramManager&
if (is_rescaling_on) { if (is_rescaling_on) {
rescale_draw_fbo.Create(); rescale_draw_fbo.Create();
rescale_read_fbo.Create(); rescale_read_fbo.Create();
// Make sure the framebuffer is created without DSA
glBindFramebuffer(GL_READ_FRAMEBUFFER, rescale_draw_fbo.handle);
glBindFramebuffer(GL_READ_FRAMEBUFFER, rescale_read_fbo.handle);
} }
} }
@ -882,11 +886,6 @@ bool Image::Scale(bool scale_src, bool scale_dst) {
UNIMPLEMENTED(); UNIMPLEMENTED();
return false; return false;
} }
GLint prev_draw_fbo;
GLint prev_read_fbo;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &prev_draw_fbo);
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &prev_read_fbo);
const GLenum attachment = [this] { const GLenum attachment = [this] {
switch (GetFormatType(info.format)) { switch (GetFormatType(info.format)) {
case SurfaceType::ColorTexture: case SurfaceType::ColorTexture:
@ -935,10 +934,8 @@ bool Image::Scale(bool scale_src, bool scale_dst) {
dst_info.size.height = dst_height; dst_info.size.height = dst_height;
auto dst_texture = MakeImage(dst_info, gl_internal_format); auto dst_texture = MakeImage(dst_info, gl_internal_format);
const auto& read_fbo = runtime->rescale_read_fbo; const GLuint read_fbo = runtime->rescale_read_fbo.handle;
const auto& draw_fbo = runtime->rescale_draw_fbo; const GLuint draw_fbo = runtime->rescale_draw_fbo.handle;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, draw_fbo.handle);
glBindFramebuffer(GL_READ_FRAMEBUFFER, read_fbo.handle);
for (s32 layer = 0; layer < info.resources.layers; ++layer) { for (s32 layer = 0; layer < info.resources.layers; ++layer) {
for (s32 level = 0; level < info.resources.levels; ++level) { for (s32 level = 0; level < info.resources.levels; ++level) {
const u32 src_level_width = std::max(1u, src_width >> level); const u32 src_level_width = std::max(1u, src_width >> level);
@ -946,20 +943,15 @@ bool Image::Scale(bool scale_src, bool scale_dst) {
const u32 dst_level_width = std::max(1u, dst_width >> level); const u32 dst_level_width = std::max(1u, dst_width >> level);
const u32 dst_level_height = std::max(1u, dst_height >> level); const u32 dst_level_height = std::max(1u, dst_height >> level);
glNamedFramebufferTextureLayer(read_fbo.handle, attachment, texture.handle, level, glNamedFramebufferTextureLayer(read_fbo, attachment, texture.handle, level, layer);
layer); glNamedFramebufferTextureLayer(draw_fbo, attachment, dst_texture.handle, level, layer);
glNamedFramebufferTextureLayer(draw_fbo.handle, attachment, dst_texture.handle, level, glBlitNamedFramebuffer(read_fbo, draw_fbo, 0, 0, src_level_width, src_level_height, 0,
layer); 0, dst_level_width, dst_level_height, mask, filter);
glBlitNamedFramebuffer(read_fbo.handle, draw_fbo.handle, 0, 0, src_level_width, glNamedFramebufferTextureLayer(read_fbo, attachment, 0, level, layer);
src_level_height, 0, 0, dst_level_width, dst_level_height, mask, glNamedFramebufferTextureLayer(draw_fbo, attachment, 0, level, layer);
filter);
} }
} }
texture = std::move(dst_texture); texture = std::move(dst_texture);
// Restore previous framebuffers
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prev_draw_fbo);
glBindFramebuffer(GL_READ_FRAMEBUFFER, prev_read_fbo);
return true; return true;
} }