Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
VertexPositionTexture.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 using SiliconStudio.Core.Mathematics;
6 
7 namespace SiliconStudio.Paradox.Graphics
8 {
9  /// <summary>
10  /// Describes a custom vertex format structure that contains position and color information.
11  /// </summary>
12  [StructLayout(LayoutKind.Sequential)]
13  public struct VertexPositionTexture : IEquatable<VertexPositionTexture>, IVertex
14  {
15  /// <summary>
16  /// Initializes a new <see cref="VertexPositionTexture"/> instance.
17  /// </summary>
18  /// <param name="position">The position of this vertex.</param>
19  /// <param name="textureCoordinate">UV texture coordinates.</param>
20  public VertexPositionTexture(Vector3 position, Vector2 textureCoordinate)
21  : this()
22  {
23  Position = position;
24  TextureCoordinate = textureCoordinate;
25  }
26 
27  /// <summary>
28  /// XYZ position.
29  /// </summary>
30  public Vector3 Position;
31 
32  /// <summary>
33  /// UV texture coordinates.
34  /// </summary>
36 
37  /// <summary>
38  /// Defines structure byte size.
39  /// </summary>
40  public static readonly int Size = 20;
41 
42  /// <summary>
43  /// The vertex layout of this struct.
44  /// </summary>
46 
47  public bool Equals(VertexPositionTexture other)
48  {
49  return Position.Equals(other.Position) && TextureCoordinate.Equals(other.TextureCoordinate);
50  }
51 
52  public override bool Equals(object obj)
53  {
54  if (ReferenceEquals(null, obj)) return false;
55  return obj is VertexPositionTexture && Equals((VertexPositionTexture)obj);
56  }
57 
58  public override int GetHashCode()
59  {
60  unchecked
61  {
62  int hashCode = Position.GetHashCode();
63  hashCode = (hashCode * 397) ^ TextureCoordinate.GetHashCode();
64  return hashCode;
65  }
66  }
67 
69  {
70  return Layout;
71  }
72 
73  public void FlipWinding()
74  {
75  TextureCoordinate.X = (1.0f - TextureCoordinate.X);
76  }
77 
78  public static bool operator ==(VertexPositionTexture left, VertexPositionTexture right)
79  {
80  return left.Equals(right);
81  }
82 
83  public static bool operator !=(VertexPositionTexture left, VertexPositionTexture right)
84  {
85  return !left.Equals(right);
86  }
87 
88  public override string ToString()
89  {
90  return string.Format("Position: {0}, Texcoord: {1}", Position, TextureCoordinate);
91  }
92  }
93 }
The layout of a vertex buffer with a set of VertexElement.
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
static VertexElement TextureCoordinate(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "TEXCOORD".
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
TextureCoordinate
The texture coordinate.
Describes a custom vertex format structure that contains position and color information.
static VertexElement Position(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "POSITION".
VertexPositionTexture(Vector3 position, Vector2 textureCoordinate)
Initializes a new VertexPositionTexture instance.
VertexDeclaration GetLayout()
Gets the layout of the vertex.
The base interface for all the vertex data structure.
Definition: IVertex.cs:9
A description of a single element for the input-assembler stage. This structure is related to Direct3...