Class AsyncTextureLoader


#include <Source/Falcor/Utils/AsyncTextureLoader.h>

class dlldecl AsyncTextureLoader


Utility class to load textures asynchronously using multiple worker threads.


loadFromFileRequest loading a texture.


Lines 36-78 in Source/Falcor/Utils/AsyncTextureLoader.h.

class dlldecl AsyncTextureLoader
    /** Constructor.
        \param[in] threadCount Number of worker threads.
    AsyncTextureLoader(size_t threadCount = std::thread::hardware_concurrency());
    /** Destructor.
        Blocks until all textures are loaded.
    /** Request loading a texture.
        \param[in] filename Filename of the image. Can also include a full path or relative path from a data directory.
        \param[in] generateMipLevels Whether the mip-chain should be generated.
        \param[in] loadAsSrgb Load the texture using sRGB format. Only valid for 3 or 4 component textures.
        \param[in] bindFlags The bind flags to create the texture with.
        \return A future to a new texture, or nullptr if the texture failed to load.
    std::future<Texture::SharedPtr> loadFromFile(const std::string& filename, bool generateMipLevels, bool loadAsSrgb, Resource::BindFlags bindFlags = Resource::BindFlags::ShaderResource);
    void runWorkers(size_t threadCount);
    void terminateWorkers();
    struct Request
        std::string filename;
        bool generateMipLevels;
        bool loadAsSrgb;
        Resource::BindFlags bindFlags;
        std::promise<Texture::SharedPtr> promise;
    std::queue<Request> mRequestQueue;      ///< Texture loading request queue.
    std::condition_variable mCondition;     ///< Condition variable for workers to wait on.
    std::mutex mMutex;                      ///< Mutex for synchronizing access to shared resources.
    std::vector<std::thread> mThreads;      ///< Worker threads.
    bool mTerminate = false;                ///< Flag to terminate worker threads.
    bool mFlushPending = false;             ///< Flag to indicate a flush is pending.
    uint32_t mUploadCounter = 0;            ///< Counter to issue a flush every few uploads.

Add Discussion as Guest

Log in