gfxPCD3D9Target.cpp 20 KB

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