Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DataBox.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 System.Runtime.InteropServices;
5 
6 namespace SiliconStudio.Paradox.Graphics
7 {
8  /// <summary>
9  /// Provides access to data organized in 3D.
10  /// </summary>
11  [StructLayout(LayoutKind.Sequential)]
12  public struct DataBox : IEquatable<DataBox>
13  {
14  /// <summary>
15  /// An empty DataBox.
16  /// </summary>
17  private static DataBox Empty;
18 
19  /// <summary>
20  /// Initializes a new instance of the <see cref="DataBox"/> struct.
21  /// </summary>
22  /// <param name="datapointer">The datapointer.</param>
23  /// <param name="rowPitch">The row pitch.</param>
24  /// <param name="slicePitch">The slice pitch.</param>
25  public DataBox(IntPtr datapointer, int rowPitch, int slicePitch)
26  {
27  DataPointer = datapointer;
28  RowPitch = rowPitch;
29  SlicePitch = slicePitch;
30  }
31 
32  /// <summary>
33  /// Pointer to the data.
34  /// </summary>
35  public IntPtr DataPointer;
36 
37  /// <summary>
38  /// Gets the number of bytes per row.
39  /// </summary>
40  public int RowPitch;
41 
42  /// <summary>
43  /// Gets the number of bytes per slice (for a 3D texture, a slice is a 2D image)
44  /// </summary>
45  public int SlicePitch;
46 
47  /// <summary>
48  /// Gets a value indicating whether this instance is empty.
49  /// </summary>
50  /// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
51  public bool IsEmpty
52  {
53  get
54  {
55  return EqualsByRef(ref Empty);
56  }
57  }
58 
59  public bool Equals(DataBox other)
60  {
61  return EqualsByRef(ref other);
62  }
63 
64  public override bool Equals(object obj)
65  {
66  if (ReferenceEquals(null, obj)) return false;
67  return obj is DataBox && Equals((DataBox)obj);
68  }
69 
70  public override int GetHashCode()
71  {
72  unchecked
73  {
74  var hashCode = DataPointer.GetHashCode();
75  hashCode = (hashCode * 397) ^ RowPitch;
76  hashCode = (hashCode * 397) ^ SlicePitch;
77  return hashCode;
78  }
79  }
80 
81  /// <summary>
82  /// Implements the operator ==.
83  /// </summary>
84  /// <param name="left">The left.</param>
85  /// <param name="right">The right.</param>
86  /// <returns>The result of the operator.</returns>
87  public static bool operator ==(DataBox left, DataBox right)
88  {
89  return left.Equals(right);
90  }
91 
92  /// <summary>
93  /// Implements the operator !=.
94  /// </summary>
95  /// <param name="left">The left.</param>
96  /// <param name="right">The right.</param>
97  /// <returns>The result of the operator.</returns>
98  public static bool operator !=(DataBox left, DataBox right)
99  {
100  return !left.Equals(right);
101  }
102 
103  private bool EqualsByRef(ref DataBox other)
104  {
105  return DataPointer.Equals(other.DataPointer) && RowPitch == other.RowPitch && SlicePitch == other.SlicePitch;
106  }
107  }
108 }
int RowPitch
Gets the number of bytes per row.
Definition: DataBox.cs:40
IntPtr DataPointer
Pointer to the data.
Definition: DataBox.cs:35
override bool Equals(object obj)
Definition: DataBox.cs:64
Provides access to data organized in 3D.
Definition: DataBox.cs:12
int SlicePitch
Gets the number of bytes per slice (for a 3D texture, a slice is a 2D image)
Definition: DataBox.cs:45
DataBox(IntPtr datapointer, int rowPitch, int slicePitch)
Initializes a new instance of the DataBox struct.
Definition: DataBox.cs:25