Vuo  1.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Typedefs | Functions | Variables
VuoSceneRenderer.cc File Reference

Description

VuoSceneRenderer implementation.

Classes

class  VuoSceneRendererInternal_object
 GL Objects corresponding with a VuoSceneObject instance. More...
 
class  VuoSceneRendererInternal
 Internal state data for a VuoSceneRenderer instance. More...
 

Macros

#define glGenVertexArrays   glGenVertexArraysAPPLE
 
#define glBindVertexArray   glBindVertexArrayAPPLE
 
#define glDeleteVertexArrays   glDeleteVertexArraysAPPLE
 

Typedefs

typedef std::list< GLuint > VuoSceneRendererVAOList
 The VAO for each VuoSubmesh.
 
typedef std::pair< void *, void * > VuoSceneRendererMeshShader
 A VuoMesh/VuoShader combination.
 
typedef std::map
< VuoSceneRendererMeshShader,
VuoSceneRendererVAOList
VuoSceneRendererMeshShaderVAOs
 The VAO for each VuoMesh/VuoShader combination.
 

Functions

static void __attribute__ ((constructor)) VuoSceneRenderer_init()
 Initialize VuoSceneRenderer_vertexArraySemaphore.
 
void VuoSceneRenderer_destroy (VuoSceneRenderer sr)
 Destroys and deallocates the scene renderer.
 
static void VuoSceneRenderer_prepareContext (CGLContextObj cgl_ctx)
 Configures OpenGL state for the specified context.
 
static void VuoSceneRenderer_uploadSceneObject (VuoSceneRendererInternal *sceneRenderer, VuoSceneObject so, VuoSceneRendererInternal_object *soi, VuoGlContext glContext, bool cache)
 Binds the relevant (given the current shader) parts of so to an OpenGL Vertex Array Object.
 
VuoSceneRenderer VuoSceneRenderer_make (VuoGlContext glContext, float backingScaleFactor)
 Creates a reference-counted object for rendering a scenegraph.
 
static void VuoSceneRenderer_regenerateProjectionMatrixInternal (VuoSceneRendererInternal *sceneRenderer)
 Helper for VuoSceneRenderer_regenerateProjectionMatrix and VuoSceneRenderer_draw.
 
void VuoSceneRenderer_regenerateProjectionMatrix (VuoSceneRenderer sr, unsigned int width, unsigned int height)
 Using the first camera found in the scene (or VuoSceneObject_makeDefaultCamera() if there is no camera in the scene), recalculates the projection matrix based on the specified viewport width and height.
 
static void VuoSceneRenderer_addUniformSuffix (char *address, int i, const char *suffix)
 Overwrites address with a null-terminated string consisting of i (converted to string, assumed to be between 0 and 19 inclusive) followed by suffix.
 
static void VuoSceneRenderer_drawSceneObject (VuoSceneObject so, VuoSceneRendererInternal_object *soi, float projectionMatrix[16], float modelviewMatrix[16], VuoSceneRendererInternal *sceneRenderer)
 Draws so (using the uploaded object names in soi).
 
static void VuoSceneRenderer_drawSceneObjectsRecursively (VuoSceneObject so, VuoSceneRendererInternal_object *soi, float projectionMatrix[16], float modelviewMatrix[16], VuoSceneRendererInternal *sceneRenderer)
 Draws so and its child objects.
 
static void VuoSceneRenderer_cleanupSceneObjectsRecursively (VuoSceneObject so, VuoSceneRendererInternal_object *soi, VuoGlContext glContext)
 Cleans up internal state created by VuoSceneRenderer_uploadSceneObjectsRecursively.
 
static void VuoSceneRenderer_cleanupMeshShaderItems (VuoSceneRendererInternal *sceneRenderer)
 Releases the GPU objects created by VuoSceneRenderer_uploadSceneObjectsRecursively.
 
static void VuoSceneRenderer_uploadSceneObjectsRecursively (VuoSceneRendererInternal *sceneRenderer, VuoSceneObject so, VuoSceneRendererInternal_object *soi, VuoGlContext glContext)
 Uploads so and its child objects to the GPU, and stores the uploaded object names in soi.
 
void VuoSceneRenderer_draw (VuoSceneRenderer sr)
 Uploads the scene to the GPU (if it's changed), and renders it.
 
void VuoSubmeshMesh_download (VuoSubmesh *submesh)
 Copies element data from GPU back to the CPU.
 
static void VuoSceneRenderer_renderText (VuoSceneRendererInternal *sceneRenderer, VuoSceneObject so, VuoSceneRendererInternal_object *soi)
 Draws all vertex normals in so.
 
void VuoSceneRenderer_setRootSceneObject (VuoSceneRenderer sr, VuoSceneObject rootSceneObject)
 Changes the scenegraph to be rendered.
 
VuoSceneObject VuoSceneRenderer_getRootSceneObject (VuoSceneRenderer sr, bool *isValid)
 Returns the scenegraph to be rendered.
 
void VuoSceneRenderer_setCameraName (VuoSceneRenderer sr, VuoText cameraName, VuoBoolean useLeftCamera)
 Changes the name of the camera to look for.
 
void VuoSceneRenderer_renderToImage (VuoSceneRenderer sr, VuoImage *image, VuoImageColorDepth imageColorDepth, VuoMultisample multisample, VuoImage *depthImage)
 Creates an OpenGL Framebuffer Object, and uses it to render the scene to image and depthImage.
 

Variables

dispatch_semaphore_t VuoSceneRenderer_vertexArraySemaphore
 Work around apparent GL driver bug, wherein attempting to simultaneously bind the same buffer to multiple VAOs on separate contexts causes a crash.
 

Class Documentation

class VuoSceneRendererInternal
Class Members
float ambientBrightness
VuoColor ambientColor
float backingScaleFactor
VuoSceneObject camera
float cameraMatrixInverse[16] Column-major 4x4 matrix.
VuoText cameraName
VuoGlContext glContext
VuoSceneRendererMeshShaderVAOs meshShaderItems Given a VuoMesh and a VuoShader, stores a set of VAOs.
bool needToRegenerateProjectionMatrix
VuoList_VuoSceneObject pointLights
float projectionMatrix[16] Column-major 4x4 matrix.
VuoSceneObject rootSceneObject The latest scene that's actually been uploaded and drawn.
VuoSceneRendererInternal_object rootSceneObjectInternal
VuoSceneObject rootSceneObjectPending The latest scene from VuoSceneRenderer_setRootSceneObject().
bool rootSceneObjectPendingUpdated Whether rootSceneObjectPending contains a new scene (compared to rootSceneObject).
bool rootSceneObjectPendingValid Whether rootSceneObjectPending has already been initialized.
bool rootSceneObjectValid Whether rootSceneObject has already been initialized (and uploaded and drawn).
dispatch_semaphore_t scenegraphSemaphore Serializes access to other data in this structure.
VuoList_VuoSceneObject spotLights
VuoBoolean useLeftCamera
unsigned int viewportHeight
unsigned int viewportWidth
VuoSceneObject vignetteQuad
VuoSceneRendererInternal_object vignetteQuadInternal
VuoShader vignetteShader

Typedef Documentation

typedef std::pair<void *, void *> VuoSceneRendererMeshShader

A VuoMesh/VuoShader combination.

The VAO for each VuoMesh/VuoShader combination.

typedef std::list<GLuint> VuoSceneRendererVAOList

The VAO for each VuoSubmesh.

Function Documentation

static void __attribute__ ( (constructor)  )
static

Initialize VuoSceneRenderer_vertexArraySemaphore.

static void VuoSceneRenderer_addUniformSuffix ( char *  address,
int  i,
const char *  suffix 
)
static

Overwrites address with a null-terminated string consisting of i (converted to string, assumed to be between 0 and 19 inclusive) followed by suffix.

static void VuoSceneRenderer_cleanupMeshShaderItems ( VuoSceneRendererInternal sceneRenderer)
static

Releases the GPU objects created by VuoSceneRenderer_uploadSceneObjectsRecursively.

static void VuoSceneRenderer_cleanupSceneObjectsRecursively ( VuoSceneObject  so,
VuoSceneRendererInternal_object soi,
VuoGlContext  glContext 
)
static

Cleans up internal state created by VuoSceneRenderer_uploadSceneObjectsRecursively.

Must be called while scenegraphSemaphore is locked.

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 VuoSceneRenderer_destroy ( VuoSceneRenderer  sr)

Destroys and deallocates the scene renderer.

This function may be called from any thread.

void VuoSceneRenderer_draw ( VuoSceneRenderer  sr)

Uploads the scene to the GPU (if it's changed), and renders it.

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 VuoSceneRenderer_drawSceneObject ( VuoSceneObject  so,
VuoSceneRendererInternal_object soi,
float  projectionMatrix[16],
float  modelviewMatrix[16],
VuoSceneRendererInternal sceneRenderer 
)
static

Draws so (using the uploaded object names in soi).

Does not traverse child objects.

Must be called while scenegraphSemaphore is locked.

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 VuoSceneRenderer_drawSceneObjectsRecursively ( VuoSceneObject  so,
VuoSceneRendererInternal_object soi,
float  projectionMatrix[16],
float  modelviewMatrix[16],
VuoSceneRendererInternal sceneRenderer 
)
static

Draws so and its child objects.

Must be called while scenegraphSemaphore is locked.

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

VuoSceneObject VuoSceneRenderer_getRootSceneObject ( VuoSceneRenderer  sr,
bool *  isValid 
)

Returns the scenegraph to be rendered.

This function only returns valid data after VuoSceneRenderer_draw has been called.

This function may be called from any thread.

VuoSceneRenderer VuoSceneRenderer_make ( VuoGlContext  glContext,
float  backingScaleFactor 
)

Creates a reference-counted object for rendering a scenegraph.

This function may be called from any thread.

static void VuoSceneRenderer_prepareContext ( CGLContextObj  cgl_ctx)
static

Configures OpenGL state for the specified context.

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 VuoSceneRenderer_regenerateProjectionMatrix ( VuoSceneRenderer  sr,
unsigned int  width,
unsigned int  height 
)

Using the first camera found in the scene (or VuoSceneObject_makeDefaultCamera() if there is no camera in the scene), recalculates the projection matrix based on the specified viewport width and height.

This function may be called from any thread.

void VuoSceneRenderer_regenerateProjectionMatrixInternal ( VuoSceneRendererInternal sceneRenderer)
static

Helper for VuoSceneRenderer_regenerateProjectionMatrix and VuoSceneRenderer_draw.

Must be called while scenegraphSemaphore is locked.

static void VuoSceneRenderer_renderText ( VuoSceneRendererInternal sceneRenderer,
VuoSceneObject  so,
VuoSceneRendererInternal_object soi 
)
static

Draws all vertex normals in so.

Must be called while scenegraphSemaphore is locked.

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.) Draws a circle using OpenGL immediate mode. For debugging only. Draws a cone using OpenGL immediate mode. For debugging only. Draws the scene's point and spot lights. Creates a mesh and image for the specified sceneobject.

void VuoSceneRenderer_renderToImage ( VuoSceneRenderer  sr,
VuoImage image,
VuoImageColorDepth  imageColorDepth,
VuoMultisample  multisample,
VuoImage depthImage 
)

Creates an OpenGL Framebuffer Object, and uses it to render the scene to image and depthImage.

void VuoSceneRenderer_setCameraName ( VuoSceneRenderer  sr,
VuoText  cameraName,
VuoBoolean  useLeftCamera 
)

Changes the name of the camera to look for.

The first camera whose name contains cameraName will be rendered (next time VuoSceneRenderer_draw() is called), or, if no camera matches, VuoSceneObject_makeDefaultCamera() will be used.

If cameraName is stereoscopic, useLeftCamera selects between the left and right cameras in the stereo pair.

This function may be called from any thread.

void VuoSceneRenderer_setRootSceneObject ( VuoSceneRenderer  sr,
VuoSceneObject  rootSceneObject 
)

Changes the scenegraph to be rendered.

This function retains the scene, but it isn't uploaded to the GPU until you call VuoSceneRenderer_draw.

This function may be called from any thread.

static void VuoSceneRenderer_uploadSceneObject ( VuoSceneRendererInternal sceneRenderer,
VuoSceneObject  so,
VuoSceneRendererInternal_object soi,
VuoGlContext  glContext,
bool  cache 
)
static

Binds the relevant (given the current shader) parts of so to an OpenGL Vertex Array Object.

Does not traverse child objects.

Must be called while scenegraphSemaphore is locked.

If cache is true, the VAO is cached in sceneRenderer->meshShaderItems (which gets cleaned up by VuoSceneRenderer_cleanupMeshShaderItems each time the root sceneobject is changed).

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 VuoSceneRenderer_uploadSceneObjectsRecursively ( VuoSceneRendererInternal sceneRenderer,
VuoSceneObject  so,
VuoSceneRendererInternal_object soi,
VuoGlContext  glContext 
)
static

Uploads so and its child objects to the GPU, and stores the uploaded object names in soi.

Must be called while scenegraphSemaphore is locked.

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 VuoSubmeshMesh_download ( VuoSubmesh submesh)

Copies element data from GPU back to the CPU.

Variable Documentation

dispatch_semaphore_t VuoSceneRenderer_vertexArraySemaphore

Work around apparent GL driver bug, wherein attempting to simultaneously bind the same buffer to multiple VAOs on separate contexts causes a crash.

(Try running CompareCameras.vuo without this.)

Also, using VuoSceneObjectRenderer and VuoSceneRender simultaneously seems to lead to crashes, so we also use this semaphore to serialize OpenGL Transform Feedback. https://b33p.net/kosada/node/8498