Vuo  2.0.0
Macros | Typedefs | Functions | Variables
VuoGlContext.cc File Reference

Description

VuoGlContext implementation.

Definition in file VuoGlContext.cc.

Go to the source code of this file.

Macros

#define VuoGlContext_checkGL(cap, value)
 Logs a warning if the specified OpenGL capability doesn't have value. More...
 
#define VuoGlContext_checkGLInt(key, value)
 Logs a warning if the specified OpenGL key doesn't have value. More...
 
#define VuoGlCheckBinding(pname)
 Check whether the specified attachment point pname is still bound. More...
 
#define VuoGlCheckTextureBinding(pname, unit)
 Check whether the specified attachment point pname is still bound. More...
 

Typedefs

typedef std::map< VuoGlContext, GLuint > VuoShaderContextType
 Type for VuoShaderContextMap. More...
 

Functions

static CGLContextObj VuoGlContext_create (CGLContextObj rootContext)
 Creates a new OpenGL context, optionally shared with rootContext. More...
 
static void VuoGlContext_renderers (void)
 Logs info about all available renderers. More...
 
void VuoGlContext_reconfig (CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *userInfo)
 Called when display settings change (a display is plugged in or unplugged, resolution is changed, …). More...
 
static void VuoGlContext_init ()
 Returns the process-wide pool singleton instance. More...
 
VuoGlContext VuoGlContext_use (void)
 Finds an unused GL context in the process-wide shared context pool (or creates one if none is available), marks it used, and returns it. More...
 
void VuoGlContext_disuseF (VuoGlContext glContext, const char *file, const unsigned int linenumber, const char *func)
 Throws the specified context back in the pool. More...
 
void VuoGlContext_perform (void(^function)(CGLContextObj cgl_ctx))
 Executes code using the global OpenGL context. More...
 
void VuoGlContext_setGlobalRootContext (void *rootContext)
 Specifies a platform-specific context to be used as the base for all of Vuo's shared GL contexts. More...
 
int VuoGlContext_getMaximumSupportedMultisampling (VuoGlContext context)
 Returns the maximum supported multisampling level for this GPU. More...
 
void * VuoGlContext_makePlatformPixelFormat (bool hasDepthBuffer, bool openGL32Core, GLint displayMask)
 Returns a platform-specific OpenGL pixelformat description. More...
 
bool VuoGlContext_isOpenGL32Core (VuoGlContext context)
 Returns true if the specified context is OpenGL 3.2+ Core Profile. More...
 
void _VGL_describe (GLenum error, CGLContextObj cgl_ctx, const char *file, const unsigned int linenumber, const char *func)
 Logs text describing the specified OpenGL error. More...
 
void _VGL (CGLContextObj cgl_ctx, const char *file, const unsigned int linenumber, const char *func)
 Helper for VGL(). More...
 

Variables

dispatch_semaphore_t VuoGlContext_poolSemaphore
 Serializes access to VuoGlContext_root, VuoGlContext_allSharedContexts and VuoGlContext_avaialbleSharedContexts. More...
 
static CGLContextObj VuoGlContext_root = NULL
 This process's global root context. More...
 
vector< CGLContextObj > VuoGlContext_allSharedContexts
 All contexts created by VuoGlContext_create (including those currently being used). More...
 
vector< CGLContextObj > VuoGlContext_avaialbleSharedContexts
 All unused contexts created by VuoGlContext_create. More...
 
static dispatch_once_t VuoGlContextPoolCreated = 0
 Make sure this process only has a single GL Context Pool. More...
 
static pthread_key_t VuoGlContextPerformKey
 Tracks whether perform is already in the current thread's callstack. More...
 
VuoShaderContextType VuoShaderContextMap
 The currently-active shader on each context. More...
 

Macro Definition Documentation

◆ VuoGlCheckBinding

#define VuoGlCheckBinding (   pname)
Value:
{ \
GLint value; \
glGetIntegerv(pname, &value); \
if (value) \
{ \
VuoLog(file, linenumber, func, #pname " (value %d) was still active when the context was disused. (This may result in leaks.)", value); \
VuoLog_backtrace(); \
} \
}

Check whether the specified attachment point pname is still bound.

(This is defined as a macro in order to stringify the argument.)

Definition at line 561 of file VuoGlContext.cc.

◆ VuoGlCheckTextureBinding

#define VuoGlCheckTextureBinding (   pname,
  unit 
)
Value:
{ \
GLint value; \
glGetIntegerv(pname, &value); \
if (value) \
{ \
VuoLog(file, linenumber, func, #pname " (texture %d on unit %d) was still active when the context was disused. (This may result in leaks.)", value, unit); \
VuoLog_backtrace(); \
} \
}

Check whether the specified attachment point pname is still bound.

(This is defined as a macro in order to stringify the argument.)

Definition at line 576 of file VuoGlContext.cc.

◆ VuoGlContext_checkGL

#define VuoGlContext_checkGL (   cap,
  value 
)
Value:
do { \
if (glIsEnabled(cap) != value) \
{ \
VUserLog("Warning: Caller incorrectly left %s %s", #cap, value ? "disabled" : "enabled"); \
VuoLog_backtrace(); \
} \
} while (0)

Logs a warning if the specified OpenGL capability doesn't have value.

Definition at line 355 of file VuoGlContext.cc.

◆ VuoGlContext_checkGLInt

#define VuoGlContext_checkGLInt (   key,
  value 
)
Value:
do { \
GLint actualValue; \
glGetIntegerv(key, &actualValue); \
if (actualValue != value) \
{ \
VUserLog("Warning: Caller incorrectly left %s set to something other than %s", #key, #value); \
VuoLog_backtrace(); \
} \
} while (0)

Logs a warning if the specified OpenGL key doesn't have value.

Definition at line 367 of file VuoGlContext.cc.

Typedef Documentation

◆ VuoShaderContextType

typedef std::map<VuoGlContext, GLuint> VuoShaderContextType

Type for VuoShaderContextMap.

Definition at line 840 of file VuoGlContext.cc.

Function Documentation

◆ _VGL()

void _VGL ( CGLContextObj  cgl_ctx,
const char *  file,
const unsigned int  linenumber,
const char *  func 
)

Helper for VGL().

Definition at line 768 of file VuoGlContext.cc.

◆ _VGL_describe()

void _VGL_describe ( GLenum  error,
CGLContextObj  cgl_ctx,
const char *  file,
const unsigned int  linenumber,
const char *  func 
)

Logs text describing the specified OpenGL error.

Definition at line 795 of file VuoGlContext.cc.

◆ VuoGlContext_create()

static CGLContextObj VuoGlContext_create ( CGLContextObj  rootContext)
static

Creates a new OpenGL context, optionally shared with rootContext.

Definition at line 448 of file VuoGlContext.cc.

◆ VuoGlContext_disuseF()

void VuoGlContext_disuseF ( VuoGlContext  glContext,
const char *  file,
const unsigned int  linenumber,
const char *  func 
)

Throws the specified context back in the pool.

This function may be called from any thread.

Definition at line 293 of file VuoGlContext.cc.

◆ VuoGlContext_getMaximumSupportedMultisampling()

int VuoGlContext_getMaximumSupportedMultisampling ( VuoGlContext  context)

Returns the maximum supported multisampling level for this GPU.

Multisampling is known to break point rendering on some GPUs, so we intentionally disable it on those.

Definition at line 592 of file VuoGlContext.cc.

◆ VuoGlContext_init()

static void VuoGlContext_init ( )
static

Returns the process-wide pool singleton instance.

Definition at line 234 of file VuoGlContext.cc.

◆ VuoGlContext_isOpenGL32Core()

bool VuoGlContext_isOpenGL32Core ( VuoGlContext  context)

Returns true if the specified context is OpenGL 3.2+ Core Profile.

Changed in Vuo 2.0.0:
New.

Definition at line 748 of file VuoGlContext.cc.

◆ VuoGlContext_makePlatformPixelFormat()

void* VuoGlContext_makePlatformPixelFormat ( bool  hasDepthBuffer,
bool  openGL32Core,
GLint  displayMask 
)

Returns a platform-specific OpenGL pixelformat description.

On Mac OS X, this is a CGLPixelFormatObj.

Parameters
hasDepthBufferIf true, the returned context will have a depth buffer.
openGL32CoreIf true, the returned context will be OpenGL 3.2 Core Profile. If false, OpenGL 2.1.
displayMaskIf -1, the context will not be restricted by display. If nonzero, the context will be restricted to the specified displays (CGDisplayIDToOpenGLDisplayMask()). If the low byte is 0xff, the context will use the Apple Software Renderer.
Returns
-1 if the displayMask is invalid. NULL if another error occurred.

Definition at line 631 of file VuoGlContext.cc.

◆ VuoGlContext_perform()

void VuoGlContext_perform ( void(^)(CGLContextObj cgl_ctx)  function)

Executes code using the global OpenGL context.

Example:
VuoGlContext_perform(^(CGLContextObj cgl_ctx){
glClear(…);
});

This function may be called from any thread.

Definition at line 392 of file VuoGlContext.cc.

◆ VuoGlContext_reconfig()

void VuoGlContext_reconfig ( CGDirectDisplayID  display,
CGDisplayChangeSummaryFlags  flags,
void *  userInfo 
)

Called when display settings change (a display is plugged in or unplugged, resolution is changed, …).

Definition at line 216 of file VuoGlContext.cc.

◆ VuoGlContext_renderers()

static void VuoGlContext_renderers ( void  )
static

Logs info about all available renderers.

Definition at line 44 of file VuoGlContext.cc.

◆ VuoGlContext_setGlobalRootContext()

void VuoGlContext_setGlobalRootContext ( void *  rootContext)

Specifies a platform-specific context to be used as the base for all of Vuo's shared GL contexts.

On Mac, this should be a CGLContext. The CGLContext must be unlocked when calling this function, but after that you may lock it at any time (Vuo doesn't require it to be locked or unlocked).

Must be called before any Vuo composition is loaded, and before any other VuoGlContext_* methods.

This function may be called from any thread.

Definition at line 545 of file VuoGlContext.cc.

◆ VuoGlContext_use()

VuoGlContext VuoGlContext_use ( void  )

Finds an unused GL context in the process-wide shared context pool (or creates one if none is available), marks it used, and returns it.

This function may be called from any thread.

Definition at line 254 of file VuoGlContext.cc.

Variable Documentation

◆ VuoGlContext_allSharedContexts

vector<CGLContextObj> VuoGlContext_allSharedContexts

All contexts created by VuoGlContext_create (including those currently being used).

Definition at line 35 of file VuoGlContext.cc.

◆ VuoGlContext_avaialbleSharedContexts

vector<CGLContextObj> VuoGlContext_avaialbleSharedContexts

All unused contexts created by VuoGlContext_create.

Definition at line 36 of file VuoGlContext.cc.

◆ VuoGlContext_poolSemaphore

dispatch_semaphore_t VuoGlContext_poolSemaphore

Serializes access to VuoGlContext_root, VuoGlContext_allSharedContexts and VuoGlContext_avaialbleSharedContexts.

Definition at line 33 of file VuoGlContext.cc.

◆ VuoGlContext_root

CGLContextObj VuoGlContext_root = NULL
static

This process's global root context.

Definition at line 34 of file VuoGlContext.cc.

◆ VuoGlContextPerformKey

pthread_key_t VuoGlContextPerformKey
static

Tracks whether perform is already in the current thread's callstack.

Definition at line 39 of file VuoGlContext.cc.

◆ VuoGlContextPoolCreated

dispatch_once_t VuoGlContextPoolCreated = 0
static

Make sure this process only has a single GL Context Pool.

Definition at line 38 of file VuoGlContext.cc.

◆ VuoShaderContextMap

VuoShaderContextType VuoShaderContextMap

The currently-active shader on each context.

This is placed in VuoGlContext (a dylib) instead of VuoShader (a static module) to ensure there's only one instance per process.

Definition at line 846 of file VuoGlContext.cc.