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-2005 The OGRE Team
|
---|
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 | */
|
---|
25 | #include "OgreD3D9Mappings.h"
|
---|
26 | #include "OgreString.h"
|
---|
27 | #include "OgreStringConverter.h"
|
---|
28 | #include "OgreLogManager.h"
|
---|
29 | #include "OgreException.h"
|
---|
30 |
|
---|
31 | namespace Ogre
|
---|
32 | {
|
---|
33 | //---------------------------------------------------------------------
|
---|
34 | DWORD D3D9Mappings::get(ShadeOptions so)
|
---|
35 | {
|
---|
36 | switch( so )
|
---|
37 | {
|
---|
38 | case SO_FLAT:
|
---|
39 | return D3DSHADE_FLAT;
|
---|
40 | case SO_GOURAUD:
|
---|
41 | return D3DSHADE_GOURAUD;
|
---|
42 | case SO_PHONG:
|
---|
43 | return D3DSHADE_PHONG;
|
---|
44 | }
|
---|
45 | return 0;
|
---|
46 | }
|
---|
47 | //---------------------------------------------------------------------
|
---|
48 | D3DLIGHTTYPE D3D9Mappings::get(Ogre::Light::LightTypes lightType)
|
---|
49 | {
|
---|
50 | switch( lightType )
|
---|
51 | {
|
---|
52 | case Light::LT_POINT:
|
---|
53 | return D3DLIGHT_POINT;
|
---|
54 | case Light::LT_DIRECTIONAL:
|
---|
55 | return D3DLIGHT_DIRECTIONAL;
|
---|
56 | case Light::LT_SPOTLIGHT:
|
---|
57 | return D3DLIGHT_SPOT;
|
---|
58 | }
|
---|
59 | return D3DLIGHT_FORCE_DWORD;
|
---|
60 | }
|
---|
61 | //---------------------------------------------------------------------
|
---|
62 | DWORD D3D9Mappings::get(TexCoordCalcMethod m, const D3DCAPS9& caps)
|
---|
63 | {
|
---|
64 | switch( m )
|
---|
65 | {
|
---|
66 | case TEXCALC_NONE:
|
---|
67 | return D3DTSS_TCI_PASSTHRU;
|
---|
68 | case TEXCALC_ENVIRONMENT_MAP_REFLECTION:
|
---|
69 | return D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR;
|
---|
70 | case TEXCALC_ENVIRONMENT_MAP_PLANAR:
|
---|
71 | if (caps.VertexProcessingCaps & D3DVTXPCAPS_TEXGEN_SPHEREMAP)
|
---|
72 | {
|
---|
73 | // Use sphere map if available
|
---|
74 | return D3DTSS_TCI_SPHEREMAP;
|
---|
75 | }
|
---|
76 | else
|
---|
77 | {
|
---|
78 | // If not, fall back on camera space reflection vector which isn't as good
|
---|
79 | return D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR;
|
---|
80 | }
|
---|
81 | case TEXCALC_ENVIRONMENT_MAP_NORMAL:
|
---|
82 | return D3DTSS_TCI_CAMERASPACENORMAL;
|
---|
83 | case TEXCALC_ENVIRONMENT_MAP:
|
---|
84 | if (caps.VertexProcessingCaps & D3DVTXPCAPS_TEXGEN_SPHEREMAP)
|
---|
85 | {
|
---|
86 | // Use sphere map if available
|
---|
87 | return D3DTSS_TCI_SPHEREMAP;
|
---|
88 | }
|
---|
89 | else
|
---|
90 | {
|
---|
91 | // If not, fall back on camera space normal which isn't as good
|
---|
92 | return D3DTSS_TCI_CAMERASPACENORMAL;
|
---|
93 | }
|
---|
94 | case TEXCALC_PROJECTIVE_TEXTURE:
|
---|
95 | return D3DTSS_TCI_CAMERASPACEPOSITION;
|
---|
96 | }
|
---|
97 | return 0;
|
---|
98 | }
|
---|
99 | //---------------------------------------------------------------------
|
---|
100 | D3DTEXTUREADDRESS D3D9Mappings::get(TextureUnitState::TextureAddressingMode tam)
|
---|
101 | {
|
---|
102 | switch( tam )
|
---|
103 | {
|
---|
104 | case TextureUnitState::TAM_WRAP:
|
---|
105 | return D3DTADDRESS_WRAP;
|
---|
106 | case TextureUnitState::TAM_MIRROR:
|
---|
107 | return D3DTADDRESS_MIRROR;
|
---|
108 | case TextureUnitState::TAM_CLAMP:
|
---|
109 | return D3DTADDRESS_CLAMP;
|
---|
110 | }
|
---|
111 | return D3DTADDRESS_FORCE_DWORD;
|
---|
112 | }
|
---|
113 | //---------------------------------------------------------------------
|
---|
114 | D3DTEXTURESTAGESTATETYPE D3D9Mappings::get(LayerBlendType lbt)
|
---|
115 | {
|
---|
116 | switch( lbt )
|
---|
117 | {
|
---|
118 | case LBT_COLOUR:
|
---|
119 | return D3DTSS_COLOROP;
|
---|
120 | case LBT_ALPHA:
|
---|
121 | return D3DTSS_ALPHAOP;
|
---|
122 | }
|
---|
123 | return D3DTSS_FORCE_DWORD;
|
---|
124 | }
|
---|
125 | //---------------------------------------------------------------------
|
---|
126 | DWORD D3D9Mappings::get(LayerBlendSource lbs)
|
---|
127 | {
|
---|
128 | switch( lbs )
|
---|
129 | {
|
---|
130 | case LBS_CURRENT:
|
---|
131 | return D3DTA_CURRENT;
|
---|
132 | case LBS_TEXTURE:
|
---|
133 | return D3DTA_TEXTURE;
|
---|
134 | case LBS_DIFFUSE:
|
---|
135 | return D3DTA_DIFFUSE;
|
---|
136 | case LBS_SPECULAR:
|
---|
137 | return D3DTA_SPECULAR;
|
---|
138 | case LBS_MANUAL:
|
---|
139 | return D3DTA_TFACTOR;
|
---|
140 | }
|
---|
141 | return 0;
|
---|
142 | }
|
---|
143 | //---------------------------------------------------------------------
|
---|
144 | DWORD D3D9Mappings::get(LayerBlendOperationEx lbo, const D3DCAPS9& devCaps)
|
---|
145 | {
|
---|
146 | switch( lbo )
|
---|
147 | {
|
---|
148 | case LBX_SOURCE1:
|
---|
149 | return D3DTOP_SELECTARG1;
|
---|
150 | case LBX_SOURCE2:
|
---|
151 | return D3DTOP_SELECTARG2;
|
---|
152 | case LBX_MODULATE:
|
---|
153 | return D3DTOP_MODULATE;
|
---|
154 | case LBX_MODULATE_X2:
|
---|
155 | return D3DTOP_MODULATE2X;
|
---|
156 | case LBX_MODULATE_X4:
|
---|
157 | return D3DTOP_MODULATE4X;
|
---|
158 | case LBX_ADD:
|
---|
159 | return D3DTOP_ADD;
|
---|
160 | case LBX_ADD_SIGNED:
|
---|
161 | return D3DTOP_ADDSIGNED;
|
---|
162 | case LBX_ADD_SMOOTH:
|
---|
163 | return D3DTOP_ADDSMOOTH;
|
---|
164 | case LBX_SUBTRACT:
|
---|
165 | return D3DTOP_SUBTRACT;
|
---|
166 | case LBX_BLEND_DIFFUSE_ALPHA:
|
---|
167 | return D3DTOP_BLENDDIFFUSEALPHA;
|
---|
168 | case LBX_BLEND_TEXTURE_ALPHA:
|
---|
169 | return D3DTOP_BLENDTEXTUREALPHA;
|
---|
170 | case LBX_BLEND_CURRENT_ALPHA:
|
---|
171 | return D3DTOP_BLENDCURRENTALPHA;
|
---|
172 | case LBX_BLEND_MANUAL:
|
---|
173 | return D3DTOP_BLENDFACTORALPHA;
|
---|
174 | case LBX_DOTPRODUCT:
|
---|
175 | if (devCaps.TextureOpCaps & D3DTEXOPCAPS_DOTPRODUCT3)
|
---|
176 | return D3DTOP_DOTPRODUCT3;
|
---|
177 | else
|
---|
178 | return D3DTOP_MODULATE;
|
---|
179 | }
|
---|
180 | return 0;
|
---|
181 | }
|
---|
182 | //---------------------------------------------------------------------
|
---|
183 | D3DBLEND D3D9Mappings::get(SceneBlendFactor sbf)
|
---|
184 | {
|
---|
185 | switch( sbf )
|
---|
186 | {
|
---|
187 | case SBF_ONE:
|
---|
188 | return D3DBLEND_ONE;
|
---|
189 | case SBF_ZERO:
|
---|
190 | return D3DBLEND_ZERO;
|
---|
191 | case SBF_DEST_COLOUR:
|
---|
192 | return D3DBLEND_DESTCOLOR;
|
---|
193 | case SBF_SOURCE_COLOUR:
|
---|
194 | return D3DBLEND_SRCCOLOR;
|
---|
195 | case SBF_ONE_MINUS_DEST_COLOUR:
|
---|
196 | return D3DBLEND_INVDESTCOLOR;
|
---|
197 | case SBF_ONE_MINUS_SOURCE_COLOUR:
|
---|
198 | return D3DBLEND_INVSRCCOLOR;
|
---|
199 | case SBF_DEST_ALPHA:
|
---|
200 | return D3DBLEND_DESTALPHA;
|
---|
201 | case SBF_SOURCE_ALPHA:
|
---|
202 | return D3DBLEND_SRCALPHA;
|
---|
203 | case SBF_ONE_MINUS_DEST_ALPHA:
|
---|
204 | return D3DBLEND_INVDESTALPHA;
|
---|
205 | case SBF_ONE_MINUS_SOURCE_ALPHA:
|
---|
206 | return D3DBLEND_INVSRCALPHA;
|
---|
207 | }
|
---|
208 | return D3DBLEND_FORCE_DWORD;
|
---|
209 | }
|
---|
210 | //---------------------------------------------------------------------
|
---|
211 | DWORD D3D9Mappings::get(CompareFunction cf)
|
---|
212 | {
|
---|
213 | switch( cf )
|
---|
214 | {
|
---|
215 | case CMPF_ALWAYS_FAIL:
|
---|
216 | return D3DCMP_NEVER;
|
---|
217 | case CMPF_ALWAYS_PASS:
|
---|
218 | return D3DCMP_ALWAYS;
|
---|
219 | case CMPF_LESS:
|
---|
220 | return D3DCMP_LESS;
|
---|
221 | case CMPF_LESS_EQUAL:
|
---|
222 | return D3DCMP_LESSEQUAL;
|
---|
223 | case CMPF_EQUAL:
|
---|
224 | return D3DCMP_EQUAL;
|
---|
225 | case CMPF_NOT_EQUAL:
|
---|
226 | return D3DCMP_NOTEQUAL;
|
---|
227 | case CMPF_GREATER_EQUAL:
|
---|
228 | return D3DCMP_GREATEREQUAL;
|
---|
229 | case CMPF_GREATER:
|
---|
230 | return D3DCMP_GREATER;
|
---|
231 | };
|
---|
232 | return 0;
|
---|
233 | }
|
---|
234 | //---------------------------------------------------------------------
|
---|
235 | DWORD D3D9Mappings::get(CullingMode cm, bool flip)
|
---|
236 | {
|
---|
237 | switch( cm )
|
---|
238 | {
|
---|
239 | case CULL_NONE:
|
---|
240 | return D3DCULL_NONE;
|
---|
241 | case CULL_CLOCKWISE:
|
---|
242 | if( flip )
|
---|
243 | return D3DCULL_CCW;
|
---|
244 | else
|
---|
245 | return D3DCULL_CW;
|
---|
246 | case CULL_ANTICLOCKWISE:
|
---|
247 | if( flip )
|
---|
248 | return D3DCULL_CW;
|
---|
249 | else
|
---|
250 | return D3DCULL_CCW;
|
---|
251 | }
|
---|
252 | return 0;
|
---|
253 | }
|
---|
254 | //---------------------------------------------------------------------
|
---|
255 | D3DFOGMODE D3D9Mappings::get(FogMode fm)
|
---|
256 | {
|
---|
257 | switch( fm )
|
---|
258 | {
|
---|
259 | case FOG_EXP:
|
---|
260 | return D3DFOG_EXP;
|
---|
261 | case FOG_EXP2:
|
---|
262 | return D3DFOG_EXP2;
|
---|
263 | case FOG_LINEAR:
|
---|
264 | return D3DFOG_LINEAR;
|
---|
265 | }
|
---|
266 | return D3DFOG_FORCE_DWORD;
|
---|
267 | }
|
---|
268 | //---------------------------------------------------------------------
|
---|
269 | D3DFILLMODE D3D9Mappings::get(SceneDetailLevel level)
|
---|
270 | {
|
---|
271 | switch(level)
|
---|
272 | {
|
---|
273 | case SDL_POINTS:
|
---|
274 | return D3DFILL_POINT;
|
---|
275 | case SDL_WIREFRAME:
|
---|
276 | return D3DFILL_WIREFRAME;
|
---|
277 | case SDL_SOLID:
|
---|
278 | return D3DFILL_SOLID;
|
---|
279 | }
|
---|
280 | return D3DFILL_FORCE_DWORD;
|
---|
281 | }
|
---|
282 | //---------------------------------------------------------------------
|
---|
283 | DWORD D3D9Mappings::get(StencilOperation op, bool invert)
|
---|
284 | {
|
---|
285 | switch(op)
|
---|
286 | {
|
---|
287 | case SOP_KEEP:
|
---|
288 | return D3DSTENCILOP_KEEP;
|
---|
289 | case SOP_ZERO:
|
---|
290 | return D3DSTENCILOP_ZERO;
|
---|
291 | case SOP_REPLACE:
|
---|
292 | return D3DSTENCILOP_REPLACE;
|
---|
293 | case SOP_INCREMENT:
|
---|
294 | return invert? D3DSTENCILOP_DECRSAT : D3DSTENCILOP_INCRSAT;
|
---|
295 | case SOP_DECREMENT:
|
---|
296 | return invert? D3DSTENCILOP_INCRSAT : D3DSTENCILOP_DECRSAT;
|
---|
297 | case SOP_INCREMENT_WRAP:
|
---|
298 | return invert? D3DSTENCILOP_DECR : D3DSTENCILOP_INCR;
|
---|
299 | case SOP_DECREMENT_WRAP:
|
---|
300 | return invert? D3DSTENCILOP_INCR : D3DSTENCILOP_DECR;
|
---|
301 | case SOP_INVERT:
|
---|
302 | return D3DSTENCILOP_INVERT;
|
---|
303 | }
|
---|
304 | return 0;
|
---|
305 | }
|
---|
306 | //---------------------------------------------------------------------
|
---|
307 | D3DSAMPLERSTATETYPE D3D9Mappings::get(FilterType ft)
|
---|
308 | {
|
---|
309 | switch (ft)
|
---|
310 | {
|
---|
311 | case FT_MIN:
|
---|
312 | return D3DSAMP_MINFILTER;
|
---|
313 | break;
|
---|
314 | case FT_MAG:
|
---|
315 | return D3DSAMP_MAGFILTER;
|
---|
316 | break;
|
---|
317 | case FT_MIP:
|
---|
318 | return D3DSAMP_MIPFILTER;
|
---|
319 | break;
|
---|
320 | }
|
---|
321 |
|
---|
322 | // to keep compiler happy
|
---|
323 | return D3DSAMP_MINFILTER;
|
---|
324 | }
|
---|
325 | //---------------------------------------------------------------------
|
---|
326 | DWORD D3D9Mappings::get(FilterType ft, FilterOptions fo, const D3DCAPS9& devCaps,
|
---|
327 | eD3DTexType texType)
|
---|
328 | {
|
---|
329 | // Assume normal
|
---|
330 | DWORD capsType = devCaps.TextureFilterCaps;
|
---|
331 |
|
---|
332 | switch( texType )
|
---|
333 | {
|
---|
334 | case D3D_TEX_TYPE_NORMAL:
|
---|
335 | capsType = devCaps.TextureFilterCaps;
|
---|
336 | break;
|
---|
337 | case D3D_TEX_TYPE_CUBE:
|
---|
338 | capsType = devCaps.CubeTextureFilterCaps;
|
---|
339 | break;
|
---|
340 | case D3D_TEX_TYPE_VOLUME:
|
---|
341 | capsType = devCaps.VolumeTextureFilterCaps;
|
---|
342 | break;
|
---|
343 | }
|
---|
344 |
|
---|
345 | switch (ft)
|
---|
346 | {
|
---|
347 | case FT_MIN:
|
---|
348 | switch( fo )
|
---|
349 | {
|
---|
350 | // NOTE: Fall through if device doesn't support requested type
|
---|
351 | case FO_ANISOTROPIC:
|
---|
352 | if( capsType & D3DPTFILTERCAPS_MINFANISOTROPIC )
|
---|
353 | {
|
---|
354 | return D3DTEXF_ANISOTROPIC;
|
---|
355 | break;
|
---|
356 | }
|
---|
357 | case FO_LINEAR:
|
---|
358 | if( capsType & D3DPTFILTERCAPS_MINFLINEAR )
|
---|
359 | {
|
---|
360 | return D3DTEXF_LINEAR;
|
---|
361 | break;
|
---|
362 | }
|
---|
363 | case FO_POINT:
|
---|
364 | case FO_NONE:
|
---|
365 | return D3DTEXF_POINT;
|
---|
366 | break;
|
---|
367 | }
|
---|
368 | break;
|
---|
369 | case FT_MAG:
|
---|
370 | switch( fo )
|
---|
371 | {
|
---|
372 | // NOTE: Fall through if device doesn't support requested type
|
---|
373 | case FO_ANISOTROPIC:
|
---|
374 | if( capsType & D3DPTFILTERCAPS_MAGFANISOTROPIC )
|
---|
375 | {
|
---|
376 | return D3DTEXF_ANISOTROPIC;
|
---|
377 | break;
|
---|
378 | }
|
---|
379 | case FO_LINEAR:
|
---|
380 | if( capsType & D3DPTFILTERCAPS_MAGFLINEAR )
|
---|
381 | {
|
---|
382 | return D3DTEXF_LINEAR;
|
---|
383 | break;
|
---|
384 | }
|
---|
385 | case FO_POINT:
|
---|
386 | case FO_NONE:
|
---|
387 | return D3DTEXF_POINT;
|
---|
388 | break;
|
---|
389 | }
|
---|
390 | break;
|
---|
391 | case FT_MIP:
|
---|
392 | switch( fo )
|
---|
393 | {
|
---|
394 | case FO_ANISOTROPIC:
|
---|
395 | case FO_LINEAR:
|
---|
396 | if( capsType & D3DPTFILTERCAPS_MIPFLINEAR )
|
---|
397 | {
|
---|
398 | return D3DTEXF_LINEAR;
|
---|
399 | break;
|
---|
400 | }
|
---|
401 | case FO_POINT:
|
---|
402 | if( capsType & D3DPTFILTERCAPS_MIPFPOINT )
|
---|
403 | {
|
---|
404 | return D3DTEXF_POINT;
|
---|
405 | break;
|
---|
406 | }
|
---|
407 | case FO_NONE:
|
---|
408 | return D3DTEXF_NONE;
|
---|
409 | break;
|
---|
410 | }
|
---|
411 | break;
|
---|
412 | }
|
---|
413 |
|
---|
414 | // should never get here
|
---|
415 | return 0;
|
---|
416 |
|
---|
417 | }
|
---|
418 | //---------------------------------------------------------------------
|
---|
419 | D3D9Mappings::eD3DTexType D3D9Mappings::get(TextureType ogreTexType)
|
---|
420 | {
|
---|
421 | switch( ogreTexType )
|
---|
422 | {
|
---|
423 | case TEX_TYPE_1D :
|
---|
424 | case TEX_TYPE_2D :
|
---|
425 | return D3D9Mappings::D3D_TEX_TYPE_NORMAL;
|
---|
426 | case TEX_TYPE_CUBE_MAP :
|
---|
427 | return D3D9Mappings::D3D_TEX_TYPE_CUBE;
|
---|
428 | case TEX_TYPE_3D :
|
---|
429 | return D3D9Mappings::D3D_TEX_TYPE_VOLUME;
|
---|
430 | }
|
---|
431 | return D3D9Mappings::D3D_TEX_TYPE_NONE;
|
---|
432 | }
|
---|
433 | //---------------------------------------------------------------------
|
---|
434 | DWORD D3D9Mappings::get(HardwareBuffer::Usage usage)
|
---|
435 | {
|
---|
436 | DWORD ret = 0;
|
---|
437 | if (usage & HardwareBuffer::HBU_DYNAMIC)
|
---|
438 | {
|
---|
439 | #if OGRE_D3D_MANAGE_BUFFERS
|
---|
440 | // Only add the dynamic flag for default pool, and
|
---|
441 | // we use default pool when buffer is discardable
|
---|
442 | if (usage & HardwareBuffer::HBU_DISCARDABLE)
|
---|
443 | ret |= D3DUSAGE_DYNAMIC;
|
---|
444 | #else
|
---|
445 | ret |= D3DUSAGE_DYNAMIC;
|
---|
446 | #endif
|
---|
447 | }
|
---|
448 | if (usage & HardwareBuffer::HBU_WRITE_ONLY)
|
---|
449 | {
|
---|
450 | ret |= D3DUSAGE_WRITEONLY;
|
---|
451 | }
|
---|
452 | return ret;
|
---|
453 | }
|
---|
454 | //---------------------------------------------------------------------
|
---|
455 | DWORD D3D9Mappings::get(HardwareBuffer::LockOptions options, HardwareBuffer::Usage usage)
|
---|
456 | {
|
---|
457 | DWORD ret = 0;
|
---|
458 | if (options == HardwareBuffer::HBL_DISCARD)
|
---|
459 | {
|
---|
460 | #if OGRE_D3D_MANAGE_BUFFERS
|
---|
461 | // Only add the discard flag for dynamic usgae and default pool
|
---|
462 | if ((usage & HardwareBuffer::HBU_DYNAMIC) &&
|
---|
463 | (usage & HardwareBuffer::HBU_DISCARDABLE))
|
---|
464 | ret |= D3DLOCK_DISCARD;
|
---|
465 | #else
|
---|
466 | // D3D doesn't like discard or no_overwrite on non-dynamic buffers
|
---|
467 | if (usage & HardwareBuffer::HBU_DYNAMIC)
|
---|
468 | ret |= D3DLOCK_DISCARD;
|
---|
469 | #endif
|
---|
470 | }
|
---|
471 | if (options == HardwareBuffer::HBL_READ_ONLY)
|
---|
472 | {
|
---|
473 | // D3D debug runtime doesn't like you locking managed buffers readonly
|
---|
474 | // when they were created with write-only (even though you CAN read
|
---|
475 | // from the software backed version)
|
---|
476 | if (!(usage & HardwareBuffer::HBU_WRITE_ONLY))
|
---|
477 | ret |= D3DLOCK_READONLY;
|
---|
478 |
|
---|
479 | }
|
---|
480 | if (options == HardwareBuffer::HBL_NO_OVERWRITE)
|
---|
481 | {
|
---|
482 | #if OGRE_D3D_MANAGE_BUFFERS
|
---|
483 | // Only add the nooverwrite flag for dynamic usgae and default pool
|
---|
484 | if ((usage & HardwareBuffer::HBU_DYNAMIC) &&
|
---|
485 | (usage & HardwareBuffer::HBU_DISCARDABLE))
|
---|
486 | ret |= D3DLOCK_NOOVERWRITE;
|
---|
487 | #else
|
---|
488 | // D3D doesn't like discard or no_overwrite on non-dynamic buffers
|
---|
489 | if (usage & HardwareBuffer::HBU_DYNAMIC)
|
---|
490 | ret |= D3DLOCK_NOOVERWRITE;
|
---|
491 | #endif
|
---|
492 | }
|
---|
493 |
|
---|
494 | return ret;
|
---|
495 | }
|
---|
496 | //---------------------------------------------------------------------
|
---|
497 | D3DFORMAT D3D9Mappings::get(HardwareIndexBuffer::IndexType itype)
|
---|
498 | {
|
---|
499 | if (itype == HardwareIndexBuffer::IT_32BIT)
|
---|
500 | {
|
---|
501 | return D3DFMT_INDEX32;
|
---|
502 | }
|
---|
503 | else
|
---|
504 | {
|
---|
505 | return D3DFMT_INDEX16;
|
---|
506 | }
|
---|
507 | }
|
---|
508 | //---------------------------------------------------------------------
|
---|
509 | D3DDECLTYPE D3D9Mappings::get(VertexElementType vType)
|
---|
510 | {
|
---|
511 | switch (vType)
|
---|
512 | {
|
---|
513 | case VET_COLOUR:
|
---|
514 | return D3DDECLTYPE_D3DCOLOR;
|
---|
515 | break;
|
---|
516 | case VET_FLOAT1:
|
---|
517 | return D3DDECLTYPE_FLOAT1;
|
---|
518 | break;
|
---|
519 | case VET_FLOAT2:
|
---|
520 | return D3DDECLTYPE_FLOAT2;
|
---|
521 | break;
|
---|
522 | case VET_FLOAT3:
|
---|
523 | return D3DDECLTYPE_FLOAT3;
|
---|
524 | break;
|
---|
525 | case VET_FLOAT4:
|
---|
526 | return D3DDECLTYPE_FLOAT4;
|
---|
527 | break;
|
---|
528 | case VET_SHORT2:
|
---|
529 | return D3DDECLTYPE_SHORT2;
|
---|
530 | break;
|
---|
531 | case VET_SHORT4:
|
---|
532 | return D3DDECLTYPE_SHORT4;
|
---|
533 | break;
|
---|
534 | case VET_UBYTE4:
|
---|
535 | return D3DDECLTYPE_UBYTE4;
|
---|
536 | break;
|
---|
537 | }
|
---|
538 | // to keep compiler happy
|
---|
539 | return D3DDECLTYPE_FLOAT3;
|
---|
540 | }
|
---|
541 | //---------------------------------------------------------------------
|
---|
542 | D3DDECLUSAGE D3D9Mappings::get(VertexElementSemantic sem)
|
---|
543 | {
|
---|
544 | switch (sem)
|
---|
545 | {
|
---|
546 | case VES_BLEND_INDICES:
|
---|
547 | return D3DDECLUSAGE_BLENDINDICES;
|
---|
548 | break;
|
---|
549 | case VES_BLEND_WEIGHTS:
|
---|
550 | return D3DDECLUSAGE_BLENDWEIGHT;
|
---|
551 | break;
|
---|
552 | case VES_DIFFUSE:
|
---|
553 | return D3DDECLUSAGE_COLOR; // NB index will differentiate
|
---|
554 | break;
|
---|
555 | case VES_SPECULAR:
|
---|
556 | return D3DDECLUSAGE_COLOR; // NB index will differentiate
|
---|
557 | break;
|
---|
558 | case VES_NORMAL:
|
---|
559 | return D3DDECLUSAGE_NORMAL;
|
---|
560 | break;
|
---|
561 | case VES_POSITION:
|
---|
562 | return D3DDECLUSAGE_POSITION;
|
---|
563 | break;
|
---|
564 | case VES_TEXTURE_COORDINATES:
|
---|
565 | return D3DDECLUSAGE_TEXCOORD;
|
---|
566 | break;
|
---|
567 | case VES_BINORMAL:
|
---|
568 | return D3DDECLUSAGE_BINORMAL;
|
---|
569 | break;
|
---|
570 | case VES_TANGENT:
|
---|
571 | return D3DDECLUSAGE_TANGENT;
|
---|
572 | break;
|
---|
573 | }
|
---|
574 | // to keep compiler happy
|
---|
575 | return D3DDECLUSAGE_POSITION;
|
---|
576 | }
|
---|
577 | //---------------------------------------------------------------------
|
---|
578 | D3DXMATRIX D3D9Mappings::makeD3DXMatrix( const Matrix4& mat )
|
---|
579 | {
|
---|
580 | // Transpose matrix
|
---|
581 | // D3D9 uses row vectors i.e. V*M
|
---|
582 | // Ogre, OpenGL and everything else uses column vectors i.e. M*V
|
---|
583 | D3DXMATRIX d3dMat;
|
---|
584 | d3dMat.m[0][0] = mat[0][0];
|
---|
585 | d3dMat.m[0][1] = mat[1][0];
|
---|
586 | d3dMat.m[0][2] = mat[2][0];
|
---|
587 | d3dMat.m[0][3] = mat[3][0];
|
---|
588 |
|
---|
589 | d3dMat.m[1][0] = mat[0][1];
|
---|
590 | d3dMat.m[1][1] = mat[1][1];
|
---|
591 | d3dMat.m[1][2] = mat[2][1];
|
---|
592 | d3dMat.m[1][3] = mat[3][1];
|
---|
593 |
|
---|
594 | d3dMat.m[2][0] = mat[0][2];
|
---|
595 | d3dMat.m[2][1] = mat[1][2];
|
---|
596 | d3dMat.m[2][2] = mat[2][2];
|
---|
597 | d3dMat.m[2][3] = mat[3][2];
|
---|
598 |
|
---|
599 | d3dMat.m[3][0] = mat[0][3];
|
---|
600 | d3dMat.m[3][1] = mat[1][3];
|
---|
601 | d3dMat.m[3][2] = mat[2][3];
|
---|
602 | d3dMat.m[3][3] = mat[3][3];
|
---|
603 |
|
---|
604 | return d3dMat;
|
---|
605 | }
|
---|
606 | //---------------------------------------------------------------------
|
---|
607 | Matrix4 D3D9Mappings::convertD3DXMatrix( const D3DXMATRIX& mat )
|
---|
608 | {
|
---|
609 | Matrix4 ogreMat;
|
---|
610 | ogreMat[0][0] = mat.m[0][0];
|
---|
611 | ogreMat[1][0] = mat.m[0][1];
|
---|
612 | ogreMat[2][0] = mat.m[0][2];
|
---|
613 | ogreMat[3][0] = mat.m[0][3];
|
---|
614 |
|
---|
615 | ogreMat[0][1] = mat.m[1][0];
|
---|
616 | ogreMat[1][1] = mat.m[1][1];
|
---|
617 | ogreMat[2][1] = mat.m[1][2];
|
---|
618 | ogreMat[3][1] = mat.m[1][3];
|
---|
619 |
|
---|
620 | ogreMat[0][2] = mat.m[2][0];
|
---|
621 | ogreMat[1][2] = mat.m[2][1];
|
---|
622 | ogreMat[2][2] = mat.m[2][2];
|
---|
623 | ogreMat[3][2] = mat.m[2][3];
|
---|
624 |
|
---|
625 | ogreMat[0][3] = mat.m[3][0];
|
---|
626 | ogreMat[1][3] = mat.m[3][1];
|
---|
627 | ogreMat[2][3] = mat.m[3][2];
|
---|
628 | ogreMat[3][3] = mat.m[3][3];
|
---|
629 |
|
---|
630 | return ogreMat;
|
---|
631 | }
|
---|
632 |
|
---|
633 |
|
---|
634 | }
|
---|