#ifndef OBSERVER_H
#define OBSERVER_H
#include <map>
#include <vector>
#include <string>
#include <IAshliFX.h>
#include "glExtensions.h"
class stateItem {
public:
virtual ~stateItem() {};
virtual void apply() = 0;
};
class blendStateItem : public stateItem {
GLenum m_enable;
GLenum m_srcFactor;
GLenum m_dstFactor;
GLenum m_blendOp;
union {
GLbitfield m_options;
struct {
unsigned int m_useEnable : 1;
unsigned int m_useBlend : 1;
unsigned int m_getSrcFactor : 1;
unsigned int m_getDstFactor : 1;
unsigned int m_useBlendFunc : 1;
unsigned int m_useBlendOp : 1;
};
};
public:
blendStateItem() : m_enable(GL_FALSE), m_srcFactor(GL_ONE), m_dstFactor(GL_ZERO), m_blendOp(GL_FUNC_ADD), m_options(0) {};
virtual ~blendStateItem() {};
virtual void apply();
friend class stateObserver;
};
class depthStateItem : public stateItem {
GLenum m_enable;
GLenum m_depthFunc;
GLboolean m_depthMask;
union {
GLbitfield m_options;
struct {
unsigned int m_useEnable : 1;
unsigned int m_useDepthFunc : 1;
unsigned int m_useDepthMask : 1;
};
};
public:
depthStateItem() : m_enable(0), m_depthFunc(GL_LEQUAL), m_depthMask(GL_TRUE), m_options(0) {};
virtual ~depthStateItem() {};
virtual void apply();
friend class stateObserver;
};
class stencilStateItem : public stateItem {
GLenum m_enable;
GLenum m_func;
GLuint m_rmask;
GLuint m_ref;
GLenum m_depthPassOp;
GLenum m_depthFailOp;
GLenum m_stencilFailOp;
GLuint m_mask;
union {
GLbitfield m_options;
struct {
unsigned int m_useEnable : 1;
unsigned int m_useStencilFunc : 1;
unsigned int m_getStencilFunc : 1;
unsigned int m_getStencilRMask : 1;
unsigned int m_getStencilRef : 1;
unsigned int m_useStencilOp : 1;
unsigned int m_getDepthPass : 1;
unsigned int m_getDepthFail : 1;
unsigned int m_getStencilFail : 1;
unsigned int m_useStencilMask : 1;
};
};
public:
stencilStateItem() : m_enable(0), m_func(GL_EQUAL), m_rmask(0xff), m_ref(0), m_depthPassOp(GL_KEEP), m_depthFailOp(GL_KEEP),
m_stencilFailOp(GL_KEEP), m_mask(0xff), m_options(0) {};
virtual ~stencilStateItem() {};
virtual void apply();
friend class stateObserver;
};
class primitiveStateItem : public stateItem {
GLenum m_polygonMode;
GLenum m_enableCull;
GLenum m_cullFace;
GLenum m_enablePolygonOffset;
GLfloat m_factor;
GLfloat m_units;
union {
GLbitfield m_options;
struct {
unsigned int m_usePolygonMode : 1;
unsigned int m_useEnableCull : 1;
unsigned int m_useCullFace : 1;
unsigned int m_useEnablePolygonOffset : 1;
unsigned int m_usePolygonOffset : 1;
unsigned int m_getFactor : 1;
unsigned int m_getUnits : 1;
};
};
public:
primitiveStateItem() : m_polygonMode(GL_FILL), m_enableCull(GL_FALSE), m_cullFace(GL_BACK), m_enablePolygonOffset(GL_FALSE),
m_factor(0.0f), m_units(0.0f), m_options(0) {};
virtual ~primitiveStateItem() {};
virtual void apply();
friend class stateObserver;
};
class alphaStateItem : public stateItem {
GLenum m_enable;
GLenum m_alphaFunc;
GLfloat m_ref;
union {
GLbitfield m_options;
struct {
unsigned int m_useEnable : 1;
unsigned int m_useAlphaFunc : 1;
unsigned int m_getAlphaFunc : 1;
unsigned int m_getRef : 1;
};
};
public:
alphaStateItem() : m_enable(GL_FALSE), m_alphaFunc(GL_ALWAYS), m_ref(0.0f), m_options(0) {};
virtual ~alphaStateItem() {};
virtual void apply();
friend class stateObserver;
};
class colorStateItem : public stateItem {
GLenum m_dither;
GLboolean m_mask[4];
union {
GLbitfield m_options;
struct {
unsigned int m_useDither : 1;
unsigned int m_useMask : 1;
};
};
public:
colorStateItem() : m_dither(GL_TRUE), m_options(0) {};
virtual ~colorStateItem() {};
virtual void apply();
friend class stateObserver;
};
class fogStateItem : public stateItem {
GLenum m_enable;
GLenum m_mode;
GLfloat m_start;
GLfloat m_end;
GLfloat m_density;
GLfloat m_color[3];
union {
GLbitfield m_options;
struct {
unsigned int m_useEnable : 1;
unsigned int m_useMode : 1;
unsigned int m_useFogStart : 1;
unsigned int m_useFogEnd : 1;
unsigned int m_useFogDensity : 1;
unsigned int m_useFogColor : 1;
};
};
public:
fogStateItem() : m_enable(GL_FALSE), m_mode(GL_LINEAR), m_start(0.0f), m_end(1.0f), m_density(1.0f), m_options(0) {};
virtual ~fogStateItem() {};
virtual void apply();
friend class stateObserver;
};
class pointStateItem : public stateItem {
GLfloat m_pointSize;
GLfloat m_pointSizeMin;
GLfloat m_pointSizeMax;
GLfloat m_pointAtten[3];
GLenum m_pointSprite;
union {
GLbitfield m_options;
struct {
unsigned int m_usePointSize : 1;
unsigned int m_usePointSizeMin : 1;
unsigned int m_usePointSizeMax : 1;
unsigned int m_usePointAtten : 1;
unsigned int m_getAttenA : 1;
unsigned int m_getAttenB : 1;
unsigned int m_getAttenC : 1;
unsigned int m_usePointSprite : 1;
};
};
public:
pointStateItem() : m_pointSize(1.0f), m_pointSizeMin(1.0f), m_pointSizeMax(32.0f), m_pointSprite(GL_FALSE), m_options(0) {};
virtual ~pointStateItem() {};
virtual void apply();
friend class stateObserver;
};
class passState {
public:
passState() {};
~passState();
void setState();
std::map< std::string, int> m_vRegMap;
std::map< std::string, int> m_fRegMap;
std::vector<stateItem*> m_stateList;
};
class stateObserver : IObserveFX {
public:
stateObserver() : m_state(NULL), m_bs(NULL), m_ds(NULL), m_ss(NULL), m_ps(NULL), m_as(NULL), m_cs(NULL), m_fs(NULL), m_ptS(NULL) {};
~stateObserver() {};
void setLightState(LightState state, int handle, const char* value);
void setMaterialState(MaterialState state, int handle, const char* value);
void setVertexRenderState(VertexRenderState state, int handle, const char* value);
void setPixelRenderState(PixelRenderState state, int handle, const char* value);
void setSamplerState(SamplerState state, int handle, const char* value);
void setVertexShaderState(VertexShaderState state, int handle, const char* value);
void setPixelShaderState(PixelShaderState state, int handle, const char* value);
void setTextureState(TextureState state, int handle, const char* value);
void setTransformState(TransformState state, int handle, const char* value);
void setPassMonitor( passState *state);
void finalizePassMonitor();
protected:
bool isTrue( const char* value);
bool isFalse( const char* value);
GLenum compareFunc( const char* value);
GLenum blendFactor( const char* value);
GLenum stencilOp( const char* value);
GLenum blendOp( const char* value);
GLenum polyMode( const char* value);
passState *m_state;
blendStateItem *m_bs;
depthStateItem *m_ds;
stencilStateItem *m_ss;
primitiveStateItem *m_ps;
alphaStateItem *m_as;
colorStateItem *m_cs;
fogStateItem *m_fs;
pointStateItem *m_ptS;
};
#endif //OBSERVER_H