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