cgfxShaderNode.h
#ifndef _cgfxShaderNode_h_
#define _cgfxShaderNode_h_
#include "cgfxShaderCommon.h"
#include <maya/MFnNumericAttribute.h>
#include <maya/MNodeMessage.h>
#include <maya/MObjectArray.h>
#include <maya/MPxHwShaderNode.h>
#include <maya/MPxNode.h>
#include <maya/MStringArray.h>
#include <maya/MTypeId.h>
#include "cgfxEffectDef.h"
#include "cgfxAttrDef.h"
#define CGFXSHADERNODE_GL_TEXTURE_MAX 32 // GL_TEXTURE31-GL_TEXTURE0+1
#define CGFXSHADERNODE_GL_COLOR_MAX 1
class cgfxShaderNode : public MPxHwShaderNode
{
friend class cgfxShaderCmd;
friend class cgfxAttrDef;
public:
cgfxShaderNode();
virtual void postConstructor();
virtual ~cgfxShaderNode();
virtual MStatus compute( const MPlug& plug, MDataBlock& data );
static void* creator();
static MStatus initialize();
static void initializeNodeAttrs();
virtual void copyInternalData( MPxNode* pSrc );
virtual bool getInternalValueInContext( const MPlug&,
MDataHandle&,
MDGContext&);
virtual bool setInternalValueInContext( const MPlug&,
const MDataHandle&,
MDGContext&);
virtual bool supportsBatching() const;
virtual bool invertTexCoords() const;
virtual bool hasTransparency();
virtual unsigned int transparencyOptions();
virtual MStatus glBind(const MDagPath& shapePath);
void bindAttrValues();
void bindViewAttrValues(const MDagPath& shapePath);
#if MAYA_API_VERSION >= 700
#define _SWATCH_RENDERING_SUPPORTED_ 1
#endif
#if defined(_SWATCH_RENDERING_SUPPORTED_)
virtual MStatus renderSwatchImage( MImage & image );
#endif
virtual MStatus glUnbind(const MDagPath& shapePath);
virtual MStatus glGeometry( const MDagPath& shapePath,
int prim,
unsigned int writable,
int indexCount,
const unsigned int * indexArray,
int vertexCount,
const int * vertexIDs,
const float * vertexArray,
int normalCount,
const float ** normalArrays,
int colorCount,
const float ** colorArrays,
int texCoordCount,
const float ** texCoordArrays);
virtual int getTexCoordSetNames( MStringArray& names );
#if MAYA_API_VERSION >= 700
virtual int getColorSetNames( MStringArray& names );
#else
virtual int colorsPerVertex();
#endif
virtual int normalsPerVertex();
cgfxAttrDefList* attrDefList() const { return fAttrDefList; };
void setAttrDefList(cgfxAttrDefList* list);
MString shaderFxFile() const { return fShaderFxFile; };
bool shaderFxFileChanged() const { return fShaderFxFileChanged; }
void setShaderFxFileChanged(bool val) { fShaderFxFileChanged = val; }
MString getTechnique() const { return fTechnique; };
const MStringArray& getTechniqueList() const { return fTechniqueList; }
void getAttributeList(MStringArray& attrList) const;
void setAttributeList(const MStringArray& attrList);
void setVertexAttributes( cgfxVertexAttribute* attributeList);
void setVertexAttributeSource( const MStringArray& sources);
void analyseVertexAttributes();
const MStringArray& getTexCoordSource() const;
const MStringArray& getColorSource() const;
const MStringArray& getEmptyUVSets() const;
const MObjectArray& getEmptyUVSetShapes() const;
inline bool getTexturesByName() const { return fTexturesByName; };
CGeffect effect() { return fEffect; };
void setEffect(CGeffect effect);
MStatus shouldSave ( const MPlug & plug, bool & ret );
static MString getPluginVersion();
protected:
bool createEffect();
void setShaderFxFile( const MString& fxFile )
{
if (fxFile != fShaderFxFile)
{
fShaderFxFile = fxFile;
fShaderFxFileChanged = true;
}
};
void setTechniqueHasBlending( CGtechnique technique );
void setTechnique( const MString& techn );
void setDataSources( const MStringArray* texCoordSources, const MStringArray* colorSources );
void updateDataSource( MStringArray& sources, MIntArray& typeList, MIntArray& indexList );
void setTexturesByName( bool texturesByName, bool updateAttributes = false);
void reportInternalError( const char* function, size_t errcode);
public:
static MTypeId sId;
static MObject sShader;
static MObject sTechnique;
static MObject sAttributeList;
static MObject sVertexAttributeList;
static MObject sVertexAttributeSource;
static MObject sTexCoordSource;
static MObject sColorSource;
static MObject sTexturesByName;
static CGcontext sCgContext;
static void cgErrorCallBack();
static void cgErrorHandler(CGcontext cgContext, CGerror cgError, void* userData);
protected:
cgfxEffect fNewEffect;
cgfxVertexAttribute* fVertexAttributes;
cgfxAttrDefList* fAttrDefList;
MString fShaderFxFile;
bool fShaderFxFileChanged;
MString fTechnique;
bool fTechniqueHasBlending;
MStringArray fAttributeListArray;
MStringArray fVertexAttributeListArray;
MStringArray fVertexAttributeSource;
bool fTexturesByName;
MStringArray fTexCoordSource;
MStringArray fColorSource;
MStringArray fUVSets;
MStringArray fColorSets;
int fNormalsPerVertex;
MIntArray fTexCoordType;
MIntArray fTexCoordIndex;
MIntArray fColorType;
MIntArray fColorIndex;
MStringArray fDataSetNames;
CGeffect fEffect;
MStringArray fTechniqueList;
GLboolean fDepthEnableState;
GLint fDepthFunc;
GLint fBlendSourceFactor;
GLint fBlendDestFactor;
bool fConstructed;
short fErrorCount;
short fErrorLimit;
MIntArray fCallbackIds;
};
#endif