TextureViewImpl.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <anki/gr/vulkan/TextureViewImpl.h>
  6. #include <anki/gr/vulkan/TextureImpl.h>
  7. namespace anki
  8. {
  9. TextureViewImpl::~TextureViewImpl()
  10. {
  11. }
  12. Error TextureViewImpl::init(const TextureViewInitInfo& inf)
  13. {
  14. ANKI_ASSERT(inf.isValid());
  15. // Store some stuff
  16. m_aspect = inf.m_depthStencilAspect;
  17. m_baseMip = inf.m_baseMipmap;
  18. m_mipCount = inf.m_mipmapCount;
  19. m_baseLayer = inf.m_baseLayer;
  20. m_layerCount = inf.m_layerCount;
  21. m_baseFace = inf.m_baseFace;
  22. m_faceCount = inf.m_faceCount;
  23. // TODO Set m_texType
  24. m_tex = inf.m_texture;
  25. const TextureImpl& tex = static_cast<const TextureImpl&>(*m_tex);
  26. // Compute the VK range
  27. VkImageSubresourceRange range;
  28. range.aspectMask = convertImageAspect(m_aspect & tex.m_aspect);
  29. range.baseMipLevel = m_baseMip;
  30. range.levelCount = m_mipCount;
  31. const TextureType type = tex.getTextureType();
  32. const U32 faceCount = textureTypeIsCube(type) ? 6 : 1;
  33. range.baseArrayLayer = m_baseLayer * faceCount + m_baseFace;
  34. range.layerCount = m_layerCount * m_faceCount;
  35. // Ask the texture for a view
  36. m_handle = tex.getOrCreateView(range);
  37. // Create the hash
  38. Array<U64, 2> toHash = {{tex.getUuid(), ptrToNumber(m_handle)}};
  39. m_hash = computeHash(&toHash[0], sizeof(toHash));
  40. return Error::NONE;
  41. }
  42. } // end namespace anki