[1] | 1 | /* |
---|
| 2 | ----------------------------------------------------------------------------- |
---|
| 3 | This source file is part of OGRE |
---|
| 4 | (Object-oriented Graphics Rendering Engine) |
---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
---|
| 6 | |
---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
| 13 | version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
| 18 | |
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
| 23 | |
---|
| 24 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | #include "OgreD3D9Mappings.h" |
---|
| 30 | #include "OgreString.h" |
---|
| 31 | #include "OgreStringConverter.h" |
---|
| 32 | #include "OgreLogManager.h" |
---|
| 33 | #include "OgreException.h" |
---|
| 34 | |
---|
| 35 | namespace Ogre |
---|
| 36 | { |
---|
| 37 | //--------------------------------------------------------------------- |
---|
| 38 | DWORD D3D9Mappings::get(ShadeOptions so) |
---|
| 39 | { |
---|
| 40 | switch( so ) |
---|
| 41 | { |
---|
| 42 | case SO_FLAT: |
---|
| 43 | return D3DSHADE_FLAT; |
---|
| 44 | case SO_GOURAUD: |
---|
| 45 | return D3DSHADE_GOURAUD; |
---|
| 46 | case SO_PHONG: |
---|
| 47 | return D3DSHADE_PHONG; |
---|
| 48 | } |
---|
| 49 | return 0; |
---|
| 50 | } |
---|
| 51 | //--------------------------------------------------------------------- |
---|
| 52 | D3DLIGHTTYPE D3D9Mappings::get(Ogre::Light::LightTypes lightType) |
---|
| 53 | { |
---|
| 54 | switch( lightType ) |
---|
| 55 | { |
---|
| 56 | case Light::LT_POINT: |
---|
| 57 | return D3DLIGHT_POINT; |
---|
| 58 | case Light::LT_DIRECTIONAL: |
---|
| 59 | return D3DLIGHT_DIRECTIONAL; |
---|
| 60 | case Light::LT_SPOTLIGHT: |
---|
| 61 | return D3DLIGHT_SPOT; |
---|
| 62 | } |
---|
| 63 | return D3DLIGHT_FORCE_DWORD; |
---|
| 64 | } |
---|
| 65 | //--------------------------------------------------------------------- |
---|
| 66 | DWORD D3D9Mappings::get(TexCoordCalcMethod m, const D3DCAPS9& caps) |
---|
| 67 | { |
---|
| 68 | switch( m ) |
---|
| 69 | { |
---|
| 70 | case TEXCALC_NONE: |
---|
| 71 | return D3DTSS_TCI_PASSTHRU; |
---|
| 72 | case TEXCALC_ENVIRONMENT_MAP_REFLECTION: |
---|
| 73 | return D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR; |
---|
| 74 | case TEXCALC_ENVIRONMENT_MAP_PLANAR: |
---|
| 75 | if (caps.VertexProcessingCaps & D3DVTXPCAPS_TEXGEN_SPHEREMAP) |
---|
| 76 | { |
---|
| 77 | // Use sphere map if available |
---|
| 78 | return D3DTSS_TCI_SPHEREMAP; |
---|
| 79 | } |
---|
| 80 | else |
---|
| 81 | { |
---|
| 82 | // If not, fall back on camera space reflection vector which isn't as good |
---|
| 83 | return D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR; |
---|
| 84 | } |
---|
| 85 | case TEXCALC_ENVIRONMENT_MAP_NORMAL: |
---|
| 86 | return D3DTSS_TCI_CAMERASPACENORMAL; |
---|
| 87 | case TEXCALC_ENVIRONMENT_MAP: |
---|
| 88 | if (caps.VertexProcessingCaps & D3DVTXPCAPS_TEXGEN_SPHEREMAP) |
---|
| 89 | { |
---|
| 90 | // Use sphere map if available |
---|
| 91 | return D3DTSS_TCI_SPHEREMAP; |
---|
| 92 | } |
---|
| 93 | else |
---|
| 94 | { |
---|
| 95 | // If not, fall back on camera space normal which isn't as good |
---|
| 96 | return D3DTSS_TCI_CAMERASPACENORMAL; |
---|
| 97 | } |
---|
| 98 | case TEXCALC_PROJECTIVE_TEXTURE: |
---|
| 99 | return D3DTSS_TCI_CAMERASPACEPOSITION; |
---|
| 100 | } |
---|
| 101 | return 0; |
---|
| 102 | } |
---|
| 103 | //--------------------------------------------------------------------- |
---|
| 104 | D3DTEXTUREADDRESS D3D9Mappings::get(TextureUnitState::TextureAddressingMode tam, const D3DCAPS9& devCaps) |
---|
| 105 | { |
---|
| 106 | switch( tam ) |
---|
| 107 | { |
---|
| 108 | case TextureUnitState::TAM_WRAP: |
---|
| 109 | return D3DTADDRESS_WRAP; |
---|
| 110 | case TextureUnitState::TAM_MIRROR: |
---|
| 111 | return D3DTADDRESS_MIRROR; |
---|
| 112 | case TextureUnitState::TAM_CLAMP: |
---|
| 113 | return D3DTADDRESS_CLAMP; |
---|
| 114 | case TextureUnitState::TAM_BORDER: |
---|
| 115 | if (devCaps.TextureAddressCaps & D3DPTADDRESSCAPS_BORDER) |
---|
| 116 | return D3DTADDRESS_BORDER; |
---|
| 117 | else |
---|
| 118 | return D3DTADDRESS_CLAMP; |
---|
| 119 | } |
---|
| 120 | return D3DTADDRESS_FORCE_DWORD; |
---|
| 121 | } |
---|
| 122 | //--------------------------------------------------------------------- |
---|
| 123 | D3DTEXTURESTAGESTATETYPE D3D9Mappings::get(LayerBlendType lbt) |
---|
| 124 | { |
---|
| 125 | switch( lbt ) |
---|
| 126 | { |
---|
| 127 | case LBT_COLOUR: |
---|
| 128 | return D3DTSS_COLOROP; |
---|
| 129 | case LBT_ALPHA: |
---|
| 130 | return D3DTSS_ALPHAOP; |
---|
| 131 | } |
---|
| 132 | return D3DTSS_FORCE_DWORD; |
---|
| 133 | } |
---|
| 134 | //--------------------------------------------------------------------- |
---|
| 135 | DWORD D3D9Mappings::get(LayerBlendSource lbs, bool perStageConstants) |
---|
| 136 | { |
---|
| 137 | switch( lbs ) |
---|
| 138 | { |
---|
| 139 | case LBS_CURRENT: |
---|
| 140 | return D3DTA_CURRENT; |
---|
| 141 | case LBS_TEXTURE: |
---|
| 142 | return D3DTA_TEXTURE; |
---|
| 143 | case LBS_DIFFUSE: |
---|
| 144 | return D3DTA_DIFFUSE; |
---|
| 145 | case LBS_SPECULAR: |
---|
| 146 | return D3DTA_SPECULAR; |
---|
| 147 | case LBS_MANUAL: |
---|
| 148 | return perStageConstants ? D3DTA_CONSTANT : D3DTA_TFACTOR; |
---|
| 149 | } |
---|
| 150 | return 0; |
---|
| 151 | } |
---|
| 152 | //--------------------------------------------------------------------- |
---|
| 153 | DWORD D3D9Mappings::get(LayerBlendOperationEx lbo, const D3DCAPS9& devCaps) |
---|
| 154 | { |
---|
| 155 | switch( lbo ) |
---|
| 156 | { |
---|
| 157 | case LBX_SOURCE1: |
---|
| 158 | return D3DTOP_SELECTARG1; |
---|
| 159 | case LBX_SOURCE2: |
---|
| 160 | return D3DTOP_SELECTARG2; |
---|
| 161 | case LBX_MODULATE: |
---|
| 162 | return D3DTOP_MODULATE; |
---|
| 163 | case LBX_MODULATE_X2: |
---|
| 164 | return D3DTOP_MODULATE2X; |
---|
| 165 | case LBX_MODULATE_X4: |
---|
| 166 | return D3DTOP_MODULATE4X; |
---|
| 167 | case LBX_ADD: |
---|
| 168 | return D3DTOP_ADD; |
---|
| 169 | case LBX_ADD_SIGNED: |
---|
| 170 | return D3DTOP_ADDSIGNED; |
---|
| 171 | case LBX_ADD_SMOOTH: |
---|
| 172 | return D3DTOP_ADDSMOOTH; |
---|
| 173 | case LBX_SUBTRACT: |
---|
| 174 | return D3DTOP_SUBTRACT; |
---|
| 175 | case LBX_BLEND_DIFFUSE_ALPHA: |
---|
| 176 | return D3DTOP_BLENDDIFFUSEALPHA; |
---|
| 177 | case LBX_BLEND_TEXTURE_ALPHA: |
---|
| 178 | return D3DTOP_BLENDTEXTUREALPHA; |
---|
| 179 | case LBX_BLEND_CURRENT_ALPHA: |
---|
| 180 | return D3DTOP_BLENDCURRENTALPHA; |
---|
| 181 | case LBX_BLEND_MANUAL: |
---|
| 182 | return D3DTOP_BLENDFACTORALPHA; |
---|
| 183 | case LBX_DOTPRODUCT: |
---|
| 184 | if (devCaps.TextureOpCaps & D3DTEXOPCAPS_DOTPRODUCT3) |
---|
| 185 | return D3DTOP_DOTPRODUCT3; |
---|
| 186 | else |
---|
| 187 | return D3DTOP_MODULATE; |
---|
| 188 | case LBX_BLEND_DIFFUSE_COLOUR: |
---|
| 189 | if (devCaps.TextureOpCaps & D3DTEXOPCAPS_LERP) |
---|
| 190 | return D3DTOP_LERP; |
---|
| 191 | else |
---|
| 192 | return D3DTOP_MODULATE; |
---|
| 193 | } |
---|
| 194 | return 0; |
---|
| 195 | } |
---|
| 196 | //--------------------------------------------------------------------- |
---|
| 197 | D3DBLEND D3D9Mappings::get(SceneBlendFactor sbf) |
---|
| 198 | { |
---|
| 199 | switch( sbf ) |
---|
| 200 | { |
---|
| 201 | case SBF_ONE: |
---|
| 202 | return D3DBLEND_ONE; |
---|
| 203 | case SBF_ZERO: |
---|
| 204 | return D3DBLEND_ZERO; |
---|
| 205 | case SBF_DEST_COLOUR: |
---|
| 206 | return D3DBLEND_DESTCOLOR; |
---|
| 207 | case SBF_SOURCE_COLOUR: |
---|
| 208 | return D3DBLEND_SRCCOLOR; |
---|
| 209 | case SBF_ONE_MINUS_DEST_COLOUR: |
---|
| 210 | return D3DBLEND_INVDESTCOLOR; |
---|
| 211 | case SBF_ONE_MINUS_SOURCE_COLOUR: |
---|
| 212 | return D3DBLEND_INVSRCCOLOR; |
---|
| 213 | case SBF_DEST_ALPHA: |
---|
| 214 | return D3DBLEND_DESTALPHA; |
---|
| 215 | case SBF_SOURCE_ALPHA: |
---|
| 216 | return D3DBLEND_SRCALPHA; |
---|
| 217 | case SBF_ONE_MINUS_DEST_ALPHA: |
---|
| 218 | return D3DBLEND_INVDESTALPHA; |
---|
| 219 | case SBF_ONE_MINUS_SOURCE_ALPHA: |
---|
| 220 | return D3DBLEND_INVSRCALPHA; |
---|
| 221 | } |
---|
| 222 | return D3DBLEND_FORCE_DWORD; |
---|
| 223 | } |
---|
| 224 | //--------------------------------------------------------------------- |
---|
| 225 | DWORD D3D9Mappings::get(CompareFunction cf) |
---|
| 226 | { |
---|
| 227 | switch( cf ) |
---|
| 228 | { |
---|
| 229 | case CMPF_ALWAYS_FAIL: |
---|
| 230 | return D3DCMP_NEVER; |
---|
| 231 | case CMPF_ALWAYS_PASS: |
---|
| 232 | return D3DCMP_ALWAYS; |
---|
| 233 | case CMPF_LESS: |
---|
| 234 | return D3DCMP_LESS; |
---|
| 235 | case CMPF_LESS_EQUAL: |
---|
| 236 | return D3DCMP_LESSEQUAL; |
---|
| 237 | case CMPF_EQUAL: |
---|
| 238 | return D3DCMP_EQUAL; |
---|
| 239 | case CMPF_NOT_EQUAL: |
---|
| 240 | return D3DCMP_NOTEQUAL; |
---|
| 241 | case CMPF_GREATER_EQUAL: |
---|
| 242 | return D3DCMP_GREATEREQUAL; |
---|
| 243 | case CMPF_GREATER: |
---|
| 244 | return D3DCMP_GREATER; |
---|
| 245 | }; |
---|
| 246 | return 0; |
---|
| 247 | } |
---|
| 248 | //--------------------------------------------------------------------- |
---|
| 249 | DWORD D3D9Mappings::get(CullingMode cm, bool flip) |
---|
| 250 | { |
---|
| 251 | switch( cm ) |
---|
| 252 | { |
---|
| 253 | case CULL_NONE: |
---|
| 254 | return D3DCULL_NONE; |
---|
| 255 | case CULL_CLOCKWISE: |
---|
| 256 | if( flip ) |
---|
| 257 | return D3DCULL_CCW; |
---|
| 258 | else |
---|
| 259 | return D3DCULL_CW; |
---|
| 260 | case CULL_ANTICLOCKWISE: |
---|
| 261 | if( flip ) |
---|
| 262 | return D3DCULL_CW; |
---|
| 263 | else |
---|
| 264 | return D3DCULL_CCW; |
---|
| 265 | } |
---|
| 266 | return 0; |
---|
| 267 | } |
---|
| 268 | //--------------------------------------------------------------------- |
---|
| 269 | D3DFOGMODE D3D9Mappings::get(FogMode fm) |
---|
| 270 | { |
---|
| 271 | switch( fm ) |
---|
| 272 | { |
---|
| 273 | case FOG_EXP: |
---|
| 274 | return D3DFOG_EXP; |
---|
| 275 | case FOG_EXP2: |
---|
| 276 | return D3DFOG_EXP2; |
---|
| 277 | case FOG_LINEAR: |
---|
| 278 | return D3DFOG_LINEAR; |
---|
| 279 | } |
---|
| 280 | return D3DFOG_FORCE_DWORD; |
---|
| 281 | } |
---|
| 282 | //--------------------------------------------------------------------- |
---|
| 283 | D3DFILLMODE D3D9Mappings::get(PolygonMode level) |
---|
| 284 | { |
---|
| 285 | switch(level) |
---|
| 286 | { |
---|
| 287 | case PM_POINTS: |
---|
| 288 | return D3DFILL_POINT; |
---|
| 289 | case PM_WIREFRAME: |
---|
| 290 | return D3DFILL_WIREFRAME; |
---|
| 291 | case PM_SOLID: |
---|
| 292 | return D3DFILL_SOLID; |
---|
| 293 | } |
---|
| 294 | return D3DFILL_FORCE_DWORD; |
---|
| 295 | } |
---|
| 296 | //--------------------------------------------------------------------- |
---|
| 297 | DWORD D3D9Mappings::get(StencilOperation op, bool invert) |
---|
| 298 | { |
---|
| 299 | switch(op) |
---|
| 300 | { |
---|
| 301 | case SOP_KEEP: |
---|
| 302 | return D3DSTENCILOP_KEEP; |
---|
| 303 | case SOP_ZERO: |
---|
| 304 | return D3DSTENCILOP_ZERO; |
---|
| 305 | case SOP_REPLACE: |
---|
| 306 | return D3DSTENCILOP_REPLACE; |
---|
| 307 | case SOP_INCREMENT: |
---|
| 308 | return invert? D3DSTENCILOP_DECRSAT : D3DSTENCILOP_INCRSAT; |
---|
| 309 | case SOP_DECREMENT: |
---|
| 310 | return invert? D3DSTENCILOP_INCRSAT : D3DSTENCILOP_DECRSAT; |
---|
| 311 | case SOP_INCREMENT_WRAP: |
---|
| 312 | return invert? D3DSTENCILOP_DECR : D3DSTENCILOP_INCR; |
---|
| 313 | case SOP_DECREMENT_WRAP: |
---|
| 314 | return invert? D3DSTENCILOP_INCR : D3DSTENCILOP_DECR; |
---|
| 315 | case SOP_INVERT: |
---|
| 316 | return D3DSTENCILOP_INVERT; |
---|
| 317 | } |
---|
| 318 | return 0; |
---|
| 319 | } |
---|
| 320 | //--------------------------------------------------------------------- |
---|
| 321 | D3DSAMPLERSTATETYPE D3D9Mappings::get(FilterType ft) |
---|
| 322 | { |
---|
| 323 | switch (ft) |
---|
| 324 | { |
---|
| 325 | case FT_MIN: |
---|
| 326 | return D3DSAMP_MINFILTER; |
---|
| 327 | break; |
---|
| 328 | case FT_MAG: |
---|
| 329 | return D3DSAMP_MAGFILTER; |
---|
| 330 | break; |
---|
| 331 | case FT_MIP: |
---|
| 332 | return D3DSAMP_MIPFILTER; |
---|
| 333 | break; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | // to keep compiler happy |
---|
| 337 | return D3DSAMP_MINFILTER; |
---|
| 338 | } |
---|
| 339 | //--------------------------------------------------------------------- |
---|
| 340 | DWORD D3D9Mappings::get(FilterType ft, FilterOptions fo, const D3DCAPS9& devCaps, |
---|
| 341 | eD3DTexType texType) |
---|
| 342 | { |
---|
| 343 | // Assume normal |
---|
| 344 | DWORD capsType = devCaps.TextureFilterCaps; |
---|
| 345 | |
---|
| 346 | switch( texType ) |
---|
| 347 | { |
---|
| 348 | case D3D_TEX_TYPE_NORMAL: |
---|
| 349 | capsType = devCaps.TextureFilterCaps; |
---|
| 350 | break; |
---|
| 351 | case D3D_TEX_TYPE_CUBE: |
---|
| 352 | capsType = devCaps.CubeTextureFilterCaps; |
---|
| 353 | break; |
---|
| 354 | case D3D_TEX_TYPE_VOLUME: |
---|
| 355 | capsType = devCaps.VolumeTextureFilterCaps; |
---|
| 356 | break; |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | switch (ft) |
---|
| 360 | { |
---|
| 361 | case FT_MIN: |
---|
| 362 | switch( fo ) |
---|
| 363 | { |
---|
| 364 | // NOTE: Fall through if device doesn't support requested type |
---|
| 365 | case FO_ANISOTROPIC: |
---|
| 366 | if( capsType & D3DPTFILTERCAPS_MINFANISOTROPIC ) |
---|
| 367 | { |
---|
| 368 | return D3DTEXF_ANISOTROPIC; |
---|
| 369 | break; |
---|
| 370 | } |
---|
| 371 | case FO_LINEAR: |
---|
| 372 | if( capsType & D3DPTFILTERCAPS_MINFLINEAR ) |
---|
| 373 | { |
---|
| 374 | return D3DTEXF_LINEAR; |
---|
| 375 | break; |
---|
| 376 | } |
---|
| 377 | case FO_POINT: |
---|
| 378 | case FO_NONE: |
---|
| 379 | return D3DTEXF_POINT; |
---|
| 380 | break; |
---|
| 381 | } |
---|
| 382 | break; |
---|
| 383 | case FT_MAG: |
---|
| 384 | switch( fo ) |
---|
| 385 | { |
---|
| 386 | // NOTE: Fall through if device doesn't support requested type |
---|
| 387 | case FO_ANISOTROPIC: |
---|
| 388 | if( capsType & D3DPTFILTERCAPS_MAGFANISOTROPIC ) |
---|
| 389 | { |
---|
| 390 | return D3DTEXF_ANISOTROPIC; |
---|
| 391 | break; |
---|
| 392 | } |
---|
| 393 | case FO_LINEAR: |
---|
| 394 | if( capsType & D3DPTFILTERCAPS_MAGFLINEAR ) |
---|
| 395 | { |
---|
| 396 | return D3DTEXF_LINEAR; |
---|
| 397 | break; |
---|
| 398 | } |
---|
| 399 | case FO_POINT: |
---|
| 400 | case FO_NONE: |
---|
| 401 | return D3DTEXF_POINT; |
---|
| 402 | break; |
---|
| 403 | } |
---|
| 404 | break; |
---|
| 405 | case FT_MIP: |
---|
| 406 | switch( fo ) |
---|
| 407 | { |
---|
| 408 | case FO_ANISOTROPIC: |
---|
| 409 | case FO_LINEAR: |
---|
| 410 | if( capsType & D3DPTFILTERCAPS_MIPFLINEAR ) |
---|
| 411 | { |
---|
| 412 | return D3DTEXF_LINEAR; |
---|
| 413 | break; |
---|
| 414 | } |
---|
| 415 | case FO_POINT: |
---|
| 416 | if( capsType & D3DPTFILTERCAPS_MIPFPOINT ) |
---|
| 417 | { |
---|
| 418 | return D3DTEXF_POINT; |
---|
| 419 | break; |
---|
| 420 | } |
---|
| 421 | case FO_NONE: |
---|
| 422 | return D3DTEXF_NONE; |
---|
| 423 | break; |
---|
| 424 | } |
---|
| 425 | break; |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | // should never get here |
---|
| 429 | return 0; |
---|
| 430 | |
---|
| 431 | } |
---|
| 432 | //--------------------------------------------------------------------- |
---|
| 433 | D3D9Mappings::eD3DTexType D3D9Mappings::get(TextureType ogreTexType) |
---|
| 434 | { |
---|
| 435 | switch( ogreTexType ) |
---|
| 436 | { |
---|
| 437 | case TEX_TYPE_1D : |
---|
| 438 | case TEX_TYPE_2D : |
---|
| 439 | return D3D9Mappings::D3D_TEX_TYPE_NORMAL; |
---|
| 440 | case TEX_TYPE_CUBE_MAP : |
---|
| 441 | return D3D9Mappings::D3D_TEX_TYPE_CUBE; |
---|
| 442 | case TEX_TYPE_3D : |
---|
| 443 | return D3D9Mappings::D3D_TEX_TYPE_VOLUME; |
---|
| 444 | } |
---|
| 445 | return D3D9Mappings::D3D_TEX_TYPE_NONE; |
---|
| 446 | } |
---|
| 447 | //--------------------------------------------------------------------- |
---|
| 448 | DWORD D3D9Mappings::get(HardwareBuffer::Usage usage) |
---|
| 449 | { |
---|
| 450 | DWORD ret = 0; |
---|
| 451 | if (usage & HardwareBuffer::HBU_DYNAMIC) |
---|
| 452 | { |
---|
| 453 | #if OGRE_D3D_MANAGE_BUFFERS |
---|
| 454 | // Only add the dynamic flag for default pool, and |
---|
| 455 | // we use default pool when buffer is discardable |
---|
| 456 | if (usage & HardwareBuffer::HBU_DISCARDABLE) |
---|
| 457 | ret |= D3DUSAGE_DYNAMIC; |
---|
| 458 | #else |
---|
| 459 | ret |= D3DUSAGE_DYNAMIC; |
---|
| 460 | #endif |
---|
| 461 | } |
---|
| 462 | if (usage & HardwareBuffer::HBU_WRITE_ONLY) |
---|
| 463 | { |
---|
| 464 | ret |= D3DUSAGE_WRITEONLY; |
---|
| 465 | } |
---|
| 466 | return ret; |
---|
| 467 | } |
---|
| 468 | //--------------------------------------------------------------------- |
---|
| 469 | DWORD D3D9Mappings::get(HardwareBuffer::LockOptions options, HardwareBuffer::Usage usage) |
---|
| 470 | { |
---|
| 471 | DWORD ret = 0; |
---|
| 472 | if (options == HardwareBuffer::HBL_DISCARD) |
---|
| 473 | { |
---|
| 474 | #if OGRE_D3D_MANAGE_BUFFERS |
---|
| 475 | // Only add the discard flag for dynamic usgae and default pool |
---|
| 476 | if ((usage & HardwareBuffer::HBU_DYNAMIC) && |
---|
| 477 | (usage & HardwareBuffer::HBU_DISCARDABLE)) |
---|
| 478 | ret |= D3DLOCK_DISCARD; |
---|
| 479 | #else |
---|
| 480 | // D3D doesn't like discard or no_overwrite on non-dynamic buffers |
---|
| 481 | if (usage & HardwareBuffer::HBU_DYNAMIC) |
---|
| 482 | ret |= D3DLOCK_DISCARD; |
---|
| 483 | #endif |
---|
| 484 | } |
---|
| 485 | if (options == HardwareBuffer::HBL_READ_ONLY) |
---|
| 486 | { |
---|
| 487 | // D3D debug runtime doesn't like you locking managed buffers readonly |
---|
| 488 | // when they were created with write-only (even though you CAN read |
---|
| 489 | // from the software backed version) |
---|
| 490 | if (!(usage & HardwareBuffer::HBU_WRITE_ONLY)) |
---|
| 491 | ret |= D3DLOCK_READONLY; |
---|
| 492 | |
---|
| 493 | } |
---|
| 494 | if (options == HardwareBuffer::HBL_NO_OVERWRITE) |
---|
| 495 | { |
---|
| 496 | #if OGRE_D3D_MANAGE_BUFFERS |
---|
| 497 | // Only add the nooverwrite flag for dynamic usgae and default pool |
---|
| 498 | if ((usage & HardwareBuffer::HBU_DYNAMIC) && |
---|
| 499 | (usage & HardwareBuffer::HBU_DISCARDABLE)) |
---|
| 500 | ret |= D3DLOCK_NOOVERWRITE; |
---|
| 501 | #else |
---|
| 502 | // D3D doesn't like discard or no_overwrite on non-dynamic buffers |
---|
| 503 | if (usage & HardwareBuffer::HBU_DYNAMIC) |
---|
| 504 | ret |= D3DLOCK_NOOVERWRITE; |
---|
| 505 | #endif |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | return ret; |
---|
| 509 | } |
---|
| 510 | //--------------------------------------------------------------------- |
---|
| 511 | D3DFORMAT D3D9Mappings::get(HardwareIndexBuffer::IndexType itype) |
---|
| 512 | { |
---|
| 513 | if (itype == HardwareIndexBuffer::IT_32BIT) |
---|
| 514 | { |
---|
| 515 | return D3DFMT_INDEX32; |
---|
| 516 | } |
---|
| 517 | else |
---|
| 518 | { |
---|
| 519 | return D3DFMT_INDEX16; |
---|
| 520 | } |
---|
| 521 | } |
---|
| 522 | //--------------------------------------------------------------------- |
---|
| 523 | D3DDECLTYPE D3D9Mappings::get(VertexElementType vType) |
---|
| 524 | { |
---|
| 525 | switch (vType) |
---|
| 526 | { |
---|
| 527 | case VET_COLOUR: |
---|
| 528 | case VET_COLOUR_ABGR: |
---|
| 529 | case VET_COLOUR_ARGB: |
---|
| 530 | return D3DDECLTYPE_D3DCOLOR; |
---|
| 531 | break; |
---|
| 532 | case VET_FLOAT1: |
---|
| 533 | return D3DDECLTYPE_FLOAT1; |
---|
| 534 | break; |
---|
| 535 | case VET_FLOAT2: |
---|
| 536 | return D3DDECLTYPE_FLOAT2; |
---|
| 537 | break; |
---|
| 538 | case VET_FLOAT3: |
---|
| 539 | return D3DDECLTYPE_FLOAT3; |
---|
| 540 | break; |
---|
| 541 | case VET_FLOAT4: |
---|
| 542 | return D3DDECLTYPE_FLOAT4; |
---|
| 543 | break; |
---|
| 544 | case VET_SHORT2: |
---|
| 545 | return D3DDECLTYPE_SHORT2; |
---|
| 546 | break; |
---|
| 547 | case VET_SHORT4: |
---|
| 548 | return D3DDECLTYPE_SHORT4; |
---|
| 549 | break; |
---|
| 550 | case VET_UBYTE4: |
---|
| 551 | return D3DDECLTYPE_UBYTE4; |
---|
| 552 | break; |
---|
| 553 | } |
---|
| 554 | // to keep compiler happy |
---|
| 555 | return D3DDECLTYPE_FLOAT3; |
---|
| 556 | } |
---|
| 557 | //--------------------------------------------------------------------- |
---|
| 558 | D3DDECLUSAGE D3D9Mappings::get(VertexElementSemantic sem) |
---|
| 559 | { |
---|
| 560 | switch (sem) |
---|
| 561 | { |
---|
| 562 | case VES_BLEND_INDICES: |
---|
| 563 | return D3DDECLUSAGE_BLENDINDICES; |
---|
| 564 | break; |
---|
| 565 | case VES_BLEND_WEIGHTS: |
---|
| 566 | return D3DDECLUSAGE_BLENDWEIGHT; |
---|
| 567 | break; |
---|
| 568 | case VES_DIFFUSE: |
---|
| 569 | return D3DDECLUSAGE_COLOR; // NB index will differentiate |
---|
| 570 | break; |
---|
| 571 | case VES_SPECULAR: |
---|
| 572 | return D3DDECLUSAGE_COLOR; // NB index will differentiate |
---|
| 573 | break; |
---|
| 574 | case VES_NORMAL: |
---|
| 575 | return D3DDECLUSAGE_NORMAL; |
---|
| 576 | break; |
---|
| 577 | case VES_POSITION: |
---|
| 578 | return D3DDECLUSAGE_POSITION; |
---|
| 579 | break; |
---|
| 580 | case VES_TEXTURE_COORDINATES: |
---|
| 581 | return D3DDECLUSAGE_TEXCOORD; |
---|
| 582 | break; |
---|
| 583 | case VES_BINORMAL: |
---|
| 584 | return D3DDECLUSAGE_BINORMAL; |
---|
| 585 | break; |
---|
| 586 | case VES_TANGENT: |
---|
| 587 | return D3DDECLUSAGE_TANGENT; |
---|
| 588 | break; |
---|
| 589 | } |
---|
| 590 | // to keep compiler happy |
---|
| 591 | return D3DDECLUSAGE_POSITION; |
---|
| 592 | } |
---|
| 593 | //--------------------------------------------------------------------- |
---|
| 594 | D3DXMATRIX D3D9Mappings::makeD3DXMatrix( const Matrix4& mat ) |
---|
| 595 | { |
---|
| 596 | // Transpose matrix |
---|
| 597 | // D3D9 uses row vectors i.e. V*M |
---|
| 598 | // Ogre, OpenGL and everything else uses column vectors i.e. M*V |
---|
| 599 | return D3DXMATRIX( |
---|
| 600 | mat[0][0], mat[1][0], mat[2][0], mat[3][0], |
---|
| 601 | mat[0][1], mat[1][1], mat[2][1], mat[3][1], |
---|
| 602 | mat[0][2], mat[1][2], mat[2][2], mat[3][2], |
---|
| 603 | mat[0][3], mat[1][3], mat[2][3], mat[3][3]); |
---|
| 604 | } |
---|
| 605 | //--------------------------------------------------------------------- |
---|
| 606 | Matrix4 D3D9Mappings::convertD3DXMatrix( const D3DXMATRIX& mat ) |
---|
| 607 | { |
---|
| 608 | return Matrix4( |
---|
| 609 | mat.m[0][0], mat.m[1][0], mat.m[2][0], mat.m[3][0], |
---|
| 610 | mat.m[0][1], mat.m[1][1], mat.m[2][1], mat.m[3][1], |
---|
| 611 | mat.m[0][2], mat.m[1][2], mat.m[2][2], mat.m[3][2], |
---|
| 612 | mat.m[0][3], mat.m[1][3], mat.m[2][3], mat.m[3][3]); |
---|
| 613 | } |
---|
| 614 | /****************************************************************************************/ |
---|
| 615 | PixelFormat D3D9Mappings::_getPF(D3DFORMAT d3dPF) |
---|
| 616 | { |
---|
| 617 | switch(d3dPF) |
---|
| 618 | { |
---|
| 619 | case D3DFMT_A8: |
---|
| 620 | return PF_A8; |
---|
| 621 | case D3DFMT_L8: |
---|
| 622 | return PF_L8; |
---|
| 623 | case D3DFMT_L16: |
---|
| 624 | return PF_L16; |
---|
| 625 | case D3DFMT_A4L4: |
---|
| 626 | return PF_A4L4; |
---|
| 627 | case D3DFMT_A8L8: |
---|
| 628 | return PF_BYTE_LA; // Assume little endian here |
---|
| 629 | case D3DFMT_R3G3B2: |
---|
| 630 | return PF_R3G3B2; |
---|
| 631 | case D3DFMT_A1R5G5B5: |
---|
| 632 | return PF_A1R5G5B5; |
---|
| 633 | case D3DFMT_A4R4G4B4: |
---|
| 634 | return PF_A4R4G4B4; |
---|
| 635 | case D3DFMT_R5G6B5: |
---|
| 636 | return PF_R5G6B5; |
---|
| 637 | case D3DFMT_R8G8B8: |
---|
| 638 | return PF_R8G8B8; |
---|
| 639 | case D3DFMT_X8R8G8B8: |
---|
| 640 | return PF_X8R8G8B8; |
---|
| 641 | case D3DFMT_A8R8G8B8: |
---|
| 642 | return PF_A8R8G8B8; |
---|
| 643 | case D3DFMT_X8B8G8R8: |
---|
| 644 | return PF_X8B8G8R8; |
---|
| 645 | case D3DFMT_A8B8G8R8: |
---|
| 646 | return PF_A8B8G8R8; |
---|
| 647 | case D3DFMT_A2R10G10B10: |
---|
| 648 | return PF_A2R10G10B10; |
---|
| 649 | case D3DFMT_A2B10G10R10: |
---|
| 650 | return PF_A2B10G10R10; |
---|
| 651 | case D3DFMT_R16F: |
---|
| 652 | return PF_FLOAT16_R; |
---|
| 653 | case D3DFMT_A16B16G16R16F: |
---|
| 654 | return PF_FLOAT16_RGBA; |
---|
| 655 | case D3DFMT_R32F: |
---|
| 656 | return PF_FLOAT32_R; |
---|
| 657 | case D3DFMT_G32R32F: |
---|
| 658 | return PF_FLOAT32_GR; |
---|
| 659 | case D3DFMT_A32B32G32R32F: |
---|
| 660 | return PF_FLOAT32_RGBA; |
---|
| 661 | case D3DFMT_G16R16F: |
---|
| 662 | return PF_FLOAT16_GR; |
---|
| 663 | case D3DFMT_A16B16G16R16: |
---|
| 664 | return PF_SHORT_RGBA; |
---|
| 665 | case D3DFMT_G16R16: |
---|
| 666 | return PF_SHORT_GR; |
---|
| 667 | case D3DFMT_DXT1: |
---|
| 668 | return PF_DXT1; |
---|
| 669 | case D3DFMT_DXT2: |
---|
| 670 | return PF_DXT2; |
---|
| 671 | case D3DFMT_DXT3: |
---|
| 672 | return PF_DXT3; |
---|
| 673 | case D3DFMT_DXT4: |
---|
| 674 | return PF_DXT4; |
---|
| 675 | case D3DFMT_DXT5: |
---|
| 676 | return PF_DXT5; |
---|
| 677 | default: |
---|
| 678 | return PF_UNKNOWN; |
---|
| 679 | } |
---|
| 680 | } |
---|
| 681 | /****************************************************************************************/ |
---|
| 682 | D3DFORMAT D3D9Mappings::_getPF(PixelFormat ogrePF) |
---|
| 683 | { |
---|
| 684 | switch(ogrePF) |
---|
| 685 | { |
---|
| 686 | case PF_L8: |
---|
| 687 | return D3DFMT_L8; |
---|
| 688 | case PF_L16: |
---|
| 689 | return D3DFMT_L16; |
---|
| 690 | case PF_A8: |
---|
| 691 | return D3DFMT_A8; |
---|
| 692 | case PF_A4L4: |
---|
| 693 | return D3DFMT_A4L4; |
---|
| 694 | case PF_BYTE_LA: |
---|
| 695 | return D3DFMT_A8L8; // Assume little endian here |
---|
| 696 | case PF_R3G3B2: |
---|
| 697 | return D3DFMT_R3G3B2; |
---|
| 698 | case PF_A1R5G5B5: |
---|
| 699 | return D3DFMT_A1R5G5B5; |
---|
| 700 | case PF_R5G6B5: |
---|
| 701 | return D3DFMT_R5G6B5; |
---|
| 702 | case PF_A4R4G4B4: |
---|
| 703 | return D3DFMT_A4R4G4B4; |
---|
| 704 | case PF_R8G8B8: |
---|
| 705 | return D3DFMT_R8G8B8; |
---|
| 706 | case PF_A8R8G8B8: |
---|
| 707 | return D3DFMT_A8R8G8B8; |
---|
| 708 | case PF_A8B8G8R8: |
---|
| 709 | return D3DFMT_A8B8G8R8; |
---|
| 710 | case PF_X8R8G8B8: |
---|
| 711 | return D3DFMT_X8R8G8B8; |
---|
| 712 | case PF_X8B8G8R8: |
---|
| 713 | return D3DFMT_X8B8G8R8; |
---|
| 714 | case PF_A2B10G10R10: |
---|
| 715 | return D3DFMT_A2B10G10R10; |
---|
| 716 | case PF_A2R10G10B10: |
---|
| 717 | return D3DFMT_A2R10G10B10; |
---|
| 718 | case PF_FLOAT16_R: |
---|
| 719 | return D3DFMT_R16F; |
---|
| 720 | case PF_FLOAT16_GR: |
---|
| 721 | return D3DFMT_G16R16F; |
---|
| 722 | case PF_FLOAT16_RGBA: |
---|
| 723 | return D3DFMT_A16B16G16R16F; |
---|
| 724 | case PF_FLOAT32_R: |
---|
| 725 | return D3DFMT_R32F; |
---|
| 726 | case PF_FLOAT32_GR: |
---|
| 727 | return D3DFMT_G32R32F; |
---|
| 728 | case PF_FLOAT32_RGBA: |
---|
| 729 | return D3DFMT_A32B32G32R32F; |
---|
| 730 | case PF_SHORT_RGBA: |
---|
| 731 | return D3DFMT_A16B16G16R16; |
---|
| 732 | case PF_SHORT_GR: |
---|
| 733 | return D3DFMT_G16R16; |
---|
| 734 | case PF_DXT1: |
---|
| 735 | return D3DFMT_DXT1; |
---|
| 736 | case PF_DXT2: |
---|
| 737 | return D3DFMT_DXT2; |
---|
| 738 | case PF_DXT3: |
---|
| 739 | return D3DFMT_DXT3; |
---|
| 740 | case PF_DXT4: |
---|
| 741 | return D3DFMT_DXT4; |
---|
| 742 | case PF_DXT5: |
---|
| 743 | return D3DFMT_DXT5; |
---|
| 744 | case PF_UNKNOWN: |
---|
| 745 | default: |
---|
| 746 | return D3DFMT_UNKNOWN; |
---|
| 747 | } |
---|
| 748 | } |
---|
| 749 | /****************************************************************************************/ |
---|
| 750 | PixelFormat D3D9Mappings::_getClosestSupportedPF(PixelFormat ogrePF) |
---|
| 751 | { |
---|
| 752 | if (_getPF(ogrePF) != D3DFMT_UNKNOWN) |
---|
| 753 | { |
---|
| 754 | return ogrePF; |
---|
| 755 | } |
---|
| 756 | switch(ogrePF) |
---|
| 757 | { |
---|
| 758 | case PF_B5G6R5: |
---|
| 759 | return PF_R5G6B5; |
---|
| 760 | case PF_B8G8R8: |
---|
| 761 | return PF_R8G8B8; |
---|
| 762 | case PF_B8G8R8A8: |
---|
| 763 | return PF_A8R8G8B8; |
---|
| 764 | case PF_SHORT_RGB: |
---|
| 765 | return PF_SHORT_RGBA; |
---|
| 766 | case PF_FLOAT16_RGB: |
---|
| 767 | return PF_FLOAT16_RGBA; |
---|
| 768 | case PF_FLOAT32_RGB: |
---|
| 769 | return PF_FLOAT32_RGBA; |
---|
| 770 | case PF_UNKNOWN: |
---|
| 771 | default: |
---|
| 772 | return PF_A8R8G8B8; |
---|
| 773 | } |
---|
| 774 | } |
---|
| 775 | |
---|
| 776 | } |
---|