get rid of the static list of Engines
Originally it was used for validating the Engine* used, but this makes no sense (no reason to validate this pointer more than any other one). The list also made sure that Engine instances were automatically destroyed when the filament library was unloaded, but again, there is no reason to do this -- it's C++ after all!
This commit is contained in:
committed by
Mathias Agopian
parent
ca7ef8cbae
commit
cb5fcbc784
+2
-49
@@ -60,43 +60,6 @@ using namespace filaflat;
|
||||
|
||||
namespace details {
|
||||
|
||||
// Global list of engines used for diagnostic purposes only.
|
||||
// This console output in the constructor helps catch situations where the Filament library is
|
||||
// loaded twice, or not at all. Note that we avoid using slog due to static initialization.
|
||||
class EngineList {
|
||||
public:
|
||||
EngineList() {
|
||||
io::LogStream cinfo(io::LogStream::Priority::INFO);
|
||||
cinfo << "Filament library loaded." << io::endl;
|
||||
}
|
||||
void add(FEngine* instance) {
|
||||
std::unique_ptr<FEngine> engine(instance);
|
||||
std::lock_guard<std::mutex> guard(mLock);
|
||||
Engine* handle = engine.get();
|
||||
mEngines[handle] = std::move(engine);
|
||||
}
|
||||
std::unique_ptr<FEngine> remove(FEngine* instance) {
|
||||
std::unique_ptr<FEngine> filamentEngine;
|
||||
std::lock_guard<std::mutex> guard(mLock);
|
||||
auto const& pos = mEngines.find(instance);
|
||||
if (pos != mEngines.end()) {
|
||||
std::swap(filamentEngine, pos->second);
|
||||
mEngines.erase(pos);
|
||||
}
|
||||
return filamentEngine;
|
||||
}
|
||||
bool isValid(Engine const& engine, const char* function) {
|
||||
std::lock_guard<std::mutex> guard(mLock);
|
||||
auto const& pos = mEngines.find(&engine);
|
||||
return pos != mEngines.end();
|
||||
}
|
||||
private:
|
||||
std::unordered_map<Engine const*, std::unique_ptr<FEngine>> mEngines;
|
||||
std::mutex mLock;
|
||||
};
|
||||
|
||||
static EngineList sEngines;
|
||||
|
||||
FEngine* FEngine::create(Backend backend, Platform* platform, void* sharedGLContext) {
|
||||
FEngine* instance = new FEngine(backend, platform, sharedGLContext);
|
||||
|
||||
@@ -133,8 +96,6 @@ FEngine* FEngine::create(Backend backend, Platform* platform, void* sharedGLCont
|
||||
}
|
||||
}
|
||||
|
||||
sEngines.add(instance);
|
||||
|
||||
// now we can initialize the largest part of the engine
|
||||
instance->init();
|
||||
|
||||
@@ -145,12 +106,6 @@ FEngine* FEngine::create(Backend backend, Platform* platform, void* sharedGLCont
|
||||
return instance;
|
||||
}
|
||||
|
||||
void FEngine::assertValid(Engine const& engine, const char* function) {
|
||||
bool valid = sEngines.isValid(engine, function);
|
||||
ASSERT_POSTCONDITION(valid,
|
||||
"Using an invalid Engine instance (@ %p) from %s.", &engine, function);
|
||||
}
|
||||
|
||||
// these must be static because only a pointer is copied to the render stream
|
||||
// Note that these coordinates are specified in OpenGL clip space. Other backends can transform
|
||||
// these in the vertex shader as needed.
|
||||
@@ -801,10 +756,8 @@ bool FEngine::execute() {
|
||||
|
||||
void FEngine::destroy(FEngine* engine) {
|
||||
if (engine) {
|
||||
std::unique_ptr<FEngine> filamentEngine = sEngines.remove(engine);
|
||||
if (filamentEngine) {
|
||||
filamentEngine->shutdown();
|
||||
}
|
||||
engine->shutdown();
|
||||
delete engine;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ IndexBuffer::Builder& IndexBuffer::Builder::bufferType(IndexType indexType) noex
|
||||
}
|
||||
|
||||
IndexBuffer* IndexBuffer::Builder::build(Engine& engine) {
|
||||
FEngine::assertValid(engine, __PRETTY_FUNCTION__);
|
||||
return upcast(engine).createIndexBuffer(*this);
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,6 @@ IndirectLight::Builder& IndirectLight::Builder::rotation(mat3f const& rotation)
|
||||
}
|
||||
|
||||
IndirectLight* IndirectLight::Builder::build(Engine& engine) {
|
||||
FEngine::assertValid(engine, __PRETTY_FUNCTION__);
|
||||
if (mImpl->mReflectionsMap) {
|
||||
if (!ASSERT_POSTCONDITION_NON_FATAL(
|
||||
mImpl->mReflectionsMap->getTarget() == Texture::Sampler::SAMPLER_CUBEMAP,
|
||||
|
||||
@@ -74,7 +74,6 @@ Material::Builder& Material::Builder::package(const void* payload, size_t size)
|
||||
}
|
||||
|
||||
Material* Material::Builder::build(Engine& engine) {
|
||||
FEngine::assertValid(engine, __PRETTY_FUNCTION__);
|
||||
MaterialParser* materialParser = FMaterial::createParser(
|
||||
upcast(engine).getBackend(), mImpl->mPayload, mImpl->mSize);
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@ RenderTarget::Builder& RenderTarget::Builder::layer(AttachmentPoint pt, uint32_t
|
||||
}
|
||||
|
||||
RenderTarget* RenderTarget::Builder::build(Engine& engine) {
|
||||
FEngine::assertValid(engine, __PRETTY_FUNCTION__);
|
||||
using backend::TextureUsage;
|
||||
const FRenderTarget::Attachment& color = mImpl->mAttachments[COLOR];
|
||||
const FRenderTarget::Attachment& depth = mImpl->mAttachments[DEPTH];
|
||||
|
||||
@@ -78,7 +78,6 @@ Skybox::Builder& Skybox::Builder::showSun(bool show) noexcept {
|
||||
}
|
||||
|
||||
Skybox* Skybox::Builder::build(Engine& engine) {
|
||||
FEngine::assertValid(engine, __PRETTY_FUNCTION__);
|
||||
FTexture* cubemap = upcast(mImpl->mEnvironmentMap);
|
||||
|
||||
if (!ASSERT_PRECONDITION_NON_FATAL(!cubemap || cubemap->isCubemap(),
|
||||
|
||||
@@ -69,7 +69,6 @@ Stream::Builder& Stream::Builder::height(uint32_t height) noexcept {
|
||||
}
|
||||
|
||||
Stream* Stream::Builder::build(Engine& engine) {
|
||||
FEngine::assertValid(engine, __PRETTY_FUNCTION__);
|
||||
if (!ASSERT_PRECONDITION_NON_FATAL(!mImpl->mStream || !mImpl->mExternalTextureId,
|
||||
"One and only one of the stream or external texture can be specified")) {
|
||||
return nullptr;
|
||||
|
||||
@@ -110,7 +110,6 @@ Texture::Builder& Texture::Builder::swizzle(Swizzle r, Swizzle g, Swizzle b, Swi
|
||||
}
|
||||
|
||||
Texture* Texture::Builder::build(Engine& engine) {
|
||||
FEngine::assertValid(engine, __PRETTY_FUNCTION__);
|
||||
if (!ASSERT_POSTCONDITION_NON_FATAL(Texture::isTextureFormatSupported(engine, mImpl->mFormat),
|
||||
"Texture format %u not supported on this platform", mImpl->mFormat)) {
|
||||
return nullptr;
|
||||
|
||||
@@ -111,7 +111,6 @@ VertexBuffer::Builder& VertexBuffer::Builder::normalized(VertexAttribute attribu
|
||||
}
|
||||
|
||||
VertexBuffer* VertexBuffer::Builder::build(Engine& engine) {
|
||||
FEngine::assertValid(engine, __PRETTY_FUNCTION__);
|
||||
if (!ASSERT_PRECONDITION_NON_FATAL(mImpl->mVertexCount > 0, "vertexCount cannot be 0")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,6 @@ LightManager::Builder& LightManager::Builder::sunHaloFalloff(float haloFalloff)
|
||||
}
|
||||
|
||||
LightManager::Builder::Result LightManager::Builder::build(Engine& engine, Entity entity) {
|
||||
FEngine::assertValid(engine, __PRETTY_FUNCTION__);
|
||||
upcast(engine).createLight(*this, entity);
|
||||
return Success;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,6 @@ RenderableManager::Builder& RenderableManager::Builder::blendOrder(size_t index,
|
||||
}
|
||||
|
||||
RenderableManager::Builder::Result RenderableManager::Builder::build(Engine& engine, Entity entity) {
|
||||
FEngine::assertValid(engine, __PRETTY_FUNCTION__);
|
||||
bool isEmpty = true;
|
||||
|
||||
if (!ASSERT_PRECONDITION_NON_FATAL(mImpl->mSkinningBoneCount <= CONFIG_MAX_BONE_COUNT,
|
||||
|
||||
@@ -135,8 +135,6 @@ public:
|
||||
|
||||
static void destroy(FEngine* engine);
|
||||
|
||||
static void assertValid(Engine const& engine, const char* function);
|
||||
|
||||
~FEngine() noexcept;
|
||||
|
||||
backend::Driver& getDriver() const noexcept { return *mDriver; }
|
||||
|
||||
Reference in New Issue
Block a user