Add IRenderer::ClearCache

This commit is contained in:
yvt 2019-07-14 23:53:10 +09:00
parent bb4675ca00
commit ed508fadd5
No known key found for this signature in database
GPG Key ID: 48F2768FA8D07C92
15 changed files with 67 additions and 11 deletions

View File

@ -43,6 +43,13 @@ namespace spades {
*/
Model @RegisterModel(const string @path) {}
/**
* Clear the cache of models and images loaded via `RegisterModel`
* and `RegisterImage`. This method is merely a hint - the
* implementation may partially or completely ignore the request.
*/
void ClearCache() {}
/** Creates an image from the specified bitmap. */
Image @CreateImage(Bitmap @bitmap) {}

View File

@ -98,6 +98,13 @@ namespace spades {
virtual IImage *RegisterImage(const char *filename) = 0;
virtual IModel *RegisterModel(const char *filename) = 0;
/**
* Clear the cache of models and images loaded via `RegisterModel`
* and `RegisterImage`. This method is merely a hint - the
* implementation may partially or completely ignore the request.
*/
virtual void ClearCache() {}
virtual IImage *CreateImage(Bitmap *) = 0;
virtual IModel *CreateModel(VoxelModel *) = 0;

View File

@ -19,13 +19,13 @@
*/
#include "GLImageManager.h"
#include "GLImage.h"
#include "GLRenderer.h"
#include "IGLDevice.h"
#include <Core/Bitmap.h>
#include <Core/Debug.h>
#include <Core/FileManager.h>
#include <Core/IStream.h>
#include "GLImage.h"
#include "GLRenderer.h"
#include "IGLDevice.h"
namespace spades {
namespace draw {
@ -102,5 +102,7 @@ namespace spades {
}
}
}
}
}
void GLImageManager::ClearCache() { images.clear(); }
} // namespace draw
} // namespace spades

View File

@ -45,6 +45,8 @@ namespace spades {
GLImage *GetWhiteImage();
void DrawAllImages(GLRenderer *);
void ClearCache();
};
}
}
} // namespace draw
} // namespace spades

View File

@ -66,5 +66,7 @@ namespace spades {
return static_cast<GLModel *>(renderer->CreateModelOptimized(voxelModel));
}
void GLModelManager::ClearCache() { models.clear(); }
} // namespace draw
} // namespace spades

View File

@ -38,6 +38,8 @@ namespace spades {
GLModelManager(GLRenderer *);
~GLModelManager();
GLModel *RegisterModel(const char *);
void ClearCache();
};
}
}
} // namespace draw
} // namespace spades

View File

@ -251,6 +251,12 @@ namespace spades {
return modelManager->RegisterModel(filename);
}
void GLRenderer::ClearCache() {
SPADES_MARK_FUNCTION();
modelManager->ClearCache();
imageManager->ClearCache();
}
client::IImage *GLRenderer::CreateImage(spades::Bitmap *bmp) {
SPADES_MARK_FUNCTION();
return GLImage::FromBitmap(bmp, device);

View File

@ -153,6 +153,8 @@ namespace spades {
client::IImage *RegisterImage(const char *filename) override;
client::IModel *RegisterModel(const char *filename) override;
void ClearCache() override;
client::IImage *CreateImage(Bitmap *) override;
client::IModel *CreateModel(VoxelModel *) override;
client::IModel *CreateModelOptimized(VoxelModel *);

View File

@ -127,5 +127,9 @@ namespace spades {
}
SWImage *SWImageManager::CreateImage(Bitmap *vm) { return new SWImage(vm); }
void SWImageManager::ClearCache() {
images.clear();
}
}
}

View File

@ -69,6 +69,8 @@ namespace spades {
SWImage *RegisterImage(const std::string &);
SWImage *CreateImage(Bitmap *);
void ClearCache();
};
}
}

View File

@ -147,5 +147,9 @@ namespace spades {
}
SWModel *SWModelManager::CreateModel(spades::VoxelModel *vm) { return new SWModel(vm); }
void SWModelManager::ClearCache() {
models.clear();
}
}
}

View File

@ -63,6 +63,8 @@ namespace spades {
SWModel *RegisterModel(const std::string &);
SWModel *CreateModel(VoxelModel *);
void ClearCache();
};
}
}

View File

@ -152,6 +152,13 @@ namespace spades {
return modelManager->RegisterModel(filename);
}
void SWRenderer::ClearCache() {
SPADES_MARK_FUNCTION();
EnsureValid();
imageManager->ClearCache();
modelManager->ClearCache();
}
client::IImage *SWRenderer::CreateImage(spades::Bitmap *bmp) {
SPADES_MARK_FUNCTION();
EnsureValid();
@ -1186,5 +1193,5 @@ namespace spades {
flatMapRenderer->SetNeedsUpdate(x, y);
}
}
}
} // namespace draw
} // namespace spades

View File

@ -159,6 +159,8 @@ namespace spades {
client::IImage *CreateImage(Bitmap *) override;
client::IModel *CreateModel(VoxelModel *) override;
void ClearCache() override;
/*
GLProgram *RegisterProgram(const std::string& name) override;
GLShader *RegisterShader(const std::string& name) override;

View File

@ -394,6 +394,11 @@ namespace spades {
asFUNCTION(RegisterModel),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Renderer",
"void ClearCache()",
asMETHOD(IRenderer, ClearCache),
asCALL_THISCALL);
manager->CheckError(r);
// OpenSpades' C++ functions increase the reference count of a passed object
// when storing it (just like the convention of Objective C), so we must
// use "auto handles" (`@+`). Otherwise, a memory leak would occur