hlslFXShader.h
#ifndef HLSL_FX_SHADER_H
#define HLSL_FX_SHADER_H
#include <vector>
#include <string>
#include <IAshliFX.h>
#include <IAshli.h>
#include "Shader.h"
#include "Observer.h"
#include "glExtensions.h"
class hlslFXShader : public shader {
struct uniform;
public:
hlslFXShader( );
virtual ~hlslFXShader();
bool createFromFile( const char *filename);
bool createFromFX( IAshliFX *fx);
protected:
bool parseParameters( const IAshliFX *fx);
DataType parseUniformType( const char *type);
Semantic parseUniformSemantic( const char *semantic);
SamplerType parseSamplerType( const char *type);
void parseExpression( uniform &u, const char *exp);
void updateHandles();
bool buildShaders();
const char* getVertexShader( int pass);
const char* getPixelShader( int pass);
public:
virtual bool valid();
virtual int passCount();
virtual int techniqueCount();
virtual const char* techniqueName( int n);
virtual bool build();
virtual void bind();
virtual void setShapeDependentState();
virtual void unbind();
virtual void setTechnique( int t);
virtual void setPass( int p);
virtual int uniformCount();
virtual int samplerCount();
virtual int attributeCount();
virtual const char* uniformName(int i);
virtual DataType uniformType(int i);
virtual Semantic uniformSemantic(int i);
virtual float* uniformDefault(int i);
virtual const char* samplerName(int i);
virtual SamplerType samplerType(int i);
virtual const char* attributeName(int i);
virtual DataType attributeType(int i);
virtual int attributeHandle(int i) {return 0;};
virtual void updateUniformBool( int i, bool val);
virtual void updateUniformInt( int i, int val);
virtual void updateUniformFloat( int i, float val);
virtual void updateUniformBVec( int i, const bool* val);
virtual void updateUniformIVec( int i, const int* val);
virtual void updateUniformVec( int i, const float* val);
virtual void updateUniformMat( int i, const float* val);
virtual void updateUniformMat( int i, const double* val);
virtual void updateSampler( int i, unsigned int val);
virtual bool usesColor();
virtual bool usesNormal();
virtual bool usesTexCoord( int set);
virtual bool usesTangent();
virtual bool usesBinormal();
virtual int tangentSlot();
virtual int binormalSlot();
virtual const char* errorString();
private:
void deleteShaders();
std::vector<GLuint> m_fShader;
std::vector<GLuint> m_vShader;
int m_techniqueCount;
std::vector<std::string> m_techniqueNames;
std::vector<int> m_passCount;
std::vector<int> m_techniqueOffset;
std::vector<std::string> m_vertexShaders;
std::vector<std::string> m_fragmentShaders;
std::vector<std::string> m_orgVertexShaders;
std::vector<std::string> m_orgFragmentShaders;
std::vector<passState*> m_stateList;
bool m_valid;
struct uniform {
std::string name;
DataType type;
Semantic usage;
std::vector<int> fReg;
std::vector<int> vReg;
float fVal[16];
float defaultVal[16];
bool dirty;
};
struct attribute {
std::string name;
DataType type;
std::vector<int> handle;
};
struct sampler {
std::string name;
SamplerType type;
GLuint texObject;
std::vector<int> texUnit;
bool dirty;
};
std::vector<uniform> m_uniformList;
std::vector<attribute> m_attributeList;
std::vector<sampler> m_samplerList;
bool m_stale;
bool m_color;
bool m_normal;
bool m_tangent;
bool m_binormal;
unsigned int m_texMask;
int m_tangentSlot;
int m_binormalSlot;
int m_activePass;
int m_activeTechnique;
std::string m_error;
};
#endif //GLSL_FX_SHADER_H