MHardwareRenderer Class Reference
[OpenMayaRender - API module for rendering]

#include <MHardwareRenderer.h>
Collaboration diagram for MHardwareRenderer:
Collaboration graph
[legend]

List of all members.


Detailed Description

Static hardware renderer interface class.

MHardwareRenderer is an interface class which wraps the hardware renderer.

Examples:

cgfxShaderNode.cpp, glExtensions.cpp, GLSLShaderNode.cpp, hlslShader.cpp, hwColorPerVertexShader.cpp, hwPhongShader.cpp, hwRenderPostEffect.cpp, OpenGLViewportRenderer.cpp, and pluginMain.cpp.


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 MString backEndString () const
DrawProcedureStatusCode  addDrawProcedure (const MString &backEndString, MDrawProcedureBase *drawProcedureptr, CallLocation location)
DrawProcedureStatusCode  removeDrawProcedure (const MString &backEndString, MDrawProcedureBase *drawProcedureptr, CallLocation location)
DrawProcedureStatusCode  insertDrawProcedure (const MString &backEndString, MDrawProcedureBase *drawProcedurePtr, CallLocation location, unsigned int listIndex, bool moveExistingItem=false)
DrawProcedureStatusCode  getDrawProcedureCount (const MString &backEndString, CallLocation location, unsigned int &count) const
DrawProcedureStatusCode  getDrawProcedureListNames (const MString &backEndString, CallLocation location, MStringArray &namesOfProcs) const
MDrawProcedureBase findDrawProcedure (const MString &backEndString, CallLocation location, const MString &procName) const
MStatus  makeResourceContextCurrent (const MString &backEndString)
MStatus  getBufferSize (const MString &backEndString, unsigned int &width, unsigned int &height) const
MStatus  getColorBufferPixelFormat (const MString &backEndString, BufferPixelFormat &fmt) const
MStatus  getDepthBufferPixelFormat (const MString &backEndString, BufferPixelFormat &fmt) const
MStatus  getCurrentExposureNumber (const MString &backEndString, unsigned int &number) const
MStatus  getTotalExposureCount (const MString &backEndString, unsigned int &number) const
MStatus  restoreCurrent (const MString &backEndString) const
MStatus  makeSwatchContextCurrent (const MString &backEndString, unsigned int &width, unsigned int &height)
MStatus  readSwatchContextPixels (const MString &backEndString, MImage &image)
MGeometryData referenceDefaultGeometry (MHardwareRenderer::GeometricShape geomShape, unsigned int &numberOfData, unsigned int *&pIndexing, unsigned int &indexLength)
MStatus  dereferenceGeometry (MGeometryData *pGeomData, unsigned int numberOfData)
void  getSwatchOrthoCameraSetting (double &l, double &r, double &b, double &t, double &n, double &f) const
void  getSwatchPerspectiveCameraSetting (double &l, double &r, double &b, double &t, double &n, double &f) const
void  getSwatchPerspectiveCameraTranslation (float &x, float &y, float &z, float &w) const
void  getSwatchLightDirection (float &x, float &y, float &z, float &w) const
void  drawSwatchBackGroundQuads (const MColor &quadColor=MColor(0.5f, 0.5f, 0.5f, 1.0f), bool textured=false, unsigned int numberOfRepeats=8) const
MGLFunctionTable glFunctionTable () const

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 & MHardwareRenderer::backEndString (  )  const

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 MHardwareRenderer::addDrawProcedure ( const MString backEndString,
MDrawProcedureBase drawProcedurePtr,
CallLocation  location  
)

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]  backEndString  Backend string.
[in]  drawProcedurePtr  Pointer to a draw procedure
[in]  location  Render location.
Returns:
  • DrawProcedureStatusCode : kSuccess, kFailure, kItemExists, or kLocationNotFound. if item already exists.
Examples:

MHardwareRenderer::DrawProcedureStatusCode MHardwareRenderer::removeDrawProcedure ( const MString backEndString,
MDrawProcedureBase drawProcedurePtr,
CallLocation  location  
)

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]  backEndString  Backend string.
[in]  drawProcedurePtr  Pointer to a draw procedure.
[in]  location  Render location.
Returns:
  • DrawProcedureStatusCode : kSuccess, kFailure, kItemNotFound, or kLocationNotFound. if item cannot be found.
Examples:

MHardwareRenderer::DrawProcedureStatusCode MHardwareRenderer::insertDrawProcedure ( const MString backEndString,
MDrawProcedureBase drawProcedurePtr,
CallLocation  location,
unsigned int  listIndex,
bool  moveExistingItem = false  
)

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]  backEndString  Backend string.
[in]  drawProcedurePtr  Pointer to a draw procedure
[in]  location  Render location.
[in]  listIndex  Desired index position within the procedure list.
[in]  moveExistingItem  Move 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 MHardwareRenderer::getDrawProcedureCount ( const MString backEndString,
CallLocation  location,
unsigned int &  count  
) const

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]  backEndString  Backend string.
[in]  location  Render location.
[out]  count  Reference 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 MHardwareRenderer::getDrawProcedureListNames ( const MString backEndString,
CallLocation  location,
MStringArray namesOfProcs  
) const

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]  backEndString  Backend string.
[in]  location  Render location.
[in,out]  namesOfProcs  Reference 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 * MHardwareRenderer::findDrawProcedure ( const MString backEndString,
CallLocation  location,
const MString procName  
) const

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]  backEndString  Backend string.
[in]  location  Render location.
[in]  procName  Name of a specific draw procedure to find.
Returns:
Pointer to a MDrawProcedureBase. null is returned if not found.

MStatus MHardwareRenderer::makeResourceContextCurrent ( const MString backEndString  ) 

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]  backEndString  Backend string.
Returns:
Status code
Examples:

MStatus MHardwareRenderer::getBufferSize ( const MString backEndString,
unsigned int &  width,
unsigned int &  height  
) const

This method returns the size of the current buffer

Parameters:
[in]  backEndString  Backend string.
[out]  width  The reference to the width value of the buffer. If the function fails for any reason, the value will not be modified.
[out]  height  The 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 MHardwareRenderer::getColorBufferPixelFormat ( const MString backEndString,
BufferPixelFormat fmt  
) const

This method returns the pixel format of the current color buffer

Parameters:
[in]  backEndString  Backend string.
[out]  fmt  The 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 MHardwareRenderer::getDepthBufferPixelFormat ( const MString backEndString,
BufferPixelFormat fmt  
) const

This method returns the pixel format of the current depth buffer

Parameters:
[in]  backEndString  Backend string.
[out]  fmt  The 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 MHardwareRenderer::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]  backEndString  Backend string.
[out]  number  Current exposure number
Returns:
Status code
Examples:

MStatus MHardwareRenderer::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]  backEndString  Backend string.
[out]  number  Total exposure count.
Returns:
Status code
Examples:

MStatus MHardwareRenderer::restoreCurrent ( const MString backEndString  )  const

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

Parameters:
[in]  backEndString  Backend string.
Returns:
Status code

MStatus MHardwareRenderer::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]  backEndString  Backend string.
[in,out]  desiredWidth  The 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]  desiredHeight  The 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 MHardwareRenderer::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]  backEndString  Backend string.
[out]  image  MImage with properly allocated block of pixels.
Returns:
Status code
Examples:

MGeometryData * MHardwareRenderer::referenceDefaultGeometry ( MHardwareRenderer::GeometricShape  geomShape,
unsigned int &  numberOfData,
unsigned int *&  pIndexing,
unsigned int &  indexLength  
)

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>;

                MHardwareRenderer::GeometricShape gshape = MHardwareRenderer::kDefaultSphere;
                if (mGeometryShape == 2)
                {
                        gshape = MHardwareRenderer::kDefaultCube;
                }
                else if (mGeometryShape == 3)
                {
                        gshape = MHardwareRenderer::kDefaultPlane;
                }

                // *** 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]  geomShape  Desired geometry shape.
[out]  numberOfData  Number of geometry data attributes returned.
[out]  pIndexing  Reference 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]  indexLength  Length 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 MHardwareRenderer::dereferenceGeometry ( MGeometryData pGeomData,
unsigned int  numberOfData  
)

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]  pGeomData  The geometry data returned from referenceDefaultGeometry().
[in]  numberOfData  Data count returned from referenceDefaultGeometry()
Examples:

void MHardwareRenderer::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]  l  The left side clipping plane
[out]  r  The right side clipping plane
[out]  b  The bottom side clipping plane
[out]  t  The top side clipping plane
[out]  n  The near side clipping plane
[out]  f  The far side clipping plane
Examples:

void MHardwareRenderer::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]  l  The left side clipping plane
[out]  r  The right side clipping plane
[out]  b  The bottom side clipping plane
[out]  t  The top side clipping plane
[out]  n  The near side clipping plane
[out]  f  The far side clipping plane
Examples:

void MHardwareRenderer::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]  x  The value for the x coord component
[out]  y  The value for the y coord component
[out]  z  The value for the z coord component
[out]  w  The value for the w coord component
Examples:

void MHardwareRenderer::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]  x  The value for the x coord component
[out]  y  The value for the y coord component
[out]  z  The value for the z coord component
[out]  w  The value for the w coord component
Examples:

void MHardwareRenderer::drawSwatchBackGroundQuads ( const MColor quadColor = MColor(0.5f, 0.5f, 0.5f, 1.0f),
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]  quadColor  The value for the quad color. Default is RGBA(0.5,0.5,0.5,1.0);
[in]  textured  Whether to draw with texture coordinates. Default is false.
[in]  numberOfRepeats  Number of checkerboard repeats. Default is 8.
Examples:

MGLFunctionTable * MHardwareRenderer::glFunctionTable (  )  const

Get a pointer to a OpenGL function table class.

Returns:
Pointer to the function table class. This may be null, if the renderer could not be initialized properly.
Examples:

Autodesk® Maya® 2011 © 1997-2010 Autodesk, Inc. All rights reserved. Generated with doxygen 1.5.6