AshliPluginMain.cpp
#include <maya/MFnPlugin.h>
#include <maya/MIOStream.h>
#include <maya/MSceneMessage.h>
#include <maya/MGlobal.h>
#include <maya/MString.h>
#include <maya/MStringResource.h>
#include <maya/MStringResourceId.h>
#include "GLSLShaderNode.h"
#include "fxManagerCmd.h"
#include "AshliShaderStrings.h"
#include "Shader.h"
#include <stdlib.h>
#include <maya/MHWShaderSwatchGenerator.h>
#include <maya/MHardwareRenderer.h>
#include <maya/MGeometryData.h>
#include <maya/MImage.h>
MCallbackId openCallback;
MCallbackId importCallback;
MCallbackId referenceCallback;
static MStatus registerMStringResources(void)
{
MStringResource::registerString(rGLSLShaderNodeFailedResourceContext);
MStringResource::registerString(rGLSLShaderNodeFailedLoadShader);
MStringResource::registerString(rGLSLShaderNodeAshliFailedFindExtensions);
MStringResource::registerString(rGLSLShaderNodeFailedAddAttribute);
MStringResource::registerString(rGLSLShaderNodeFailedDestroyAttribute);
return MS::kSuccess;
}
MStatus initializePlugin( MObject obj )
{
MStatus status;
const char *sm3;
if ( NULL != (sm3 = getenv("ASHLI_SM3_SUPPORT"))) {
if (strcmp( sm3, "0") != 0)
shader::sSupportSM3 = true;
}
const MString& swatchName = MHWShaderSwatchGenerator::initialize();
MString swatchClassification;
const char *ashliEnvVar = getenv("ASHLI_SWATCH_RENDERING");
#ifdef WIN32
if (!ashliEnvVar)
swatchClassification = ":swatch/" + swatchName;
else
{
if ( 0 != strcmp(ashliEnvVar,"0") )
swatchClassification = ":swatch/" + swatchName;
}
#else
if ( ashliEnvVar && ( 0 != strcmp( ashliEnvVar, "0") ) )
{
swatchClassification = ":swatch/" + swatchName;
}
#endif
const MString UserClassify( "shader/surface/utility/" + swatchClassification );
MFnPlugin plugin( obj, "ATI", "6.5", "Any");
status = plugin.registerUIStrings(registerMStringResources, "AshliShaderInitStrings");
if (!status) {
status.perror("registerUIStrings");
return status;
}
CHECK_MSTATUS( plugin.registerNode("AshliShader", glslShaderNode::sId, glslShaderNode::creator, glslShaderNode::initialize,
MPxNode::kHwShaderNode, &UserClassify));
plugin.registerCommand( "effectManager", fxManagerCmd::creator, fxManagerCmd::mySyntax);
openCallback = MSceneMessage::addCallback(MSceneMessage::kAfterOpen, glslShaderNode::rejigShaders);
importCallback = MSceneMessage::addCallback(MSceneMessage::kAfterImport, glslShaderNode::rejigShaders);
referenceCallback = MSceneMessage::addCallback(MSceneMessage::kAfterReference, glslShaderNode::rejigShaders);
return status;
}
MStatus uninitializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj );
MSceneMessage::removeCallback( openCallback);
MSceneMessage::removeCallback( importCallback);
MSceneMessage::removeCallback( referenceCallback);
CHECK_MSTATUS(plugin.deregisterNode(glslShaderNode::sId));
return status;
}