Files
MapLibreParticleLab/src/mbgl/map/environment.hpp
Konstantin Käfer 61fa436193 coalesce buffer deletions and run them in bulk during rendering
On iOS, the main thread does framebuffer operations just before it requests a rerender of the view contents. This means that GL operations on the Map thread will interfere with that and cause a crash. While most GL operations happen throughout rendering (which is synchronized with the main thread), deletion of shared_ptrs release in turn their OpenGL objects. This may happen at any time and isn't synced with rendering.

This patch changes this so instead of deleting all objects immediately, we are collecting all abandoned IDs and delete them in bulk once the main thread has given us permission to use OpenGL calls (i.e. during render()).
2015-03-20 19:47:54 +01:00

87 lines
2.1 KiB
C++

#ifndef MBGL_MAP_MAP_ENVIRONMENT
#define MBGL_MAP_MAP_ENVIRONMENT
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/util.hpp>
#include <thread>
#include <functional>
#include <vector>
typedef struct uv_loop_s uv_loop_t;
namespace mbgl {
class FileSource;
class Request;
class Response;
struct Resource;
enum class ThreadType : uint8_t {
Unknown = 0,
Main = 1 << 0,
Map = 1 << 1,
TileWorker = 1 << 2,
};
class Environment final : private util::noncopyable {
public:
Environment(FileSource&);
~Environment();
static Environment& Get();
static bool inScope();
static bool currentlyOn(ThreadType);
static std::string threadName();
unsigned getID() const;
// #############################################################################################
// File request APIs
void requestAsync(const Resource&, std::function<void(const Response&)>);
Request* request(const Resource&, std::function<void(const Response&)>);
void cancelRequest(Request*);
// #############################################################################################
// Mark OpenGL objects for deletion
void abandonVAO(uint32_t vao);
void abandonBuffer(uint32_t buffer);
void abandonTexture(uint32_t texture);
// Actually remove the objects we marked as abandoned with the above methods.
// Only call this while the OpenGL context is exclusive to this thread.
void performCleanup();
// #############################################################################################
// Request to terminate the environment.
void terminate();
private:
unsigned id;
FileSource& fileSource;
// Stores OpenGL objects that we marked for deletion
std::vector<uint32_t> abandonedVAOs;
std::vector<uint32_t> abandonedBuffers;
std::vector<uint32_t> abandonedTextures;
public:
uv_loop_t* const loop;
};
class EnvironmentScope final {
public:
EnvironmentScope(Environment&, ThreadType, const std::string& name);
~EnvironmentScope();
private:
std::thread::id id;
};
}
#endif