forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShaderManager.cpp
41 lines (35 loc) · 908 Bytes
/
ShaderManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "ShaderManager.h"
#include "QtAV/VideoShader.h"
namespace QtAV {
ShaderManager::ShaderManager(QOpenGLContext *ctx) :
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QObject(ctx)
#else
QObject(0)
#endif
, m_ctx(ctx)
{
}
ShaderManager::~ShaderManager()
{
invalidated();
}
VideoShader* ShaderManager::prepareMaterial(VideoMaterial *material)
{
const qint64 type = material->type();
VideoShader *shader = shader_cache.value(type, 0);
if (shader)
return shader;
qDebug() << QString("[ShaderManager] cache a new shader material type(%1): %2").arg(type).arg(VideoMaterial::typeName(type));
shader = material->createShader();
shader->initialize();
shader_cache[type] = shader;
return shader;
}
void ShaderManager::invalidated()
{
// TODO: thread safe required?
qDeleteAll(shader_cache.values());
shader_cache.clear();
}
} //namespace QtAV