Implemented caching of the shader parameter size

This commit is contained in:
SND\AstrorEnales_cp 2012-08-19 17:34:27 +00:00
parent cde32060ec
commit 2ffe3004cd
4 changed files with 82 additions and 33 deletions

View File

@ -2,6 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.RenderSystem.Windows.Metro.Shader namespace ANX.RenderSystem.Windows.Metro.Shader
{ {
public class ExtendedShader public class ExtendedShader

View File

@ -1,27 +1,92 @@
using System; using System;
using System.IO; using System.IO;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.RenderSystem.Windows.Metro.Shader namespace ANX.RenderSystem.Windows.Metro.Shader
{ {
public class ExtendedShaderParameter public class ExtendedShaderParameter
{ {
public string Type; #region Public
public string Name; public string Type
public int ArraySize; {
public int[] TypeDimensions; get;
private set;
}
public ExtendedShaderParameter(BinaryReader reader) public string Name
{
get;
private set;
}
public int ArraySize
{
get;
private set;
}
public int[] TypeDimensions
{
get;
private set;
}
public int SizeInBytes
{
get;
private set;
}
public bool IsTexture
{
get;
private set;
}
#endregion
#region Constructor
public ExtendedShaderParameter(BinaryReader reader)
{ {
Type = reader.ReadString(); Type = reader.ReadString();
Name = reader.ReadString(); Name = reader.ReadString();
ArraySize = reader.ReadInt32(); ArraySize = reader.ReadInt32();
IsTexture = Type.ToLower().Contains("texture");
SizeInBytes = GetParameterTypeSize() * ArraySize;
int numberOfDimensions = reader.ReadByte(); int numberOfDimensions = reader.ReadByte();
TypeDimensions = new int[numberOfDimensions]; TypeDimensions = new int[numberOfDimensions];
for (int dimIndex = 0; dimIndex < numberOfDimensions; dimIndex++) for (int dimIndex = 0; dimIndex < numberOfDimensions; dimIndex++)
{ {
TypeDimensions[dimIndex] = (int)reader.ReadByte(); TypeDimensions[dimIndex] = (int)reader.ReadByte();
SizeInBytes *= TypeDimensions[dimIndex];
} }
} }
} #endregion
#region GetParameterTypeSize
private int GetParameterTypeSize()
{
if (IsTexture)
return 0;
if (Type == "float" ||
Type == "int" ||
Type == "uint" ||
Type == "dword")
return 4;
if (Type == "double")
return 8;
if (Type == "bool")
return 1;
if (Type == "half")
return 2;
throw new NotImplementedException("Parameter type " + Type + " has no size value!");
}
#endregion
}
} }

View File

@ -1,6 +1,10 @@
using System; using System;
using System.IO; using System.IO;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.RenderSystem.Windows.Metro.Shader namespace ANX.RenderSystem.Windows.Metro.Shader
{ {
public class ExtendedShaderPass public class ExtendedShaderPass

View File

@ -191,17 +191,10 @@ namespace ANX.RenderSystem.Windows.Metro.Shader
else else
{ {
var parameter = parentEffect.shader.Parameters[index]; var parameter = parentEffect.shader.Parameters[index];
if (parameter.Type.ToLower().Contains("texture")) if (parameter.IsTexture)
continue; continue;
int size = GetParameterTypeSize(parameter.Type); writer.Write(new byte[parameter.SizeInBytes]);
foreach (int dimension in parameter.TypeDimensions)
{
size *= dimension;
}
size *= parameter.ArraySize;
writer.Write(new byte[size]);
} }
} }
@ -224,23 +217,6 @@ namespace ANX.RenderSystem.Windows.Metro.Shader
} }
#endregion #endregion
private int GetParameterTypeSize(string type)
{
if (type == "float" ||
type == "int" ||
type == "uint" ||
type == "dword")
return 4;
if (type == "double")
return 8;
if (type == "bool")
return 1;
if (type == "half")
return 2;
throw new NotImplementedException("Parameter type " + type + " has no size value!");
}
#region Dispose #region Dispose
public void Dispose() public void Dispose()
{ {