D3D9TextureCube.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../../Precompiled.h"
  23. #include "../../Core/Context.h"
  24. #include "../../Core/Profiler.h"
  25. #include "../../Graphics/Graphics.h"
  26. #include "../../Graphics/GraphicsEvents.h"
  27. #include "../../Graphics/GraphicsImpl.h"
  28. #include "../../Graphics/Renderer.h"
  29. #include "../../Graphics/TextureCube.h"
  30. #include "../../IO/FileSystem.h"
  31. #include "../../IO/Log.h"
  32. #include "../../Resource/ResourceCache.h"
  33. #include "../../Resource/XMLFile.h"
  34. #include "../../DebugNew.h"
  35. #ifdef _MSC_VER
  36. #pragma warning(disable:4355)
  37. #endif
  38. namespace Atomic
  39. {
  40. void TextureCube::OnDeviceLost()
  41. {
  42. if (usage_ > TEXTURE_STATIC)
  43. Release();
  44. }
  45. void TextureCube::OnDeviceReset()
  46. {
  47. if (usage_ > TEXTURE_STATIC || !object_.ptr_ || dataPending_)
  48. {
  49. // If has a resource file, reload through the resource cache. Otherwise just recreate.
  50. ResourceCache* cache = GetSubsystem<ResourceCache>();
  51. if (cache->Exists(GetName()))
  52. dataLost_ = !cache->ReloadResource(this);
  53. if (!object_.ptr_)
  54. {
  55. Create();
  56. dataLost_ = true;
  57. }
  58. }
  59. dataPending_ = false;
  60. }
  61. void TextureCube::Release()
  62. {
  63. if (graphics_)
  64. {
  65. for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
  66. {
  67. if (graphics_->GetTexture(i) == this)
  68. graphics_->SetTexture(i, 0);
  69. }
  70. }
  71. for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
  72. {
  73. if (renderSurfaces_[i])
  74. renderSurfaces_[i]->Release();
  75. }
  76. ATOMIC_SAFE_RELEASE(object_.ptr_);
  77. resolveDirty_ = false;
  78. levelsDirty_ = false;
  79. }
  80. bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int width, int height, const void* data)
  81. {
  82. ATOMIC_PROFILE(SetTextureData);
  83. if (!object_.ptr_)
  84. {
  85. ATOMIC_LOGERROR("No texture created, can not set data");
  86. return false;
  87. }
  88. if (!data)
  89. {
  90. ATOMIC_LOGERROR("Null source for setting data");
  91. return false;
  92. }
  93. if (level >= levels_)
  94. {
  95. ATOMIC_LOGERROR("Illegal mip level for setting data");
  96. return false;
  97. }
  98. if (graphics_->IsDeviceLost())
  99. {
  100. ATOMIC_LOGWARNING("Texture data assignment while device is lost");
  101. dataPending_ = true;
  102. return true;
  103. }
  104. if (IsCompressed())
  105. {
  106. x &= ~3;
  107. y &= ~3;
  108. }
  109. int levelWidth = GetLevelWidth(level);
  110. int levelHeight = GetLevelHeight(level);
  111. if (x < 0 || x + width > levelWidth || y < 0 || y + height > levelHeight || width <= 0 || height <= 0)
  112. {
  113. ATOMIC_LOGERROR("Illegal dimensions for setting data");
  114. return false;
  115. }
  116. D3DLOCKED_RECT d3dLockedRect;
  117. RECT d3dRect;
  118. d3dRect.left = x;
  119. d3dRect.top = y;
  120. d3dRect.right = x + width;
  121. d3dRect.bottom = y + height;
  122. DWORD flags = 0;
  123. if (level == 0 && x == 0 && y == 0 && width == levelWidth && height == levelHeight && usage_ > TEXTURE_STATIC)
  124. flags |= D3DLOCK_DISCARD;
  125. HRESULT hr = ((IDirect3DCubeTexture9*)object_.ptr_)->LockRect((D3DCUBEMAP_FACES)face, level, &d3dLockedRect,
  126. (flags & D3DLOCK_DISCARD) ? 0 : &d3dRect, flags);
  127. if (FAILED(hr))
  128. {
  129. ATOMIC_LOGD3DERROR("Could not lock texture", hr);
  130. return false;
  131. }
  132. if (IsCompressed())
  133. {
  134. height = (height + 3) >> 2;
  135. y >>= 2;
  136. }
  137. unsigned char* src = (unsigned char*)data;
  138. unsigned rowSize = GetRowDataSize(width);
  139. // GetRowDataSize() returns CPU-side (source) data size, so need to convert for X8R8G8B8
  140. if (format_ == D3DFMT_X8R8G8B8)
  141. rowSize = rowSize / 3 * 4;
  142. // Perform conversion from RGB / RGBA as necessary
  143. switch (format_)
  144. {
  145. default:
  146. for (int i = 0; i < height; ++i)
  147. {
  148. unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
  149. memcpy(dest, src, rowSize);
  150. src += rowSize;
  151. }
  152. break;
  153. case D3DFMT_X8R8G8B8:
  154. for (int i = 0; i < height; ++i)
  155. {
  156. unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
  157. for (int j = 0; j < width; ++j)
  158. {
  159. *dest++ = src[2];
  160. *dest++ = src[1];
  161. *dest++ = src[0];
  162. *dest++ = 255;
  163. src += 3;
  164. }
  165. }
  166. break;
  167. case D3DFMT_A8R8G8B8:
  168. for (int i = 0; i < height; ++i)
  169. {
  170. unsigned char* dest = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
  171. for (int j = 0; j < width; ++j)
  172. {
  173. *dest++ = src[2];
  174. *dest++ = src[1];
  175. *dest++ = src[0];
  176. *dest++ = src[3];
  177. src += 4;
  178. }
  179. }
  180. break;
  181. }
  182. ((IDirect3DCubeTexture9*)object_.ptr_)->UnlockRect((D3DCUBEMAP_FACES)face, level);
  183. return true;
  184. }
  185. bool TextureCube::SetData(CubeMapFace face, Deserializer& source)
  186. {
  187. SharedPtr<Image> image(new Image(context_));
  188. if (!image->Load(source))
  189. return false;
  190. return SetData(face, image);
  191. }
  192. bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
  193. {
  194. if (!image)
  195. {
  196. ATOMIC_LOGERROR("Null image, can not load texture");
  197. return false;
  198. }
  199. // Use a shared ptr for managing the temporary mip images created during this function
  200. SharedPtr<Image> mipImage;
  201. unsigned memoryUse = 0;
  202. int quality = QUALITY_HIGH;
  203. Renderer* renderer = GetSubsystem<Renderer>();
  204. if (renderer)
  205. quality = renderer->GetTextureQuality();
  206. if (!image->IsCompressed())
  207. {
  208. unsigned char* levelData = image->GetData();
  209. int levelWidth = image->GetWidth();
  210. int levelHeight = image->GetHeight();
  211. unsigned components = image->GetComponents();
  212. unsigned format = 0;
  213. if (levelWidth != levelHeight)
  214. {
  215. ATOMIC_LOGERROR("Cube texture width not equal to height");
  216. return false;
  217. }
  218. // Discard unnecessary mip levels
  219. for (unsigned i = 0; i < mipsToSkip_[quality]; ++i)
  220. {
  221. mipImage = image->GetNextLevel(); image = mipImage;
  222. levelData = image->GetData();
  223. levelWidth = image->GetWidth();
  224. levelHeight = image->GetHeight();
  225. }
  226. switch (components)
  227. {
  228. case 1:
  229. format = useAlpha ? Graphics::GetAlphaFormat() : Graphics::GetLuminanceFormat();
  230. break;
  231. case 2:
  232. format = Graphics::GetLuminanceAlphaFormat();
  233. break;
  234. case 3:
  235. format = Graphics::GetRGBFormat();
  236. break;
  237. case 4:
  238. format = Graphics::GetRGBAFormat();
  239. break;
  240. default:
  241. assert(false); // Should never reach here
  242. break;
  243. }
  244. // Create the texture when face 0 is being loaded, check that rest of the faces are same size & format
  245. if (!face)
  246. {
  247. // If image was previously compressed, reset number of requested levels to avoid error if level count is too high for new size
  248. if (IsCompressed() && requestedLevels_ > 1)
  249. requestedLevels_ = 0;
  250. SetSize(levelWidth, format);
  251. }
  252. else
  253. {
  254. if (!object_.ptr_)
  255. {
  256. ATOMIC_LOGERROR("Cube texture face 0 must be loaded first");
  257. return false;
  258. }
  259. if (levelWidth != width_ || format != format_)
  260. {
  261. ATOMIC_LOGERROR("Cube texture face does not match size or format of face 0");
  262. return false;
  263. }
  264. }
  265. for (unsigned i = 0; i < levels_; ++i)
  266. {
  267. SetData(face, i, 0, 0, levelWidth, levelHeight, levelData);
  268. memoryUse += levelWidth * levelHeight * components;
  269. if (i < levels_ - 1)
  270. {
  271. mipImage = image->GetNextLevel(); image = mipImage;
  272. levelData = image->GetData();
  273. levelWidth = image->GetWidth();
  274. levelHeight = image->GetHeight();
  275. }
  276. }
  277. }
  278. else
  279. {
  280. int width = image->GetWidth();
  281. int height = image->GetHeight();
  282. unsigned levels = image->GetNumCompressedLevels();
  283. unsigned format = graphics_->GetFormat(image->GetCompressedFormat());
  284. bool needDecompress = false;
  285. if (width != height)
  286. {
  287. ATOMIC_LOGERROR("Cube texture width not equal to height");
  288. return false;
  289. }
  290. if (!format)
  291. {
  292. format = Graphics::GetRGBAFormat();
  293. needDecompress = true;
  294. }
  295. unsigned mipsToSkip = mipsToSkip_[quality];
  296. if (mipsToSkip >= levels)
  297. mipsToSkip = levels - 1;
  298. while (mipsToSkip && (width / (1 << mipsToSkip) < 4 || height / (1 << mipsToSkip) < 4))
  299. --mipsToSkip;
  300. width /= (1 << mipsToSkip);
  301. height /= (1 << mipsToSkip);
  302. // Create the texture when face 0 is being loaded, assume rest of the faces are same size & format
  303. if (!face)
  304. {
  305. SetNumLevels(Max((levels - mipsToSkip), 1U));
  306. SetSize(width, format);
  307. }
  308. else
  309. {
  310. if (!object_.ptr_)
  311. {
  312. ATOMIC_LOGERROR("Cube texture face 0 must be loaded first");
  313. return false;
  314. }
  315. if (width != width_ || format != format_)
  316. {
  317. ATOMIC_LOGERROR("Cube texture face does not match size or format of face 0");
  318. return false;
  319. }
  320. }
  321. for (unsigned i = 0; i < levels_ && i < levels - mipsToSkip; ++i)
  322. {
  323. CompressedLevel level = image->GetCompressedLevel(i + mipsToSkip);
  324. if (!needDecompress)
  325. {
  326. SetData(face, i, 0, 0, level.width_, level.height_, level.data_);
  327. memoryUse += level.rows_ * level.rowSize_;
  328. }
  329. else
  330. {
  331. unsigned char* rgbaData = new unsigned char[level.width_ * level.height_ * 4];
  332. level.Decompress(rgbaData);
  333. SetData(face, i, 0, 0, level.width_, level.height_, rgbaData);
  334. memoryUse += level.width_ * level.height_ * 4;
  335. delete[] rgbaData;
  336. }
  337. }
  338. }
  339. faceMemoryUse_[face] = memoryUse;
  340. unsigned totalMemoryUse = sizeof(TextureCube);
  341. for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
  342. totalMemoryUse += faceMemoryUse_[i];
  343. SetMemoryUse(totalMemoryUse);
  344. return true;
  345. }
  346. bool TextureCube::GetData(CubeMapFace face, unsigned level, void* dest) const
  347. {
  348. if (!object_.ptr_)
  349. {
  350. ATOMIC_LOGERROR("No texture created, can not get data");
  351. return false;
  352. }
  353. if (!dest)
  354. {
  355. ATOMIC_LOGERROR("Null destination for getting data");
  356. return false;
  357. }
  358. if (level >= levels_)
  359. {
  360. ATOMIC_LOGERROR("Illegal mip level for getting data");
  361. return false;
  362. }
  363. if (graphics_->IsDeviceLost())
  364. {
  365. ATOMIC_LOGWARNING("Getting texture data while device is lost");
  366. return false;
  367. }
  368. if (resolveDirty_)
  369. graphics_->ResolveToTexture(const_cast<TextureCube*>(this));
  370. int levelWidth = GetLevelWidth(level);
  371. int levelHeight = GetLevelHeight(level);
  372. D3DLOCKED_RECT d3dLockedRect;
  373. RECT d3dRect;
  374. d3dRect.left = 0;
  375. d3dRect.top = 0;
  376. d3dRect.right = levelWidth;
  377. d3dRect.bottom = levelHeight;
  378. IDirect3DSurface9* offscreenSurface = 0;
  379. // Need to use a offscreen surface & GetRenderTargetData() for rendertargets
  380. if (renderSurfaces_[face])
  381. {
  382. if (level != 0)
  383. {
  384. ATOMIC_LOGERROR("Can only get mip level 0 data from a rendertarget");
  385. return false;
  386. }
  387. // If multisampled, must copy the surface of the resolve texture instead of the multisampled surface
  388. IDirect3DSurface9* resolveSurface = 0;
  389. if (multiSample_ > 1)
  390. {
  391. HRESULT hr = ((IDirect3DCubeTexture9*)object_.ptr_)->GetCubeMapSurface((D3DCUBEMAP_FACES)face, 0,
  392. (IDirect3DSurface9**)&resolveSurface);
  393. if (FAILED(hr))
  394. {
  395. ATOMIC_LOGD3DERROR("Could not get surface of the resolve texture", hr);
  396. ATOMIC_SAFE_RELEASE(resolveSurface);
  397. return false;
  398. }
  399. }
  400. IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
  401. HRESULT hr = device->CreateOffscreenPlainSurface((UINT)width_, (UINT)height_, (D3DFORMAT)format_, D3DPOOL_SYSTEMMEM, &offscreenSurface, 0);
  402. if (FAILED(hr))
  403. {
  404. ATOMIC_LOGD3DERROR("Could not create surface for getting rendertarget data", hr);
  405. ATOMIC_SAFE_RELEASE(offscreenSurface);
  406. ATOMIC_SAFE_RELEASE(resolveSurface);
  407. return false;
  408. }
  409. if (resolveSurface)
  410. hr = device->GetRenderTargetData(resolveSurface, offscreenSurface);
  411. else
  412. hr = device->GetRenderTargetData((IDirect3DSurface9*)renderSurfaces_[face]->GetSurface(), offscreenSurface);
  413. ATOMIC_SAFE_RELEASE(resolveSurface);
  414. if (FAILED(hr))
  415. {
  416. ATOMIC_LOGD3DERROR("Could not get rendertarget data", hr);
  417. ATOMIC_SAFE_RELEASE(offscreenSurface);
  418. return false;
  419. }
  420. if (FAILED(offscreenSurface->LockRect(&d3dLockedRect, &d3dRect, D3DLOCK_READONLY)))
  421. {
  422. ATOMIC_LOGD3DERROR("Could not lock surface for getting rendertarget data", hr);
  423. ATOMIC_SAFE_RELEASE(offscreenSurface);
  424. return false;
  425. }
  426. }
  427. else
  428. {
  429. HRESULT hr = ((IDirect3DCubeTexture9*)object_.ptr_)->LockRect((D3DCUBEMAP_FACES)face, level, &d3dLockedRect, &d3dRect, D3DLOCK_READONLY);
  430. if (FAILED(hr))
  431. {
  432. ATOMIC_LOGD3DERROR("Could not lock texture", hr);
  433. return false;
  434. }
  435. }
  436. int height = levelHeight;
  437. if (IsCompressed())
  438. height = (height + 3) >> 2;
  439. unsigned char* destPtr = (unsigned char*)dest;
  440. unsigned rowSize = GetRowDataSize(levelWidth);
  441. // GetRowDataSize() returns CPU-side (destination) data size, so need to convert for X8R8G8B8
  442. if (format_ == D3DFMT_X8R8G8B8)
  443. rowSize = rowSize / 3 * 4;
  444. // Perform conversion to RGB / RGBA as necessary
  445. switch (format_)
  446. {
  447. default:
  448. for (int i = 0; i < height; ++i)
  449. {
  450. unsigned char* src = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
  451. memcpy(destPtr, src, rowSize);
  452. destPtr += rowSize;
  453. }
  454. break;
  455. case D3DFMT_X8R8G8B8:
  456. for (int i = 0; i < height; ++i)
  457. {
  458. unsigned char* src = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
  459. for (int j = 0; j < levelWidth; ++j)
  460. {
  461. destPtr[2] = *src++;
  462. destPtr[1] = *src++;
  463. destPtr[0] = *src++;
  464. ++src;
  465. destPtr += 3;
  466. }
  467. }
  468. break;
  469. case D3DFMT_A8R8G8B8:
  470. for (int i = 0; i < height; ++i)
  471. {
  472. unsigned char* src = (unsigned char*)d3dLockedRect.pBits + i * d3dLockedRect.Pitch;
  473. for (int j = 0; j < levelWidth; ++j)
  474. {
  475. destPtr[2] = *src++;
  476. destPtr[1] = *src++;
  477. destPtr[0] = *src++;
  478. destPtr[3] = *src++;
  479. destPtr += 4;
  480. }
  481. }
  482. break;
  483. }
  484. if (offscreenSurface)
  485. offscreenSurface->UnlockRect();
  486. else
  487. ((IDirect3DCubeTexture9*)object_.ptr_)->UnlockRect((D3DCUBEMAP_FACES)face, level);
  488. ATOMIC_SAFE_RELEASE(offscreenSurface);
  489. return true;
  490. }
  491. bool TextureCube::Create()
  492. {
  493. Release();
  494. if (!graphics_ || !width_ || !height_)
  495. return false;
  496. if (graphics_->IsDeviceLost())
  497. {
  498. ATOMIC_LOGWARNING("Texture creation while device is lost");
  499. return true;
  500. }
  501. GraphicsImpl* impl = graphics_->GetImpl();
  502. unsigned pool = usage_ > TEXTURE_STATIC ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
  503. unsigned d3dUsage = 0;
  504. switch (usage_)
  505. {
  506. case TEXTURE_DYNAMIC:
  507. d3dUsage |= D3DUSAGE_DYNAMIC;
  508. break;
  509. case TEXTURE_RENDERTARGET:
  510. d3dUsage |= D3DUSAGE_RENDERTARGET;
  511. if (requestedLevels_ != 1)
  512. {
  513. // Check mipmap autogeneration support
  514. if (impl->CheckFormatSupport((D3DFORMAT)format_, D3DUSAGE_AUTOGENMIPMAP, D3DRTYPE_TEXTURE))
  515. {
  516. requestedLevels_ = 0;
  517. d3dUsage |= D3DUSAGE_AUTOGENMIPMAP;
  518. }
  519. else
  520. requestedLevels_ = 1;
  521. }
  522. break;
  523. default:
  524. break;
  525. }
  526. if (multiSample_ > 1)
  527. {
  528. // Fall back to non-multisampled if unsupported multisampling mode
  529. GraphicsImpl* impl = graphics_->GetImpl();
  530. if (!impl->CheckMultiSampleSupport((D3DFORMAT)format_, multiSample_))
  531. {
  532. multiSample_ = 1;
  533. autoResolve_ = false;
  534. }
  535. }
  536. IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
  537. HRESULT hr = device->CreateCubeTexture(
  538. (UINT)width_,
  539. requestedLevels_,
  540. d3dUsage,
  541. (D3DFORMAT)format_,
  542. (D3DPOOL)pool,
  543. (IDirect3DCubeTexture9**)&object_.ptr_,
  544. 0);
  545. if (FAILED(hr))
  546. {
  547. ATOMIC_LOGD3DERROR("Could not create cube texture", hr);
  548. ATOMIC_SAFE_RELEASE(object_.ptr_);
  549. return false;
  550. }
  551. levels_ = ((IDirect3DCubeTexture9*)object_.ptr_)->GetLevelCount();
  552. if (usage_ == TEXTURE_RENDERTARGET)
  553. {
  554. for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
  555. {
  556. if (multiSample_ > 1)
  557. {
  558. // Create the multisampled face rendertarget if necessary
  559. HRESULT hr = device->CreateRenderTarget(
  560. (UINT)width_,
  561. (UINT)height_,
  562. (D3DFORMAT)format_,
  563. (D3DMULTISAMPLE_TYPE)multiSample_,
  564. 0,
  565. FALSE,
  566. (IDirect3DSurface9**)&renderSurfaces_[i]->surface_,
  567. 0);
  568. if (FAILED(hr))
  569. {
  570. ATOMIC_LOGD3DERROR("Could not create multisampled rendertarget surface", hr);
  571. ATOMIC_SAFE_RELEASE(renderSurfaces_[i]->surface_);
  572. return false;
  573. }
  574. }
  575. else
  576. {
  577. hr = ((IDirect3DCubeTexture9*)object_.ptr_)->GetCubeMapSurface((D3DCUBEMAP_FACES)i, 0,
  578. (IDirect3DSurface9**)&renderSurfaces_[i]->surface_);
  579. if (FAILED(hr))
  580. {
  581. ATOMIC_LOGD3DERROR("Could not get rendertarget surface", hr);
  582. ATOMIC_SAFE_RELEASE(renderSurfaces_[i]->surface_);
  583. return false;
  584. }
  585. }
  586. }
  587. }
  588. return true;
  589. }
  590. }