Vuo  0.9.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Macros | Typedefs | Functions | Variables
VuoGlPool.cc File Reference

Description

VuoGlPool implementation.

Classes

struct  VuoIoSurfacePoolEntryType
 An entry in the IOSurface pool. More...
 

Macros

#define RETURN_STRING_IF_EQUAL(value)   if (constant == value) return #value
 Helper for VuoGl_stringForConstant.
 

Typedefs

typedef map< GLuint, unsigned int > VuoGlPoolReferenceCounts
 The number of times each OpenGL Buffer Object is retained.
 
typedef pair< unsigned short,
unsigned short > 
VuoGlTextureDimensionsType
 Texture width and height.
 
typedef pair< queue< GLuint >
, double > 
VuoGlTextureLastUsed
 A queue of textures of a given format and size, including the last time any of the textures were used.
 
typedef map< GLenum, map
< VuoGlTextureDimensionsType,
VuoGlTextureLastUsed > > 
VuoGlTexturePoolType
 VuoGlTexturePool[internalformat][size] gives a list of unused textures.
 
typedef map< GLuint, unsigned int > VuoGlTextureReferenceCounts
 The number of times each glTextureName is retained..
 
typedef map
< VuoGlTextureDimensionsType,
deque
< VuoIoSurfacePoolEntryType > > 
VuoIoSurfacePoolType
 VuoIoSurfacePoolType[size] gives a list of IOSurfaces.
 

Functions

static map< VuoGlPoolType, map
< unsigned long, vector
< GLuint > > > VuoGlPool 
__attribute__ ((init_priority(101)))
 The reference count for each OpenGL Buffer Object.
 
static void __attribute__ ((constructor)) VuoGlTexturePool_init(void)
 Initializes the GL Texture Pool.
 
GLuint VuoGlPool_use (VuoGlPoolType type, unsigned long size)
 Returns an OpenGL Buffer Object of type type.
 
void VuoGlPool_disuse (VuoGlPoolType type, unsigned long size, GLuint name)
 Indicates that the caller is done using the OpenGL object name of type type.
 
void VuoGlPool_retainF (GLuint glBufferName, const char *file, unsigned int line, const char *func)
 Helper for VuoGlPool_retain.
 
void VuoGlPool_releaseF (VuoGlPoolType type, unsigned long size, GLuint glBufferName, const char *file, unsigned int line, const char *func)
 Helper for VuoGlPool_release.
 
static double VuoGlTexturePool_getTime (void)
 Returns the number of seconds (including fractional seconds) since midnight 1970.01.01 GMT.
 
static void VuoGlTexturePool_cleanup (void *blah)
 Purges expired textures from the GL Texture Pool.
 
static void __attribute__ ((destructor)) VuoGlTexturePool_fini(void)
 Destroys the GL Texture Pool.
 
GLuint VuoGlTexture_getType (GLuint format)
 Returns the OpenGL texture data type corresponding with OpenGL texture format.
 
GLuint VuoGlTexturePool_use (VuoGlContext glContext, GLenum internalformat, unsigned short width, unsigned short height, GLenum format)
 Returns an OpenGL texture.
 
static void VuoGlTexurePool_disuse (VuoGlContext glContext, GLenum internalformat, unsigned short width, unsigned short height, GLuint name)
 Indicates that the caller is done using the OpenGL texture name.
 
void VuoGlTexture_retain (GLuint glTextureName)
 Increments the reference count for glTextureName.
 
void VuoGlTexture_release (GLenum internalformat, unsigned short width, unsigned short height, GLuint glTextureName)
 Decrements the reference count for glTextureName.
 
static void VuoIoSurfacePool_cleanup (void *blah)
 Periodically cleans up the IOSurface pool.
 
VuoIoSurface VuoIoSurfacePool_use (VuoGlContext glContext, unsigned short pixelsWide, unsigned short pixelsHigh, GLuint *outputTexture)
 Returns an IOSurface (backed by outputTexture) with the specified dimensions.
 
uint32_t VuoIoSurfacePool_getId (VuoIoSurface ioSurface)
 Returns the IOSurface's interprocess ID.
 
void VuoIoSurfacePool_disuse (VuoGlContext glContext, unsigned short pixelsWide, unsigned short pixelsHigh, VuoIoSurface ioSurface, GLuint texture)
 Called by the sending end of an IOSurface texture transfer to indicate that it is finished using the IOSurface's texture.
 
void VuoIoSurfacePool_signal (VuoIoSurface ioSurface)
 Called by the receiving end of an IOSurface texture transfer to indicate that it is finished using the IOSurface's texture.
 
void VuoGlShader_printShaderInfoLog (CGLContextObj cgl_ctx, GLuint obj)
 Prints GLSL debug information to the console.
 
string VuoGlShader_replaceInclude (string source, string includeFileName, const unsigned char *includeContents, unsigned int includeContentsLength)
 If source contains the string include(includeFileName), replaces that string with includeContents.
 
GLuint VuoGlShader_use (VuoGlContext glContext, GLenum type, const char *source)
 Returns an OpenGL Shader Object representing the specified source.
 
const char * VuoGl_stringForConstant (GLenum constant)
 Returns a string for the specified OpenGL constant.
 

Variables

static dispatch_semaphore_t VuoGlPool_semaphore
 Serializes access to VuoGlPool.
 
static dispatch_semaphore_t VuoGlPool_referenceCountsSemaphore = NULL
 Synchronizes access to VuoGlPool_referenceCounts.
 
static VuoGlTexturePoolTypeVuoGlTexturePool
 A pool of GL Textures.
 
static dispatch_semaphore_t VuoGlTexturePool_semaphore
 Serializes access to VuoGlTexturePool.
 
static dispatch_semaphore_t VuoGlTexturePool_canceledAndCompleted
 Signals when the last VuoGlTexturePool cleanup has completed.
 
static dispatch_source_t VuoGlTexturePool_timer
 Periodically cleans up VuoGlTexturePool.
 
static double textureTimeout = 0.1
 Seconds a texture can remain in the pool unused, before it gets purged.
 
static dispatch_semaphore_t VuoGlTexture_referenceCountsSemaphore = NULL
 Synchronizes access to VuoGlTexture_referenceCounts.
 
static VuoIoSurfacePoolTypeVuoIoSurfacePool
 Unused IOSurfaces.
 
static VuoIoSurfacePoolTypeVuoIoSurfaceQuarantine
 IOSurfaces which might still be in use by the receiver.
 
static dispatch_semaphore_t VuoIoSurfacePool_semaphore
 Serializes access to the IOSurface pool.
 
static dispatch_semaphore_t VuoIoSurfacePool_canceledAndCompleted
 Signals when the last IOSurface pool cleanup has completed.
 
static dispatch_source_t VuoIoSurfacePool_timer
 Periodically cleans up the IOSurface pool.
 
static CFStringRef receiverFinishedWithIoSurfaceKey = CFSTR("VuoReceiverFinished")
 Signals from the receiver to the sender, when the receiver is finished using the IOSurface.
 
static double ioSurfaceCleanupInterval = 0.1
 Interval (in seconds) to promote IOSurfaces from the quarantine to the pool, and to clean old IOSurfaces from the pool.
 
dispatch_semaphore_t VuoGlShaderPool_semaphore = NULL
 Synchronizes access to VuoGlShaderPool.
 

Class Documentation

struct VuoIoSurfacePoolEntryType
Class Members
VuoIoSurface ioSurface
double lastUsedTime
GLuint texture

Macro Definition Documentation

#define RETURN_STRING_IF_EQUAL (   value)    if (constant == value) return #value

Typedef Documentation

typedef map<GLuint, unsigned int> VuoGlPoolReferenceCounts

The number of times each OpenGL Buffer Object is retained.

typedef pair<unsigned short,unsigned short> VuoGlTextureDimensionsType

Texture width and height.

typedef pair<queue<GLuint>,double> VuoGlTextureLastUsed

A queue of textures of a given format and size, including the last time any of the textures were used.

VuoGlTexturePool[internalformat][size] gives a list of unused textures.

typedef map<GLuint, unsigned int> VuoGlTextureReferenceCounts

The number of times each glTextureName is retained..

VuoIoSurfacePoolType[size] gives a list of IOSurfaces.

Function Documentation

map< GLenum, map< long, GLuint > > VuoGlShaderPool __attribute__ ( (init_priority(101))  )
static

The reference count for each OpenGL Buffer Object.

Shaders, keyed by type (vertex, fragment, ...) and source code hash.

The reference count for each OpenGL Texture Object.

__attribute__ ( (constructor)  )
static

Initializes the GL Texture Pool.

Initializes VuoGlShaderPool_semaphore.

static void __attribute__ ( (destructor)  )
static

Destroys the GL Texture Pool.

const char* VuoGl_stringForConstant ( GLenum  constant)

Returns a string for the specified OpenGL constant.

Don't free the string returned by this function.

void VuoGlPool_disuse ( VuoGlPoolType  type,
unsigned long  size,
GLuint  name 
)

Indicates that the caller is done using the OpenGL object name of type type.

The object is returned to the pool, so other callers can use it (which is more efficient than deleting and re-generating objects).

This function may be called from any thread. (However, the caller is responsible for ensuring that the GL context is not used simultaneously on multiple threads.)

void VuoGlPool_releaseF ( VuoGlPoolType  type,
unsigned long  size,
GLuint  glBufferName,
const char *  file,
unsigned int  line,
const char *  func 
)

Helper for VuoGlPool_release.

void VuoGlPool_retainF ( GLuint  glBufferName,
const char *  file,
unsigned int  line,
const char *  func 
)

Helper for VuoGlPool_retain.

GLuint VuoGlPool_use ( VuoGlPoolType  type,
unsigned long  size 
)

Returns an OpenGL Buffer Object of type type.

If an existing, unused buffer of the specified type and size is available, it is returned. Otherwise, a new buffer is created.

Todo:
https://b33p.net/kosada/node/6901 The returned buffer's storage ~~is~~ will be preallocated (so the caller can efficiently upload data using glBufferSubData),

This function may be called from any thread. (However, the caller is responsible for ensuring that the GL context is not used simultaneously on multiple threads.)

Todo:
https://b33p.net/kosada/node/6901
void VuoGlShader_printShaderInfoLog ( CGLContextObj  cgl_ctx,
GLuint  obj 
)

Prints GLSL debug information to the console.

This function may be called from any thread. (However, the caller is responsible for ensuring that the GL context is not used simultaneously on multiple threads.)

string VuoGlShader_replaceInclude ( string  source,
string  includeFileName,
const unsigned char *  includeContents,
unsigned int  includeContentsLength 
)

If source contains the string include(includeFileName), replaces that string with includeContents.

GLuint VuoGlShader_use ( VuoGlContext  glContext,
GLenum  type,
const char *  source 
)

Returns an OpenGL Shader Object representing the specified source.

To improve performance, this function keeps a cache of precompiled shaders. If a precompiled shader exists for the specified source, that shader is returned. Otherwise, source is passed off to OpenGL to be compiled.

Do not call glDeleteShaders() on the returned shader; it's expected to persist throughout the lifetime of the process.

GLuint VuoGlTexture_getType ( GLuint  format)

Returns the OpenGL texture data type corresponding with OpenGL texture format.

Assumes format refers to an 8-bits-per-channel texture.

void VuoGlTexture_release ( GLenum  internalformat,
unsigned short  width,
unsigned short  height,
GLuint  glTextureName 
)

Decrements the reference count for glTextureName.

This function may be called from any thread.

void VuoGlTexture_retain ( GLuint  glTextureName)

Increments the reference count for glTextureName.

This function may be called from any thread.

static void VuoGlTexturePool_cleanup ( void *  blah)
static

Purges expired textures from the GL Texture Pool.

static double VuoGlTexturePool_getTime ( void  )
static

Returns the number of seconds (including fractional seconds) since midnight 1970.01.01 GMT.

GLuint VuoGlTexturePool_use ( VuoGlContext  glContext,
GLenum  internalformat,
unsigned short  width,
unsigned short  height,
GLenum  format 
)

Returns an OpenGL texture.

If an existing, unused texture matching the specified internalformat, width, and height is available, it is returned. Otherwise, a new texture is created.

The returned texture's storage is preallocated (so the caller can efficiently upload data using glTexSubImage2D), and its texturing properties are set to the defaults:

  • wrapping: clamp to border
  • filtering: linear

See glTexImage2D for information about internalformat and format.

This function may be called from any thread. (However, the caller is responsible for ensuring that the GL context is not used simultaneously on multiple threads.)

static void VuoGlTexurePool_disuse ( VuoGlContext  glContext,
GLenum  internalformat,
unsigned short  width,
unsigned short  height,
GLuint  name 
)
static

Indicates that the caller is done using the OpenGL texture name.

The texture is returned to the pool, so other callers can use it (which is more efficient than deleting and re-generating textures).

This function may be called from any thread. (However, the caller is responsible for ensuring that the GL context is not used simultaneously on multiple threads.)

static void VuoIoSurfacePool_cleanup ( void *  blah)
static

Periodically cleans up the IOSurface pool.

void VuoIoSurfacePool_disuse ( VuoGlContext  glContext,
unsigned short  pixelsWide,
unsigned short  pixelsHigh,
VuoIoSurface  ioSurface,
GLuint  texture 
)

Called by the sending end of an IOSurface texture transfer to indicate that it is finished using the IOSurface's texture.

This enables the IOSurface to be reused for another texture transfer (once the receiving end indicates it is done with it, via VuoIoSurfacePool_signal()).

uint32_t VuoIoSurfacePool_getId ( VuoIoSurface  ioSurface)

Returns the IOSurface's interprocess ID.

void VuoIoSurfacePool_signal ( VuoIoSurface  ioSurface)

Called by the receiving end of an IOSurface texture transfer to indicate that it is finished using the IOSurface's texture.

This enables the sender to reuse the IOSurface for another texture transfer.

VuoIoSurface VuoIoSurfacePool_use ( VuoGlContext  glContext,
unsigned short  pixelsWide,
unsigned short  pixelsHigh,
GLuint *  outputTexture 
)

Returns an IOSurface (backed by outputTexture) with the specified dimensions.

Uses an IOSurface from the pool, if possible. If not, creates a new IOSurface.

Variable Documentation

double ioSurfaceCleanupInterval = 0.1
static

Interval (in seconds) to promote IOSurfaces from the quarantine to the pool, and to clean old IOSurfaces from the pool.

CFStringRef receiverFinishedWithIoSurfaceKey = CFSTR("VuoReceiverFinished")
static

Signals from the receiver to the sender, when the receiver is finished using the IOSurface.

double textureTimeout = 0.1
static

Seconds a texture can remain in the pool unused, before it gets purged.

dispatch_semaphore_t VuoGlPool_referenceCountsSemaphore = NULL
static

Synchronizes access to VuoGlPool_referenceCounts.

dispatch_semaphore_t VuoGlPool_semaphore
static

Serializes access to VuoGlPool.

dispatch_semaphore_t VuoGlShaderPool_semaphore = NULL

Synchronizes access to VuoGlShaderPool.

dispatch_semaphore_t VuoGlTexture_referenceCountsSemaphore = NULL
static

Synchronizes access to VuoGlTexture_referenceCounts.

VuoGlTexturePoolType* VuoGlTexturePool
static

A pool of GL Textures.

dispatch_semaphore_t VuoGlTexturePool_canceledAndCompleted
static

Signals when the last VuoGlTexturePool cleanup has completed.

dispatch_semaphore_t VuoGlTexturePool_semaphore
static

Serializes access to VuoGlTexturePool.

dispatch_source_t VuoGlTexturePool_timer
static

Periodically cleans up VuoGlTexturePool.

VuoIoSurfacePoolType* VuoIoSurfacePool
static

Unused IOSurfaces.

dispatch_semaphore_t VuoIoSurfacePool_canceledAndCompleted
static

Signals when the last IOSurface pool cleanup has completed.

dispatch_semaphore_t VuoIoSurfacePool_semaphore
static

Serializes access to the IOSurface pool.

dispatch_source_t VuoIoSurfacePool_timer
static

Periodically cleans up the IOSurface pool.

VuoIoSurfacePoolType* VuoIoSurfaceQuarantine
static

IOSurfaces which might still be in use by the receiver.