Miam-Player  0.8.0
A nice music player
VideoShader.h
Go to the documentation of this file.
1 /******************************************************************************
2  QtAV: Multimedia framework based on Qt and FFmpeg
3  Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
4 
5 * This file is part of QtAV (from 2014)
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ******************************************************************************/
21 
22 #ifndef QTAV_VIDEOSHADER_H
23 #define QTAV_VIDEOSHADER_H
24 
25 #include <QtAV/OpenGLTypes.h>
26 #include <QtAV/VideoFrame.h>
27 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
28 #include <QtGui/QOpenGLShaderProgram>
29 #include <QtGui/QOpenGLShader>
30 #else
31 #include <QtOpenGL/QGLShaderProgram>
32 #include <QtOpenGL/QGLShader>
33 #undef QOpenGLShaderProgram
34 #undef QOpenGLShader
35 #define QOpenGLShaderProgram QGLShaderProgram
36 #define QOpenGLShader QGLShader
37 #endif
38 
39 QT_BEGIN_NAMESPACE
40 class QOpenGLShaderProgram;
41 QT_END_NAMESPACE
42 namespace QtAV {
43 class VideoMaterial;
44 class VideoShaderPrivate;
54 {
56 public:
57  VideoShader();
58  virtual ~VideoShader();
64  virtual char const *const *attributeNames() const;
71  virtual const char *vertexShader() const;
72  virtual const char *fragmentShader() const;
77  virtual void initialize(QOpenGLShaderProgram* shaderProgram = 0);
78  int uniformLocation(const char* name) const;
85  int textureLocationCount() const;
86  int textureLocation(int index) const;
87  int matrixLocation() const;
88  int colorMatrixLocation() const;
89  int opacityLocation() const;
90  int channelMapLocation() const;
91  int texelSizeLocation() const;
92  int textureSizeLocation() const;
93  VideoFormat videoFormat() const;
94  // defalut is GL_TEXTURE_2D
95  int textureTarget() const;
96  QOpenGLShaderProgram* program();
102  bool update(VideoMaterial* material);
103 
104 protected:
106  void rebuildLater();
107 private:
112  virtual void programReady() {}
113 
115 
128  virtual const char* userShaderHeader(QOpenGLShader::ShaderType) const {return 0;}
136  virtual bool setUserUniformValues() {return false;}
141  virtual void setUserUniformValue(Uniform&) {}
153  virtual const char* userSample() const { return 0;}
159  virtual const char* userPostProcess() const {return 0;}
161 
162  QByteArray shaderSourceFromFile(const QString& fileName) const;
163  bool build(QOpenGLShaderProgram* shaderProgram);
164  void setVideoFormat(const VideoFormat& format);
165  void setTextureTarget(int type);
166  void setMaterialType(qint32 value);
167  friend class VideoMaterial;
168 protected:
171 };
172 
180 {
182 public:
183  VideoMaterial();
184  virtual ~VideoMaterial() {}
185  void setCurrentFrame(const VideoFrame& frame);
186  VideoFormat currentFormat() const;
187  VideoShader* createShader() const;
188  void initializeShader(VideoShader* shader) const;
189  virtual qint32 type() const;
190  static QString typeName(qint32 value);
191 
192  bool bind(); // TODO: roi
193  void unbind();
194  int compare(const VideoMaterial* other) const;
195 
196  bool hasAlpha() const;
201  bool isDirty() const;
206  void setDirty(bool value);
207  const QMatrix4x4 &colorMatrix() const;
208  const QMatrix4x4& channelMap() const;
209  int bitsPerComponent() const; //0 if the value of components are different
210  QVector2D vectorTo8bit() const;
211  int planeCount() const;
225  qreal validTextureWidth() const;
226  QSize frameSize() const;
232  QSizeF texelSize(int plane) const; //vec2?
237  QVector<QVector2D> texelSize() const;
242  QSize textureSize(int plane) const;
247  QVector<QVector2D> textureSize() const;
253  QRectF normalizedROI(const QRectF& roi) const;
262  QPointF mapToTexture(int plane, const QPointF& p, int normalize = -1) const;
263  QRectF mapToTexture(int plane, const QRectF& r, int normalize = -1) const;
264  qreal brightness() const;
265  void setBrightness(qreal value);
266  qreal contrast() const;
267  void setContrast(qreal value);
268  qreal hue() const;
269  void setHue(qreal value);
270  qreal saturation() const;
271  void setSaturation(qreal value);
272 protected:
273  // TODO: roi
274  // whether to update texture is set internal
275  void bindPlane(int p, bool updateTexture = true);
278 };
279 } //namespace QtAV
280 #endif // QTAV_VIDEOSHADER_H
virtual ~VideoMaterial()
Definition: VideoShader.h:184
#define Q_AV_EXPORT
Definition: QtAV_Global.h:40
The VideoFormat class Describes the layout of video data.
Definition: VideoFormat.h:39
Definition: OpenGLTypes.h:28
#define DPTR_DECLARE_PRIVATE(Class)
Definition: dptr.h:107
Definition: VideoShader_p.h:103
The VideoShader class Represents a shader for rendering a video frame.
Definition: VideoShader.h:53
Definition: VideoShader_p.h:55
Definition: VideoFrame.h:32
ShaderType
Definition: VideoShader_p.h:48
The VideoMaterial class Encapsulates rendering state for a video shader program.
Definition: VideoShader.h:179
#define DPTR_DECLARE(Class)
Definition: dptr.h:105
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31