TextureImpl.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. {
  12. /// @addtogroup opengl
  13. /// @{
  14. /// Small wrapper on top of a texture view and its aspect.
  15. struct MicroTextureView
  16. {
  17. GLuint m_glName;
  18. DepthStencilAspectBit m_aspect;
  19. };
  20. /// Texture container.
  21. class TextureImpl final : public Texture, public GlObject
  22. {
  23. public:
  24. GLenum m_target = GL_NONE; ///< GL_TEXTURE_2D, GL_TEXTURE_3D... etc.
  25. GLenum m_internalFormat = GL_NONE; ///< GL_COMPRESSED_RED, GL_RGB16 etc.
  26. GLenum m_glFormat = GL_NONE;
  27. GLenum m_glType = GL_NONE;
  28. U32 m_surfaceCountPerLevel = 0;
  29. U8 m_faceCount = 0; ///< 6 for cubes and 1 for the rest.
  30. Bool m_compressed = false;
  31. TextureImpl(GrManager* manager, CString name)
  32. : Texture(manager, name)
  33. {
  34. }
  35. ~TextureImpl();
  36. /// Init some stuff.
  37. void preInit(const TextureInitInfo& init);
  38. /// Create the texture storage.
  39. void init(const TextureInitInfo& init);
  40. /// Write texture data.
  41. void copyFromBuffer(const TextureSubresourceInfo& subresource, GLuint pbo, PtrSize offset, PtrSize dataSize) const;
  42. /// Generate mipmaps.
  43. void generateMipmaps2d(const TextureViewImpl& view) const;
  44. void bind() const;
  45. void clear(const TextureSubresourceInfo& subresource, const ClearValue& clearValue) const;
  46. U computeSurfaceIdx(const TextureSurfaceInfo& surf) const;
  47. MicroTextureView getOrCreateView(const TextureSubresourceInfo& subresource) const;
  48. TextureType computeNewTexTypeOfSubresource(const TextureSubresourceInfo& subresource) const
  49. {
  50. ANKI_ASSERT(isSubresourceValid(subresource));
  51. return (textureTypeIsCube(m_texType) && subresource.m_faceCount != 6) ? TextureType::_2D : m_texType;
  52. }
  53. private:
  54. mutable HashMap<TextureSubresourceInfo, MicroTextureView> m_viewsMap;
  55. mutable Mutex m_viewsMapMtx;
  56. };
  57. /// @}
  58. } // end namespace anki