TextureImpl.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Gr/Texture.h>
  7. #include <AnKi/Gr/gl/GlObject.h>
  8. #include <AnKi/Gr/Utils/Functions.h>
  9. #include <AnKi/Util/HashMap.h>
  10. namespace anki {
  11. /// @addtogroup opengl
  12. /// @{
  13. /// Small wrapper on top of a texture view and its aspect.
  14. struct MicroTextureView
  15. {
  16. GLuint m_glName;
  17. DepthStencilAspectBit m_aspect;
  18. };
  19. /// Texture container.
  20. class TextureImpl final : public Texture, public GlObject
  21. {
  22. public:
  23. GLenum m_target = GL_NONE; ///< GL_TEXTURE_2D, GL_TEXTURE_3D... etc.
  24. GLenum m_internalFormat = GL_NONE; ///< GL_COMPRESSED_RED, GL_RGB16 etc.
  25. GLenum m_glFormat = GL_NONE;
  26. GLenum m_glType = GL_NONE;
  27. U32 m_surfaceCountPerLevel = 0;
  28. U8 m_faceCount = 0; ///< 6 for cubes and 1 for the rest.
  29. Bool m_compressed = false;
  30. TextureImpl(GrManager* manager, CString name)
  31. : Texture(manager, name)
  32. {
  33. }
  34. ~TextureImpl();
  35. /// Init some stuff.
  36. void preInit(const TextureInitInfo& init);
  37. /// Create the texture storage.
  38. void init(const TextureInitInfo& init);
  39. /// Write texture data.
  40. void copyFromBuffer(const TextureSubresourceInfo& subresource, GLuint pbo, PtrSize offset, PtrSize dataSize) const;
  41. /// Generate mipmaps.
  42. void generateMipmaps2d(const TextureViewImpl& view) const;
  43. void bind() const;
  44. void clear(const TextureSubresourceInfo& subresource, const ClearValue& clearValue) const;
  45. U computeSurfaceIdx(const TextureSurfaceInfo& surf) const;
  46. MicroTextureView getOrCreateView(const TextureSubresourceInfo& subresource) const;
  47. TextureType computeNewTexTypeOfSubresource(const TextureSubresourceInfo& subresource) const
  48. {
  49. ANKI_ASSERT(isSubresourceValid(subresource));
  50. return (textureTypeIsCube(m_texType) && subresource.m_faceCount != 6) ? TextureType::_2D : m_texType;
  51. }
  52. private:
  53. mutable HashMap<TextureSubresourceInfo, MicroTextureView> m_viewsMap;
  54. mutable Mutex m_viewsMapMtx;
  55. };
  56. /// @}
  57. } // end namespace anki