Ember

Texture Creation

Apr 28th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. bool Texture::Create(Texture::Description description, Texture::Mip** mips)
  2. {
  3.     D3D11_SUBRESOURCE_DATA* textureData;
  4.     bool result;
  5.  
  6.     D3D11_TEXTURE2D_DESC textureDesc;
  7.     ZeroMemory(&textureDesc, sizeof(textureDesc));
  8.     textureDesc.Width = description.Width;
  9.     textureDesc.Height = description.Height;
  10.     textureDesc.MipLevels = description.Mips;
  11.     textureDesc.ArraySize = description.Depth;
  12.     textureDesc.Format = (DXGI_FORMAT)description.Format;
  13.     textureDesc.SampleDesc.Count = 1;
  14.     textureDesc.SampleDesc.Quality = 0;
  15.     textureDesc.Usage = (D3D11_USAGE)(D3D11_USAGE_IMMUTABLE * description.Flags & Texture::Flags::Immutable);
  16.     textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
  17.     textureDesc.CPUAccessFlags = 0;
  18.     textureDesc.MiscFlags = 0;
  19.  
  20.     textureData = new D3D11_SUBRESOURCE_DATA[description.Mips];
  21.     ZeroMemory(&textureData, sizeof(textureData));
  22.  
  23.     for(UByte i = description.Mips; i > 0; --i)
  24.     {
  25.         textureData[i].pSysMem = mips[i]->Data;
  26.         textureData[i].SysMemPitch = mips[i]->Width * 4;
  27.         textureData[i].SysMemSlicePitch = mips[i]->Height;
  28.     }
  29.  
  30.     result = Handle::Window->Device->CreateTexture2D(&textureDesc, textureData, &mTexture);
  31.  
  32.     D3D11_SHADER_RESOURCE_VIEW_DESC rvDesc;
  33.     ZeroMemory(&rvDesc, sizeof(rvDesc));
  34.     rvDesc.Format = textureDesc.Format;
  35.     rvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
  36.     rvDesc.Texture2D.MostDetailedMip = 0;
  37.     rvDesc.Texture2D.MipLevels = description.Mips;
  38.  
  39.     result = Handle::Window->Device->CreateShaderResourceView(mTexture, &rvDesc, &mTextureRV);
  40.  
  41.     delete textureData;
  42.     textureData = 0;
  43.  
  44.     return 1;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment