mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-14 02:14:35 +00:00
PostProcessing/slang: Flip textures if using OpenGL
Fixes them being sampled upside down.
This commit is contained in:
@@ -1472,13 +1472,37 @@ bool PostProcessing::SlangShader::UploadLUTTextures(Error* error)
|
||||
Assert(!tex.needs_feedback);
|
||||
|
||||
Image image;
|
||||
if (!image.LoadFromFile(tex.path.c_str(), error) ||
|
||||
!(tex.texture = g_gpu_device->FetchAndUploadTextureImage(image, GPUTexture::Flags::None, error)))
|
||||
if (!image.LoadFromFile(tex.path.c_str(), error))
|
||||
{
|
||||
Error::AddPrefixFmt(error, "Failed to load LUT texture from file '{}': ", Path::GetFileName(tex.path));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Flip textures in GL so the texture coordinates match what we're rendering in screen space.
|
||||
if (g_gpu_device->UsesLowerLeftOrigin())
|
||||
{
|
||||
// Have to decompress if compressed.
|
||||
if (Image::IsCompressedFormat(image.GetFormat()))
|
||||
{
|
||||
std::optional<Image> decompressed = image.ConvertToRGBA8(error);
|
||||
if (!decompressed.has_value())
|
||||
{
|
||||
Error::AddPrefixFmt(error, "Failed to decompress LUT texture from file '{}': ", Path::GetFileName(tex.path));
|
||||
return false;
|
||||
}
|
||||
|
||||
image = std::move(decompressed.value());
|
||||
}
|
||||
|
||||
image.FlipY();
|
||||
}
|
||||
|
||||
if (!(tex.texture = g_gpu_device->FetchAndUploadTextureImage(image, GPUTexture::Flags::None, error)))
|
||||
{
|
||||
Error::AddPrefixFmt(error, "Failed to upload LUT texture from file '{}': ", Path::GetFileName(tex.path));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use clamp to border for LUTs by default.
|
||||
GPUSampler::Config sampler_config =
|
||||
tex.linear_filter ? GPUSampler::GetLinearConfig() : GPUSampler::GetNearestConfig();
|
||||
|
||||
Reference in New Issue
Block a user