Vuo  2.3.2
Classes | Macros | Typedefs | Functions
VuoSceneRenderer.cc File Reference

Description

VuoSceneRenderer implementation.

Definition in file VuoSceneRenderer.cc.

Go to the source code of this file.

Classes

class  VuoSceneRendererInternal_object
 GL Objects corresponding with a VuoSceneObject instance. More...
 
struct  VuoSceneRenderer_TreeRenderState
 State for rendering an object at its particular place in the hierarchy. More...
 
class  VuoSceneRendererInternal
 Internal state data for a VuoSceneRenderer instance. More...
 
struct  VuoSceneRendererInternal::glState
 Store OpenGL state locally so we can change only when necessary, since calling glEnable/Disable marks the state dirty even if the state was unchanged. More...
 

Macros

#define VuoSceneRenderer_setGL(cap, value)
 Ensures the specified OpenGL capability is set to value (avoiding a state change if possible). More...
 
#define VuoSceneRenderer_setGLDepthMask(value)
 Ensures the OpenGL depth mask is set to value (avoiding a state change if possible). More...
 
#define VuoSceneRenderer_setGLFaceCulling(value)
 Ensures the OpenGL face culling mode is set to value (avoiding a state change if possible). More...
 
#define VuoSceneRenderer_setGLBlendFunction(srcRGB, dstRGB, srcAlpha, dstAlpha)
 Ensures the OpenGL blend function is set to the specified values (avoiding a state change if possible). More...
 
#define VuoSceneRenderer_setGLBlendEquation(modeRGB, modeAlpha)
 Ensures the OpenGL blend equation is set to the specified values (avoiding a state change if possible). More...
 
#define glGenVertexArrays   glGenVertexArraysAPPLE
 Stub. More...
 
#define glBindVertexArray   glBindVertexArrayAPPLE
 Stub. More...
 
#define glDeleteVertexArrays   glDeleteVertexArraysAPPLE
 Stub. More...
 

Typedefs

typedef std::pair< VuoMesh, VuoShaderVuoSceneRendererMeshShader
 A VuoMesh/VuoShader combination. More...
 
typedef std::map< VuoSceneRendererMeshShader, GLuint > VuoSceneRendererMeshShaderVAOs
 The VAO for each VuoMesh/VuoShader combination. More...
 

Functions

void VuoSceneRenderer_destroy (VuoSceneRenderer sr)
 Destroys and deallocates the scene renderer. More...
 
static bool VuoSceneRenderer_uploadSceneObject (VuoSceneRendererInternal *sceneRenderer, VuoSceneObject so, VuoSceneRendererInternal_object *soi, VuoGlContext glContext, bool cache)
 Draws all vertex normals in so. More...
 
VuoSceneRenderer VuoSceneRenderer_make (float backingScaleFactor)
 Creates a reference-counted object for rendering a scenegraph. More...
 
static void VuoSceneRenderer_regenerateProjectionMatrixInternal (VuoSceneRendererInternal *sceneRenderer)
 Helper for VuoSceneRenderer_regenerateProjectionMatrix and VuoSceneRenderer_draw. More...
 
static void VuoSceneRenderer_findCameraOrDefault (VuoSceneRendererInternal *sceneRenderer)
 Sets sceneRenderer->camera to the scenegraph's active camera (or, if there's no explicit camera in the scenegraph, sets it to the default camera). More...
 
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. More...
 
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. More...
 
void VuoSceneRenderer_checkDataBounds (CGLContextObj cgl_ctx, VuoMesh mesh, GLuint positionAttribute)
 Checks to ensure the currently-active VBO is correctly configured. More...
 
static void VuoSceneRenderer_drawSceneObject (VuoSceneObject so, VuoSceneRendererInternal_object *soi, float projectionMatrix[16], float modelviewMatrix[16], VuoSceneRendererInternal *sceneRenderer, VuoGlContext glContext)
 Draws so (using the uploaded object names in soi). More...
 
static void VuoSceneRenderer_drawSceneObjects (VuoSceneRendererInternal *sceneRenderer, VuoGlContext glContext, list< VuoSceneRenderer_TreeRenderState > &renderList)
 Draws so and its child objects. More...
 
static void VuoSceneRenderer_cleanupRenderLists (VuoSceneRendererInternal *sceneRenderer)
 Cleans up internal state created by VuoSceneRenderer_uploadSceneObjects. More...
 
static void VuoSceneRenderer_cleanupMeshShaderItems (VuoSceneRendererInternal *sceneRenderer, VuoGlContext glContext)
 Releases the GPU objects created by VuoSceneRenderer_uploadSceneObjects. More...
 
static void VuoSceneRenderer_uploadSceneObjects (VuoSceneRendererInternal *sceneRenderer, VuoGlContext glContext, VuoPoint3d cameraTranslation)
 Uploads so and its child objects to the GPU, and stores the uploaded object names in the opaqueObjects and potentiallyTransparentObjects render lists. More...
 
void VuoSceneRenderer_draw (VuoSceneRenderer sr, CGLContextObj cgl_ctx)
 Uploads the scene to the GPU (if it's changed), and renders it. More...
 
void VuoSceneRenderer_setRootSceneObject (VuoSceneRenderer sr, VuoSceneObject rootSceneObject)
 Changes the scenegraph to be rendered. More...
 
VuoSceneObject VuoSceneRenderer_getRootSceneObject (VuoSceneRenderer sr, bool *isValid)
 Returns the scenegraph to be rendered. More...
 
void VuoSceneRenderer_setCameraName (VuoSceneRenderer sr, VuoText cameraName, VuoBoolean useLeftCamera)
 Changes the name of the camera to look for. More...
 
bool VuoSceneRenderer_renderInternal (VuoSceneRenderer sr, VuoGlContext glContext, GLuint *outputTexture, GLenum target, GLuint imageGlInternalFormat, VuoMultisample multisample, GLuint *outputDepthTexture, bool invertDepthImage)
 Helper for VuoSceneRenderer_render*. More...
 
void VuoSceneRenderer_renderToImage (VuoSceneRenderer sr, VuoImage *image, VuoImageColorDepth imageColorDepth, VuoMultisample multisample, VuoImage *depthImage, bool invertDepthImage)
 Renders the scene onto image and optionally depthImage. More...
 
VuoIoSurface VuoSceneRenderer_renderToIOSurface (VuoSceneRenderer sr, VuoImageColorDepth imageColorDepth, VuoMultisample multisample, bool includeDepthBuffer)
 Renders the scene onto an IOSurface. More...
 

Class Documentation

◆ VuoSceneRenderer_TreeRenderState

struct VuoSceneRenderer_TreeRenderState
Class Members
float modelviewMatrix[16]
VuoSceneObject so
VuoSceneRendererInternal_object * soi

◆ VuoSceneRendererInternal

class VuoSceneRendererInternal
Class Members
float ambientBrightness
VuoColor ambientColor
float backingScaleFactor
VuoSceneObject camera
float cameraMatrixInverse[16] Column-major 4x4 matrix.
VuoText cameraName
GLint glContextRendererID
struct glState glState
VuoSceneRendererMeshShaderVAOs meshShaderItems Given a VuoMesh and a VuoShader, stores a set of VAOs.
list< VuoSceneRenderer_TreeRenderState > opaqueObjects
GLuint outputFramebuffer
GLuint outputFramebuffer2
VuoList_VuoSceneObject pointLights
list< VuoSceneRenderer_TreeRenderState > potentiallyTransparentObjects
float projectionMatrix[16] Column-major 4x4 matrix.
GLuint renderBuffer
GLuint renderDepthBuffer
VuoSceneObject rootSceneObject The latest scene that's actually been uploaded and drawn.
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.
VuoShader sharedTextOverrideShader
bool shouldSortByDepth If true, opaqueObjects and potentiallyTransparentObjects are ordered by distance from the camera (descending and ascending, respectively).

If false, only opaqueObjects is populated, ordered by depth-first traversal of the scenegraph.

VuoList_VuoSceneObject spotLights
VuoBoolean useLeftCamera
unsigned int viewportHeight
unsigned int viewportWidth
VuoSceneObject vignetteQuad
VuoSceneRendererInternal_object vignetteQuadInternal
VuoShader vignetteShader

◆ VuoSceneRendererInternal::glState

struct VuoSceneRendererInternal::glState
Class Members
GLenum vGL_BLEND_DST_ALPHA
GLenum vGL_BLEND_DST_RGB
GLenum vGL_BLEND_EQUATION_ALPHA
GLenum vGL_BLEND_EQUATION_RGB
GLenum vGL_BLEND_SRC_ALPHA
GLenum vGL_BLEND_SRC_RGB
bool vGL_CULL_FACE
GLenum vGL_CULL_FACE_MODE
bool vGL_DEPTH_MASK
bool vGL_DEPTH_TEST
bool vGL_SAMPLE_ALPHA_TO_COVERAGE
bool vGL_SAMPLE_ALPHA_TO_ONE

Macro Definition Documentation

◆ glBindVertexArray

#define glBindVertexArray   glBindVertexArrayAPPLE

Stub.

Definition at line 25 of file VuoSceneRenderer.cc.

◆ glDeleteVertexArrays

#define glDeleteVertexArrays   glDeleteVertexArraysAPPLE

Stub.

Definition at line 26 of file VuoSceneRenderer.cc.

◆ glGenVertexArrays

#define glGenVertexArrays   glGenVertexArraysAPPLE

Stub.

Definition at line 24 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_setGL

#define VuoSceneRenderer_setGL (   cap,
  value 
)
Value:
do { \
if (sceneRenderer->glState.v ## cap != value) \
{ \
if (value) \
glEnable(cap); \
else \
glDisable(cap); \
sceneRenderer->glState.v ## cap = value; \
} \
} while(0)

Ensures the specified OpenGL capability is set to value (avoiding a state change if possible).

Definition at line 174 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_setGLBlendEquation

#define VuoSceneRenderer_setGLBlendEquation (   modeRGB,
  modeAlpha 
)
Value:
do { \
if (sceneRenderer->glState.vGL_BLEND_EQUATION_RGB != modeRGB \
|| sceneRenderer->glState.vGL_BLEND_EQUATION_ALPHA != modeAlpha) \
{ \
glBlendEquationSeparate(modeRGB, modeAlpha); \
sceneRenderer->glState.vGL_BLEND_EQUATION_RGB = modeRGB; \
sceneRenderer->glState.vGL_BLEND_EQUATION_ALPHA = modeAlpha; \
} \
} while(0)

Ensures the OpenGL blend equation is set to the specified values (avoiding a state change if possible).

Definition at line 231 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_setGLBlendFunction

#define VuoSceneRenderer_setGLBlendFunction (   srcRGB,
  dstRGB,
  srcAlpha,
  dstAlpha 
)
Value:
do { \
if (sceneRenderer->glState.vGL_BLEND_SRC_RGB != srcRGB \
|| sceneRenderer->glState.vGL_BLEND_DST_RGB != dstRGB \
|| sceneRenderer->glState.vGL_BLEND_SRC_ALPHA != srcAlpha \
|| sceneRenderer->glState.vGL_BLEND_DST_ALPHA != dstAlpha) \
{ \
glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); \
sceneRenderer->glState.vGL_BLEND_SRC_RGB = srcRGB; \
sceneRenderer->glState.vGL_BLEND_DST_RGB = dstRGB; \
sceneRenderer->glState.vGL_BLEND_SRC_ALPHA = srcAlpha; \
sceneRenderer->glState.vGL_BLEND_DST_ALPHA = dstAlpha; \
} \
} while(0)

Ensures the OpenGL blend function is set to the specified values (avoiding a state change if possible).

Definition at line 213 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_setGLDepthMask

#define VuoSceneRenderer_setGLDepthMask (   value)
Value:
do { \
if (sceneRenderer->glState.vGL_DEPTH_MASK != value) \
{ \
glDepthMask(value); \
sceneRenderer->glState.vGL_DEPTH_MASK = value; \
} \
} while(0)

Ensures the OpenGL depth mask is set to value (avoiding a state change if possible).

Definition at line 189 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_setGLFaceCulling

#define VuoSceneRenderer_setGLFaceCulling (   value)
Value:
do { \
if (sceneRenderer->glState.vGL_CULL_FACE_MODE != value) \
{ \
glCullFace(value); \
sceneRenderer->glState.vGL_CULL_FACE_MODE = value; \
} \
} while(0)

Ensures the OpenGL face culling mode is set to value (avoiding a state change if possible).

Definition at line 201 of file VuoSceneRenderer.cc.

Typedef Documentation

◆ VuoSceneRendererMeshShader

A VuoMesh/VuoShader combination.

Definition at line 60 of file VuoSceneRenderer.cc.

◆ VuoSceneRendererMeshShaderVAOs

The VAO for each VuoMesh/VuoShader combination.

Definition at line 61 of file VuoSceneRenderer.cc.

Function Documentation

◆ VuoSceneRenderer_addUniformSuffix()

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.

Definition at line 485 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_checkDataBounds()

void VuoSceneRenderer_checkDataBounds ( CGLContextObj  cgl_ctx,
VuoMesh  mesh,
GLuint  positionAttribute 
)

Checks to ensure the currently-active VBO is correctly configured.

This is time-consuming (since it downloads data from the GPU), so it should be used sparingly (e.g., in debug mode).

Definition at line 503 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_cleanupMeshShaderItems()

static void VuoSceneRenderer_cleanupMeshShaderItems ( VuoSceneRendererInternal sceneRenderer,
VuoGlContext  glContext 
)
static

Releases the GPU objects created by VuoSceneRenderer_uploadSceneObjects.

Definition at line 1532 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_cleanupRenderLists()

static void VuoSceneRenderer_cleanupRenderLists ( VuoSceneRendererInternal sceneRenderer)
static

Cleans up internal state created by VuoSceneRenderer_uploadSceneObjects.

Must be called while scenegraphSemaphore is locked.

Definition at line 1510 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_destroy()

void VuoSceneRenderer_destroy ( VuoSceneRenderer  sr)

Destroys and deallocates the scene renderer.

This function may be called from any thread.

Definition at line 1613 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_draw()

void VuoSceneRenderer_draw ( VuoSceneRenderer  sr,
CGLContextObj  cgl_ctx 
)

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

Definition at line 968 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_drawSceneObject()

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

Definition at line 608 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_drawSceneObjects()

static void VuoSceneRenderer_drawSceneObjects ( VuoSceneRendererInternal sceneRenderer,
VuoGlContext  glContext,
list< VuoSceneRenderer_TreeRenderState > &  renderList 
)
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.)

Definition at line 943 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_findCameraOrDefault()

static void VuoSceneRenderer_findCameraOrDefault ( VuoSceneRendererInternal sceneRenderer)
static

Sets sceneRenderer->camera to the scenegraph's active camera (or, if there's no explicit camera in the scenegraph, sets it to the default camera).

Definition at line 303 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_getRootSceneObject()

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.

Definition at line 1575 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_make()

VuoSceneRenderer VuoSceneRenderer_make ( float  backingScaleFactor)

Creates a reference-counted object for rendering a scenegraph.

This function may be called from any thread.

Definition at line 255 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_regenerateProjectionMatrix()

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.

Definition at line 339 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_regenerateProjectionMatrixInternal()

void VuoSceneRenderer_regenerateProjectionMatrixInternal ( VuoSceneRendererInternal sceneRenderer)
static

Helper for VuoSceneRenderer_regenerateProjectionMatrix and VuoSceneRenderer_draw.

Must be called while scenegraphSemaphore is locked.

Definition at line 361 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_renderInternal()

bool VuoSceneRenderer_renderInternal ( VuoSceneRenderer  sr,
VuoGlContext  glContext,
GLuint *  outputTexture,
GLenum  target,
GLuint  imageGlInternalFormat,
VuoMultisample  multisample,
GLuint *  outputDepthTexture,
bool  invertDepthImage 
)

Helper for VuoSceneRenderer_render*.

Definition at line 1662 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_renderToImage()

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

Renders the scene onto image and optionally depthImage.

If depthImage is NULL, the scenegraph is traversed in depth-first order for rendering. If non-NULL, objects are rendered according to their distance from the camera (opaque objects front-to-back, then transparent objects back-to-front).

Changed in Vuo 2.0.0:
Added depth-sorting behavior.

Definition at line 1839 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_renderToIOSurface()

VuoIoSurface VuoSceneRenderer_renderToIOSurface ( VuoSceneRenderer  sr,
VuoImageColorDepth  imageColorDepth,
VuoMultisample  multisample,
bool  includeDepthBuffer 
)

Renders the scene onto an IOSurface.

If includeDepthBuffer is false, the scenegraph is traversed in depth-first order for rendering. If true, objects are rendered according to their distance from the camera (opaque objects front-to-back, then transparent objects back-to-front).

Changed in Vuo 2.0.0:
Added depth-sorting behavior.

Definition at line 1868 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_setCameraName()

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.

Definition at line 1591 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_setRootSceneObject()

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.

Definition at line 1549 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_uploadSceneObject()

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

Returns false if the object can't potentially generate visible output (e.g., if it's the empty object).

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

Definition at line 1326 of file VuoSceneRenderer.cc.

◆ VuoSceneRenderer_uploadSceneObjects()

static void VuoSceneRenderer_uploadSceneObjects ( VuoSceneRendererInternal sceneRenderer,
VuoGlContext  glContext,
VuoPoint3d  cameraTranslation 
)
static

Uploads so and its child objects to the GPU, and stores the uploaded object names in the opaqueObjects and potentiallyTransparentObjects render lists.

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

Definition at line 1439 of file VuoSceneRenderer.cc.