#ifndef _cgfxEffectDef_h_
#define _cgfxEffectDef_h_
#include "cgfxShaderCommon.h"
class cgfxShaderNode;
class cgfxEffect;
class cgfxPassStateSetter;
#include <maya/MDagPath.h>
#include <maya/MObjectHandle.h>
class cgfxVertexAttribute
{
public:
cgfxVertexAttribute();
MString fName;
MString fSemantic;
MString fUIName;
MString fType;
MString fSourceName;
enum SourceType
{
kNone,
kPosition,
kNormal,
kUV,
kTangent,
kBinormal,
kColor,
kBlindData,
kUnknown
} fSourceType;
int fSourceIndex;
cgfxVertexAttribute* fNext;
};
struct sourceStreamInfo
{
cgfxVertexAttribute::SourceType fSourceType;
MString fSourceName;
unsigned int fOffset;
unsigned int fStride;
unsigned int fDimension;
unsigned int fElementSize;
GLuint fDataBufferId;
};
#define MAX_STRUCTURE_ELEMENTS 16
class cgfxVaryingParameterStructure
{
public:
int fLength;
int fSize;
struct cgfxVaryingParameterElement
{
cgfxVertexAttribute* fVertexAttribute;
int fSize;
};
cgfxVaryingParameterElement fElements[ MAX_STRUCTURE_ELEMENTS];
};
class cgfxStructureCache
{
public:
cgfxStructureCache( const MDagPath& shape, const MString& name, int stride, int count);
~cgfxStructureCache();
MObjectHandle fShape;
MString fName;
int fElementSize;
int fVertexCount;
char* fData;
cgfxStructureCache* fNext;
};
class cgfxVaryingParameter
{
public:
cgfxVaryingParameter( CGparameter parameter);
~cgfxVaryingParameter();
void setupAttributes( cgfxVertexAttribute*& vertexAttributes, CGprogram program);
cgfxVertexAttribute* setupAttribute( MString name, const MString& semantic, CGparameter parameter, cgfxVertexAttribute*& vertexAttributes);
void bind( const MDagPath& shape, cgfxStructureCache** cache,
int vertexCount, const float * vertexArray,
int normalsPerVertex, int normalCount, const float ** normalArrays,
int colorCount, const float ** colorArrays,
int texCoordCount, const float ** texCoordArrays);
bool bind( const float* data, int stride);
bool bind(const sourceStreamInfo& source);
void null();
CGparameter fParameter;
MString fName;
int fGLType;
int fGLIndex;
cgfxVertexAttribute* fVertexAttribute;
cgfxVaryingParameterStructure* fVertexStructure;
cgfxVaryingParameter* fNext;
};
class cgfxPass
{
public:
cgfxPass( CGpass pass, cgfxEffect* effect);
~cgfxPass();
void setupAttributes( cgfxVertexAttribute*& vertexAttributes);
void bind( const MDagPath& shape,
int vertexCount, const float * vertexArray,
int normalsPerVertex, int normalCount, const float ** normalArrays,
int colorCount, const float ** colorArrays,
int texCoordCount, const float ** texCoordArrays);
void bind(const sourceStreamInfo dataSources[], const int sourceCount);
CGpass fPass;
CGprogram fProgram;
MString fName;
cgfxEffect* fEffect;
cgfxVaryingParameter* fParameters;
cgfxPassStateSetter* fPassState;
cgfxPass* fNext;
};
class cgfxTechnique
{
public:
cgfxTechnique( CGtechnique technique, cgfxEffect* effect);
~cgfxTechnique();
void setupAttributes( cgfxVertexAttribute*& vertexAttributes);
CGtechnique fTechnique;
MString fName;
cgfxEffect* fEffect;
cgfxPass* fPasses;
bool fValid;
bool fMultiPass;
cgfxTechnique* fNext;
};
class cgfxEffect
{
public:
cgfxEffect();
~cgfxEffect();
void setEffect( CGeffect effect);
void setupAttributes( cgfxShaderNode* shader);
void flushCache();
void flushCache( const MDagPath& shape);
CGeffect fEffect;
cgfxTechnique* fTechnique;
cgfxTechnique* fTechniques;
cgfxStructureCache* fCache;
};
#undef VALID
#endif