Skip to content

Commit

Permalink
Fix potential crash on old drivers or incorrect format returned by Op…
Browse files Browse the repository at this point in the history
…enGL "get_resource_view_format"
  • Loading branch information
crosire committed Aug 27, 2022
1 parent 09bd9cd commit 9a0e2f6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions source/opengl/opengl_impl_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ reshade::api::format reshade::opengl::device_impl::get_resource_view_format(api:
if (_supports_dsa)
{
gl.GetTextureLevelParameteriv(object, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_format);
gl.GetTextureParameteriv(object, GL_TEXTURE_SWIZZLE_RGBA, swizzle_mask);
}
else
{
Expand All @@ -1010,8 +1011,7 @@ reshade::api::format reshade::opengl::device_impl::get_resource_view_format(api:
level_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X;

gl.GetTexLevelParameteriv(level_target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_format);

gl.GetTextureParameteriv(object, GL_TEXTURE_SWIZZLE_RGBA, swizzle_mask);
gl.GetTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle_mask);

gl.BindTexture(target, prev_binding);
}
Expand All @@ -1035,6 +1035,9 @@ reshade::api::format reshade::opengl::device_impl::get_resource_view_format(api:
case GL_FRAMEBUFFER_DEFAULT:
internal_format = (object == GL_DEPTH_STENCIL_ATTACHMENT || object == GL_DEPTH_ATTACHMENT || object == GL_STENCIL_ATTACHMENT) ? _default_depth_format : _default_color_format;
break;
default:
assert(false);
break;
}

return convert_format(internal_format, swizzle_mask);
Expand Down

0 comments on commit 9a0e2f6

Please sign in to comment.