Stellarium  0.18.3
Public Types | Public Member Functions | Static Public Member Functions
StelOpenGLArray Class Reference

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...
 
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. More...
 
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...
 

Detailed Description

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.

Member Enumeration Documentation

◆ 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.

Constructor & Destructor Documentation

◆ StelOpenGLArray()

StelOpenGLArray::StelOpenGLArray ( )

No OpenGL objects are created with this call, so this can be used without a GL context.

Member Function Documentation

◆ bind()

void StelOpenGLArray::bind ( )
Note
Requires a valid bound GL context

◆ draw() [1/2]

void StelOpenGLArray::draw ( ) const
inline

Does not bind the array first.

◆ draw() [2/2]

void StelOpenGLArray::draw ( int  offset,
int  count 
) const
inline

◆ 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
objThe StelOBJ instance which data should be transferred to GL
useTangentsWhether 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.