1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#include "IrrCompileConfig.h"
7
#define _IRR_DONT_DO_MEMORY_DEBUGGING_HERE
8
#include "CD3D8Driver.h"
10
#ifdef _IRR_COMPILE_WITH_DIRECT3D_8_
13
#include "S3DVertex.h"
14
#include "CD3D8Texture.h"
15
#include "CD3D8MaterialRenderer.h"
16
#include "CD3D8ShaderMaterialRenderer.h"
17
#include "CD3D8NormalMapRenderer.h"
18
#include "CD3D8ParallaxMapRenderer.h"
19
#include "SIrrCreationParameters.h"
28
CD3D8Driver::CD3D8Driver(const core::dimension2d<u32>& screenSize, HWND window,
29
bool fullscreen, bool stencilbuffer,
30
io::IFileSystem* io, bool pureSoftware, bool vsync)
31
: CNullDriver(io, screenSize), CurrentRenderMode(ERM_NONE),
32
ResetRenderStates(true), Transformation3DChanged(false), StencilBuffer(stencilbuffer),
33
D3DLibrary(0), pID3D(0), pID3DDevice(0), PrevRenderTarget(0),
34
WindowId(0), SceneSourceRect(0),
35
LastVertexType((video::E_VERTEX_TYPE)-1), MaxTextureUnits(0), MaxUserClipPlanes(0),
36
MaxLightDistance(0), LastSetLight(-1), DeviceLost(false),
37
DriverWasReset(true), DisplayAdapter(0)
40
setDebugName("CD3D8Driver");
45
for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
46
CurrentTexture[i] = 0;
47
MaxLightDistance=sqrtf(FLT_MAX);
48
// create sphere map matrix
50
SphereMapMatrixD3D8._11 = 0.5f; SphereMapMatrixD3D8._12 = 0.0f;
51
SphereMapMatrixD3D8._13 = 0.0f; SphereMapMatrixD3D8._14 = 0.0f;
52
SphereMapMatrixD3D8._21 = 0.0f; SphereMapMatrixD3D8._22 =-0.5f;
53
SphereMapMatrixD3D8._23 = 0.0f; SphereMapMatrixD3D8._24 = 0.0f;
54
SphereMapMatrixD3D8._31 = 0.0f; SphereMapMatrixD3D8._32 = 0.0f;
55
SphereMapMatrixD3D8._33 = 1.0f; SphereMapMatrixD3D8._34 = 0.0f;
56
SphereMapMatrixD3D8._41 = 0.5f; SphereMapMatrixD3D8._42 = 0.5f;
57
SphereMapMatrixD3D8._43 = 0.0f; SphereMapMatrixD3D8._44 = 1.0f;
59
UnitMatrixD3D8 = *(D3DMATRIX*)((void*)core::IdentityMatrix.pointer());
61
// init direct 3d is done in the factory function
66
CD3D8Driver::~CD3D8Driver()
68
deleteMaterialRenders();
73
pID3DDevice->Release();
80
void CD3D8Driver::createMaterialRenderers()
82
// create D3D8 material renderers
84
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_SOLID(pID3DDevice, this));
85
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_SOLID_2_LAYER(pID3DDevice, this));
87
// add the same renderer for all lightmap types
88
CD3D8MaterialRenderer_LIGHTMAP* lmr = new CD3D8MaterialRenderer_LIGHTMAP(pID3DDevice, this);
89
addMaterialRenderer(lmr); // for EMT_LIGHTMAP:
90
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_ADD:
91
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_M2:
92
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_M4:
93
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_LIGHTING:
94
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_LIGHTING_M2:
95
addMaterialRenderer(lmr); // for EMT_LIGHTMAP_LIGHTING_M4:
98
// add remaining material renderers
99
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_DETAIL_MAP(pID3DDevice, this));
100
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_SPHERE_MAP(pID3DDevice, this));
101
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_REFLECTION_2_LAYER(pID3DDevice, this));
102
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_TRANSPARENT_ADD_COLOR(pID3DDevice, this));
103
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL(pID3DDevice, this));
104
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_TRANSPARENT_ALPHA_CHANNEL_REF(pID3DDevice, this));
105
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_TRANSPARENT_VERTEX_ALPHA(pID3DDevice, this));
106
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_TRANSPARENT_REFLECTION_2_LAYER(pID3DDevice, this));
108
// add normal map renderers
110
video::IMaterialRenderer* renderer = 0;
112
renderer = new CD3D8NormalMapRenderer(pID3DDevice, this, tmp,
113
MaterialRenderers[EMT_SOLID].Renderer);
116
renderer = new CD3D8NormalMapRenderer(pID3DDevice, this, tmp,
117
MaterialRenderers[EMT_TRANSPARENT_ADD_COLOR].Renderer);
120
renderer = new CD3D8NormalMapRenderer(pID3DDevice, this, tmp,
121
MaterialRenderers[EMT_TRANSPARENT_VERTEX_ALPHA].Renderer);
124
// add parallax map renderers
126
renderer = new CD3D8ParallaxMapRenderer(pID3DDevice, this, tmp,
127
MaterialRenderers[EMT_SOLID].Renderer);
130
renderer = new CD3D8ParallaxMapRenderer(pID3DDevice, this, tmp,
131
MaterialRenderers[EMT_TRANSPARENT_ADD_COLOR].Renderer);
134
renderer = new CD3D8ParallaxMapRenderer(pID3DDevice, this, tmp,
135
MaterialRenderers[EMT_TRANSPARENT_VERTEX_ALPHA].Renderer);
138
// add basic 1 texture blending
139
addAndDropMaterialRenderer(new CD3D8MaterialRenderer_ONETEXTURE_BLEND(pID3DDevice, this));
143
//! initialises the Direct3D API
144
bool CD3D8Driver::initDriver(const core::dimension2d<u32>& screenSize,
145
HWND hwnd, u32 bits, bool fullScreen, bool pureSoftware,
146
bool highPrecisionFPU, bool vsync, u8 antiAlias, u32 displayAdapter)
149
typedef IDirect3D8 * (__stdcall *D3DCREATETYPE)(UINT);
150
DisplayAdapter = displayAdapter;
152
#if defined( _IRR_XBOX_PLATFORM_)
153
D3DCREATETYPE d3dCreate = (D3DCREATETYPE) &Direct3DCreate8;
155
D3DLibrary = LoadLibrary( __TEXT("d3d8.dll") );
159
os::Printer::log("Error, could not load d3d8.dll.", ELL_ERROR);
163
D3DCREATETYPE d3dCreate = (D3DCREATETYPE) GetProcAddress(D3DLibrary, "Direct3DCreate8");
167
os::Printer::log("Error, could not get proc adress of Direct3DCreate8.", ELL_ERROR);
172
//just like pID3D = Direct3DCreate8(D3D_SDK_VERSION);
173
pID3D = (*d3dCreate)(D3D_SDK_VERSION);
177
os::Printer::log("Error initializing D3D.", ELL_ERROR);
181
// print device information
182
D3DADAPTER_IDENTIFIER8 dai;
183
if (!FAILED(pID3D->GetAdapterIdentifier(DisplayAdapter, D3DENUM_NO_WHQL_LEVEL, &dai)))
187
s32 Product = HIWORD(dai.DriverVersion.HighPart);
188
s32 Version = LOWORD(dai.DriverVersion.HighPart);
189
s32 SubVersion = HIWORD(dai.DriverVersion.LowPart);
190
s32 Build = LOWORD(dai.DriverVersion.LowPart);
192
sprintf(tmp, "%s %s %d.%d.%d.%d", dai.Description, dai.Driver, Product, Version,
194
os::Printer::log(tmp, ELL_INFORMATION);
197
D3DDISPLAYMODE d3ddm;
198
hr = pID3D->GetAdapterDisplayMode(DisplayAdapter, &d3ddm);
201
os::Printer::log("Error: Could not get Adapter Display mode.", ELL_ERROR);
205
ZeroMemory(&present, sizeof(present));
207
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
208
present.Windowed = TRUE;
209
present.BackBufferFormat = d3ddm.Format;
210
present.EnableAutoDepthStencil = TRUE;
214
present.SwapEffect = D3DSWAPEFFECT_FLIP;
215
present.Windowed = FALSE;
216
present.BackBufferWidth = screenSize.Width;
217
present.BackBufferHeight = screenSize.Height;
218
present.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
219
present.FullScreen_PresentationInterval = vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
222
present.BackBufferFormat = D3DFMT_X8R8G8B8;
224
present.BackBufferFormat = D3DFMT_R5G6B5;
227
D3DDEVTYPE devtype = D3DDEVTYPE_HAL;
228
#ifndef _IRR_D3D_NO_SHADER_DEBUGGING
229
devtype = D3DDEVTYPE_REF;
232
// enable anti alias if possible and whished
240
if(!FAILED(pID3D->CheckDeviceMultiSampleType(DisplayAdapter,
241
devtype , present.BackBufferFormat, !fullScreen,
242
(D3DMULTISAMPLE_TYPE)antiAlias)))
244
present.MultiSampleType = (D3DMULTISAMPLE_TYPE)antiAlias;
245
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
252
os::Printer::log("Anti aliasing disabled because hardware/driver lacks necessary caps.", ELL_WARNING);
255
// check stencil buffer compatibility
258
present.AutoDepthStencilFormat = D3DFMT_D24S8;
259
if(FAILED(pID3D->CheckDeviceFormat(DisplayAdapter, devtype,
260
present.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
261
D3DRTYPE_SURFACE, present.AutoDepthStencilFormat)))
263
#if !defined( _IRR_XBOX_PLATFORM_)
264
present.AutoDepthStencilFormat = D3DFMT_D24X4S4;
265
if(FAILED(pID3D->CheckDeviceFormat(DisplayAdapter, devtype,
266
present.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
267
D3DRTYPE_SURFACE, present.AutoDepthStencilFormat)))
269
present.AutoDepthStencilFormat = D3DFMT_D15S1;
270
if(FAILED(pID3D->CheckDeviceFormat(DisplayAdapter, devtype,
271
present.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
272
D3DRTYPE_SURFACE, present.AutoDepthStencilFormat)))
274
os::Printer::log("Device does not support stencilbuffer, disabling stencil buffer.", ELL_WARNING);
275
StencilBuffer = false;
281
if(FAILED(pID3D->CheckDepthStencilMatch(DisplayAdapter, devtype,
282
present.BackBufferFormat, present.BackBufferFormat, present.AutoDepthStencilFormat)))
284
os::Printer::log("Depth-stencil format is not compatible with display format, disabling stencil buffer.", ELL_WARNING);
285
StencilBuffer = false;
288
// do not use else here to cope with flag change in previous block
291
#if !defined( _IRR_XBOX_PLATFORM_)
292
present.AutoDepthStencilFormat = D3DFMT_D32;
293
if(FAILED(pID3D->CheckDeviceFormat(DisplayAdapter, devtype,
294
present.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
295
D3DRTYPE_SURFACE, present.AutoDepthStencilFormat)))
297
present.AutoDepthStencilFormat = D3DFMT_D24X8;
298
if(FAILED(pID3D->CheckDeviceFormat(DisplayAdapter, devtype,
299
present.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
300
D3DRTYPE_SURFACE, present.AutoDepthStencilFormat)))
302
present.AutoDepthStencilFormat = D3DFMT_D16;
303
if(FAILED(pID3D->CheckDeviceFormat(DisplayAdapter, devtype,
304
present.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
305
D3DRTYPE_SURFACE, present.AutoDepthStencilFormat)))
307
os::Printer::log("Device does not support required depth buffer.", ELL_WARNING);
313
present.AutoDepthStencilFormat = D3DFMT_D16;
314
if(FAILED(pID3D->CheckDeviceFormat(DisplayAdapter, devtype,
315
present.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
316
D3DRTYPE_SURFACE, present.AutoDepthStencilFormat)))
318
os::Printer::log("Device does not support required depth buffer.", ELL_WARNING);
325
#if defined( _IRR_XBOX_PLATFORM_)
326
DWORD fpuPrecision = 0;
328
DWORD fpuPrecision = highPrecisionFPU ? D3DCREATE_FPU_PRESERVE : 0;
332
hr = pID3D->CreateDevice(DisplayAdapter, D3DDEVTYPE_REF, hwnd,
333
fpuPrecision | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present, &pID3DDevice);
336
os::Printer::log("Was not able to create Direct3D8 software device.", ELL_ERROR);
340
hr = pID3D->CreateDevice(DisplayAdapter, devtype, hwnd,
341
fpuPrecision | D3DCREATE_HARDWARE_VERTEXPROCESSING, &present, &pID3DDevice);
344
hr = pID3D->CreateDevice(DisplayAdapter, devtype, hwnd,
345
fpuPrecision | D3DCREATE_MIXED_VERTEXPROCESSING , &present, &pID3DDevice);
347
hr = pID3D->CreateDevice(DisplayAdapter, devtype, hwnd,
348
fpuPrecision | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present, &pID3DDevice);
350
os::Printer::log("Was not able to create Direct3D8 device.", ELL_ERROR);
355
os::Printer::log("Was not able to create Direct3D8 device.", ELL_ERROR);
360
pID3DDevice->GetDeviceCaps(&Caps);
363
(!(Caps.StencilCaps & D3DSTENCILCAPS_DECRSAT) ||
364
!(Caps.StencilCaps & D3DSTENCILCAPS_INCRSAT) ||
365
!(Caps.StencilCaps & D3DSTENCILCAPS_KEEP)))
367
os::Printer::log("Device not able to use stencil buffer, disabling stencil buffer.", ELL_WARNING);
368
StencilBuffer = false;
371
// set default vertex shader
372
setVertexShader(EVT_STANDARD);
374
// enable antialiasing
376
pID3DDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
379
setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
382
ExposedData.D3D8.D3D8 = pID3D;
383
ExposedData.D3D8.D3DDev8 = pID3DDevice;
384
ExposedData.D3D8.HWnd = hwnd;
386
ResetRenderStates = true;
389
createMaterialRenderers();
391
MaxTextureUnits = core::min_((u32)Caps.MaxSimultaneousTextures, MATERIAL_MAX_TEXTURES);
392
MaxUserClipPlanes = (u32)Caps.MaxUserClipPlanes;
394
DriverAttributes->setAttribute("MaxTextures", (s32)MaxTextureUnits);
395
DriverAttributes->setAttribute("MaxSupportedTextures", (s32)Caps.MaxSimultaneousTextures);
396
DriverAttributes->setAttribute("MaxLights", (s32)Caps.MaxActiveLights);
397
DriverAttributes->setAttribute("MaxAnisotropy", (s32)Caps.MaxAnisotropy);
398
DriverAttributes->setAttribute("MaxUserClipPlanes", (s32)Caps.MaxUserClipPlanes);
399
DriverAttributes->setAttribute("MaxIndices", (s32)Caps.MaxVertexIndex);
400
DriverAttributes->setAttribute("MaxTextureSize", (s32)core::min_(Caps.MaxTextureHeight,Caps.MaxTextureWidth));
401
DriverAttributes->setAttribute("MaxTextureLODBias", 16.f);
402
DriverAttributes->setAttribute("Version", 800);
403
DriverAttributes->setAttribute("ShaderLanguageVersion", (s32)Caps.VertexShaderVersion*100);
404
DriverAttributes->setAttribute("AntiAlias", antiAlias);
406
// set the renderstates
407
setRenderStates3DMode();
414
//! applications must call this method before performing any rendering. returns false if failed.
415
bool CD3D8Driver::beginScene(bool backBuffer, bool zBuffer, SColor color,
416
const SExposedVideoData& videoData, core::rect<s32>* sourceRect)
418
CNullDriver::beginScene(backBuffer, zBuffer, color, videoData, sourceRect);
419
WindowId = (HWND)videoData.D3D8.HWnd;
420
SceneSourceRect = sourceRect;
428
#ifndef _IRR_XBOX_PLATFORM_
429
if(FAILED(hr = pID3DDevice->TestCooperativeLevel()))
431
if (hr == D3DERR_DEVICELOST)
434
hr = pID3DDevice->TestCooperativeLevel();
435
if (hr == D3DERR_DEVICELOST)
439
if ((hr == D3DERR_DEVICENOTRESET) && !reset())
448
flags |= D3DCLEAR_TARGET;
451
flags |= D3DCLEAR_ZBUFFER;
454
flags |= D3DCLEAR_STENCIL;
458
hr = pID3DDevice->Clear( 0, NULL, flags, color.color, 1.0, 0);
460
os::Printer::log("Direct3D8 clear failed.", ELL_WARNING);
463
hr = pID3DDevice->BeginScene();
466
os::Printer::log("Direct3D8 begin scene failed.", ELL_WARNING);
474
//! applications must call this method after performing any rendering. returns false if failed.
475
bool CD3D8Driver::endScene()
477
CNullDriver::endScene();
478
DriverWasReset=false;
480
HRESULT hr = pID3DDevice->EndScene();
483
os::Printer::log("DIRECT3D8 end scene failed.", ELL_WARNING);
489
if ( SceneSourceRect)
491
srcRct = &sourceRectData;
492
sourceRectData.left = SceneSourceRect->UpperLeftCorner.X;
493
sourceRectData.top = SceneSourceRect->UpperLeftCorner.Y;
494
sourceRectData.right = SceneSourceRect->LowerRightCorner.X;
495
sourceRectData.bottom = SceneSourceRect->LowerRightCorner.Y;
498
hr = pID3DDevice->Present(srcRct, NULL, WindowId, NULL);
503
if (hr == D3DERR_DEVICELOST)
506
os::Printer::log("DIRECT3D8 device lost.", ELL_WARNING);
509
os::Printer::log("DIRECT3D8 present failed.", ELL_WARNING);
514
//! resets the device
515
bool CD3D8Driver::reset()
518
os::Printer::log("Resetting D3D8 device.", ELL_INFORMATION);
520
for (i=0; i<Textures.size(); ++i)
522
if (Textures[i].Surface->isRenderTarget())
524
IDirect3DTexture8* tex = ((CD3D8Texture*)(Textures[i].Surface))->getDX8Texture();
531
HRESULT hr = pID3DDevice->Reset(&present);
533
for (i=0; i<Textures.size(); ++i)
535
if (Textures[i].Surface->isRenderTarget())
536
((CD3D8Texture*)(Textures[i].Surface))->createRenderTarget();
541
if (hr == D3DERR_DEVICELOST)
544
os::Printer::log("Resetting failed due to device lost.", ELL_WARNING);
547
os::Printer::log("Resetting failed.", ELL_WARNING);
552
ResetRenderStates = true;
553
LastVertexType = (E_VERTEX_TYPE)-1;
555
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
556
CurrentTexture[i] = 0;
558
setVertexShader(EVT_STANDARD);
559
setRenderStates3DMode();
560
setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
561
setAmbientLight(AmbientLight);
567
//! queries the features of the driver, returns true if feature is available
568
bool CD3D8Driver::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
570
if (!FeatureEnabled[feature])
575
case EVDF_RENDER_TO_TARGET:
576
case EVDF_MULTITEXTURE:
577
case EVDF_BILINEAR_FILTER:
579
case EVDF_HARDWARE_TL:
580
return (Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0;
582
return (Caps.TextureCaps & D3DPTEXTURECAPS_MIPMAP) != 0;
583
case EVDF_STENCIL_BUFFER:
584
return StencilBuffer && Caps.StencilCaps;
585
case EVDF_VERTEX_SHADER_1_1:
586
return Caps.VertexShaderVersion >= D3DVS_VERSION(1,1);
587
case EVDF_VERTEX_SHADER_2_0:
588
return Caps.VertexShaderVersion >= D3DVS_VERSION(2,0);
589
case EVDF_VERTEX_SHADER_3_0:
590
return Caps.VertexShaderVersion >= D3DVS_VERSION(3,0);
591
case EVDF_PIXEL_SHADER_1_1:
592
return Caps.PixelShaderVersion >= D3DPS_VERSION(1,1);
593
case EVDF_PIXEL_SHADER_1_2:
594
return Caps.PixelShaderVersion >= D3DPS_VERSION(1,2);
595
case EVDF_PIXEL_SHADER_1_3:
596
return Caps.PixelShaderVersion >= D3DPS_VERSION(1,3);
597
case EVDF_PIXEL_SHADER_1_4:
598
return Caps.PixelShaderVersion >= D3DPS_VERSION(1,4);
599
case EVDF_PIXEL_SHADER_2_0:
600
return Caps.PixelShaderVersion >= D3DPS_VERSION(2,0);
601
case EVDF_PIXEL_SHADER_3_0:
602
return Caps.PixelShaderVersion >= D3DPS_VERSION(3,0);
603
case EVDF_TEXTURE_NSQUARE:
604
return (Caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) == 0;
605
case EVDF_TEXTURE_NPOT:
606
return (Caps.TextureCaps & D3DPTEXTURECAPS_POW2) == 0;
607
case EVDF_COLOR_MASK:
608
return (Caps.PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE) != 0;
609
case EVDF_BLEND_OPERATIONS:
610
case EVDF_TEXTURE_MATRIX:
618
//! sets transformation
619
void CD3D8Driver::setTransform(E_TRANSFORMATION_STATE state,
620
const core::matrix4& mat)
625
pID3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)((void*)mat.pointer()));
626
Transformation3DChanged = true;
629
pID3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)((void*)mat.pointer()));
630
Transformation3DChanged = true;
633
pID3DDevice->SetTransform( D3DTS_PROJECTION, (D3DMATRIX*)((void*)mat.pointer()));
634
Transformation3DChanged = true;
639
if (state-ETS_TEXTURE_0 < MATERIAL_MAX_TEXTURES)
641
pID3DDevice->SetTextureStageState( state - ETS_TEXTURE_0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
642
pID3DDevice->SetTransform((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+ ( state - ETS_TEXTURE_0 )),
643
(D3DMATRIX*)((void*)mat.pointer()));
648
Matrices[state] = mat;
652
//! sets the current Texture
653
bool CD3D8Driver::setActiveTexture(u32 stage, const video::ITexture* texture)
655
if (CurrentTexture[stage] == texture)
658
if (texture && (texture->getDriverType() != EDT_DIRECT3D8))
660
os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
664
CurrentTexture[stage] = texture;
668
pID3DDevice->SetTexture(stage, 0);
669
pID3DDevice->SetTextureStageState( stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
673
pID3DDevice->SetTexture(stage, ((const CD3D8Texture*)texture)->getDX8Texture());
680
void CD3D8Driver::setMaterial(const SMaterial& material)
683
OverrideMaterial.apply(Material);
685
for (u32 i=0; i<MaxTextureUnits; ++i)
687
setActiveTexture(i, Material.getTexture(i));
688
setTransform((E_TRANSFORMATION_STATE) ( ETS_TEXTURE_0 + i ),
689
material.getTextureMatrix(i));
694
//! returns a device dependent texture from a software surface (IImage)
695
video::ITexture* CD3D8Driver::createDeviceDependentTexture(IImage* surface,const io::path& name, void* mipmapData)
697
return new CD3D8Texture(surface, this, TextureCreationFlags, name, mipmapData);
701
//! Enables or disables a texture creation flag.
702
void CD3D8Driver::setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag,
705
if (flag == video::ETCF_CREATE_MIP_MAPS && !queryFeature(EVDF_MIP_MAP))
708
CNullDriver::setTextureCreationFlag(flag, enabled);
712
//! sets a render target
713
bool CD3D8Driver::setRenderTarget(video::ITexture* texture,
714
bool clearBackBuffer, bool clearZBuffer, SColor color)
716
// check for right driver type
718
if (texture && texture->getDriverType() != EDT_DIRECT3D8)
720
os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
724
// check for valid render target
726
CD3D8Texture* tex = (CD3D8Texture*)texture;
728
if (texture && !tex->isRenderTarget())
730
os::Printer::log("Fatal Error: Tried to set a non render target texture as render target.", ELL_ERROR);
734
if (texture && (tex->getSize().Width > ScreenSize.Width ||
735
tex->getSize().Height > ScreenSize.Height ))
737
os::Printer::log("Error: Tried to set a render target texture which is bigger than the screen.", ELL_ERROR);
741
// check if we should set the previous RT back
747
if (PrevRenderTarget)
749
IDirect3DSurface8* dss = 0;
750
pID3DDevice->GetDepthStencilSurface(&dss);
752
if (FAILED(pID3DDevice->SetRenderTarget(PrevRenderTarget, dss)))
754
os::Printer::log("Error: Could not set back to previous render target.", ELL_ERROR);
761
CurrentRendertargetSize = core::dimension2d<u32>(0,0);
762
PrevRenderTarget->Release();
763
PrevRenderTarget = 0;
768
// we want to set a new target. so do this.
770
// store previous target
772
if (!PrevRenderTarget && (FAILED(pID3DDevice->GetRenderTarget(&PrevRenderTarget))))
774
os::Printer::log("Could not get previous render target.", ELL_ERROR);
778
// set new render target
780
IDirect3DSurface8* dss = 0;
781
pID3DDevice->GetDepthStencilSurface(&dss);
783
if (FAILED(pID3DDevice->SetRenderTarget(tex->getRenderTargetSurface(), dss)))
785
os::Printer::log("Error: Could not set render target.", ELL_ERROR);
792
CurrentRendertargetSize = tex->getSize();
794
Transformation3DChanged = true;
796
if (clearBackBuffer || clearZBuffer)
801
flags |= D3DCLEAR_TARGET;
804
flags |= D3DCLEAR_ZBUFFER;
806
pID3DDevice->Clear(0, NULL, flags, color.color, 1.0f, 0);
813
//! Creates a render target texture.
814
ITexture* CD3D8Driver::addRenderTargetTexture(
815
const core::dimension2d<u32>& size, const io::path& name,
816
const ECOLOR_FORMAT format)
818
CD3D8Texture* tex = new CD3D8Texture(this, size, name);
834
void CD3D8Driver::setViewPort(const core::rect<s32>& area)
836
core::rect<s32> vp(area);
837
core::rect<s32> rendert(0,0, ScreenSize.Width, ScreenSize.Height);
838
vp.clipAgainst(rendert);
840
D3DVIEWPORT8 viewPort;
841
viewPort.X = vp.UpperLeftCorner.X;
842
viewPort.Y = vp.UpperLeftCorner.Y;
843
viewPort.Width = vp.getWidth();
844
viewPort.Height = vp.getHeight();
845
viewPort.MinZ = 0.0f;
846
viewPort.MaxZ = 1.0f;
848
HRESULT hr = D3DERR_INVALIDCALL;
849
if (vp.getHeight()>0 && vp.getWidth()>0)
850
hr = pID3DDevice->SetViewport(&viewPort);
853
os::Printer::log("Failed setting the viewport.", ELL_WARNING);
859
//! gets the area of the current viewport
860
const core::rect<s32>& CD3D8Driver::getViewPort() const
866
//! draws a vertex primitive list
867
void CD3D8Driver::drawVertexPrimitiveList(const void* vertices,
868
u32 vertexCount, const void* indexList, u32 primitiveCount,
869
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
872
if (!checkPrimitiveCount(primitiveCount))
875
CNullDriver::drawVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType,iType);
877
if (!vertexCount || !primitiveCount)
880
draw2D3DVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount,
881
vType, pType, iType, true);
885
//! draws a vertex primitive list in 2d
886
void CD3D8Driver::draw2DVertexPrimitiveList(const void* vertices,
887
u32 vertexCount, const void* indexList, u32 primitiveCount,
888
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
891
if (!checkPrimitiveCount(primitiveCount))
894
CNullDriver::draw2DVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType,iType);
896
if (!vertexCount || !primitiveCount)
899
draw2D3DVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount,
900
vType, pType, iType, false);
904
void CD3D8Driver::draw2D3DVertexPrimitiveList(const void* vertices,
905
u32 vertexCount, const void* indexList, u32 primitiveCount,
906
E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType,
907
E_INDEX_TYPE iType, bool is3D)
909
setVertexShader(vType);
911
const u32 stride = getVertexPitchFromType(vType);
913
D3DFORMAT indexType=D3DFMT_UNKNOWN;
918
indexType=D3DFMT_INDEX16;
923
indexType=D3DFMT_INDEX32;
930
if (!setRenderStates3DMode())
935
if (Material.MaterialType==EMT_ONETEXTURE_BLEND)
937
E_BLEND_FACTOR srcFact;
938
E_BLEND_FACTOR dstFact;
939
E_MODULATE_FUNC modulo;
941
unpack_texureBlendFunc ( srcFact, dstFact, modulo, alphaSource, Material.MaterialTypeParam);
942
setRenderStates2DMode(alphaSource&video::EAS_VERTEX_COLOR, (Material.getTexture(0) != 0), (alphaSource&video::EAS_TEXTURE) != 0);
945
setRenderStates2DMode(Material.MaterialType==EMT_TRANSPARENT_VERTEX_ALPHA, (Material.getTexture(0) != 0), Material.MaterialType==EMT_TRANSPARENT_ALPHA_CHANNEL);
950
case scene::EPT_POINT_SPRITES:
951
case scene::EPT_POINTS:
953
f32 tmp=Material.Thickness/getScreenSize().Height;
954
if (pType==scene::EPT_POINT_SPRITES)
955
pID3DDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
956
pID3DDevice->SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);
957
pID3DDevice->SetRenderState(D3DRS_POINTSIZE, *(DWORD*)(&tmp));
959
pID3DDevice->SetRenderState(D3DRS_POINTSCALE_A, *(DWORD*)(&tmp));
960
pID3DDevice->SetRenderState(D3DRS_POINTSCALE_B, *(DWORD*)(&tmp));
961
pID3DDevice->SetRenderState(D3DRS_POINTSIZE_MIN, *(DWORD*)(&tmp));
963
pID3DDevice->SetRenderState(D3DRS_POINTSCALE_C, *(DWORD*)(&tmp));
964
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_POINTLIST, 0, vertexCount,
965
primitiveCount, indexList, indexType, vertices, stride);
966
pID3DDevice->SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);
967
if (pType==scene::EPT_POINT_SPRITES)
968
pID3DDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, FALSE);
971
case scene::EPT_LINE_STRIP:
972
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_LINESTRIP, 0, vertexCount,
973
primitiveCount, indexList, indexType, vertices, stride);
975
case scene::EPT_LINE_LOOP:
977
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_LINESTRIP, 0, vertexCount,
978
primitiveCount - 1, indexList, indexType, vertices, stride);
979
u16 tmpIndices[] = {primitiveCount - 1, 0};
980
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_LINELIST, 0, vertexCount,
981
1, tmpIndices, indexType, vertices, stride);
984
case scene::EPT_LINES:
985
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_LINELIST, 0, vertexCount,
986
primitiveCount, indexList, indexType, vertices, stride);
988
case scene::EPT_TRIANGLE_STRIP:
989
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLESTRIP, 0, vertexCount,
990
primitiveCount, indexList, indexType, vertices, stride);
992
case scene::EPT_TRIANGLE_FAN:
993
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLEFAN, 0, vertexCount,
994
primitiveCount, indexList, indexType, vertices, stride);
996
case scene::EPT_TRIANGLES:
997
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, vertexCount,
998
primitiveCount, indexList, indexType, vertices, stride);
1004
//! draws an 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted.
1005
void CD3D8Driver::draw2DImage(const video::ITexture* texture,
1006
const core::position2d<s32>& pos,
1007
const core::rect<s32>& sourceRect,
1008
const core::rect<s32>* clipRect, SColor color,
1009
bool useAlphaChannelOfTexture)
1014
if (!sourceRect.isValid())
1017
if (!setActiveTexture(0, texture))
1020
core::position2d<s32> targetPos = pos;
1021
core::position2d<s32> sourcePos = sourceRect.UpperLeftCorner;
1022
// This needs to be signed as it may go negative.
1023
core::dimension2d<s32> sourceSize(sourceRect.getSize());
1024
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
1028
if (targetPos.X < clipRect->UpperLeftCorner.X)
1030
sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X;
1031
if (sourceSize.Width <= 0)
1034
sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X;
1035
targetPos.X = clipRect->UpperLeftCorner.X;
1038
if (targetPos.X + (s32)sourceSize.Width > clipRect->LowerRightCorner.X)
1040
sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X;
1041
if (sourceSize.Width <= 0)
1045
if (targetPos.Y < clipRect->UpperLeftCorner.Y)
1047
sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y;
1048
if (sourceSize.Height <= 0)
1051
sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y;
1052
targetPos.Y = clipRect->UpperLeftCorner.Y;
1055
if (targetPos.Y + (s32)sourceSize.Height > clipRect->LowerRightCorner.Y)
1057
sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y;
1058
if (sourceSize.Height <= 0)
1063
// clip these coordinates
1067
sourceSize.Width += targetPos.X;
1068
if (sourceSize.Width <= 0)
1071
sourcePos.X -= targetPos.X;
1075
if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width)
1077
sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width;
1078
if (sourceSize.Width <= 0)
1084
sourceSize.Height += targetPos.Y;
1085
if (sourceSize.Height <= 0)
1088
sourcePos.Y -= targetPos.Y;
1092
if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height)
1094
sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height;
1095
if (sourceSize.Height <= 0)
1099
// ok, we've clipped everything.
1102
core::rect<f32> tcoords;
1103
tcoords.UpperLeftCorner.X = (f32)sourcePos.X / texture->getOriginalSize().Width ;
1104
tcoords.UpperLeftCorner.Y = (f32)sourcePos.Y / texture->getOriginalSize().Height;
1105
tcoords.LowerRightCorner.X = tcoords.UpperLeftCorner.X + (f32)sourceSize.Width / texture->getOriginalSize().Width;
1106
tcoords.LowerRightCorner.Y = tcoords.UpperLeftCorner.Y + (f32)sourceSize.Height / texture->getOriginalSize().Height;
1108
const core::rect<s32> poss(targetPos, sourceSize);
1110
setRenderStates2DMode(color.getAlpha()<255, true, useAlphaChannelOfTexture);
1113
vtx[0] = S3DVertex((f32)poss.UpperLeftCorner.X,
1114
(f32)poss.UpperLeftCorner.Y, 0.0f,
1115
0.0f, 0.0f, 0.0f, color,
1116
tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
1117
vtx[1] = S3DVertex((f32)poss.LowerRightCorner.X,
1118
(f32)poss.UpperLeftCorner.Y, 0.0f,
1119
0.0f, 0.0f, 0.0f, color,
1120
tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
1121
vtx[2] = S3DVertex((f32)poss.LowerRightCorner.X,
1122
(f32)poss.LowerRightCorner.Y, 0.0f,
1123
0.0f, 0.0f, 0.0f, color,
1124
tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
1125
vtx[3] = S3DVertex((f32)poss.UpperLeftCorner.X,
1126
(f32)poss.LowerRightCorner.Y, 0.0f,
1127
0.0f, 0.0f, 0.0f, color,
1128
tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
1130
const s16 indices[6] = {0,1,2,0,2,3};
1132
setVertexShader(EVT_STANDARD);
1134
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &indices[0],
1135
D3DFMT_INDEX16, &vtx[0], sizeof(S3DVertex));
1139
void CD3D8Driver::draw2DImage(const video::ITexture* texture,
1140
const core::rect<s32>& destRect,
1141
const core::rect<s32>& sourceRect,
1142
const core::rect<s32>* clipRect,
1143
const video::SColor* const colors,
1144
bool useAlphaChannelOfTexture)
1149
const core::dimension2d<u32>& ss = texture->getOriginalSize();
1150
core::rect<f32> tcoords;
1151
tcoords.UpperLeftCorner.X = (f32)sourceRect.UpperLeftCorner.X / (f32)ss.Width;
1152
tcoords.UpperLeftCorner.Y = (f32)sourceRect.UpperLeftCorner.Y / (f32)ss.Height;
1153
tcoords.LowerRightCorner.X = (f32)sourceRect.LowerRightCorner.X / (f32)ss.Width;
1154
tcoords.LowerRightCorner.Y = (f32)sourceRect.LowerRightCorner.Y / (f32)ss.Height;
1156
core::rect<s32> clippedRect(destRect);
1159
clippedRect.clipAgainst(*clipRect);
1161
//tcoords must be clipped by the same factors
1162
const f32 tcWidth = tcoords.getWidth();
1163
const f32 tcHeight = tcoords.getHeight();
1165
const f32 invDestRectWidth = 1.f / (f32)(destRect.getWidth());
1166
f32 scale = (f32)(clippedRect.UpperLeftCorner.X - destRect.UpperLeftCorner.X) * invDestRectWidth;
1167
tcoords.UpperLeftCorner.X += scale * tcWidth;
1168
scale = (f32)(destRect.LowerRightCorner.X - clippedRect.LowerRightCorner.X) * invDestRectWidth;
1169
tcoords.LowerRightCorner.X -= scale * tcWidth;
1171
const f32 invDestRectHeight = 1.f / (f32)(destRect.getHeight());
1172
scale = (f32)(clippedRect.UpperLeftCorner.Y - destRect.UpperLeftCorner.Y) * invDestRectHeight;
1173
tcoords.UpperLeftCorner.Y += scale * tcHeight;
1174
scale = (f32)(destRect.LowerRightCorner.Y - clippedRect.LowerRightCorner.Y) * invDestRectHeight;
1175
tcoords.LowerRightCorner.Y -= scale * tcHeight;
1178
const video::SColor temp[4] =
1186
const video::SColor* const useColor = colors ? colors : temp;
1188
S3DVertex vtx[4]; // clock wise
1189
vtx[0] = S3DVertex((f32)clippedRect.UpperLeftCorner.X, (f32)clippedRect.UpperLeftCorner.Y, 0.0f,
1190
0.0f, 0.0f, 0.0f, useColor[0],
1191
tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);
1192
vtx[1] = S3DVertex((f32)clippedRect.LowerRightCorner.X, (f32)clippedRect.UpperLeftCorner.Y, 0.0f,
1193
0.0f, 0.0f, 0.0f, useColor[3],
1194
tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);
1195
vtx[2] = S3DVertex((f32)clippedRect.LowerRightCorner.X, (f32)clippedRect.LowerRightCorner.Y, 0.0f,
1196
0.0f, 0.0f, 0.0f, useColor[2],
1197
tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);
1198
vtx[3] = S3DVertex((f32)clippedRect.UpperLeftCorner.X, (f32)clippedRect.LowerRightCorner.Y, 0.0f,
1199
0.0f, 0.0f, 0.0f, useColor[1],
1200
tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);
1202
const s16 indices[6] = {0,1,2,0,2,3};
1204
setRenderStates2DMode(useColor[0].getAlpha()<255 || useColor[1].getAlpha()<255 ||
1205
useColor[2].getAlpha()<255 || useColor[3].getAlpha()<255,
1206
true, useAlphaChannelOfTexture);
1208
setActiveTexture(0, texture);
1210
setVertexShader(EVT_STANDARD);
1212
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &indices[0],
1213
D3DFMT_INDEX16, &vtx[0], sizeof(S3DVertex));
1217
//!Draws an 2d rectangle with a gradient.
1218
void CD3D8Driver::draw2DRectangle(const core::rect<s32>& position,
1219
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown,
1220
SColor colorRightDown, const core::rect<s32>* clip)
1222
core::rect<s32> pos(position);
1225
pos.clipAgainst(*clip);
1231
vtx[0] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.UpperLeftCorner.Y, 0.0f,
1232
0.0f, 0.0f, 0.0f, colorLeftUp, 0.0f, 0.0f);
1233
vtx[1] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.UpperLeftCorner.Y, 0.0f,
1234
0.0f, 0.0f, 0.0f, colorRightUp, 0.0f, 1.0f);
1235
vtx[2] = S3DVertex((f32)pos.LowerRightCorner.X, (f32)pos.LowerRightCorner.Y, 0.0f,
1236
0.0f, 0.0f, 0.0f, colorRightDown, 1.0f, 0.0f);
1237
vtx[3] = S3DVertex((f32)pos.UpperLeftCorner.X, (f32)pos.LowerRightCorner.Y, 0.0f,
1238
0.0f, 0.0f, 0.0f, colorLeftDown, 1.0f, 1.0f);
1240
const s16 indices[6] = {0,1,2,0,2,3};
1242
setRenderStates2DMode(
1243
colorLeftUp.getAlpha() < 255 ||
1244
colorRightUp.getAlpha() < 255 ||
1245
colorLeftDown.getAlpha() < 255 ||
1246
colorRightDown.getAlpha() < 255, false, false);
1248
setActiveTexture(0,0);
1250
setVertexShader(EVT_STANDARD);
1252
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &indices[0],
1253
D3DFMT_INDEX16, &vtx[0], sizeof(S3DVertex));
1257
//! Draws a 2d line.
1258
void CD3D8Driver::draw2DLine(const core::position2d<s32>& start,
1259
const core::position2d<s32>& end,
1262
// thanks to Vash TheStampede who sent in his implementation
1264
vtx[0] = S3DVertex((f32)start.X, (f32)start.Y, 0.0f,
1265
0.0f, 0.0f, 0.0f, // normal
1266
color, 0.0f, 0.0f); // texture
1268
vtx[1] = S3DVertex((f32)end.X, (f32)end.Y, 0.0f,
1272
setRenderStates2DMode(color.getAlpha() < 255, false, false);
1273
setActiveTexture(0,0);
1275
setVertexShader(EVT_STANDARD);
1277
pID3DDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, &vtx[0], sizeof(S3DVertex));
1282
void CD3D8Driver::drawPixel(u32 x, u32 y, const SColor & color)
1284
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
1285
if (x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height)
1288
setRenderStates2DMode(color.getAlpha() < 255, false, false);
1289
setActiveTexture(0,0);
1291
setVertexShader(EVT_STANDARD);
1293
S3DVertex vertex((f32)x, (f32)y, 0.f, 0.f, 0.f, 0.f, color, 0.f, 0.f);
1295
pID3DDevice->DrawPrimitiveUP(D3DPT_POINTLIST, 1, &vertex, sizeof(vertex));
1299
//! sets right vertex shader
1300
void CD3D8Driver::setVertexShader(E_VERTEX_TYPE newType)
1302
// Because we don't know if a vertex shader was set in a material instead of a
1303
// fvf, this call cannot be prevented in D3D8.
1304
//if (newType != LastVertexType)
1306
LastVertexType = newType;
1312
hr = pID3DDevice->SetVertexShader(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1);
1315
hr = pID3DDevice->SetVertexShader(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX2);
1318
hr = pID3DDevice->SetVertexShader(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX3 |
1319
D3DFVF_TEXCOORDSIZE2(0) | // real texture coord
1320
D3DFVF_TEXCOORDSIZE3(1) | // misuse texture coord 2 for tangent
1321
D3DFVF_TEXCOORDSIZE3(2) // misuse texture coord 3 for binormal
1328
os::Printer::log("Could not set vertex Shader.", ELL_ERROR);
1335
//! sets the needed renderstates
1336
bool CD3D8Driver::setRenderStates3DMode()
1341
if (CurrentRenderMode != ERM_3D)
1343
// switch back the matrices
1344
pID3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)((void*)&Matrices[ETS_VIEW]));
1345
pID3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)((void*)&Matrices[ETS_WORLD]));
1346
pID3DDevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)((void*)&Matrices[ETS_PROJECTION]));
1348
pID3DDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
1350
ResetRenderStates = true;
1353
if (ResetRenderStates || LastMaterial != Material)
1355
// unset old material
1357
if (CurrentRenderMode == ERM_3D &&
1358
LastMaterial.MaterialType != Material.MaterialType &&
1359
LastMaterial.MaterialType >= 0 && LastMaterial.MaterialType < (s32)MaterialRenderers.size())
1360
MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial();
1362
// set new material.
1364
if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
1365
MaterialRenderers[Material.MaterialType].Renderer->OnSetMaterial(
1366
Material, LastMaterial, ResetRenderStates, this);
1369
bool shaderOK = true;
1371
if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
1372
shaderOK = MaterialRenderers[Material.MaterialType].Renderer->OnRender(this, LastVertexType);
1374
LastMaterial = Material;
1376
ResetRenderStates = false;
1378
CurrentRenderMode = ERM_3D;
1384
//! Map Irrlicht texture wrap mode to native values
1385
D3DTEXTUREADDRESS CD3D8Driver::getTextureWrapMode(const u8 clamp)
1390
if (Caps.TextureAddressCaps & D3DPTADDRESSCAPS_WRAP)
1391
return D3DTADDRESS_WRAP;
1393
case ETC_CLAMP_TO_EDGE:
1394
if (Caps.TextureAddressCaps & D3DPTADDRESSCAPS_CLAMP)
1395
return D3DTADDRESS_CLAMP;
1397
if (Caps.TextureAddressCaps & D3DPTADDRESSCAPS_MIRROR)
1398
return D3DTADDRESS_MIRROR;
1399
case ETC_CLAMP_TO_BORDER:
1400
if (Caps.TextureAddressCaps & D3DPTADDRESSCAPS_BORDER)
1401
return D3DTADDRESS_BORDER;
1403
return D3DTADDRESS_CLAMP;
1404
case ETC_MIRROR_CLAMP:
1405
case ETC_MIRROR_CLAMP_TO_EDGE:
1406
case ETC_MIRROR_CLAMP_TO_BORDER:
1407
if (Caps.TextureAddressCaps & D3DPTADDRESSCAPS_MIRRORONCE)
1408
return D3DTADDRESS_MIRRORONCE;
1410
return D3DTADDRESS_CLAMP;
1412
return D3DTADDRESS_WRAP;
1417
//! Can be called by an IMaterialRenderer to make its work easier.
1418
void CD3D8Driver::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
1419
bool resetAllRenderstates)
1421
if (resetAllRenderstates ||
1422
lastmaterial.AmbientColor != material.AmbientColor ||
1423
lastmaterial.DiffuseColor != material.DiffuseColor ||
1424
lastmaterial.SpecularColor != material.SpecularColor ||
1425
lastmaterial.EmissiveColor != material.EmissiveColor ||
1426
lastmaterial.Shininess != material.Shininess)
1429
mat.Diffuse = colorToD3D(material.DiffuseColor);
1430
mat.Ambient = colorToD3D(material.AmbientColor);
1431
mat.Specular = colorToD3D(material.SpecularColor);
1432
mat.Emissive = colorToD3D(material.EmissiveColor);
1433
mat.Power = material.Shininess;
1434
pID3DDevice->SetMaterial(&mat);
1437
if (lastmaterial.ColorMaterial != material.ColorMaterial)
1439
pID3DDevice->SetRenderState(D3DRS_COLORVERTEX, (material.ColorMaterial != ECM_NONE));
1440
pID3DDevice->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE,
1441
((material.ColorMaterial == ECM_DIFFUSE)||
1442
(material.ColorMaterial == ECM_DIFFUSE_AND_AMBIENT))?D3DMCS_COLOR1:D3DMCS_MATERIAL);
1443
pID3DDevice->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE,
1444
((material.ColorMaterial == ECM_AMBIENT)||
1445
(material.ColorMaterial == ECM_DIFFUSE_AND_AMBIENT))?D3DMCS_COLOR1:D3DMCS_MATERIAL);
1446
pID3DDevice->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE,
1447
(material.ColorMaterial == ECM_EMISSIVE)?D3DMCS_COLOR1:D3DMCS_MATERIAL);
1448
pID3DDevice->SetRenderState(D3DRS_SPECULARMATERIALSOURCE,
1449
(material.ColorMaterial == ECM_SPECULAR)?D3DMCS_COLOR1:D3DMCS_MATERIAL);
1453
if (resetAllRenderstates || lastmaterial.Wireframe != material.Wireframe || lastmaterial.PointCloud != material.PointCloud)
1455
if (material.Wireframe)
1456
pID3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
1458
if (material.PointCloud)
1459
pID3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_POINT);
1461
pID3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
1465
if (resetAllRenderstates || lastmaterial.GouraudShading != material.GouraudShading)
1467
if (material.GouraudShading)
1468
pID3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
1470
pID3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
1474
if (resetAllRenderstates || lastmaterial.Lighting != material.Lighting)
1476
if (material.Lighting)
1477
pID3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
1479
pID3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
1483
if (resetAllRenderstates || lastmaterial.ZBuffer != material.ZBuffer)
1485
switch (material.ZBuffer)
1488
pID3DDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
1490
case ECFN_LESSEQUAL:
1491
pID3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
1492
pID3DDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
1495
pID3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
1496
pID3DDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);
1499
pID3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
1500
pID3DDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
1503
pID3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
1504
pID3DDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_NOTEQUAL);
1506
case ECFN_GREATEREQUAL:
1507
pID3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
1508
pID3DDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_GREATEREQUAL);
1511
pID3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
1512
pID3DDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_GREATER);
1515
pID3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
1516
pID3DDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
1522
// if (resetAllRenderstates || lastmaterial.ZWriteEnable != material.ZWriteEnable)
1524
if (material.ZWriteEnable && (AllowZWriteOnTransparent || !material.isTransparent()))
1525
pID3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE);
1527
pID3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE);
1530
// back face culling
1531
if (resetAllRenderstates || (lastmaterial.FrontfaceCulling != material.FrontfaceCulling) || (lastmaterial.BackfaceCulling != material.BackfaceCulling))
1533
// if (material.FrontfaceCulling && material.BackfaceCulling)
1534
// pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW|D3DCULL_CCW);
1536
if (material.FrontfaceCulling)
1537
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
1539
if (material.BackfaceCulling)
1540
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
1542
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
1546
if (resetAllRenderstates || lastmaterial.FogEnable != material.FogEnable)
1548
pID3DDevice->SetRenderState(D3DRS_FOGENABLE, material.FogEnable);
1551
// specular highlights
1552
if (resetAllRenderstates || !core::equals(lastmaterial.Shininess, material.Shininess))
1554
bool enable = (material.Shininess!=0);
1555
pID3DDevice->SetRenderState(D3DRS_SPECULARENABLE, enable);
1556
pID3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, enable);
1557
pID3DDevice->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
1561
if (resetAllRenderstates || lastmaterial.NormalizeNormals != material.NormalizeNormals)
1563
pID3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, material.NormalizeNormals);
1567
if (queryFeature(EVDF_COLOR_MASK) &&
1568
(resetAllRenderstates || lastmaterial.ColorMask != material.ColorMask))
1571
((material.ColorMask & ECP_RED)?D3DCOLORWRITEENABLE_RED:0) |
1572
((material.ColorMask & ECP_GREEN)?D3DCOLORWRITEENABLE_GREEN:0) |
1573
((material.ColorMask & ECP_BLUE)?D3DCOLORWRITEENABLE_BLUE:0) |
1574
((material.ColorMask & ECP_ALPHA)?D3DCOLORWRITEENABLE_ALPHA:0);
1575
pID3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, flag);
1578
if (queryFeature(EVDF_BLEND_OPERATIONS) &&
1579
(resetAllRenderstates|| lastmaterial.BlendOperation != material.BlendOperation))
1581
if (material.BlendOperation==EBO_NONE)
1582
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
1585
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
1586
switch (material.BlendOperation)
1589
case EBO_MAX_FACTOR:
1591
pID3DDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_MAX);
1594
case EBO_MIN_FACTOR:
1596
pID3DDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_MIN);
1599
pID3DDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_SUBTRACT);
1601
case EBO_REVSUBTRACT:
1602
pID3DDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_REVSUBTRACT);
1605
pID3DDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
1612
if (queryFeature(EVDF_POLYGON_OFFSET) && (resetAllRenderstates ||
1613
lastmaterial.PolygonOffsetDirection != material.PolygonOffsetDirection ||
1614
lastmaterial.PolygonOffsetFactor != material.PolygonOffsetFactor))
1616
pID3DDevice->SetRenderState(D3DRS_ZBIAS, material.PolygonOffsetFactor);
1620
if (resetAllRenderstates || lastmaterial.Thickness != material.Thickness)
1622
pID3DDevice->SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&material.Thickness));
1625
// texture address mode
1626
for (u32 st=0; st<MaxTextureUnits; ++st)
1628
if (resetAllRenderstates || lastmaterial.TextureLayer[st].LODBias != material.TextureLayer[st].LODBias)
1630
const float tmp = material.TextureLayer[st].LODBias * 0.125f;
1631
pID3DDevice->SetTextureStageState(st, D3DTSS_MIPMAPLODBIAS, *(DWORD*)(&tmp));
1634
if (resetAllRenderstates || lastmaterial.TextureLayer[st].TextureWrapU != material.TextureLayer[st].TextureWrapU)
1635
pID3DDevice->SetTextureStageState(st, D3DTSS_ADDRESSU, getTextureWrapMode(material.TextureLayer[st].TextureWrapU));
1636
// If separate UV not supported reuse U for V
1637
if (!(Caps.TextureAddressCaps & D3DPTADDRESSCAPS_INDEPENDENTUV))
1638
pID3DDevice->SetTextureStageState(st, D3DTSS_ADDRESSV, getTextureWrapMode(material.TextureLayer[st].TextureWrapU));
1639
else if (resetAllRenderstates || lastmaterial.TextureLayer[st].TextureWrapV != material.TextureLayer[st].TextureWrapV)
1640
pID3DDevice->SetTextureStageState(st, D3DTSS_ADDRESSV, getTextureWrapMode(material.TextureLayer[st].TextureWrapV));
1642
// Bilinear and/or trilinear
1643
if (resetAllRenderstates ||
1644
lastmaterial.TextureLayer[st].BilinearFilter != material.TextureLayer[st].BilinearFilter ||
1645
lastmaterial.TextureLayer[st].TrilinearFilter != material.TextureLayer[st].TrilinearFilter ||
1646
lastmaterial.TextureLayer[st].AnisotropicFilter != material.TextureLayer[st].AnisotropicFilter ||
1647
lastmaterial.UseMipMaps != material.UseMipMaps)
1649
if (material.TextureLayer[st].BilinearFilter || material.TextureLayer[st].TrilinearFilter || material.TextureLayer[st].AnisotropicFilter>1)
1651
const D3DTEXTUREFILTERTYPE tftMag = ((Caps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC) &&
1652
material.TextureLayer[st].AnisotropicFilter) ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR;
1653
const D3DTEXTUREFILTERTYPE tftMin = ((Caps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC) &&
1654
material.TextureLayer[st].AnisotropicFilter) ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR;
1655
const D3DTEXTUREFILTERTYPE tftMip = material.UseMipMaps? (material.TextureLayer[st].TrilinearFilter ? D3DTEXF_LINEAR : D3DTEXF_POINT) : D3DTEXF_NONE;
1657
if (tftMag==D3DTEXF_ANISOTROPIC || tftMin == D3DTEXF_ANISOTROPIC)
1658
pID3DDevice->SetTextureStageState(st, D3DTSS_MAXANISOTROPY, core::min_((DWORD)material.TextureLayer[st].AnisotropicFilter, Caps.MaxAnisotropy));
1659
pID3DDevice->SetTextureStageState(st, D3DTSS_MAGFILTER, tftMag);
1660
pID3DDevice->SetTextureStageState(st, D3DTSS_MINFILTER, tftMin);
1661
pID3DDevice->SetTextureStageState(st, D3DTSS_MIPFILTER, tftMip);
1665
pID3DDevice->SetTextureStageState(st, D3DTSS_MINFILTER, D3DTEXF_POINT);
1666
pID3DDevice->SetTextureStageState(st, D3DTSS_MIPFILTER, D3DTEXF_NONE);
1667
pID3DDevice->SetTextureStageState(st, D3DTSS_MAGFILTER, D3DTEXF_POINT);
1674
//! sets the needed renderstates
1675
void CD3D8Driver::setRenderStatesStencilShadowMode(bool zfail)
1677
if ((CurrentRenderMode != ERM_SHADOW_VOLUME_ZFAIL &&
1678
CurrentRenderMode != ERM_SHADOW_VOLUME_ZPASS) ||
1679
Transformation3DChanged)
1681
// switch back the matrices
1682
pID3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)((void*)&Matrices[ETS_VIEW]));
1683
pID3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)((void*)&Matrices[ETS_WORLD]));
1684
pID3DDevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)((void*)&Matrices[ETS_PROJECTION]));
1686
Transformation3DChanged = false;
1688
setActiveTexture(0,0);
1689
setActiveTexture(1,0);
1690
setActiveTexture(2,0);
1691
setActiveTexture(3,0);
1693
pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);
1694
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
1695
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
1696
pID3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
1697
pID3DDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
1698
pID3DDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
1699
pID3DDevice->SetTextureStageState(3, D3DTSS_COLOROP, D3DTOP_DISABLE);
1700
pID3DDevice->SetTextureStageState(3, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
1702
pID3DDevice->SetVertexShader(D3DFVF_XYZ);
1703
LastVertexType = (video::E_VERTEX_TYPE)(-1);
1705
pID3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
1706
pID3DDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE );
1707
pID3DDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT);
1709
//pID3DDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
1710
//pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
1712
// unset last 3d material
1713
if (CurrentRenderMode == ERM_3D &&
1714
Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
1715
MaterialRenderers[Material.MaterialType].Renderer->OnUnsetMaterial();
1718
if (CurrentRenderMode != ERM_SHADOW_VOLUME_ZPASS && !zfail)
1720
// USE THE ZPASS METHOD
1722
pID3DDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS );
1723
pID3DDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP );
1724
pID3DDevice->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP );
1726
pID3DDevice->SetRenderState( D3DRS_STENCILREF, 0x1 );
1727
pID3DDevice->SetRenderState( D3DRS_STENCILMASK, 0xffffffff );
1728
pID3DDevice->SetRenderState( D3DRS_STENCILWRITEMASK, 0xffffffff );
1730
pID3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);
1731
pID3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
1732
pID3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
1735
if (CurrentRenderMode != ERM_SHADOW_VOLUME_ZFAIL && zfail)
1737
// USE THE ZFAIL METHOD
1739
pID3DDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS );
1740
pID3DDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP );
1741
pID3DDevice->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP );
1742
pID3DDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
1744
pID3DDevice->SetRenderState( D3DRS_STENCILREF, 0x0 );
1745
pID3DDevice->SetRenderState( D3DRS_STENCILMASK, 0xffffffff );
1746
pID3DDevice->SetRenderState( D3DRS_STENCILWRITEMASK, 0xffffffff );
1748
pID3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
1749
pID3DDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
1750
pID3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
1753
CurrentRenderMode = zfail ? ERM_SHADOW_VOLUME_ZFAIL : ERM_SHADOW_VOLUME_ZPASS;
1757
//! sets the needed renderstates
1758
void CD3D8Driver::setRenderStatesStencilFillMode(bool alpha)
1760
if (CurrentRenderMode != ERM_STENCIL_FILL || Transformation3DChanged)
1762
pID3DDevice->SetTransform(D3DTS_VIEW, &UnitMatrixD3D8);
1763
pID3DDevice->SetTransform(D3DTS_WORLD, &UnitMatrixD3D8);
1764
pID3DDevice->SetTransform(D3DTS_PROJECTION, &UnitMatrixD3D8);
1766
pID3DDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
1767
pID3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
1768
pID3DDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
1770
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
1771
pID3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
1772
pID3DDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
1773
pID3DDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
1774
pID3DDevice->SetTextureStageState(3, D3DTSS_COLOROP, D3DTOP_DISABLE);
1775
pID3DDevice->SetTextureStageState(3, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
1777
pID3DDevice->SetRenderState(D3DRS_STENCILREF, 0x1 );
1778
pID3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL);
1779
//pID3DDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATEREQUAL);
1780
pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
1781
pID3DDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP );
1782
pID3DDevice->SetRenderState( D3DRS_STENCILMASK, 0xffffffff );
1783
pID3DDevice->SetRenderState( D3DRS_STENCILWRITEMASK, 0xffffffff );
1785
pID3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
1787
Transformation3DChanged = false;
1791
pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
1792
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
1793
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
1794
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
1795
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
1796
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
1797
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1798
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
1802
pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
1803
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
1804
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
1805
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
1806
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
1810
CurrentRenderMode = ERM_STENCIL_FILL;
1814
//! sets the needed renderstates
1815
void CD3D8Driver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel)
1820
if (CurrentRenderMode != ERM_2D || Transformation3DChanged)
1822
// unset last 3d material
1823
if (CurrentRenderMode == ERM_3D)
1825
if (static_cast<u32>(LastMaterial.MaterialType) < MaterialRenderers.size())
1826
MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial();
1828
if (!OverrideMaterial2DEnabled)
1830
setBasicRenderStates(InitMaterial2D, LastMaterial, true);
1831
LastMaterial=InitMaterial2D;
1833
// fix everything that is wrongly set by SMaterial default
1834
pID3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
1835
pID3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
1836
pID3DDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
1837
pID3DDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
1838
pID3DDevice->SetTextureStageState(3, D3DTSS_COLOROP, D3DTOP_DISABLE);
1839
pID3DDevice->SetTextureStageState(3, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
1841
pID3DDevice->SetRenderState( D3DRS_STENCILENABLE, FALSE );
1844
pID3DDevice->SetTransform(D3DTS_WORLD, &UnitMatrixD3D8);
1846
m.setTranslation(core::vector3df(-0.5f,-0.5f,0));
1847
pID3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)((void*)m.pointer()));
1849
const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
1850
m.buildProjectionMatrixOrthoLH(f32(renderTargetSize.Width), f32(-(s32)(renderTargetSize.Height)), -1.0, 1.0);
1851
m.setTranslation(core::vector3df(-1,1,0));
1852
pID3DDevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)((void*)m.pointer()));
1854
Transformation3DChanged = false;
1856
if (OverrideMaterial2DEnabled)
1858
OverrideMaterial2D.Lighting=false;
1859
setBasicRenderStates(OverrideMaterial2D, LastMaterial, false);
1860
LastMaterial = OverrideMaterial2D;
1863
// no alphaChannel without texture
1864
alphaChannel &= texture;
1866
if (alpha || alphaChannel)
1868
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
1869
pID3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1870
pID3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1873
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
1874
pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
1875
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
1876
pID3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
1879
setTransform(ETS_TEXTURE_0, core::IdentityMatrix);
1880
// Due to the transformation change, the previous line would call a reset each frame
1881
// but we can safely reset the variable as it was false before
1882
Transformation3DChanged=false;
1886
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
1890
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
1891
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
1895
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
1901
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
1904
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
1908
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
1909
pID3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
1913
CurrentRenderMode = ERM_2D;
1917
//! deletes all dynamic lights there are
1918
void CD3D8Driver::deleteAllDynamicLights()
1920
for (s32 i=0; i<LastSetLight+1; ++i)
1921
pID3DDevice->LightEnable(i, false);
1925
CNullDriver::deleteAllDynamicLights();
1929
//! adds a dynamic light
1930
s32 CD3D8Driver::addDynamicLight(const SLight& dl)
1932
CNullDriver::addDynamicLight(dl);
1939
light.Type = D3DLIGHT_POINT;
1942
light.Type = D3DLIGHT_SPOT;
1944
case ELT_DIRECTIONAL:
1945
light.Type = D3DLIGHT_DIRECTIONAL;
1949
light.Position = *(D3DVECTOR*)((void*)(&dl.Position));
1950
light.Direction = *(D3DVECTOR*)((void*)(&dl.Direction));
1952
light.Range = core::min_(dl.Radius, MaxLightDistance);
1953
light.Falloff = dl.Falloff;
1955
light.Diffuse = *(D3DCOLORVALUE*)((void*)(&dl.DiffuseColor));
1956
light.Specular = *(D3DCOLORVALUE*)((void*)(&dl.SpecularColor));
1957
light.Ambient = *(D3DCOLORVALUE*)((void*)(&dl.AmbientColor));
1959
light.Attenuation0 = dl.Attenuation.X;
1960
light.Attenuation1 = dl.Attenuation.Y;
1961
light.Attenuation2 = dl.Attenuation.Z;
1963
light.Theta = dl.InnerCone * 2.0f * core::DEGTORAD;
1964
light.Phi = dl.OuterCone * 2.0f * core::DEGTORAD;
1968
if(D3D_OK == pID3DDevice->SetLight(LastSetLight, &light))
1970
// I don't care if this succeeds
1971
(void)pID3DDevice->LightEnable(LastSetLight, true);
1972
return LastSetLight;
1979
void CD3D8Driver::turnLightOn(s32 lightIndex, bool turnOn)
1981
if(lightIndex < 0 || lightIndex > LastSetLight)
1984
(void)pID3DDevice->LightEnable(lightIndex, turnOn);
1988
//! returns the maximal amount of dynamic lights the device can handle
1989
u32 CD3D8Driver::getMaximalDynamicLightAmount() const
1991
return Caps.MaxActiveLights;
1995
//! Sets the dynamic ambient light color. The default color is
1996
//! (0,0,0,0) which means it is dark.
1997
//! \param color: New color of the ambient light.
1998
void CD3D8Driver::setAmbientLight(const SColorf& color)
2003
AmbientLight = color;
2004
D3DCOLOR col = color.toSColor().color;
2005
pID3DDevice->SetRenderState(D3DRS_AMBIENT, col);
2009
//! \return Returns the name of the video driver. Example: In case of the DIRECT3D8
2010
//! driver, it would return "Direct3D8.1".
2011
const wchar_t* CD3D8Driver::getName() const
2013
return L"Direct3D 8.1";
2017
//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do
2018
//! this: Frist, draw all geometry. Then use this method, to draw the shadow
2019
//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.
2020
void CD3D8Driver::drawStencilShadowVolume(const core::vector3df* triangles, s32 count, bool zfail)
2022
if (!StencilBuffer || !count)
2025
setRenderStatesStencilShadowMode(zfail);
2031
// Draw front-side of shadow volume in stencil/z only
2032
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW );
2033
pID3DDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_INCRSAT);
2034
pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles, sizeof(core::vector3df));
2036
// Now reverse cull order so front sides of shadow volume are written.
2037
pID3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );
2038
pID3DDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_DECRSAT);
2039
pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles, sizeof(core::vector3df));
2045
// Draw front-side of shadow volume in stencil/z only
2046
pID3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW );
2047
pID3DDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_INCRSAT );
2048
pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles, sizeof(core::vector3df));
2050
// Now reverse cull order so front sides of shadow volume are written.
2051
pID3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
2052
pID3DDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_DECRSAT );
2053
pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, count / 3, triangles, sizeof(core::vector3df));
2058
//! Fills the stencil shadow with color. After the shadow volume has been drawn
2059
//! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this
2060
//! to draw the color of the shadow.
2061
void CD3D8Driver::drawStencilShadow(bool clearStencilBuffer, video::SColor leftUpEdge,
2062
video::SColor rightUpEdge, video::SColor leftDownEdge, video::SColor rightDownEdge)
2068
vtx[0] = S3DVertex(1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, leftUpEdge, 0.0f, 0.0f);
2069
vtx[1] = S3DVertex(1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, rightUpEdge, 0.0f, 1.0f);
2070
vtx[2] = S3DVertex(-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, leftDownEdge, 1.0f, 0.0f);
2071
vtx[3] = S3DVertex(-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, rightDownEdge, 1.0f, 1.0f);
2073
const s16 indices[6] = {0,1,2,1,3,2};
2075
setRenderStatesStencilFillMode(
2076
leftUpEdge.getAlpha() < 255 ||
2077
rightUpEdge.getAlpha() < 255 ||
2078
leftDownEdge.getAlpha() < 255 ||
2079
rightDownEdge.getAlpha() < 255);
2081
setActiveTexture(0,0);
2083
setVertexShader(EVT_STANDARD);
2085
pID3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &indices[0],
2086
D3DFMT_INDEX16, &vtx[0], sizeof(S3DVertex));
2088
if (clearStencilBuffer)
2089
pID3DDevice->Clear(0, NULL, D3DCLEAR_STENCIL,0, 1.0, 0);
2093
//! Returns the maximum amount of primitives (mostly vertices) which
2094
//! the device is able to render with one drawIndexedTriangleList
2096
u32 CD3D8Driver::getMaximalPrimitiveCount() const
2098
return Caps.MaxPrimitiveCount;
2102
//! Sets the fog mode.
2103
void CD3D8Driver::setFog(SColor color, E_FOG_TYPE fogType, f32 start,
2104
f32 end, f32 density, bool pixelFog, bool rangeFog)
2106
CNullDriver::setFog(color, fogType, start, end, density, pixelFog, rangeFog);
2111
pID3DDevice->SetRenderState(D3DRS_FOGCOLOR, color.color);
2113
pID3DDevice->SetRenderState(
2114
#if defined( _IRR_XBOX_PLATFORM_)
2117
pixelFog ? D3DRS_FOGTABLEMODE : D3DRS_FOGVERTEXMODE,
2119
(fogType==EFT_FOG_LINEAR)? D3DFOG_LINEAR : (fogType==EFT_FOG_EXP)?D3DFOG_EXP:D3DFOG_EXP2);
2121
if (fogType==EFT_FOG_LINEAR)
2123
pID3DDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD*)(&start));
2124
pID3DDevice->SetRenderState(D3DRS_FOGEND, *(DWORD*)(&end));
2127
pID3DDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD*)(&density));
2130
pID3DDevice->SetRenderState(D3DRS_RANGEFOGENABLE, rangeFog);
2134
//! Draws a 3d line.
2135
void CD3D8Driver::draw3DLine(const core::vector3df& start,
2136
const core::vector3df& end, SColor color)
2138
setVertexShader(EVT_STANDARD);
2139
setRenderStates3DMode();
2140
video::S3DVertex v[2];
2146
pID3DDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, v, sizeof(S3DVertex));
2150
void CD3D8Driver::OnResize(const core::dimension2d<u32>& size)
2155
CNullDriver::OnResize(size);
2160
//! Returns type of video driver
2161
E_DRIVER_TYPE CD3D8Driver::getDriverType() const
2163
return EDT_DIRECT3D8;
2167
//! Returns the transformation set by setTransform
2168
const core::matrix4& CD3D8Driver::getTransform(E_TRANSFORMATION_STATE state) const
2170
return Matrices[state];
2174
//! Sets a vertex shader constant.
2175
void CD3D8Driver::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
2178
pID3DDevice->SetVertexShaderConstant(startRegister, data, constantAmount);
2182
//! Sets a pixel shader constant.
2183
void CD3D8Driver::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
2186
pID3DDevice->SetPixelShaderConstant(startRegister, data, constantAmount);
2190
//! Sets a constant for the vertex shader based on a name.
2191
bool CD3D8Driver::setVertexShaderConstant(const c8* name, const f32* floats, int count)
2193
os::Printer::log("Cannot set constant, no HLSL supported in D3D8");
2198
//! Sets a constant for the pixel shader based on a name.
2199
bool CD3D8Driver::setPixelShaderConstant(const c8* name, const f32* floats, int count)
2201
os::Printer::log("Cannot set constant, no HLSL supported in D3D8");
2206
//! Adds a new material renderer to the VideoDriver, using pixel and/or
2207
//! vertex shaders to render geometry.
2208
s32 CD3D8Driver::addShaderMaterial(const c8* vertexShaderProgram,
2209
const c8* pixelShaderProgram,
2210
IShaderConstantSetCallBack* callback,
2211
E_MATERIAL_TYPE baseMaterial, s32 userData)
2214
CD3D8ShaderMaterialRenderer* r = new CD3D8ShaderMaterialRenderer(
2215
pID3DDevice, this, nr, vertexShaderProgram, pixelShaderProgram,
2216
callback, getMaterialRenderer(baseMaterial), userData);
2223
//! Returns a pointer to the IVideoDriver interface. (Implementation for
2224
//! IMaterialRendererServices)
2225
IVideoDriver* CD3D8Driver::getVideoDriver()
2231
//! Clears the ZBuffer.
2232
void CD3D8Driver::clearZBuffer()
2234
const HRESULT hr = pID3DDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER, 0, 1.0, 0);
2237
os::Printer::log("CD3D8Driver clearZBuffer() failed.", ELL_WARNING);
2241
//! Returns an image created from the last rendered frame.
2242
IImage* CD3D8Driver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target)
2244
#if defined( _IRR_XBOX_PLATFORM_)
2247
if (target != video::ERT_FRAME_BUFFER)
2250
// query the screen dimensions of the current adapter
2251
D3DDISPLAYMODE displayMode;
2252
pID3DDevice->GetDisplayMode(&displayMode);
2254
if (format==video::ECF_UNKNOWN)
2255
format=video::ECF_A8R8G8B8;
2257
// create the image surface to store the front buffer image [always A8R8G8B8]
2259
LPDIRECT3DSURFACE8 lpSurface;
2260
if (FAILED(hr = pID3DDevice->CreateImageSurface(displayMode.Width, displayMode.Height, D3DFMT_A8R8G8B8, &lpSurface)))
2263
// read the front buffer into the image surface
2264
if (FAILED(hr = pID3DDevice->GetFrontBuffer(lpSurface)))
2266
lpSurface->Release();
2276
ClientToScreen( (HWND)getExposedVideoData().D3D8.HWnd, &clientPoint );
2278
clientRect.left = clientPoint.x;
2279
clientRect.top = clientPoint.y;
2280
clientRect.right = clientRect.left + ScreenSize.Width;
2281
clientRect.bottom = clientRect.top + ScreenSize.Height;
2283
// window can be off-screen partly, we can't take screenshots from that
2284
clientRect.left = core::max_(clientRect.left, 0l);
2285
clientRect.top = core::max_(clientRect.top, 0l);
2286
clientRect.right = core::min_(clientRect.right, (long)displayMode.Width);
2287
clientRect.bottom = core::min_(clientRect.bottom, (long)displayMode.Height );
2290
// lock our area of the surface
2291
D3DLOCKED_RECT lockedRect;
2292
if (FAILED(lpSurface->LockRect(&lockedRect, &clientRect, D3DLOCK_READONLY)))
2294
lpSurface->Release();
2298
irr::core::dimension2d<u32> shotSize;
2299
shotSize.Width = core::min_( ScreenSize.Width, (u32)(clientRect.right-clientRect.left) );
2300
shotSize.Height = core::min_( ScreenSize.Height, (u32)(clientRect.bottom-clientRect.top) );
2302
// this could throw, but we aren't going to worry about that case very much
2303
IImage* newImage = createImage(format, shotSize);
2307
// d3d pads the image, so we need to copy the correct number of bytes
2308
u32* dP = (u32*)newImage->lock();
2309
u8 * sP = (u8 *)lockedRect.pBits;
2311
// If the display mode format doesn't promise anything about the Alpha value
2312
// and it appears that it's not presenting 255, then we should manually
2313
// set each pixel alpha value to 255.
2314
if(D3DFMT_X8R8G8B8 == displayMode.Format && (0xFF000000 != (*dP & 0xFF000000)))
2316
for (u32 y = 0; y < shotSize.Height; ++y)
2318
for(u32 x = 0; x < shotSize.Width; ++x)
2320
newImage->setPixel(x,y,*((u32*)sP) | 0xFF000000);
2324
sP += lockedRect.Pitch - (4 * shotSize.Width);
2329
for (u32 y = 0; y < shotSize.Height; ++y)
2331
convertColor(sP, video::ECF_A8R8G8B8, shotSize.Width, dP, format);
2332
sP += lockedRect.Pitch;
2333
dP += shotSize.Width;
2340
// we can unlock and release the surface
2341
lpSurface->UnlockRect();
2343
// release the image surface
2344
lpSurface->Release();
2346
// return status of save operation to caller
2352
// returns the current size of the screen or rendertarget
2353
const core::dimension2d<u32>& CD3D8Driver::getCurrentRenderTargetSize() const
2355
if ( CurrentRendertargetSize.Width == 0 )
2358
return CurrentRendertargetSize;
2362
// Set/unset a clipping plane.
2363
bool CD3D8Driver::setClipPlane(u32 index, const core::plane3df& plane, bool enable)
2365
#if defined( _IRR_XBOX_PLATFORM_)
2368
if (index >= MaxUserClipPlanes)
2370
pID3DDevice->SetClipPlane(index, (const float*)&plane);
2371
enableClipPlane(index, enable);
2377
// Enable/disable a clipping plane.
2378
void CD3D8Driver::enableClipPlane(u32 index, bool enable)
2380
#if defined( _IRR_XBOX_PLATFORM_)
2383
if (index >= MaxUserClipPlanes)
2386
pID3DDevice->GetRenderState(D3DRS_CLIPPLANEENABLE, &renderstate);
2388
renderstate |= (1 << index);
2390
renderstate &= ~(1 << index);
2391
pID3DDevice->SetRenderState(D3DRS_CLIPPLANEENABLE, renderstate);
2396
core::dimension2du CD3D8Driver::getMaxTextureSize() const
2398
return core::dimension2du(Caps.MaxTextureWidth, Caps.MaxTextureHeight);
2402
} // end namespace video
2403
} // end namespace irr
2405
#endif // _IRR_COMPILE_WITH_DIRECT3D_8_
2413
#ifdef _IRR_COMPILE_WITH_DIRECT3D_8_
2414
//! creates a video driver
2415
IVideoDriver* createDirectX8Driver(const SIrrlichtCreationParameters& params,
2416
io::IFileSystem* io, HWND window)
2418
const bool pureSoftware = false;
2419
CD3D8Driver* dx8 = new CD3D8Driver(params.WindowSize, window, params.Fullscreen, params.Stencilbuffer, io, pureSoftware);
2421
if (!dx8->initDriver(params.WindowSize, window, params.Bits, params.Fullscreen, pureSoftware, params.HighPrecisionFPU,
2422
params.Vsync, params.AntiAlias, params.DisplayAdapter))
2430
#endif // _IRR_COMPILE_WITH_DIRECT3D_8_
2432
} // end namespace video
2433
} // end namespace irr