public AddVDataArguments(OpsParsedStatement statement) { OpsParsedArgument typeArg = statement.FindArgument("type"); if (typeArg == null) { typeArg = statement.FindArgument(""); if (typeArg == null) { throw new OpsException("'type' argument argument"); } } type = MeshDeclarationHelper.DecodeType(typeArg.Value); OpsParsedArgument usageArg = statement.FindArgument("usage"); if (usageArg != null) { usage = MeshDeclarationHelper.DecodeUsage(usageArg.Value); } OpsParsedArgument usageIdxArg = statement.FindArgument("usageIdx"); if (usageIdxArg != null) { usageIdx = int.Parse(usageIdxArg.Value); } }
public StreamDataType(short id, int numValues, int dataSize, DeclarationType declarationType, DeclarationUsage declarationUsage, byte usageIndex) { this.Id = id; this.NumValues = numValues; this.DataSize = dataSize; this.DeclarationType = declarationType; this.DeclarationUsage = declarationUsage; this.UsageIndex = usageIndex; }
/// <summary> /// Initializes a new instance of the <see cref="VertexElement"/> struct. /// </summary> /// <param name="stream">The stream.</param> /// <param name="offset">The offset.</param> /// <param name="type">The type.</param> /// <param name="method">The method.</param> /// <param name="usage">The usage.</param> /// <param name="usageIndex">Index of the usage.</param> public VertexElement(short stream, short offset, DeclarationType type, DeclarationMethod method, DeclarationUsage usage, byte usageIndex = 0) { Stream = stream; Offset = offset; Type = type; Method = method; Usage = usage; UsageIndex = usageIndex; }
/// <summary> /// Initializes a new instance of the <see cref="VertexElement"/> struct. /// </summary> /// <param name="stream">The stream.</param> /// <param name="offset">The offset.</param> /// <param name="type">The type.</param> /// <param name="method">The method.</param> /// <param name="usage">The usage.</param> /// <param name="usageIndex">Index of the usage.</param> public VertexElement(short stream, short offset, DeclarationType type, DeclarationMethod method, DeclarationUsage usage, byte usageIndex) { Stream = stream; Offset = offset; Type = type; Method = method; Usage = usage; UsageIndex = usageIndex; }
/// <summary> /// VertexElement - Defines input vertex data to the pipeline /// </summary> /// <param name="stream">Stream number</param> /// <param name="offset">Offset (if any) from the beginning of the stream to the start of the data</param> /// <param name="declarationType">One of several predefined types that define the data size</param> /// <param name="declarationMethod">Tessellator processing method. This method determines how the tessellator interprets/operates on the vertex data</param> /// <param name="declarationUsage">Defines the intended use of the data</param> /// <param name="usageIndex">Modifies the usage data to allow the user to specify multiple usage types</param> public VertexElement(short stream, short offset, DeclarationType declarationType, DeclarationMethod declarationMethod, DeclarationUsage declarationUsage, byte usageIndex) { Stream = stream; Offset = offset; DeclarationType = declarationType; DeclarationMethod = declarationMethod; DeclarationUsage = declarationUsage; UsageIndex = usageIndex; }
/// <summary> /// Returns the number of streams of a certain <see cref="DeclarationUsage"/>. /// </summary> /// <param name="usage">The <see cref="DeclarationUsage"/> to get the number of streams for.</param> /// <returns>The number of streams of a certain <see cref="DeclarationUsage"/>.</returns> public int Count(DeclarationUsage usage) { int counter = 0; for (int i = 0; i < types.Length; i++) { if (StreamFactory.Instance.VertexElement(types[i]).DeclarationUsage == usage) { counter++; } } return(counter); }
public static bool FindElement(VertexElement[] decl, DeclarationUsage usage, int usageIdx, out int found) { for (int iExists = 0; decl[iExists].Stream != 255 && iExists < decl.Length; iExists++) { if (decl[iExists].DeclarationUsage == usage && decl[iExists].UsageIndex == usageIdx) { found = iExists; return(true); } } found = -1; return(false); }
public static bool ExtractUsage(VertexElement[] elements, DeclarationUsage usage, int index, out DeclarationType format, out int offset) { format = (DeclarationType)0; offset = 0; for (int i = 0; i < elements.Length; i++) { if (elements[i].Usage == usage && elements[i].UsageIndex == index) { format = elements[i].Type; offset = elements[i].Offset; return(true); } } return(false); }
public static bool FindValidUsageIndex(VertexElement[] decl, DeclarationUsage usage, out int usageIndex, out int insertBefore) { int length = GetLength(decl); usageIndex = 0; insertBefore = length; for (int iExists = 0; iExists < length; iExists++) { if (decl[iExists].DeclarationUsage == usage && decl[iExists].UsageIndex >= usageIndex) { insertBefore = iExists + 1; usageIndex = decl[iExists].UsageIndex + 1; } } return(usageIndex < MaxUsageIndex + 1); }
public AddVDataArguments(OpsParsedStatement statement) { OpsParsedArgument typeArg = statement.FindArgument("type"); if(typeArg == null) { typeArg = statement.FindArgument(""); if(typeArg == null) throw new OpsException("'type' argument argument"); } type = MeshDeclarationHelper.DecodeType(typeArg.Value); OpsParsedArgument usageArg = statement.FindArgument("usage"); if(usageArg != null) usage = MeshDeclarationHelper.DecodeUsage(usageArg.Value); OpsParsedArgument usageIdxArg = statement.FindArgument("usageIdx"); if(usageIdxArg != null) usageIdx = int.Parse( usageIdxArg.Value ); }
static VertexDeclarationBuilder() { _formatMapping = new Dictionary <Type, DeclarationType>(); _formatMappingSize = new Dictionary <DeclarationType, int>(); _usageMapping = new Dictionary <string, DeclarationUsage>(); _formatMapping.Add(typeof(Color), DeclarationType.Color); _formatMapping.Add(typeof(Half2), DeclarationType.HalfTwo); _formatMapping.Add(typeof(Half4), DeclarationType.HalfFour); _formatMapping.Add(typeof(float), DeclarationType.Float1); _formatMapping.Add(typeof(Vector2), DeclarationType.Float2); _formatMapping.Add(typeof(Vector3), DeclarationType.Float3); _formatMapping.Add(typeof(Vector4), DeclarationType.Float4); foreach (KeyValuePair <Type, DeclarationType> kvp in _formatMapping) { _formatMappingSize.Add(kvp.Value, Marshal.SizeOf(kvp.Key)); } FieldInfo[] enums = typeof(DeclarationUsage).GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); foreach (FieldInfo field in enums) { DeclarationUsage usage = (DeclarationUsage)field.GetValue(null); _usageMapping.Add(usage.ToString().ToLower(), usage); } _usageMapping.Add("norm", DeclarationUsage.Normal); _usageMapping.Add("pos", DeclarationUsage.Position); _usageMapping.Add("binorm", DeclarationUsage.Binormal); _usageMapping.Add("colour", DeclarationUsage.Color); _usageMapping.Add("diffuse", DeclarationUsage.Color); _usageMapping.Add("col", DeclarationUsage.Color); _usageMapping.Add("size", DeclarationUsage.PointSize); _usageMapping.Add("psize", DeclarationUsage.PointSize); _usageMapping.Add("tex", DeclarationUsage.TextureCoordinate); _usageMapping.Add("texture", DeclarationUsage.TextureCoordinate); _usageMapping.Add("texcoord", DeclarationUsage.TextureCoordinate); _usageMapping.Add("texcoordinate", DeclarationUsage.TextureCoordinate); }
public DelVDataArguments(OpsParsedStatement statement) { OpsParsedArgument usageArg = statement.FindArgument("usage"); if (usageArg == null) { usageArg = statement.FindArgument(""); if (usageArg == null) { throw OpsException.ArgRequired("usage"); } } usage = MeshDeclarationHelper.DecodeUsage(usageArg.Value); OpsParsedArgument usageIdxArg = statement.FindArgument("usageIdx"); if (usageIdxArg != null) { hasSrcUsageIdx = true; usageIdx = int.Parse(usageIdxArg.Value); } }
public CloneVDataArguments(OpsParsedStatement statement) { OpsParsedArgument usageArg = statement.FindArgument("usage"); if (usageArg == null) { usageArg = statement.FindArgument(""); if (usageArg == null) { throw OpsException.ArgRequired("usage"); } } srcUsage = MeshDeclarationHelper.DecodeUsage(usageArg.Value); OpsParsedArgument usageIdxArg = statement.FindArgument("usageIdx"); if (usageIdxArg != null) { srcUsageIdx = int.Parse(usageIdxArg.Value); hasSrcUsageIdx = true; } OpsParsedArgument dstUsageArg = statement.FindArgument("newusage"); if (dstUsageArg != null) { dstUsage = MeshDeclarationHelper.DecodeUsage(dstUsageArg.Value); } OpsParsedArgument dstUsageIdxArg = statement.FindArgument("newusageIdx"); if (dstUsageIdxArg != null) { dstUsageIdx = int.Parse(dstUsageIdxArg.Value); hasDstUsageIdx = true; } }
public VectorDataType(short id, int numValues, int dataSize, DeclarationType declarationType, DeclarationUsage declarationUsage, byte usageIndex) : base(id, numValues, dataSize, declarationType, declarationUsage, usageIndex) { }
public static bool FindValidUsageIndex(VertexElement[] decl, DeclarationUsage usage, out int usageIndex, out int insertBefore) { int length= GetLength(decl); usageIndex = 0; insertBefore = length; for(int iExists = 0; iExists < length; iExists++) { if( decl[iExists].DeclarationUsage == usage && decl[iExists].UsageIndex >= usageIndex ) { insertBefore = iExists+1; usageIndex = decl[iExists].UsageIndex+1; } } return (usageIndex < MaxUsageIndex+1); }
public VertexElementAttribute(DeclarationUsage usage, byte usageIndex) { _usage = usage; _format = DeclarationType.Unused; _index = usageIndex; }
public DelVDataArguments(OpsParsedStatement statement) { OpsParsedArgument usageArg = statement.FindArgument("usage"); if(usageArg == null) { usageArg = statement.FindArgument(""); if(usageArg == null) throw OpsException.ArgRequired("usage"); } usage = MeshDeclarationHelper.DecodeUsage(usageArg.Value); OpsParsedArgument usageIdxArg = statement.FindArgument("usageIdx"); if(usageIdxArg != null) { hasSrcUsageIdx = true; usageIdx = int.Parse( usageIdxArg.Value ); } }
public static bool ExtractUsage(VertexElement[] elements, DeclarationUsage usage, int index, out DeclarationType format, out int offset) { format = (DeclarationType)0; offset = 0; for (int i = 0; i < elements.Length; i++) { if (elements[i].Usage == usage && elements[i].UsageIndex == index) { format = elements[i].Type; offset = elements[i].Offset; return true; } } return false; }
public VertexElementAttribute(DeclarationUsage usage, DeclarationType format) { _usage = usage; _format = format; }
public static VertexElement[] AddElement( VertexElement[] decl, DeclarationType type, DeclarationUsage usage, int usageIdx, out int insertBefore) { int length = GetLength(decl); if( length + 1 > MaxLength) throw new OpsException("Exceeded maximum declaration length: " + MaxLength); if( usageIdx + 1 > MaxUsageIndex) throw new OpsException("Exceeded MaxUsageIndex: " + MaxUsageIndex); int found; if( FindElement( decl, usage, usageIdx , out found) ) throw new OpsException("VertexElement with that input usage+index already exists"); VertexElement[] result= new VertexElement[MaxLength]; insertBefore= length; for( int less = 1 ; less <= usageIdx ; less++ ) { if( FindElement( decl, usage, usageIdx-less , out found) ) { //insertBefore should be 1 after where a previous is found...that way they are consecutive //otherwise we just add it to the end.(see initialization insertBefore=length) insertBefore = found+1; break; } } //MOVE EVERYTHING OUT OF THE WAY FOR THE NEW ELEMENT short typeSize = (short)GetTypeSize(type); //go to decl.Length-1 so that we cant have room for the added element for( int iCopyFrom = 0, iCopyTo = 0; iCopyFrom < decl.Length-1; iCopyFrom++, iCopyTo++ ) { //if we are the new element insert here if(iCopyFrom == insertBefore) { VertexElement insertVE = new VertexElement(); insertVE.Stream = 0; if(insertBefore < length) insertVE.Offset = decl[iCopyFrom].Offset; else if(length > 0) insertVE.Offset = (short)((short)(decl[insertBefore-1].Offset) + (short)GetTypeSize( decl[insertBefore-1].DeclarationType )); else insertVE.Offset = 0; insertVE.DeclarationType = type; insertVE.DeclarationMethod = DeclarationMethod.Default; insertVE.DeclarationUsage = usage; insertVE.UsageIndex = (byte)usageIdx; result[iCopyTo]=insertVE; iCopyTo++; } VertexElement copyVE = decl[iCopyFrom]; if(iCopyFrom >= insertBefore) { copyVE.Offset += typeSize; } result[iCopyTo] = copyVE; } result[length+1]=VertexElement.VertexDeclarationEnd; return result; }
public static bool FindValidUsageIndex(VertexElement[] decl, DeclarationUsage usage, out int usageIndex) { int insertBefore; return(FindValidUsageIndex(decl, usage, out usageIndex, out insertBefore)); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// Creates a new instance of a semantic object. /// </summary> /// <param name="usage">Usage of parameter.</param> /// <param name="usageIndex">UsageIndex of parameter.</param> public Semantic(DeclarationUsage usage, int usageIndex) { Usage = usage; UsageIndex = usageIndex; }
public static VertexElement[] AddElement(VertexElement[] decl, DeclarationType type, DeclarationUsage usage, int usageIdx, out int insertBefore) { int length = GetLength(decl); if (length + 1 > MaxLength) { throw new OpsException("Exceeded maximum declaration length: " + MaxLength); } if (usageIdx + 1 > MaxUsageIndex) { throw new OpsException("Exceeded MaxUsageIndex: " + MaxUsageIndex); } int found; if (FindElement(decl, usage, usageIdx, out found)) { throw new OpsException("VertexElement with that input usage+index already exists"); } VertexElement[] result = new VertexElement[MaxLength]; insertBefore = length; for (int less = 1; less <= usageIdx; less++) { if (FindElement(decl, usage, usageIdx - less, out found)) { //insertBefore should be 1 after where a previous is found...that way they are consecutive //otherwise we just add it to the end.(see initialization insertBefore=length) insertBefore = found + 1; break; } } //MOVE EVERYTHING OUT OF THE WAY FOR THE NEW ELEMENT short typeSize = (short)GetTypeSize(type); //go to decl.Length-1 so that we cant have room for the added element for (int iCopyFrom = 0, iCopyTo = 0; iCopyFrom < decl.Length - 1; iCopyFrom++, iCopyTo++) { //if we are the new element insert here if (iCopyFrom == insertBefore) { VertexElement insertVE = new VertexElement(); insertVE.Stream = 0; if (insertBefore < length) { insertVE.Offset = decl[iCopyFrom].Offset; } else if (length > 0) { insertVE.Offset = (short)((short)(decl[insertBefore - 1].Offset) + (short)GetTypeSize(decl[insertBefore - 1].DeclarationType)); } else { insertVE.Offset = 0; } insertVE.DeclarationType = type; insertVE.DeclarationMethod = DeclarationMethod.Default; insertVE.DeclarationUsage = usage; insertVE.UsageIndex = (byte)usageIdx; result[iCopyTo] = insertVE; iCopyTo++; } VertexElement copyVE = decl[iCopyFrom]; if (iCopyFrom >= insertBefore) { copyVE.Offset += typeSize; } result[iCopyTo] = copyVE; } result[length + 1] = VertexElement.VertexDeclarationEnd; return(result); }
/// <summary> /// Initializes a new instance of the <see cref="VertexElementAttribute"/> class. /// </summary> /// <param name="type">The type.</param> /// <param name="usage">The vertex element usage.</param> public VertexElementAttribute(DeclarationType type, DeclarationUsage usage) { Type = type; Usage = usage; }
public VertexElement[] GetDeclaration(Type type) { lock (_declarationMapping) { VertexElement[] mapping; if (_declarationMapping.TryGetValue(type, out mapping)) { return(mapping); } if (type == typeof(Vector3)) //special case { mapping = new VertexElement[] { new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0) } } ; if (type == typeof(Vector4)) { mapping = new VertexElement[] { new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0) } } ; if (mapping == null) { List <VertexElement> elements = new List <VertexElement>(); int offset = 0; if (type.IsValueType == false) { throw new ArgumentException("Type " + type.Name + " is a not a ValueType (struct)"); } foreach (FieldInfo f in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { if (!f.ReflectedType.IsValueType) { throw new ArgumentException("Field " + type.Name + "." + f.Name + " is a not a ValueType (struct)"); } int size = Marshal.SizeOf(f.FieldType); bool attribSet = false; foreach (object o in f.GetCustomAttributes(true)) { if (o is VertexElementAttribute) { VertexElementAttribute att = (VertexElementAttribute)o; DeclarationType format = att.Type; if (format == DeclarationType.Unused) { format = DetermineFormat(f); } else { int formatSize; if (!_formatMappingSize.TryGetValue(format, out formatSize)) { throw new ArgumentException(string.Format("Invlaid DeclarationType ({0}) specified in VertexElementAttribute for {1}.{2}", format, type.FullName, f.Name)); } if (formatSize != Marshal.SizeOf(f.FieldType)) { throw new ArgumentException(string.Format("DeclarationType size mismatch in {4}.{5}, {0} requires a size of {1}, specified type {2} has size {3}", format, formatSize, f.FieldType.FullName, Marshal.SizeOf(f.FieldType), type.FullName, f.Name)); } } elements.Add(new VertexElement(0, (short)offset, format, DeclarationMethod.Default, att.Usage, (byte)att.Index)); attribSet = true; break; } } if (!attribSet) { DeclarationType format = DetermineFormat(f); int index; DeclarationUsage usage = DetermineUsage(elements, f, out index); elements.Add(new VertexElement(0, (short)offset, format, DeclarationMethod.Default, usage, (byte)index)); } offset += size; } elements.Add(VertexElement.VertexDeclarationEnd); mapping = elements.ToArray(); } _declarationMapping.Add(type, mapping); return(mapping); } }
public VertexElement(short stream, short offset, DeclarationType declType, DeclarationMethod declMethod, DeclarationUsage declUsage, byte usageIndex) { }
public VertexElementAttribute(DeclarationUsage usage) { _usage = usage; _format = DeclarationType.Unused; }
public static bool FindValidUsageIndex(VertexElement[] decl, DeclarationUsage usage, out int usageIndex) { int insertBefore; return FindValidUsageIndex( decl, usage, out usageIndex, out insertBefore); }
public VertexElementAttribute(DeclarationUsage usage, DeclarationType format, byte usageIndex) { _usage = usage; _format = format; _index = usageIndex; }
static void ParseSemantic(string semanticString, out DeclarationUsage declarationUsage, out byte index) { var match = SemanticEx.Match(semanticString); if (!match.Success) throw new InvalidDataException(string.Format("'{0}' is not a correct D3D9 semantic", semanticString)); declarationUsage = ParseDeclarationUsage(match.Groups[1].Value); index = string.IsNullOrEmpty(match.Groups[2].Value) ? (byte)0 : byte.Parse(match.Groups[2].Value); }
public static bool FindElement(VertexElement[] decl, DeclarationUsage usage, int usageIdx, out int found) { for(int iExists = 0; decl[iExists].Stream != 255 && iExists < decl.Length; iExists++) { if( decl[iExists].DeclarationUsage == usage && decl[iExists].UsageIndex == usageIdx ) { found = iExists; return true; } } found = -1; return false; }
public BoneIndexDataType(short id, int numValues, int dataSize, DeclarationType declarationType, DeclarationUsage declarationUsage, byte usageIndex) : base(id, numValues, dataSize, declarationType, declarationUsage, usageIndex) { }
public CloneVDataArguments(OpsParsedStatement statement) { OpsParsedArgument usageArg = statement.FindArgument("usage"); if(usageArg == null) { usageArg = statement.FindArgument(""); if(usageArg == null) throw OpsException.ArgRequired("usage"); } srcUsage = MeshDeclarationHelper.DecodeUsage(usageArg.Value); OpsParsedArgument usageIdxArg = statement.FindArgument("usageIdx"); if( usageIdxArg != null ) { srcUsageIdx = int.Parse( usageIdxArg.Value ); hasSrcUsageIdx = true; } OpsParsedArgument dstUsageArg = statement.FindArgument("newusage"); if(dstUsageArg != null) dstUsage = MeshDeclarationHelper.DecodeUsage(dstUsageArg.Value); OpsParsedArgument dstUsageIdxArg = statement.FindArgument("newusageIdx"); if( dstUsageIdxArg != null ) { dstUsageIdx = int.Parse( dstUsageIdxArg.Value ); hasDstUsageIdx = true; } }
public VertexUsage(DeclarationUsage usage = DeclarationUsage.Position, int index = 0) { Usage = usage; Index = index; }
public VertexFieldAttribute(DeclarationUsage usage) { this.usage = usage; }
public static Vertices <TVertexType> CreateSingleElementVertices(DeviceContext context, TVertexType[] data, DeclarationUsage elementUsage, int index) { if (typeof(float) != typeof(TVertexType) && typeof(Vector2) != typeof(TVertexType) && typeof(Vector3) != typeof(TVertexType) && typeof(Vector4) != typeof(TVertexType) && typeof(Half2) != typeof(TVertexType) && typeof(Half4) != typeof(TVertexType)) { throw new ArgumentException("Only float and vector types are supported for single element vertex buffers"); } if (data == null) { throw new ArgumentNullException(); } if (index >= 16 || index < 0) { throw new ArgumentException("index"); } DeclarationType format = VertexDeclarationBuilder.DetermineFormat(typeof(TVertexType)); VertexElement[] elements = new VertexElement[] { new VertexElement(0, 0, format, DeclarationMethod.Default, elementUsage, (byte)index) }; int stride = VertexElementAttribute.CalculateVertexStride(elements); return(new Vertices <TVertexType>(context, data, elements, stride)); }