Torque3D Documentation / _generateds / gfxD3D11TextureManager.cpp

gfxD3D11TextureManager.cpp

Engine/source/gfx/D3D11/gfxD3D11TextureManager.cpp

More...

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2015 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "gfx/D3D11/gfxD3D11Device.h"
 25#include "gfx/D3D11/gfxD3D11EnumTranslate.h"
 26#include "gfx/bitmap/bitmapUtils.h"
 27#include "gfx/bitmap/imageUtils.h"
 28#include "gfx/gfxCardProfile.h"
 29#include "gfx/gfxStringEnumTranslate.h"
 30#include "core/strings/unicode.h"
 31#include "core/util/swizzle.h"
 32#include "core/util/safeDelete.h"
 33#include "console/console.h"
 34#include "core/resourceManager.h"
 35
 36GFXD3D11TextureManager::GFXD3D11TextureManager()
 37{
 38   ZeroMemory(mCurTexSet, sizeof(mCurTexSet));
 39}
 40
 41GFXD3D11TextureManager::~GFXD3D11TextureManager()
 42{
 43   // Destroy texture table now so just in case some texture objects
 44   // are still left, we don't crash on a pure virtual method call.
 45   SAFE_DELETE_ARRAY( mHashTable );
 46}
 47
 48void GFXD3D11TextureManager::_innerCreateTexture( GFXD3D11TextureObject *retTex, 
 49                                               U32 height, 
 50                                               U32 width, 
 51                                               U32 depth,
 52                                               GFXFormat format, 
 53                                               GFXTextureProfile *profile, 
 54                                               U32 numMipLevels,
 55                                               bool forceMips,
 56                                               S32 antialiasLevel)
 57{
 58   U32 usage = 0;
 59   U32 bindFlags = 0;
 60   U32 miscFlags = 0;
 61   
 62   if(!retTex->mProfile->isZTarget() && !retTex->mProfile->isSystemMemory())
 63      bindFlags =  D3D11_BIND_SHADER_RESOURCE;
 64   
 65   U32 cpuFlags = 0;
 66
 67   retTex->mProfile = profile;
 68   retTex->isManaged = false;
 69   DXGI_FORMAT d3dTextureFormat = GFXD3D11TextureFormat[format];
 70
 71   if( retTex->mProfile->isDynamic() )
 72   {
 73      usage = D3D11_USAGE_DYNAMIC;
 74      cpuFlags |= D3D11_CPU_ACCESS_WRITE;
 75      retTex->isManaged = false;      
 76   }
 77   else if ( retTex->mProfile->isSystemMemory() )
 78   {
 79      usage |= D3D11_USAGE_STAGING;
 80      cpuFlags |= D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
 81   }
 82   else
 83   {
 84      usage = D3D11_USAGE_DEFAULT;
 85      retTex->isManaged = true;
 86   }
 87
 88   if( retTex->mProfile->isRenderTarget() )
 89   {
 90      bindFlags |= D3D11_BIND_RENDER_TARGET;
 91      //need to check to make sure this format supports render targets
 92      U32 supportFlag = 0;
 93      
 94      D3D11DEVICE->CheckFormatSupport(d3dTextureFormat, &supportFlag);
 95      //if it doesn't support render targets then default to R8G8B8A8
 96      if(!(supportFlag & D3D11_FORMAT_SUPPORT_RENDER_TARGET))
 97         d3dTextureFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
 98
 99      retTex->isManaged =false;
100   }
101
102   if( retTex->mProfile->isZTarget() )
103   {
104      bindFlags |= D3D11_BIND_DEPTH_STENCIL;
105      retTex->isManaged = false;
106   }
107
108   if( !forceMips && !retTex->mProfile->isSystemMemory() &&
109       numMipLevels == 0 &&
110       !(depth > 0) )
111   {
112      miscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
113      bindFlags |= D3D11_BIND_RENDER_TARGET; // in order to automatically generate mips. Resource needs to be a rendertarget and shader resource
114   }
115
116   if( depth > 0 )
117   {
118      D3D11_TEXTURE3D_DESC desc;
119      ZeroMemory(&desc, sizeof(D3D11_TEXTURE3D_DESC));
120
121      desc.BindFlags = bindFlags;
122      desc.CPUAccessFlags = cpuFlags;
123      desc.Depth = depth;
124      desc.Width = width;
125      desc.Height = height;
126      desc.Format = d3dTextureFormat;
127      desc.Usage = (D3D11_USAGE)usage;
128      desc.MipLevels = numMipLevels;
129
130      HRESULT hr = D3D11DEVICE->CreateTexture3D(&desc, NULL, retTex->get3DTexPtr());
131
132      if(FAILED(hr)) 
133      {
134         AssertFatal(false, "GFXD3D11TextureManager::_createTexture - failed to create volume texture!");
135      }
136
137      if (!retTex->mProfile->isSystemMemory())
138      {
139         createResourceView(height, width, depth, d3dTextureFormat, numMipLevels, bindFlags, retTex);
140      }
141
142      retTex->mTextureSize.set(width, height, depth);
143      retTex->get3DTex()->GetDesc(&desc);
144      retTex->mMipLevels = numMipLevels;
145      retTex->mFormat = format;
146   }
147   else
148   {
149      U32 numQualityLevels = 0;
150
151      switch (antialiasLevel)
152      {
153         case 0:
154         case AA_MATCH_BACKBUFFER:
155            antialiasLevel = 1;
156            break;
157
158         default:
159         {
160            antialiasLevel = 0;
161            D3D11DEVICE->CheckMultisampleQualityLevels(d3dTextureFormat, antialiasLevel, &numQualityLevels);
162            AssertFatal(numQualityLevels, "Invalid AA level!");
163            break;
164         }
165      }
166
167      if(retTex->mProfile->isZTarget())
168      {
169         D3D11_TEXTURE2D_DESC desc;
170        
171         ZeroMemory(&desc, sizeof(D3D11_TEXTURE2D_DESC));
172         desc.ArraySize = 1;
173         desc.BindFlags = bindFlags;
174         desc.CPUAccessFlags = cpuFlags;
175         //depth stencil must be a typeless format if it is bound on render target and shader resource simultaneously
176         // we'll send the real format for the creation of the views
177         desc.Format =  DXGI_FORMAT_R24G8_TYPELESS; 
178         desc.MipLevels = numMipLevels;
179         desc.SampleDesc.Count = antialiasLevel;
180         desc.SampleDesc.Quality = numQualityLevels;
181         desc.Height = height;
182         desc.Width = width;
183         desc.Usage = (D3D11_USAGE)usage;
184         HRESULT hr = D3D11DEVICE->CreateTexture2D(&desc, NULL, retTex->getSurfacePtr());
185         
186         if(FAILED(hr)) 
187         {
188            AssertFatal(false, "Failed to create Zbuffer texture");
189         }
190
191         retTex->mFormat = format; // Assigning format like this should be fine.
192      }
193      else
194      {
195         D3D11_TEXTURE2D_DESC desc;
196        
197         ZeroMemory(&desc, sizeof(D3D11_TEXTURE2D_DESC));
198         desc.ArraySize = 1;
199         desc.BindFlags = bindFlags;
200         desc.CPUAccessFlags = cpuFlags;
201         desc.Format = d3dTextureFormat;
202         desc.MipLevels = numMipLevels;
203         desc.SampleDesc.Count = antialiasLevel;
204         desc.SampleDesc.Quality = numQualityLevels;
205         desc.Height = height;
206         desc.Width = width;
207         desc.Usage = (D3D11_USAGE)usage;
208         desc.MiscFlags = miscFlags;
209         HRESULT hr = D3D11DEVICE->CreateTexture2D(&desc, NULL, retTex->get2DTexPtr());
210
211         if(FAILED(hr)) 
212         {
213            AssertFatal(false, "GFXD3D11TextureManager::_createTexture - failed to create texture!");
214         }
215
216         retTex->get2DTex()->GetDesc(&desc);
217         retTex->mMipLevels = desc.MipLevels;
218      }
219
220      // start creating the resource views...
221      // don't bother creating views for system memory/staging textures 
222      // they are just used for copying
223
224      if (!retTex->mProfile->isSystemMemory())
225      {
226         createResourceView(height, width, depth, d3dTextureFormat, numMipLevels, bindFlags, retTex);
227      }
228
229      // Get the actual size of the texture...
230      D3D11_TEXTURE2D_DESC probeDesc;
231      ZeroMemory(&probeDesc, sizeof(D3D11_TEXTURE2D_DESC));
232     
233      if( retTex->get2DTex() != NULL )
234      {
235         retTex->get2DTex()->GetDesc(&probeDesc);
236      }
237      else if( retTex->getSurface() != NULL )
238      {
239         retTex->getSurface()->GetDesc(&probeDesc);
240      }
241
242      retTex->mTextureSize.set(probeDesc.Width, probeDesc.Height, 0);
243      S32 fmt = 0;
244
245      if(!profile->isZTarget())
246         fmt = probeDesc.Format;
247      else
248         fmt = DXGI_FORMAT_D24_UNORM_S8_UINT; // we need to assign this manually.
249
250      GFXREVERSE_LOOKUP( GFXD3D11TextureFormat, GFXFormat, fmt );
251      retTex->mFormat = (GFXFormat)fmt;
252   }
253}
254
255//-----------------------------------------------------------------------------
256// createTexture
257//-----------------------------------------------------------------------------
258GFXTextureObject *GFXD3D11TextureManager::_createTextureObject( U32 height, 
259                                                               U32 width,
260                                                               U32 depth,
261                                                               GFXFormat format, 
262                                                               GFXTextureProfile *profile, 
263                                                               U32 numMipLevels,
264                                                               bool forceMips, 
265                                                               S32 antialiasLevel,
266                                                               GFXTextureObject *inTex )
267{
268   GFXD3D11TextureObject *retTex;
269   if ( inTex )
270   {
271      AssertFatal(static_cast<GFXD3D11TextureObject*>( inTex ), "GFXD3D11TextureManager::_createTexture() - Bad inTex type!");
272      retTex = static_cast<GFXD3D11TextureObject*>( inTex );
273      retTex->release();
274   }      
275   else
276   {
277      retTex = new GFXD3D11TextureObject(GFX, profile);
278      retTex->registerResourceWithDevice(GFX);
279   }
280
281   _innerCreateTexture(retTex, height, width, depth, format, profile, numMipLevels, forceMips, antialiasLevel);
282
283   return retTex;
284}
285
286bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *aTexture, GBitmap *pDL)
287{
288   PROFILE_SCOPE(GFXD3D11TextureManager_loadTexture);
289
290   GFXD3D11TextureObject *texture = static_cast<GFXD3D11TextureObject*>(aTexture);
291
292   // Check with profiler to see if we can do automatic mipmap generation.
293   const bool supportsAutoMips = GFX->getCardProfiler()->queryProfile("autoMipMapLevel", true);
294
295   // Helper bool
296   const bool isCompressedTexFmt = ImageUtil::isCompressedFormat(aTexture->mFormat);
297
298   // Settings for mipmap generation
299   U32 maxDownloadMip = pDL->getNumMipLevels();
300   U32 nbMipMapLevel  = pDL->getNumMipLevels();
301
302   if( supportsAutoMips && !isCompressedTexFmt )
303   {
304      maxDownloadMip = 1;
305      nbMipMapLevel  = aTexture->mMipLevels;
306   }
307   GFXD3D11Device* dev = D3D11;
308
309   bool isDynamic = texture->mProfile->isDynamic();
310   // Fill the texture...
311   for( U32 i = 0; i < maxDownloadMip; i++ )
312   {
313      U32 subResource = D3D11CalcSubresource(i, 0, aTexture->mMipLevels);
314
315      if(!isDynamic)
316      {
317         U8* copyBuffer = NULL;
318
319         switch(texture->mFormat)
320         {
321            case GFXFormatR8G8B8:
322            case GFXFormatR8G8B8_SRGB:
323            {
324               PROFILE_SCOPE(Swizzle24_Upload);
325
326               U8* Bits = new U8[pDL->getWidth(i) * pDL->getHeight(i) * 4];
327               dMemcpy(Bits, pDL->getBits(i), pDL->getWidth(i) * pDL->getHeight(i) * 3);
328               bitmapConvertRGB_to_RGBX(&Bits, pDL->getWidth(i) * pDL->getHeight(i));
329               copyBuffer = new U8[pDL->getWidth(i) * pDL->getHeight(i) * 4];
330               
331               dev->getDeviceSwizzle32()->ToBuffer(copyBuffer, Bits, pDL->getWidth(i) * pDL->getHeight(i) * 4);
332               dev->getDeviceContext()->UpdateSubresource(texture->get2DTex(), subResource, NULL, copyBuffer, pDL->getWidth() * 4, pDL->getHeight() *4);
333               SAFE_DELETE_ARRAY(Bits);
334               break;
335            }
336
337            case GFXFormatR8G8B8A8:
338            case GFXFormatR8G8B8X8:
339            case GFXFormatR8G8B8A8_SRGB:
340            {
341               PROFILE_SCOPE(Swizzle32_Upload);
342               copyBuffer = new U8[pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel()];
343               dev->getDeviceSwizzle32()->ToBuffer(copyBuffer, pDL->getBits(i), pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel());
344               dev->getDeviceContext()->UpdateSubresource(texture->get2DTex(), subResource, NULL, copyBuffer, pDL->getWidth() * pDL->getBytesPerPixel(), pDL->getHeight() *pDL->getBytesPerPixel());
345               break;
346            }
347
348            default:
349            {
350               // Just copy the bits in no swizzle or padding
351               PROFILE_SCOPE(SwizzleNull_Upload);
352               AssertFatal( pDL->getFormat() == texture->mFormat, "Format mismatch");
353               dev->getDeviceContext()->UpdateSubresource(texture->get2DTex(), subResource, NULL, pDL->getBits(i), pDL->getWidth() *pDL->getBytesPerPixel(), pDL->getHeight() *pDL->getBytesPerPixel());
354            }
355         }
356
357         SAFE_DELETE_ARRAY(copyBuffer);
358       }
359     
360      else
361      {
362         D3D11_MAPPED_SUBRESOURCE mapping;
363         HRESULT res =  dev->getDeviceContext()->Map(texture->get2DTex(), subResource, D3D11_MAP_WRITE, 0, &mapping);
364
365         AssertFatal(res, "tex2d map call failure");
366
367         switch( texture->mFormat )
368         {
369            case GFXFormatR8G8B8:
370            case GFXFormatR8G8B8_SRGB:
371            {
372               PROFILE_SCOPE(Swizzle24_Upload);
373
374               U8* Bits = new U8[pDL->getWidth(i) * pDL->getHeight(i) * 4];
375               dMemcpy(Bits, pDL->getBits(i), pDL->getWidth(i) * pDL->getHeight(i) * 3);
376               bitmapConvertRGB_to_RGBX(&Bits, pDL->getWidth(i) * pDL->getHeight(i));              
377
378               dev->getDeviceSwizzle32()->ToBuffer(mapping.pData, Bits, pDL->getWidth(i) * pDL->getHeight(i) * 4);
379               SAFE_DELETE_ARRAY(Bits);
380            }
381            break;
382
383            case GFXFormatR8G8B8A8:
384            case GFXFormatR8G8B8X8:
385            case GFXFormatR8G8B8A8_SRGB:
386            {
387               PROFILE_SCOPE(Swizzle32_Upload);
388               dev->getDeviceSwizzle32()->ToBuffer(mapping.pData, pDL->getBits(i), pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel());
389            }
390            break;
391
392            default:
393            {
394               // Just copy the bits in no swizzle or padding
395               PROFILE_SCOPE(SwizzleNull_Upload);
396               AssertFatal( pDL->getFormat() == texture->mFormat, "Format mismatch");
397               dMemcpy(mapping.pData, pDL->getBits(i), pDL->getWidth(i) * pDL->getHeight(i) * pDL->getBytesPerPixel());
398            }
399         }
400
401         dev->getDeviceContext()->Unmap(texture->get2DTex(), subResource);
402      }
403   }
404
405   D3D11_TEXTURE2D_DESC desc;
406   // if the texture asked for mip generation. lets generate it.
407   texture->get2DTex()->GetDesc(&desc);
408   if (desc.MiscFlags &D3D11_RESOURCE_MISC_GENERATE_MIPS)
409   {
410      dev->getDeviceContext()->GenerateMips(texture->getSRView());
411      //texture->mMipLevels = desc.MipLevels;
412   }
413
414   return true;          
415}
416
417bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *inTex, void *raw)
418{
419   PROFILE_SCOPE(GFXD3D11TextureManager_loadTextureRaw);
420
421   GFXD3D11TextureObject *texture = (GFXD3D11TextureObject *) inTex;
422   GFXD3D11Device* dev = static_cast<GFXD3D11Device *>(GFX);
423   // currently only for volume textures...
424   if(texture->getDepth() < 1) return false;
425
426   U8* Bits = NULL;
427  
428   if(texture->mFormat == GFXFormatR8G8B8 || texture->mFormat == GFXFormatR8G8B8_SRGB)
429   {
430      // convert 24 bit to 32 bit
431      Bits = new U8[texture->getWidth() * texture->getHeight() * texture->getDepth() * 4];
432      dMemcpy(Bits, raw, texture->getWidth() * texture->getHeight() * texture->getDepth() * 3);
433      bitmapConvertRGB_to_RGBX(&Bits, texture->getWidth() * texture->getHeight() * texture->getDepth());      
434   }
435
436   U32 bytesPerPix = 1;
437
438   switch(texture->mFormat)
439   {
440      case GFXFormatR8G8B8:
441      case GFXFormatR8G8B8_SRGB:
442      case GFXFormatR8G8B8A8:
443      case GFXFormatR8G8B8X8:
444      case GFXFormatR8G8B8A8_SRGB:
445         bytesPerPix = 4;
446         break;
447   }
448
449   D3D11_BOX box;
450   box.left    = 0;
451   box.right   = texture->getWidth();
452   box.front   = 0;
453   box.back    = texture->getDepth();
454   box.top     = 0;
455   box.bottom  = texture->getHeight();
456
457   if(texture->mFormat == GFXFormatR8G8B8 || texture->mFormat == GFXFormatR8G8B8_SRGB) // converted format also for volume textures
458      dev->getDeviceContext()->UpdateSubresource(texture->get3DTex(), 0, &box, Bits, texture->getWidth() * bytesPerPix, texture->getHeight() * bytesPerPix);
459   else
460      dev->getDeviceContext()->UpdateSubresource(texture->get3DTex(), 0, &box, raw, texture->getWidth() * bytesPerPix, texture->getHeight() * bytesPerPix);
461
462   SAFE_DELETE_ARRAY(Bits);
463
464   return true;
465}
466
467bool GFXD3D11TextureManager::_refreshTexture(GFXTextureObject *texture)
468{
469   U32 usedStrategies = 0;
470   GFXD3D11TextureObject *realTex = static_cast<GFXD3D11TextureObject *>(texture);
471
472   if(texture->mProfile->doStoreBitmap())
473   {
474      if(texture->mBitmap)
475         _loadTexture(texture, texture->mBitmap);
476
477      if(texture->mDDS)
478         _loadTexture(texture, texture->mDDS);
479
480      usedStrategies++;
481   }
482
483   if(texture->mProfile->isRenderTarget() || texture->mProfile->isDynamic() || texture->mProfile->isZTarget())
484   {
485      realTex->release();
486      _innerCreateTexture(realTex, texture->getHeight(), texture->getWidth(), texture->getDepth(), texture->mFormat, texture->mProfile, texture->mMipLevels, false, texture->mAntialiasLevel);
487      usedStrategies++;
488   }
489
490   AssertFatal(usedStrategies < 2, "GFXD3D11TextureManager::_refreshTexture - Inconsistent profile flags!");
491
492   return true;
493}
494
495bool GFXD3D11TextureManager::_freeTexture(GFXTextureObject *texture, bool zombify)
496{
497   AssertFatal(dynamic_cast<GFXD3D11TextureObject *>(texture),"Not an actual d3d texture object!");
498   GFXD3D11TextureObject *tex = static_cast<GFXD3D11TextureObject *>( texture );
499
500   // If it's a managed texture and we're zombifying, don't blast it, D3D allows
501   // us to keep it.
502   if(zombify && tex->isManaged)
503     return true;
504
505   tex->release();
506
507   return true;
508}
509
510/// Load a texture from a proper DDSFile instance.
511bool GFXD3D11TextureManager::_loadTexture(GFXTextureObject *aTexture, DDSFile *dds)
512{
513   PROFILE_SCOPE(GFXD3D11TextureManager_loadTextureDDS);
514
515   GFXD3D11TextureObject *texture = static_cast<GFXD3D11TextureObject*>(aTexture);
516   GFXD3D11Device* dev = static_cast<GFXD3D11Device *>(GFX);
517   // Fill the texture...
518   for( U32 i = 0; i < aTexture->mMipLevels; i++ )
519   {
520      PROFILE_SCOPE(GFXD3DTexMan_loadSurface);
521
522      AssertFatal( dds->mSurfaces.size() > 0, "Assumption failed. DDSFile has no surfaces." );
523
524      U32 subresource = D3D11CalcSubresource(i, 0, aTexture->mMipLevels);
525      dev->getDeviceContext()->UpdateSubresource(texture->get2DTex(), subresource, 0, dds->mSurfaces[0]->mMips[i], dds->getSurfacePitch(i), 0);
526   }
527
528   D3D11_TEXTURE2D_DESC desc;
529   // if the texture asked for mip generation. lets generate it.
530   texture->get2DTex()->GetDesc(&desc);
531   if (desc.MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS)
532      dev->getDeviceContext()->GenerateMips(texture->getSRView());
533
534   return true;
535}
536
537void GFXD3D11TextureManager::createResourceView(U32 height, U32 width, U32 depth, DXGI_FORMAT format, U32 numMipLevels,U32 usageFlags, GFXTextureObject *inTex)
538{
539   GFXD3D11TextureObject *tex = static_cast<GFXD3D11TextureObject*>(inTex);
540   ID3D11Resource* resource = NULL;
541   
542   if(tex->get2DTex())
543      resource = tex->get2DTex();
544   else if(tex->getSurface())
545      resource = tex->getSurface();
546   else
547      resource = tex->get3DTex();
548
549   HRESULT hr;
550   //TODO: add MSAA support later.
551   if(usageFlags & D3D11_BIND_SHADER_RESOURCE)
552   {
553      D3D11_SHADER_RESOURCE_VIEW_DESC desc;
554
555      if(usageFlags & D3D11_BIND_DEPTH_STENCIL)
556         desc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS; // reads the depth
557      else
558         desc.Format = format;
559   
560      if(depth > 0)
561      {
562         desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
563         desc.Texture3D.MipLevels = -1;
564         desc.Texture3D.MostDetailedMip = 0;
565      }
566      else
567      {
568         desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
569         desc.Texture2D.MipLevels = -1;
570         desc.Texture2D.MostDetailedMip = 0;
571      }
572      
573      hr = D3D11DEVICE->CreateShaderResourceView(resource,&desc, tex->getSRViewPtr());
574      AssertFatal(SUCCEEDED(hr), "CreateShaderResourceView:: failed to create view!");
575   }
576
577   if(usageFlags & D3D11_BIND_RENDER_TARGET)
578   {
579      D3D11_RENDER_TARGET_VIEW_DESC desc;
580      desc.Format = format;
581      desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
582      desc.Texture2D.MipSlice = 0;
583      hr = D3D11DEVICE->CreateRenderTargetView(resource, &desc, tex->getRTViewPtr());
584      AssertFatal(SUCCEEDED(hr), "CreateRenderTargetView:: failed to create view!");
585   }
586
587   if(usageFlags & D3D11_BIND_DEPTH_STENCIL)
588   {
589      D3D11_DEPTH_STENCIL_VIEW_DESC desc;
590      desc.Format = format;
591      desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
592      desc.Texture2D.MipSlice = 0;
593      desc.Flags = 0;
594      hr = D3D11DEVICE->CreateDepthStencilView(resource,&desc, tex->getDSViewPtr());
595      AssertFatal(SUCCEEDED(hr), "CreateDepthStencilView:: failed to create view!");
596   }
597}
598