From c8f5c2f4a950c65dd396680cda98bcecdb83edd7 Mon Sep 17 00:00:00 2001 From: wang-bin Date: Thu, 3 Sep 2015 18:21:30 +0800 Subject: [PATCH] gl: simplify video material type --- src/QtAV/VideoShader.h | 3 ++- src/ShaderManager.cpp | 4 ++-- src/ShaderManager.h | 2 +- src/VideoShader.cpp | 54 ++++++++++-------------------------------- 4 files changed, 18 insertions(+), 45 deletions(-) diff --git a/src/QtAV/VideoShader.h b/src/QtAV/VideoShader.h index 70f43f749..f26bdec34 100644 --- a/src/QtAV/VideoShader.h +++ b/src/QtAV/VideoShader.h @@ -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(); diff --git a/src/ShaderManager.cpp b/src/ShaderManager.cpp index bf821088f..f23766e38 100644 --- a/src/ShaderManager.cpp +++ b/src/ShaderManager.cpp @@ -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; diff --git a/src/ShaderManager.h b/src/ShaderManager.h index 173f604be..61c7e1da3 100644 --- a/src/ShaderManager.h +++ b/src/ShaderManager.h @@ -54,7 +54,7 @@ public Q_SLOTS: private: QOpenGLContext *m_ctx; - QHash shader_cache; + QHash shader_cache; }; } //namespace QtAV #endif // QTAV_SHADERMANAGER_H diff --git a/src/VideoShader.cpp b/src/VideoShader.cpp index 3e3224ae3..307aeb51c 100644 --- a/src/VideoShader.cpp +++ b/src/VideoShader.cpp @@ -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()