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 cap ability is set to value (avoiding a state change if possible). | |
#define | VuoSceneRenderer_setGLDepthMask(value) |
Ensures the OpenGL depth mask is set to value (avoiding a state change if possible). | |
#define | VuoSceneRenderer_setGLFaceCulling(value) |
Ensures the OpenGL face culling mode is set to value (avoiding a state change if possible). | |
#define | VuoSceneRenderer_setGLBlendFunction(srcRGB, dstRGB, srcAlpha, dstAlpha) |
Ensures the OpenGL blend function is set to the specified values (avoiding a state change if possible). | |
#define | VuoSceneRenderer_setGLBlendEquation(modeRGB, modeAlpha) |
Ensures the OpenGL blend equation is set to the specified values (avoiding a state change if possible). | |
#define | glGenVertexArrays glGenVertexArraysAPPLE |
Stub. | |
#define | glBindVertexArray glBindVertexArrayAPPLE |
Stub. | |
#define | glDeleteVertexArrays glDeleteVertexArraysAPPLE |
Stub. | |
Typedefs | |
typedef std::pair< VuoMesh, VuoShader > | VuoSceneRendererMeshShader |
A VuoMesh/VuoShader combination. | |
typedef std::map< VuoSceneRendererMeshShader, GLuint > | VuoSceneRendererMeshShaderVAOs |
The VAO for each VuoMesh/VuoShader combination. | |
Functions | |
void | VuoSceneRenderer_destroy (VuoSceneRenderer sr) |
Destroys and deallocates the scene renderer. | |
static bool | VuoSceneRenderer_uploadSceneObject (VuoSceneRendererInternal *sceneRenderer, VuoSceneObject so, VuoSceneRendererInternal_object *soi, VuoGlContext glContext, bool cache) |
Draws all vertex normals in so . | |
VuoSceneRenderer | VuoSceneRenderer_make (float backingScaleFactor) |
Creates a reference-counted object for rendering a scenegraph. | |
static void | VuoSceneRenderer_regenerateProjectionMatrixInternal (VuoSceneRendererInternal *sceneRenderer) |
Helper for VuoSceneRenderer_regenerateProjectionMatrix and VuoSceneRenderer_draw. | |
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). | |
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 . | |
void | VuoSceneRenderer_checkDataBounds (CGLContextObj cgl_ctx, VuoMesh mesh, GLuint positionAttribute) |
Checks to ensure the currently-active VBO is correctly configured. | |
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 ). | |
static void | VuoSceneRenderer_drawSceneObjects (VuoSceneRendererInternal *sceneRenderer, VuoGlContext glContext, list< VuoSceneRenderer_TreeRenderState > &renderList) |
Draws so and its child objects. | |
static void | VuoSceneRenderer_cleanupRenderLists (VuoSceneRendererInternal *sceneRenderer) |
Cleans up internal state created by VuoSceneRenderer_uploadSceneObjects . | |
static void | VuoSceneRenderer_cleanupMeshShaderItems (VuoSceneRendererInternal *sceneRenderer, VuoGlContext glContext) |
Releases the GPU objects created by VuoSceneRenderer_uploadSceneObjects . | |
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. | |
void | VuoSceneRenderer_draw (VuoSceneRenderer sr, CGLContextObj cgl_ctx) |
Uploads the scene to the GPU (if it's changed), and renders it. | |
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. | |
bool | VuoSceneRenderer_renderInternal (VuoSceneRenderer sr, VuoGlContext glContext, GLuint *outputTexture, GLenum target, GLuint imageGlInternalFormat, VuoMultisample multisample, GLuint *outputDepthTexture, bool invertDepthImage) |
Helper for VuoSceneRenderer_render* . | |
void | VuoSceneRenderer_renderToImage (VuoSceneRenderer sr, VuoImage *image, VuoImageColorDepth imageColorDepth, VuoMultisample multisample, VuoImage *depthImage, bool invertDepthImage) |
Renders the scene onto image and optionally depthImage . | |
VuoIoSurface | VuoSceneRenderer_renderToIOSurface (VuoSceneRenderer sr, VuoImageColorDepth imageColorDepth, VuoMultisample multisample, bool includeDepthBuffer) |
Renders the scene onto an IOSurface. | |
struct VuoSceneRenderer_TreeRenderState |
Class Members | ||
---|---|---|
float | modelviewMatrix[16] | |
VuoSceneObject | so | |
VuoSceneRendererInternal_object * | soi |
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 |
VuoList_VuoSceneObject | spotLights | |
VuoBoolean | useLeftCamera | |
unsigned int | viewportHeight | |
unsigned int | viewportWidth | |
VuoSceneObject | vignetteQuad | |
VuoSceneRendererInternal_object | vignetteQuadInternal | |
VuoShader | vignetteShader |
struct VuoSceneRendererInternal::glState |
#define glBindVertexArray glBindVertexArrayAPPLE |
Stub.
Definition at line 25 of file VuoSceneRenderer.cc.
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE |
Stub.
Definition at line 26 of file VuoSceneRenderer.cc.
#define glGenVertexArrays glGenVertexArraysAPPLE |
Stub.
Definition at line 24 of file VuoSceneRenderer.cc.
#define VuoSceneRenderer_setGL | ( | cap, | |
value | |||
) |
Ensures the specified OpenGL cap
ability is set to value
(avoiding a state change if possible).
Definition at line 172 of file VuoSceneRenderer.cc.
#define VuoSceneRenderer_setGLBlendEquation | ( | modeRGB, | |
modeAlpha | |||
) |
Ensures the OpenGL blend equation is set to the specified values (avoiding a state change if possible).
Definition at line 229 of file VuoSceneRenderer.cc.
#define VuoSceneRenderer_setGLBlendFunction | ( | srcRGB, | |
dstRGB, | |||
srcAlpha, | |||
dstAlpha | |||
) |
Ensures the OpenGL blend function is set to the specified values (avoiding a state change if possible).
Definition at line 211 of file VuoSceneRenderer.cc.
#define VuoSceneRenderer_setGLDepthMask | ( | value | ) |
Ensures the OpenGL depth mask is set to value
(avoiding a state change if possible).
Definition at line 187 of file VuoSceneRenderer.cc.
#define VuoSceneRenderer_setGLFaceCulling | ( | value | ) |
Ensures the OpenGL face culling mode is set to value
(avoiding a state change if possible).
Definition at line 199 of file VuoSceneRenderer.cc.
typedef std::pair<VuoMesh, VuoShader> VuoSceneRendererMeshShader |
A VuoMesh/VuoShader combination.
Definition at line 58 of file VuoSceneRenderer.cc.
typedef std::map<VuoSceneRendererMeshShader, GLuint> VuoSceneRendererMeshShaderVAOs |
The VAO for each VuoMesh/VuoShader combination.
Definition at line 59 of file VuoSceneRenderer.cc.
|
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 483 of file VuoSceneRenderer.cc.
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 501 of file VuoSceneRenderer.cc.
|
static |
Releases the GPU objects created by VuoSceneRenderer_uploadSceneObjects
.
Definition at line 1530 of file VuoSceneRenderer.cc.
|
static |
Cleans up internal state created by VuoSceneRenderer_uploadSceneObjects
.
Must be called while scenegraphSemaphore is locked.
Definition at line 1508 of file VuoSceneRenderer.cc.
void VuoSceneRenderer_destroy | ( | VuoSceneRenderer | sr | ) |
Destroys and deallocates the scene renderer.
This function may be called from any thread.
Definition at line 1611 of file VuoSceneRenderer.cc.
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 966 of file VuoSceneRenderer.cc.
|
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 606 of file VuoSceneRenderer.cc.
|
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 941 of file VuoSceneRenderer.cc.
|
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 301 of file VuoSceneRenderer.cc.
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 1573 of file VuoSceneRenderer.cc.
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 253 of file VuoSceneRenderer.cc.
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 337 of file VuoSceneRenderer.cc.
|
static |
Helper for VuoSceneRenderer_regenerateProjectionMatrix and VuoSceneRenderer_draw.
Must be called while scenegraphSemaphore is locked.
Definition at line 359 of file VuoSceneRenderer.cc.
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 1660 of file VuoSceneRenderer.cc.
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).
Definition at line 1837 of file VuoSceneRenderer.cc.
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).
Definition at line 1866 of file VuoSceneRenderer.cc.
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 1589 of file VuoSceneRenderer.cc.
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 1547 of file VuoSceneRenderer.cc.
|
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 1324 of file VuoSceneRenderer.cc.
|
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 1437 of file VuoSceneRenderer.cc.