• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // d3d_format: Describes a D3D9 format. Used by the D3D9 and GL back-ends.
7 
8 #include "libANGLE/renderer/d3d_format.h"
9 
10 using namespace angle;
11 
12 namespace rx
13 {
14 namespace d3d9
15 {
16 namespace
17 {
18 constexpr D3DFORMAT D3DFMT_INTZ = ((D3DFORMAT)(MAKEFOURCC('I', 'N', 'T', 'Z')));
19 constexpr D3DFORMAT D3DFMT_NULL = ((D3DFORMAT)(MAKEFOURCC('N', 'U', 'L', 'L')));
20 }  // anonymous namespace
21 
D3DFormat()22 D3DFormat::D3DFormat()
23     : pixelBytes(0),
24       blockWidth(0),
25       blockHeight(0),
26       redBits(0),
27       greenBits(0),
28       blueBits(0),
29       alphaBits(0),
30       luminanceBits(0),
31       depthBits(0),
32       stencilBits(0),
33       formatID(angle::FormatID::NONE)
34 {}
35 
D3DFormat(GLuint bits,GLuint blockWidth,GLuint blockHeight,GLuint redBits,GLuint greenBits,GLuint blueBits,GLuint alphaBits,GLuint lumBits,GLuint depthBits,GLuint stencilBits,FormatID formatID)36 D3DFormat::D3DFormat(GLuint bits,
37                      GLuint blockWidth,
38                      GLuint blockHeight,
39                      GLuint redBits,
40                      GLuint greenBits,
41                      GLuint blueBits,
42                      GLuint alphaBits,
43                      GLuint lumBits,
44                      GLuint depthBits,
45                      GLuint stencilBits,
46                      FormatID formatID)
47     : pixelBytes(bits / 8),
48       blockWidth(blockWidth),
49       blockHeight(blockHeight),
50       redBits(redBits),
51       greenBits(greenBits),
52       blueBits(blueBits),
53       alphaBits(alphaBits),
54       luminanceBits(lumBits),
55       depthBits(depthBits),
56       stencilBits(stencilBits),
57       formatID(formatID)
58 {}
59 
GetD3DFormatInfo(D3DFORMAT format)60 const D3DFormat &GetD3DFormatInfo(D3DFORMAT format)
61 {
62     if (format == D3DFMT_NULL)
63     {
64         static const D3DFormat info(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FormatID::NONE);
65         return info;
66     }
67 
68     if (format == D3DFMT_INTZ)
69     {
70         static const D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 24, 8, FormatID::D24_UNORM_S8_UINT);
71         return info;
72     }
73 
74     switch (format)
75     {
76         case D3DFMT_UNKNOWN:
77         {
78             static const D3DFormat info(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FormatID::NONE);
79             return info;
80         }
81 
82         case D3DFMT_L8:
83         {
84             static const D3DFormat info(8, 1, 1, 0, 0, 0, 0, 8, 0, 0, FormatID::L8_UNORM);
85             return info;
86         }
87         case D3DFMT_A8:
88         {
89             static const D3DFormat info(8, 1, 1, 0, 0, 0, 8, 0, 0, 0, FormatID::A8_UNORM);
90             return info;
91         }
92         case D3DFMT_A8L8:
93         {
94             static const D3DFormat info(16, 1, 1, 0, 0, 0, 8, 8, 0, 0, FormatID::L8A8_UNORM);
95             return info;
96         }
97 
98         case D3DFMT_A4R4G4B4:
99         {
100             static const D3DFormat info(16, 1, 1, 4, 4, 4, 4, 0, 0, 0, FormatID::B4G4R4A4_UNORM);
101             return info;
102         }
103         case D3DFMT_A1R5G5B5:
104         {
105             static const D3DFormat info(16, 1, 1, 5, 5, 5, 1, 0, 0, 0, FormatID::B5G5R5A1_UNORM);
106             return info;
107         }
108         case D3DFMT_R5G6B5:
109         {
110             static const D3DFormat info(16, 1, 1, 5, 6, 5, 0, 0, 0, 0, FormatID::R5G6B5_UNORM);
111             return info;
112         }
113         case D3DFMT_X8R8G8B8:
114         {
115             static const D3DFormat info(32, 1, 1, 8, 8, 8, 0, 0, 0, 0, FormatID::B8G8R8X8_UNORM);
116             return info;
117         }
118         case D3DFMT_A8R8G8B8:
119         {
120             static const D3DFormat info(32, 1, 1, 8, 8, 8, 8, 0, 0, 0, FormatID::B8G8R8A8_UNORM);
121             return info;
122         }
123 
124         case D3DFMT_R16F:
125         {
126             static const D3DFormat info(16, 1, 1, 16, 0, 0, 0, 0, 0, 0, FormatID::R16_FLOAT);
127             return info;
128         }
129         case D3DFMT_G16R16F:
130         {
131             static const D3DFormat info(32, 1, 1, 16, 16, 0, 0, 0, 0, 0, FormatID::R16G16_FLOAT);
132             return info;
133         }
134         case D3DFMT_A16B16G16R16F:
135         {
136             static const D3DFormat info(64, 1, 1, 16, 16, 16, 16, 0, 0, 0,
137                                         FormatID::R16G16B16A16_FLOAT);
138             return info;
139         }
140         case D3DFMT_R32F:
141         {
142             static const D3DFormat info(32, 1, 1, 32, 0, 0, 0, 0, 0, 0, FormatID::R32_FLOAT);
143             return info;
144         }
145         case D3DFMT_G32R32F:
146         {
147             static const D3DFormat info(64, 1, 1, 32, 32, 0, 0, 0, 0, 0, FormatID::R32G32_FLOAT);
148             return info;
149         }
150         case D3DFMT_A32B32G32R32F:
151         {
152             static const D3DFormat info(128, 1, 1, 32, 32, 32, 32, 0, 0, 0,
153                                         FormatID::R32G32B32A32_FLOAT);
154             return info;
155         }
156 
157         case D3DFMT_D16:
158         {
159             static const D3DFormat info(16, 1, 1, 0, 0, 0, 0, 0, 16, 0, FormatID::D16_UNORM);
160             return info;
161         }
162         case D3DFMT_D24S8:
163         {
164             static const D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 24, 8,
165                                         FormatID::D24_UNORM_S8_UINT);
166             return info;
167         }
168         case D3DFMT_D24X8:
169         {
170             static const D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 24, 0, FormatID::D16_UNORM);
171             return info;
172         }
173         case D3DFMT_D32:
174         {
175             static const D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 32, 0, FormatID::D32_UNORM);
176             return info;
177         }
178 
179         case D3DFMT_DXT1:
180         {
181             static const D3DFormat info(64, 4, 4, 0, 0, 0, 0, 0, 0, 0,
182                                         FormatID::BC1_RGBA_UNORM_BLOCK);
183             return info;
184         }
185         case D3DFMT_DXT3:
186         {
187             static const D3DFormat info(128, 4, 4, 0, 0, 0, 0, 0, 0, 0,
188                                         FormatID::BC2_RGBA_UNORM_BLOCK);
189             return info;
190         }
191         case D3DFMT_DXT5:
192         {
193             static const D3DFormat info(128, 4, 4, 0, 0, 0, 0, 0, 0, 0,
194                                         FormatID::BC3_RGBA_UNORM_BLOCK);
195             return info;
196         }
197 
198         default:
199         {
200             static const D3DFormat defaultInfo;
201             return defaultInfo;
202         }
203     }
204 }
205 }  // namespace d3d9
206 }  // namespace rx
207