Skip to content

Commit

Permalink
gl: simplify video material type
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Sep 3, 2015
1 parent 8f8ae59 commit c8f5c2f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/QtAV/VideoShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class Q_AV_EXPORT VideoMaterial
void setCurrentFrame(const VideoFrame& frame);
VideoFormat currentFormat() const;
VideoShader* createShader() const;
virtual const char* type() const;
virtual qint64 type() const;
static QString typeName(qint64 value);

bool bind(); // TODO: roi
void unbind();
Expand Down
4 changes: 2 additions & 2 deletions src/ShaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ ShaderManager::~ShaderManager()

VideoShader* ShaderManager::prepareMaterial(VideoMaterial *material)
{
const char* type = material->type();
const qint64 type = material->type();
VideoShader *shader = shader_cache.value(type, 0);
if (shader)
return shader;
qDebug("[ShaderManager] cache a new shader material type: %s", type);
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;
Expand Down
2 changes: 1 addition & 1 deletion src/ShaderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Q_SLOTS:

private:
QOpenGLContext *m_ctx;
QHash<const char*, VideoShader*> shader_cache;
QHash<qint64, VideoShader*> shader_cache;
};
} //namespace QtAV
#endif // QTAV_SHADERMANAGER_H
54 changes: 13 additions & 41 deletions src/VideoShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,51 +491,23 @@ VideoShader* VideoMaterial::createShader() const
return shader;
}

const char *VideoMaterial::type() const
QString VideoMaterial::typeName(qint64 value)
{
return QString("gl material planar: %1, has alpha: %2, big endian: %3, 2d texture: %4, 8bit channel: %5")
.arg(!!(value&(1<<4)))
.arg(!!(value&(1<<3)))
.arg(!!(value&(1<<2)))
.arg(!!(value&(1<<1)))
.arg(!!(value&1));
}

qint64 VideoMaterial::type() const
{
DPTR_D(const VideoMaterial);
const VideoFormat &fmt = d.video_format;
const bool tex_2d = d.target == GL_TEXTURE_2D;
if (!fmt.isPlanar()) {
if (fmt.hasAlpha()) {
if (tex_2d)
return "packed rgb(a) material";
return "packed rgb(a) + rectangle texture material";
}
if (tex_2d)
return "packed rgb/yuv(no alpha) material";
return "packed rgb/yuv(no alpha) + rectangle texture material";
}
if (fmt.bytesPerPixel(0) == 1) {
if (fmt.planeCount() == 4) {
if (tex_2d)
return "8bit 4plane yuv material";
return "8bit 4plane yuv + rectangle texture material";
}
if (tex_2d)
return "8bit yuv material";
return "8bit yuv + rectangle texture material";
}
if (fmt.isBigEndian()) {
if (fmt.planeCount() == 4) {
if (tex_2d)
return "4plane 16bit-be material";
return "4plane 16bit-be + rectangle texture material";
}
if (tex_2d)
return "planar 16bit-be material";
return "planar 16bit-be + rectangle texture material";
} else {
if (fmt.planeCount() == 4) {
if (tex_2d)
return "4plane 16bit-le material";
return "4plane 16bit-le + rectangle texture material";
}
if (tex_2d)
return "planar 16bit-le material";
return "planar 16bit-le + rectangle texture material";
}
return "invalid material";
// planar,alpha,be,2d,8bit
return (fmt.isPlanar()<<4)|(fmt.hasAlpha()<<3)|(fmt.isBigEndian()<<2)|(tex_2d<<1)|(fmt.bytesPerPixel(0) == 1);
}

bool VideoMaterial::bind()
Expand Down

0 comments on commit c8f5c2f

Please sign in to comment.