This reference page is linked to from the following overview topics: A hardware shading node plug-in example.
Static hardware renderer interface class.
MHardwareRenderer is an interface class which wraps the hardware renderer.
#include <MHardwareRenderer.h>
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 |
Returns a string identifying the current
"backend" being used. |
|
DrawProcedureStatusCode | addDrawProcedure (const MString &backEndString, MDrawProcedureBase *drawProcedureptr, CallLocation location) |
Add a drawing procedure to the renderer.
|
|
DrawProcedureStatusCode | removeDrawProcedure (const MString &backEndString, MDrawProcedureBase *drawProcedureptr, CallLocation location) |
Remove a drawing procedure to the renderer.
|
|
DrawProcedureStatusCode | 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. |
|
DrawProcedureStatusCode | getDrawProcedureCount (const MString &backEndString, CallLocation location, unsigned int &count) const |
Find the length of the procedure list for a
given render location. |
|
DrawProcedureStatusCode | 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. |
|
MDrawProcedureBase * | 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.
|
|
MStatus | makeResourceContextCurrent (const MString &backEndString) |
Make the hardware renderer's "resource
context" current. |
|
MStatus | getBufferSize (const MString &backEndString, unsigned int &width, unsigned int &height) const |
This method returns the size of the current
buffer. |
|
MStatus | getColorBufferPixelFormat (const MString &backEndString, BufferPixelFormat &fmt) const |
This method returns the pixel format of the
current color buffer. |
|
MStatus | getDepthBufferPixelFormat (const MString &backEndString, BufferPixelFormat &fmt) const |
This method returns the pixel format of the
current depth buffer. |
|
MStatus | getCurrentExposureNumber (const MString &backEndString, unsigned int &number) const |
This method returns the current exposure
number during rendering. |
|
MStatus | getTotalExposureCount (const MString &backEndString, unsigned int &number) const |
This method returns the total number of
exposures for rendering a single frame. |
|
MStatus | restoreCurrent (const MString &backEndString) const |
This method restores the current context to
the one that the HWrenderer is using. |
|
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.
|
|
MStatus | readSwatchContextPixels (const MString &backEndString, MImage &image) |
Read the contents of the swatch context into
an MImage. |
|
MGeometryData * | 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. |
|
MStatus | 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. |
|
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.
|
|
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.
|
|
void | getSwatchPerspectiveCameraTranslation (float &x, float &y, float &z, float &w) const |
This method returns a perspective camera 3D
translation values. |
|
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.
|
|
void | drawSwatchBackGroundQuads (const MColor &quadColor=kDefaultQuadColor, bool textured=false, unsigned int numberOfRepeats=8) const |
This draws a set of quads in a checkboard
pattern. |
|
MGLFunctionTable * | glFunctionTable () const |
Get a pointer to a OpenGL function table
class. |
Draw Procedure status codes.
enum BufferPixelFormat |
Specify the pixel format of the current buffer.
enum CallLocation |
Draw Procedure call locations.
enum GeometricShape |
Default geometry shapes.
const MString & 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.
MHardwareRenderer::DrawProcedureStatusCode 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).
[in] | backEndString | Backend string. |
[in] | drawProcedurePtr | Pointer to a draw procedure |
[in] | location | Render location. |
MHardwareRenderer::DrawProcedureStatusCode 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.
[in] | backEndString | Backend string. |
[in] | drawProcedurePtr | Pointer to a draw procedure. |
[in] | location | Render location. |
MHardwareRenderer::DrawProcedureStatusCode 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 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).
[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". |
MHardwareRenderer::DrawProcedureStatusCode 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).
[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. |
MHardwareRenderer::DrawProcedureStatusCode 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).
[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. |
MDrawProcedureBase * 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.
[in] | backEndString | Backend string. |
[in] | location | Render location. |
[in] | procName | Name of a specific draw procedure to find. |
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:
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.
[in] | backEndString | Backend string. |
MStatus getBufferSize | ( | const MString & | backEndString, |
unsigned int & | width, | ||
unsigned int & | height | ||
) | const |
This method returns the size of the current buffer.
[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. |
MStatus getColorBufferPixelFormat | ( | const MString & | backEndString, |
BufferPixelFormat & | fmt | ||
) | const |
This method returns the pixel format of the current color buffer.
[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. |
MStatus getDepthBufferPixelFormat | ( | const MString & | backEndString, |
BufferPixelFormat & | fmt | ||
) | const |
This method returns the pixel format of the current depth buffer.
[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. |
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.
[in] | backEndString | Backend string. |
[out] | number | Current exposure number |
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.
[in] | backEndString | Backend string. |
[out] | number | Total exposure count. |
This method restores the current context to the one that the HWrenderer is using.
[in] | backEndString | Backend string. |
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:
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.
[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. |
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.
[in] | backEndString | Backend string. |
[out] | image | MImage with properly allocated block of pixels. |
MGeometryData * 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:
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 ); } }
[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. |
MStatus 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.
[in] | pGeomData | The geometry data returned from referenceDefaultGeometry(). |
[in] | numberOfData | Data count returned from referenceDefaultGeometry() |
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.
[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 |
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.
[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 |
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.
[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 |
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.
[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 |
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.
[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. |
MGLFunctionTable * glFunctionTable | ( | ) | const |
Get a pointer to a OpenGL function table class.