Upgrade stb_image; rm stb_image threadlocal patch;

stb_image's vertical flip flag was not thread safe in the version
of stb_image we were using.  We patched stb_image to use a thread
local variable for the flag.  stb_image has since been upgraded to
expose a thread local version of the flag, so our patch is no longer
necessary after upgrading.

The CMake flag to enable the thread local patch did not make very much
sense because thread local stuff is unconditionally used elsewhere.
This commit is contained in:
bjorn 2020-12-25 16:43:25 -07:00
parent 4ded7ef37a
commit 30e01f94a3
4 changed files with 341 additions and 157 deletions

View File

@ -38,8 +38,6 @@ option(LOVR_BUILD_EXE "Build an executable (or an apk on Android)" ON)
option(LOVR_BUILD_SHARED "Build a shared library (takes precedence over LOVR_BUILD_EXE)" OFF)
option(LOVR_BUILD_BUNDLE "On macOS, build a .app bundle instead of a raw program" OFF)
option(LOVR_USE_THREADLOCAL "Allow use of thread local storage; disable to run on Windows XP as a DLL" ON)
# Setup
if(EMSCRIPTEN)
string(CONCAT LOVR_EMSCRIPTEN_FLAGS
@ -290,15 +288,10 @@ if(LOVR_ENABLE_HEADSET AND LOVR_USE_PICO)
endif()
# pthreads
if(LOVR_ENABLE_THREAD)
if(NOT WIN32 AND NOT EMSCRIPTEN)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(LOVR_PTHREADS Threads::Threads)
endif()
if (LOVR_USE_THREADLOCAL)
add_definitions(-DUSE_LOVR_STBI_THREADLOCAL)
endif()
if(LOVR_ENABLE_THREAD AND NOT (WIN32 OR EMSCRIPTEN))
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(LOVR_PTHREADS Threads::Threads)
endif()
# LÖVR

View File

@ -5,7 +5,3 @@
#define STBI_ONLY_HDR
#define STBI_ASSERT(x)
#include "stb_image.h"
#ifndef LOVR_STBI_VFLIP_PATCH
#error "Somebody updated stb_image.h without replacing the thread-local patch"
#endif

File diff suppressed because it is too large Load Diff

View File

@ -491,7 +491,7 @@ TextureData* lovrTextureDataInitFromBlob(TextureData* textureData, Blob* blob, b
int width, height;
int length = (int) blob->size;
stbi_set_flip_vertically_on_load(flip);
stbi_set_flip_vertically_on_load_thread(flip);
if (stbi_is_16_bit_from_memory(blob->data, length)) {
int channels;
textureData->blob->data = stbi_load_16_from_memory(blob->data, length, &width, &height, &channels, 0);