Miam-Player  0.8.0
A nice music player
OpenGLTypes.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 2016)
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 #ifndef QTAV_OPENGLTYPES_H
22 #define QTAV_OPENGLTYPES_H
23 #include <QtCore/QVector>
24 #include <QtAV/QtAV_Global.h>
25 
26 namespace QtAV {
27 // TODO: namespace gl/gfx?
29 public:
30  enum { V = 16, Vec = 1<<V, M = 20, Mat = 1<<M };
31  enum Type {
32  Unknown = 0,
33  Bool = 1<<0,
34  Int = 1<<1,
35  UInt = 1<<2,
36  Float = 1<<3,
37  Double = 1<<4,
38  Sampler = 1<<5, //TODO: i,u sampler2D, i,u image etc
39  BVec2 = Bool|Vec|(2<<(V+1)),
40  BVec3 = Bool|Vec|(3<<(V+1)),
41  BVec4 = Bool|Vec|(4<<(V+1)),
42  IVec2 = Int|Vec|(2<<(V+1)),
43  IVec3 = Int|Vec|(3<<(V+1)),
44  IVec4 = Int|Vec|(4<<(V+1)),
45  UVec2 = UInt|Vec|(2<<(V+1)),
46  UVec3 = UInt|Vec|(3<<(V+1)),
47  UVec4 = UInt|Vec|(4<<(V+1)),
48  Vec2 = Float|Vec|(2<<(V+1)),
49  Vec3 = Float|Vec|(3<<(V+1)),
50  Vec4 = Float|Vec|(4<<(V+1)),
51  Mat2 = Float|Mat|(2<<(M+1)), //TODO: mat2x3 2x4 3x2 3x4 4x3
52  Mat3 = Float|Mat|(3<<(M+1)),
53  Mat4 = Float|Mat|(4<<(M+1)),
54  DMat2 = Double|Mat|(2<<(M+1)),
55  DMat3 = Double|Mat|(3<<(M+1)),
56  DMat4 = Double|Mat|(4<<(M+1)),
57  };
58  bool isBool() const {return type()&Bool;}
59  bool isInt() const {return type()&Int;}
60  bool isUInt() const {return type()&UInt;}
61  bool isFloat() const {return type()&Float;}
62  bool isDouble() const {return type()&Double;}
63  bool isVec() const {return type()&Vec;}
64  bool isMat() const {return type()&Mat;}
65 
66  bool dirty;
67  int location; //TODO: auto resolve location?
68  QByteArray name;
73  Uniform& setType(Type tp, int count = 1);
74  Uniform(Type tp = Float, int count = 1);
82  void set(const float& v, int count = 0);
83  void set(const unsigned& v, int count = 0);
84  void set(const int& v, int count = 0);
85  void set(const float* v, int count = 0);
86  void set(const unsigned* v, int count = 0);
87  void set(const int* v, int count = 0);
93  void set(const QVariant& v);
100  bool setGL();
101  bool operator == (const Uniform &other) const {
102  if (type() != other.type())
103  return false;
104  if (name != other.name)
105  return false;
106  if (data != other.data)
107  return false;
108  return true;
109  }
110  Type type() const {return t;}
115  int tupleSize() const {return tuple_size;}
120  int arraySize() const {return array_size;}
124  template<typename T> QVector<T> value() const {
125  Q_ASSERT(sizeof(T)*tupleSize()*arraySize() <= data.size()*sizeof(int) && "Bad type or array size");
126  QVector<T> v(tupleSize()*arraySize());
127  memcpy((char*)v.data(), (const char*)data.constData(), v.size()*sizeof(T));
128  return v;
129  }
130  template<typename T> const T* address() const {
131  Q_ASSERT(sizeof(T)*tupleSize()*arraySize() <= data.size()*sizeof(int) && "Bad type or array size");
132  return reinterpret_cast<const T*>(data.constData());
133  }
134 private:
135  int tuple_size;
136  int array_size;
137  Type t;
138  QVector<int> data; //uniform array
139 };
140 #ifndef QT_NO_DEBUG_STREAM
141 Q_AV_EXPORT QDebug operator<<(QDebug debug, const Uniform &u);
142 Q_AV_EXPORT QDebug operator<<(QDebug debug, Uniform::Type ut);
143 #endif
144 } //namespace QtAV
145 
146 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
147 QT_BEGIN_NAMESPACE
148 Q_DECLARE_METATYPE(QVector<double>)
149 Q_DECLARE_METATYPE(QVector<float>)
150 Q_DECLARE_METATYPE(QVector<int>)
151 Q_DECLARE_METATYPE(QVector<unsigned>)
152 QT_END_NAMESPACE
153 #endif
154 #endif
int location
Definition: OpenGLTypes.h:67
bool isDouble() const
Definition: OpenGLTypes.h:62
#define Q_AV_EXPORT
Definition: QtAV_Global.h:40
bool isInt() const
Definition: OpenGLTypes.h:59
bool isMat() const
Definition: OpenGLTypes.h:64
bool isBool() const
Definition: OpenGLTypes.h:58
Type type() const
Definition: OpenGLTypes.h:110
Definition: OpenGLTypes.h:28
const T * address() const
Definition: OpenGLTypes.h:130
Type
Definition: OpenGLTypes.h:31
bool isUInt() const
Definition: OpenGLTypes.h:60
bool dirty
Definition: OpenGLTypes.h:66
int arraySize() const
arraySize If uniform is an array, it&#39;s array size; otherwise 1
Definition: OpenGLTypes.h:120
QVector< T > value() const
Return an array of given type.
Definition: OpenGLTypes.h:124
Q_AV_EXPORT QDebug operator<<(QDebug debug, const AudioFormat &fmt)
int tupleSize() const
tupleSize 2, 3, 4 for vec2, vec3 and vec4; 2^2, 3^2 and 4^2 for mat2, mat3 and mat4 ...
Definition: OpenGLTypes.h:115
bool operator==(const TagButton &t1, const TagButton &t2)
Definition: tagbutton.h:61
bool isVec() const
Definition: OpenGLTypes.h:63
QByteArray name
Definition: OpenGLTypes.h:68
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31
bool isFloat() const
Definition: OpenGLTypes.h:61