MPxDrawOverride is the API entry point for defining low-level drawing of plug-in DAG objects in Viewport 2.0. It is designed as a back door for legacy (for example, fixed function) draw code which gives complete and total control (and responsibility) for drawing the associated DAG object regardless of shader assignment. Due to the wide-open nature of the interface, Maya cannot attempt to optimize the rendering of objects which draw using this interface (for example, no consolidation, no vertex data sharing, and so forth). This interface is not draw API agnostic; multiple code paths need to be written and maintained if the plug-in needs to support both OpenGL and DirectX. There is no integration with lighting. Transparency is supported; however MPxDrawOverride does not support advanced transparency algorithms such as weighted average or depth peeling, even if MPxDrawOverride::isTransparent() is set to true. When either the Weighted Average or Depth Peeling transparency algorithm is selected, the default Object Sorting algorithm is used instead. Effects can be supported via MPxDrawOverride::excludedFromPostEffects(). Unlike MPxGeometryOverride or MPxShaderOverride, where part of the setup is done by Maya, MPxDrawOverride requires the plug-in author to perform all shader setup, geometry binding, and draw calls manually. The interface gives the highest level of power for managing the draw of plug-in DAG objects, but also comes with a matching level of responsibility.
Implementations of MPxDrawOverride must be registered with MDrawRegistry using classification strings. The classification string must begin with "drawdb/geometry" in order to be properly recognized by the system. DAG objects with classification strings that satisfy the override classification string are evaluated using the override. Maya creates one instance of the registered MPxDrawOverride for each associated DAG object.
The override has several helper methods: transform(), boundingBox() and isBounded() which may be called by Maya before drawing to obtain information about the drawable scene management purposes. Maya will draw the bounding box for an MPxDrawOverride when in “bounding box” display mode. If isBounded() returns a false value then there is no way for Maya to determine what to draw. The MPxDrawOverride is responsible for drawing its own bounding box in this case.
The actual draw occurs on every refresh, and consists of two stages: preparation and execution.
Any required data from the Maya dependency graph must be retrieved and cached in the prepareForDraw() stage. It is invalid to pull data from the Maya dependency graph in the draw method and Maya may become unstable as a result. Implementations may allow Maya to handle the data caching by returning a pointer to the data from this method. This same pointer is passed to the draw callback. On subsequent draws, the pointer is also be passed back into the prepareForDraw() method so that the data may be modified and reused instead of reallocated.
In the draw method, the override is free to act as necessary to draw the object (apart from triggering evaluation of the Maya dependency graph). Access to device information can be obtained through MDrawContext, and the override can make use of MStateManager and MTextureManager to handle device state and resources. If the override needs to modify the state (in any manner), to avoid draw corruption, it must be sure to restore that state before completing execution.
Figure 44: The draw override supplies transform and bounds information for any culling, will be called to perform draw preparation during the “Update Phase” and then called to perform drawing during the “Draw Phase.” Intermediate phases between updating and drawing are skipped over.