blob: bd2f34341c212d44c0dd26b2276eacb571fa0af1 [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
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000155// A map to determine the pixel size and mip generation function of a given D3D format
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000156struct D3DFormatInfo
157{
158 GLuint mPixelBits;
159 GLuint mBlockWidth;
160 GLuint mBlockHeight;
161 GLint mInternalFormat;
162
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000163 MipGenerationFunction mMipGenerationFunction;
164
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000165 D3DFormatInfo()
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000166 : mPixelBits(0), mBlockWidth(0), mBlockHeight(0), mInternalFormat(GL_NONE), mMipGenerationFunction(NULL)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000167 { }
168
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000169 D3DFormatInfo(GLuint pixelBits, GLuint blockWidth, GLuint blockHeight, GLint internalFormat,
170 MipGenerationFunction mipFunc)
171 : mPixelBits(pixelBits), mBlockWidth(blockWidth), mBlockHeight(blockHeight), mInternalFormat(internalFormat),
172 mMipGenerationFunction(mipFunc)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000173 { }
174};
175
176typedef std::pair<D3DFORMAT, D3DFormatInfo> D3D9FormatInfoPair;
177typedef std::map<D3DFORMAT, D3DFormatInfo> D3D9FormatInfoMap;
178
179static D3D9FormatInfoMap buildD3D9FormatInfoMap()
180{
181 D3D9FormatInfoMap map;
182
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000183 // | D3DFORMAT | | S |W |H | Internal format | Mip generation function |
184 map.insert(D3D9FormatInfoPair(D3DFMT_NULL, D3DFormatInfo( 0, 0, 0, GL_NONE, NULL )));
185 map.insert(D3D9FormatInfoPair(D3DFMT_UNKNOWN, D3DFormatInfo( 0, 0, 0, GL_NONE, NULL )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000186
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000187 map.insert(D3D9FormatInfoPair(D3DFMT_L8, D3DFormatInfo( 8, 1, 1, GL_LUMINANCE8_EXT, GenerateMip<L8> )));
188 map.insert(D3D9FormatInfoPair(D3DFMT_A8, D3DFormatInfo( 8, 1, 1, GL_ALPHA8_EXT, GenerateMip<A8> )));
189 map.insert(D3D9FormatInfoPair(D3DFMT_A8L8, D3DFormatInfo( 16, 1, 1, GL_LUMINANCE8_ALPHA8_EXT, GenerateMip<A8L8> )));
190 map.insert(D3D9FormatInfoPair(D3DFMT_A4R4G4B4, D3DFormatInfo( 16, 1, 1, GL_RGBA4, NULL )));
191 map.insert(D3D9FormatInfoPair(D3DFMT_A1R5G5B5, D3DFormatInfo( 16, 1, 1, GL_RGB5_A1, NULL )));
192 map.insert(D3D9FormatInfoPair(D3DFMT_R5G6B5, D3DFormatInfo( 16, 1, 1, GL_RGB565, NULL )));
193 map.insert(D3D9FormatInfoPair(D3DFMT_X8R8G8B8, D3DFormatInfo( 32, 1, 1, GL_RGB8_OES, GenerateMip<A8R8G8B8> )));
194 map.insert(D3D9FormatInfoPair(D3DFMT_A8R8G8B8, D3DFormatInfo( 32, 1, 1, GL_RGBA8_OES, GenerateMip<A8R8G8B8> )));
195 map.insert(D3D9FormatInfoPair(D3DFMT_A16B16G16R16F, D3DFormatInfo( 64, 1, 1, GL_RGBA16F_EXT, GenerateMip<A16B16G16R16F>)));
196 map.insert(D3D9FormatInfoPair(D3DFMT_A32B32G32R32F, D3DFormatInfo(128, 1, 1, GL_RGBA32F_EXT, GenerateMip<A32B32G32R32F>)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000197
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000198 map.insert(D3D9FormatInfoPair(D3DFMT_D16, D3DFormatInfo( 16, 1, 1, GL_DEPTH_COMPONENT16, NULL )));
199 map.insert(D3D9FormatInfoPair(D3DFMT_D24S8, D3DFormatInfo( 32, 1, 1, GL_DEPTH24_STENCIL8_OES, NULL )));
200 map.insert(D3D9FormatInfoPair(D3DFMT_D24X8, D3DFormatInfo( 32, 1, 1, GL_DEPTH_COMPONENT16, NULL )));
201 map.insert(D3D9FormatInfoPair(D3DFMT_D32, D3DFormatInfo( 32, 1, 1, GL_DEPTH_COMPONENT32_OES, NULL )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000202
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000203 map.insert(D3D9FormatInfoPair(D3DFMT_INTZ, D3DFormatInfo( 32, 1, 1, GL_DEPTH24_STENCIL8_OES, NULL )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000204
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000205 map.insert(D3D9FormatInfoPair(D3DFMT_DXT1, D3DFormatInfo( 64, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, NULL )));
206 map.insert(D3D9FormatInfoPair(D3DFMT_DXT3, D3DFormatInfo(128, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, NULL )));
207 map.insert(D3D9FormatInfoPair(D3DFMT_DXT5, D3DFormatInfo(128, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, NULL )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000208
209 return map;
210}
211
212static bool getD3D9FormatInfo(D3DFORMAT format, D3DFormatInfo *outFormatInfo)
213{
214 static const D3D9FormatInfoMap infoMap = buildD3D9FormatInfoMap();
215 D3D9FormatInfoMap::const_iterator iter = infoMap.find(format);
216 if (iter != infoMap.end())
217 {
218 if (outFormatInfo)
219 {
220 *outFormatInfo = iter->second;
221 }
222 return true;
223 }
224 else
225 {
226 return false;
227 }
228}
229
230namespace d3d9
231{
232
233MipGenerationFunction GetMipGenerationFunction(D3DFORMAT format)
234{
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000235 D3DFormatInfo d3dFormatInfo;
236 if (getD3D9FormatInfo(format, &d3dFormatInfo))
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000237 {
shannonwoods@chromium.orgba9d7502013-05-30 00:14:58 +0000238 return d3dFormatInfo.mMipGenerationFunction;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000239 }
240 else
241 {
242 UNREACHABLE();
243 return NULL;
244 }
245}
246
247LoadImageFunction GetImageLoadFunction(GLint internalFormat, const Renderer9 *renderer)
248{
249 if (!renderer)
250 {
251 return NULL;
252 }
253
254 ASSERT(renderer->getCurrentClientVersion() == 2);
255
256 D3D9FormatInfo d3d9FormatInfo;
257 if (getD3D9FormatInfo(internalFormat, &d3d9FormatInfo))
258 {
259 return d3d9FormatInfo.mLoadFunction(renderer);
260 }
261 else
262 {
263 UNREACHABLE();
264 return NULL;
265 }
266}
267
268GLuint GetFormatPixelBytes(D3DFORMAT format)
269{
270 D3DFormatInfo d3dFormatInfo;
271 if (getD3D9FormatInfo(format, &d3dFormatInfo))
272 {
273 return d3dFormatInfo.mPixelBits / 8;
274 }
275 else
276 {
277 UNREACHABLE();
278 return 0;
279 }
280}
281
282GLuint GetBlockWidth(D3DFORMAT format)
283{
284 D3DFormatInfo d3dFormatInfo;
285 if (getD3D9FormatInfo(format, &d3dFormatInfo))
286 {
287 return d3dFormatInfo.mBlockWidth;
288 }
289 else
290 {
291 UNREACHABLE();
292 return 0;
293 }
294}
295
296GLuint GetBlockHeight(D3DFORMAT format)
297{
298 D3DFormatInfo d3dFormatInfo;
299 if (getD3D9FormatInfo(format, &d3dFormatInfo))
300 {
301 return d3dFormatInfo.mBlockHeight;
302 }
303 else
304 {
305 UNREACHABLE();
306 return 0;
307 }
308}
309
310GLuint GetBlockSize(D3DFORMAT format, GLuint width, GLuint height)
311{
312 D3DFormatInfo d3dFormatInfo;
313 if (getD3D9FormatInfo(format, &d3dFormatInfo))
314 {
315 GLuint numBlocksWide = (width + d3dFormatInfo.mBlockWidth - 1) / d3dFormatInfo.mBlockWidth;
316 GLuint numBlocksHight = (height + d3dFormatInfo.mBlockHeight - 1) / d3dFormatInfo.mBlockHeight;
317
318 return (d3dFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8;
319 }
320 else
321 {
322 UNREACHABLE();
323 return 0;
324 }
325}
326
327void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset)
328{
329 D3DFormatInfo d3dFormatInfo;
330 if (getD3D9FormatInfo(format, &d3dFormatInfo))
331 {
332 int upsampleCount = 0;
333
334 GLsizei blockWidth = d3dFormatInfo.mBlockWidth;
335 GLsizei blockHeight = d3dFormatInfo.mBlockHeight;
336
337 // Don't expand the size of full textures that are at least (blockWidth x blockHeight) already.
338 if (isImage || *requestWidth < blockWidth || *requestHeight < blockHeight)
339 {
340 while (*requestWidth % blockWidth != 0 || *requestHeight % blockHeight != 0)
341 {
342 *requestWidth <<= 1;
343 *requestHeight <<= 1;
344 upsampleCount++;
345 }
346 }
347 *levelOffset = upsampleCount;
348 }
349}
350
351}
352
353namespace gl_d3d9
354{
355
356D3DFORMAT GetTexureFormat(GLint internalFormat, const Renderer9 *renderer)
357{
358 if (!renderer)
359 {
360 UNREACHABLE();
361 return D3DFMT_UNKNOWN;
362 }
363
364 ASSERT(renderer->getCurrentClientVersion() == 2);
365
366 D3D9FormatInfo d3d9FormatInfo;
367 if (getD3D9FormatInfo(internalFormat, &d3d9FormatInfo))
368 {
369 return d3d9FormatInfo.mTexFormat(renderer);
370 }
371 else
372 {
373 UNREACHABLE();
374 return D3DFMT_UNKNOWN;
375 }
376}
377
378D3DFORMAT GetRenderFormat(GLint internalFormat, const Renderer9 *renderer)
379{
380 if (!renderer)
381 {
382 UNREACHABLE();
383 return D3DFMT_UNKNOWN;
384 }
385
386 ASSERT(renderer->getCurrentClientVersion() == 2);
387
388 D3D9FormatInfo d3d9FormatInfo;
389 if (getD3D9FormatInfo(internalFormat, &d3d9FormatInfo))
390 {
391 return d3d9FormatInfo.mRenderFormat(renderer);
392 }
393 else
394 {
395 UNREACHABLE();
396 return D3DFMT_UNKNOWN;
397 }
398}
399
400D3DMULTISAMPLE_TYPE GetMultisampleType(GLsizei samples)
401{
402 return (samples > 1) ? static_cast<D3DMULTISAMPLE_TYPE>(samples) : D3DMULTISAMPLE_NONE;
403}
404
405}
406
407namespace d3d9_gl
408{
409
410GLint GetInternalFormat(D3DFORMAT format)
411{
412 static const D3D9FormatInfoMap infoMap = buildD3D9FormatInfoMap();
413 D3D9FormatInfoMap::const_iterator iter = infoMap.find(format);
414 if (iter != infoMap.end())
415 {
416 return iter->second.mInternalFormat;
417 }
418 else
419 {
420 UNREACHABLE();
421 return GL_NONE;
422 }
423}
424
425GLsizei GetSamplesCount(D3DMULTISAMPLE_TYPE type)
426{
427 return (type != D3DMULTISAMPLE_NONMASKABLE) ? type : 0;
428}
429
430bool IsFormatChannelEquivalent(D3DFORMAT d3dformat, GLenum format, GLuint clientVersion)
431{
432 GLint internalFormat = d3d9_gl::GetInternalFormat(d3dformat);
433 GLenum convertedFormat = gl::GetFormat(internalFormat, clientVersion);
434 return convertedFormat == format;
435}
436
437}
438
439}