mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 20:43:09 +00:00
More fixes
Limit the texture renderer to prevent memory issues. Prevent textures to be loaded and bound if gl textures cannot load. Fix gen bntx types (PC) from having inaccuate target set.
This commit is contained in:
parent
2719136c66
commit
33456d0295
5 changed files with 63 additions and 35 deletions
|
@ -1601,6 +1601,12 @@ namespace FirstPlugin
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||||
{
|
{
|
||||||
int target = 1;
|
int target = 1;
|
||||||
|
if (Parent != null && Parent is BNTX)
|
||||||
|
{
|
||||||
|
bool IsNX = ((BNTX)Parent).BinaryTexFile.PlatformTarget == "NX ";
|
||||||
|
if (!IsNX)
|
||||||
|
target = 0;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -514,8 +514,6 @@ namespace FirstPlugin
|
||||||
|
|
||||||
private static void SetTextureUniforms(FMAT mat, FSHP m, SF.Shader shader)
|
private static void SetTextureUniforms(FMAT mat, FSHP m, SF.Shader shader)
|
||||||
{
|
{
|
||||||
SetDefaultTextureAttributes(mat, shader);
|
|
||||||
|
|
||||||
GL.ActiveTexture(TextureUnit.Texture0 + 1);
|
GL.ActiveTexture(TextureUnit.Texture0 + 1);
|
||||||
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID);
|
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID);
|
||||||
|
|
||||||
|
@ -549,34 +547,36 @@ namespace FirstPlugin
|
||||||
MatTexture matex = (MatTexture)mat.TextureMaps[t];
|
MatTexture matex = (MatTexture)mat.TextureMaps[t];
|
||||||
|
|
||||||
if (matex.Type == MatTexture.TextureType.Diffuse)
|
if (matex.Type == MatTexture.TextureType.Diffuse)
|
||||||
TextureUniform(shader, mat, mat.HasDiffuseMap, "DiffuseMap", matex);
|
mat.HasDiffuseMap = TextureUniform(shader, mat, "DiffuseMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.Normal)
|
else if (matex.Type == MatTexture.TextureType.Normal)
|
||||||
TextureUniform(shader, mat, mat.HasNormalMap, "NormalMap", matex);
|
mat.HasNormalMap = TextureUniform(shader, mat, "NormalMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.Emission)
|
else if (matex.Type == MatTexture.TextureType.Emission)
|
||||||
TextureUniform(shader, mat, mat.HasEmissionMap, "EmissionMap", matex);
|
mat.HasEmissionMap = TextureUniform(shader, mat, "EmissionMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.Specular)
|
else if (matex.Type == MatTexture.TextureType.Specular)
|
||||||
TextureUniform(shader, mat, mat.HasSpecularMap, "SpecularMap", matex);
|
mat.HasSpecularMap = TextureUniform(shader, mat, "SpecularMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.Shadow)
|
else if (matex.Type == MatTexture.TextureType.Shadow)
|
||||||
TextureUniform(shader, mat, mat.HasShadowMap, "BakeShadowMap", matex);
|
mat.HasShadowMap = TextureUniform(shader, mat, "BakeShadowMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.Light)
|
else if (matex.Type == MatTexture.TextureType.Light)
|
||||||
TextureUniform(shader, mat, mat.HasLightMap, "BakeLightMap", matex);
|
mat.HasLightMap = TextureUniform(shader, mat, "BakeLightMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.Metalness)
|
else if (matex.Type == MatTexture.TextureType.Metalness)
|
||||||
TextureUniform(shader, mat, mat.HasMetalnessMap, "MetalnessMap", matex);
|
mat.HasMetalnessMap = TextureUniform(shader, mat, "MetalnessMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.Roughness)
|
else if (matex.Type == MatTexture.TextureType.Roughness)
|
||||||
TextureUniform(shader, mat, mat.HasRoughnessMap, "RoughnessMap", matex);
|
mat.HasRoughnessMap = TextureUniform(shader, mat, "RoughnessMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.TeamColor)
|
else if (matex.Type == MatTexture.TextureType.TeamColor)
|
||||||
TextureUniform(shader, mat, mat.HasTeamColorMap, "TeamColorMap", matex);
|
mat.HasTeamColorMap = TextureUniform(shader, mat, "TeamColorMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.Transparency)
|
else if (matex.Type == MatTexture.TextureType.Transparency)
|
||||||
TextureUniform(shader, mat, mat.HasTransparencyMap, "TransparencyMap", matex);
|
mat.HasTransparencyMap = TextureUniform(shader, mat, "TransparencyMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.DiffuseLayer2)
|
else if (matex.Type == MatTexture.TextureType.DiffuseLayer2)
|
||||||
TextureUniform(shader, mat, mat.HasDiffuseLayer, "DiffuseLayer", matex);
|
mat.HasDiffuseLayer = TextureUniform(shader, mat, "DiffuseLayer", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.SphereMap)
|
else if (matex.Type == MatTexture.TextureType.SphereMap)
|
||||||
TextureUniform(shader, mat, mat.HasSphereMap, "SphereMap", matex);
|
mat.HasSphereMap = mat.HasSphereMap = TextureUniform(shader, mat, "SphereMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.SubSurfaceScattering)
|
else if (matex.Type == MatTexture.TextureType.SubSurfaceScattering)
|
||||||
TextureUniform(shader, mat, mat.HasSubSurfaceScatteringMap, "SubSurfaceScatteringMap", matex);
|
mat.HasSubSurfaceScatteringMap = TextureUniform(shader, mat, "SubSurfaceScatteringMap", matex);
|
||||||
else if (matex.Type == MatTexture.TextureType.MRA)
|
else if (matex.Type == MatTexture.TextureType.MRA)
|
||||||
TextureUniform(shader, mat, mat.HasMRA, "MRA", matex);
|
mat.HasMRA = TextureUniform(shader, mat, "MRA", matex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetDefaultTextureAttributes(mat, shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LoadPBRMaps(SF.Shader shader)
|
private static void LoadPBRMaps(SF.Shader shader)
|
||||||
|
@ -597,18 +597,23 @@ namespace FirstPlugin
|
||||||
GL.Uniform1(shader.GetUniformLocation("brdfLUT"), 27);
|
GL.Uniform1(shader.GetUniformLocation("brdfLUT"), 27);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TextureUniform(SF.Shader shader, FMAT mat, bool hasTex, string name, MatTexture mattex)
|
private static bool TextureUniform(SF.Shader shader, FMAT mat, string name, MatTexture mattex)
|
||||||
{
|
{
|
||||||
if (mattex.textureState == STGenericMatTexture.TextureState.Binded)
|
if (mattex.textureState == STGenericMatTexture.TextureState.Binded)
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
// Bind the texture and create the uniform if the material has the right textures.
|
// Bind the texture and create the uniform if the material has the right textures.
|
||||||
if (hasTex)
|
bool IsBound = BindTexture(mattex, mat, shader, mat.GetResFileU() != null);
|
||||||
{
|
int texId = mattex.textureUnit + 1;
|
||||||
GL.Uniform1(shader.GetUniformLocation(name), BindTexture(mattex, mat, shader, mat.GetResFileU() != null));
|
|
||||||
}
|
if (IsBound)
|
||||||
|
GL.Uniform1(shader.GetUniformLocation(name), texId);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
public static int BindTexture(MatTexture tex, FMAT material, SF.Shader shader, bool IsWiiU)
|
public static bool BindTexture(MatTexture tex, FMAT material, SF.Shader shader, bool IsWiiU)
|
||||||
{
|
{
|
||||||
BFRES bfres = (BFRES)material.Parent.Parent.Parent.Parent;
|
BFRES bfres = (BFRES)material.Parent.Parent.Parent.Parent;
|
||||||
|
|
||||||
|
@ -628,8 +633,7 @@ namespace FirstPlugin
|
||||||
{
|
{
|
||||||
if (ftexCont.ResourceNodes.ContainsKey(activeTex))
|
if (ftexCont.ResourceNodes.ContainsKey(activeTex))
|
||||||
{
|
{
|
||||||
BindFTEX(ftexCont, tex, shader, activeTex);
|
return BindFTEX(ftexCont, tex, shader, activeTex);
|
||||||
return tex.textureUnit + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -638,8 +642,7 @@ namespace FirstPlugin
|
||||||
{
|
{
|
||||||
if (ftexContainer.ResourceNodes.ContainsKey(activeTex))
|
if (ftexContainer.ResourceNodes.ContainsKey(activeTex))
|
||||||
{
|
{
|
||||||
BindFTEX(ftexContainer, tex, shader, activeTex);
|
return BindFTEX(ftexContainer, tex, shader, activeTex);
|
||||||
return tex.textureUnit + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -652,8 +655,7 @@ namespace FirstPlugin
|
||||||
{
|
{
|
||||||
if (bntx.Textures.ContainsKey(activeTex))
|
if (bntx.Textures.ContainsKey(activeTex))
|
||||||
{
|
{
|
||||||
BindBNTX(bntx, tex, shader, activeTex);
|
return BindBNTX(bntx, tex, shader, activeTex);
|
||||||
return tex.textureUnit + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -662,15 +664,15 @@ namespace FirstPlugin
|
||||||
{
|
{
|
||||||
if (bntx.Textures.ContainsKey(activeTex))
|
if (bntx.Textures.ContainsKey(activeTex))
|
||||||
{
|
{
|
||||||
BindBNTX(bntx, tex, shader, activeTex);
|
return BindBNTX(bntx, tex, shader, activeTex);
|
||||||
return tex.textureUnit + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tex.textureUnit + 1;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BindFTEX(BFRESGroupNode ftexContainer, MatTexture tex, SF.Shader shader, string activeTex)
|
private static bool BindFTEX(BFRESGroupNode ftexContainer, MatTexture tex, SF.Shader shader, string activeTex)
|
||||||
{
|
{
|
||||||
FTEX ftex = (FTEX)ftexContainer.ResourceNodes[activeTex];
|
FTEX ftex = (FTEX)ftexContainer.ResourceNodes[activeTex];
|
||||||
|
|
||||||
|
@ -678,9 +680,11 @@ namespace FirstPlugin
|
||||||
ftex.LoadOpenGLTexture();
|
ftex.LoadOpenGLTexture();
|
||||||
|
|
||||||
BindGLTexture(tex, shader, ftex);
|
BindGLTexture(tex, shader, ftex);
|
||||||
|
|
||||||
|
return ftex.RenderableTex.GLInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BindBNTX(BNTX bntx, MatTexture tex, SF.Shader shader, string activeTex)
|
private static bool BindBNTX(BNTX bntx, MatTexture tex, SF.Shader shader, string activeTex)
|
||||||
{
|
{
|
||||||
if (bntx.Textures[activeTex].RenderableTex == null ||
|
if (bntx.Textures[activeTex].RenderableTex == null ||
|
||||||
!bntx.Textures[activeTex].RenderableTex.GLInitialized)
|
!bntx.Textures[activeTex].RenderableTex.GLInitialized)
|
||||||
|
@ -689,10 +693,16 @@ namespace FirstPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
BindGLTexture(tex, shader, bntx.Textures[activeTex]);
|
BindGLTexture(tex, shader, bntx.Textures[activeTex]);
|
||||||
|
|
||||||
|
return bntx.Textures[activeTex].RenderableTex.GLInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BindGLTexture(MatTexture tex, SF.Shader shader, STGenericTexture texture)
|
private static void BindGLTexture(MatTexture tex, SF.Shader shader, STGenericTexture texture)
|
||||||
{
|
{
|
||||||
|
//If the texture is still not initialized then return
|
||||||
|
if (!texture.RenderableTex.GLInitialized)
|
||||||
|
return;
|
||||||
|
|
||||||
if (tex.Type == STGenericMatTexture.TextureType.Diffuse)
|
if (tex.Type == STGenericMatTexture.TextureType.Diffuse)
|
||||||
{
|
{
|
||||||
shader.SetInt("RedChannel", (int)texture.RedChannel);
|
shader.SetInt("RedChannel", (int)texture.RedChannel);
|
||||||
|
|
|
@ -15,6 +15,8 @@ namespace Toolbox.Library
|
||||||
public float B { get; set; }
|
public float B { get; set; }
|
||||||
public float A { get; set; }
|
public float A { get; set; }
|
||||||
|
|
||||||
|
public float Time { get; set; }
|
||||||
|
|
||||||
public Color Color
|
public Color Color
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
@ -96,6 +96,13 @@ namespace Toolbox.Library.Rendering
|
||||||
|
|
||||||
width = (int)GenericTexture.Width;
|
width = (int)GenericTexture.Width;
|
||||||
height = (int)GenericTexture.Height;
|
height = (int)GenericTexture.Height;
|
||||||
|
|
||||||
|
if (Runtime.DisableLoadingGLHighResTextures)
|
||||||
|
{
|
||||||
|
if (width >= 3000 || height >= 3000)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (GenericTexture.ArrayCount == 0)
|
if (GenericTexture.ArrayCount == 0)
|
||||||
GenericTexture.ArrayCount = 1;
|
GenericTexture.ArrayCount = 1;
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@ namespace Toolbox.Library
|
||||||
|
|
||||||
public class Runtime
|
public class Runtime
|
||||||
{
|
{
|
||||||
|
//Disable loading 3k and higher texture res to prevent slowdown and memory issues
|
||||||
|
public static bool DisableLoadingGLHighResTextures = true;
|
||||||
|
|
||||||
public static bool UseSingleInstance = true;
|
public static bool UseSingleInstance = true;
|
||||||
public static bool UseDirectXTexDecoder = true;
|
public static bool UseDirectXTexDecoder = true;
|
||||||
public static bool DEVELOPER_DEBUG_MODE = false;
|
public static bool DEVELOPER_DEBUG_MODE = false;
|
||||||
|
|
Loading…
Reference in a new issue