Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgrhisupport_mac.mm
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#include <Metal/MTLPixelFormat.h>
8
10
12
13QRhiTexture::Format toRhiTextureFormatFromMetal(uint format, QRhiTexture::Flags *flags)
14{
15 auto rhiFormat = QRhiTexture::UnknownFormat;
16 bool sRGB = false;
17 switch (format) {
18 case MTLPixelFormatRGBA8Unorm_sRGB:
19 sRGB = true;
20 Q_FALLTHROUGH();
21 case MTLPixelFormatRGBA8Unorm:
22 case MTLPixelFormatInvalid:
23 rhiFormat = QRhiTexture::RGBA8;
24 break;
25 case MTLPixelFormatBGRA8Unorm_sRGB:
26 sRGB = true;
27 Q_FALLTHROUGH();
28 case MTLPixelFormatBGRA8Unorm:
29 rhiFormat = QRhiTexture::BGRA8;
30 break;
31#ifndef Q_OS_MACOS
32 case MTLPixelFormatR8Unorm_sRGB:
33 sRGB = true;
34 Q_FALLTHROUGH();
35#endif
36 case MTLPixelFormatR8Unorm:
37 rhiFormat = QRhiTexture::R8;
38 break;
39#ifndef Q_OS_MACOS
40 case MTLPixelFormatRG8Unorm_sRGB:
41 sRGB = true;
42 Q_FALLTHROUGH();
43#endif
44 case MTLPixelFormatRG8Unorm:
45 rhiFormat = QRhiTexture::RG8;
46 break;
47 case MTLPixelFormatR16Unorm:
48 rhiFormat = QRhiTexture::R16;
49 break;
50 case MTLPixelFormatRG16Unorm:
51 rhiFormat = QRhiTexture::RG16;
52 break;
53 case MTLPixelFormatRGBA16Float:
54 rhiFormat = QRhiTexture::RGBA16F;
55 break;
56 case MTLPixelFormatRGBA32Float:
57 rhiFormat = QRhiTexture::RGBA32F;
58 break;
59 case MTLPixelFormatR16Float:
60 rhiFormat = QRhiTexture::R16F;
61 break;
62 case MTLPixelFormatR32Float:
63 rhiFormat = QRhiTexture::R32F;
64 break;
65 case MTLPixelFormatRGB10A2Unorm:
66 rhiFormat = QRhiTexture::RGB10A2;
67 break;
68#ifdef Q_OS_MACOS
69 case MTLPixelFormatDepth16Unorm:
70 rhiFormat = QRhiTexture::D16;
71 break;
72 case MTLPixelFormatDepth24Unorm_Stencil8:
73 rhiFormat = QRhiTexture::D24S8;
74 break;
75#endif
76 case MTLPixelFormatDepth32Float_Stencil8:
77 rhiFormat = QRhiTexture::D24S8;
78 break;
79 case MTLPixelFormatDepth32Float:
80 rhiFormat = QRhiTexture::D32F;
81 break;
82#ifdef Q_OS_MACOS
83 case MTLPixelFormatBC1_RGBA_sRGB:
84 sRGB = true;
85 Q_FALLTHROUGH();
86 case MTLPixelFormatBC1_RGBA:
87 rhiFormat = QRhiTexture::BC1;
88 break;
89 case MTLPixelFormatBC2_RGBA_sRGB:
90 sRGB = true;
91 Q_FALLTHROUGH();
92 case MTLPixelFormatBC2_RGBA:
93 rhiFormat = QRhiTexture::BC2;
94 break;
95 case MTLPixelFormatBC3_RGBA_sRGB:
96 sRGB = true;
97 Q_FALLTHROUGH();
98 case MTLPixelFormatBC3_RGBA:
99 rhiFormat = QRhiTexture::BC3;
100 break;
101 case MTLPixelFormatBC4_RUnorm:
102 rhiFormat = QRhiTexture::BC4;
103 break;
104 case MTLPixelFormatBC6H_RGBUfloat:
105 rhiFormat = QRhiTexture::BC6H;
106 break;
107 case MTLPixelFormatBC7_RGBAUnorm_sRGB:
108 sRGB = true;
109 Q_FALLTHROUGH();
110 case MTLPixelFormatBC7_RGBAUnorm:
111 rhiFormat = QRhiTexture::BC7;
112 break;
113#endif
114#ifndef Q_OS_MACOS
115 case MTLPixelFormatETC2_RGB8_sRGB:
116 sRGB = true;
117 Q_FALLTHROUGH();
118 case MTLPixelFormatETC2_RGB8:
119 rhiFormat = QRhiTexture::ETC2_RGB8;
120 break;
121 case MTLPixelFormatETC2_RGB8A1_sRGB:
122 sRGB = true;
123 Q_FALLTHROUGH();
124 case MTLPixelFormatETC2_RGB8A1:
125 rhiFormat = QRhiTexture::ETC2_RGB8A1;
126 break;
127 case MTLPixelFormatEAC_RGBA8_sRGB:
128 sRGB = true;
129 Q_FALLTHROUGH();
130 case MTLPixelFormatEAC_RGBA8:
131 rhiFormat = QRhiTexture::ETC2_RGBA8;
132 break;
133 case MTLPixelFormatASTC_4x4_sRGB:
134 sRGB = true;
135 Q_FALLTHROUGH();
136 case MTLPixelFormatASTC_4x4_LDR:
137 rhiFormat = QRhiTexture::ASTC_4x4;
138 break;
139 case MTLPixelFormatASTC_5x4_sRGB:
140 sRGB = true;
141 Q_FALLTHROUGH();
142 case MTLPixelFormatASTC_5x4_LDR:
143 rhiFormat = QRhiTexture::ASTC_5x4;
144 break;
145 case MTLPixelFormatASTC_5x5_sRGB:
146 sRGB = true;
147 Q_FALLTHROUGH();
148 case MTLPixelFormatASTC_5x5_LDR:
149 rhiFormat = QRhiTexture::ASTC_5x5;
150 break;
151 case MTLPixelFormatASTC_6x5_sRGB:
152 sRGB = true;
153 Q_FALLTHROUGH();
154 case MTLPixelFormatASTC_6x5_LDR:
155 rhiFormat = QRhiTexture::ASTC_6x5;
156 break;
157 case MTLPixelFormatASTC_6x6_sRGB:
158 sRGB = true;
159 Q_FALLTHROUGH();
160 case MTLPixelFormatASTC_6x6_LDR:
161 rhiFormat = QRhiTexture::ASTC_6x6;
162 break;
163 case MTLPixelFormatASTC_8x5_sRGB:
164 sRGB = true;
165 Q_FALLTHROUGH();
166 case MTLPixelFormatASTC_8x5_LDR:
167 rhiFormat = QRhiTexture::ASTC_8x5;
168 break;
169 case MTLPixelFormatASTC_8x6_sRGB:
170 sRGB = true;
171 Q_FALLTHROUGH();
172 case MTLPixelFormatASTC_8x6_LDR:
173 rhiFormat = QRhiTexture::ASTC_8x6;
174 break;
175 case MTLPixelFormatASTC_8x8_sRGB:
176 sRGB = true;
177 Q_FALLTHROUGH();
178 case MTLPixelFormatASTC_8x8_LDR:
179 rhiFormat = QRhiTexture::ASTC_8x8;
180 break;
181 case MTLPixelFormatASTC_10x5_sRGB:
182 sRGB = true;
183 Q_FALLTHROUGH();
184 case MTLPixelFormatASTC_10x5_LDR:
185 rhiFormat = QRhiTexture::ASTC_10x5;
186 break;
187 case MTLPixelFormatASTC_10x6_sRGB:
188 sRGB = true;
189 Q_FALLTHROUGH();
190 case MTLPixelFormatASTC_10x6_LDR:
191 rhiFormat = QRhiTexture::ASTC_10x6;
192 break;
193 case MTLPixelFormatASTC_10x8_sRGB:
194 sRGB = true;
195 Q_FALLTHROUGH();
196 case MTLPixelFormatASTC_10x8_LDR:
197 rhiFormat = QRhiTexture::ASTC_10x8;
198 break;
199 case MTLPixelFormatASTC_10x10_sRGB:
200 sRGB = true;
201 Q_FALLTHROUGH();
202 case MTLPixelFormatASTC_10x10_LDR:
203 rhiFormat = QRhiTexture::ASTC_10x10;
204 break;
205 case MTLPixelFormatASTC_12x10_sRGB:
206 sRGB = true;
207 Q_FALLTHROUGH();
208 case MTLPixelFormatASTC_12x10_LDR:
209 rhiFormat = QRhiTexture::ASTC_12x10;
210 break;
211 case MTLPixelFormatASTC_12x12_sRGB:
212 sRGB = true;
213 Q_FALLTHROUGH();
214 case MTLPixelFormatASTC_12x12_LDR:
215 rhiFormat = QRhiTexture::ASTC_12x12;
216 break;
217#endif
218 default:
219 qWarning("MTLPixelFormat %d is not supported", format);
220 break;
221 }
222 if (sRGB)
223 (*flags) |=(QRhiTexture::sRGB);
224 return rhiFormat;
225}
226
227}
228
229QT_END_NAMESPACE
QRhiTexture::Format toRhiTextureFormatFromMetal(uint format, QRhiTexture::Flags *flags)
Combined button and popup list for selecting options.