#if _MSC_VER >= 1700
#pragma warning( disable: 4005 )
#endif
#include "dx11ShaderOverride.h"
#include <maya/MString.h>
#include <maya/MDrawContext.h>
static const bool DO_CUSTOM_DRAW = true;
static const bool PRINT_DEBUG_INFO = false;
{
return new dx11ShaderOverride(obj);
}
dx11ShaderOverride::dx11ShaderOverride(
const MObject& obj)
, fShaderNode(NULL)
, fGeometryVersionId(0)
, fBBoxExtraScale(1.0f)
, fStates()
{
if(shaderNode)
{
fBBoxExtraScale = shaderNode->boundingBoxExtraScale();
}
}
dx11ShaderOverride::~dx11ShaderOverride()
{
}
MString dx11ShaderOverride::initialize(
const MInitContext& initContext,MInitFeedback& initFeedback)
{
fShaderNode = NULL;
MInitContext* nonConst = const_cast<MInitContext*>(&initContext);
}
if (fShaderNode)
{
int count = fShaderNode->techniqueCount();
int activeTechnique = fShaderNode->activeTechnique();
if (activeTechnique >= 0 && activeTechnique < count)
{
addGeometryRequirements(*fShaderNode->vertexBufferDescLists());
dx11ShaderDX11EffectTechnique* technique = fShaderNode->technique();
if (technique)
{
int passCount = fShaderNode->techniquePassCount();
if (passCount > 0)
{
dx11ShaderDX11Pass* dxPass = technique->GetPassByIndex(0);
if (dxPass)
{
D3DX11_PASS_DESC descPass;
dxPass->GetDesc(&descPass);
addShaderSignature( descPass.pIAInputSignature, descPass.IAInputSignatureSize);
}
}
}
}
MString customPrimitiveGeneratorName = fShaderNode->techniqueIndexBufferType();
{
addIndexingRequirement(indexingRequirement);
}
fGeometryVersionId = fShaderNode->geometryVersionId();
}
MString result =
MString(
"Autodesk Maya dx11ShaderOverride, nodeName=");
result += fShaderNode ? fShaderNode->name() :
MString(
"null");
result +=
MString(
", effectFileName=");
result += fShaderNode ? fShaderNode->effectName() :
MString(
"null");
result += fShaderNode ? fShaderNode->activeTechniqueName() :
MString(
"null");
if(fShaderNode && fShaderNode->techniqueIsSelectable()) {
result +=
MString(
", selectable=true");
}
return result;
}
void dx11ShaderOverride::updateDG(
MObject object)
{
}
void dx11ShaderOverride::updateDevice()
{
}
void dx11ShaderOverride::endUpdate()
{
}
{
return (fShaderNode && fShaderNode->techniqueHandlesContext(context));
}
{
if (fShaderNode) {
if (theRenderer)
{
dx11ShaderDX11Device* dxDevice = (dx11ShaderDX11Device*)theRenderer->
GPUDeviceHandle();
if (dxDevice)
{
ID3D11DeviceContext* dxContext = NULL;
dxDevice->GetImmediateContext(&dxContext);
if (dxContext)
{
fShaderNode->backupStates(dxContext, fStates);
dxContext->VSSetShader(NULL, NULL, 0);
dxContext->PSSetShader(NULL, NULL, 0);
dxContext->GSSetShader(NULL, NULL, 0);
dxContext->HSSetShader(NULL, NULL, 0);
dxContext->DSSetShader(NULL, NULL, 0);
dxContext->Release();
}
}
}
fShaderNode->updateShaderBasedGeoChanges();
fShaderNode->updateLightsInformation();
}
}
bool dx11ShaderOverride::draw(
{
if (!fShaderNode) return false;
static const bool debugPassInformation = false;
if (debugPassInformation)
{
printf(
"dx11 shader drawing in pass[%s], semantic[", passId.
asChar());
for (
unsigned int i=0; i<passSem.
length(); i++)
printf(" %s", passSem[i].asChar());
printf("\n");
}
return fShaderNode->render(context, renderItemList);
}
{
if (fShaderNode) {
if (theRenderer)
{
dx11ShaderDX11Device* dxDevice = (dx11ShaderDX11Device*)theRenderer->
GPUDeviceHandle();
if (dxDevice)
{
ID3D11DeviceContext* dxContext = NULL;
dxDevice->GetImmediateContext(&dxContext);
if (dxContext)
{
fShaderNode->restoreStates(dxContext, fStates);
dxContext->VSSetShader(NULL, NULL, 0);
dxContext->PSSetShader(NULL, NULL, 0);
dxContext->GSSetShader(NULL, NULL, 0);
dxContext->HSSetShader(NULL, NULL, 0);
dxContext->DSSetShader(NULL, NULL, 0);
dxContext->Release();
}
}
}
}
}
{
}
bool dx11ShaderOverride::isTransparent()
{
return (fShaderNode && fShaderNode->techniqueIsTransparent());
}
bool dx11ShaderOverride::supportsAdvancedTransparency() const
{
return (fShaderNode && fShaderNode->techniqueSupportsAdvancedTransparency());
}
bool dx11ShaderOverride::overridesDrawState()
{
return (fShaderNode && fShaderNode->techniqueOverridesDrawState());
}
bool dx11ShaderOverride::rebuildAlways()
{
return !fShaderNode || fShaderNode->rebuildAlways(fGeometryVersionId);
}
double dx11ShaderOverride::boundingBoxExtraScale() const
{
return fShaderNode ? fShaderNode->boundingBoxExtraScale() : fBBoxExtraScale;
}
bool dx11ShaderOverride::overridesNonMaterialItems() const
{
return fShaderNode ? fShaderNode->techniqueOverridesNonMaterialItems() : false;
}
bool dx11ShaderOverride::handlesConsolidatedGeometry() const
{
return fShaderNode ? fShaderNode->techniqueHandlesConsolidatedGeometry() : true;
}