public VertexAttribute(VertexUsage usage, VertexAttribPointerType type, int index, int dimension) : this(usage, type, index, dimension, false) { }
public VertexAttribute(VertexUsage usage, VertexAttribPointerType type, int dimension, bool normalized) : this(usage, type, 0, dimension, normalized) { }
/// <summary> /// Initializes a new instance of the <see cref="VertexElement"/> structure. /// </summary> /// <param name="position">The element's position within the vertex data, in bytes.</param> /// <param name="format">The element's vertex format.</param> /// <param name="usage">The element's usage hint.</param> /// <param name="index">The element's usage index.</param> public VertexElement(Int32 position, VertexFormat format, VertexUsage usage, Int32 index) { Contract.EnsureRange(index >= 0 && index < UsageIndexCount, "index"); this.position = position; this.format = format; this.usage = usage; this.index = index; }
/// <summary> /// Initializes a new instance of the <see cref="VertexElement"/> structure. /// </summary> /// <param name="position">The element's position within the vertex data, in bytes.</param> /// <param name="format">The element's vertex format.</param> /// <param name="usage">The element's usage hint.</param> /// <param name="index">The element's usage index.</param> public VertexElement(Int32 position, VertexFormat format, VertexUsage usage, Int32 index) { Contract.EnsureRange(index >= 0 && index < UsageIndexCount, nameof(index)); this.position = position; this.format = format; this.usage = usage; this.index = index; }
public VertexAttribute GetAttribute(VertexUsage usage, int index = 0) { VertexAttribute attribute = _attributes.FirstOrDefault(a => a.Usage == usage && a.Index == index); if (attribute == null) { throw new InvalidOperationException("VertexAttrubute not found"); } return(attribute); }
public VertexBufferProperties( int inputCount, VertexUsage usage, byte[] data, int byteWidth) { InputCount = inputCount; Usage = usage; Data = (byte[])data.Clone(); ByteWidth = byteWidth; }
public AttributeBinding AddBinding( int index, VertexUsage usage, int usageIndex = 0) { VertexAttribute v = _vertexBuffer.VertexFormat.GetAttribute(usage, usageIndex); AttributeBinding binding = new AttributeBinding(index, v.Dimension, v.Type, v.Normalized, _vertexBuffer.VertexFormat.Stride, v.Offset); _bindings.Add(binding); _dirty = true; return(binding); }
public void Add( int slot, string name, VertexUsage usage, int index, int dimension ) { var mapping = new AttributeMapping(slot, name, usage, index, dimension); mappings.Add(mapping); }
public VertexAttribute(VertexUsage usage, VertexAttribPointerType type, int index, int dimension, bool normalized) { Usage = usage; Type = type; Index = index; Dimension = dimension; Normalized = normalized; Offset = -1; // set by VertexFormat when attached to it }
public void Add( int slot, string name, VertexUsage srcUsage, int srcIndex, VertexUsage dstUsage, int dstIndex, int dimension ) { var mapping = new AttributeMapping(slot, name, srcUsage, srcIndex, dstUsage, dstIndex, dimension); mappings.Add(mapping); }
public Attribute( VertexUsage usage, VertexAttribPointerType type, int index, int dimension ) { Usage = usage; Type = type; Index = index; Dimension = dimension; Offset = -1; // Set by VertexFormat when attached to it Normalized = false; }
public Attribute FindAttribute(VertexUsage usage, int index) { foreach (Attribute attribute in attributes) { if ( ((attribute.Usage & usage) == usage) && (attribute.Index == index) ) { return(attribute); } } return(null); }
public bool HasAttribute(VertexUsage usage, int index) { foreach (Attribute attribute in attributes) { if ( ((attribute.Usage & usage) == usage) && (attribute.Index == index) ) { return(true); } } return(false); }
public AttributeMapping( int slot, string name, VertexUsage usage, int index, int dimension ) { Slot = slot; Name = name; SrcUsage = usage; DstUsage = usage; SrcIndex = index; DstIndex = index; Dimension = dimension; }
public VertexAttribute Add(VertexUsage usage, VertexAttribPointerType type, int index, int dimension, int offset, bool normalized) { VertexAttribute attribute = new VertexAttribute() { Usage = usage, Type = type, Index = index, Dimension = dimension, Offset = offset, Normalized = normalized }; Stride += attribute.Stride(); _attributes.Add(attribute); return(attribute); }
public override object Read(ContentReader reader) { VertexFormat format = new VertexFormat(); uint stride = reader.ReadUInt32(); uint elementCount = reader.ReadUInt32(); for (int i = 0; i < elementCount; i++) { int dimension = reader.ReadSByte(); VertexAttribPointerType type = EnumToPointerType(reader.ReadSByte()); VertexUsage usage = EnumToVertexUsage(reader.ReadUInt32()); bool normalized = usage == VertexUsage.TextureCoordinate; format.Add(new VertexAttribute(usage, type, dimension, normalized)); } return(format); }
/// <summary> /// Gets the name of the shader attribute which corresponds to the specified Ultraviolet vertex usage. /// </summary> /// <param name="usage">The vertex usage for which to retrieve a name.</param> /// <param name="index">The vertex usage index for which to retrieve a name.</param> /// <returns>The name of the specified shader attribute.</returns> private static String GetVertexAttributeNameFromUsage(VertexUsage usage, Int32 index) { return(vertexAttributeNames[((int)usage * VertexElement.UsageIndexCount) + index]); }
/// <summary> /// Initializes a new instance of <see cref="VertexBufferProperties"/> class. /// </summary> /// <param name="inputCount">The number of inputs to the vertex shader.</param> /// <param name="usage">Indicates how frequently the vertex buffer is likely to be updated.</param> /// <param name="data">The initial contents of the vertex buffer</param> public VertexBufferProperties(int inputCount, VertexUsage usage, DataStream data) { InputCount = inputCount; Usage = usage; Data = data; }
/// <summary> /// Gets the name of the shader attribute which corresponds to the specified Ultraviolet vertex usage. /// </summary> /// <param name="usage">The vertex usage for which to retrieve a name.</param> /// <param name="index">The vertex usage index for which to retrieve a name.</param> /// <returns>The name of the specified shader attribute.</returns> private static String GetVertexAttributeNameFromUsage(VertexUsage usage, Int32 index) { return vertexAttributeNames[((int)usage * VertexElement.UsageIndexCount) + index]; }
public VertexAttribute(int dimensions, VertexAttribPointerType type, VertexUsage usage) { Dimension = dimensions; Type = type; Usage = usage; }
public void ValidateVertexDeclarationForShader(VertexDeclaration declaration, IShader shader, Type verticesType) { VertexUsage[] usage; if (vertexDeclarationUsage == null) { vertexDeclarationUsage = new Dictionary <VertexDeclaration, VertexUsage[]>(); } if (!vertexDeclarationUsage.TryGetValue(declaration, out usage)) { //build usage VertexElement[] elements = declaration.GetVertexElements(); SortedList <VertexElementUsage, List <int> > usageIndices = new SortedList <VertexElementUsage, List <int> >(); foreach (VertexElement ve in elements) { List <int> inds; if (!usageIndices.TryGetValue(ve.VertexElementUsage, out inds)) { inds = new List <int>(); usageIndices.Add(ve.VertexElementUsage, inds); } inds.Add(ve.UsageIndex); } List <VertexUsage> usages = new List <VertexUsage>(); foreach (KeyValuePair <VertexElementUsage, List <int> > kvp in usageIndices) { VertexUsage vuse = new VertexUsage(); kvp.Value.Sort(); vuse.usage = kvp.Key; foreach (int i in kvp.Value) { vuse.index = i; usages.Add(vuse); } } usage = usages.ToArray(); vertexDeclarationUsage.Add(declaration, usage); } int shaderCount = shader.GetVertexInputCount(); if (shaderCount == 0) { return; } VertexElementUsage use; int index; int sv = 0; for (int dv = 0; dv < usage.Length && sv < shaderCount;) { shader.GetVertexInput(sv, out use, out index); if (usage[dv].usage == use) { if (usage[dv].index == index) { dv++; //all happy, elements match. sv++; continue; } if (usage[dv].index > index) { //bugger, missing element break; } dv++; continue; } if ((int)use > (int)usage[dv].usage) { dv++; continue; } break; //bugger. } if (sv < shaderCount) { //problems.. shader.GetVertexInput(sv, out use, out index); //generate an error describing the problem, //fill it in with details about the state string vertexType = "VerticesGroup"; string vertexDecl = "vertex structure"; string shaderType = string.Format("type {0}", shader.GetType()); string errorFormat = @"Error: The current vertex shader is attempting to read data that is not present in the vertices being drawn.{5}The shader currently in use ({0}) has a vertex shader that reads '{1}{2}' from each vertex.{5}However, the {3} being drawn does not contain a '{1}{2}' value in it's {4}."; if (verticesType != null) { vertexType = string.Format("Vertices<{0}> object", verticesType.FullName); } //add some helpers in some common situations... if (shader.GetType().IsPublic == false && shader.GetType().Namespace == "Xen.Ex.Material") { shaderType = "MaterialShader"; if (use == VertexElementUsage.Tangent || use == VertexElementUsage.Binormal) { errorFormat += Environment.NewLine; errorFormat += "NOTE: MaterialShader properties may change the vertex data it tries to access. Using a Normal Map requires the vertices have Tangents and Binormals."; } if (use == VertexElementUsage.Color) { errorFormat += Environment.NewLine; errorFormat += "NOTE: MaterialShader properties may change the vertex data it tries to access. Setting 'UseVertexColour' to true requires the vertices have Color0 data."; } if (use == VertexElementUsage.Normal) { errorFormat += Environment.NewLine; errorFormat += "NOTE: MaterialShader properties may change the vertex data it tries to access. Enabling lighting requires the vertices have Normals."; } } if (verticesType == typeof(byte)) { vertexType = "XNA vertex data"; vertexDecl = "vertex declaration"; if (use == VertexElementUsage.Tangent || use == VertexElementUsage.Binormal) { errorFormat += Environment.NewLine; errorFormat += "NOTE: If you are drawing a ModelInstance, the Xen Model Importer can generate Tangent/Binormal data by setting the 'Generate Tangent Frames' Content Processor property for the file to true."; } } string error = string.Format(errorFormat, shaderType, use, index, vertexType, vertexDecl, Environment.NewLine); throw new InvalidOperationException(error); } }
public bool HasAttribute(VertexUsage usage, int index) { return(_attributes.Any(a => a.Usage == usage && a.Index == index)); }
public AttributeMapping(string name, VertexUsage usage, int index) { Name = name; Usage = usage; Index = index; }
public void Add(string name, VertexUsage usage, int index = 0) { _mappings.Add(new AttributeMapping(name, usage, index)); }