00001
00002
00003 #ifndef __GL_SHADER_H
00004 #define __GL_SHADER_H
00005
00006 #include <gra/shader/LocalShader.h>
00007 #include <esg/energy/PolygonalEnergy.h>
00008 #include <gra/reflection/GLReflection.h>
00009 #include <esg/SceneGraphObject.h>
00010 #include <GL/gl.h>
00011
00012 using namespace esg;
00013
00014 namespace gra {
00015
00029 class GRA_EXPORT GLShader : public LocalShader {
00030 public:
00034 enum MeshMode {
00035 VERTICES,
00036 EDGES,
00037 FACETS,
00038 FACET_EDGES,
00039 FACET_CORNERS
00040 };
00041
00045 enum ShadingMode {
00046 COLOR,
00047 FLAT,
00048 SMOOTH,
00049 TEXTURE
00050 };
00051
00056 enum FacetMode {
00057 AUTO,
00058 FRONT,
00059 BACK,
00060 FRONT_AND_BACK
00061 };
00062
00063 protected:
00064 MeshMode _meshMode;
00065 ShadingMode _shadingMode;
00066 int _meshDensity;
00067 FacetMode _facetMode;
00068
00069 protected:
00070 void _illum_vertices (Mesh&) const;
00071 void _illum_edges (Mesh&) const;
00072 void _illum_facets (GLenum, Mesh&) const;
00073 bool _use_precomputed_energy (PolygonalEnergy&) const;
00074
00075 public:
00084 GLShader (MeshMode mmode = FACETS,
00085 ShadingMode smode = SMOOTH,
00086 int density = 1,
00087 FacetMode fmode = AUTO)
00088 : LocalShader(new GLReflection(), NULL, NULL, false),
00089 _meshMode(mmode),
00090 _shadingMode(smode),
00091 _meshDensity(density),
00092 _facetMode(fmode) {
00093 if (_shadingMode == FLAT) {
00094 if (_meshMode == VERTICES) _meshMode = FACET_CORNERS;
00095 if (_meshMode == EDGES) _meshMode = FACET_EDGES;
00096 }
00097 }
00098
00102 virtual ~GLShader () {
00103 if (_pReflectionModel) delete _pReflectionModel;
00104 }
00105
00113 virtual bool setRenderedShape (SceneGraphObject * pShape,
00114 const Matrix4 * pTrMat);
00115
00132 virtual Color3f* illuminatePoint (const Vector3& location,
00133 const Vector3& normal,
00134 const Vector3& eyeDir,
00135 float eyeDist,
00136 double* pNV,
00137 const Matrix4* pTrMat) {
00138 return NULL;
00139 }
00140
00146 virtual void setMeshDensity (int d) { _meshDensity = d; }
00147
00151 virtual int getMeshDensity () const { return _meshDensity; }
00152 };
00153
00154 }
00155
00156 #endif // __GL_SHADER_H