public SdkMeshVertexBuffer(BinaryReader reader) { NumVertices = reader.ReadUInt64(); SizeBytes = reader.ReadUInt64(); StrideBytes = reader.ReadUInt64(); Decl = new List<VertexElement>(); var processElem = true; for (int j = 0; j < MaxVertexElements; j++) { var stream = reader.ReadUInt16(); var offset = reader.ReadUInt16(); var type = reader.ReadByte(); var method = reader.ReadByte(); var usage = reader.ReadByte(); var usageIndex = reader.ReadByte(); if (stream < 16 && processElem) { var element = new VertexElement((short)stream, (short)offset, (DeclarationType)type, (DeclarationMethod)method, (DeclarationUsage)usage, usageIndex); Decl.Add(element); } else { processElem = false; } } DataOffset = reader.ReadUInt64(); Vertices = new List<VertPosNormTexTan>(); if (SizeBytes > 0) { ReadVertices(reader); } }
public static int CalculateVertexStride(VertexElement[] elements) { int stride = 0; for (int i = 0; i < elements.Length; i++) stride = Math.Max(stride, elements[i].Offset + VertexElementAttribute.SizeOfFormatType(elements[i].Type)); return stride; }
public static bool IsEqual(this VertexElement a, VertexElement b) { return (a.Method == b.Method && a.Offset == b.Offset && a.Stream == b.Stream && a.Type == b.Type && a.Usage == b.Usage && a.UsageIndex == b.UsageIndex); }
/// <summary> /// Converts a declarator from a flexible vertex format (FVF) code. /// </summary> /// <param name="fvf">Combination of <see cref="VertexFormat"/> that describes the FVF from which to generate the returned declarator array..</param> /// <returns> /// A declarator from a flexible vertex format (FVF) code. /// </returns> /// <unmanaged>HRESULT D3DXDeclaratorFromFVF([In] D3DFVF FVF,[In, Buffer] D3DVERTEXELEMENT9* pDeclarator)</unmanaged> public static VertexElement[] DeclaratorFromFVF(VertexFormat fvf) { var vertices = new VertexElement[(int)VertexFormatDeclaratorCount.Max]; var result = D3DX9.DeclaratorFromFVF(fvf, vertices); if (result.Failure) return null; var copy = new VertexElement[D3DX9.GetDeclLength(vertices) + 1]; Array.Copy(vertices, copy, copy.Length); copy[copy.Length - 1] = VertexElement.VertexDeclarationEnd; return copy; }
public static D3D9.VertexDeclaration Generate(DECLChunk declChunk, DX dx) { D3D9.VertexElement[] vertexElements = new D3D9.VertexElement[declChunk.Declarations.Count + 1]; for (int i = 0; i < declChunk.Declarations.Count; i++) { var declElem = declChunk.Declarations[i]; D3D9.VertexElement element = new D3D9.VertexElement(0, declElem.Offset, (D3D9.DeclarationType)declElem.Type, (D3D9.DeclarationMethod)declElem.Method, (D3D9.DeclarationUsage)declElem.Usage, declElem.UsageIndex); vertexElements[i] = element; } vertexElements[vertexElements.Length - 1] = D3D9.VertexElement.VertexDeclarationEnd; lock (dx.GlobalLock) { D3D9.VertexDeclaration vertexDecl = new D3D9.VertexDeclaration(dx.Device, vertexElements); return(vertexDecl); } }
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; }
/// <summary> /// Gets the size of a vertex from the vertex declaration. /// </summary> /// <param name="elements">The elements.</param> /// <param name="stream">The stream.</param> /// <returns>The vertex declaration size, in bytes.</returns> /// <unmanaged>unsigned int D3DXGetDeclVertexSize([In, Buffer] const D3DVERTEXELEMENT9* pDecl,[In] unsigned int Stream)</unmanaged> public static int GetDeclarationVertexSize(VertexElement[] elements, int stream) { return D3DX9.GetDeclVertexSize(elements, stream); }
/// <summary> /// Gets the number of elements in the vertex declaration. /// </summary> /// <param name="declaration">The declaration.</param> /// <returns>The number of elements in the vertex declaration.</returns> /// <unmanaged>unsigned int D3DXGetDeclLength([In, Buffer] const D3DVERTEXELEMENT9* pDecl)</unmanaged> public static int GetDeclarationLength(VertexElement[] declaration) { return D3DX9.GetDeclLength(declaration); }
/// <summary> /// Generates an output vertex declaration from the input declaration. The output declaration is intended for use by the mesh tessellation functions. /// </summary> /// <param name="declaration">The input declaration.</param> /// <returns>The output declaration</returns> /// <unmanaged>HRESULT D3DXGenerateOutputDecl([In, Buffer] D3DVERTEXELEMENT9* pOutput,[In, Buffer] const D3DVERTEXELEMENT9* pInput)</unmanaged> public static VertexElement[] GenerateOutputDeclaration(VertexElement[] declaration) { var vertices = new VertexElement[(int)VertexFormatDeclaratorCount.Max]; var result = D3DX9.GenerateOutputDecl(vertices, declaration); if (result.Failure) return null; var copy = new VertexElement[D3DX9.GetDeclLength(vertices) + 1]; Array.Copy(vertices, copy, copy.Length); copy[copy.Length - 1] = VertexElement.VertexDeclarationEnd; return copy; }
/// <summary> /// Converts a flexible vertex format (FVF) code from a declarator. /// </summary> /// <param name="declarator">The declarator array.</param> /// <returns>A <see cref="VertexFormat"/> that describes the vertex format returned from the declarator.</returns> /// <unmanaged>HRESULT D3DXFVFFromDeclarator([In, Buffer] const D3DVERTEXELEMENT9* pDeclarator,[Out] D3DFVF* pFVF)</unmanaged> public static VertexFormat FVFFromDeclarator(VertexElement[] declarator) { return D3DX9.FVFFromDeclarator(declarator); }
/// <summary> /// Create a vertex shader declaration from the device and the vertex elements. /// </summary> /// <remarks> /// See the {{Vertex Declaration (Direct3D 9)}} page for a detailed description of how to map vertex declarations between different versions of DirectX. /// </remarks> /// <param name="elements"> An array of <see cref="SharpDX.Direct3D9.VertexElement"/> vertex elements. </param> /// <returns><see cref="VertexDeclaration"/> If the method succeeds</returns> /// <unmanaged>HRESULT IDirect3DDevice9::CreateVertexDeclaration([In, Buffer] const D3DVERTEXELEMENT9* pVertexElements,[None] IDirect3DVertexDeclaration9** ppDecl)</unmanaged> public VertexDeclaration(Device device, VertexElement[] elements) { device.CreateVertexDeclaration(elements, this); }
protected void FillBuffers() { DataStream stream, streamIndex; if (!thickLines) { stream = vertexBuffer.Lock(0, 0, LockFlags.None); stream.WriteRange(vertices); vertexBuffer.Unlock(); graphicsDevice.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse; } else { stream = vertexBuffer.Lock(0, 0, LockFlags.None); stream.WriteRange(thickVertices); vertexBuffer.Unlock(); VertexElement[] velements = new VertexElement[] { new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0), new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0), new VertexElement(0, 24, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 1), new VertexElement(0, 32, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0), VertexElement.VertexDeclarationEnd, }; vertexDeclaration = new VertexDeclaration(graphicsDevice, velements); } streamIndex = indexBuffer.Lock(0, 0, LockFlags.None); streamIndex.WriteRange(indices); indexBuffer.Unlock(); }