Sharing a little bit of me

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Sharing a tiny piece of my Tool Box

      As we all know the D3DX## helper libraries have been deprecated, and I've ran into a couple of issues trying to adapt to this change.

      So far the coolest (even though not greatest) piece of code I've switch over to the new standard is some code to load a texture array into DirectX properly.

      I know most of you guys could probably figure it out in a couple of hours, but I want to save you the headache.

      Ok, so here it is...

      Note: You need the DirectX Toll Kit Lib, which you can find the source code here...

      directxtk.codeplex.com/

      Source Code

      1. static ID3D11ShaderResourceView* CreateTexture2DArray(ID3D11Device* d3dDEvice, ID3D11DeviceContext* context,
      2. const vector<wstring>& filesname)
      3. {
      4. uint textureCount = filesname.size();
      5. vector<ID3D11Texture2D*> vResources2D(textureCount);
      6. //Create a 2DTexture for each texture file
      7. for(uint i = 0; i < textureCount; ++i)
      8. {
      9. //Note: This function is in the DirectX Tool Kit Library
      10. CreateDDSTextureFromFileEx(d3dDEvice,
      11. filesname[i].c_str(),
      12. NULL,
      13. D3D11_USAGE_IMMUTABLE,//You can also use D3D11_USAGE_DEFAULT
      14. D3D11_BIND_SHADER_RESOURCE,
      15. NULL,
      16. NULL,
      17. false,
      18. reinterpret_cast<ID3D11Resource**>(&vResources2D[i]),
      19. nullptr);//Ensure the last parameter is NULL so a view to the texture is not created!
      20. }
      21. //Get the description from at least 1 of the textures since both HAVE to be the same dimension and format
      22. D3D11_TEXTURE2D_DESC vtexDesc;
      23. vResources2D[0]->GetDesc(&vtexDesc);
      24. D3D11_TEXTURE2D_DESC texDesc;
      25. texDesc.Width = vtexDesc.Width;
      26. texDesc.Height = vtexDesc.Height;
      27. texDesc.MipLevels = vtexDesc.MipLevels;
      28. texDesc.ArraySize = textureCount;
      29. texDesc.Format = vtexDesc.Format;
      30. texDesc.SampleDesc.Count = 1;
      31. texDesc.SampleDesc.Quality = 0;
      32. texDesc.Usage = D3D11_USAGE_DEFAULT;
      33. texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
      34. texDesc.CPUAccessFlags = NULL;
      35. texDesc.MiscFlags = NULL;
      36. ID3D11Texture2D* textureArray = nullptr;
      37. d3dDEvice->CreateTexture2D(&texDesc, NULL, &textureArray);
      38. //Per texture
      39. for(uint itextureIndex = 0; itextureIndex < textureCount; ++itextureIndex)
      40. {
      41. //Per MipMap level
      42. for(uint miplevel = 0; miplevel < texDesc.MipLevels; miplevel++)
      43. {
      44. context->CopySubresourceRegion(textureArray,
      45. D3D11CalcSubresource(miplevel, itextureIndex, texDesc.MipLevels),
      46. NULL,
      47. NULL,
      48. NULL,
      49. vResources2D[itextureIndex],
      50. miplevel,
      51. nullptr);
      52. }
      53. }
      54. //Release the Video Memory used per temporary textures
      55. for(uint i = 0; i < textureCount; ++i)
      56. ReleaseCOM(vResources2D[i]);
      57. //Create the view to the Texture array by filling out the Texture2DArray union from D3D11_SHADER_RESOURCE_VIEW_DESC
      58. D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
      59. srvDesc.Format = texDesc.Format;
      60. srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
      61. srvDesc.Texture2DArray.MostDetailedMip = 0;
      62. srvDesc.Texture2DArray.MipLevels = texDesc.MipLevels;
      63. srvDesc.Texture2DArray.FirstArraySlice = 0;
      64. srvDesc.Texture2DArray.ArraySize = textureCount;
      65. ID3D11ShaderResourceView* TextureSRV = nullptr;
      66. d3dDEvice->CreateShaderResourceView(textureArray, &srvDesc, &TextureSRV);
      67. ReleaseCOM(textureArray);
      68. //Remember that the pointer returned here needs to be properly release by YOUR application
      69. return TextureSRV;
      70. }
      Display All
      Intel i7 3930k
      8GB Mushkin LP @ 2133 mhz
      GTX 680
      Asus Rampage IV Extreme
      Corsair 650w

      The post was edited 2 times, last by hondero ().

    • DirectXTK and Simplemath are pretty good. I've been using them for a while now after I converted my code to use the Windows SDK.

      They're basically porting the XNA libraries to C++ and DirectX. It speeds up development quite a bit, and should replace most of the functionality that got lost from Directx10/d3dx ( like model loading etc.). There will also be support for animated models in the future.

      The programmers behind the DirectX Toolkit and Simplemath update their blogs when there are new additions:
      blogs.msdn.com/b/shawnhar/
      blogs.msdn.com/b/chuckw/

      They're also quite helpful if you have questions about the library, or possible bugs.

      The post was edited 2 times, last by Corvwyn ().