From b05b5b3bd8b973846b62dfe51b84952da756232b Mon Sep 17 00:00:00 2001 From: GPUCode <47210458+GPUCode@users.noreply.github.com> Date: Fri, 14 Oct 2022 19:58:38 +0300 Subject: [PATCH] renderer_opengl: Address cubemap related errors (#6158) --- src/video_core/rasterizer_cache/rasterizer_cache.cpp | 5 +++-- src/video_core/rasterizer_cache/texture_runtime.cpp | 11 +++++++---- src/video_core/rasterizer_cache/texture_runtime.h | 3 ++- .../renderer_opengl/gl_resource_manager.cpp | 8 ++++---- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/video_core/rasterizer_cache/rasterizer_cache.cpp b/src/video_core/rasterizer_cache/rasterizer_cache.cpp index f2db5b2de..925c468a9 100644 --- a/src/video_core/rasterizer_cache/rasterizer_cache.cpp +++ b/src/video_core/rasterizer_cache/rasterizer_cache.cpp @@ -559,7 +559,8 @@ const CachedTextureCube& RasterizerCacheOpenGL::GetTextureCube(const TextureCube u32 scaled_size = cube.res_scale * config.width; - for (const Face& face : faces) { + for (std::size_t i = 0; i < faces.size(); i++) { + const Face& face = faces[i]; if (face.watcher && !face.watcher->IsValid()) { auto surface = face.watcher->Get(); if (!surface->invalid_regions.empty()) { @@ -570,7 +571,7 @@ const CachedTextureCube& RasterizerCacheOpenGL::GetTextureCube(const TextureCube const auto dst_rect = Common::Rectangle{0, scaled_size, scaled_size, 0}; const Aspect aspect = ToAspect(surface->type); runtime.BlitTextures(surface->texture, {aspect, src_rect}, cube.texture, - {aspect, dst_rect}); + {aspect, dst_rect, 0, static_cast(i)}, true); face.watcher->Validate(); } diff --git a/src/video_core/rasterizer_cache/texture_runtime.cpp b/src/video_core/rasterizer_cache/texture_runtime.cpp index ebbb6955e..f7955bb25 100644 --- a/src/video_core/rasterizer_cache/texture_runtime.cpp +++ b/src/video_core/rasterizer_cache/texture_runtime.cpp @@ -127,7 +127,8 @@ bool TextureRuntime::CopyTextures(const OGLTexture& src_tex, Subresource src_sub } bool TextureRuntime::BlitTextures(const OGLTexture& src_tex, Subresource src_subresource, - const OGLTexture& dst_tex, Subresource dst_subresource) { + const OGLTexture& dst_tex, Subresource dst_subresource, + bool dst_cube) { OpenGLState prev_state = OpenGLState::GetCurState(); SCOPE_EXIT({ prev_state.Apply(); }); @@ -136,10 +137,12 @@ bool TextureRuntime::BlitTextures(const OGLTexture& src_tex, Subresource src_sub state.draw.draw_framebuffer = draw_fbo.handle; state.Apply(); - auto BindAttachment = [src_level = src_subresource.level, dst_level = dst_subresource.level]( - GLenum target, u32 src_tex, u32 dst_tex) -> void { + auto BindAttachment = + [dst_cube, src_level = src_subresource.level, dst_level = dst_subresource.level, + dst_layer = dst_subresource.layer](GLenum target, u32 src_tex, u32 dst_tex) -> void { + GLenum dst_target = dst_cube ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + dst_layer : GL_TEXTURE_2D; glFramebufferTexture2D(GL_READ_FRAMEBUFFER, target, GL_TEXTURE_2D, src_tex, src_level); - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, target, GL_TEXTURE_2D, dst_tex, dst_level); + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, target, dst_target, dst_tex, dst_level); }; // Sanity check; Can't blit a color texture to a depth buffer diff --git a/src/video_core/rasterizer_cache/texture_runtime.h b/src/video_core/rasterizer_cache/texture_runtime.h index bad99cdc9..c97076b12 100644 --- a/src/video_core/rasterizer_cache/texture_runtime.h +++ b/src/video_core/rasterizer_cache/texture_runtime.h @@ -57,7 +57,8 @@ public: // Copies a rectangle of src_tex to another rectange of dst_rect performing // scaling and format conversions bool BlitTextures(const OGLTexture& src_tex, Subresource src_subresource, - const OGLTexture& dst_tex, Subresource dst_subresource); + const OGLTexture& dst_tex, Subresource dst_subresource, + bool dst_cube = false); // Generates mipmaps for all the available levels of the texture void GenerateMipmaps(const OGLTexture& tex, u32 max_level); diff --git a/src/video_core/renderer_opengl/gl_resource_manager.cpp b/src/video_core/renderer_opengl/gl_resource_manager.cpp index 2deeb9bc4..080922b8b 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.cpp +++ b/src/video_core/renderer_opengl/gl_resource_manager.cpp @@ -56,7 +56,7 @@ void OGLTexture::Allocate(GLenum target, GLsizei levels, GLenum internalformat, GLsizei height, GLsizei depth) { GLuint old_tex = OpenGLState::GetCurState().texture_units[0].texture_2d; glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, handle); + glBindTexture(target, handle); switch (target) { case GL_TEXTURE_1D: @@ -76,9 +76,9 @@ void OGLTexture::Allocate(GLenum target, GLsizei levels, GLenum internalformat, break; } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D, old_tex); }