diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-03-18 04:28:35 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-03-18 04:28:35 (GMT) |
commit | b1fe3626c2406e917b6c858c84e45f12368e969a (patch) | |
tree | 8c31f0468c5d29f3cf6ae6b1a0153ed4b14ebd15 /src | |
parent | b72a2bcf8d813ec6b76eb6cc986408c75a1c96bf (diff) | |
download | Qt-b1fe3626c2406e917b6c858c84e45f12368e969a.zip Qt-b1fe3626c2406e917b6c858c84e45f12368e969a.tar.gz Qt-b1fe3626c2406e917b6c858c84e45f12368e969a.tar.bz2 |
Add a raw bind() function to QGLBuffer.
It is awkward for a Qt application to do the equivalent of
glBindBuffer(GL_ARRAY_BUFFER, 0) without knowing the QGLBuffer
that was previously bound, or to bind a raw id obtained elsewhere.
Resolving the extension is annoying.
This change provides a raw low-level version of bind() for directly
resolving and calling glBindBuffer() to assist such applications.
Reviewed-by: Sarah Smith
Diffstat (limited to 'src')
-rw-r--r-- | src/opengl/qglbuffer.cpp | 32 | ||||
-rw-r--r-- | src/opengl/qglbuffer.h | 2 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/opengl/qglbuffer.cpp b/src/opengl/qglbuffer.cpp index 7022a53..2ab7c32 100644 --- a/src/opengl/qglbuffer.cpp +++ b/src/opengl/qglbuffer.cpp @@ -369,6 +369,38 @@ void QGLBuffer::release() const glBindBuffer(d->type, 0); } +#undef ctx + +/*! + Binds a raw \a bufferId to the specified buffer \a type + in the current QGLContext. Returns false if there is + no context current or the GL buffer extension could + not be resolved. + + This function is a direct call to \c{glBindBuffer()} for + use when the caller does not have a QGLBuffer but does + have a raw \a bufferId. It can also be used to release + the current buffer when the caller does not know which + QGLBuffer object is currently bound: + + \code + QGLBuffer::bind(QGLBuffer::VertexBuffer, 0); + \endcode +*/ +bool QGLBuffer::bind(QGLBuffer::Type type, uint bufferId) +{ + const QGLContext *ctx = QGLContext::currentContext(); + if (ctx) { + if (qt_resolve_buffer_extensions(const_cast<QGLContext *>(ctx))) { + glBindBuffer(GLenum(type), GLuint(bufferId)); + return true; + } + } + return false; +} + +#define ctx d->guard.context() + /*! Returns the GL identifier associated with this buffer; zero if the buffer has not been created. diff --git a/src/opengl/qglbuffer.h b/src/opengl/qglbuffer.h index ecb86e2..a060733 100644 --- a/src/opengl/qglbuffer.h +++ b/src/opengl/qglbuffer.h @@ -97,6 +97,8 @@ public: bool bind() const; void release() const; + static bool bind(QGLBuffer::Type type, uint bufferId); + uint bufferId() const; int size() const; |