浏览代码

add enum support to hlsl generator

/main
vlad-andreev 8 年前
当前提交
32b466e2
共有 2 个文件被更改,包括 60 次插入38 次删除
  1. 12
      Assets/ShaderGenerator/CSharpToHLSL.cs
  2. 86
      Assets/ShaderGenerator/ShaderTypeGeneration.cs

12
Assets/ShaderGenerator/CSharpToHLSL.cs


foreach (var assembly in assemblyList)
{
Type[] types = assembly.GetExportedTypes();
foreach (var type in types)
{
object[] attributes = type.GetCustomAttributes(true);

}
if (!skipFile)
{
{
using (System.IO.StreamWriter writer = File.CreateText(fileName))
{
writer.Write("//\n");

writer.Write(gen.EmitAccessors() + "\n");
}
}
writer.Write("\n");
}
}

}
return name;
}
public Stack<string> currentNamespaces;
public Stack<string> currentClasses;
public List<ShaderTypeGenerator> generators;

public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
// Structured types only
if (typeDeclaration.Type == ClassType.Class || typeDeclaration.Type == ClassType.Struct)
if (typeDeclaration.Type == ClassType.Class || typeDeclaration.Type == ClassType.Struct || typeDeclaration.Type == ClassType.Enum)
ShaderTypeGenerator gen;
if (visitorData.m_typeName.TryGetValue(name, out gen))
{

86
Assets/ShaderGenerator/ShaderTypeGeneration.cs


Aggressive
};
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Enum)]
public bool simple;
public int debugCounterStart;
public GenerateHLSL(PackingRules rules = PackingRules.Exact, bool simple = false, int debugCounterStart = 1)
public bool simple;
public int debugCounterStart;
public GenerateHLSL(PackingRules rules = PackingRules.Exact, bool simple = false, int debugCounterStart = 1)
this.simple = simple;
this.debugCounterStart = debugCounterStart;
}
this.simple = simple;
this.debugCounterStart = debugCounterStart;
}
[AttributeUsage(AttributeTargets.Field)]
public class SurfaceDataAttributes : System.Attribute
{
public string displayName;
public SurfaceDataAttributes(string displayName = "")
{
this.displayName = displayName;
}
}
[AttributeUsage(AttributeTargets.Field)]
public class SurfaceDataAttributes : System.Attribute
{
public string displayName;
public SurfaceDataAttributes(string displayName = "")
{
this.displayName = displayName;
}
}
internal class ShaderTypeGenerator
internal class ShaderTypeGenerator
debugCounter = 0;
}
debugCounter = 0;
}
enum PrimitiveType
{

// merge accessors
Accessor acc = current.accessor;
acc.name = current.name;
e.Current.accessor = acc;
e.Current.swizzleOffset += offset;

FieldInfo[] fields = type.GetFields();
shaderFields = new List<ShaderFieldInfo>();
if (type.IsEnum)
{
foreach (var field in fields)
{
if (!field.IsSpecialName)
{
string name = field.Name;
for (int i = 1; i < name.Length; i++)
{
if (char.IsLower(name[i-1]) && char.IsUpper(name[i]))
{
// case switch, insert underscore
name = name.Insert(i, "_");
}
}
statics[(type.Name + "_" + name).ToUpper()] = field.GetRawConstantValue().ToString();
}
}
errors = null;
return true;
}
foreach (var field in fields)
{

continue;
}
if (attr.simple)
{
string subNamespace = type.Namespace.Substring(type.Namespace.LastIndexOf((".")) + 1);
statics["DEBUGVIEW_" + subNamespace.ToUpper() + "_" + type.Name.ToUpper() + "_" + field.Name.ToUpper()] = Convert.ToString(attr.debugCounterStart + debugCounter++);
}
if (attr.simple)
{
string subNamespace = type.Namespace.Substring(type.Namespace.LastIndexOf((".")) + 1);
statics["DEBUGVIEW_" + subNamespace.ToUpper() + "_" + type.Name.ToUpper() + "_" + field.Name.ToUpper()] = Convert.ToString(attr.debugCounterStart + debugCounter++);
}
if (field.FieldType.IsPrimitive)
{

else if (field.FieldType == typeof(Vector4))
EmitPrimitiveType(PrimitiveType.Float, 4, field.Name, "", shaderFields);
else if (field.FieldType == typeof(Matrix4x4))
EmitMatrixType(PrimitiveType.Float, 4, 4, field.Name, "", shaderFields);
else if (!ExtractComplex(field, shaderFields))
EmitMatrixType(PrimitiveType.Float, 4, 4, field.Name, "", shaderFields);
else if (!ExtractComplex(field, shaderFields))
{
// Error reporting done in ExtractComplex()
return false;

get { return statics.Count > 0; }
}
public bool IsSimple()
{
return attr.simple;
}
public bool IsSimple()
{
return attr.simple;
}
public int debugCounter;
public int debugCounter;
public List<string> errors = null;
Dictionary<string, string> statics;

正在加载...
取消
保存