Qt 4.8
Public Types | Public Functions | Static Public Functions | Properties | List of all members
QGLBuffer Class Reference

The QGLBuffer class provides functions for creating and managing GL buffer objects. More...

#include <qglbuffer.h>

Public Types

enum  Access { ReadOnly = 0x88B8, WriteOnly = 0x88B9, ReadWrite = 0x88BA }
 This enum defines the access mode for QGLBuffer::map(). More...
 
enum  Type { VertexBuffer = 0x8892, IndexBuffer = 0x8893, PixelPackBuffer = 0x88EB, PixelUnpackBuffer = 0x88EC }
 This enum defines the type of GL buffer object to create with QGLBuffer. More...
 
enum  UsagePattern {
  StreamDraw = 0x88E0, StreamRead = 0x88E1, StreamCopy = 0x88E2, StaticDraw = 0x88E4,
  StaticRead = 0x88E5, StaticCopy = 0x88E6, DynamicDraw = 0x88E8, DynamicRead = 0x88E9,
  DynamicCopy = 0x88EA
}
 This enum defines the usage pattern of a QGLBuffer object. More...
 

Public Functions

void allocate (const void *data, int count)
 Allocates count bytes of space to the buffer, initialized to the contents of data. More...
 
void allocate (int count)
 Allocates count bytes of space to the buffer. More...
 
bool bind ()
 Binds the buffer associated with this object to the current GL context. More...
 
GLuint bufferId () const
 Returns the GL identifier associated with this buffer; zero if the buffer has not been created. More...
 
bool create ()
 Creates the buffer object in the GL server. More...
 
void destroy ()
 Destroys this buffer object, including the storage being used in the GL server. More...
 
bool isCreated () const
 Returns true if this buffer has been created; false otherwise. More...
 
void * map (QGLBuffer::Access access)
 Maps the contents of this buffer into the application's memory space and returns a pointer to it. More...
 
QGLBufferoperator= (const QGLBuffer &other)
 Assigns a shallow copy of other to this object. More...
 
 QGLBuffer ()
 Constructs a new buffer object of type QGLBuffer::VertexBuffer. More...
 
 QGLBuffer (QGLBuffer::Type type)
 Constructs a new buffer object of type. More...
 
 QGLBuffer (const QGLBuffer &other)
 Constructs a shallow copy of other. More...
 
bool read (int offset, void *data, int count)
 Reads the count bytes in this buffer starting at offset into data. More...
 
void release ()
 Releases the buffer associated with this object from the current GL context. More...
 
void setUsagePattern (QGLBuffer::UsagePattern value)
 Sets the usage pattern for this buffer object to value. More...
 
int size () const
 Returns the size of the data in this buffer, for reading operations. More...
 
QGLBuffer::Type type () const
 Returns the type of buffer represented by this object. More...
 
bool unmap ()
 Unmaps the buffer after it was mapped into the application's memory space with a previous call to map(). More...
 
QGLBuffer::UsagePattern usagePattern () const
 Returns the usage pattern for this buffer object. More...
 
void write (int offset, const void *data, int count)
 Replaces the count bytes of this buffer starting at offset with the contents of data. More...
 
 ~QGLBuffer ()
 Destroys this buffer object, including the storage being used in the GL server. More...
 

Static Public Functions

static void release (QGLBuffer::Type type)
 Releases the buffer associated with type in the current QGLContext. More...
 

Properties

QGLBufferPrivated_ptr
 

Detailed Description

The QGLBuffer class provides functions for creating and managing GL buffer objects.

Since
4.7

Buffer objects are created in the GL server so that the client application can avoid uploading vertices, indices, texture image data, etc every time they are needed.

QGLBuffer objects can be copied around as a reference to the underlying GL buffer object:

buffer1.create();
QGLBuffer buffer2 = buffer1;

QGLBuffer performs a shallow copy when objects are copied in this manner, but does not implement copy-on-write semantics. The original object will be affected whenever the copy is modified.

Definition at line 56 of file qglbuffer.h.

Enumerations

◆ Access

This enum defines the access mode for QGLBuffer::map().

  • ReadOnly The buffer will be mapped for reading only.
  • WriteOnly The buffer will be mapped for writing only.
  • ReadWrite The buffer will be mapped for reading and writing.
Enumerator
ReadOnly 
WriteOnly 
ReadWrite 

Definition at line 87 of file qglbuffer.h.

88  {
89  ReadOnly = 0x88B8, // GL_READ_ONLY
90  WriteOnly = 0x88B9, // GL_WRITE_ONLY
91  ReadWrite = 0x88BA // GL_READ_WRITE
92  };

◆ Type

This enum defines the type of GL buffer object to create with QGLBuffer.

  • VertexBuffer Vertex buffer object for use when specifying vertex arrays.
  • IndexBuffer Index buffer object for use with glDrawElements().
  • PixelPackBuffer Pixel pack buffer object for reading pixel data from the GL server (for example, with glReadPixels()). Not supported under OpenGL/ES.
  • PixelUnpackBuffer Pixel unpack buffer object for writing pixel data to the GL server (for example, with glTexImage2D()). Not supported under OpenGL/ES.
Enumerator
VertexBuffer 
IndexBuffer 
PixelPackBuffer 
PixelUnpackBuffer 

Definition at line 59 of file qglbuffer.h.

60  {
61  VertexBuffer = 0x8892, // GL_ARRAY_BUFFER
62  IndexBuffer = 0x8893, // GL_ELEMENT_ARRAY_BUFFER
63  PixelPackBuffer = 0x88EB, // GL_PIXEL_PACK_BUFFER
64  PixelUnpackBuffer = 0x88EC // GL_PIXEL_UNPACK_BUFFER
65  };

◆ UsagePattern

This enum defines the usage pattern of a QGLBuffer object.

  • StreamDraw The data will be set once and used a few times for drawing operations. Under OpenGL/ES 1.1 this is identical to StaticDraw.
  • StreamRead The data will be set once and used a few times for reading data back from the GL server. Not supported under OpenGL/ES.
  • StreamCopy The data will be set once and used a few times for reading data back from the GL server for use in further drawing operations. Not supported under OpenGL/ES.
  • StaticDraw The data will be set once and used many times for drawing operations.
  • StaticRead The data will be set once and used many times for reading data back from the GL server. Not supported under OpenGL/ES.
  • StaticCopy The data will be set once and used many times for reading data back from the GL server for use in further drawing operations. Not supported under OpenGL/ES.
  • DynamicDraw The data will be modified repeatedly and used many times for drawing operations.
  • DynamicRead The data will be modified repeatedly and used many times for reading data back from the GL server. Not supported under OpenGL/ES.
  • DynamicCopy The data will be modified repeatedly and used many times for reading data back from the GL server for use in further drawing operations. Not supported under OpenGL/ES.
Enumerator
StreamDraw 
StreamRead 
StreamCopy 
StaticDraw 
StaticRead 
StaticCopy 
DynamicDraw 
DynamicRead 
DynamicCopy 

Definition at line 74 of file qglbuffer.h.

75  {
76  StreamDraw = 0x88E0, // GL_STREAM_DRAW
77  StreamRead = 0x88E1, // GL_STREAM_READ
78  StreamCopy = 0x88E2, // GL_STREAM_COPY
79  StaticDraw = 0x88E4, // GL_STATIC_DRAW
80  StaticRead = 0x88E5, // GL_STATIC_READ
81  StaticCopy = 0x88E6, // GL_STATIC_COPY
82  DynamicDraw = 0x88E8, // GL_DYNAMIC_DRAW
83  DynamicRead = 0x88E9, // GL_DYNAMIC_READ
84  DynamicCopy = 0x88EA // GL_DYNAMIC_COPY
85  };

Constructors and Destructors

◆ QGLBuffer() [1/3]

QGLBuffer::QGLBuffer ( )

Constructs a new buffer object of type QGLBuffer::VertexBuffer.

Note: this constructor just creates the QGLBuffer instance. The actual buffer object in the GL server is not created until create() is called.

See also
create()

Definition at line 169 of file qglbuffer.cpp.

◆ QGLBuffer() [2/3]

QGLBuffer::QGLBuffer ( QGLBuffer::Type  type)
explicit

Constructs a new buffer object of type.

Note: this constructor just creates the QGLBuffer instance. The actual buffer object in the GL server is not created until create() is called.

See also
create()

Definition at line 182 of file qglbuffer.cpp.

183  : d_ptr(new QGLBufferPrivate(type))
184 {
185 }
QGLBuffer::Type type() const
Returns the type of buffer represented by this object.
Definition: qglbuffer.cpp:235
QGLBufferPrivate * d_ptr
Definition: qglbuffer.h:123

◆ QGLBuffer() [3/3]

QGLBuffer::QGLBuffer ( const QGLBuffer other)

Constructs a shallow copy of other.

Note: QGLBuffer does not implement copy-on-write semantics, so other will be affected whenever the copy is modified.

Definition at line 193 of file qglbuffer.cpp.

194  : d_ptr(other.d_ptr)
195 {
196  d_ptr->ref.ref();
197 }
bool ref()
Atomically increments the value of this QAtomicInt.
QGLBufferPrivate * d_ptr
Definition: qglbuffer.h:123
QAtomicInt ref
Definition: qglbuffer.cpp:154

◆ ~QGLBuffer()

QGLBuffer::~QGLBuffer ( )

Destroys this buffer object, including the storage being used in the GL server.

Definition at line 205 of file qglbuffer.cpp.

206 {
207  if (!d_ptr->ref.deref()) {
208  destroy();
209  delete d_ptr;
210  }
211 }
void destroy()
Destroys this buffer object, including the storage being used in the GL server.
Definition: qglbuffer.cpp:328
QGLBufferPrivate * d_ptr
Definition: qglbuffer.h:123
bool deref()
Atomically decrements the value of this QAtomicInt.
QAtomicInt ref
Definition: qglbuffer.cpp:154

Functions

◆ allocate() [1/2]

void QGLBuffer::allocate ( const void *  data,
int  count 
)

Allocates count bytes of space to the buffer, initialized to the contents of data.

Any previous contents will be removed.

It is assumed that create() has been called on this buffer and that it has been bound to the current context.

See also
create(), read(), write()

Definition at line 398 of file qglbuffer.cpp.

399 {
400 #ifndef QT_NO_DEBUG
401  if (!isCreated())
402  qWarning("QGLBuffer::allocate(): buffer not created");
403 #endif
404  Q_D(QGLBuffer);
405  if (d->guard.id())
406  glBufferData(d->type, count, data, d->actualUsagePattern);
407 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
bool isCreated() const
Returns true if this buffer has been created; false otherwise.
Definition: qglbuffer.cpp:317
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56
#define glBufferData

◆ allocate() [2/2]

void QGLBuffer::allocate ( int  count)
inline

Allocates count bytes of space to the buffer.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Any previous contents will be removed.

It is assumed that create() has been called on this buffer and that it has been bound to the current context.

See also
create(), write()

Definition at line 117 of file qglbuffer.h.

Referenced by allocate().

117 { allocate(0, count); }
void allocate(const void *data, int count)
Allocates count bytes of space to the buffer, initialized to the contents of data.
Definition: qglbuffer.cpp:398

◆ bind()

bool QGLBuffer::bind ( )

Binds the buffer associated with this object to the current GL context.

Returns false if binding was not possible, usually because type() is not supported on this GL implementation.

The buffer must be bound to the same QGLContext current when create() was called, or to another QGLContext that is sharing with it. Otherwise, false will be returned from this function.

See also
release(), create()

Definition at line 436 of file qglbuffer.cpp.

437 {
438 #ifndef QT_NO_DEBUG
439  if (!isCreated())
440  qWarning("QGLBuffer::bind(): buffer not created");
441 #endif
442  Q_D(const QGLBuffer);
443  GLuint bufferId = d->guard.id();
444  if (bufferId) {
446  d->guard.context())) {
447 #ifndef QT_NO_DEBUG
448  qWarning("QGLBuffer::bind: buffer is not valid in the current context");
449 #endif
450  return false;
451  }
452  glBindBuffer(d->type, bufferId);
453  return true;
454  } else {
455  return false;
456  }
457 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
GLuint bufferId() const
Returns the GL identifier associated with this buffer; zero if the buffer has not been created...
Definition: qglbuffer.cpp:509
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
static bool areSharing(const QGLContext *context1, const QGLContext *context2)
Returns true if context1 and context2 are sharing their GL resources such as textures, shader programs, etc; otherwise returns false.
Definition: qgl.cpp:3319
Q_CORE_EXPORT void qWarning(const char *,...)
bool isCreated() const
Returns true if this buffer has been created; false otherwise.
Definition: qglbuffer.cpp:317
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56
#define glBindBuffer

◆ bufferId()

GLuint QGLBuffer::bufferId ( ) const

Returns the GL identifier associated with this buffer; zero if the buffer has not been created.

See also
isCreated()

Definition at line 509 of file qglbuffer.cpp.

Referenced by bind(), create(), and destroy().

510 {
511  Q_D(const QGLBuffer);
512  return d->guard.id();
513 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56

◆ create()

bool QGLBuffer::create ( )

Creates the buffer object in the GL server.

Returns true if the object was created; false otherwise.

This function must be called with a current QGLContext. The buffer will be bound to and can only be used in that context (or any other context that is shared with it).

This function will return false if the GL implementation does not support buffers, or there is no current QGLContext.

See also
isCreated(), allocate(), write(), destroy()

Definition at line 290 of file qglbuffer.cpp.

291 {
292  Q_D(QGLBuffer);
293  if (d->guard.id())
294  return true;
296  if (ctx) {
297  if (!qt_resolve_buffer_extensions(const_cast<QGLContext *>(ctx)))
298  return false;
299  GLuint bufferId = 0;
300  glGenBuffers(1, &bufferId);
301  if (bufferId) {
302  d->guard.setContext(ctx);
303  d->guard.setId(bufferId);
304  return true;
305  }
306  }
307  return false;
308 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
GLuint bufferId() const
Returns the GL identifier associated with this buffer; zero if the buffer has not been created...
Definition: qglbuffer.cpp:509
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
bool qt_resolve_buffer_extensions(QGLContext *ctx)
#define ctx
Definition: qglbuffer.cpp:501
#define glGenBuffers
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56

◆ destroy()

void QGLBuffer::destroy ( )

Destroys this buffer object, including the storage being used in the GL server.

All references to the buffer will become invalid.

Definition at line 328 of file qglbuffer.cpp.

Referenced by operator=(), and ~QGLBuffer().

329 {
330  Q_D(QGLBuffer);
331  GLuint bufferId = d->guard.id();
332  if (bufferId) {
333  // Switch to the original creating context to destroy it.
334  QGLShareContextScope scope(d->guard.context());
335  glDeleteBuffers(1, &bufferId);
336  }
337  d->guard.setId(0);
338  d->guard.setContext(0);
339 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
GLuint bufferId() const
Returns the GL identifier associated with this buffer; zero if the buffer has not been created...
Definition: qglbuffer.cpp:509
#define glDeleteBuffers
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56

◆ isCreated()

bool QGLBuffer::isCreated ( ) const

Returns true if this buffer has been created; false otherwise.

See also
create(), destroy()

Definition at line 317 of file qglbuffer.cpp.

Referenced by allocate(), bind(), map(), release(), unmap(), and write().

318 {
319  Q_D(const QGLBuffer);
320  return d->guard.id() != 0;
321 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56

◆ map()

void * QGLBuffer::map ( QGLBuffer::Access  access)

Maps the contents of this buffer into the application's memory space and returns a pointer to it.

Returns null if memory mapping is not possible. The access parameter indicates the type of access to be performed.

It is assumed that create() has been called on this buffer and that it has been bound to the current context.

This function is only supported under OpenGL/ES if the GL_OES_mapbuffer extension is present.

See also
unmap(), create(), bind()

Definition at line 552 of file qglbuffer.cpp.

553 {
554  Q_D(QGLBuffer);
555 #ifndef QT_NO_DEBUG
556  if (!isCreated())
557  qWarning("QGLBuffer::map(): buffer not created");
558 #endif
559  if (!d->guard.id())
560  return 0;
561  if (!glMapBufferARB)
562  return 0;
563 #ifdef QT_OPENGL_ES_2
565  return 0;
566 #endif
567  return glMapBufferARB(d->type, access);
568 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
int access(const char *, int)
#define glMapBufferARB
Q_CORE_EXPORT void qWarning(const char *,...)
bool isCreated() const
Returns true if this buffer has been created; false otherwise.
Definition: qglbuffer.cpp:317
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56

◆ operator=()

QGLBuffer & QGLBuffer::operator= ( const QGLBuffer other)

Assigns a shallow copy of other to this object.

Note: QGLBuffer does not implement copy-on-write semantics, so other will be affected whenever the copy is modified.

Definition at line 219 of file qglbuffer.cpp.

220 {
221  if (d_ptr != other.d_ptr) {
222  other.d_ptr->ref.ref();
223  if (!d_ptr->ref.deref()) {
224  destroy();
225  delete d_ptr;
226  }
227  d_ptr = other.d_ptr;
228  }
229  return *this;
230 }
bool ref()
Atomically increments the value of this QAtomicInt.
void destroy()
Destroys this buffer object, including the storage being used in the GL server.
Definition: qglbuffer.cpp:328
QGLBufferPrivate * d_ptr
Definition: qglbuffer.h:123
bool deref()
Atomically decrements the value of this QAtomicInt.
QAtomicInt ref
Definition: qglbuffer.cpp:154

◆ read()

bool QGLBuffer::read ( int  offset,
void *  data,
int  count 
)

Reads the count bytes in this buffer starting at offset into data.

Returns true on success; false if reading from the buffer is not supported. Buffer reading is not supported under OpenGL/ES.

It is assumed that this buffer has been bound to the current context.

See also
write(), bind()

Definition at line 351 of file qglbuffer.cpp.

352 {
353 #if !defined(QT_OPENGL_ES)
354  Q_D(QGLBuffer);
355  if (!glGetBufferSubData || !d->guard.id())
356  return false;
357  while (glGetError() != GL_NO_ERROR) ; // Clear error state.
358  glGetBufferSubData(d->type, offset, count, data);
359  return glGetError() == GL_NO_ERROR;
360 #else
361  Q_UNUSED(offset);
362  Q_UNUSED(data);
363  Q_UNUSED(count);
364  return false;
365 #endif
366 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
static const char * data(const QByteArray &arr)
#define glGetBufferSubData
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define GL_NO_ERROR

◆ release() [1/2]

void QGLBuffer::release ( )

Releases the buffer associated with this object from the current GL context.

This function must be called with the same QGLContext current as when bind() was called on the buffer.

See also
bind()

Definition at line 468 of file qglbuffer.cpp.

469 {
470 #ifndef QT_NO_DEBUG
471  if (!isCreated())
472  qWarning("QGLBuffer::release(): buffer not created");
473 #endif
474  Q_D(const QGLBuffer);
475  if (d->guard.id())
476  glBindBuffer(d->type, 0);
477 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
bool isCreated() const
Returns true if this buffer has been created; false otherwise.
Definition: qglbuffer.cpp:317
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56
#define glBindBuffer

◆ release() [2/2]

void QGLBuffer::release ( QGLBuffer::Type  type)
static

Releases the buffer associated with type in the current QGLContext.

This function is a direct call to glBindBuffer(type, 0) for use when the caller does not know which QGLBuffer has been bound to the context but wants to make sure that it is released.

Definition at line 494 of file qglbuffer.cpp.

495 {
497  if (ctx && qt_resolve_buffer_extensions(const_cast<QGLContext *>(ctx)))
498  glBindBuffer(GLenum(type), 0);
499 }
QGLBuffer::Type type() const
Returns the type of buffer represented by this object.
Definition: qglbuffer.cpp:235
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
bool qt_resolve_buffer_extensions(QGLContext *ctx)
#define ctx
Definition: qglbuffer.cpp:501
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
unsigned int GLenum
Definition: main.cpp:50
#define glBindBuffer

◆ setUsagePattern()

void QGLBuffer::setUsagePattern ( QGLBuffer::UsagePattern  value)

Sets the usage pattern for this buffer object to value.

This function must be called before allocate() or write().

See also
usagePattern(), allocate(), write()

Definition at line 259 of file qglbuffer.cpp.

260 {
261  Q_D(QGLBuffer);
262 #if defined(QT_OPENGL_ES_1)
263  // OpenGL/ES 1.1 does not support GL_STREAM_DRAW, so use GL_STATIC_DRAW.
264  // OpenGL/ES 2.0 does support GL_STREAM_DRAW.
265  d->usagePattern = value;
266  if (value == StreamDraw)
267  d->actualUsagePattern = StaticDraw;
268  else
269  d->actualUsagePattern = value;
270 #else
271  d->usagePattern = d->actualUsagePattern = value;
272 #endif
273 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56

◆ size()

int QGLBuffer::size ( ) const

Returns the size of the data in this buffer, for reading operations.

Returns -1 if fetching the buffer size is not supported, or the buffer has not been created.

It is assumed that this buffer has been bound to the current context.

See also
isCreated(), bind()

Definition at line 528 of file qglbuffer.cpp.

529 {
530  Q_D(const QGLBuffer);
531  if (!d->guard.id())
532  return -1;
533  GLint value = -1;
534  glGetBufferParameteriv(d->type, GL_BUFFER_SIZE, &value);
535  return value;
536 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define glGetBufferParameteriv
#define GL_BUFFER_SIZE
Definition: qglbuffer.cpp:516
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56
typedef GLint
Definition: glfunctions.h:67

◆ type()

QGLBuffer::Type QGLBuffer::type ( ) const

Returns the type of buffer represented by this object.

Definition at line 235 of file qglbuffer.cpp.

236 {
237  Q_D(const QGLBuffer);
238  return d->type;
239 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56

◆ unmap()

bool QGLBuffer::unmap ( )

Unmaps the buffer after it was mapped into the application's memory space with a previous call to map().

Returns true if the unmap succeeded; false otherwise.

It is assumed that this buffer has been bound to the current context, and that it was previously mapped with map().

This function is only supported under OpenGL/ES if the GL_OES_mapbuffer extension is present.

See also
map()

Definition at line 583 of file qglbuffer.cpp.

584 {
585  Q_D(QGLBuffer);
586 #ifndef QT_NO_DEBUG
587  if (!isCreated())
588  qWarning("QGLBuffer::unmap(): buffer not created");
589 #endif
590  if (!d->guard.id())
591  return false;
592  if (!glUnmapBufferARB)
593  return false;
594  return glUnmapBufferARB(d->type) == GL_TRUE;
595 }
double d
Definition: qnumeric_p.h:62
#define GL_TRUE
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
bool isCreated() const
Returns true if this buffer has been created; false otherwise.
Definition: qglbuffer.cpp:317
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56
#define glUnmapBufferARB

◆ usagePattern()

QGLBuffer::UsagePattern QGLBuffer::usagePattern ( ) const

Returns the usage pattern for this buffer object.

The default value is StaticDraw.

See also
setUsagePattern()

Definition at line 247 of file qglbuffer.cpp.

248 {
249  Q_D(const QGLBuffer);
250  return d->usagePattern;
251 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56

◆ write()

void QGLBuffer::write ( int  offset,
const void *  data,
int  count 
)

Replaces the count bytes of this buffer starting at offset with the contents of data.

Any other bytes in the buffer will be left unmodified.

It is assumed that create() has been called on this buffer and that it has been bound to the current context.

See also
create(), read(), allocate()

Definition at line 378 of file qglbuffer.cpp.

379 {
380 #ifndef QT_NO_DEBUG
381  if (!isCreated())
382  qWarning("QGLBuffer::allocate(): buffer not created");
383 #endif
384  Q_D(QGLBuffer);
385  if (d->guard.id())
386  glBufferSubData(d->type, offset, count, data);
387 }
double d
Definition: qnumeric_p.h:62
#define glBufferSubData
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
bool isCreated() const
Returns true if this buffer has been created; false otherwise.
Definition: qglbuffer.cpp:317
The QGLBuffer class provides functions for creating and managing GL buffer objects.
Definition: qglbuffer.h:56

Properties

◆ d_ptr

QGLBufferPrivate* QGLBuffer::d_ptr
private

Definition at line 123 of file qglbuffer.h.

Referenced by operator=(), QGLBuffer(), and ~QGLBuffer().


The documentation for this class was generated from the following files: