Skip to content

Commit

Permalink
gl: dynamic shader object
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Mar 28, 2016
1 parent f05b6c4 commit a30ffaf
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/QtAV/VideoShaderObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,29 @@ class DynamicShaderObjectPrivate;
*/
class Q_AV_EXPORT DynamicShaderObject : public VideoShaderObject
{
Q_OBJECT
DPTR_DECLARE_PRIVATE(DynamicShaderObject)
Q_PROPERTY(QString header READ header WRITE setHeader NOTIFY headerChanged)
Q_PROPERTY(QString sample READ sample WRITE setSample NOTIFY sampleChanged)
Q_PROPERTY(QString postProcess READ postProcess WRITE setPostProcess NOTIFY postProcessChanged)
public:
DynamicShaderObject(QObject* parent = 0);
QString header() const;
void setHeader(const QString& text);
QString sample() const;
void setSample(const QString& text);
QString postProcess() const;
void setPostProcess(const QString& text);
Q_SIGNALS:
void headerChanged();
void sampleChanged();
void postProcessChanged();
protected:
DynamicShaderObject(DynamicShaderObjectPrivate &d, QObject* parent = 0);
private:
const char* userShaderHeader(QOpenGLShader::ShaderType st) const Q_DECL_OVERRIDE;
const char* userSample() const Q_DECL_OVERRIDE;
const char* userPostProcess() const Q_DECL_OVERRIDE;
};
} //namespace QtAV

Expand Down
85 changes: 85 additions & 0 deletions src/opengl/VideoShaderObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,89 @@ void VideoShaderObject::programReady()
}
}
}

class DynamicShaderObjectPrivate : public VideoShaderObjectPrivate {
public:
QString header;
QString sampleFunc;
QString pp;
};

DynamicShaderObject::DynamicShaderObject(QObject *parent)
: VideoShaderObject(*new DynamicShaderObjectPrivate(), parent)
{}

DynamicShaderObject::DynamicShaderObject(DynamicShaderObjectPrivate &d, QObject *parent)
: VideoShaderObject(d, parent)
{}

QString DynamicShaderObject::header() const
{
return d_func().header;
}

void DynamicShaderObject::setHeader(const QString &text)
{
DPTR_D(DynamicShaderObject);
if (d.header == text)
return;
d.header = text;
Q_EMIT headerChanged();
rebuildLater();
}


QString DynamicShaderObject::sample() const
{
return d_func().sampleFunc;
}

void DynamicShaderObject::setSample(const QString &text)
{
DPTR_D(DynamicShaderObject);
if (d.sampleFunc == text)
return;
d.sampleFunc = text;
Q_EMIT sampleChanged();
rebuildLater();
}

QString DynamicShaderObject::postProcess() const
{
return d_func().pp;
}

void DynamicShaderObject::setPostProcess(const QString &text)
{
DPTR_D(DynamicShaderObject);
if (d.pp == text)
return;
d.pp = text;
Q_EMIT postProcessChanged();
rebuildLater();
}

const char* DynamicShaderObject::userShaderHeader(QOpenGLShader::ShaderType st) const
{
if (st == QOpenGLShader::Vertex)
return 0;
if (d_func().header.isEmpty())
return 0;
return d_func().header.toUtf8().constData();
}

const char* DynamicShaderObject::userSample() const
{
if (d_func().sampleFunc.isEmpty())
return 0;
return d_func().sampleFunc.toUtf8().constData();
}

const char* DynamicShaderObject::userPostProcess() const
{
if (d_func().pp.isEmpty())
return 0;
return d_func().pp.toUtf8().constData();
}

} //namespace QtAV

0 comments on commit a30ffaf

Please sign in to comment.