Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | #include "precompiled.h" |
michael@0 | 2 | // |
michael@0 | 3 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
michael@0 | 4 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | // found in the LICENSE file. |
michael@0 | 6 | // |
michael@0 | 7 | |
michael@0 | 8 | // renderer9_utils.cpp: Conversion functions and other utility routines |
michael@0 | 9 | // specific to the D3D9 renderer. |
michael@0 | 10 | |
michael@0 | 11 | #include "libGLESv2/renderer/renderer9_utils.h" |
michael@0 | 12 | #include "libGLESv2/mathutil.h" |
michael@0 | 13 | #include "libGLESv2/Context.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "common/debug.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace gl_d3d9 |
michael@0 | 18 | { |
michael@0 | 19 | |
michael@0 | 20 | D3DCMPFUNC ConvertComparison(GLenum comparison) |
michael@0 | 21 | { |
michael@0 | 22 | D3DCMPFUNC d3dComp = D3DCMP_ALWAYS; |
michael@0 | 23 | switch (comparison) |
michael@0 | 24 | { |
michael@0 | 25 | case GL_NEVER: d3dComp = D3DCMP_NEVER; break; |
michael@0 | 26 | case GL_ALWAYS: d3dComp = D3DCMP_ALWAYS; break; |
michael@0 | 27 | case GL_LESS: d3dComp = D3DCMP_LESS; break; |
michael@0 | 28 | case GL_LEQUAL: d3dComp = D3DCMP_LESSEQUAL; break; |
michael@0 | 29 | case GL_EQUAL: d3dComp = D3DCMP_EQUAL; break; |
michael@0 | 30 | case GL_GREATER: d3dComp = D3DCMP_GREATER; break; |
michael@0 | 31 | case GL_GEQUAL: d3dComp = D3DCMP_GREATEREQUAL; break; |
michael@0 | 32 | case GL_NOTEQUAL: d3dComp = D3DCMP_NOTEQUAL; break; |
michael@0 | 33 | default: UNREACHABLE(); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | return d3dComp; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | D3DCOLOR ConvertColor(gl::Color color) |
michael@0 | 40 | { |
michael@0 | 41 | return D3DCOLOR_RGBA(gl::unorm<8>(color.red), |
michael@0 | 42 | gl::unorm<8>(color.green), |
michael@0 | 43 | gl::unorm<8>(color.blue), |
michael@0 | 44 | gl::unorm<8>(color.alpha)); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | D3DBLEND ConvertBlendFunc(GLenum blend) |
michael@0 | 48 | { |
michael@0 | 49 | D3DBLEND d3dBlend = D3DBLEND_ZERO; |
michael@0 | 50 | |
michael@0 | 51 | switch (blend) |
michael@0 | 52 | { |
michael@0 | 53 | case GL_ZERO: d3dBlend = D3DBLEND_ZERO; break; |
michael@0 | 54 | case GL_ONE: d3dBlend = D3DBLEND_ONE; break; |
michael@0 | 55 | case GL_SRC_COLOR: d3dBlend = D3DBLEND_SRCCOLOR; break; |
michael@0 | 56 | case GL_ONE_MINUS_SRC_COLOR: d3dBlend = D3DBLEND_INVSRCCOLOR; break; |
michael@0 | 57 | case GL_DST_COLOR: d3dBlend = D3DBLEND_DESTCOLOR; break; |
michael@0 | 58 | case GL_ONE_MINUS_DST_COLOR: d3dBlend = D3DBLEND_INVDESTCOLOR; break; |
michael@0 | 59 | case GL_SRC_ALPHA: d3dBlend = D3DBLEND_SRCALPHA; break; |
michael@0 | 60 | case GL_ONE_MINUS_SRC_ALPHA: d3dBlend = D3DBLEND_INVSRCALPHA; break; |
michael@0 | 61 | case GL_DST_ALPHA: d3dBlend = D3DBLEND_DESTALPHA; break; |
michael@0 | 62 | case GL_ONE_MINUS_DST_ALPHA: d3dBlend = D3DBLEND_INVDESTALPHA; break; |
michael@0 | 63 | case GL_CONSTANT_COLOR: d3dBlend = D3DBLEND_BLENDFACTOR; break; |
michael@0 | 64 | case GL_ONE_MINUS_CONSTANT_COLOR: d3dBlend = D3DBLEND_INVBLENDFACTOR; break; |
michael@0 | 65 | case GL_CONSTANT_ALPHA: d3dBlend = D3DBLEND_BLENDFACTOR; break; |
michael@0 | 66 | case GL_ONE_MINUS_CONSTANT_ALPHA: d3dBlend = D3DBLEND_INVBLENDFACTOR; break; |
michael@0 | 67 | case GL_SRC_ALPHA_SATURATE: d3dBlend = D3DBLEND_SRCALPHASAT; break; |
michael@0 | 68 | default: UNREACHABLE(); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | return d3dBlend; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | D3DBLENDOP ConvertBlendOp(GLenum blendOp) |
michael@0 | 75 | { |
michael@0 | 76 | D3DBLENDOP d3dBlendOp = D3DBLENDOP_ADD; |
michael@0 | 77 | |
michael@0 | 78 | switch (blendOp) |
michael@0 | 79 | { |
michael@0 | 80 | case GL_FUNC_ADD: d3dBlendOp = D3DBLENDOP_ADD; break; |
michael@0 | 81 | case GL_FUNC_SUBTRACT: d3dBlendOp = D3DBLENDOP_SUBTRACT; break; |
michael@0 | 82 | case GL_FUNC_REVERSE_SUBTRACT: d3dBlendOp = D3DBLENDOP_REVSUBTRACT; break; |
michael@0 | 83 | default: UNREACHABLE(); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | return d3dBlendOp; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | D3DSTENCILOP ConvertStencilOp(GLenum stencilOp) |
michael@0 | 90 | { |
michael@0 | 91 | D3DSTENCILOP d3dStencilOp = D3DSTENCILOP_KEEP; |
michael@0 | 92 | |
michael@0 | 93 | switch (stencilOp) |
michael@0 | 94 | { |
michael@0 | 95 | case GL_ZERO: d3dStencilOp = D3DSTENCILOP_ZERO; break; |
michael@0 | 96 | case GL_KEEP: d3dStencilOp = D3DSTENCILOP_KEEP; break; |
michael@0 | 97 | case GL_REPLACE: d3dStencilOp = D3DSTENCILOP_REPLACE; break; |
michael@0 | 98 | case GL_INCR: d3dStencilOp = D3DSTENCILOP_INCRSAT; break; |
michael@0 | 99 | case GL_DECR: d3dStencilOp = D3DSTENCILOP_DECRSAT; break; |
michael@0 | 100 | case GL_INVERT: d3dStencilOp = D3DSTENCILOP_INVERT; break; |
michael@0 | 101 | case GL_INCR_WRAP: d3dStencilOp = D3DSTENCILOP_INCR; break; |
michael@0 | 102 | case GL_DECR_WRAP: d3dStencilOp = D3DSTENCILOP_DECR; break; |
michael@0 | 103 | default: UNREACHABLE(); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | return d3dStencilOp; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | D3DTEXTUREADDRESS ConvertTextureWrap(GLenum wrap) |
michael@0 | 110 | { |
michael@0 | 111 | D3DTEXTUREADDRESS d3dWrap = D3DTADDRESS_WRAP; |
michael@0 | 112 | |
michael@0 | 113 | switch (wrap) |
michael@0 | 114 | { |
michael@0 | 115 | case GL_REPEAT: d3dWrap = D3DTADDRESS_WRAP; break; |
michael@0 | 116 | case GL_CLAMP_TO_EDGE: d3dWrap = D3DTADDRESS_CLAMP; break; |
michael@0 | 117 | case GL_MIRRORED_REPEAT: d3dWrap = D3DTADDRESS_MIRROR; break; |
michael@0 | 118 | default: UNREACHABLE(); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | return d3dWrap; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | D3DCULL ConvertCullMode(GLenum cullFace, GLenum frontFace) |
michael@0 | 125 | { |
michael@0 | 126 | D3DCULL cull = D3DCULL_CCW; |
michael@0 | 127 | switch (cullFace) |
michael@0 | 128 | { |
michael@0 | 129 | case GL_FRONT: |
michael@0 | 130 | cull = (frontFace == GL_CCW ? D3DCULL_CW : D3DCULL_CCW); |
michael@0 | 131 | break; |
michael@0 | 132 | case GL_BACK: |
michael@0 | 133 | cull = (frontFace == GL_CCW ? D3DCULL_CCW : D3DCULL_CW); |
michael@0 | 134 | break; |
michael@0 | 135 | case GL_FRONT_AND_BACK: |
michael@0 | 136 | cull = D3DCULL_NONE; // culling will be handled during draw |
michael@0 | 137 | break; |
michael@0 | 138 | default: UNREACHABLE(); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | return cull; |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | D3DCUBEMAP_FACES ConvertCubeFace(GLenum cubeFace) |
michael@0 | 145 | { |
michael@0 | 146 | D3DCUBEMAP_FACES face = D3DCUBEMAP_FACE_POSITIVE_X; |
michael@0 | 147 | |
michael@0 | 148 | switch (cubeFace) |
michael@0 | 149 | { |
michael@0 | 150 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
michael@0 | 151 | face = D3DCUBEMAP_FACE_POSITIVE_X; |
michael@0 | 152 | break; |
michael@0 | 153 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
michael@0 | 154 | face = D3DCUBEMAP_FACE_NEGATIVE_X; |
michael@0 | 155 | break; |
michael@0 | 156 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
michael@0 | 157 | face = D3DCUBEMAP_FACE_POSITIVE_Y; |
michael@0 | 158 | break; |
michael@0 | 159 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
michael@0 | 160 | face = D3DCUBEMAP_FACE_NEGATIVE_Y; |
michael@0 | 161 | break; |
michael@0 | 162 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
michael@0 | 163 | face = D3DCUBEMAP_FACE_POSITIVE_Z; |
michael@0 | 164 | break; |
michael@0 | 165 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
michael@0 | 166 | face = D3DCUBEMAP_FACE_NEGATIVE_Z; |
michael@0 | 167 | break; |
michael@0 | 168 | default: UNREACHABLE(); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | return face; |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | DWORD ConvertColorMask(bool red, bool green, bool blue, bool alpha) |
michael@0 | 175 | { |
michael@0 | 176 | return (red ? D3DCOLORWRITEENABLE_RED : 0) | |
michael@0 | 177 | (green ? D3DCOLORWRITEENABLE_GREEN : 0) | |
michael@0 | 178 | (blue ? D3DCOLORWRITEENABLE_BLUE : 0) | |
michael@0 | 179 | (alpha ? D3DCOLORWRITEENABLE_ALPHA : 0); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | D3DTEXTUREFILTERTYPE ConvertMagFilter(GLenum magFilter, float maxAnisotropy) |
michael@0 | 183 | { |
michael@0 | 184 | if (maxAnisotropy > 1.0f) |
michael@0 | 185 | { |
michael@0 | 186 | return D3DTEXF_ANISOTROPIC; |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | D3DTEXTUREFILTERTYPE d3dMagFilter = D3DTEXF_POINT; |
michael@0 | 190 | switch (magFilter) |
michael@0 | 191 | { |
michael@0 | 192 | case GL_NEAREST: d3dMagFilter = D3DTEXF_POINT; break; |
michael@0 | 193 | case GL_LINEAR: d3dMagFilter = D3DTEXF_LINEAR; break; |
michael@0 | 194 | default: UNREACHABLE(); |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | return d3dMagFilter; |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | void ConvertMinFilter(GLenum minFilter, D3DTEXTUREFILTERTYPE *d3dMinFilter, D3DTEXTUREFILTERTYPE *d3dMipFilter, float maxAnisotropy) |
michael@0 | 201 | { |
michael@0 | 202 | switch (minFilter) |
michael@0 | 203 | { |
michael@0 | 204 | case GL_NEAREST: |
michael@0 | 205 | *d3dMinFilter = D3DTEXF_POINT; |
michael@0 | 206 | *d3dMipFilter = D3DTEXF_NONE; |
michael@0 | 207 | break; |
michael@0 | 208 | case GL_LINEAR: |
michael@0 | 209 | *d3dMinFilter = D3DTEXF_LINEAR; |
michael@0 | 210 | *d3dMipFilter = D3DTEXF_NONE; |
michael@0 | 211 | break; |
michael@0 | 212 | case GL_NEAREST_MIPMAP_NEAREST: |
michael@0 | 213 | *d3dMinFilter = D3DTEXF_POINT; |
michael@0 | 214 | *d3dMipFilter = D3DTEXF_POINT; |
michael@0 | 215 | break; |
michael@0 | 216 | case GL_LINEAR_MIPMAP_NEAREST: |
michael@0 | 217 | *d3dMinFilter = D3DTEXF_LINEAR; |
michael@0 | 218 | *d3dMipFilter = D3DTEXF_POINT; |
michael@0 | 219 | break; |
michael@0 | 220 | case GL_NEAREST_MIPMAP_LINEAR: |
michael@0 | 221 | *d3dMinFilter = D3DTEXF_POINT; |
michael@0 | 222 | *d3dMipFilter = D3DTEXF_LINEAR; |
michael@0 | 223 | break; |
michael@0 | 224 | case GL_LINEAR_MIPMAP_LINEAR: |
michael@0 | 225 | *d3dMinFilter = D3DTEXF_LINEAR; |
michael@0 | 226 | *d3dMipFilter = D3DTEXF_LINEAR; |
michael@0 | 227 | break; |
michael@0 | 228 | default: |
michael@0 | 229 | *d3dMinFilter = D3DTEXF_POINT; |
michael@0 | 230 | *d3dMipFilter = D3DTEXF_NONE; |
michael@0 | 231 | UNREACHABLE(); |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | if (maxAnisotropy > 1.0f) |
michael@0 | 235 | { |
michael@0 | 236 | *d3dMinFilter = D3DTEXF_ANISOTROPIC; |
michael@0 | 237 | } |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | D3DFORMAT ConvertRenderbufferFormat(GLenum format) |
michael@0 | 241 | { |
michael@0 | 242 | switch (format) |
michael@0 | 243 | { |
michael@0 | 244 | case GL_NONE: return D3DFMT_NULL; |
michael@0 | 245 | case GL_RGBA4: |
michael@0 | 246 | case GL_RGB5_A1: |
michael@0 | 247 | case GL_RGBA8_OES: return D3DFMT_A8R8G8B8; |
michael@0 | 248 | case GL_RGB565: return D3DFMT_R5G6B5; |
michael@0 | 249 | case GL_RGB8_OES: return D3DFMT_X8R8G8B8; |
michael@0 | 250 | case GL_DEPTH_COMPONENT16: |
michael@0 | 251 | case GL_STENCIL_INDEX8: |
michael@0 | 252 | case GL_DEPTH24_STENCIL8_OES: return D3DFMT_D24S8; |
michael@0 | 253 | default: UNREACHABLE(); return D3DFMT_A8R8G8B8; |
michael@0 | 254 | } |
michael@0 | 255 | } |
michael@0 | 256 | |
michael@0 | 257 | D3DMULTISAMPLE_TYPE GetMultisampleTypeFromSamples(GLsizei samples) |
michael@0 | 258 | { |
michael@0 | 259 | if (samples <= 1) |
michael@0 | 260 | return D3DMULTISAMPLE_NONE; |
michael@0 | 261 | else |
michael@0 | 262 | return (D3DMULTISAMPLE_TYPE)samples; |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | } |
michael@0 | 266 | |
michael@0 | 267 | namespace d3d9_gl |
michael@0 | 268 | { |
michael@0 | 269 | |
michael@0 | 270 | unsigned int GetStencilSize(D3DFORMAT stencilFormat) |
michael@0 | 271 | { |
michael@0 | 272 | if (stencilFormat == D3DFMT_INTZ) |
michael@0 | 273 | { |
michael@0 | 274 | return 8; |
michael@0 | 275 | } |
michael@0 | 276 | switch(stencilFormat) |
michael@0 | 277 | { |
michael@0 | 278 | case D3DFMT_D24FS8: |
michael@0 | 279 | case D3DFMT_D24S8: |
michael@0 | 280 | return 8; |
michael@0 | 281 | case D3DFMT_D24X4S4: |
michael@0 | 282 | return 4; |
michael@0 | 283 | case D3DFMT_D15S1: |
michael@0 | 284 | return 1; |
michael@0 | 285 | case D3DFMT_D16_LOCKABLE: |
michael@0 | 286 | case D3DFMT_D32: |
michael@0 | 287 | case D3DFMT_D24X8: |
michael@0 | 288 | case D3DFMT_D32F_LOCKABLE: |
michael@0 | 289 | case D3DFMT_D16: |
michael@0 | 290 | return 0; |
michael@0 | 291 | //case D3DFMT_D32_LOCKABLE: return 0; // DirectX 9Ex only |
michael@0 | 292 | //case D3DFMT_S8_LOCKABLE: return 8; // DirectX 9Ex only |
michael@0 | 293 | default: |
michael@0 | 294 | return 0; |
michael@0 | 295 | } |
michael@0 | 296 | } |
michael@0 | 297 | |
michael@0 | 298 | unsigned int GetAlphaSize(D3DFORMAT colorFormat) |
michael@0 | 299 | { |
michael@0 | 300 | switch (colorFormat) |
michael@0 | 301 | { |
michael@0 | 302 | case D3DFMT_A16B16G16R16F: |
michael@0 | 303 | return 16; |
michael@0 | 304 | case D3DFMT_A32B32G32R32F: |
michael@0 | 305 | return 32; |
michael@0 | 306 | case D3DFMT_A2R10G10B10: |
michael@0 | 307 | return 2; |
michael@0 | 308 | case D3DFMT_A8R8G8B8: |
michael@0 | 309 | return 8; |
michael@0 | 310 | case D3DFMT_A1R5G5B5: |
michael@0 | 311 | return 1; |
michael@0 | 312 | case D3DFMT_X8R8G8B8: |
michael@0 | 313 | case D3DFMT_R5G6B5: |
michael@0 | 314 | return 0; |
michael@0 | 315 | default: |
michael@0 | 316 | return 0; |
michael@0 | 317 | } |
michael@0 | 318 | } |
michael@0 | 319 | |
michael@0 | 320 | GLsizei GetSamplesFromMultisampleType(D3DMULTISAMPLE_TYPE type) |
michael@0 | 321 | { |
michael@0 | 322 | if (type == D3DMULTISAMPLE_NONMASKABLE) |
michael@0 | 323 | return 0; |
michael@0 | 324 | else |
michael@0 | 325 | return type; |
michael@0 | 326 | } |
michael@0 | 327 | |
michael@0 | 328 | bool IsFormatChannelEquivalent(D3DFORMAT d3dformat, GLenum format) |
michael@0 | 329 | { |
michael@0 | 330 | switch (d3dformat) |
michael@0 | 331 | { |
michael@0 | 332 | case D3DFMT_L8: |
michael@0 | 333 | return (format == GL_LUMINANCE); |
michael@0 | 334 | case D3DFMT_A8L8: |
michael@0 | 335 | return (format == GL_LUMINANCE_ALPHA); |
michael@0 | 336 | case D3DFMT_DXT1: |
michael@0 | 337 | return (format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT || format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT); |
michael@0 | 338 | case D3DFMT_DXT3: |
michael@0 | 339 | return (format == GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE); |
michael@0 | 340 | case D3DFMT_DXT5: |
michael@0 | 341 | return (format == GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE); |
michael@0 | 342 | case D3DFMT_A8R8G8B8: |
michael@0 | 343 | case D3DFMT_A16B16G16R16F: |
michael@0 | 344 | case D3DFMT_A32B32G32R32F: |
michael@0 | 345 | return (format == GL_RGBA || format == GL_BGRA_EXT); |
michael@0 | 346 | case D3DFMT_X8R8G8B8: |
michael@0 | 347 | return (format == GL_RGB); |
michael@0 | 348 | default: |
michael@0 | 349 | if (d3dformat == D3DFMT_INTZ && gl::IsDepthTexture(format)) |
michael@0 | 350 | return true; |
michael@0 | 351 | return false; |
michael@0 | 352 | } |
michael@0 | 353 | } |
michael@0 | 354 | |
michael@0 | 355 | GLenum ConvertBackBufferFormat(D3DFORMAT format) |
michael@0 | 356 | { |
michael@0 | 357 | switch (format) |
michael@0 | 358 | { |
michael@0 | 359 | case D3DFMT_A4R4G4B4: return GL_RGBA4; |
michael@0 | 360 | case D3DFMT_A8R8G8B8: return GL_RGBA8_OES; |
michael@0 | 361 | case D3DFMT_A1R5G5B5: return GL_RGB5_A1; |
michael@0 | 362 | case D3DFMT_R5G6B5: return GL_RGB565; |
michael@0 | 363 | case D3DFMT_X8R8G8B8: return GL_RGB8_OES; |
michael@0 | 364 | default: |
michael@0 | 365 | UNREACHABLE(); |
michael@0 | 366 | } |
michael@0 | 367 | |
michael@0 | 368 | return GL_RGBA4; |
michael@0 | 369 | } |
michael@0 | 370 | |
michael@0 | 371 | GLenum ConvertDepthStencilFormat(D3DFORMAT format) |
michael@0 | 372 | { |
michael@0 | 373 | if (format == D3DFMT_INTZ) |
michael@0 | 374 | { |
michael@0 | 375 | return GL_DEPTH24_STENCIL8_OES; |
michael@0 | 376 | } |
michael@0 | 377 | switch (format) |
michael@0 | 378 | { |
michael@0 | 379 | case D3DFMT_D16: |
michael@0 | 380 | case D3DFMT_D24X8: |
michael@0 | 381 | return GL_DEPTH_COMPONENT16; |
michael@0 | 382 | case D3DFMT_D24S8: |
michael@0 | 383 | return GL_DEPTH24_STENCIL8_OES; |
michael@0 | 384 | case D3DFMT_UNKNOWN: |
michael@0 | 385 | return GL_NONE; |
michael@0 | 386 | default: |
michael@0 | 387 | UNREACHABLE(); |
michael@0 | 388 | } |
michael@0 | 389 | |
michael@0 | 390 | return GL_DEPTH24_STENCIL8_OES; |
michael@0 | 391 | } |
michael@0 | 392 | |
michael@0 | 393 | GLenum ConvertRenderTargetFormat(D3DFORMAT format) |
michael@0 | 394 | { |
michael@0 | 395 | if (format == D3DFMT_INTZ) |
michael@0 | 396 | { |
michael@0 | 397 | return GL_DEPTH24_STENCIL8_OES; |
michael@0 | 398 | } |
michael@0 | 399 | |
michael@0 | 400 | switch (format) |
michael@0 | 401 | { |
michael@0 | 402 | case D3DFMT_A4R4G4B4: return GL_RGBA4; |
michael@0 | 403 | case D3DFMT_A8R8G8B8: return GL_RGBA8_OES; |
michael@0 | 404 | case D3DFMT_A1R5G5B5: return GL_RGB5_A1; |
michael@0 | 405 | case D3DFMT_R5G6B5: return GL_RGB565; |
michael@0 | 406 | case D3DFMT_X8R8G8B8: return GL_RGB8_OES; |
michael@0 | 407 | case D3DFMT_D16: |
michael@0 | 408 | case D3DFMT_D24X8: |
michael@0 | 409 | return GL_DEPTH_COMPONENT16; |
michael@0 | 410 | case D3DFMT_D24S8: |
michael@0 | 411 | return GL_DEPTH24_STENCIL8_OES; |
michael@0 | 412 | case D3DFMT_UNKNOWN: |
michael@0 | 413 | return GL_NONE; |
michael@0 | 414 | default: |
michael@0 | 415 | UNREACHABLE(); |
michael@0 | 416 | } |
michael@0 | 417 | |
michael@0 | 418 | return GL_RGBA4; |
michael@0 | 419 | } |
michael@0 | 420 | |
michael@0 | 421 | GLenum GetEquivalentFormat(D3DFORMAT format) |
michael@0 | 422 | { |
michael@0 | 423 | if (format == D3DFMT_INTZ) |
michael@0 | 424 | return GL_DEPTH24_STENCIL8_OES; |
michael@0 | 425 | if (format == D3DFMT_NULL) |
michael@0 | 426 | return GL_NONE; |
michael@0 | 427 | |
michael@0 | 428 | switch (format) |
michael@0 | 429 | { |
michael@0 | 430 | case D3DFMT_A4R4G4B4: return GL_RGBA4; |
michael@0 | 431 | case D3DFMT_A8R8G8B8: return GL_RGBA8_OES; |
michael@0 | 432 | case D3DFMT_A1R5G5B5: return GL_RGB5_A1; |
michael@0 | 433 | case D3DFMT_R5G6B5: return GL_RGB565; |
michael@0 | 434 | case D3DFMT_X8R8G8B8: return GL_RGB8_OES; |
michael@0 | 435 | case D3DFMT_D16: return GL_DEPTH_COMPONENT16; |
michael@0 | 436 | case D3DFMT_D24S8: return GL_DEPTH24_STENCIL8_OES; |
michael@0 | 437 | case D3DFMT_UNKNOWN: return GL_NONE; |
michael@0 | 438 | case D3DFMT_DXT1: return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; |
michael@0 | 439 | case D3DFMT_DXT3: return GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE; |
michael@0 | 440 | case D3DFMT_DXT5: return GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE; |
michael@0 | 441 | case D3DFMT_A32B32G32R32F: return GL_RGBA32F_EXT; |
michael@0 | 442 | case D3DFMT_A16B16G16R16F: return GL_RGBA16F_EXT; |
michael@0 | 443 | case D3DFMT_L8: return GL_LUMINANCE8_EXT; |
michael@0 | 444 | case D3DFMT_A8L8: return GL_LUMINANCE8_ALPHA8_EXT; |
michael@0 | 445 | default: UNREACHABLE(); |
michael@0 | 446 | return GL_NONE; |
michael@0 | 447 | } |
michael@0 | 448 | } |
michael@0 | 449 | |
michael@0 | 450 | } |
michael@0 | 451 | |
michael@0 | 452 | namespace d3d9 |
michael@0 | 453 | { |
michael@0 | 454 | |
michael@0 | 455 | bool IsCompressedFormat(D3DFORMAT surfaceFormat) |
michael@0 | 456 | { |
michael@0 | 457 | switch(surfaceFormat) |
michael@0 | 458 | { |
michael@0 | 459 | case D3DFMT_DXT1: |
michael@0 | 460 | case D3DFMT_DXT2: |
michael@0 | 461 | case D3DFMT_DXT3: |
michael@0 | 462 | case D3DFMT_DXT4: |
michael@0 | 463 | case D3DFMT_DXT5: |
michael@0 | 464 | return true; |
michael@0 | 465 | default: |
michael@0 | 466 | return false; |
michael@0 | 467 | } |
michael@0 | 468 | } |
michael@0 | 469 | |
michael@0 | 470 | size_t ComputeRowSize(D3DFORMAT format, unsigned int width) |
michael@0 | 471 | { |
michael@0 | 472 | if (format == D3DFMT_INTZ) |
michael@0 | 473 | { |
michael@0 | 474 | return 4 * width; |
michael@0 | 475 | } |
michael@0 | 476 | switch (format) |
michael@0 | 477 | { |
michael@0 | 478 | case D3DFMT_L8: |
michael@0 | 479 | return 1 * width; |
michael@0 | 480 | case D3DFMT_A8L8: |
michael@0 | 481 | return 2 * width; |
michael@0 | 482 | case D3DFMT_X8R8G8B8: |
michael@0 | 483 | case D3DFMT_A8R8G8B8: |
michael@0 | 484 | return 4 * width; |
michael@0 | 485 | case D3DFMT_A16B16G16R16F: |
michael@0 | 486 | return 8 * width; |
michael@0 | 487 | case D3DFMT_A32B32G32R32F: |
michael@0 | 488 | return 16 * width; |
michael@0 | 489 | case D3DFMT_DXT1: |
michael@0 | 490 | return 8 * ((width + 3) / 4); |
michael@0 | 491 | case D3DFMT_DXT3: |
michael@0 | 492 | case D3DFMT_DXT5: |
michael@0 | 493 | return 16 * ((width + 3) / 4); |
michael@0 | 494 | default: |
michael@0 | 495 | UNREACHABLE(); |
michael@0 | 496 | return 0; |
michael@0 | 497 | } |
michael@0 | 498 | } |
michael@0 | 499 | |
michael@0 | 500 | } |