class MHardwareRenderer

Jump to documentation

Static hardware renderer interface class (OpenMayaRender) (OpenMayaRender.py)

public members:

enum DrawProcedureStatusCode
Draw Procedure status codes
kSuccess
Success
kFailure
Failure
kItemExists
Item already exists
kItemNotFound
Item is not found
kLocationNotFound
Location not found
enum BufferPixelFormat
Specify the pixel format of the current buffer
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
enum CallLocation
Draw Procedure call locations
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.
enum GeometricShape
Default geometry shapes
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.
static MHardwareRenderer * theRenderer ()
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 = kDefaultQuadColor, bool textured = false, unsigned int numberOfRepeats = 8) const
MGLFunctionTable * glFunctionTable () const

Documentation

This class is a wrapper class to access the hardware renderer
Description

MHardwareRenderer is an interface class which wraps the hardware renderer.

Functions

MHardwareRenderer * MHardwareRenderer:: theRenderer ()

Description

Returns a static pointer to the hardware renderer wrapper class.

Arguments

  • None.

Return Value

  • Pointer to a MHardwareRenderer.

const MString & MHardwareRenderer:: backEndString () const

Description

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

Arguments

  • None.

Return Value

  • Pointer to a MHardwareRenderer.

MStatus MHardwareRenderer:: makeResourceContextCurrent (const MString & backEndString )

Description

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.

Arguments

  • backEndString : Backend string.

Return Value

  • status code

Status Codes

  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.

MHardwareRenderer::DrawProcedureStatusCode MHardwareRenderer:: addDrawProcedure ( const MString & backEndString , MDrawProcedureBase *drawProcedurePtr, CallLocation location)

Description

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

Arguments

  • backEndString : Backend string.
  • drawProcedurePtr : Pointer to a draw procedure
  • location : Render location.

Return Value

  • DrawProcedureStatusCode : kSuccess, kFailure, kItemExists, or kLocationNotFound. if item already exists.

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

Description

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.

Arguments

  • backEndString : Backend string.
  • drawProcedurePtr : Pointer to a draw procedure.
  • location : Render location.

Return Value

  • DrawProcedureStatusCode : kSuccess, kFailure, kItemNotFound, or kLocationNotFound. if item cannot be found.

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

Description

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

Arguments

  • backEndString : Backend string.
  • drawProcedurePtr : Pointer to a draw procedure
  • location : Render location.
  • listIndex : Desired index position within the procedure list.
  • moveExistingItem : Move the procedure if it already exists in the list. The default value for this method argument is "false".

Return Value

  • DrawProcedureStatusCode : kSuccess, kFailure, kItemExists, or kLocationNotFound. if item already exists.

MHardwareRenderer::DrawProcedureStatusCode MHardwareRenderer:: getDrawProcedureCount ( const MString & backEndString , CallLocation location, unsigned int &count ) const

Description

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

Arguments

  • backEndString : Backend string.
  • location : Render location.
  • count : Reference to the list count. This value is returned. If the function fails for any reason, then a value of 0 is returned.

Return Value

  • DrawProcedureStatusCode : kSuccess, kFailure, or kLocationNotFound. if item already exists.

MHardwareRenderer::DrawProcedureStatusCode MHardwareRenderer:: getDrawProcedureListNames ( const MString & backEndString , CallLocation location, MStringArray &namesOfProcs ) const

Description

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

Arguments

  • backEndString : Backend string.
  • location : Render location.
  • 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.

Return Value

  • DrawProcedureStatusCode : kSuccess, kFailure, or kLocationNotFound. if item already exists.

MDrawProcedureBase * MHardwareRenderer:: findDrawProcedure ( const MString & backEndString , CallLocation location, const MString &procName ) const

Description

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.

Arguments

  • backEndString : Backend string.
  • location : Render location.
  • procName : Name of a specific draw procedure to find.

Return Value

  • Pointer to a MDrawProcedureBase. null is returned if not found.

MStatus MHardwareRenderer:: restoreCurrent (const MString & backEndString ) const

Description

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

Arguments

  • backEndString : Backend string.

Return Value

  • status code

Status Codes

  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.

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

Description

This method returns the size of the current buffer

Arguments

  • backEndString : Backend string.
  • width : The reference to the width value of the buffer. If the function fails for any reason, the value will not be modified.
  • height : The reference to the height value of the buffer. If the function fails for any reason, the value will not be modified.

Return Value

  • status code

Status Codes

  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.

MStatus MHardwareRenderer:: getColorBufferPixelFormat ( const MString & backEndString , BufferPixelFormat &fmt ) const

Description

This method returns the pixel format of the current color buffer

Arguments

  • backEndString : Backend string.
  • fmt : The reference to the pixel format value of the buffer. If the function fails for any reason, the value will not be modified.

Return Value

  • status code

Status Codes

  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.

MStatus MHardwareRenderer:: getDepthBufferPixelFormat ( const MString & backEndString , BufferPixelFormat &fmt ) const

Description

This method returns the pixel format of the current depth buffer

Arguments

  • backEndString : Backend string.
  • fmt : The reference to the pixel format value of the buffer If the function fails for any reason, the value will not be modified.

Return Value

  • status code

Status Codes

  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.

MStatus MHardwareRenderer:: getCurrentExposureNumber ( const MString & backEndString , unsigned int &number ) const

Description

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.

Arguments

  • backEndString : Backend string.
  • number : Current exposure number

Return Value

  • status code

Status Codes

  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.

MStatus MHardwareRenderer:: getTotalExposureCount ( const MString & backEndString , unsigned int &number ) const

Description

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.

Arguments

  • backEndString : Backend string.
  • number : Total exposure count.

Return Value

  • status code

Status Codes

  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.

MStatus MHardwareRenderer:: makeSwatchContextCurrent (const MString & backEndString , unsigned int & desiredWidth, unsigned int & desiredHeight )

Description

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.

Arguments

  • backEndString : Backend string.
  • 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.
  • 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.

Return Value

  • status code

Status Codes

  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.

MStatus MHardwareRenderer:: readSwatchContextPixels (const MString & backEndString , MImage & image )

Description

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.

Arguments

  • backEndString : Backend string.
  • image : MImage with properly allocated block of pixels.

Return Value

  • status code

Status Codes

  • MS::kSuccess The method was successful.
  • MS::kFailure An error has occurred.

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

Description

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

Arguments

  • geomShape : Desired geometry shape.
  • numberOfData : Number of geometry data attributes returned.
  • 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.
  • indexLength : Length of the indexing array.

Return Value

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

MStatus MHardwareRenderer:: dereferenceGeometry ( MGeometryData * pGeomData, unsigned int numberOfData)

Description

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.

Arguments

  • pGeomeData : The geometry data returned from referenceDefaultGeometry().
  • numberOfData : Data count returned from referenceDefaultGeometry()

Return Value

void MHardwareRenderer:: getSwatchOrthoCameraSetting ( double& l, double& r, double& b, double& t, double& n, double& f ) const

Description

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.

Arguments

  • l : The left side clipping plane
  • r : The right side clipping plane
  • b : The bottom side clipping plane
  • t : The top side clipping plane
  • n : The near side clipping plane
  • f : The far side clipping plane

Return Value

None.

void MHardwareRenderer:: getSwatchPerspectiveCameraSetting ( double& l, double& r, double& b, double& t, double& n, double& f ) const

Description

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.

Arguments

  • l : The left side clipping plane
  • r : The right side clipping plane
  • b : The bottom side clipping plane
  • t : The top side clipping plane
  • n : The near side clipping plane
  • f : The far side clipping plane

Return Value

None.

void MHardwareRenderer:: getSwatchPerspectiveCameraTranslation ( float& x, float& y, float& z, float& w ) const

Description

This method returns a perspective camera 3D translation values. These are the default values used for rendering the swatch.

Arguments

  • x : The value for the x coord component
  • y : The value for the y coord component
  • z : The value for the z coord component
  • w : The value for the w coord component

Return Value

None.

void MHardwareRenderer:: getSwatchLightDirection ( float& x, float& y, float& z, float& w ) const

Description

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

Arguments

  • x : The value for the x coord component
  • y : The value for the y coord component
  • z : The value for the z coord component
  • w : The value for the w coord component

Return Value

None.

void MHardwareRenderer:: drawSwatchBackGroundQuads ( const MColor & quadColor, bool textured, unsigned int numberOfRepeats ) const

Description

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.

Arguments

  • quadColor : The value for the quad color. Default is RGBA(0.5,0.5,0.5,1.0);
  • textured : Whether to draw with texture coordinates. Default is false.
  • numberOfRepeats : Number of checkerboard repeats. Default is 8.

Return Value

None.

MGLFunctionTable * MHardwareRenderer:: glFunctionTable () const

Description

Get a pointer to a OpenGL function table class.

Arguments

None.

Return Value

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

This class has no child classes.


Autodesk® Maya® 2008 © 1997-2007 Autodesk, Inc. All rights reserved. doc++ Copyright