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