Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ExtensionMethods.cs
浏览该文件的文档.
1namespace Engine.Graphics {
2 public static class ExtensionMethods {
3 public static int GetSize(this IndexFormat format) {
4 switch (format) {
5 case IndexFormat.SixteenBits: return 2;
6 case IndexFormat.ThirtyTwoBits: return 4;
7 default: throw new InvalidOperationException("Unsupported IndexFormat.");
8 }
9 }
10
11 public static string GetSemanticString(this VertexElementSemantic semantic) {
12 switch (semantic) {
13 case VertexElementSemantic.Position: return "POSITION";
14 case VertexElementSemantic.Color: return "COLOR";
15 case VertexElementSemantic.Normal: return "NORMAL";
16 case VertexElementSemantic.TextureCoordinate: return "TEXCOORD";
17 case VertexElementSemantic.TextureCoordinate0: return "TEXCOORD0";
18 case VertexElementSemantic.TextureCoordinate1: return "TEXCOORD1";
19 case VertexElementSemantic.TextureCoordinate2: return "TEXCOORD2";
20 case VertexElementSemantic.TextureCoordinate3: return "TEXCOORD3";
21 case VertexElementSemantic.TextureCoordinate4: return "TEXCOORD4";
22 case VertexElementSemantic.TextureCoordinate5: return "TEXCOORD5";
23 case VertexElementSemantic.TextureCoordinate6: return "TEXCOORD6";
24 case VertexElementSemantic.TextureCoordinate7: return "TEXCOORD7";
25 case VertexElementSemantic.Instance: return "INSTANCE";
26 case VertexElementSemantic.BlendIndices: return "BLENDINDICES";
27 case VertexElementSemantic.BlendWeights: return "BLENDWEIGHTS";
28 default: throw new InvalidOperationException("Unrecognized vertex semantic.");
29 }
30 }
31
32 public static int GetSize(this ColorFormat format) {
33 return format switch {
37 ColorFormat.R8 => 1,
41 _ => throw new InvalidOperationException("Unsupported ColorFormat.")
42 };
43 }
44
45 public static int GetSize(this DepthFormat format) {
46 switch (format) {
47 case DepthFormat.None: return 0;
48 case DepthFormat.Depth16: return 2;
49 case DepthFormat.Depth24Stencil8: return 4;
50 default: throw new InvalidOperationException("Unsupported DepthFormat.");
51 }
52 }
53
54 public static int GetPrimitivesCount(this PrimitiveType primitiveType, int indicesCount) {
55 switch (primitiveType) {
56 case PrimitiveType.LineList: return indicesCount / 2;
57 case PrimitiveType.LineStrip: return MathUtils.Max(indicesCount - 1, 0);
58 case PrimitiveType.TriangleList: return indicesCount / 3;
59 case PrimitiveType.TriangleStrip: return MathUtils.Max(indicesCount - 2, 0);
60 default: throw new InvalidOperationException("Unsupported PrimitiveType.");
61 }
62 }
63
64 public static int GetSize(this ShaderParameterType type) {
65 switch (type) {
66 case ShaderParameterType.Float: return 4;
67 case ShaderParameterType.Vector2: return 8;
68 case ShaderParameterType.Vector3: return 12;
69 case ShaderParameterType.Vector4: return 16;
70 case ShaderParameterType.Matrix: return 64;
71 default: throw new InvalidOperationException("Unsupported ShaderParameterType.");
72 }
73 }
74
75 public static int GetElementsCount(this VertexElementFormat format) {
76 switch (format) {
77 case VertexElementFormat.Single: return 1;
78 case VertexElementFormat.Vector2: return 2;
79 case VertexElementFormat.Vector3: return 3;
80 case VertexElementFormat.Vector4: return 4;
81 case VertexElementFormat.Byte4: return 4;
82 case VertexElementFormat.NormalizedByte4: return 4;
83 case VertexElementFormat.Short2: return 2;
84 case VertexElementFormat.NormalizedShort2: return 2;
85 case VertexElementFormat.Short4: return 4;
86 case VertexElementFormat.NormalizedShort4: return 4;
87 default: throw new InvalidOperationException("Unsupported VertexElementFormat.");
88 }
89 }
90
91 public static int GetElementSize(this VertexElementFormat format) {
92 switch (format) {
93 case VertexElementFormat.Single: return 4;
94 case VertexElementFormat.Vector2: return 4;
95 case VertexElementFormat.Vector3: return 4;
96 case VertexElementFormat.Vector4: return 4;
97 case VertexElementFormat.Byte4: return 1;
98 case VertexElementFormat.NormalizedByte4: return 1;
99 case VertexElementFormat.Short2: return 2;
100 case VertexElementFormat.NormalizedShort2: return 2;
101 case VertexElementFormat.Short4: return 2;
102 case VertexElementFormat.NormalizedShort4: return 2;
103 default: throw new InvalidOperationException("Unsupported VertexElementFormat.");
104 }
105 }
106
107 public static int GetSize(this VertexElementFormat format) => format.GetElementsCount() * format.GetElementSize();
108 }
109}
static int GetSize(this VertexElementFormat format)
static int GetSize(this ShaderParameterType type)
static int GetElementsCount(this VertexElementFormat format)
static int GetElementSize(this VertexElementFormat format)
static int GetSize(this ColorFormat format)
static int GetSize(this IndexFormat format)
static string GetSemanticString(this VertexElementSemantic semantic)
static int GetPrimitivesCount(this PrimitiveType primitiveType, int indicesCount)
static int GetSize(this DepthFormat format)
static int Max(int x1, int x2)