Stellarium
HEAD
|
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>
Public Types | |
enum | AttributeLocation { ATTLOC_VERTEX , ATTLOC_TEXCOORD , ATTLOC_NORMAL , ATTLOC_TANGENT , ATTLOC_BITANGENT , ATTLOC_SIZE } |
Specifies the attribute location used for the glVertexAttribPointer calls. More... | |
Public Member Functions | |
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. | |
Static Public Member Functions | |
static void | initGL () |
Initializes some global GL state. Requires a valid bound GL context. | |
static bool | supportsVertexArrayObject () |
Returns true if the hardware supports use of vertex array objects. More... | |
static bool | supportsIntegerElementIndex () |
Returns true if the hardware supports use of (unsigned) integer element indices, instead of just byte and short. More... | |
Encapsulates vertex data stored in the OpenGL server memory, which can be used for fast drawing commands, without repeated CPU-GPU data uploads.
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.
Specifies the attribute location used for the glVertexAttribPointer calls.
Shaders should be configured to use these locations before linking, so that a single vertex format can be used for all shaders.
StelOpenGLArray::StelOpenGLArray | ( | ) |
Constructs an empty StelOpenGLArray.
No OpenGL objects are created with this call, so this can be used without a GL context.
void StelOpenGLArray::bind | ( | ) |
Binds this array for drawing/manipulating with OpenGL.
|
inline |
Issues a glDrawElements call for all indices stored in this array.
Does not bind the array first.
|
inline |
Returns the type used for element index data in this instance.
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().
bool StelOpenGLArray::load | ( | const StelOBJ * | obj, |
bool | useTangents = true |
||
) |
Loads the data from the given OBJ file into OpenGL buffers.
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
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 |
void StelOpenGLArray::release | ( | ) |
Releases the bound array data.
|
inlinestatic |
Returns true if the hardware supports use of (unsigned) integer element indices, instead of just byte and short.
This is required for loading larger models (>65535 vertices) without manual splitting
|
inlinestatic |
Returns true if the hardware supports use of vertex array objects.
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.