All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Luminous::StateGL Class Reference

Keeps track of current OpenGL state, one instance is shared between all *GL -classes in the same rendering context. More...

#include <Luminous/StateGL.hpp>

Public Types

typedef std::map< GLuint,
BufferMapping > 
BufferMaps
 Cache to keep track of mapped buffers.
 

Public Member Functions

int64_t availableUploadBytes () const
 Get the number of bytes available for uploading content to the GPU. More...
 
BufferMapsbufferMaps ()
 Get the cache for active buffer mappings. More...
 
void clearUploadedBytes ()
 Sets the number of available upload bytes to zero. More...
 
void consumeUploadBytes (int64_t bytes)
 Consume the given amount of bytes from the upload budget. More...
 
GLuint drawFramebuffer () const
 Get the handle to the current draw framebuffer. More...
 
RenderDriverGL & driver ()
 Get the render driver associated with this state. More...
 
Radiant::TimeStamp frameTime () const
 Get the current frame time. More...
 
GLuint program () const
 Get the current program object handle. More...
 
GLuint readFramebuffer () const
 Get the handle to the current read framebuffer. More...
 
bool setFramebuffer (GLenum target, GLuint handle)
 Set the current framebuffer. More...
 
void setFrameTime (Radiant::TimeStamp t)
 Set the frame time. More...
 
bool setProgram (GLuint handle)
 Sets the current program object. More...
 
bool setTextureUnit (int index)
 Set the current active texture unit. More...
 
void setUpdateFrequency (int64_t fps)
 Set the target update frequency. More...
 
void setUploadLimits (int64_t limit, int64_t margin)
 Set the maximum and minimum number of bytes per second for uploading content to the GPU. More...
 
bool setVertexArray (GLuint handle)
 Set the current vertex array. More...
 
 StateGL (unsigned int threadIndex, RenderDriverGL &driver)
 Constructor. More...
 
int textureUnit () const
 Get the current active texture unit. More...
 
unsigned int threadIndex () const
 Get the render thread index this state object was associated with. More...
 
int64_t uploadLimit () const
 Get the maximum number of bytes per second used for uploading content to the GPU. More...
 
int64_t uploadMargin () const
 Get the minimum number of bytes per second used for uploading content to the GPU. More...
 
GLuint vertexArray () const
 Get the current vertex array. More...
 

Detailed Description

Keeps track of current OpenGL state, one instance is shared between all *GL -classes in the same rendering context.

None of these functions actually modify any OpenGL state. This class is used to minimize OpenGL state changes to improve rendering performance.

Constructor & Destructor Documentation

Luminous::StateGL::StateGL ( unsigned int  threadIndex,
RenderDriverGL &  driver 
)
inline

Constructor.

Parameters
threadIndexrender thread index
driverrender driver to use

Member Function Documentation

int64_t Luminous::StateGL::availableUploadBytes ( ) const
inline

Get the number of bytes available for uploading content to the GPU.

This limit is used to spread heavy upload operations across multiple rendering frames to avoid stalling the application.

Returns
number of bytes available
StateGL::BufferMaps & Luminous::StateGL::bufferMaps ( )
inline

Get the cache for active buffer mappings.

Returns
buffer mapping cache
void Luminous::StateGL::clearUploadedBytes ( )
inline

Sets the number of available upload bytes to zero.

See Also
consumeUploadBytes
void Luminous::StateGL::consumeUploadBytes ( int64_t  bytes)
inline

Consume the given amount of bytes from the upload budget.

This function decreases the upload budget by the given amount.

Parameters
bytesnumber of bytes to consume
See Also
availableUploadBytes
GLuint Luminous::StateGL::drawFramebuffer ( ) const
inline

Get the handle to the current draw framebuffer.

Returns
framebuffer handle
RenderDriverGL& Luminous::StateGL::driver ( )
inline

Get the render driver associated with this state.

Returns
render driver
Radiant::TimeStamp Luminous::StateGL::frameTime ( ) const
inline

Get the current frame time.

Returns
frame time
GLuint Luminous::StateGL::program ( ) const
inline

Get the current program object handle.

Returns
current program object handle
GLuint Luminous::StateGL::readFramebuffer ( ) const
inline

Get the handle to the current read framebuffer.

Returns
framebuffer handle
bool Luminous::StateGL::setFramebuffer ( GLenum  target,
GLuint  handle 
)
inline

Set the current framebuffer.

Parameters
targetframebuffer target (GL_READ_FRAMEBUFFER, GL_FRAMEBUFFER, GL_DRAW_FRAMEBUFFER)
handlehandle to the framebuffer
Returns
true if the current framebuffer was changed; otherwise false
void Luminous::StateGL::setFrameTime ( Radiant::TimeStamp  t)
inline

Set the frame time.

The frame time is used to keep track of resource expiration.

Parameters
tframe time
bool Luminous::StateGL::setProgram ( GLuint  handle)
inline

Sets the current program object.

Parameters
handlehandle to the program object
Returns
true if current program was changed
bool Luminous::StateGL::setTextureUnit ( int  index)
inline

Set the current active texture unit.

Indexing starts from zero.

Parameters
indextexture unit index
void Luminous::StateGL::setUpdateFrequency ( int64_t  fps)
inline

Set the target update frequency.

This is only used to calculate frame-based upload limits

Parameters
fpstarget frames per second
void Luminous::StateGL::setUploadLimits ( int64_t  limit,
int64_t  margin 
)
inline

Set the maximum and minimum number of bytes per second for uploading content to the GPU.

Parameters
limitmaximum number of bytes to upload per second
marginminimum number of bytes to upload per second
bool Luminous::StateGL::setVertexArray ( GLuint  handle)
inline

Set the current vertex array.

Parameters
handlevertex array handle
Returns
true if the current vertex array was changed
int Luminous::StateGL::textureUnit ( ) const
inline

Get the current active texture unit.

Returns
active texture unit
unsigned int Luminous::StateGL::threadIndex ( ) const
inline

Get the render thread index this state object was associated with.

Returns
render thread index
int64_t Luminous::StateGL::uploadLimit ( ) const
inline

Get the maximum number of bytes per second used for uploading content to the GPU.

Returns
number of bytes per second
int64_t Luminous::StateGL::uploadMargin ( ) const
inline

Get the minimum number of bytes per second used for uploading content to the GPU.

Returns
number of bytes per second
GLuint Luminous::StateGL::vertexArray ( ) const
inline

Get the current vertex array.

Returns
current vertex array handle