forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSharpDXHelper.cs
184 lines (157 loc) · 6.77 KB
/
SharpDXHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
namespace Microsoft.Xna.Framework
{
using System;
using Graphics;
using SharpDX.Mathematics.Interop;
static internal class SharpDXHelper
{
static public SharpDX.DXGI.SwapEffect ToSwapEffect(PresentInterval presentInterval)
{
SharpDX.DXGI.SwapEffect effect;
switch (presentInterval)
{
case PresentInterval.One:
case PresentInterval.Two:
default:
#if WINDOWS_UAP
effect = SharpDX.DXGI.SwapEffect.FlipSequential;
#else
effect = SharpDX.DXGI.SwapEffect.Discard;
#endif
break;
case PresentInterval.Immediate:
effect = SharpDX.DXGI.SwapEffect.Sequential;
break;
}
//if (present.RenderTargetUsage != RenderTargetUsage.PreserveContents && present.MultiSampleCount == 0)
//effect = SharpDX.DXGI.SwapEffect.Discard;
return effect;
}
static public SharpDX.DXGI.Format ToFormat(DepthFormat format)
{
switch (format)
{
default:
case DepthFormat.None:
return SharpDX.DXGI.Format.Unknown;
case DepthFormat.Depth16:
return SharpDX.DXGI.Format.D16_UNorm;
case DepthFormat.Depth24:
case DepthFormat.Depth24Stencil8:
return SharpDX.DXGI.Format.D24_UNorm_S8_UInt;
}
}
static public SharpDX.DXGI.Format ToFormat(SurfaceFormat format)
{
switch (format)
{
case SurfaceFormat.Color:
default:
return SharpDX.DXGI.Format.R8G8B8A8_UNorm;
case SurfaceFormat.Bgr565:
return SharpDX.DXGI.Format.B5G6R5_UNorm;
case SurfaceFormat.Bgra5551:
return SharpDX.DXGI.Format.B5G5R5A1_UNorm;
case SurfaceFormat.Bgra4444:
#if WINDOWS_UAP
return SharpDX.DXGI.Format.B4G4R4A4_UNorm;
#else
return (SharpDX.DXGI.Format)115;
#endif
case SurfaceFormat.Dxt1:
return SharpDX.DXGI.Format.BC1_UNorm;
case SurfaceFormat.Dxt3:
return SharpDX.DXGI.Format.BC2_UNorm;
case SurfaceFormat.Dxt5:
return SharpDX.DXGI.Format.BC3_UNorm;
case SurfaceFormat.NormalizedByte2:
return SharpDX.DXGI.Format.R8G8_SNorm;
case SurfaceFormat.NormalizedByte4:
return SharpDX.DXGI.Format.R8G8B8A8_SNorm;
case SurfaceFormat.Rgba1010102:
return SharpDX.DXGI.Format.R10G10B10A2_UNorm;
case SurfaceFormat.Rg32:
return SharpDX.DXGI.Format.R16G16_UNorm;
case SurfaceFormat.Rgba64:
return SharpDX.DXGI.Format.R16G16B16A16_UNorm;
case SurfaceFormat.Alpha8:
return SharpDX.DXGI.Format.A8_UNorm;
case SurfaceFormat.Single:
return SharpDX.DXGI.Format.R32_Float;
case SurfaceFormat.HalfSingle:
return SharpDX.DXGI.Format.R16_Float;
case SurfaceFormat.HalfVector2:
return SharpDX.DXGI.Format.R16G16_Float;
case SurfaceFormat.Vector2:
return SharpDX.DXGI.Format.R32G32_Float;
case SurfaceFormat.Vector4:
return SharpDX.DXGI.Format.R32G32B32A32_Float;
case SurfaceFormat.HalfVector4:
return SharpDX.DXGI.Format.R16G16B16A16_Float;
case SurfaceFormat.HdrBlendable:
// TODO: This needs to check the graphics device and
// return the best hdr blendable format for the device.
return SharpDX.DXGI.Format.R16G16B16A16_Float;
case SurfaceFormat.Bgr32:
return SharpDX.DXGI.Format.B8G8R8X8_UNorm;
case SurfaceFormat.Bgra32:
return SharpDX.DXGI.Format.B8G8R8A8_UNorm;
case SurfaceFormat.ColorSRgb:
return SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb;
case SurfaceFormat.Bgr32SRgb:
return SharpDX.DXGI.Format.B8G8R8X8_UNorm_SRgb;
case SurfaceFormat.Bgra32SRgb:
return SharpDX.DXGI.Format.B8G8R8A8_UNorm_SRgb;
case SurfaceFormat.Dxt1SRgb:
return SharpDX.DXGI.Format.BC1_UNorm_SRgb;
case SurfaceFormat.Dxt3SRgb:
return SharpDX.DXGI.Format.BC2_UNorm_SRgb;
case SurfaceFormat.Dxt5SRgb:
return SharpDX.DXGI.Format.BC3_UNorm_SRgb;
}
}
static public RawVector2 ToVector2(this Vector2 vec)
{
return new RawVector2(vec.X, vec.Y);
}
static public RawVector3 ToVector3(this Vector3 vec)
{
return new RawVector3(vec.X, vec.Y, vec.Z);
}
static public RawVector4 ToVector4(this Vector4 vec)
{
return new RawVector4(vec.X, vec.Y, vec.Z, vec.W);
}
static public RawColor4 ToColor4(this Color color)
{
return new RawColor4(color.R / 255.0f, color.G / 255.0f, color.B / 255.0f, color.A / 255.0f);
}
static public SharpDX.Direct3D11.Comparison ToComparison(this CompareFunction compare)
{
switch (compare)
{
case CompareFunction.Always:
return SharpDX.Direct3D11.Comparison.Always;
case CompareFunction.Equal:
return SharpDX.Direct3D11.Comparison.Equal;
case CompareFunction.Greater:
return SharpDX.Direct3D11.Comparison.Greater;
case CompareFunction.GreaterEqual:
return SharpDX.Direct3D11.Comparison.GreaterEqual;
case CompareFunction.Less:
return SharpDX.Direct3D11.Comparison.Less;
case CompareFunction.LessEqual:
return SharpDX.Direct3D11.Comparison.LessEqual;
case CompareFunction.Never:
return SharpDX.Direct3D11.Comparison.Never;
case CompareFunction.NotEqual:
return SharpDX.Direct3D11.Comparison.NotEqual;
default:
throw new ArgumentException("Invalid comparison!");
}
}
}
}