Implemented caching of the shader parameter size
This commit is contained in:
parent
cde32060ec
commit
2ffe3004cd
@ -2,6 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
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
|
||||
{
|
||||
public class ExtendedShader
|
||||
|
@ -1,27 +1,92 @@
|
||||
using System;
|
||||
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
|
||||
{
|
||||
public class ExtendedShaderParameter
|
||||
{
|
||||
public string Type;
|
||||
public string Name;
|
||||
public int ArraySize;
|
||||
public int[] TypeDimensions;
|
||||
{
|
||||
#region Public
|
||||
public string Type
|
||||
{
|
||||
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();
|
||||
Name = reader.ReadString();
|
||||
ArraySize = reader.ReadInt32();
|
||||
|
||||
IsTexture = Type.ToLower().Contains("texture");
|
||||
SizeInBytes = GetParameterTypeSize() * ArraySize;
|
||||
|
||||
int numberOfDimensions = reader.ReadByte();
|
||||
TypeDimensions = new int[numberOfDimensions];
|
||||
for (int dimIndex = 0; dimIndex < numberOfDimensions; dimIndex++)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
using System;
|
||||
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
|
||||
{
|
||||
public class ExtendedShaderPass
|
||||
|
@ -191,17 +191,10 @@ namespace ANX.RenderSystem.Windows.Metro.Shader
|
||||
else
|
||||
{
|
||||
var parameter = parentEffect.shader.Parameters[index];
|
||||
if (parameter.Type.ToLower().Contains("texture"))
|
||||
if (parameter.IsTexture)
|
||||
continue;
|
||||
|
||||
int size = GetParameterTypeSize(parameter.Type);
|
||||
foreach (int dimension in parameter.TypeDimensions)
|
||||
{
|
||||
size *= dimension;
|
||||
}
|
||||
|
||||
size *= parameter.ArraySize;
|
||||
writer.Write(new byte[size]);
|
||||
writer.Write(new byte[parameter.SizeInBytes]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,23 +217,6 @@ namespace ANX.RenderSystem.Windows.Metro.Shader
|
||||
}
|
||||
#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
|
||||
public void Dispose()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user