Files
oak-editor/app/render/backend/opengl/opengltexturecache.h
T
itsmattkc 91c7d8aa4d 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.
2019-12-10 14:53:47 +11:00

54 lines
978 B
C++

#ifndef OPENGLTEXTURECACHE_H
#define OPENGLTEXTURECACHE_H
#include <QMutex>
#include "openglframebuffer.h"
#include "opengltexture.h"
#include "render/videoparams.h"
class OpenGLTextureCache
{
public:
class Reference {
public:
Reference(OpenGLTextureCache* parent, OpenGLTexturePtr texture);
~Reference();
DISABLE_COPY_MOVE(Reference)
OpenGLTexturePtr texture();
void ParentKilled();
private:
OpenGLTextureCache* parent_;
OpenGLTexturePtr texture_;
};
using ReferencePtr = std::shared_ptr<Reference>;
OpenGLTextureCache() = default;
~OpenGLTextureCache();
DISABLE_COPY_MOVE(OpenGLTextureCache)
ReferencePtr Get(const VideoRenderingParams& params, const void *data = nullptr);
private:
void Relinquish(Reference* ref);
QMutex lock_;
QList<OpenGLTexturePtr> available_textures_;
QList<Reference*> existing_references_;
};
Q_DECLARE_METATYPE(OpenGLTextureCache::ReferencePtr)
#endif // OPENGLTEXTURECACHE_H