implemented texture cache for performance

Creating and destroying textures is a slow process, particularly when we can
re-use them throughout most of the render chain. We now keep them stored so
they can be re-used which improves performance substantially.
This commit is contained in:
itsmattkc
2019-12-10 14:53:47 +11:00
parent 6ac33d8dc4
commit 91c7d8aa4d
9 changed files with 55 additions and 35 deletions
@@ -7,7 +7,7 @@ OpenGLTextureCache::~OpenGLTextureCache()
}
}
OpenGLTextureCache::ReferencePtr OpenGLTextureCache::Get(const VideoRenderingParams &params)
OpenGLTextureCache::ReferencePtr OpenGLTextureCache::Get(const VideoRenderingParams &params, const void *data)
{
OpenGLTexturePtr texture = nullptr;
@@ -28,10 +28,14 @@ OpenGLTextureCache::ReferencePtr OpenGLTextureCache::Get(const VideoRenderingPar
lock_.unlock();
QOpenGLContext* ctx = QOpenGLContext::currentContext();
// If we didn't find a texture, we'll need to create one
if (!texture) {
texture = std::make_shared<OpenGLTexture>();
texture->Create(QOpenGLContext::currentContext(), params.effective_width(), params.effective_height(), params.format());
texture->Create(ctx, params.effective_width(), params.effective_height(), params.format(), data);
} else if (data) {
texture->Upload(data);
}
return std::make_shared<Reference>(this, texture);