first commit
This commit is contained in:
65
project/fm_viewer/fav/opengl/ShaderManager.cpp
Normal file
65
project/fm_viewer/fav/opengl/ShaderManager.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "ShaderManager.h"
|
||||
#if !(REMOVE_SHADER_MANAGER)
|
||||
|
||||
#include "../VideoShader.h"
|
||||
|
||||
|
||||
namespace FAV {
|
||||
class ShaderManager::Private
|
||||
{
|
||||
public:
|
||||
~Private() {
|
||||
// TODO: thread safe required?
|
||||
qDeleteAll(shader_cache.values());
|
||||
shader_cache.clear();
|
||||
}
|
||||
|
||||
QHash<qint32, VideoShader*> shader_cache;
|
||||
};
|
||||
|
||||
ShaderManager::ShaderManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
, d(new Private())
|
||||
{
|
||||
#if (MODEL_360)
|
||||
dualMode = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
ShaderManager::~ShaderManager()
|
||||
{
|
||||
delete d;
|
||||
d = 0;
|
||||
}
|
||||
|
||||
VideoShader* ShaderManager::prepareMaterial(VideoMaterial *material, qint32 materialType)
|
||||
{
|
||||
|
||||
#if (MODEL_360)
|
||||
qint32 type = materialType != -1 ? materialType : material->type();
|
||||
if(dualMode == 1)
|
||||
{
|
||||
type = 9999;
|
||||
}
|
||||
#else
|
||||
const qint32 type = materialType != -1 ? materialType : material->type();
|
||||
#endif
|
||||
VideoShader *shader = d->shader_cache.value(type, 0);
|
||||
if (shader)
|
||||
{
|
||||
return shader;
|
||||
}
|
||||
#if (DEBUG_SHADER_MANAGER)
|
||||
qDebug() << QString("[ShaderManager] cache a new shader material type(%1): %2").arg(type).arg(VideoMaterial::typeName(type));
|
||||
#endif
|
||||
shader = material->createShader();
|
||||
#if (MODEL_360)
|
||||
shader->dualMode = dualMode;
|
||||
#endif
|
||||
shader->initialize();
|
||||
d->shader_cache[type] = shader;
|
||||
return shader;
|
||||
}
|
||||
} //namespace FAV
|
||||
#endif //#if !(REMOVE_VIDEO_SHADER)
|
||||
|
||||
Reference in New Issue
Block a user