Add async texture loading

This commit is contained in:
Magnus Norddahl 2025-04-12 01:52:17 +02:00
commit dd782038e4
6 changed files with 225 additions and 4 deletions

View file

@ -51,6 +51,7 @@
#include "imagehelpers.h"
#include "v_video.h"
#include "v_font.h"
#include <mutex>
// Wrappers to keep the definitions of these classes out of here.
IHardwareTexture* CreateHardwareTexture(int numchannels);
@ -325,6 +326,11 @@ bool FTexture::ProcessData(unsigned char* buffer, int w, int h, bool ispatch)
FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
{
// Textures may be loaded on the main thread or on a worker thread.
// To keep things simple, make sure only one of the threads is doing this at any given time.
static std::mutex mutex;
std::unique_lock lock(mutex);
FTextureBuffer result;
if (flags & CTF_Indexed)
{