blob: 47838ef358adc7c4c93058109dfd11a47860013d [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001#include "precompiled.h"
2//
3// Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// formatutils9.cpp: Queries for GL image formats and their translations to D3D9
9// formats.
10
11#include "libGLESv2/renderer/formatutils9.h"
12#include "libGLESv2/renderer/Renderer9.h"
13#include "libGLESv2/renderer/generatemip.h"
14#include "libGLESv2/renderer/loadimage.h"
15
16namespace rx
17{
18
19// Each GL internal format corresponds to one D3D format and data loading function.
20// Due to not all formats being available all the time, some of the function/format types are wrapped
21// in templates that perform format support queries on a Renderer9 object which is supplied
22// when requesting the function or format.
23
24typedef bool ((Renderer9::*Renderer9FormatCheckFunction)(void) const);
25typedef LoadImageFunction (*RendererCheckLoadFunction)(const Renderer9 *renderer);
26
27template <Renderer9FormatCheckFunction pred, LoadImageFunction prefered, LoadImageFunction fallback>
28LoadImageFunction RendererCheckLoad(const Renderer9 *renderer)
29{
30 return ((renderer->*pred)()) ? prefered : fallback;
31}
32
33template <LoadImageFunction loadFunc>
34LoadImageFunction SimpleLoad(const Renderer9 *renderer)
35{
36 return loadFunc;
37}
38
39LoadImageFunction UnreachableLoad(const Renderer9 *renderer)
40{
41 UNREACHABLE();
42 return NULL;
43}
44
45typedef bool (*FallbackPredicateFunction)(void);
46
47template <FallbackPredicateFunction pred, LoadImageFunction prefered, LoadImageFunction fallback>
48LoadImageFunction FallbackLoadFunction(const Renderer9 *renderer)
49{
50 return pred() ? prefered : fallback;
51}
52
53typedef D3DFORMAT (*FormatQueryFunction)(const rx::Renderer9 *renderer);
54
55template <Renderer9FormatCheckFunction pred, D3DFORMAT prefered, D3DFORMAT fallback>
56D3DFORMAT CheckFormatSupport(const rx::Renderer9 *renderer)
57{
58 return (renderer->*pred)() ? prefered : fallback;
59}
60
61template <D3DFORMAT format>
62D3DFORMAT D3D9Format(const rx::Renderer9 *renderer)
63{
64 return format;
65}
66
67struct D3D9FormatInfo
68{
69 FormatQueryFunction mTexFormat;
70 FormatQueryFunction mRenderFormat;
71 RendererCheckLoadFunction mLoadFunction;
72
73 D3D9FormatInfo()
74 : mTexFormat(NULL), mRenderFormat(NULL), mLoadFunction(NULL)
75 { }
76
77 D3D9FormatInfo(FormatQueryFunction textureFormat, FormatQueryFunction renderFormat, RendererCheckLoadFunction loadFunc)
78 : mTexFormat(textureFormat), mRenderFormat(renderFormat), mLoadFunction(loadFunc)
79 { }
80};
81
82const D3DFORMAT D3DFMT_INTZ = ((D3DFORMAT)(MAKEFOURCC('I','N','T','Z')));
83const D3DFORMAT D3DFMT_NULL = ((D3DFORMAT)(MAKEFOURCC('N','U','L','L')));
84
85typedef std::pair<GLint, D3D9FormatInfo> D3D9FormatPair;
86typedef std::map<GLint, D3D9FormatInfo> D3D9FormatMap;
87
88static D3D9FormatMap buildD3D9FormatMap()
89{
90 D3D9FormatMap map;
91
92 // | Internal format | Texture format | Render format | Load function |
93 map.insert(D3D9FormatPair(GL_NONE, D3D9FormatInfo(D3D9Format<D3DFMT_NULL>, D3D9Format<D3DFMT_NULL>, UnreachableLoad )));
94
95 map.insert(D3D9FormatPair(GL_DEPTH_COMPONENT16, D3D9FormatInfo(D3D9Format<D3DFMT_INTZ>, D3D9Format<D3DFMT_D24S8>, UnreachableLoad )));
96 map.insert(D3D9FormatPair(GL_DEPTH_COMPONENT32_OES, D3D9FormatInfo(D3D9Format<D3DFMT_INTZ>, D3D9Format<D3DFMT_D32>, UnreachableLoad )));
97 map.insert(D3D9FormatPair(GL_DEPTH24_STENCIL8_OES, D3D9FormatInfo(D3D9Format<D3DFMT_INTZ>, D3D9Format<D3DFMT_D24S8>, UnreachableLoad )));
98 map.insert(D3D9FormatPair(GL_STENCIL_INDEX8, D3D9FormatInfo(D3D9Format<D3DFMT_UNKNOWN>, D3D9Format<D3DFMT_D24S8>, UnreachableLoad ))); // TODO: What's the texture format?
99
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000100 map.insert(D3D9FormatPair(GL_RGBA32F_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A32B32G32R32F>, D3D9Format<D3DFMT_A32B32G32R32F>, SimpleLoad<loadToNative<GLfloat, 4> > )));
101 map.insert(D3D9FormatPair(GL_RGB32F_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A32B32G32R32F>, D3D9Format<D3DFMT_A32B32G32R32F>, SimpleLoad<loadToNative<GLfloat, 3> > )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000102 map.insert(D3D9FormatPair(GL_ALPHA32F_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A32B32G32R32F>, D3D9Format<D3DFMT_UNKNOWN>, SimpleLoad<loadAlphaFloatDataToRGBA> )));
103 map.insert(D3D9FormatPair(GL_LUMINANCE32F_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A32B32G32R32F>, D3D9Format<D3DFMT_UNKNOWN>, SimpleLoad<loadLuminanceFloatDataToRGBA> )));
104 map.insert(D3D9FormatPair(GL_LUMINANCE_ALPHA32F_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A32B32G32R32F>, D3D9Format<D3DFMT_UNKNOWN>, SimpleLoad<loadLuminanceAlphaFloatDataToRGBA> )));
105
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000106 map.insert(D3D9FormatPair(GL_RGBA16F_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A16B16G16R16F>, D3D9Format<D3DFMT_A16B16G16R16F>, SimpleLoad<loadToNative<GLhalf, 4>> )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000107 map.insert(D3D9FormatPair(GL_RGB16F_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A16B16G16R16F>, D3D9Format<D3DFMT_A16B16G16R16F>, SimpleLoad<loadRGBHalfFloatDataToRGBA> )));
108 map.insert(D3D9FormatPair(GL_ALPHA16F_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A16B16G16R16F>, D3D9Format<D3DFMT_UNKNOWN>, SimpleLoad<loadAlphaHalfFloatDataToRGBA> )));
109 map.insert(D3D9FormatPair(GL_LUMINANCE16F_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A16B16G16R16F>, D3D9Format<D3DFMT_UNKNOWN>, SimpleLoad<loadLuminanceHalfFloatDataToRGBA> )));
110 map.insert(D3D9FormatPair(GL_LUMINANCE_ALPHA16F_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A16B16G16R16F>, D3D9Format<D3DFMT_UNKNOWN>, SimpleLoad<loadLuminanceAlphaHalfFloatDataToRGBA>)));
111
112 map.insert(D3D9FormatPair(GL_ALPHA8_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A8R8G8B8>, D3D9Format<D3DFMT_A8R8G8B8>, FallbackLoadFunction<gl::supportsSSE2, loadAlphaDataToBGRASSE2, loadAlphaDataToBGRA>)));
113
114 map.insert(D3D9FormatPair(GL_RGB8_OES, D3D9FormatInfo(D3D9Format<D3DFMT_X8R8G8B8>, D3D9Format<D3DFMT_X8R8G8B8>, SimpleLoad<loadRGBUByteDataToBGRX> )));
115 map.insert(D3D9FormatPair(GL_RGB565, D3D9FormatInfo(D3D9Format<D3DFMT_X8R8G8B8>, D3D9Format<D3DFMT_R5G6B5>, SimpleLoad<loadRGB565DataToBGRA> )));
116 map.insert(D3D9FormatPair(GL_RGBA8_OES, D3D9FormatInfo(D3D9Format<D3DFMT_A8R8G8B8>, D3D9Format<D3DFMT_A8R8G8B8>, FallbackLoadFunction<gl::supportsSSE2, loadRGBAUByteDataToBGRASSE2, loadRGBAUByteDataToBGRA>)));
117 map.insert(D3D9FormatPair(GL_RGBA4, D3D9FormatInfo(D3D9Format<D3DFMT_A8R8G8B8>, D3D9Format<D3DFMT_A8R8G8B8>, SimpleLoad<loadRGBA4444DataToBGRA> )));
118 map.insert(D3D9FormatPair(GL_RGB5_A1, D3D9FormatInfo(D3D9Format<D3DFMT_A8R8G8B8>, D3D9Format<D3DFMT_A8R8G8B8>, SimpleLoad<loadRGBA5551DataToBGRA> )));
119
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000120 map.insert(D3D9FormatPair(GL_BGRA8_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_A8R8G8B8>, D3D9Format<D3DFMT_A8R8G8B8>, SimpleLoad<loadToNative<GLubyte, 4> > )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000121 map.insert(D3D9FormatPair(GL_BGRA4_ANGLEX, D3D9FormatInfo(D3D9Format<D3DFMT_A8R8G8B8>, D3D9Format<D3DFMT_A8R8G8B8>, SimpleLoad<loadRGBA4444DataToRGBA> )));
122 map.insert(D3D9FormatPair(GL_BGR5_A1_ANGLEX, D3D9FormatInfo(D3D9Format<D3DFMT_A8R8G8B8>, D3D9Format<D3DFMT_A8R8G8B8>, SimpleLoad<loadRGBA5551DataToRGBA> )));
123
124 map.insert(D3D9FormatPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_DXT1>, D3D9Format<D3DFMT_UNKNOWN>, SimpleLoad<loadCompressedBlockDataToNative<4, 4, 8> >)));
125 map.insert(D3D9FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, D3D9FormatInfo(D3D9Format<D3DFMT_DXT1>, D3D9Format<D3DFMT_UNKNOWN>, SimpleLoad<loadCompressedBlockDataToNative<4, 4, 8> >)));
126 map.insert(D3D9FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, D3D9FormatInfo(D3D9Format<D3DFMT_DXT3>, D3D9Format<D3DFMT_UNKNOWN>, SimpleLoad<loadCompressedBlockDataToNative<4, 4, 16> >)));
127 map.insert(D3D9FormatPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, D3D9FormatInfo(D3D9Format<D3DFMT_DXT5>, D3D9Format<D3DFMT_UNKNOWN>, SimpleLoad<loadCompressedBlockDataToNative<4, 4, 16> >)));
128
129 // These formats require checking if the renderer supports D3DFMT_L8 or D3DFMT_A8L8 and
130 // then changing the format and loading function appropriately.
shannonwoods@chromium.org8d46e912013-05-30 00:14:32 +0000131 map.insert(D3D9FormatPair(GL_LUMINANCE8_EXT, D3D9FormatInfo(CheckFormatSupport<&Renderer9::getLuminanceTextureSupport, D3DFMT_L8, D3DFMT_A8R8G8B8>, D3D9Format<D3DFMT_UNKNOWN>, RendererCheckLoad<&Renderer9::getLuminanceTextureSupport, loadToNative<GLubyte, 1>, loadLuminanceDataToBGRA>)));
132 map.insert(D3D9FormatPair(GL_LUMINANCE8_ALPHA8_EXT, D3D9FormatInfo(CheckFormatSupport<&Renderer9::getLuminanceAlphaTextureSupport, D3DFMT_A8L8, D3DFMT_A8R8G8B8>, D3D9Format<D3DFMT_UNKNOWN>, RendererCheckLoad<&Renderer9::getLuminanceTextureSupport, loadToNative<GLubyte, 2>, loadLuminanceAlphaDataToBGRA>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000133
134 return map;
135}
136
137static bool getD3D9FormatInfo(GLint internalFormat, D3D9FormatInfo *outFormatInfo)
138{
139 static const D3D9FormatMap formatMap = buildD3D9FormatMap();
140 D3D9FormatMap::const_iterator iter = formatMap.find(internalFormat);
141 if (iter != formatMap.end())
142 {
143 if (outFormatInfo)
144 {
145 *outFormatInfo = iter->second;
146 }
147 return true;
148 }
149 else
150 {
151 return false;
152 }
153}
154
155// A map for determining the mip map generation function given a texture's internal D3D format
156typedef std::pair<D3DFORMAT, MipGenerationFunction> FormatMipPair;
157typedef std::map<D3DFORMAT, MipGenerationFunction> FormatMipMap;
158
159static FormatMipMap buildFormatMipMap()
160{
161 FormatMipMap map;
162
163 // | D3DFORMAT | Mip generation function |
164 map.insert(FormatMipPair(D3DFMT_L8, GenerateMip<L8> ));
165 map.insert(FormatMipPair(D3DFMT_A8L8, GenerateMip<A8L8> ));
166 map.insert(FormatMipPair(D3DFMT_A8R8G8B8, GenerateMip<A8R8G8B8> ));
167 map.insert(FormatMipPair(D3DFMT_X8R8G8B8, GenerateMip<A8R8G8B8> ));
168 map.insert(FormatMipPair(D3DFMT_A16B16G16R16F, GenerateMip<A16B16G16R16F>));
169 map.insert(FormatMipPair(D3DFMT_A32B32G32R32F, GenerateMip<A32B32G32R32F>));
170
171 return map;
172}
173
174// A map to determine the pixel size of a given D3D format
175struct D3DFormatInfo
176{
177 GLuint mPixelBits;
178 GLuint mBlockWidth;
179 GLuint mBlockHeight;
180 GLint mInternalFormat;
181
182 D3DFormatInfo()
183 : mPixelBits(0), mBlockWidth(0), mBlockHeight(0), mInternalFormat(GL_NONE)
184 { }
185
186 D3DFormatInfo(GLuint pixelBits, GLuint blockWidth, GLuint blockHeight, GLint internalFormat)
187 : mPixelBits(pixelBits), mBlockWidth(blockWidth), mBlockHeight(blockHeight), mInternalFormat(internalFormat)
188 { }
189};
190
191typedef std::pair<D3DFORMAT, D3DFormatInfo> D3D9FormatInfoPair;
192typedef std::map<D3DFORMAT, D3DFormatInfo> D3D9FormatInfoMap;
193
194static D3D9FormatInfoMap buildD3D9FormatInfoMap()
195{
196 D3D9FormatInfoMap map;
197
198 // | D3DFORMAT | | S |W |H | Internal format |
199 map.insert(D3D9FormatInfoPair(D3DFMT_NULL, D3DFormatInfo( 0, 0, 0, GL_NONE )));
200 map.insert(D3D9FormatInfoPair(D3DFMT_UNKNOWN, D3DFormatInfo( 0, 0, 0, GL_NONE )));
201
202 map.insert(D3D9FormatInfoPair(D3DFMT_L8, D3DFormatInfo( 8, 1, 1, GL_LUMINANCE8_EXT )));
203 map.insert(D3D9FormatInfoPair(D3DFMT_A8, D3DFormatInfo( 8, 1, 1, GL_ALPHA8_EXT )));
204 map.insert(D3D9FormatInfoPair(D3DFMT_A8L8, D3DFormatInfo( 16, 1, 1, GL_LUMINANCE8_ALPHA8_EXT )));
205 map.insert(D3D9FormatInfoPair(D3DFMT_A4R4G4B4, D3DFormatInfo( 16, 1, 1, GL_RGBA4 )));
206 map.insert(D3D9FormatInfoPair(D3DFMT_A1R5G5B5, D3DFormatInfo( 16, 1, 1, GL_RGB5_A1 )));
207 map.insert(D3D9FormatInfoPair(D3DFMT_R5G6B5, D3DFormatInfo( 16, 1, 1, GL_RGB565 )));
208 map.insert(D3D9FormatInfoPair(D3DFMT_X8R8G8B8, D3DFormatInfo( 32, 1, 1, GL_RGB8_OES )));
209 map.insert(D3D9FormatInfoPair(D3DFMT_A8R8G8B8, D3DFormatInfo( 32, 1, 1, GL_RGBA8_OES )));
210 map.insert(D3D9FormatInfoPair(D3DFMT_A16B16G16R16F, D3DFormatInfo( 64, 1, 1, GL_RGBA16F_EXT )));
211 map.insert(D3D9FormatInfoPair(D3DFMT_A32B32G32R32F, D3DFormatInfo(128, 1, 1, GL_RGBA32F_EXT )));
212
213 map.insert(D3D9FormatInfoPair(D3DFMT_D16, D3DFormatInfo( 16, 1, 1, GL_DEPTH_COMPONENT16 )));
214 map.insert(D3D9FormatInfoPair(D3DFMT_D24S8, D3DFormatInfo( 32, 1, 1, GL_DEPTH24_STENCIL8_OES )));
215 map.insert(D3D9FormatInfoPair(D3DFMT_D24X8, D3DFormatInfo( 32, 1, 1, GL_DEPTH_COMPONENT16 )));
216 map.insert(D3D9FormatInfoPair(D3DFMT_D32, D3DFormatInfo( 32, 1, 1, GL_DEPTH_COMPONENT32_OES )));
217
218 map.insert(D3D9FormatInfoPair(D3DFMT_INTZ, D3DFormatInfo( 32, 1, 1, GL_DEPTH24_STENCIL8_OES )));
219
220 map.insert(D3D9FormatInfoPair(D3DFMT_DXT1, D3DFormatInfo( 64, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT )));
221 map.insert(D3D9FormatInfoPair(D3DFMT_DXT3, D3DFormatInfo(128, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE)));
222 map.insert(D3D9FormatInfoPair(D3DFMT_DXT5, D3DFormatInfo(128, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE)));
223
224 return map;
225}
226
227static bool getD3D9FormatInfo(D3DFORMAT format, D3DFormatInfo *outFormatInfo)
228{
229 static const D3D9FormatInfoMap infoMap = buildD3D9FormatInfoMap();
230 D3D9FormatInfoMap::const_iterator iter = infoMap.find(format);
231 if (iter != infoMap.end())
232 {
233 if (outFormatInfo)
234 {
235 *outFormatInfo = iter->second;
236 }
237 return true;
238 }
239 else
240 {
241 return false;
242 }
243}
244
245namespace d3d9
246{
247
248MipGenerationFunction GetMipGenerationFunction(D3DFORMAT format)
249{
250 static const FormatMipMap mipFunctionMap = buildFormatMipMap();
251 FormatMipMap::const_iterator iter = mipFunctionMap.find(format);
252 if (iter != mipFunctionMap.end())
253 {
254 return iter->second;
255 }
256 else
257 {
258 UNREACHABLE();
259 return NULL;
260 }
261}
262
263LoadImageFunction GetImageLoadFunction(GLint internalFormat, const Renderer9 *renderer)
264{
265 if (!renderer)
266 {
267 return NULL;
268 }
269
270 ASSERT(renderer->getCurrentClientVersion() == 2);
271
272 D3D9FormatInfo d3d9FormatInfo;
273 if (getD3D9FormatInfo(internalFormat, &d3d9FormatInfo))
274 {
275 return d3d9FormatInfo.mLoadFunction(renderer);
276 }
277 else
278 {
279 UNREACHABLE();
280 return NULL;
281 }
282}
283
284GLuint GetFormatPixelBytes(D3DFORMAT format)
285{
286 D3DFormatInfo d3dFormatInfo;
287 if (getD3D9FormatInfo(format, &d3dFormatInfo))
288 {
289 return d3dFormatInfo.mPixelBits / 8;
290 }
291 else
292 {
293 UNREACHABLE();
294 return 0;
295 }
296}
297
298GLuint GetBlockWidth(D3DFORMAT format)
299{
300 D3DFormatInfo d3dFormatInfo;
301 if (getD3D9FormatInfo(format, &d3dFormatInfo))
302 {
303 return d3dFormatInfo.mBlockWidth;
304 }
305 else
306 {
307 UNREACHABLE();
308 return 0;
309 }
310}
311
312GLuint GetBlockHeight(D3DFORMAT format)
313{
314 D3DFormatInfo d3dFormatInfo;
315 if (getD3D9FormatInfo(format, &d3dFormatInfo))
316 {
317 return d3dFormatInfo.mBlockHeight;
318 }
319 else
320 {
321 UNREACHABLE();
322 return 0;
323 }
324}
325
326GLuint GetBlockSize(D3DFORMAT format, GLuint width, GLuint height)
327{
328 D3DFormatInfo d3dFormatInfo;
329 if (getD3D9FormatInfo(format, &d3dFormatInfo))
330 {
331 GLuint numBlocksWide = (width + d3dFormatInfo.mBlockWidth - 1) / d3dFormatInfo.mBlockWidth;
332 GLuint numBlocksHight = (height + d3dFormatInfo.mBlockHeight - 1) / d3dFormatInfo.mBlockHeight;
333
334 return (d3dFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
335 }
336 else
337 {
338 UNREACHABLE();
339 return 0;
340 }
341}
342
343void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset)
344{
345 D3DFormatInfo d3dFormatInfo;
346 if (getD3D9FormatInfo(format, &d3dFormatInfo))
347 {
348 int upsampleCount = 0;
349
350 GLsizei blockWidth = d3dFormatInfo.mBlockWidth;
351 GLsizei blockHeight = d3dFormatInfo.mBlockHeight;
352
353 // Don't expand the size of full textures that are at least (blockWidth x blockHeight) already.
354 if (isImage || *requestWidth < blockWidth || *requestHeight < blockHeight)
355 {
356 while (*requestWidth % blockWidth != 0 || *requestHeight % blockHeight != 0)
357 {
358 *requestWidth <<= 1;
359 *requestHeight <<= 1;
360 upsampleCount++;
361 }
362 }
363 *levelOffset = upsampleCount;
364 }
365}
366
367}
368
369namespace gl_d3d9
370{
371
372D3DFORMAT GetTexureFormat(GLint internalFormat, const Renderer9 *renderer)
373{
374 if (!renderer)
375 {
376 UNREACHABLE();
377 return D3DFMT_UNKNOWN;
378 }
379
380 ASSERT(renderer->getCurrentClientVersion() == 2);
381
382 D3D9FormatInfo d3d9FormatInfo;
383 if (getD3D9FormatInfo(internalFormat, &d3d9FormatInfo))
384 {
385 return d3d9FormatInfo.mTexFormat(renderer);
386 }
387 else
388 {
389 UNREACHABLE();
390 return D3DFMT_UNKNOWN;
391 }
392}
393
394D3DFORMAT GetRenderFormat(GLint internalFormat, const Renderer9 *renderer)
395{
396 if (!renderer)
397 {
398 UNREACHABLE();
399 return D3DFMT_UNKNOWN;
400 }
401
402 ASSERT(renderer->getCurrentClientVersion() == 2);
403
404 D3D9FormatInfo d3d9FormatInfo;
405 if (getD3D9FormatInfo(internalFormat, &d3d9FormatInfo))
406 {
407 return d3d9FormatInfo.mRenderFormat(renderer);
408 }
409 else
410 {
411 UNREACHABLE();
412 return D3DFMT_UNKNOWN;
413 }
414}
415
416D3DMULTISAMPLE_TYPE GetMultisampleType(GLsizei samples)
417{
418 return (samples > 1) ? static_cast<D3DMULTISAMPLE_TYPE>(samples) : D3DMULTISAMPLE_NONE;
419}
420
421}
422
423namespace d3d9_gl
424{
425
426GLint GetInternalFormat(D3DFORMAT format)
427{
428 static const D3D9FormatInfoMap infoMap = buildD3D9FormatInfoMap();
429 D3D9FormatInfoMap::const_iterator iter = infoMap.find(format);
430 if (iter != infoMap.end())
431 {
432 return iter->second.mInternalFormat;
433 }
434 else
435 {
436 UNREACHABLE();
437 return GL_NONE;
438 }
439}
440
441GLsizei GetSamplesCount(D3DMULTISAMPLE_TYPE type)
442{
443 return (type != D3DMULTISAMPLE_NONMASKABLE) ? type : 0;
444}
445
446bool IsFormatChannelEquivalent(D3DFORMAT d3dformat, GLenum format, GLuint clientVersion)
447{
448 GLint internalFormat = d3d9_gl::GetInternalFormat(d3dformat);
449 GLenum convertedFormat = gl::GetFormat(internalFormat, clientVersion);
450 return convertedFormat == format;
451}
452
453}
454
455}