gfxPCD3D9Target.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "gfx/D3D9/pc/gfxPCD3D9Target.h"
  24. #include "gfx/D3D9/gfxD3D9Device.h"
  25. #include "gfx/D3D9/gfxD3D9TextureObject.h"
  26. #include "gfx/D3D9/gfxD3D9Cubemap.h"
  27. #include "gfx/D3D9/gfxD3D9EnumTranslate.h"
  28. #include "gfx/D3D9/pc/gfxPCD3D9Device.h"
  29. #include "gfx/gfxDebugEvent.h"
  30. #include "windowManager/win32/win32Window.h"
  31. GFXPCD3D9TextureTarget::GFXPCD3D9TextureTarget()
  32. : mTargetSize( Point2I::Zero ),
  33. mTargetFormat( GFXFormatR8G8B8A8 )
  34. {
  35. for(S32 i=0; i<MaxRenderSlotId; i++)
  36. {
  37. mTargets[i] = NULL;
  38. mResolveTargets[i] = NULL;
  39. }
  40. }
  41. GFXPCD3D9TextureTarget::~GFXPCD3D9TextureTarget()
  42. {
  43. // Release anything we might be holding.
  44. for(S32 i=0; i<MaxRenderSlotId; i++)
  45. {
  46. mResolveTargets[i] = NULL;
  47. if( GFXDevice::devicePresent() )
  48. {
  49. mDevice->destroyD3DResource( mTargets[i] ); // SAFE_RELEASE
  50. mTargets[i] = NULL;
  51. }
  52. else
  53. SAFE_RELEASE( mTargets[i] );
  54. }
  55. zombify();
  56. }
  57. void GFXPCD3D9TextureTarget::attachTexture( RenderSlot slot, GFXTextureObject *tex, U32 mipLevel/*=0*/, U32 zOffset /*= 0*/ )
  58. {
  59. GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_attachTexture, ColorI::RED );
  60. AssertFatal(slot < MaxRenderSlotId, "GFXPCD3D9TextureTarget::attachTexture - out of range slot.");
  61. // TODO: The way this is implemented... you can attach a texture
  62. // object multiple times and it will release and reset it.
  63. //
  64. // We should rework this to detect when no change has occured
  65. // and skip out early.
  66. // Mark state as dirty so device can know to update.
  67. invalidateState();
  68. // Release what we had, it's definitely going to change.
  69. mDevice->destroyD3DResource( mTargets[slot] ); // SAFE_RELEASE
  70. mTargets[slot] = NULL;
  71. mResolveTargets[slot] = NULL;
  72. if(slot == Color0)
  73. {
  74. mTargetSize = Point2I::Zero;
  75. mTargetFormat = GFXFormatR8G8B8A8;
  76. }
  77. // Are we clearing?
  78. if(!tex)
  79. {
  80. // Yup - just exit, it'll stay NULL.
  81. return;
  82. }
  83. // Take care of default targets
  84. if( tex == GFXTextureTarget::sDefaultDepthStencil )
  85. {
  86. mTargets[slot] = mDevice->mDeviceDepthStencil;
  87. mTargets[slot]->AddRef();
  88. }
  89. else
  90. {
  91. // Cast the texture object to D3D...
  92. AssertFatal(dynamic_cast<GFXD3D9TextureObject*>(tex),
  93. "GFXPCD3D9TextureTarget::attachTexture - invalid texture object.");
  94. GFXD3D9TextureObject *d3dto = static_cast<GFXD3D9TextureObject*>(tex);
  95. // Grab the surface level.
  96. if( slot == DepthStencil )
  97. {
  98. mTargets[slot] = d3dto->getSurface();
  99. if ( mTargets[slot] )
  100. mTargets[slot]->AddRef();
  101. }
  102. else
  103. {
  104. // getSurface will almost always return NULL. It will only return non-NULL
  105. // if the surface that it needs to render to is different than the mip level
  106. // in the actual texture. This will happen with MSAA.
  107. if( d3dto->getSurface() == NULL )
  108. {
  109. D3D9Assert(d3dto->get2DTex()->GetSurfaceLevel(mipLevel, &mTargets[slot]),
  110. "GFXPCD3D9TextureTarget::attachTexture - could not get surface level for the passed texture!");
  111. }
  112. else
  113. {
  114. mTargets[slot] = d3dto->getSurface();
  115. mTargets[slot]->AddRef();
  116. // Only assign resolve target if d3dto has a surface to give us.
  117. //
  118. // That usually means there is an MSAA target involved, which is why
  119. // the resolve is needed to get the data out of the target.
  120. mResolveTargets[slot] = d3dto;
  121. if ( tex && slot == Color0 )
  122. {
  123. mTargetSize.set( tex->getSize().x, tex->getSize().y );
  124. mTargetFormat = tex->getFormat();
  125. }
  126. }
  127. }
  128. // Update surface size
  129. if(slot == Color0)
  130. {
  131. IDirect3DSurface9 *surface = mTargets[Color0];
  132. if ( surface )
  133. {
  134. D3DSURFACE_DESC sd;
  135. surface->GetDesc(&sd);
  136. mTargetSize = Point2I(sd.Width, sd.Height);
  137. S32 format = sd.Format;
  138. GFXREVERSE_LOOKUP( GFXD3D9TextureFormat, GFXFormat, format );
  139. mTargetFormat = (GFXFormat)format;
  140. }
  141. }
  142. }
  143. }
  144. void GFXPCD3D9TextureTarget::attachTexture( RenderSlot slot, GFXCubemap *tex, U32 face, U32 mipLevel/*=0*/ )
  145. {
  146. GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_attachTexture_Cubemap, ColorI::RED );
  147. AssertFatal(slot < MaxRenderSlotId, "GFXPCD3D9TextureTarget::attachTexture - out of range slot.");
  148. // Mark state as dirty so device can know to update.
  149. invalidateState();
  150. // Release what we had, it's definitely going to change.
  151. mDevice->destroyD3DResource( mTargets[slot] ); // SAFE_RELEASE
  152. mTargets[slot] = NULL;
  153. mResolveTargets[slot] = NULL;
  154. // Cast the texture object to D3D...
  155. AssertFatal(!tex || dynamic_cast<GFXD3D9Cubemap*>(tex),
  156. "GFXD3DTextureTarget::attachTexture - invalid cubemap object.");
  157. GFXD3D9Cubemap *cube = static_cast<GFXD3D9Cubemap*>(tex);
  158. if(slot == Color0)
  159. {
  160. mTargetSize = Point2I::Zero;
  161. mTargetFormat = GFXFormatR8G8B8A8;
  162. }
  163. // Are we clearing?
  164. if(!tex)
  165. {
  166. // Yup - just exit, it'll stay NULL.
  167. return;
  168. }
  169. D3D9Assert(cube->mCubeTex->GetCubeMapSurface( (D3DCUBEMAP_FACES)face, mipLevel, &mTargets[slot] ),
  170. "GFXD3DTextureTarget::attachTexture - could not get surface level for the passed texture!");
  171. // Update surface size
  172. if(slot == Color0)
  173. {
  174. IDirect3DSurface9 *surface = mTargets[Color0];
  175. if ( surface )
  176. {
  177. D3DSURFACE_DESC sd;
  178. surface->GetDesc(&sd);
  179. mTargetSize = Point2I(sd.Width, sd.Height);
  180. S32 format = sd.Format;
  181. GFXREVERSE_LOOKUP( GFXD3D9TextureFormat, GFXFormat, format );
  182. mTargetFormat = (GFXFormat)format;
  183. }
  184. }
  185. }
  186. void GFXPCD3D9TextureTarget::activate()
  187. {
  188. GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_activate, ColorI::RED );
  189. AssertFatal( mTargets[GFXTextureTarget::Color0],
  190. "GFXPCD3D9TextureTarget::activate() - You can never have a NULL primary render target!" );
  191. const U32 NumRenderTargets = getMin( mDevice->getNumRenderTargets(), (U32)Color4 - Color0 );
  192. LPDIRECT3DDEVICE9 d3dDevice = mDevice->getDevice();
  193. // Clear the state indicator.
  194. stateApplied();
  195. IDirect3DSurface9 *depth = mTargets[GFXTextureTarget::DepthStencil];
  196. // In debug lets do a complete test to be sure we don't
  197. // have a bad depth format for this display mode.
  198. #ifdef TORQUE_DEBUG
  199. if ( depth && mTargets[GFXTextureTarget::Color0] )
  200. {
  201. D3DSURFACE_DESC desc;
  202. D3D9Assert( mTargets[GFXTextureTarget::Color0]->GetDesc( &desc ),
  203. "GFXPCD3D9TextureTarget::activate() - Failed to get surface description!");
  204. D3DFORMAT renderFormat = desc.Format;
  205. D3D9Assert( depth->GetDesc( &desc ),
  206. "GFXPCD3D9TextureTarget::activate() - Failed to get surface description!");
  207. D3DFORMAT depthFormat = desc.Format;
  208. HRESULT hr = mDevice->getD3D()->CheckDepthStencilMatch( D3DADAPTER_DEFAULT,
  209. D3DDEVTYPE_HAL,
  210. mDevice->mDisplayMode.Format,
  211. renderFormat,
  212. depthFormat );
  213. D3D9Assert( hr, "GFXPCD3D9TextureTarget::activate() - Bad depth format for this target!" );
  214. }
  215. #endif
  216. // First clear the non-primary targets to make the debug DX runtime happy.
  217. for(U32 i = 1; i < NumRenderTargets; i++)
  218. D3D9Assert(d3dDevice->SetRenderTarget( i, NULL ),
  219. avar("GFXPCD3D9TextureTarget::activate() - failed to clear texture target %d!", i) );
  220. // Now set all the new surfaces into the appropriate slots.
  221. for(U32 i = 0; i < NumRenderTargets; i++)
  222. {
  223. IDirect3DSurface9 *target = mTargets[GFXTextureTarget::Color0 + i];
  224. if ( target )
  225. {
  226. D3D9Assert(d3dDevice->SetRenderTarget(i, target),
  227. avar("GFXPCD3D9TextureTarget::activate() - failed to set slot %d for texture target!", i) );
  228. }
  229. }
  230. // TODO: This is often the same shared depth buffer used by most
  231. // render targets. Are we getting performance hit from setting it
  232. // multiple times... aside from the function call?
  233. D3D9Assert(d3dDevice->SetDepthStencilSurface( depth ),
  234. "GFXPCD3D9TextureTarget::activate() - failed to set depthstencil target!" );
  235. }
  236. void GFXPCD3D9TextureTarget::deactivate()
  237. {
  238. // Nothing to do... the next activate() call will
  239. // set all the targets correctly.
  240. }
  241. void GFXPCD3D9TextureTarget::resolve()
  242. {
  243. GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_resolve, ColorI::RED );
  244. for (U32 i = 0; i < MaxRenderSlotId; i++)
  245. {
  246. // We use existance @ mResolveTargets as a flag that we need to copy
  247. // data from the rendertarget into the texture.
  248. if (mResolveTargets[i])
  249. {
  250. IDirect3DSurface9 *surf;
  251. D3D9Assert( mResolveTargets[i]->get2DTex()->GetSurfaceLevel( 0, &surf ),
  252. "GFXPCD3D9TextureTarget::resolve() - GetSurfaceLevel failed!" );
  253. D3D9Assert( mDevice->getDevice()->StretchRect( mTargets[i], NULL, surf, NULL, D3DTEXF_NONE ),
  254. "GFXPCD3D9TextureTarget::resolve() - StretchRect failed!" );
  255. surf->Release();
  256. }
  257. }
  258. }
  259. void GFXPCD3D9TextureTarget::resolveTo( GFXTextureObject *tex )
  260. {
  261. GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_resolveTo, ColorI::RED );
  262. if ( mTargets[Color0] == NULL )
  263. return;
  264. IDirect3DSurface9 *surf;
  265. D3D9Assert( ((GFXD3D9TextureObject*)(tex))->get2DTex()->GetSurfaceLevel( 0, &surf ),
  266. "GFXPCD3D9TextureTarget::resolveTo() - GetSurfaceLevel failed!" );
  267. D3D9Assert( mDevice->getDevice()->StretchRect( mTargets[Color0], NULL, surf, NULL, D3DTEXF_NONE ),
  268. "GFXPCD3D9TextureTarget::resolveTo() - StretchRect failed!" );
  269. surf->Release();
  270. }
  271. void GFXPCD3D9TextureTarget::zombify()
  272. {
  273. for(int i = 0; i < MaxRenderSlotId; i++)
  274. attachTexture(RenderSlot(i), NULL);
  275. }
  276. void GFXPCD3D9TextureTarget::resurrect()
  277. {
  278. }
  279. //------------------------------------------------------------------------------
  280. //------------------------------------------------------------------------------
  281. GFXPCD3D9WindowTarget::GFXPCD3D9WindowTarget()
  282. {
  283. mSwapChain = NULL;
  284. mDepthStencil = NULL;
  285. mWindow = NULL;
  286. mDevice = NULL;
  287. mBackbuffer = NULL;
  288. mImplicit = true;
  289. }
  290. GFXPCD3D9WindowTarget::~GFXPCD3D9WindowTarget()
  291. {
  292. SAFE_RELEASE(mSwapChain);
  293. SAFE_RELEASE(mDepthStencil);
  294. SAFE_RELEASE(mBackbuffer);
  295. }
  296. void GFXPCD3D9WindowTarget::initPresentationParams()
  297. {
  298. // Get some video mode related info.
  299. GFXVideoMode vm = mWindow->getVideoMode();
  300. // Do some validation...
  301. if(vm.fullScreen == true && mImplicit == false)
  302. {
  303. AssertISV(false,
  304. "GFXPCD3D9WindowTarget::initPresentationParams - Cannot go fullscreen with secondary window!");
  305. }
  306. Win32Window *win = dynamic_cast<Win32Window*>(mWindow);
  307. AssertISV(win, "GFXPCD3D9WindowTarget::initPresentationParams() - got a non Win32Window window passed in! Did DX go crossplatform?");
  308. HWND hwnd = win->getHWND();
  309. // At some point, this will become GFXPCD3D9WindowTarget like trunk has,
  310. // so this cast isn't as bad as it looks. ;) BTR
  311. GFXPCD3D9Device* pcdevice = dynamic_cast<GFXPCD3D9Device*>(mDevice);
  312. mPresentationParams = pcdevice->setupPresentParams(vm, hwnd);
  313. if (mImplicit)
  314. {
  315. pcdevice->mMultisampleType = mPresentationParams.MultiSampleType;
  316. pcdevice->mMultisampleLevel = mPresentationParams.MultiSampleQuality;
  317. }
  318. }
  319. const Point2I GFXPCD3D9WindowTarget::getSize()
  320. {
  321. return mWindow->getVideoMode().resolution;
  322. }
  323. GFXFormat GFXPCD3D9WindowTarget::getFormat()
  324. {
  325. S32 format = mPresentationParams.BackBufferFormat;
  326. GFXREVERSE_LOOKUP( GFXD3D9TextureFormat, GFXFormat, format );
  327. return (GFXFormat)format;
  328. }
  329. bool GFXPCD3D9WindowTarget::present()
  330. {
  331. AssertFatal(mSwapChain, "GFXPCD3D9WindowTarget::present - no swap chain present to present!");
  332. HRESULT res = mSwapChain->Present(NULL, NULL, NULL, NULL, NULL);
  333. return (res == S_OK);
  334. }
  335. void GFXPCD3D9WindowTarget::setImplicitSwapChain()
  336. {
  337. AssertFatal(mImplicit, "Invalid swap chain type! Additional swap chains are created as needed");
  338. // Reacquire our swapchain & DS
  339. if(!mSwapChain)
  340. mDevice->getDevice()->GetSwapChain(0, &mSwapChain);
  341. if(!mDepthStencil)
  342. mDevice->getDevice()->GetDepthStencilSurface(&mDepthStencil);
  343. if (!mBackbuffer)
  344. mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mBackbuffer);
  345. }
  346. void GFXPCD3D9WindowTarget::createAdditionalSwapChain()
  347. {
  348. AssertFatal(!mImplicit, "Invalid swap chain type! Implicit swap chains use the device");
  349. // Since we're not going to do a device reset for an additional swap
  350. // chain, we can just release our resources and regrab them.
  351. SAFE_RELEASE(mSwapChain);
  352. SAFE_RELEASE(mDepthStencil);
  353. SAFE_RELEASE(mBackbuffer);
  354. // If there's a fullscreen window active, don't try to create these additional swap chains.
  355. // CodeReview, we need to store the window target with the implicit swap chain better, this line below
  356. // could fail if the current render target isn't what we expect.
  357. GFXPCD3D9WindowTarget* currTarget = dynamic_cast<GFXPCD3D9WindowTarget*>(mDevice->getActiveRenderTarget());
  358. if (currTarget && currTarget->getWindow()->getVideoMode().fullScreen)
  359. return;
  360. // Setup our presentation params.
  361. initPresentationParams();
  362. // Create our resources!
  363. D3D9Assert(mDevice->getDevice()->CreateAdditionalSwapChain(&mPresentationParams, &mSwapChain),
  364. "GFXPCD3D9WindowTarget::createAdditionalSwapChain - couldn't reallocate additional swap chain!");
  365. D3D9Assert(mDevice->getDevice()->CreateDepthStencilSurface(mPresentationParams.BackBufferWidth, mPresentationParams.BackBufferHeight,
  366. D3DFMT_D24S8, mPresentationParams.MultiSampleType, mPresentationParams.MultiSampleQuality, false, &mDepthStencil, NULL),
  367. "GFXPCD3D9WindowTarget::createAdditionalSwapChain: Unable to create stencil/depth surface");
  368. D3D9Assert(mSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &mBackbuffer),
  369. "GFXPCD3D9WindowTarget::createAdditionalSwapChain: Unable to get backbuffer!");
  370. }
  371. void GFXPCD3D9WindowTarget::resetMode()
  372. {
  373. mWindow->setSuppressReset(true);
  374. if (mSwapChain)
  375. {
  376. // The current video settings.
  377. D3DPRESENT_PARAMETERS pp;
  378. mSwapChain->GetPresentParameters(&pp);
  379. bool ppFullscreen = !pp.Windowed;
  380. Point2I backbufferSize(pp.BackBufferWidth, pp.BackBufferHeight);
  381. // The settings we are now applying.
  382. const GFXVideoMode &mode = mWindow->getVideoMode();
  383. // Convert the current multisample parameters into something
  384. // we can compare with our GFXVideoMode.antialiasLevel value.
  385. U32 ppAntiAliaseLevel = 0;
  386. if ( pp.MultiSampleType != D3DMULTISAMPLE_NONE )
  387. ppAntiAliaseLevel = pp.MultiSampleQuality + 1;
  388. // Early out if none of the settings which require a device reset
  389. // have changed.
  390. if ( backbufferSize == getSize() &&
  391. ppFullscreen == mode.fullScreen &&
  392. ppAntiAliaseLevel == mode.antialiasLevel )
  393. return;
  394. }
  395. // So, the video mode has changed - if we're an additional swap chain
  396. // just kill the swapchain and reallocate to match new vid mode.
  397. if(mImplicit == false)
  398. {
  399. createAdditionalSwapChain();
  400. }
  401. else
  402. {
  403. // Setup our presentation params.
  404. initPresentationParams();
  405. // Otherwise, we have to reset the device, if we're the implicit swapchain.
  406. mDevice->reset(mPresentationParams);
  407. }
  408. // Update our size, too.
  409. mSize = Point2I(mPresentationParams.BackBufferWidth, mPresentationParams.BackBufferHeight);
  410. mWindow->setSuppressReset(false);
  411. }
  412. void GFXPCD3D9WindowTarget::zombify()
  413. {
  414. // Release our resources
  415. SAFE_RELEASE(mSwapChain);
  416. SAFE_RELEASE(mDepthStencil);
  417. SAFE_RELEASE(mBackbuffer);
  418. }
  419. void GFXPCD3D9WindowTarget::resurrect()
  420. {
  421. if(mImplicit)
  422. {
  423. setImplicitSwapChain();
  424. }
  425. else if(!mSwapChain)
  426. {
  427. createAdditionalSwapChain();
  428. }
  429. }
  430. void GFXPCD3D9WindowTarget::activate()
  431. {
  432. GFXDEBUGEVENT_SCOPE( GFXPCD3D9WindowTarget_activate, ColorI::RED );
  433. LPDIRECT3DDEVICE9 d3dDevice = mDevice->getDevice();
  434. // In debug lets do a complete test to be sure we don't
  435. // have a bad depth format for this display mode.
  436. #ifdef TORQUE_DEBUG
  437. if ( mDepthStencil && mBackbuffer )
  438. {
  439. D3DSURFACE_DESC desc;
  440. D3D9Assert( mBackbuffer->GetDesc( &desc ),
  441. "GFXPCD3D9TextureTarget::activate() - Failed to get surface description!");
  442. D3DFORMAT renderFormat = desc.Format;
  443. D3D9Assert( mDepthStencil->GetDesc( &desc ),
  444. "GFXPCD3D9TextureTarget::activate() - Failed to get surface description!");
  445. D3DFORMAT depthFormat = desc.Format;
  446. HRESULT hr = mDevice->getD3D()->CheckDepthStencilMatch( D3DADAPTER_DEFAULT,
  447. D3DDEVTYPE_HAL,
  448. mDevice->mDisplayMode.Format,
  449. renderFormat,
  450. depthFormat );
  451. D3D9Assert( hr, "GFXPCD3D9WindowTarget::activate() - Bad depth format for this back buffer!" );
  452. }
  453. #endif
  454. D3D9Assert( d3dDevice->SetRenderTarget( 0, mBackbuffer ),
  455. "GFXPCD3D9WindowTarget::activate() - Failed to set backbuffer target!" );
  456. D3D9Assert( d3dDevice->SetDepthStencilSurface( mDepthStencil ),
  457. "GFXPCD3D9WindowTarget::activate() - Failed to set depthstencil target!" );
  458. D3DPRESENT_PARAMETERS pp;
  459. mSwapChain->GetPresentParameters(&pp);
  460. // Update our video mode here, too.
  461. GFXVideoMode vm;
  462. vm = mWindow->getVideoMode();
  463. vm.resolution.x = pp.BackBufferWidth;
  464. vm.resolution.y = pp.BackBufferHeight;
  465. vm.fullScreen = !pp.Windowed;
  466. mSize = vm.resolution;
  467. }
  468. void GFXPCD3D9WindowTarget::resolveTo( GFXTextureObject *tex )
  469. {
  470. GFXDEBUGEVENT_SCOPE( GFXPCD3D9WindowTarget_resolveTo, ColorI::RED );
  471. IDirect3DSurface9 *surf;
  472. D3D9Assert( ((GFXD3D9TextureObject*)(tex))->get2DTex()->GetSurfaceLevel( 0, &surf ),
  473. "GFXPCD3D9WindowTarget::resolveTo() - GetSurfaceLevel failed!" );
  474. D3D9Assert( mDevice->getDevice()->StretchRect( mBackbuffer, NULL, surf, NULL, D3DTEXF_NONE ),
  475. "GFXPCD3D9WindowTarget::resolveTo() - StretchRect failed!" );
  476. surf->Release();
  477. }