Class AsyncModelParse#

Class Documentation#

class AsyncModelParse#

Runs ObjLoader::parseCpu (or GltfLoader::parseCpu, by extension) on a worker thread.

Model loading is ~2.8 s of device-free CPU work against ~15 ms of GPU upload (measured on the bundled 27 MB model), and today all of it happens inline, so the window freezes. This moves the CPU half off the render thread; the caller polls and performs the upload itself, because that half must run on the thread owning the device.

Deliberately one parse at a time. A queue would need cancellation semantics for the common case - the user picking a third model while the second is still loading - and there is no evidence yet that anything needs more than “the newest request wins”.

Public Functions

AsyncModelParse() = default#
AsyncModelParse(const AsyncModelParse&) = delete#
AsyncModelParse &operator=(const AsyncModelParse&) = delete#
inline ~AsyncModelParse()#

Joins any running parse. The destructor must never detach: a worker writing into loader after this object dies is a use-after-free that would surface as corrupted geometry rather than a crash.

inline void start(const std::string &modelFile)#

Starts parsing modelFile. If a parse is already running this blocks until it finishes and discards its result - see the note above about newest-wins.

inline bool isRunning() const#

True between start() and the result being taken.

inline bool isFinished() const#

True once the worker has stored its result. Cheap enough to call every frame.

inline bool wasSuccessful() const#
inline std::unique_ptr<ObjLoader> takeResult()#

Joins the worker and hands over the parsed loader, leaving this object idle. Returns nullptr if nothing was started or the parse failed.

Joining here rather than in isFinished() keeps the polling path free of thread bookkeeping, and means the caller cannot accidentally read the loader while the worker still holds it.

inline bool parsedGltf() const#

True when the pending/just-finished parse was a glTF document, so the caller knows to take the glTF result rather than the OBJ one. Valid until a result is taken or a new parse starts.

inline std::unique_ptr<GltfLoader> takeGltfResult()#

The glTF analogue of takeResult(): joins and hands over the parsed GltfLoader (nullptr if the last parse was OBJ, failed, or nothing ran).

inline void waitForCompletion()#