MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ExportTexture

Method ExportTexture

Source/Engine/ContentExporters/ExportTexture.cpp:12–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include "Engine/Tools/TextureTool/TextureTool.h"
11
12ExportAssetResult AssetExporters::ExportTexture(ExportAssetContext& context)
13{
14 // Prepare
15 auto asset = (TextureBase*)context.Asset.Get();
16 auto lock = asset->Storage->LockSafe();
17 auto path = GET_OUTPUT_PATH(context, "png");
18
19 // Load the top mip data
20 const int32 chunkIndex = 0;
21 if (asset->LoadChunk(chunkIndex))
22 return ExportAssetResult::CannotLoadData;
23 BytesContainer data;
24 asset->GetMipData(0, data);
25 if (data.IsInvalid())
26 return ExportAssetResult::Error;
27
28 // Peek image description
29 const auto format = asset->Format();
30 const int32 width = asset->Width();
31 const int32 height = asset->Height();
32 uint32 rowPitch, slicePitch;
33 RenderTools::ComputePitch(format, width, height, rowPitch, slicePitch);
34
35 // Setup texture data
36 TextureData textureData;
37 textureData.Width = width;
38 textureData.Height = height;
39 textureData.Depth = 1;
40 textureData.Format = format;
41 textureData.Items.Resize(1);
42 auto& item = textureData.Items[0];
43 item.Mips.Resize(1);
44 auto& mip = item.Mips[0];
45 mip.RowPitch = rowPitch;
46 mip.DepthPitch = slicePitch;
47 mip.Lines = height;
48 mip.Data.Link(data.Get(), slicePitch);
49
50 // Export to file
51 if (TextureTool::ExportTexture(path, textureData))
52 {
53 return ExportAssetResult::Error;
54 }
55
56 return ExportAssetResult::Ok;
57}
58
59ExportAssetResult AssetExporters::ExportCubeTexture(ExportAssetContext& context)
60{

Callers

nothing calls this directly

Calls 8

LockSafeMethod · 0.80
LoadChunkMethod · 0.80
GetMipDataMethod · 0.80
FormatMethod · 0.80
GetMethod · 0.45
IsInvalidMethod · 0.45
ResizeMethod · 0.45
LinkMethod · 0.45

Tested by

no test coverage detected