OSDN Git Service

SlimDX から SharpDX へ機械的に移行。
[dtxmania/dtxmania.git] / FDK17プロジェクト / コード / 01.フレームワーク / DeviceSettings / ConversionMethods.cs
1 /*\r
2 * Copyright (c) 2007-2009 SlimDX Group\r
3\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
10\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
13\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
20 * THE SOFTWARE.\r
21 */\r
22 using SharpDX;\r
23 using SharpDX.Direct3D9;\r
24 using DXGI = SharpDX.DXGI;\r
25 \r
26 namespace SampleFramework\r
27 {\r
28     static class ConversionMethods\r
29     {\r
30         public static int GetDepthBits(Format format)\r
31         {\r
32             switch (format)\r
33             {\r
34                 case Format.D32SingleLockable:\r
35                 case Format.D32:\r
36                     return 32;\r
37 \r
38                 case Format.D24X8:\r
39                 case Format.D24S8:\r
40                 case Format.D24X4S4:\r
41                 case Format.D24SingleS8:\r
42                     return 24;\r
43 \r
44                 case Format.D16Lockable:\r
45                 case Format.D16:\r
46                     return 16;\r
47 \r
48                 case Format.D15S1:\r
49                     return 15;\r
50 \r
51                 default:\r
52                     return 0;\r
53             }\r
54         }\r
55 \r
56         public static int GetStencilBits(Format format)\r
57         {\r
58             switch (format)\r
59             {\r
60                 case Format.D15S1:\r
61                     return 1;\r
62 \r
63                 case Format.D24X4S4:\r
64                     return 4;\r
65 \r
66                 case Format.D24S8:\r
67                 case Format.D24SingleS8:\r
68                     return 8;\r
69 \r
70                 default:\r
71                     return 0;\r
72             }\r
73         }\r
74 \r
75         public static int GetColorBits(Format format)\r
76         {\r
77             switch (format)\r
78             {\r
79                 case Format.R8G8B8:\r
80                 case Format.A8R8G8B8:\r
81                 case Format.A8B8G8R8:\r
82                 case Format.X8R8G8B8:\r
83                     return 8;\r
84 \r
85                 case Format.R5G6B5:\r
86                 case Format.X1R5G5B5:\r
87                 case Format.A1R5G5B5:\r
88                     return 5;\r
89 \r
90                 case Format.A4R4G4B4:\r
91                 case Format.X4R4G4B4:\r
92                     return 4;\r
93 \r
94                 case Format.R3G3B2:\r
95                 case Format.A8R3G3B2:\r
96                     return 2;\r
97 \r
98                 case Format.A2R10G10B10:\r
99                 case Format.A2B10G10R10:\r
100                     return 10;\r
101 \r
102                 case Format.A16B16G16R16:\r
103                     return 16;\r
104 \r
105                 default:\r
106                     return 0;\r
107             }\r
108         }\r
109 \r
110         public static int GetColorBits(DXGI.Format format)\r
111         {\r
112             switch (format)\r
113             {\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
122                     return 32;\r
123 \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
130                     return 16;\r
131 \r
132                 case DXGI.Format.R10G10B10A2_Typeless:\r
133                 case DXGI.Format.R10G10B10A2_UInt:\r
134                 case DXGI.Format.R10G10B10A2_UNorm:\r
135                     return 10;\r
136 \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
143                     return 8;\r
144 \r
145                 case DXGI.Format.B5G5R5A1_UNorm:\r
146                 case DXGI.Format.B5G6R5_UNorm:\r
147                     return 5;\r
148 \r
149                 default:\r
150                     return 0;\r
151             }\r
152         }\r
153 \r
154         public static MultisampleType ToDirect3D9(int type)\r
155         {\r
156             return (MultisampleType)type;\r
157         }\r
158 \r
159         public static Format ToDirect3D9(DXGI.Format format)\r
160         {\r
161             switch (format)\r
162             {\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
170                     return Format.A8;\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
191             }\r
192 \r
193             return Format.Unknown;\r
194         }\r
195 \r
196         public static float ToFloat(DXGI.Rational rational)\r
197         {\r
198             float denom = 1;\r
199             if (rational.Denominator != 0)\r
200                 denom = rational.Denominator;\r
201             return rational.Numerator / denom;\r
202         }\r
203     }\r
204 }\r