KWin
|
Vertex Buffer Object. More...
#include <glvertexbuffer.h>
Public Types | |
enum | UsageHint { Dynamic , Static , Stream } |
Public Member Functions | |
GLVertexBuffer (UsageHint hint) | |
~GLVertexBuffer () | |
void | setAttribLayout (std::span< const GLVertexAttrib > attribs, size_t stride) |
void | setData (const void *data, size_t sizeInBytes) |
void | setVertexCount (int count) |
template<std::ranges::contiguous_range T> requires std::is_same<std::ranges::range_value_t<T>, GLVertex2D>::value | |
void | setVertices (const T &range) |
template<std::ranges::contiguous_range T> requires std::is_same<std::ranges::range_value_t<T>, GLVertex3D>::value | |
void | setVertices (const T &range) |
template<std::ranges::contiguous_range T> requires std::is_same<std::ranges::range_value_t<T>, QVector2D>::value | |
void | setVertices (const T &range) |
template<typename T > | |
std::optional< std::span< T > > | map (size_t count) |
void | unmap () |
void | bindArrays () |
void | unbindArrays () |
void | draw (GLenum primitiveMode, int first, int count) |
void | draw (const QRegion ®ion, GLenum primitiveMode, int first, int count, bool hardwareClipping=false) |
void | render (GLenum primitiveMode) |
void | render (const QRegion ®ion, GLenum primitiveMode, bool hardwareClipping=false) |
void | reset () |
void | endOfFrame () |
void | beginFrame () |
Static Public Member Functions | |
static void | initStatic () |
static void | cleanup () |
static bool | supportsIndexedQuads () |
static GLVertexBuffer * | streamingBuffer () |
Static Public Attributes | |
static constexpr std::array | GLVertex2DLayout |
static constexpr std::array | GLVertex3DLayout |
Vertex Buffer Object.
This is a short helper class to use vertex buffer objects (VBO). A VBO can be used to buffer vertex data and to store them on graphics memory.
Definition at line 70 of file glvertexbuffer.h.
Enum to define how often the vertex data in the buffer object changes.
Enumerator | |
---|---|
Dynamic | frequent changes, but used several times for rendering |
Static | No changes to data. |
Stream | Data only used once for rendering, updated very frequently. |
Definition at line 76 of file glvertexbuffer.h.
|
explicit |
Definition at line 383 of file glvertexbuffer.cpp.
|
default |
void KWin::GLVertexBuffer::beginFrame | ( | ) |
Notifies the vertex buffer that we are about to paint a frame.
Definition at line 592 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::bindArrays | ( | ) |
Binds the vertex arrays to the context.
Definition at line 499 of file glvertexbuffer.cpp.
|
static |
Definition at line 639 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::draw | ( | const QRegion & | region, |
GLenum | primitiveMode, | ||
int | first, | ||
int | count, | ||
bool | hardwareClipping = false ) |
Draws count vertices beginning with first.
Definition at line 514 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::draw | ( | GLenum | primitiveMode, |
int | first, | ||
int | count ) |
Draws count vertices beginning with first.
Definition at line 509 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::endOfFrame | ( | ) |
Notifies the vertex buffer that we are done painting the frame.
Definition at line 561 of file glvertexbuffer.cpp.
|
static |
Definition at line 608 of file glvertexbuffer.cpp.
|
inline |
Maps an unused range of the data store into the client's address space.
The data store will be reallocated if it is smaller than the given size.
The buffer object is mapped for writing, not reading. Attempts to read from the mapped buffer range may result in system errors, including program termination. The data in the mapped region is undefined until it has been written to. If subsequent GL calls access unwritten memory, the results are undefined and system errors, including program termination, may occur.
No GL calls that access the buffer object must be made while the buffer object is mapped. The returned pointer must not be passed as a parameter value to any GL function.
It is assumed that the GL_ARRAY_BUFFER_BINDING will not be changed while the buffer object is mapped.
Definition at line 176 of file glvertexbuffer.h.
void KWin::GLVertexBuffer::render | ( | const QRegion & | region, |
GLenum | primitiveMode, | ||
bool | hardwareClipping = false ) |
Same as above restricting painting to region if hardwareClipping is true. It's within the caller's responsibility to enable GL_SCISSOR_TEST.
Definition at line 492 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::render | ( | GLenum | primitiveMode | ) |
Renders the vertex data in given primitiveMode. Please refer to OpenGL documentation of glDrawArrays or glDrawElements for allowed values for primitiveMode. Best is to use GL_TRIANGLES or similar to be future compatible.
Definition at line 487 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::reset | ( | ) |
Resets the instance to default values. Useful for shared buffers.
Definition at line 556 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::setAttribLayout | ( | std::span< const GLVertexAttrib > | attribs, |
size_t | stride ) |
Specifies how interleaved vertex attributes are laid out in the buffer object.
Note that the attributes and the stride should be 32 bit aligned or a performance penalty may be incurred.
For some hardware the optimal stride is a multiple of 32 bytes.
Example:
struct Vertex { QVector3D position; QVector2D texcoord; }; const std::array attribs = { GLVertexAttrib{ VA_Position, 3, GL_FLOAT, offsetof(Vertex, position) }, GLVertexAttrib{ VA_TexCoord, 2, GL_FLOAT, offsetof(Vertex, texcoord) }, }; Vertex vertices[6]; vbo->setAttribLayout(std::span(attribs), sizeof(Vertex)); vbo->setData(vertices, sizeof(vertices));
Definition at line 474 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::setData | ( | const void * | data, |
size_t | sizeInBytes ) |
Uploads data into the buffer object's data store.
Definition at line 390 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::setVertexCount | ( | int | count | ) |
Sets the number of vertices that will be drawn by the render() method.
Definition at line 469 of file glvertexbuffer.cpp.
|
inline |
Definition at line 125 of file glvertexbuffer.h.
|
inline |
Definition at line 134 of file glvertexbuffer.h.
|
inline |
Definition at line 143 of file glvertexbuffer.h.
|
static |
|
static |
Returns true if indexed quad mode is supported, and false otherwise.
Definition at line 551 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::unbindArrays | ( | ) |
Disables the vertex arrays.
Definition at line 504 of file glvertexbuffer.cpp.
void KWin::GLVertexBuffer::unmap | ( | ) |
Flushes the mapped buffer range and unmaps the buffer.
Definition at line 427 of file glvertexbuffer.cpp.
|
staticconstexpr |
Definition at line 265 of file glvertexbuffer.h.
|
staticconstexpr |
Definition at line 279 of file glvertexbuffer.h.