MHardwareRenderer Class Reference

#include <MHardwareRenderer.h>

Class Description

Public Types

enum  DrawProcedureStatusCode {
  kSuccess = 0, kFailure, kItemExists, kItemNotFound,
  kLocationNotFound
}
 Draw Procedure status codes. More...
 
enum  BufferPixelFormat { kRGBA_Fix8, kRGBA_Float16, kDepth_Float32 }
 Specify the pixel format of the current buffer. More...
 
enum  CallLocation { kPreRendering = 0, kPreExposure = 1, kPostExposure = 2, kPostRendering = 3 }
 Draw Procedure call locations. More...
 
enum  GeometricShape { kDefaultSphere = 0, kDefaultPlane, kDefaultCube }
 Default geometry shapes. More...
 

Public Member Functions

const MStringbackEndString () const
 This method is obsolete. More...
 
DrawProcedureStatusCode addDrawProcedure (const MString &backEndString, MDrawProcedureBase *drawProcedureptr, CallLocation location)
 This method is obsolete. More...
 
DrawProcedureStatusCode removeDrawProcedure (const MString &backEndString, MDrawProcedureBase *drawProcedureptr, CallLocation location)
 This method is obsolete. More...
 
DrawProcedureStatusCode insertDrawProcedure (const MString &backEndString, MDrawProcedureBase *drawProcedurePtr, CallLocation location, unsigned int listIndex, bool moveExistingItem=false)
 This method is obsolete. More...
 
DrawProcedureStatusCode getDrawProcedureCount (const MString &backEndString, CallLocation location, unsigned int &count) const
 This method is obsolete. More...
 
DrawProcedureStatusCode getDrawProcedureListNames (const MString &backEndString, CallLocation location, MStringArray &namesOfProcs) const
 This method is obsolete. More...
 
MDrawProcedureBasefindDrawProcedure (const MString &backEndString, CallLocation location, const MString &procName) const
 This method is obsolete. More...
 
MStatus makeResourceContextCurrent (const MString &backEndString)
 This method is obsolete. More...
 
MStatus getBufferSize (const MString &backEndString, unsigned int &width, unsigned int &height) const
 This method is obsolete. More...
 
MStatus getColorBufferPixelFormat (const MString &backEndString, BufferPixelFormat &fmt) const
 This method is obsolete. More...
 
MStatus getDepthBufferPixelFormat (const MString &backEndString, BufferPixelFormat &fmt) const
 This method is obsolete. More...
 
MStatus getCurrentExposureNumber (const MString &backEndString, unsigned int &number) const
 This method returns the current exposure number during rendering. More...
 
MStatus getTotalExposureCount (const MString &backEndString, unsigned int &number) const
 This method returns the total number of exposures for rendering a single frame. More...
 
MStatus restoreCurrent (const MString &backEndString) const
 This method is obsolete. More...
 
MStatus makeSwatchContextCurrent (const MString &backEndString, unsigned int &width, unsigned int &height)
 The swatch context is a "scratch" context which can be used to hardware render an image for swatch display. More...
 
MStatus readSwatchContextPixels (const MString &backEndString, MImage &image)
 Read the contents of the swatch context into an MImage. More...
 
MGeometryDatareferenceDefaultGeometry (MHardwareRenderer::GeometricShape geomShape, unsigned int &numberOfData, unsigned int *&pIndexing, unsigned int &indexLength)
 This method is obsolete. More...
 
MStatus dereferenceGeometry (MGeometryData *pGeomData, unsigned int numberOfData)
 This method is obsolete. More...
 
void getSwatchOrthoCameraSetting (double &l, double &r, double &b, double &t, double &n, double &f) const
 This method returns an orthographics camera clipping plane values which form the camera viewing volume. More...
 
void getSwatchPerspectiveCameraSetting (double &l, double &r, double &b, double &t, double &n, double &f) const
 This method returns a perspective camera clipping plane values which form the camera viewing volume. More...
 
void getSwatchPerspectiveCameraTranslation (float &x, float &y, float &z, float &w) const
 This method returns a perspective camera 3D translation values. More...
 
void getSwatchLightDirection (float &x, float &y, float &z, float &w) const
 This method returns the direction vector of the default directional light used for rendering the swatch. More...
 
void drawSwatchBackGroundQuads (const MColor &quadColor=kDefaultQuadColor, bool textured=false, unsigned int numberOfRepeats=8) const
 This draws a set of quads in a checkboard pattern. More...
 
MGLFunctionTableglFunctionTable () const
 This method is obsolete. More...
 

Member Enumeration Documentation

Draw Procedure status codes.

Enumerator
kSuccess 

Success.

kFailure 

Failure.

kItemExists 

Item already exists.

kItemNotFound 

Item is not found.

kLocationNotFound 

Location not found.

Specify the pixel format of the current buffer.

Enumerator
kRGBA_Fix8 

8 bit Red, Green, Blue, and Alpha channel

kRGBA_Float16 

16 bit Red, Green, Blue, and Alpha channel

kDepth_Float32 

32 bit floating point depth buffer

Draw Procedure call locations.

Enumerator
kPreRendering 

Before rendering one frame. No model or view matrices.

kPreExposure 

Before rendering one "exposure".

If multiple exposures are are required to render one frame. After the frame buffer is cleared and model and view matrices are set up for the current exposure.

kPostExposure 

After rendering one "exposure".

kPostRendering 

After rendering one frame. Before a possible fame buffer swap.

Default geometry shapes.

Enumerator
kDefaultSphere 

Sphere with radius 1, centered at 0,0,0.

kDefaultPlane 

Plane with width and height of 1, centered at 0,0,0.

Assuming "Y-Up" orientation: width = x-axis, and height = y-axis.

kDefaultCube 

Cube with width, height and depth of 1, centered at 0,0,0.

Member Function Documentation

const MString & backEndString ( ) const

This method is obsolete.

Deprecated:
Please use the Viewport 2.0 backend independent MHWRender interfaces instead.

Returns a string identifying the current "backend" being used. A backend represents a drawing API. Currently the only backend supported natively is OpenGL.

Returns
Pointer to a MHardwareRenderer.
+ Examples:
MHardwareRenderer::DrawProcedureStatusCode addDrawProcedure ( const MString backEndString,
MDrawProcedureBase drawProcedurePtr,
CallLocation  location 
)

This method is obsolete.

Deprecated:
Use MHWRender::MRenderOverride instead.

Add a drawing procedure to the renderer.

For a given render location, each procedure in a procedure list must have a unique string name. Instances of the a draw procedure procedure with different string names is allowed.

When attempting to add a procedure, if an existing procedure with the same name already exists in the procedure list to added to, then the addition will fail. An appropriate error code will be returned (kItemExists).

If the list cannot be found then (kLocationNotFound) is returned.

If the procedure is added, then success (kSuccess) will be returned. If the function fails for any other reason, then a failure code will be returned (kFailure).

Parameters
[in]backEndStringBackend string.
[in]drawProcedurePtrPointer to a draw procedure
[in]locationRender location.
Returns
  • DrawProcedureStatusCode : kSuccess, kFailure, kItemExists, or kLocationNotFound. if item already exists.
+ Examples:
MHardwareRenderer::DrawProcedureStatusCode removeDrawProcedure ( const MString backEndString,
MDrawProcedureBase drawProcedurePtr,
CallLocation  location 
)

This method is obsolete.

Deprecated:
Use MHWRender::MRenderOverride instead.

Remove a drawing procedure to the renderer. The procedure to remove is searched for based on procedure name. If a procedure with the given name is not found then an appropriate error code will be returned (kItemNotFound).

If the render location list does not exist then (kLocationNotFound) will be returned.

If the procedure is removed, then success (kSuccess) will be returned. If the function fails for any other reason, then a failure code (kFailure) will be returned.

Parameters
[in]backEndStringBackend string.
[in]drawProcedurePtrPointer to a draw procedure.
[in]locationRender location.
Returns
  • DrawProcedureStatusCode : kSuccess, kFailure, kItemNotFound, or kLocationNotFound. if item cannot be found.
+ Examples:
MHardwareRenderer::DrawProcedureStatusCode insertDrawProcedure ( const MString backEndString,
MDrawProcedureBase drawProcedurePtr,
CallLocation  location,
unsigned int  listIndex,
bool  moveExistingItem = false 
)

This method is obsolete.

Deprecated:
Use MHWRender::MRenderOverride instead.

Insert a drawing procedure to a list of procedures at a specific index location in the list.

For a given render location, each procedure in a procedure list must have a unique string name. Instances of the a draw procedure procedure with different string names is allowed.

Note that all procedure lists use 0 based indexing.

If an index is used which is beyond the end of the list, the item will be appended as the last item in the list.

When attempting to insert a procedure, if an existing procedure with the same name already exists in the procedure list to insert to, then two possible things can occur:

  • If the flag to move the item is set to "false", then the insertion will fail. An appropriate error code will be returned (kItemExists).
  • If the flag to move the item is set to "true", then instead of failure, the method will attempt to move the existing item from it's current index location to the requested index location (listIndex).

If the list cannot be found then (kLocationNotFound) is returned.

If the procedure is inserted, then success (kSuccess) will be returned. If the function fails for any other reason, then a failure code will be returned (kFailure).

Parameters
[in]backEndStringBackend string.
[in]drawProcedurePtrPointer to a draw procedure
[in]locationRender location.
[in]listIndexDesired index position within the procedure list.
[in]moveExistingItemMove the procedure if it already exists in the list. The default value for this method argument is "false".
Returns
  • DrawProcedureStatusCode : kSuccess, kFailure, kItemExists, or kLocationNotFound. if item already exists.
MHardwareRenderer::DrawProcedureStatusCode getDrawProcedureCount ( const MString backEndString,
CallLocation  location,
unsigned int &  count 
) const

This method is obsolete.

Deprecated:
Use MHWRender::MRenderOverride instead.

Find the length of the procedure list for a given render location.

If the list cannot be found then (kLocationNotFound) is returned. If the count can be successfully determined then (kSuccess) will be returned. If the function fails for any other reason, then a failure code will be returned (kFailure).

Parameters
[in]backEndStringBackend string.
[in]locationRender location.
[out]countReference to the list count. This value is returned. If the function fails for any reason, then a value of 0 is returned.
Returns
  • DrawProcedureStatusCode : kSuccess, kFailure, or kLocationNotFound. if item already exists.
MHardwareRenderer::DrawProcedureStatusCode getDrawProcedureListNames ( const MString backEndString,
CallLocation  location,
MStringArray namesOfProcs 
) const

This method is obsolete.

Deprecated:
Use MHWRender::MRenderOverride instead.

Get the names of drawing procedures for a given procedure list at a given render location.

If the list cannot be found then (kLocationNotFound) is returned. If the list can be successfully determined then (kSuccess) will be returned. If the function fails for any other reason, then a failure code will be returned (kFailure).

Parameters
[in]backEndStringBackend string.
[in]locationRender location.
[in,out]namesOfProcsReference to a string array. This array will be modified to return the list of names. If the function fails for any reason, the array will not be modified.
Returns
  • DrawProcedureStatusCode : kSuccess, kFailure, or kLocationNotFound. if item already exists.
MDrawProcedureBase * findDrawProcedure ( const MString backEndString,
CallLocation  location,
const MString procName 
) const

This method is obsolete.

Deprecated:
Use MHWRender::MRenderOverride instead.

Find a drawing procedure instance with a specific name within a procedure list at a given render location.

If the item can be successfully found then a pointer to the procedure will be returned. Otherwise a null (0) pointer will be returned.

Parameters
[in]backEndStringBackend string.
[in]locationRender location.
[in]procNameName of a specific draw procedure to find.
Returns
Pointer to a MDrawProcedureBase. null is returned if not found.
MStatus makeResourceContextCurrent ( const MString backEndString)

This method is obsolete.

Deprecated:
Please use the Viewport 2.0 device independent MHWRender interfaces instead.

Make the hardware renderer's "resource context" current. The "resource context" is used by the hardware renderer for sharing drawing resources such as hardware textures, geometry and shader programs. In fact all resources in the resource context are shared by all other Maya defined 3d contexts.

Note that this applies to interactive 3d viewports as well as the hardware renderer. This does not apply to non 3d contexts such as the timeline, or range slider.

Advantages of allowing the setting the resource context include:

  • Non-Maya defined resources can be bound to the resource context and also shared.
  • The API writer can bind resources without depending on existence 3d viewports or hardware renderer contexts.
  • There is an available context in both interactive and batch.

Basically this means that resources can be managed at any time one Maya has been initialized.

Example : This call can be made so that resources can be created and bound to a Maya context during loading of a scene file, as it is unknown what the current drawable context is at this time. This can be useful when writing a hardware shader plugin as it frees the API writer from depending on having to be in one of the 3d draw routines in order to access a context.

Note that if the hardware renderer has already specified a context for drawing into, then invoking this call will have no effect as it is not necessary to switch contexts to manage resources. To reiterate, any resource managed for the drawing context will be shared by the resource context.

If the hardware renderer is not supported, then no resource context will exist and this call will fail. If the hardware renderer has not been initialized yet then this call will also fail. This should only occur if this call is attempted before Maya has been initialized.

Parameters
[in]backEndStringBackend string.
Returns
Status code
+ Examples:
MStatus getBufferSize ( const MString backEndString,
unsigned int &  width,
unsigned int &  height 
) const

This method is obsolete.

Deprecated:
Use MHWRender::MRenderTarget and MHWRender::MRenderTargetDescription instead.

This method returns the size of the current buffer

Parameters
[in]backEndStringBackend string.
[out]widthThe reference to the width value of the buffer. If the function fails for any reason, the value will not be modified.
[out]heightThe reference to the height value of the buffer. If the function fails for any reason, the value will not be modified.
Returns
Status code
+ Examples:
MStatus getColorBufferPixelFormat ( const MString backEndString,
BufferPixelFormat fmt 
) const

This method is obsolete.

Deprecated:
Use MHWRender::MRenderTarget and MHWRender::MRenderTargetDescription instead.

This method returns the pixel format of the current color buffer

Parameters
[in]backEndStringBackend string.
[out]fmtThe reference to the pixel format value of the buffer. If the function fails for any reason, the value will not be modified.
Returns
Status code
+ Examples:
MStatus getDepthBufferPixelFormat ( const MString backEndString,
BufferPixelFormat fmt 
) const

This method is obsolete.

Deprecated:
Use MHWRender::MRenderTarget and MHWRender::MRenderTargetDescription instead.

This method returns the pixel format of the current depth buffer

Parameters
[in]backEndStringBackend string.
[out]fmtThe reference to the pixel format value of the buffer If the function fails for any reason, the value will not be modified.
Returns
Status code
MStatus getCurrentExposureNumber ( const MString backEndString,
unsigned int &  number 
) const

This method returns the current exposure number during rendering.

If the renderer is not currently rendering a value of 0 is returned as the current exposure number.

Parameters
[in]backEndStringBackend string.
[out]numberCurrent exposure number
Returns
Status code
+ Examples:
MStatus getTotalExposureCount ( const MString backEndString,
unsigned int &  number 
) const

This method returns the total number of exposures for rendering a single frame.

If the renderer is not currently rendering a value of 0 is returned as the total exposure count.

Parameters
[in]backEndStringBackend string.
[out]numberTotal exposure count.
Returns
Status code
+ Examples:
MStatus restoreCurrent ( const MString backEndString) const

This method is obsolete.

Deprecated:
Please use the Viewport 2.0 device independent MHWRender interfaces instead.

This method restores the current context to the one that the HWrenderer is using

Parameters
[in]backEndStringBackend string.
Returns
Status code
MStatus makeSwatchContextCurrent ( const MString backEndString,
unsigned int &  desiredWidth,
unsigned int &  desiredHeight 
)

The swatch context is a "scratch" context which can be used to hardware render an image for swatch display.

The swatch context has the following pixel format:

  • Color : 24 bit RGBA (red, green, blue, alpha) format, with 8 bits precision per channel.
  • Stencil : 8 bit precision.
  • Depth : 24 bit fixed point integer precison .

The maximum context size is 512 by 512, and the minimum size : 64 by 64. The actual maximum size is dependent on the video card and available memory resources.

This method makes the swatch context "current", and should be called before attempting to draw anything for swatch rendering.

The desired image width and height represents the desired viewport size to render. These values will be clamped between the minimum and maximum values of the swatch context.

If for any reason the swatch context cannot be made current, no rendering should be performed as the destination of the rendering is undefined.

This method should never be called while in the middle of drawing to another context (e.g. during MPxHwShaderNode::glGeometry()) as draw calls will be redirected to the swatch context.

e.g. Refer to MPxHwShaderNode::renderSwatchImage() for swatch rendering for hardware shaders for more details on the usage of this method.

Parameters
[in]backEndStringBackend string.
[in,out]desiredWidthThe desired width of the image to render. The dimensions of the context may differ. The size is clamped to be within the minimum and maximum context dimensions.
[in,out]desiredHeightThe desired height of the image to render. The dimensions of the context may differ. The size is clamped to be within the minimum and maximum context dimensions.
Returns
Status code
+ Examples:
MStatus readSwatchContextPixels ( const MString backEndString,
MImage image 
)

Read the contents of the swatch context into an MImage.

MImage is assumed to be of the correct pixel format (24-bit RGBA, with 8-bits per channel). MImage is assumed to also have pre-allocated the correct amount of data as this routine will copy the swatch context contents directly into the MImage.

If the swatch context is not available for any reason, or MImage has not been properly set up, then a failure condition will be returned.

Parameters
[in]backEndStringBackend string.
[out]imageMImage with properly allocated block of pixels.
Returns
Status code
+ Examples:
MGeometryData * referenceDefaultGeometry ( MHardwareRenderer::GeometricShape  geomShape,
unsigned int &  numberOfData,
unsigned int *&  pIndexing,
unsigned int &  indexLength 
)

This method is obsolete.

Deprecated:
Use MHWRender::MGeometryUtilities::acquireReferenceGeometry() instead.

Obtain a reference to geometry for some "default" shapes maintained by the hardware renderer. All data can be assumed to be "read-only", as the data is not owned by the caller.

To maintain proper reference counting of internal data, the user must "deference" the data when no longer using it via the MHardwareRenderer::dereferenceGeometry(). It is recommended to immediately dereference the data after each use. There negligable overhead to reference and dereference data in this manner.

Available default shapes include:

  • A polygonal sphere : Sphere has radius of 1 and is centered at the origin (0,0,0) in object space.
  • A polygonal cube : Cube has dimensions of 1 and is centered at the origin (0,0,0) in object space.
  • A polygonal plane : Plane has dimensions of 1 is centered at the origin (0,0,0) in object space. Assuming "Y-Up" orientation, the width is the along the x-axis and the height is along the y-axis.

Example usage taken from the provided hwPhngShader sample devkit plugin:

{
unsigned int numberOfData = 0; // Attribute count
unsigned int *pIndexing = 0; // Attribute indexing
unsigned int indexCount = 0; // Length of indexing array
// Geometry shape to obtain
unsigned int mGeometryShape = <user input>;
if (mGeometryShape == 2)
{
}
else if (mGeometryShape == 3)
{
}
// *** Obtain data references
MGeometryData * pGeomData =
pRenderer->referenceDefaultGeometry( gshape, numberOfData, pIndexing, indexCount);
// Draw default data
if (pGeomData)
{
glPushClientAttrib ( GL_CLIENT_VERTEX_ARRAY_BIT );
float *vertexData = (float *)( pGeomData[0].data() );
if (vertexData)
{
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer ( 3, GL_FLOAT, 0, vertexData );
}
float *normalData = (float *)( pGeomData[1].data() );
if (normalData)
{
glEnableClientState( GL_NORMAL_ARRAY );
glNormalPointer ( GL_FLOAT, 0, normalData );
}
if (vertexData && normalData && pIndexing )
glDrawElements ( GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, pIndexing );
glPopClientAttrib();
// *** Release data references after usage.
pRenderer->dereferenceGeometry( pGeomData, numberOfData );
}
}
Parameters
[in]geomShapeDesired geometry shape.
[out]numberOfDataNumber of geometry data attributes returned.
[out]pIndexingReference to an indexing array used to access attribute data. This value is modified and returned if the routine is successful. Indexing can be assumed to be for representing triangles. That is each 3-tuple index can be used to access 1 triangle in the attribute data.
[out]indexLengthLength of the indexing array.
Returns
A pointer to an array of geometric data attributes (MGeometryData). Currently four attributes are returned. In array order they are: position, normal, texture coordinates, tangents, and binormals. It can be assumed that all data is float such that:
  • Positions are 3 float (x,y,z) positions
  • Normals are 3 float (x,y,z) vectors.
  • Texture coordinates are 2 float (u,v) tuples.
  • Tangents are 3 float (x,y,z) vectors.
  • Binormals are 3 float (x,y,z) vectors.
+ Examples:
MStatus dereferenceGeometry ( MGeometryData pGeomData,
unsigned int  numberOfData 
)

This method is obsolete.

Deprecated:
Use MHWRender::MGeometryUtilities::releaseReferenceGeometry() instead.

This is the companion method to MHardwareRenderer::referenceDefaultGeometry() and must always be called immediate after usage of data supplied by the reference call.

This call simply maintains proper internal state for any data used.

Parameters
[in]pGeomDataThe geometry data returned from referenceDefaultGeometry().
[in]numberOfDataData count returned from referenceDefaultGeometry()
+ Examples:
void getSwatchOrthoCameraSetting ( double &  l,
double &  r,
double &  b,
double &  t,
double &  n,
double &  f 
) const

This method returns an orthographics camera clipping plane values which form the camera viewing volume.

These values are the default values used for rendering the swatch.

Parameters
[out]lThe left side clipping plane
[out]rThe right side clipping plane
[out]bThe bottom side clipping plane
[out]tThe top side clipping plane
[out]nThe near side clipping plane
[out]fThe far side clipping plane
+ Examples:
void getSwatchPerspectiveCameraSetting ( double &  l,
double &  r,
double &  b,
double &  t,
double &  n,
double &  f 
) const

This method returns a perspective camera clipping plane values which form the camera viewing volume.

These values are the default values used for rendering the swatch.

Parameters
[out]lThe left side clipping plane
[out]rThe right side clipping plane
[out]bThe bottom side clipping plane
[out]tThe top side clipping plane
[out]nThe near side clipping plane
[out]fThe far side clipping plane
+ Examples:
void getSwatchPerspectiveCameraTranslation ( float &  x,
float &  y,
float &  z,
float &  w 
) const

This method returns a perspective camera 3D translation values.

These are the default values used for rendering the swatch.

Parameters
[out]xThe value for the x coord component
[out]yThe value for the y coord component
[out]zThe value for the z coord component
[out]wThe value for the w coord component
+ Examples:
void getSwatchLightDirection ( float &  x,
float &  y,
float &  z,
float &  w 
) const

This method returns the direction vector of the default directional light used for rendering the swatch.

Parameters
[out]xThe value for the x coord component
[out]yThe value for the y coord component
[out]zThe value for the z coord component
[out]wThe value for the w coord component
+ Examples:
void drawSwatchBackGroundQuads ( const MColor quadColor = kDefaultQuadColor,
bool  textured = false,
unsigned int  numberOfRepeats = 8 
) const

This draws a set of quads in a checkboard pattern.

Areas that are not drawn will have the background color show through.

By default the checker repeat is 8, but can be overridden by the user.

By default the quad colour is opaque grey, but can be overridden by the user.

By default the quads are not drawn textured. This can be overridden by the user.

The quads will completely cover the entire background.

Parameters
[in]quadColorThe value for the quad color. Default is RGBA(0.5,0.5,0.5,1.0);
[in]texturedWhether to draw with texture coordinates. Default is false.
[in]numberOfRepeatsNumber of checkerboard repeats. Default is 8.
+ Examples:

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