2 * Copyright (c) 2007-2009 SlimDX Group
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
23 using SharpDX.Direct3D9;
\r
24 using DXGI = SharpDX.DXGI;
\r
26 namespace SampleFramework
\r
28 static class ConversionMethods
\r
30 public static int GetDepthBits(Format format)
\r
34 case Format.D32SingleLockable:
\r
40 case Format.D24X4S4:
\r
41 case Format.D24SingleS8:
\r
44 case Format.D16Lockable:
\r
56 public static int GetStencilBits(Format format)
\r
63 case Format.D24X4S4:
\r
67 case Format.D24SingleS8:
\r
75 public static int GetColorBits(Format format)
\r
80 case Format.A8R8G8B8:
\r
81 case Format.A8B8G8R8:
\r
82 case Format.X8R8G8B8:
\r
86 case Format.X1R5G5B5:
\r
87 case Format.A1R5G5B5:
\r
90 case Format.A4R4G4B4:
\r
91 case Format.X4R4G4B4:
\r
95 case Format.A8R3G3B2:
\r
98 case Format.A2R10G10B10:
\r
99 case Format.A2B10G10R10:
\r
102 case Format.A16B16G16R16:
\r
110 public static int GetColorBits(DXGI.Format format)
\r
114 case DXGI.Format.R32G32B32A32_Float:
\r
115 case DXGI.Format.R32G32B32A32_SInt:
\r
116 case DXGI.Format.R32G32B32A32_Typeless:
\r
117 case DXGI.Format.R32G32B32A32_UInt:
\r
118 case DXGI.Format.R32G32B32_Float:
\r
119 case DXGI.Format.R32G32B32_SInt:
\r
120 case DXGI.Format.R32G32B32_Typeless:
\r
121 case DXGI.Format.R32G32B32_UInt:
\r
124 case DXGI.Format.R16G16B16A16_Float:
\r
125 case DXGI.Format.R16G16B16A16_SInt:
\r
126 case DXGI.Format.R16G16B16A16_SNorm:
\r
127 case DXGI.Format.R16G16B16A16_Typeless:
\r
128 case DXGI.Format.R16G16B16A16_UInt:
\r
129 case DXGI.Format.R16G16B16A16_UNorm:
\r
132 case DXGI.Format.R10G10B10A2_Typeless:
\r
133 case DXGI.Format.R10G10B10A2_UInt:
\r
134 case DXGI.Format.R10G10B10A2_UNorm:
\r
137 case DXGI.Format.R8G8B8A8_SInt:
\r
138 case DXGI.Format.R8G8B8A8_SNorm:
\r
139 case DXGI.Format.R8G8B8A8_Typeless:
\r
140 case DXGI.Format.R8G8B8A8_UInt:
\r
141 case DXGI.Format.R8G8B8A8_UNorm:
\r
142 case DXGI.Format.R8G8B8A8_UNorm_SRgb:
\r
145 case DXGI.Format.B5G5R5A1_UNorm:
\r
146 case DXGI.Format.B5G6R5_UNorm:
\r
154 public static MultisampleType ToDirect3D9(int type)
\r
156 return (MultisampleType)type;
\r
159 public static Format ToDirect3D9(DXGI.Format format)
\r
163 case DXGI.Format.R8G8B8A8_UNorm:
\r
164 return Format.A8R8G8B8;
\r
165 case DXGI.Format.B5G6R5_UNorm:
\r
166 return Format.R5G6B5;
\r
167 case DXGI.Format.B5G5R5A1_UNorm:
\r
168 return Format.A1R5G5B5;
\r
169 case DXGI.Format.A8_UNorm:
\r
171 case DXGI.Format.R10G10B10A2_UNorm:
\r
172 return Format.A2B10G10R10;
\r
173 case DXGI.Format.B8G8R8A8_UNorm:
\r
174 return Format.A8B8G8R8;
\r
175 case DXGI.Format.R16G16_UNorm:
\r
176 return Format.G16R16;
\r
177 case DXGI.Format.R16G16B16A16_UNorm:
\r
178 return Format.A16B16G16R16;
\r
179 case DXGI.Format.R16_Float:
\r
180 return Format.R16F;
\r
181 case DXGI.Format.R16G16_Float:
\r
182 return Format.G16R16F;
\r
183 case DXGI.Format.R16G16B16A16_Float:
\r
184 return Format.A16B16G16R16F;
\r
185 case DXGI.Format.R32_Float:
\r
186 return Format.R32F;
\r
187 case DXGI.Format.R32G32_Float:
\r
188 return Format.G32R32F;
\r
189 case DXGI.Format.R32G32B32A32_Float:
\r
190 return Format.A32B32G32R32F;
\r
193 return Format.Unknown;
\r
196 public static float ToFloat(DXGI.Rational rational)
\r
199 if (rational.Denominator != 0)
\r
200 denom = rational.Denominator;
\r
201 return rational.Numerator / denom;
\r