Stellarium  0.16.1
List of all members | 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. More...
 
void clear ()
 Releases the OpenGL data. Requires a valid context. More...
 
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. More...
 
const QOpenGLBuffer & getIndexBuffer () const
 Returns the buffer used for the element index data. More...
 
const QOpenGLVertexArrayObject & getVAO () const
 Returns the VAO which is used, when possible. More...
 
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() More...
 
int getIndexCount () const
 Returns the number of indices stored in this array. More...
 

Static Public Member Functions

static void initGL ()
 Initializes some global GL state. Requires a valid bound GL context. More...
 
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

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.

Definition at line 40 of file StelOpenGLArray.hpp.

Member Enumeration Documentation

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.

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.

Definition at line 46 of file StelOpenGLArray.hpp.

Constructor & Destructor Documentation

StelOpenGLArray::StelOpenGLArray ( )

Constructs an empty StelOpenGLArray.

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

StelOpenGLArray::~StelOpenGLArray ( )

Releases the OpenGL data, if it has not happened yet.

Member Function Documentation

void StelOpenGLArray::bind ( )

Binds this array for drawing/manipulating with OpenGL.

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

Releases the OpenGL data. Requires a valid context.

void StelOpenGLArray::draw ( ) const
inline

Issues a glDrawElements call for all indices stored in this array.

Does not bind the array first.

Definition at line 93 of file StelOpenGLArray.hpp.

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

Issues a glDrawElements call for the count indices starting at offset Does not bind the array first.

Definition at line 99 of file StelOpenGLArray.hpp.

const QOpenGLBuffer& StelOpenGLArray::getIndexBuffer ( ) const
inline

Returns the buffer used for the element index data.

Definition at line 107 of file StelOpenGLArray.hpp.

GLenum StelOpenGLArray::getIndexBufferType ( ) const
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().

Definition at line 114 of file StelOpenGLArray.hpp.

size_t StelOpenGLArray::getIndexBufferTypeSize ( ) const
inline

Returns the size in bytes for the type from getIndexBufferType()

Definition at line 116 of file StelOpenGLArray.hpp.

int StelOpenGLArray::getIndexCount ( ) const
inline

Returns the number of indices stored in this array.

Definition at line 118 of file StelOpenGLArray.hpp.

const QOpenGLVertexArrayObject& StelOpenGLArray::getVAO ( ) const
inline

Returns the VAO which is used, when possible.

Definition at line 109 of file StelOpenGLArray.hpp.

const QOpenGLBuffer& StelOpenGLArray::getVertexBuffer ( ) const
inline

Returns the buffer used for the vertex data.

Definition at line 105 of file StelOpenGLArray.hpp.

static void StelOpenGLArray::initGL ( )
static

Initializes some global GL state. Requires a valid bound GL context.

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

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
void StelOpenGLArray::release ( )

Releases the bound array data.

Note
Requires a valid bound GL context
static bool StelOpenGLArray::supportsIntegerElementIndex ( )
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

Definition at line 130 of file StelOpenGLArray.hpp.

static bool StelOpenGLArray::supportsVertexArrayObject ( )
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.

Note
The result of this function is valid only after calling initGL() in a GL context.

Definition at line 127 of file StelOpenGLArray.hpp.


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