Polyphase Game Engine
Loading...
Searching...
No Matches
TextureImportFixupModal.h
Go to the documentation of this file.
1#pragma once
2
3#include "Engine.h"
4
5#if EDITOR
6
7#include "AssetRef.h"
9
10#include <cstdint>
11#include <string>
12#include <vector>
13
14// Post-import scan for textures whose width or height isn't a power of two.
15// Texture::Import enqueues a row here when stbi_load returns a non-POT image;
16// Create() is deferred. The user picks Pad (next POT, transparent border),
17// Resize (previous POT via stbir bilinear), or Cancel (asset is discarded)
18// per row or in bulk. The fix is applied via Texture::FinalizeDeferredImport.
19class TextureImportFixupModal
20{
21public:
22
23 enum class FixChoice
24 {
25 None,
26 Padded,
27 Resized,
29 };
30
31 struct PendingRow
32 {
33 AssetRef mTexture; // half-imported asset (auto-cleared on unload)
34 std::string mAssetName; // captured at enqueue so the row still labels after teardown
35 std::string mSourcePath;
36 std::vector<uint8_t> mDecodedPixels; // RGBA8, srcW * srcH * 4
37 uint32_t mSrcWidth = 0;
38 uint32_t mSrcHeight = 0;
39 uint32_t mPadWidth = 0; // next POT >= srcW
40 uint32_t mPadHeight = 0;
41 uint32_t mResizeWidth = 0; // prev POT <= srcW (min 1)
42 uint32_t mResizeHeight = 0;
43 FixChoice mResolved = FixChoice::None;
44 };
45
46 static TextureImportFixupModal* Get();
47
48 // Called from Texture::Import when stbi_load returns a non-POT image.
49 // Transfers ownership of the decoded pixel buffer.
50 void Enqueue(Texture* tex,
51 const std::string& sourcePath,
52 std::vector<uint8_t>&& pixels,
53 uint32_t srcW, uint32_t srcH);
54
55 bool HasPending() const { return !mRows.empty(); }
56
57 // Returns true if `asset` was enqueued by Texture::Import and the user
58 // hasn't resolved the row yet. Callers (e.g. ActionManager) should skip
59 // any auto-save of the asset while this is true, because mPixels is empty
60 // and SaveStream would assert. The modal saves the asset itself after
61 // ApplyPad / ApplyResize finalize the pixel buffer.
62 bool IsAwaitingFixup(const Asset* asset) const;
63
64 // Wipe all queued rows without resolving them. Called from project
65 // unload paths so a stale modal doesn't carry across project switches.
66 void Reset();
67
68 // Call from EditorImguiDraw every frame.
69 void Draw();
70
71private:
72
73 TextureImportFixupModal() = default;
74
75 void ApplyPad(PendingRow& row);
76 void ApplyResize(PendingRow& row);
77 void ApplyCancel(PendingRow& row);
78
79 std::vector<PendingRow> mRows;
80 bool mModalRequested = false;
81};
82
83#endif // EDITOR
Definition AssetRef.h:18
Definition Asset.h:119
Definition Texture.h:10