MBlendState Class Reference

This reference page is linked to from the following overview topics: 2.6 State and State Manager.



Detailed Description

Container class for an acquired GPU blend state.

MBlendState wraps an acquired composite GPU blend state. This blend state can be used to set the current GPU blend state using MStateManager::setBlendState(myBlendState).

Instances of MBlendState cannot be created or modified by users. You can read the descriptor for an MBlendState using MBlendState::desc(), but you cannot set or alter the descriptor directly.

MBlendState can only be obtained via MStateManager::acquireBlendState(). To use MStateManager::acquireBlendState(), create and fill an MBlendStateDesc instance with the requested state and pass it to MStateManager::acquireBlendState() which will return the cached unique blend state of that description. If the unique blend state did not previously exist in the cache, it is created.

The information included in the blend state includes alpha to coverage enable, independent blend enable, a global float4 blend factor, and an array of blending descriptors, one for each target.

The advantages of using this class rather than setting blend states explicitly are:

1. Since the states are cached internally, state setting is much faster than setting individual states. 2. Since state is set through the Maya viewport API, Maya can maintain accurate knowledge of the current GPU state, even in the presence of arbitrary plug-ins. This also speeds state setup by reducing redundant state setting and OGL queries. 3. The information is device aware, meaning that it will return the correct results based on the current active device. For example it will return the appropriate values for DirectX versus an OpenGL device.

Examples:

cgfxShaderNode.h, footPrintNode.cpp, hwColorPerVertexShader.cpp, and hwPhongShader.cpp.

#include <MStateManager.h>

List of all members.

Public Types

enum  BlendOperation {
  kAdd = 0x1, kSubtract = 0x2, kReverseSubtract = 0x3, kMin = 0x4,
  kMax = 0x5
}
 

Blend operations for hardware target blending.

More...
enum  BlendOption {
  kZero = 1, kOne = 2, kSourceColor = 3, kInvSourceColor = 4,
  kSourceAlpha = 5, kInvSourceAlpha = 6, kSourceAlphaSat = 11, kDestinationColor = 9,
  kInvDestinationColor = 10, kDestinationAlpha = 7, kInvDestinationAlpha = 8, kBothSourceAlpha = 12,
  kBothInvSourceAlpha = 13, kBlendFactor = 14, kInvBlendFactor = 15
}
 

Specifies what value to use as blend factor with an optional pre-operation.

More...
enum  ChannelMask {
  kNoChannels = 0, kRedChannel = 0x1, kGreenChannel = 0x2, kBlueChannel = 0x4,
  kAlphaChannel = 0x8, kRGBChannels = 0x7, kRGBAChannels = 0xf
}
 

A bitfield that indicates which color components(red, green, blue, alpha) are writable.

More...

Public Member Functions

const MBlendStateDescdesc (MStatus *ReturnStatus=NULL) const
 Get the blend state descriptor that was used to create the state object.
void * resourceHandle () const
 This method allows access to the draw API dependent handle for a blend state.

Static Public Member Functions

static const char * className ()
 Returns the name of this class.

Static Public Attributes

static const int kMaxTargets = 8
 Maximum number of simulatanious render targets.

Member Enumeration Documentation

Blend operations for hardware target blending.

Enumerator:
kAdd 

Add the source and destination together.

kSubtract 

Destination minus source.

kReverseSubtract 

Source minus destination.

kMin 

The minimum of the source and destination.

kMax 

The maximum of the source and destination.

Specifies what value to use as blend factor with an optional pre-operation.

Enumerator:
kZero 

Blend factor is 0.

kOne 

Blend factor is 1.

kSourceColor 

Blend factor is source color, src.rgb.

kInvSourceColor 

Blend factor is the complement of the source color, (1 - src.rgb).

kSourceAlpha 

Blend factor is source alpha, src.a.

kInvSourceAlpha 

Blend factor is the complement of the source alpha, (1 - src.a).

kSourceAlphaSat 

Blend factor is (f, f, f, 1); where f = saturate(src.a) between 0 and 1.

kDestinationColor 

Blend factor is destination color, dst.rgb.

kInvDestinationColor 

Blend factor is the complement of the destination color, (1 - dst.rgb).

kDestinationAlpha 

Blend factor is destination alpha, dst.a.

kInvDestinationAlpha 

Blend factor is the complement of the destination alpha, (1 - dst.a).

kBothSourceAlpha 

Source blend factor is src.a, destination blend factor is (1- src.a).

kBothInvSourceAlpha 

Source blend factor is (1- src.a), destination blend factor is src.a.

kBlendFactor 

Blend factor is the global blend factor specified by users.

kInvBlendFactor 

Blend factor is the complement of the global blend factor, (1 - blendFactor.rgba).

A bitfield that indicates which color components(red, green, blue, alpha) are writable.

Enumerator:
kNoChannels 

 

kRedChannel 

 

kGreenChannel 

 

kBlueChannel 

 

kAlphaChannel 

 

kRGBChannels 

 

kRGBAChannels 

 


Member Function Documentation

const MBlendStateDesc & desc ( MStatus ReturnStatus = NULL) const

Get the blend state descriptor that was used to create the state object.

Parameters:
[out]ReturnStatusreturn status
Returns:
A reference to the blend state descriptor
Status Codes:
const char * className ( ) [static]

Returns the name of this class.

Returns:
Name of this class.
void * resourceHandle ( ) const

This method allows access to the draw API dependent handle for a blend state.

This handle is owned by the MBlendState and is provided to allow access to use as a read-only object.

Modifications should never be performed on this handle.

Any modifications may result in unpredictable stability as the MBlendState no longer has knowledge of it's contents.

For OpenGL, such a handle does not exist and a NULL pointer will be returned.

For DirectX 10 and higher, a pointer to a Direct3D state will be returned.

Returns:
A pointer (handle) to the state if successful, otherwise NULL.

MBlendState MBlendState MBlendState MBlendState MBlendState MBlendState MBlendState MBlendState MBlendState MBlendState
MBlendState MBlendState MBlendState MBlendState MBlendState MBlendState MBlendState MBlendState MBlendState MBlendState