qglbuffer.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3class QGLBufferPrivate -
4{ -
5public: -
6 QGLBufferPrivate(QGLBuffer::Type t) -
7 : ref(1), -
8 type(t), -
9 guard(0), -
10 usagePattern(QGLBuffer::StaticDraw), -
11 actualUsagePattern(QGLBuffer::StaticDraw) -
12 { -
13 }
never executed: }
0
14 -
15 QAtomicInt ref; -
16 QGLBuffer::Type type; -
17 QGLSharedResourceGuardBase *guard; -
18 QGLBuffer::UsagePattern usagePattern; -
19 QGLBuffer::UsagePattern actualUsagePattern; -
20}; -
21QGLBuffer::QGLBuffer() -
22 : d_ptr(new QGLBufferPrivate(QGLBuffer::VertexBuffer)) -
23{ -
24}
never executed: }
0
25QGLBuffer::QGLBuffer(QGLBuffer::Type type) -
26 : d_ptr(new QGLBufferPrivate(type)) -
27{ -
28}
never executed: }
0
29 -
30 -
31 -
32 -
33 -
34 -
35 -
36QGLBuffer::QGLBuffer(const QGLBuffer &other) -
37 : d_ptr(other.d_ptr) -
38{ -
39 d_ptr->ref.ref(); -
40}
never executed: }
0
41 -
42 -
43 -
44 -
45 -
46 -
47 -
48QGLBuffer::~QGLBuffer() -
49{ -
50 if (!d_ptr->ref.deref()) {
never evaluated: !d_ptr->ref.deref()
0
51 destroy(); -
52 delete d_ptr; -
53 }
never executed: }
0
54}
never executed: }
0
55 -
56 -
57 -
58 -
59 -
60 -
61 -
62QGLBuffer &QGLBuffer::operator=(const QGLBuffer &other) -
63{ -
64 if (d_ptr != other.d_ptr) {
never evaluated: d_ptr != other.d_ptr
0
65 other.d_ptr->ref.ref(); -
66 if (!d_ptr->ref.deref()) {
never evaluated: !d_ptr->ref.deref()
0
67 destroy(); -
68 delete d_ptr; -
69 }
never executed: }
0
70 d_ptr = other.d_ptr; -
71 }
never executed: }
0
72 return *this;
never executed: return *this;
0
73} -
74 -
75 -
76 -
77 -
78QGLBuffer::Type QGLBuffer::type() const -
79{ -
80 const QGLBufferPrivate * const d = d_func(); -
81 return d->type;
never executed: return d->type;
0
82} -
83 -
84 -
85 -
86 -
87 -
88 -
89 -
90QGLBuffer::UsagePattern QGLBuffer::usagePattern() const -
91{ -
92 const QGLBufferPrivate * const d = d_func(); -
93 return d->usagePattern;
never executed: return d->usagePattern;
0
94} -
95 -
96 -
97 -
98 -
99 -
100 -
101 -
102void QGLBuffer::setUsagePattern(QGLBuffer::UsagePattern value) -
103{ -
104 QGLBufferPrivate * const d = d_func(); -
105 d->usagePattern = d->actualUsagePattern = value; -
106}
never executed: }
0
107 -
108 -
109 -
110namespace { -
111 void freeBufferFunc(QGLContext *ctx, GLuint id) -
112 { -
113 (void)ctx;; -
114 QGLContextPrivate::extensionFuncs(ctx).qt_glDeleteBuffers(1, &id); -
115 }
never executed: }
0
116} -
117bool QGLBuffer::create() -
118{ -
119 QGLBufferPrivate * const d = d_func(); -
120 if (d->guard && d->guard->id())
never evaluated: d->guard
never evaluated: d->guard->id()
0
121 return true;
never executed: return true;
0
122 QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext()); -
123 if (ctx) {
never evaluated: ctx
0
124 if (!qt_resolve_buffer_extensions(ctx))
never evaluated: !qt_resolve_buffer_extensions(ctx)
0
125 return false;
never executed: return false;
0
126 GLuint bufferId = 0; -
127 QGLContextPrivate::extensionFuncs(ctx).qt_glGenBuffers(1, &bufferId); -
128 if (bufferId) {
never evaluated: bufferId
0
129 if (d->guard)
never evaluated: d->guard
0
130 d->guard->free();
never executed: d->guard->free();
0
131 -
132 d->guard = createSharedResourceGuard(ctx, bufferId, freeBufferFunc); -
133 return true;
never executed: return true;
0
134 } -
135 }
never executed: }
0
136 return false;
never executed: return false;
0
137} -
138bool QGLBuffer::isCreated() const -
139{ -
140 const QGLBufferPrivate * const d = d_func(); -
141 return d->guard && d->guard->id();
never executed: return d->guard && d->guard->id();
0
142} -
143 -
144 -
145 -
146 -
147 -
148 -
149void QGLBuffer::destroy() -
150{ -
151 QGLBufferPrivate * const d = d_func(); -
152 if (d->guard) {
never evaluated: d->guard
0
153 d->guard->free(); -
154 d->guard = 0; -
155 }
never executed: }
0
156}
never executed: }
0
157bool QGLBuffer::read(int offset, void *data, int count) -
158{ -
159 -
160 QGLBufferPrivate * const d = d_func(); -
161 if (!QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glGetBufferSubData || !d->guard->id())
never evaluated: !QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glGetBufferSubData
never evaluated: !d->guard->id()
0
162 return false;
never executed: return false;
0
163 while (glGetError() != 0x0) ;
never executed: ;
never evaluated: glGetError() != 0x0
0
164 QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glGetBufferSubData(d->type, offset, count, data); -
165 return glGetError() == 0x0;
never executed: return glGetError() == 0x0;
0
166 -
167 -
168 -
169 -
170 -
171 -
172} -
173void QGLBuffer::write(int offset, const void *data, int count) -
174{ -
175 -
176 -
177 -
178 -
179 QGLBufferPrivate * const d = d_func(); -
180 if (d->guard && d->guard->id())
never evaluated: d->guard
never evaluated: d->guard->id()
0
181 QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glBufferSubData(d->type, offset, count, data);
never executed: QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glBufferSubData(d->type, offset, count, data);
0
182}
never executed: }
0
183void QGLBuffer::allocate(const void *data, int count) -
184{ -
185 -
186 -
187 -
188 -
189 QGLBufferPrivate * const d = d_func(); -
190 if (d->guard && d->guard->id())
never evaluated: d->guard
never evaluated: d->guard->id()
0
191 QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glBufferData(d->type, count, data, d->actualUsagePattern);
never executed: QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glBufferData(d->type, count, data, d->actualUsagePattern);
0
192}
never executed: }
0
193bool QGLBuffer::bind() -
194{ -
195 -
196 -
197 -
198 -
199 const QGLBufferPrivate * const d = d_func(); -
200 GLuint bufferId = d->guard ? d->guard->id() : 0;
never evaluated: d->guard
0
201 if (bufferId) {
never evaluated: bufferId
0
202 if (d->guard->group() != QOpenGLContextGroup::currentContextGroup()) {
never evaluated: d->guard->group() != QOpenGLContextGroup::currentContextGroup()
0
203 -
204 -
205 -
206 return false;
never executed: return false;
0
207 } -
208 QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glBindBuffer(d->type, bufferId); -
209 return true;
never executed: return true;
0
210 } else { -
211 return false;
never executed: return false;
0
212 } -
213} -
214void QGLBuffer::release() -
215{ -
216 -
217 -
218 -
219 -
220 const QGLBufferPrivate * const d = d_func(); -
221 if (d->guard && d->guard->id())
never evaluated: d->guard
never evaluated: d->guard->id()
0
222 QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glBindBuffer(d->type, 0);
never executed: QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glBindBuffer(d->type, 0);
0
223}
never executed: }
0
224void QGLBuffer::release(QGLBuffer::Type type) -
225{ -
226 const QGLContext *ctx = QGLContext::currentContext(); -
227 if (ctx && qt_resolve_buffer_extensions(const_cast<QGLContext *>(ctx)))
never evaluated: ctx
never evaluated: qt_resolve_buffer_extensions(const_cast<QGLContext *>(ctx))
0
228 QGLContextPrivate::extensionFuncs(ctx).qt_glBindBuffer(GLenum(type), 0);
never executed: QGLContextPrivate::extensionFuncs(ctx).qt_glBindBuffer(GLenum(type), 0);
0
229}
never executed: }
0
230GLuint QGLBuffer::bufferId() const -
231{ -
232 const QGLBufferPrivate * const d = d_func(); -
233 return d->guard ? d->guard->id() : 0;
never executed: return d->guard ? d->guard->id() : 0;
0
234} -
235int QGLBuffer::size() const -
236{ -
237 const QGLBufferPrivate * const d = d_func(); -
238 if (!d->guard || !d->guard->id())
never evaluated: !d->guard
never evaluated: !d->guard->id()
0
239 return -1;
never executed: return -1;
0
240 GLint value = -1; -
241 QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glGetBufferParameteriv(d->type, 0x8764, &value); -
242 return value;
never executed: return value;
0
243} -
244void *QGLBuffer::map(QGLBuffer::Access access) -
245{ -
246 QGLBufferPrivate * const d = d_func(); -
247 -
248 -
249 -
250 -
251 if (!d->guard || !d->guard->id())
never evaluated: !d->guard
never evaluated: !d->guard->id()
0
252 return 0;
never executed: return 0;
0
253 if (!QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glMapBufferARB)
never evaluated: !QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glMapBufferARB
0
254 return 0;
never executed: return 0;
0
255 return QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glMapBufferARB(d->type, access);
never executed: return QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glMapBufferARB(d->type, access);
0
256} -
257bool QGLBuffer::unmap() -
258{ -
259 QGLBufferPrivate * const d = d_func(); -
260 -
261 -
262 -
263 -
264 if (!d->guard || !d->guard->id())
never evaluated: !d->guard
never evaluated: !d->guard->id()
0
265 return false;
never executed: return false;
0
266 if (!QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glUnmapBufferARB)
never evaluated: !QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glUnmapBufferARB
0
267 return false;
never executed: return false;
0
268 return QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glUnmapBufferARB(d->type) == 0x1;
never executed: return QGLContextPrivate::extensionFuncs(QGLContext::currentContext()).qt_glUnmapBufferARB(d->type) == 0x1;
0
269} -
270 -
271 -
272 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial