Files
leocad/common/lc_texturemanager.h
T
Leonardo Zide 98c67f3705 Align texture acquisition and scoped ownership
Texture lookup previously acquired references implicitly, and mesh sections and
loader requests paired raw texture pointers with manual release paths. Separate
borrowed lookup from scoped acquisition and explicit load requests/waits to match
the piece data ownership API.

Store lcTextureRef in mesh sections and loader requests, retain references on
section copies, and reset worker-shared request handles on the UI thread before
completion, cancellation, or shutdown. Keep reference primitives internal and use
scoped acquisitions for merge validation. Remove redundant section initialization
and synth-notification resets, and document the resulting ownership contracts.

Validation: macOS Debug build, diff whitespace checks, and 30 offscreen lifecycle
checks covering reference copies/moves, texture dependencies, cancellation,
shutdown, merge conflicts, and existing piece ownership paths. Successful GPU
upload/rendering is not covered by the offscreen checks.
2026-10-19 10:38:51 -07:00

50 lines
1.8 KiB
C++

#pragma once
#include "lc_texture.h"
// Creates and reuses textures, tracks their references, and prepares image data.
// The asset loader handles scheduling, OpenGL uploads, and retries.
class lcTextureManager
{
public:
lcTextureManager() = default;
~lcTextureManager();
lcTextureManager(const lcTextureManager&) = delete;
lcTextureManager(lcTextureManager&&) = delete;
lcTextureManager& operator=(const lcTextureManager&) = delete;
lcTextureManager& operator=(lcTextureManager&&) = delete;
// Deletes all managed textures, regardless of reference count.
// Stop workers and release mesh references before calling.
void Clear();
// Returns a borrowed registered texture for this source, or nullptr. No creation or acquisition.
lcTexture* FindTexture(const lcFileSource& Source);
// Returns an existing texture for this source or creates one.
// Call on the UI thread and release the returned reference when done.
// Returns nullptr for an invalid name or missing source.
lcTexture* AcquireTexture(const char* Name, const lcFileSource& Source, const QString& ProjectPath);
// Keeps a texture alive for another owner.
void AddTextureReference(lcTexture* Texture);
// Releases an owner's reference. Unloads unused textures and
// deletes temporary textures when their last reference is released.
void ReleaseTexture(lcTexture* Texture);
// Decodes and prepares image pixels for a later OpenGL upload.
// Preserves the file position. Workers must use separate file instances.
// Returns a DecodeFailed error if loading or preparation fails.
lcTextureBuildResult BuildTextureData(lcFile& File);
private:
// Reads an image from the current file position without advancing it.
// Supports memory and disk files; returns DecodeFailed on failure.
lcTextureBuildResult DecodeTextureData(lcFile& File);
QMutex mMutex;
std::vector<lcTexture*> mTextures;
};