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 | case TextureUnitState::TAM_BORDER:
|
---|
111 | return D3DTADDRESS_BORDER;
|
---|
112 | }
|
---|
113 | return D3DTADDRESS_FORCE_DWORD;
|
---|
114 | }
|
---|
115 | //---------------------------------------------------------------------
|
---|
116 | D3DTEXTURESTAGESTATETYPE D3D9Mappings::get(LayerBlendType lbt)
|
---|
117 | {
|
---|
118 | switch( lbt )
|
---|
119 | {
|
---|
120 | case LBT_COLOUR:
|
---|
121 | return D3DTSS_COLOROP;
|
---|
122 | case LBT_ALPHA:
|
---|
123 | return D3DTSS_ALPHAOP;
|
---|
124 | }
|
---|
125 | return D3DTSS_FORCE_DWORD;
|
---|
126 | }
|
---|
127 | //---------------------------------------------------------------------
|
---|
128 | DWORD D3D9Mappings::get(LayerBlendSource lbs)
|
---|
129 | {
|
---|
130 | switch( lbs )
|
---|
131 | {
|
---|
132 | case LBS_CURRENT:
|
---|
133 | return D3DTA_CURRENT;
|
---|
134 | case LBS_TEXTURE:
|
---|
135 | return D3DTA_TEXTURE;
|
---|
136 | case LBS_DIFFUSE:
|
---|
137 | return D3DTA_DIFFUSE;
|
---|
138 | case LBS_SPECULAR:
|
---|
139 | return D3DTA_SPECULAR;
|
---|
140 | case LBS_MANUAL:
|
---|
141 | return D3DTA_TFACTOR;
|
---|
142 | }
|
---|
143 | return 0;
|
---|
144 | }
|
---|
145 | //---------------------------------------------------------------------
|
---|
146 | DWORD D3D9Mappings::get(LayerBlendOperationEx lbo, const D3DCAPS9& devCaps)
|
---|
147 | {
|
---|
148 | switch( lbo )
|
---|
149 | {
|
---|
150 | case LBX_SOURCE1:
|
---|
151 | return D3DTOP_SELECTARG1;
|
---|
152 | case LBX_SOURCE2:
|
---|
153 | return D3DTOP_SELECTARG2;
|
---|
154 | case LBX_MODULATE:
|
---|
155 | return D3DTOP_MODULATE;
|
---|
156 | case LBX_MODULATE_X2:
|
---|
157 | return D3DTOP_MODULATE2X;
|
---|
158 | case LBX_MODULATE_X4:
|
---|
159 | return D3DTOP_MODULATE4X;
|
---|
160 | case LBX_ADD:
|
---|
161 | return D3DTOP_ADD;
|
---|
162 | case LBX_ADD_SIGNED:
|
---|
163 | return D3DTOP_ADDSIGNED;
|
---|
164 | case LBX_ADD_SMOOTH:
|
---|
165 | return D3DTOP_ADDSMOOTH;
|
---|
166 | case LBX_SUBTRACT:
|
---|
167 | return D3DTOP_SUBTRACT;
|
---|
168 | case LBX_BLEND_DIFFUSE_ALPHA:
|
---|
169 | return D3DTOP_BLENDDIFFUSEALPHA;
|
---|
170 | case LBX_BLEND_TEXTURE_ALPHA:
|
---|
171 | return D3DTOP_BLENDTEXTUREALPHA;
|
---|
172 | case LBX_BLEND_CURRENT_ALPHA:
|
---|
173 | return D3DTOP_BLENDCURRENTALPHA;
|
---|
174 | case LBX_BLEND_MANUAL:
|
---|
175 | return D3DTOP_BLENDFACTORALPHA;
|
---|
176 | case LBX_DOTPRODUCT:
|
---|
177 | if (devCaps.TextureOpCaps & D3DTEXOPCAPS_DOTPRODUCT3)
|
---|
178 | return D3DTOP_DOTPRODUCT3;
|
---|
179 | else
|
---|
180 | return D3DTOP_MODULATE;
|
---|
181 | case LBX_BLEND_DIFFUSE_COLOUR:
|
---|
182 | if (devCaps.TextureOpCaps & D3DTEXOPCAPS_LERP)
|
---|
183 | return D3DTOP_LERP;
|
---|
184 | else
|
---|
185 | return D3DTOP_MODULATE;
|
---|
186 | }
|
---|
187 | return 0;
|
---|
188 | }
|
---|
189 | //---------------------------------------------------------------------
|
---|
190 | D3DBLEND D3D9Mappings::get(SceneBlendFactor sbf)
|
---|
191 | {
|
---|
192 | switch( sbf )
|
---|
193 | {
|
---|
194 | case SBF_ONE:
|
---|
195 | return D3DBLEND_ONE;
|
---|
196 | case SBF_ZERO:
|
---|
197 | return D3DBLEND_ZERO;
|
---|
198 | case SBF_DEST_COLOUR:
|
---|
199 | return D3DBLEND_DESTCOLOR;
|
---|
200 | case SBF_SOURCE_COLOUR:
|
---|
201 | return D3DBLEND_SRCCOLOR;
|
---|
202 | case SBF_ONE_MINUS_DEST_COLOUR:
|
---|
203 | return D3DBLEND_INVDESTCOLOR;
|
---|
204 | case SBF_ONE_MINUS_SOURCE_COLOUR:
|
---|
205 | return D3DBLEND_INVSRCCOLOR;
|
---|
206 | case SBF_DEST_ALPHA:
|
---|
207 | return D3DBLEND_DESTALPHA;
|
---|
208 | case SBF_SOURCE_ALPHA:
|
---|
209 | return D3DBLEND_SRCALPHA;
|
---|
210 | case SBF_ONE_MINUS_DEST_ALPHA:
|
---|
211 | return D3DBLEND_INVDESTALPHA;
|
---|
212 | case SBF_ONE_MINUS_SOURCE_ALPHA:
|
---|
213 | return D3DBLEND_INVSRCALPHA;
|
---|
214 | }
|
---|
215 | return D3DBLEND_FORCE_DWORD;
|
---|
216 | }
|
---|
217 | //---------------------------------------------------------------------
|
---|
218 | DWORD D3D9Mappings::get(CompareFunction cf)
|
---|
219 | {
|
---|
220 | switch( cf )
|
---|
221 | {
|
---|
222 | case CMPF_ALWAYS_FAIL:
|
---|
223 | return D3DCMP_NEVER;
|
---|
224 | case CMPF_ALWAYS_PASS:
|
---|
225 | return D3DCMP_ALWAYS;
|
---|
226 | case CMPF_LESS:
|
---|
227 | return D3DCMP_LESS;
|
---|
228 | case CMPF_LESS_EQUAL:
|
---|
229 | return D3DCMP_LESSEQUAL;
|
---|
230 | case CMPF_EQUAL:
|
---|
231 | return D3DCMP_EQUAL;
|
---|
232 | case CMPF_NOT_EQUAL:
|
---|
233 | return D3DCMP_NOTEQUAL;
|
---|
234 | case CMPF_GREATER_EQUAL:
|
---|
235 | return D3DCMP_GREATEREQUAL;
|
---|
236 | case CMPF_GREATER:
|
---|
237 | return D3DCMP_GREATER;
|
---|
238 | };
|
---|
239 | return 0;
|
---|
240 | }
|
---|
241 | //---------------------------------------------------------------------
|
---|
242 | DWORD D3D9Mappings::get(CullingMode cm, bool flip)
|
---|
243 | {
|
---|
244 | switch( cm )
|
---|
245 | {
|
---|
246 | case CULL_NONE:
|
---|
247 | return D3DCULL_NONE;
|
---|
248 | case CULL_CLOCKWISE:
|
---|
249 | if( flip )
|
---|
250 | return D3DCULL_CCW;
|
---|
251 | else
|
---|
252 | return D3DCULL_CW;
|
---|
253 | case CULL_ANTICLOCKWISE:
|
---|
254 | if( flip )
|
---|
255 | return D3DCULL_CW;
|
---|
256 | else
|
---|
257 | return D3DCULL_CCW;
|
---|
258 | }
|
---|
259 | return 0;
|
---|
260 | }
|
---|
261 | //---------------------------------------------------------------------
|
---|
262 | D3DFOGMODE D3D9Mappings::get(FogMode fm)
|
---|
263 | {
|
---|
264 | switch( fm )
|
---|
265 | {
|
---|
266 | case FOG_EXP:
|
---|
267 | return D3DFOG_EXP;
|
---|
268 | case FOG_EXP2:
|
---|
269 | return D3DFOG_EXP2;
|
---|
270 | case FOG_LINEAR:
|
---|
271 | return D3DFOG_LINEAR;
|
---|
272 | }
|
---|
273 | return D3DFOG_FORCE_DWORD;
|
---|
274 | }
|
---|
275 | //---------------------------------------------------------------------
|
---|
276 | D3DFILLMODE D3D9Mappings::get(PolygonMode level)
|
---|
277 | {
|
---|
278 | switch(level)
|
---|
279 | {
|
---|
280 | case PM_POINTS:
|
---|
281 | return D3DFILL_POINT;
|
---|
282 | case PM_WIREFRAME:
|
---|
283 | return D3DFILL_WIREFRAME;
|
---|
284 | case PM_SOLID:
|
---|
285 | return D3DFILL_SOLID;
|
---|
286 | }
|
---|
287 | return D3DFILL_FORCE_DWORD;
|
---|
288 | }
|
---|
289 | //---------------------------------------------------------------------
|
---|
290 | DWORD D3D9Mappings::get(StencilOperation op, bool invert)
|
---|
291 | {
|
---|
292 | switch(op)
|
---|
293 | {
|
---|
294 | case SOP_KEEP:
|
---|
295 | return D3DSTENCILOP_KEEP;
|
---|
296 | case SOP_ZERO:
|
---|
297 | return D3DSTENCILOP_ZERO;
|
---|
298 | case SOP_REPLACE:
|
---|
299 | return D3DSTENCILOP_REPLACE;
|
---|
300 | case SOP_INCREMENT:
|
---|
301 | return invert? D3DSTENCILOP_DECRSAT : D3DSTENCILOP_INCRSAT;
|
---|
302 | case SOP_DECREMENT:
|
---|
303 | return invert? D3DSTENCILOP_INCRSAT : D3DSTENCILOP_DECRSAT;
|
---|
304 | case SOP_INCREMENT_WRAP:
|
---|
305 | return invert? D3DSTENCILOP_DECR : D3DSTENCILOP_INCR;
|
---|
306 | case SOP_DECREMENT_WRAP:
|
---|
307 | return invert? D3DSTENCILOP_INCR : D3DSTENCILOP_DECR;
|
---|
308 | case SOP_INVERT:
|
---|
309 | return D3DSTENCILOP_INVERT;
|
---|
310 | }
|
---|
311 | return 0;
|
---|
312 | }
|
---|
313 | //---------------------------------------------------------------------
|
---|
314 | D3DSAMPLERSTATETYPE D3D9Mappings::get(FilterType ft)
|
---|
315 | {
|
---|
316 | switch (ft)
|
---|
317 | {
|
---|
318 | case FT_MIN:
|
---|
319 | return D3DSAMP_MINFILTER;
|
---|
320 | break;
|
---|
321 | case FT_MAG:
|
---|
322 | return D3DSAMP_MAGFILTER;
|
---|
323 | break;
|
---|
324 | case FT_MIP:
|
---|
325 | return D3DSAMP_MIPFILTER;
|
---|
326 | break;
|
---|
327 | }
|
---|
328 |
|
---|
329 | // to keep compiler happy
|
---|
330 | return D3DSAMP_MINFILTER;
|
---|
331 | }
|
---|
332 | //---------------------------------------------------------------------
|
---|
333 | DWORD D3D9Mappings::get(FilterType ft, FilterOptions fo, const D3DCAPS9& devCaps,
|
---|
334 | eD3DTexType texType)
|
---|
335 | {
|
---|
336 | // Assume normal
|
---|
337 | DWORD capsType = devCaps.TextureFilterCaps;
|
---|
338 |
|
---|
339 | switch( texType )
|
---|
340 | {
|
---|
341 | case D3D_TEX_TYPE_NORMAL:
|
---|
342 | capsType = devCaps.TextureFilterCaps;
|
---|
343 | break;
|
---|
344 | case D3D_TEX_TYPE_CUBE:
|
---|
345 | capsType = devCaps.CubeTextureFilterCaps;
|
---|
346 | break;
|
---|
347 | case D3D_TEX_TYPE_VOLUME:
|
---|
348 | capsType = devCaps.VolumeTextureFilterCaps;
|
---|
349 | break;
|
---|
350 | }
|
---|
351 |
|
---|
352 | switch (ft)
|
---|
353 | {
|
---|
354 | case FT_MIN:
|
---|
355 | switch( fo )
|
---|
356 | {
|
---|
357 | // NOTE: Fall through if device doesn't support requested type
|
---|
358 | case FO_ANISOTROPIC:
|
---|
359 | if( capsType & D3DPTFILTERCAPS_MINFANISOTROPIC )
|
---|
360 | {
|
---|
361 | return D3DTEXF_ANISOTROPIC;
|
---|
362 | break;
|
---|
363 | }
|
---|
364 | case FO_LINEAR:
|
---|
365 | if( capsType & D3DPTFILTERCAPS_MINFLINEAR )
|
---|
366 | {
|
---|
367 | return D3DTEXF_LINEAR;
|
---|
368 | break;
|
---|
369 | }
|
---|
370 | case FO_POINT:
|
---|
371 | case FO_NONE:
|
---|
372 | return D3DTEXF_POINT;
|
---|
373 | break;
|
---|
374 | }
|
---|
375 | break;
|
---|
376 | case FT_MAG:
|
---|
377 | switch( fo )
|
---|
378 | {
|
---|
379 | // NOTE: Fall through if device doesn't support requested type
|
---|
380 | case FO_ANISOTROPIC:
|
---|
381 | if( capsType & D3DPTFILTERCAPS_MAGFANISOTROPIC )
|
---|
382 | {
|
---|
383 | return D3DTEXF_ANISOTROPIC;
|
---|
384 | break;
|
---|
385 | }
|
---|
386 | case FO_LINEAR:
|
---|
387 | if( capsType & D3DPTFILTERCAPS_MAGFLINEAR )
|
---|
388 | {
|
---|
389 | return D3DTEXF_LINEAR;
|
---|
390 | break;
|
---|
391 | }
|
---|
392 | case FO_POINT:
|
---|
393 | case FO_NONE:
|
---|
394 | return D3DTEXF_POINT;
|
---|
395 | break;
|
---|
396 | }
|
---|
397 | break;
|
---|
398 | case FT_MIP:
|
---|
399 | switch( fo )
|
---|
400 | {
|
---|
401 | case FO_ANISOTROPIC:
|
---|
402 | case FO_LINEAR:
|
---|
403 | if( capsType & D3DPTFILTERCAPS_MIPFLINEAR )
|
---|
404 | {
|
---|
405 | return D3DTEXF_LINEAR;
|
---|
406 | break;
|
---|
407 | }
|
---|
408 | case FO_POINT:
|
---|
409 | if( capsType & D3DPTFILTERCAPS_MIPFPOINT )
|
---|
410 | {
|
---|
411 | return D3DTEXF_POINT;
|
---|
412 | break;
|
---|
413 | }
|
---|
414 | case FO_NONE:
|
---|
415 | return D3DTEXF_NONE;
|
---|
416 | break;
|
---|
417 | }
|
---|
418 | break;
|
---|
419 | }
|
---|
420 |
|
---|
421 | // should never get here
|
---|
422 | return 0;
|
---|
423 |
|
---|
424 | }
|
---|
425 | //---------------------------------------------------------------------
|
---|
426 | D3D9Mappings::eD3DTexType D3D9Mappings::get(TextureType ogreTexType)
|
---|
427 | {
|
---|
428 | switch( ogreTexType )
|
---|
429 | {
|
---|
430 | case TEX_TYPE_1D :
|
---|
431 | case TEX_TYPE_2D :
|
---|
432 | return D3D9Mappings::D3D_TEX_TYPE_NORMAL;
|
---|
433 | case TEX_TYPE_CUBE_MAP :
|
---|
434 | return D3D9Mappings::D3D_TEX_TYPE_CUBE;
|
---|
435 | case TEX_TYPE_3D :
|
---|
436 | return D3D9Mappings::D3D_TEX_TYPE_VOLUME;
|
---|
437 | }
|
---|
438 | return D3D9Mappings::D3D_TEX_TYPE_NONE;
|
---|
439 | }
|
---|
440 | //---------------------------------------------------------------------
|
---|
441 | DWORD D3D9Mappings::get(HardwareBuffer::Usage usage)
|
---|
442 | {
|
---|
443 | DWORD ret = 0;
|
---|
444 | if (usage & HardwareBuffer::HBU_DYNAMIC)
|
---|
445 | {
|
---|
446 | #if OGRE_D3D_MANAGE_BUFFERS
|
---|
447 | // Only add the dynamic flag for default pool, and
|
---|
448 | // we use default pool when buffer is discardable
|
---|
449 | if (usage & HardwareBuffer::HBU_DISCARDABLE)
|
---|
450 | ret |= D3DUSAGE_DYNAMIC;
|
---|
451 | #else
|
---|
452 | ret |= D3DUSAGE_DYNAMIC;
|
---|
453 | #endif
|
---|
454 | }
|
---|
455 | if (usage & HardwareBuffer::HBU_WRITE_ONLY)
|
---|
456 | {
|
---|
457 | ret |= D3DUSAGE_WRITEONLY;
|
---|
458 | }
|
---|
459 | return ret;
|
---|
460 | }
|
---|
461 | //---------------------------------------------------------------------
|
---|
462 | DWORD D3D9Mappings::get(HardwareBuffer::LockOptions options, HardwareBuffer::Usage usage)
|
---|
463 | {
|
---|
464 | DWORD ret = 0;
|
---|
465 | if (options == HardwareBuffer::HBL_DISCARD)
|
---|
466 | {
|
---|
467 | #if OGRE_D3D_MANAGE_BUFFERS
|
---|
468 | // Only add the discard flag for dynamic usgae and default pool
|
---|
469 | if ((usage & HardwareBuffer::HBU_DYNAMIC) &&
|
---|
470 | (usage & HardwareBuffer::HBU_DISCARDABLE))
|
---|
471 | ret |= D3DLOCK_DISCARD;
|
---|
472 | #else
|
---|
473 | // D3D doesn't like discard or no_overwrite on non-dynamic buffers
|
---|
474 | if (usage & HardwareBuffer::HBU_DYNAMIC)
|
---|
475 | ret |= D3DLOCK_DISCARD;
|
---|
476 | #endif
|
---|
477 | }
|
---|
478 | if (options == HardwareBuffer::HBL_READ_ONLY)
|
---|
479 | {
|
---|
480 | // D3D debug runtime doesn't like you locking managed buffers readonly
|
---|
481 | // when they were created with write-only (even though you CAN read
|
---|
482 | // from the software backed version)
|
---|
483 | if (!(usage & HardwareBuffer::HBU_WRITE_ONLY))
|
---|
484 | ret |= D3DLOCK_READONLY;
|
---|
485 |
|
---|
486 | }
|
---|
487 | if (options == HardwareBuffer::HBL_NO_OVERWRITE)
|
---|
488 | {
|
---|
489 | #if OGRE_D3D_MANAGE_BUFFERS
|
---|
490 | // Only add the nooverwrite flag for dynamic usgae and default pool
|
---|
491 | if ((usage & HardwareBuffer::HBU_DYNAMIC) &&
|
---|
492 | (usage & HardwareBuffer::HBU_DISCARDABLE))
|
---|
493 | ret |= D3DLOCK_NOOVERWRITE;
|
---|
494 | #else
|
---|
495 | // D3D doesn't like discard or no_overwrite on non-dynamic buffers
|
---|
496 | if (usage & HardwareBuffer::HBU_DYNAMIC)
|
---|
497 | ret |= D3DLOCK_NOOVERWRITE;
|
---|
498 | #endif
|
---|
499 | }
|
---|
500 |
|
---|
501 | return ret;
|
---|
502 | }
|
---|
503 | //---------------------------------------------------------------------
|
---|
504 | D3DFORMAT D3D9Mappings::get(HardwareIndexBuffer::IndexType itype)
|
---|
505 | {
|
---|
506 | if (itype == HardwareIndexBuffer::IT_32BIT)
|
---|
507 | {
|
---|
508 | return D3DFMT_INDEX32;
|
---|
509 | }
|
---|
510 | else
|
---|
511 | {
|
---|
512 | return D3DFMT_INDEX16;
|
---|
513 | }
|
---|
514 | }
|
---|
515 | //---------------------------------------------------------------------
|
---|
516 | D3DDECLTYPE D3D9Mappings::get(VertexElementType vType)
|
---|
517 | {
|
---|
518 | switch (vType)
|
---|
519 | {
|
---|
520 | case VET_COLOUR:
|
---|
521 | case VET_COLOUR_ABGR:
|
---|
522 | case VET_COLOUR_ARGB:
|
---|
523 | return D3DDECLTYPE_D3DCOLOR;
|
---|
524 | break;
|
---|
525 | case VET_FLOAT1:
|
---|
526 | return D3DDECLTYPE_FLOAT1;
|
---|
527 | break;
|
---|
528 | case VET_FLOAT2:
|
---|
529 | return D3DDECLTYPE_FLOAT2;
|
---|
530 | break;
|
---|
531 | case VET_FLOAT3:
|
---|
532 | return D3DDECLTYPE_FLOAT3;
|
---|
533 | break;
|
---|
534 | case VET_FLOAT4:
|
---|
535 | return D3DDECLTYPE_FLOAT4;
|
---|
536 | break;
|
---|
537 | case VET_SHORT2:
|
---|
538 | return D3DDECLTYPE_SHORT2;
|
---|
539 | break;
|
---|
540 | case VET_SHORT4:
|
---|
541 | return D3DDECLTYPE_SHORT4;
|
---|
542 | break;
|
---|
543 | case VET_UBYTE4:
|
---|
544 | return D3DDECLTYPE_UBYTE4;
|
---|
545 | break;
|
---|
546 | }
|
---|
547 | // to keep compiler happy
|
---|
548 | return D3DDECLTYPE_FLOAT3;
|
---|
549 | }
|
---|
550 | //---------------------------------------------------------------------
|
---|
551 | D3DDECLUSAGE D3D9Mappings::get(VertexElementSemantic sem)
|
---|
552 | {
|
---|
553 | switch (sem)
|
---|
554 | {
|
---|
555 | case VES_BLEND_INDICES:
|
---|
556 | return D3DDECLUSAGE_BLENDINDICES;
|
---|
557 | break;
|
---|
558 | case VES_BLEND_WEIGHTS:
|
---|
559 | return D3DDECLUSAGE_BLENDWEIGHT;
|
---|
560 | break;
|
---|
561 | case VES_DIFFUSE:
|
---|
562 | return D3DDECLUSAGE_COLOR; // NB index will differentiate
|
---|
563 | break;
|
---|
564 | case VES_SPECULAR:
|
---|
565 | return D3DDECLUSAGE_COLOR; // NB index will differentiate
|
---|
566 | break;
|
---|
567 | case VES_NORMAL:
|
---|
568 | return D3DDECLUSAGE_NORMAL;
|
---|
569 | break;
|
---|
570 | case VES_POSITION:
|
---|
571 | return D3DDECLUSAGE_POSITION;
|
---|
572 | break;
|
---|
573 | case VES_TEXTURE_COORDINATES:
|
---|
574 | return D3DDECLUSAGE_TEXCOORD;
|
---|
575 | break;
|
---|
576 | case VES_BINORMAL:
|
---|
577 | return D3DDECLUSAGE_BINORMAL;
|
---|
578 | break;
|
---|
579 | case VES_TANGENT:
|
---|
580 | return D3DDECLUSAGE_TANGENT;
|
---|
581 | break;
|
---|
582 | }
|
---|
583 | // to keep compiler happy
|
---|
584 | return D3DDECLUSAGE_POSITION;
|
---|
585 | }
|
---|
586 | //---------------------------------------------------------------------
|
---|
587 | D3DXMATRIX D3D9Mappings::makeD3DXMatrix( const Matrix4& mat )
|
---|
588 | {
|
---|
589 | // Transpose matrix
|
---|
590 | // D3D9 uses row vectors i.e. V*M
|
---|
591 | // Ogre, OpenGL and everything else uses column vectors i.e. M*V
|
---|
592 | D3DXMATRIX d3dMat;
|
---|
593 | d3dMat.m[0][0] = mat[0][0];
|
---|
594 | d3dMat.m[0][1] = mat[1][0];
|
---|
595 | d3dMat.m[0][2] = mat[2][0];
|
---|
596 | d3dMat.m[0][3] = mat[3][0];
|
---|
597 |
|
---|
598 | d3dMat.m[1][0] = mat[0][1];
|
---|
599 | d3dMat.m[1][1] = mat[1][1];
|
---|
600 | d3dMat.m[1][2] = mat[2][1];
|
---|
601 | d3dMat.m[1][3] = mat[3][1];
|
---|
602 |
|
---|
603 | d3dMat.m[2][0] = mat[0][2];
|
---|
604 | d3dMat.m[2][1] = mat[1][2];
|
---|
605 | d3dMat.m[2][2] = mat[2][2];
|
---|
606 | d3dMat.m[2][3] = mat[3][2];
|
---|
607 |
|
---|
608 | d3dMat.m[3][0] = mat[0][3];
|
---|
609 | d3dMat.m[3][1] = mat[1][3];
|
---|
610 | d3dMat.m[3][2] = mat[2][3];
|
---|
611 | d3dMat.m[3][3] = mat[3][3];
|
---|
612 |
|
---|
613 | return d3dMat;
|
---|
614 | }
|
---|
615 | //---------------------------------------------------------------------
|
---|
616 | Matrix4 D3D9Mappings::convertD3DXMatrix( const D3DXMATRIX& mat )
|
---|
617 | {
|
---|
618 | Matrix4 ogreMat;
|
---|
619 | ogreMat[0][0] = mat.m[0][0];
|
---|
620 | ogreMat[1][0] = mat.m[0][1];
|
---|
621 | ogreMat[2][0] = mat.m[0][2];
|
---|
622 | ogreMat[3][0] = mat.m[0][3];
|
---|
623 |
|
---|
624 | ogreMat[0][1] = mat.m[1][0];
|
---|
625 | ogreMat[1][1] = mat.m[1][1];
|
---|
626 | ogreMat[2][1] = mat.m[1][2];
|
---|
627 | ogreMat[3][1] = mat.m[1][3];
|
---|
628 |
|
---|
629 | ogreMat[0][2] = mat.m[2][0];
|
---|
630 | ogreMat[1][2] = mat.m[2][1];
|
---|
631 | ogreMat[2][2] = mat.m[2][2];
|
---|
632 | ogreMat[3][2] = mat.m[2][3];
|
---|
633 |
|
---|
634 | ogreMat[0][3] = mat.m[3][0];
|
---|
635 | ogreMat[1][3] = mat.m[3][1];
|
---|
636 | ogreMat[2][3] = mat.m[3][2];
|
---|
637 | ogreMat[3][3] = mat.m[3][3];
|
---|
638 |
|
---|
639 | return ogreMat;
|
---|
640 | }
|
---|
641 | /****************************************************************************************/
|
---|
642 | PixelFormat D3D9Mappings::_getPF(D3DFORMAT d3dPF)
|
---|
643 | {
|
---|
644 | switch(d3dPF)
|
---|
645 | {
|
---|
646 | case D3DFMT_A8:
|
---|
647 | return PF_A8;
|
---|
648 | case D3DFMT_L8:
|
---|
649 | return PF_L8;
|
---|
650 | case D3DFMT_L16:
|
---|
651 | return PF_L16;
|
---|
652 | case D3DFMT_A4L4:
|
---|
653 | return PF_A4L4;
|
---|
654 | case D3DFMT_A8L8:
|
---|
655 | return PF_BYTE_LA; // Assume little endian here
|
---|
656 | case D3DFMT_R3G3B2:
|
---|
657 | return PF_R3G3B2;
|
---|
658 | case D3DFMT_A1R5G5B5:
|
---|
659 | return PF_A1R5G5B5;
|
---|
660 | case D3DFMT_A4R4G4B4:
|
---|
661 | return PF_A4R4G4B4;
|
---|
662 | case D3DFMT_R5G6B5:
|
---|
663 | return PF_R5G6B5;
|
---|
664 | case D3DFMT_R8G8B8:
|
---|
665 | return PF_R8G8B8;
|
---|
666 | case D3DFMT_X8R8G8B8:
|
---|
667 | return PF_X8R8G8B8;
|
---|
668 | case D3DFMT_A8R8G8B8:
|
---|
669 | return PF_A8R8G8B8;
|
---|
670 | case D3DFMT_X8B8G8R8:
|
---|
671 | return PF_X8B8G8R8;
|
---|
672 | case D3DFMT_A8B8G8R8:
|
---|
673 | return PF_A8B8G8R8;
|
---|
674 | case D3DFMT_A2R10G10B10:
|
---|
675 | return PF_A2R10G10B10;
|
---|
676 | case D3DFMT_A2B10G10R10:
|
---|
677 | return PF_A2B10G10R10;
|
---|
678 | case D3DFMT_R16F:
|
---|
679 | return PF_FLOAT16_R;
|
---|
680 | case D3DFMT_A16B16G16R16F:
|
---|
681 | return PF_FLOAT16_RGBA;
|
---|
682 | case D3DFMT_R32F:
|
---|
683 | return PF_FLOAT32_R;
|
---|
684 | case D3DFMT_A32B32G32R32F:
|
---|
685 | return PF_FLOAT32_RGBA;
|
---|
686 | case D3DFMT_A16B16G16R16:
|
---|
687 | return PF_SHORT_RGBA;
|
---|
688 | case D3DFMT_DXT1:
|
---|
689 | return PF_DXT1;
|
---|
690 | case D3DFMT_DXT2:
|
---|
691 | return PF_DXT2;
|
---|
692 | case D3DFMT_DXT3:
|
---|
693 | return PF_DXT3;
|
---|
694 | case D3DFMT_DXT4:
|
---|
695 | return PF_DXT4;
|
---|
696 | case D3DFMT_DXT5:
|
---|
697 | return PF_DXT5;
|
---|
698 | default:
|
---|
699 | return PF_UNKNOWN;
|
---|
700 | }
|
---|
701 | }
|
---|
702 | /****************************************************************************************/
|
---|
703 | D3DFORMAT D3D9Mappings::_getPF(PixelFormat ogrePF)
|
---|
704 | {
|
---|
705 | switch(ogrePF)
|
---|
706 | {
|
---|
707 | case PF_L8:
|
---|
708 | return D3DFMT_L8;
|
---|
709 | case PF_L16:
|
---|
710 | return D3DFMT_L16;
|
---|
711 | case PF_A8:
|
---|
712 | return D3DFMT_A8;
|
---|
713 | case PF_A4L4:
|
---|
714 | return D3DFMT_A4L4;
|
---|
715 | case PF_BYTE_LA:
|
---|
716 | return D3DFMT_A8L8; // Assume little endian here
|
---|
717 | case PF_R3G3B2:
|
---|
718 | return D3DFMT_R3G3B2;
|
---|
719 | case PF_A1R5G5B5:
|
---|
720 | return D3DFMT_A1R5G5B5;
|
---|
721 | case PF_R5G6B5:
|
---|
722 | return D3DFMT_R5G6B5;
|
---|
723 | case PF_A4R4G4B4:
|
---|
724 | return D3DFMT_A4R4G4B4;
|
---|
725 | case PF_R8G8B8:
|
---|
726 | return D3DFMT_R8G8B8;
|
---|
727 | case PF_A8R8G8B8:
|
---|
728 | return D3DFMT_A8R8G8B8;
|
---|
729 | case PF_A8B8G8R8:
|
---|
730 | return D3DFMT_A8B8G8R8;
|
---|
731 | case PF_X8R8G8B8:
|
---|
732 | return D3DFMT_X8R8G8B8;
|
---|
733 | case PF_X8B8G8R8:
|
---|
734 | return D3DFMT_X8B8G8R8;
|
---|
735 | case PF_A2B10G10R10:
|
---|
736 | return D3DFMT_A2B10G10R10;
|
---|
737 | case PF_A2R10G10B10:
|
---|
738 | return D3DFMT_A2R10G10B10;
|
---|
739 | case PF_FLOAT16_R:
|
---|
740 | return D3DFMT_R16F;
|
---|
741 | case PF_FLOAT16_RGBA:
|
---|
742 | return D3DFMT_A16B16G16R16F;
|
---|
743 | case PF_FLOAT32_R:
|
---|
744 | return D3DFMT_R32F;
|
---|
745 | case PF_FLOAT32_RGBA:
|
---|
746 | return D3DFMT_A32B32G32R32F;
|
---|
747 | case PF_SHORT_RGBA:
|
---|
748 | return D3DFMT_A16B16G16R16;
|
---|
749 | case PF_DXT1:
|
---|
750 | return D3DFMT_DXT1;
|
---|
751 | case PF_DXT2:
|
---|
752 | return D3DFMT_DXT2;
|
---|
753 | case PF_DXT3:
|
---|
754 | return D3DFMT_DXT3;
|
---|
755 | case PF_DXT4:
|
---|
756 | return D3DFMT_DXT4;
|
---|
757 | case PF_DXT5:
|
---|
758 | return D3DFMT_DXT5;
|
---|
759 | case PF_UNKNOWN:
|
---|
760 | default:
|
---|
761 | return D3DFMT_UNKNOWN;
|
---|
762 | }
|
---|
763 | }
|
---|
764 | /****************************************************************************************/
|
---|
765 | PixelFormat D3D9Mappings::_getClosestSupportedPF(PixelFormat ogrePF)
|
---|
766 | {
|
---|
767 | if (_getPF(ogrePF) != D3DFMT_UNKNOWN)
|
---|
768 | {
|
---|
769 | return ogrePF;
|
---|
770 | }
|
---|
771 | switch(ogrePF)
|
---|
772 | {
|
---|
773 | case PF_B5G6R5:
|
---|
774 | return PF_R5G6B5;
|
---|
775 | case PF_B8G8R8:
|
---|
776 | return PF_R8G8B8;
|
---|
777 | case PF_B8G8R8A8:
|
---|
778 | return PF_A8R8G8B8;
|
---|
779 | case PF_FLOAT16_RGB:
|
---|
780 | return PF_FLOAT16_RGBA;
|
---|
781 | case PF_FLOAT32_RGB:
|
---|
782 | return PF_FLOAT32_RGBA;
|
---|
783 | case PF_UNKNOWN:
|
---|
784 | default:
|
---|
785 | return PF_A8R8G8B8;
|
---|
786 | }
|
---|
787 | }
|
---|
788 |
|
---|
789 | }
|
---|