// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Collections/Array.h" #include "Engine/Core/Types/DataContainer.h" #include "Engine/Graphics/Config.h" #include "Engine/Graphics/PixelFormat.h" /// /// Single texture mip map entry data. /// class FLAXENGINE_API TextureMipData { public: uint32 RowPitch; uint32 DepthPitch; uint32 Lines; BytesContainer Data; TextureMipData(); TextureMipData(const TextureMipData& other); TextureMipData(TextureMipData&& other) noexcept; TextureMipData& operator=(const TextureMipData& other); TextureMipData& operator=(TextureMipData&& other) noexcept; bool GetPixels(Array& pixels, int32 width, int32 height, PixelFormat format) const; bool GetPixels(Array& pixels, int32 width, int32 height, PixelFormat format) const; void Copy(void* data, uint32 dataRowPitch, uint32 dataDepthPitch, uint32 dataDepthSlices, uint32 targetRowPitch); template T& Get(int32 x, int32 y) { return *(T*)(Data.Get() + y * RowPitch + x * sizeof(T)); } template const T& Get(int32 x, int32 y) const { return *(const T*)(Data.Get() + y * RowPitch + x * sizeof(T)); } }; /// /// Texture data container (used to keep data downloaded from the GPU). /// class FLAXENGINE_API TextureData { public: /// /// Single entry of the texture array. Contains collection of mip maps. /// struct FLAXENGINE_API ArrayEntry { /// /// The mip maps collection. /// Array> Mips; }; public: /// /// Init /// TextureData() { } /// /// Destructor /// ~TextureData() { } public: /// /// Top level texture width (in pixels). /// int32 Width = 0; /// /// Top level texture height (in pixels). /// int32 Height = 0; /// /// Top level texture depth (in pixels). /// int32 Depth = 0; /// /// The texture data format. /// PixelFormat Format = PixelFormat::Unknown; /// /// The items collection (depth slices or array slices). /// Array> Items; public: /// /// Gather texture data /// /// Texture array index /// Mip map index /// Result data TextureMipData* GetData(int32 arrayIndex, int32 mipLevel) { return &Items[arrayIndex].Mips[mipLevel]; } /// /// Gather texture data /// /// Texture array index /// Mip map index /// Result data const TextureMipData* GetData(int32 arrayIndex, int32 mipLevel) const { return &Items[arrayIndex].Mips[mipLevel]; } /// /// Gets amount of textures in the array /// int32 GetArraySize() const { return Items.Count(); } /// /// Gets amount of mip maps in the textures /// int32 GetMipLevels() const { return Items.HasItems() ? Items[0].Mips.Count() : 0; } /// /// Clear data /// void Clear() { Items.Resize(0, false); } };