Encapsulates vertex data stored in the OpenGL server memory, which can be used for fast drawing commands, without repeated CPU-GPU data uploads.
More...
#include <StelOpenGLArray.hpp>
|
| StelOpenGLArray () |
| Constructs an empty StelOpenGLArray. More...
|
|
| ~StelOpenGLArray () |
| Releases the OpenGL data, if it has not happened yet.
|
|
void | clear () |
| Releases the OpenGL data. Requires a valid context.
|
|
bool | load (const StelOBJ *obj, bool useTangents=true) |
| Loads the data from the given OBJ file into OpenGL buffers. More...
|
|
bool | load (const StelVertexArray &array) |
|
void | bind () |
| Binds this array for drawing/manipulating with OpenGL. More...
|
|
void | release () |
| Releases the bound array data. More...
|
|
void | draw () const |
| Issues a glDrawElements call for all indices stored in this array. More...
|
|
void | draw (int offset, int count) const |
| Issues a glDrawElements call for the count indices starting at offset Does not bind the array first.
|
|
const QOpenGLBuffer & | getVertexBuffer () const |
| Returns the buffer used for the vertex data.
|
|
const QOpenGLBuffer & | getIndexBuffer () const |
| Returns the buffer used for the element index data.
|
|
const QOpenGLVertexArrayObject & | getVAO () const |
| Returns the VAO which is used, when possible.
|
|
GLenum | getIndexBufferType () const |
| Returns the type used for element index data in this instance. More...
|
|
size_t | getIndexBufferTypeSize () const |
| Returns the size in bytes for the type from getIndexBufferType()
|
|
int | getIndexCount () const |
| Returns the number of indices stored in this array.
|
|
Each StelOpenGLArray uses a single vertex buffer for vertex data, an element index buffer, and a vertex array object for faster binding if the hardware supports it.
◆ AttributeLocation
Shaders should be configured to use these locations before linking, so that a single vertex format can be used for all shaders.
Enumerator |
---|
ATTLOC_VERTEX | This is the OpenGL attribute location where 3D vertex positions are mapped to.
|
ATTLOC_TEXCOORD | This is the OpenGL attribute location where 2D vertex texture coordinates are mapped to.
|
ATTLOC_NORMAL | This is the OpenGL attribute location where 3D vertex normals are mapped to.
|
ATTLOC_TANGENT | This is the OpenGL attribute location where vertex tangents are mapped to.
|
ATTLOC_BITANGENT | This is the OpenGL attribute location where vertex bitangents are mapped to.
|
ATTLOC_SIZE | The attribute locations starting with this index are unused, and should be used for custom vertex attributes not supported by this class.
|
◆ StelOpenGLArray()
StelOpenGLArray::StelOpenGLArray |
( |
| ) |
|
No OpenGL objects are created with this call, so this can be used without a GL context.
◆ bind()
void StelOpenGLArray::bind |
( |
| ) |
|
- Note
- Requires a valid bound GL context
◆ draw()
void StelOpenGLArray::draw |
( |
| ) |
const |
|
inline |
Does not bind the array first.
◆ getIndexBufferType()
GLenum StelOpenGLArray::getIndexBufferType |
( |
| ) |
const |
|
inline |
This is either GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT or GL_UNSIGNED_INT (if hardware supports it). The actual type is chosen depending on the requirements of the data passed into load().
◆ load()
bool StelOpenGLArray::load |
( |
const StelOBJ * |
obj, |
|
|
bool |
useTangents = true |
|
) |
| |
The StelOBJ instance is not required after this constructor, the data has been copied to OpenGL.
The data is stored in an interleaved format, i.e. the vertex buffer is a vector of StelOBJ::Vertex structs
- Returns
- false if the data could not be loaded into GL
- Parameters
-
obj | The StelOBJ instance which data should be transferred to GL |
useTangents | Whether to also load tangent/bitangent data, or skip it to save GL memory |
- Note
- Requires a valid bound GL context
◆ release()
void StelOpenGLArray::release |
( |
| ) |
|
- Note
- Requires a valid bound GL context
◆ supportsIntegerElementIndex()
static bool StelOpenGLArray::supportsIntegerElementIndex |
( |
| ) |
|
|
inlinestatic |
This is required for loading larger models (>65535 vertices) without manual splitting
◆ supportsVertexArrayObject()
static bool StelOpenGLArray::supportsVertexArrayObject |
( |
| ) |
|
|
inlinestatic |
These are used if possible to increase performance, because the driver does not need to re-validate the vertex attribute state for each draw call.
- Note
- The result of this function is valid only after calling initGL() in a GL context.