Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
VertexBufferBinding.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using SiliconStudio.Core.Serialization.Converters;
5 
6 namespace SiliconStudio.Paradox.Graphics
7 {
8  /// <summary>
9  /// Binding structure that specifies a vertex buffer and other per-vertex parameters (such as offset and instancing) for a graphics device.
10  /// </summary>
11  [DataConverter(AutoGenerate = true, CustomConvertFromData = true)]
12  public struct VertexBufferBinding : IEquatable<VertexBufferBinding>
13  {
14  private readonly int hashCode;
15 
16  /// <summary>
17  /// Creates an instance of this object.
18  /// </summary>
19  /// <param name="vertexBuffer">The vertex buffer</param>
20  /// <param name="vertexDeclaration">The vertex declaration.</param>
21  /// <param name="vertexCount">The vertex count.</param>
22  /// <param name="vertexStride">The vertex stride.</param>
23  /// <param name="vertexOffset">Offset (in Vertex ElementCount) from the beginning of the buffer to the first vertex to use.</param>
24  public VertexBufferBinding(Buffer vertexBuffer, VertexDeclaration vertexDeclaration, int vertexCount, int vertexStride = 0, int vertexOffset = 0) : this()
25  {
26  if (vertexBuffer == null) throw new ArgumentNullException("vertexBuffer");
27  if (vertexDeclaration == null) throw new ArgumentNullException("vertexDeclaration");
28 
29  Buffer = vertexBuffer;
30  Stride = vertexStride != 0 ? vertexStride : vertexDeclaration.VertexStride;
31  Offset = vertexOffset;
32  Count = vertexCount;
33  Declaration = vertexDeclaration;
34 
35  unchecked
36  {
37  hashCode = Buffer.GetHashCode();
38  hashCode = (hashCode*397) ^ Offset;
39  hashCode = (hashCode*397) ^ Stride;
40  hashCode = (hashCode*397) ^ Count;
41  hashCode = (hashCode*397) ^ Declaration.GetHashCode();
42  }
43  }
44 
45  /// <summary>
46  /// Gets a vertex buffer.
47  /// </summary>
48  [DataMemberConvert]
49  public Buffer Buffer { get; private set; }
50 
51  /// <summary>
52  /// Gets the offset (vertex index) between the beginning of the buffer and the vertex data to use.
53  /// </summary>
54  [DataMemberConvert]
55  public int Offset { get; private set; }
56 
57  /// <summary>
58  /// Gets the vertex stride.
59  /// </summary>
60  [DataMemberConvert]
61  public int Stride { get; private set; }
62 
63  /// <summary>
64  /// Gets the number of vertex.
65  /// </summary>
66  /// <value>The count.</value>
67  [DataMemberConvert]
68  public int Count { get; private set; }
69 
70  /// <summary>
71  /// Gets the layout of the vertex buffer.
72  /// </summary>
73  /// <value>The declaration.</value>
74  [DataMemberConvert]
75  public VertexDeclaration Declaration { get; private set; }
76 
77  public bool Equals(VertexBufferBinding other)
78  {
79  return Buffer.Equals(other.Buffer) && Offset == other.Offset && Stride == other.Stride && Count == other.Count && Declaration.Equals(other.Declaration);
80  }
81 
82  public override bool Equals(object obj)
83  {
84  if (ReferenceEquals(null, obj)) return false;
85  return obj is VertexBufferBinding && Equals((VertexBufferBinding)obj);
86  }
87 
88  public override int GetHashCode()
89  {
90  return hashCode;
91  }
92  }
93 }
The layout of a vertex buffer with a set of VertexElement.
Base class for converters to/from a data type.
All-in-One Buffer class linked SharpDX.Direct3D11.Buffer.
SiliconStudio.Paradox.Graphics.Buffer Buffer
Definition: BasicEffect.cs:15
VertexBufferBinding(Buffer vertexBuffer, VertexDeclaration vertexDeclaration, int vertexCount, int vertexStride=0, int vertexOffset=0)
Creates an instance of this object.
VertexDeclaration Declaration
Gets the layout of the vertex buffer.
int Offset
Gets the offset (vertex index) between the beginning of the buffer and the vertex data to use...
Binding structure that specifies a vertex buffer and other per-vertex parameters (such as offset and ...