1
0
mirror of synced 2024-11-30 18:24:39 +01:00

Prevent failed images from loading in opengl

This commit is contained in:
KillzXGaming 2019-11-05 17:32:39 -05:00
parent 367e9a1287
commit 28e0edb8ad
2 changed files with 33 additions and 22 deletions

View File

@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Gal.Texture
{
public class ASTCDecoderException : Exception
{
public ASTCDecoderException(string ExMsg) : base(ExMsg) { Toolbox.Library.Forms.STErrorDialog.Show(ExMsg, "", ExMsg); }
public ASTCDecoderException(string ExMsg) : base(ExMsg) {/* Toolbox.Library.Forms.STErrorDialog.Show(ExMsg, "", ExMsg);*/ }
}
//https://github.com/GammaUNC/FasTC/blob/master/ASTCEncoder/src/Decompressor.cpp
@ -67,12 +67,12 @@ namespace Ryujinx.Graphics.Gal.Texture
if (BlockX > 12 || BlockY > 12)
{
throw new ASTCDecoderException("Block size unsupported!");
throw new Exception("Block size unsupported!");
}
if (BlockZ != 1 || Z != 1)
{
throw new ASTCDecoderException("3D compressed textures unsupported!");
throw new Exception("3D compressed textures unsupported!");
}
using (MemoryStream OutputStream = new MemoryStream())
@ -121,7 +121,7 @@ namespace Ryujinx.Graphics.Gal.Texture
if (TexelParams.Error)
{
throw new ASTCDecoderException("Invalid block mode");
throw new Exception("Invalid block mode");
}
// Console.WriteLine($"BlockWidth {BlockWidth} {BlockHeight} BlockHeight");
@ -136,17 +136,17 @@ namespace Ryujinx.Graphics.Gal.Texture
if (TexelParams.VoidExtentHDR)
{
throw new ASTCDecoderException("HDR void extent blocks are unsupported!");
throw new Exception("HDR void extent blocks are unsupported!");
}
if (TexelParams.Width > BlockWidth)
{
throw new ASTCDecoderException("Texel weight grid width should be smaller than block width");
throw new Exception("Texel weight grid width should be smaller than block width");
}
if (TexelParams.Height > BlockHeight)
{
throw new ASTCDecoderException("Texel weight grid height should be smaller than block height");
throw new Exception("Texel weight grid height should be smaller than block height");
}
// Read num partitions
@ -155,7 +155,7 @@ namespace Ryujinx.Graphics.Gal.Texture
if (NumberPartitions == 4 && TexelParams.DualPlane)
{
throw new ASTCDecoderException("Dual plane mode is incompatible with four partition blocks");
throw new Exception("Dual plane mode is incompatible with four partition blocks");
}
// Based on the number of partitions, read the color endpoint mode for

View File

@ -114,11 +114,12 @@ namespace Toolbox.Library.Rendering
TexID = GenerateOpenGLTexture(this, bitmap);
}
private bool IsFailedState = false;
private bool UseMipmaps = false;
private bool UseOpenGLDecoder = true;
public void LoadOpenGLTexture(STGenericTexture GenericTexture, int ArrayStartIndex = 0, bool LoadArrayLevels = false)
{
if (!Runtime.OpenTKInitialized || GLInitialized || Runtime.UseLegacyGL)
if (!Runtime.OpenTKInitialized || GLInitialized || Runtime.UseLegacyGL || IsFailedState)
return;
width = (int)GenericTexture.Width;
@ -162,25 +163,27 @@ namespace Toolbox.Library.Rendering
GenericTexture.ArrayCount = 1;
List<STGenericTexture.Surface> Surfaces = new List<STGenericTexture.Surface>();
if (UseMipmaps && GenericTexture.ArrayCount <= 1)
try
{
//Load surfaces with mip maps
Surfaces = GenericTexture.GetSurfaces(ArrayStartIndex, false, 6);
}
else
{
//Only load first mip level. Will be generated after
for (int i = 0; i < GenericTexture.ArrayCount; i++)
if (UseMipmaps && GenericTexture.ArrayCount <= 1)
{
if (i >= ArrayStartIndex && i <= ArrayStartIndex + 6) //Only load up to 6 faces
//Load surfaces with mip maps
Surfaces = GenericTexture.GetSurfaces(ArrayStartIndex, false, 6);
}
else
{
//Only load first mip level. Will be generated after
for (int i = 0; i < GenericTexture.ArrayCount; i++)
{
Surfaces.Add(new STGenericTexture.Surface()
if (i >= ArrayStartIndex && i <= ArrayStartIndex + 6) //Only load up to 6 faces
{
mipmaps = new List<byte[]>() { GenericTexture.GetImageData(i, 0) }
});
Surfaces.Add(new STGenericTexture.Surface()
{
mipmaps = new List<byte[]>() { GenericTexture.GetImageData(i, 0) }
});
}
}
}
}
if (Surfaces.Count == 0 || Surfaces[0].mipmaps[0].Length == 0)
return;
@ -238,6 +241,14 @@ namespace Toolbox.Library.Rendering
}
Surfaces.Clear();
}
catch
{
IsFailedState = true;
GLInitialized = false;
return;
}
}
static bool IsPow2(int Value)