MRenderUtilities Class Reference

#include <MRenderUtilities.h>

Class Description

Utilities for Viewport 2.0.

This class is a utility class for rendering in Viewport 2.0

Public Types

enum  MaterialViewerCamera { kPerspectiveCamera = 0, kOrthogonalCameraWithMargin, kOrthogonalCameraCloseUp }
 Camera positions supported by the Material Viewer. More...
 
enum  MaterialViewerLights { kDefaultLights = 0, kSwatchLight, kAmbientLight }
 Light rigs supported by the Material Viewer. More...
 

Static Public Member Functions

static MDrawContextacquireSwatchDrawContext (const MRenderTarget *colorTarget=NULL, const MRenderTarget *depthTarget=NULL)
 Acquire a draw context fit for rendering a swatch into the provided render targets. More...
 
static MDrawContextacquireUVTextureDrawContext (const MRenderTarget *colorTarget=NULL, const MRenderTarget *depthTarget=NULL)
 Acquire a draw context fit for rendering a texture for the UV editor into the provided render targets. More...
 
static void releaseDrawContext (MDrawContext *context, bool releaseTargets=true)
 Release a draw context. More...
 
static void swatchBackgroundColor (float &r, float &g, float &b, float &a)
 This method returns the default background color for the hardware rendered swatch. More...
 
static MStatus blitTargetToImage (const MRenderTarget *target, MImage &image)
 Copy the data from a target to an image. More...
 
static MStatus blitTargetToGL (const MRenderTarget *target, const float region[2][2], bool unfiltered)
 Blit the data from a target to current GL context. More...
 
static MStatus drawSimpleMesh (MDrawContext &context, const MVertexBuffer &vertexBuffer, const MIndexBuffer &indexBuffer, MGeometry::Primitive primitiveType, int start, int count)
 Render a simple mesh. More...
 
static MStatus renderMaterialViewerGeometry (const MString &shape, MObject shaderNode, MImage &image, MaterialViewerCamera cameraMode=kPerspectiveCamera, MaterialViewerLights lightRig=kDefaultLights)
 Do an off-screen render replicating the results shown by the Material Viewer window of Hypershade. More...
 
static const char * className ()
 Returns the name of this class. More...
 

Member Enumeration Documentation

Camera positions supported by the Material Viewer.

Enumerator
kPerspectiveCamera 

Perspective camera with Material Viewer settings.

kOrthogonalCameraWithMargin 

Orthogonal camera with margins as wide as perspective camera for planar swatches.

kOrthogonalCameraCloseUp 

Orthogonal camera set up to fully capture a MaterialViewerShape::kPlaneShape for UV editor images.

Light rigs supported by the Material Viewer.

Enumerator
kDefaultLights 

Material Viewer default light rig.

kSwatchLight 

Single directional swatch light.

kAmbientLight 

Ambient light scheme.

Member Function Documentation

MDrawContext * acquireSwatchDrawContext ( const MRenderTarget colorTarget = NULL,
const MRenderTarget depthTarget = NULL 
)
static

Acquire a draw context fit for rendering a swatch into the provided render targets.

The caller is responsible for releasing the draw context when it is no longer needed, by calling MRenderUtilities::releaseDrawContext(). If no targets are specified, then the caller will also have to properly setup render targets before drawing. Specifying targets also insures that the proper GL context is made active when using GL devices.

Parameters
[in]colorTargetThe color target for swatch drawing. Can be NULL.
[in]depthTargetThe depth target for swatch drawing. Can be NULL.
Returns
The draw context, NULL on failure.
+ Examples:
MDrawContext * acquireUVTextureDrawContext ( const MRenderTarget colorTarget = NULL,
const MRenderTarget depthTarget = NULL 
)
static

Acquire a draw context fit for rendering a texture for the UV editor into the provided render targets.

The caller is responsible for releasing the draw context when it is no longer needed, by calling MRenderUtilities::releaseDrawContext(). If no targets are specified, then the caller will also have to properly setup render targets before drawing. Specifying targets also insures that the proper GL context is made active when using GL devices.

Parameters
[in]colorTargetThe color target for UV texture drawing. Can be NULL.
[in]depthTargetThe depth target for UV texture drawing. Can be NULL.
Returns
The draw context, NULL on failure.
+ Examples:
void releaseDrawContext ( MDrawContext context,
bool  releaseTargets = true 
)
static

Release a draw context.

If releaseTargets is requested, the device will have NULL targets on function exit.

Parameters
[in]contextThe draw context to delete
[in]releaseTargetsRemoves the current draw targets from the device, defaults to true.
+ Examples:
void swatchBackgroundColor ( float &  r,
float &  g,
float &  b,
float &  a 
)
static

This method returns the default background color for the hardware rendered swatch.

Parameters
[out]rThe value for the red component.
[out]gThe value for the green component.
[out]bThe value for the blue component.
[out]aThe value for the alpha component.
+ Examples:
MStatus blitTargetToImage ( const MRenderTarget target,
MImage image 
)
static

Copy the data from a target to an image.

Only 2D targets and targets with the following formats are supported

  • kR8G8B8A8_UNORM
  • kB8G8R8A8
  • kA8B8G8R8
  • kR32_FLOAT
  • kR32G32_FLOAT
  • kR32G32B32_FLOAT
  • kR32G32B32A32_FLOAT 8-bits formats only works with byte typed image. Float formats only works with float typed image and same number of channels.
Parameters
[in]targetThe source target to get the data from.
[in]imageThe destination image to copy the data to.
Returns
Status code
Status Codes:
+ Examples:
MStatus blitTargetToGL ( const MRenderTarget target,
const float  region[2][2],
bool  unfiltered 
)
static

Blit the data from a target to current GL context.

Only 2D targets and targets with the following formats are supported

  • kR8G8B8A8_UNORM
  • kB8G8R8A8
  • kA8B8G8R8
  • kR32_FLOAT
  • kR32G32_FLOAT
  • kR32G32B32_FLOAT
Parameters
[in]targetThe source target to get the data from.
[in]regionRectangular region to be rendered.
[in]unfilteredRender with hardware filtering or sharply defined pixels.
Returns
Status code
Status Codes:
+ Examples:
MStatus drawSimpleMesh ( MDrawContext context,
const MVertexBuffer vertexBuffer,
const MIndexBuffer indexBuffer,
MGeometry::Primitive  primitiveType,
int  start,
int  count 
)
static

Render a simple mesh.

Parameters
[in]contextThe draw context to use for render.
[in]vertexBufferThe vertex buffer for the mesh.
[in]indexBufferThe index buffer for the mesh.
[in]primitiveTypeThe primitive type of the mesh.
[in]startThe location of the first index read from the index buffer.
[in]countThe number of indices to draw.
Returns
MStatus renderMaterialViewerGeometry ( const MString shape,
MObject  shaderNode,
MImage image,
MaterialViewerCamera  cameraMode = kPerspectiveCamera,
MaterialViewerLights  lightRig = kDefaultLights 
)
static

Do an off-screen render replicating the results shown by the Material Viewer window of Hypershade.

Parameters
[in]shapeShape to render. Valid values include "meshSphere", "meshPlane", "meshShaderball", "meshTeapot", "meshCloth", and "meshHair".
[in]shaderNodeThe shader node to use on the geometry.
[in]imageThe image where the result should be stored.
[in]cameraModeThe camera to use for rendering. Defaults to MRenderUtilities::kPerspectiveCamera.
[in]lightRigThe light rig to use for rendering. Defaults to MRenderUtilities::kDefaultLights.
Returns
+ Examples:
const char * className ( )
static

Returns the name of this class.

Returns
The name of this class.

The documentation for this class was generated from the following files:
  • MRenderUtilities.h
  • MRenderUtilities.cpp