renderer_opengl: Address cubemap related errors (#6158)

This commit is contained in:
GPUCode 2022-10-14 19:58:38 +03:00 committed by GitHub
parent 1759e2afc2
commit b05b5b3bd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 11 deletions

View File

@ -559,7 +559,8 @@ const CachedTextureCube& RasterizerCacheOpenGL::GetTextureCube(const TextureCube
u32 scaled_size = cube.res_scale * config.width; 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()) { if (face.watcher && !face.watcher->IsValid()) {
auto surface = face.watcher->Get(); auto surface = face.watcher->Get();
if (!surface->invalid_regions.empty()) { if (!surface->invalid_regions.empty()) {
@ -570,7 +571,7 @@ const CachedTextureCube& RasterizerCacheOpenGL::GetTextureCube(const TextureCube
const auto dst_rect = Common::Rectangle<u32>{0, scaled_size, scaled_size, 0}; const auto dst_rect = Common::Rectangle<u32>{0, scaled_size, scaled_size, 0};
const Aspect aspect = ToAspect(surface->type); const Aspect aspect = ToAspect(surface->type);
runtime.BlitTextures(surface->texture, {aspect, src_rect}, cube.texture, runtime.BlitTextures(surface->texture, {aspect, src_rect}, cube.texture,
{aspect, dst_rect}); {aspect, dst_rect, 0, static_cast<u32>(i)}, true);
face.watcher->Validate(); face.watcher->Validate();
} }

View File

@ -127,7 +127,8 @@ bool TextureRuntime::CopyTextures(const OGLTexture& src_tex, Subresource src_sub
} }
bool TextureRuntime::BlitTextures(const OGLTexture& src_tex, Subresource src_subresource, 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(); OpenGLState prev_state = OpenGLState::GetCurState();
SCOPE_EXIT({ prev_state.Apply(); }); 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.draw.draw_framebuffer = draw_fbo.handle;
state.Apply(); state.Apply();
auto BindAttachment = [src_level = src_subresource.level, dst_level = dst_subresource.level]( auto BindAttachment =
GLenum target, u32 src_tex, u32 dst_tex) -> void { [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_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 // Sanity check; Can't blit a color texture to a depth buffer

View File

@ -57,7 +57,8 @@ public:
// Copies a rectangle of src_tex to another rectange of dst_rect performing // Copies a rectangle of src_tex to another rectange of dst_rect performing
// scaling and format conversions // scaling and format conversions
bool BlitTextures(const OGLTexture& src_tex, Subresource src_subresource, 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 // Generates mipmaps for all the available levels of the texture
void GenerateMipmaps(const OGLTexture& tex, u32 max_level); void GenerateMipmaps(const OGLTexture& tex, u32 max_level);

View File

@ -56,7 +56,7 @@ void OGLTexture::Allocate(GLenum target, GLsizei levels, GLenum internalformat,
GLsizei height, GLsizei depth) { GLsizei height, GLsizei depth) {
GLuint old_tex = OpenGLState::GetCurState().texture_units[0].texture_2d; GLuint old_tex = OpenGLState::GetCurState().texture_units[0].texture_2d;
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, handle); glBindTexture(target, handle);
switch (target) { switch (target) {
case GL_TEXTURE_1D: case GL_TEXTURE_1D:
@ -76,9 +76,9 @@ void OGLTexture::Allocate(GLenum target, GLsizei levels, GLenum internalformat,
break; break;
} }
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, old_tex); glBindTexture(GL_TEXTURE_2D, old_tex);
} }