00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _ISHADING_H_
00017 #define _ISHADING_H_
00018
00019
00020 #include <GL/glew.h>
00021 #include <GL/gl.h>
00022
00023
00024 #include <vector>
00025
00026
00027 #include <maya/MGlobal.h>
00028 #include <maya/MFnTransform.h>
00029 #include <maya/MItSelectionList.h>
00030 #include <maya/MVector.h>
00031 #include <maya/MMatrix.h>
00032
00033
00034 #include <Cg/cg.h>
00035 #include <Cg/cgGL.h>
00036
00037
00038 #include <error_checker.h>
00039
00040 #ifdef _WIN32
00041 # pragma warning( disable:4244 )
00042 #endif
00043
00044
00045
00046
00047
00049 class IShading {
00050
00051 friend class ISphereShading;
00052 friend class IQuadricShading;
00053 friend class IMaterial;
00054
00055 private:
00056
00058 IShading();
00059
00061 ~IShading();
00062
00063 private:
00064
00066 static inline void
00067 checkCgError( const std::string& msg = "");
00068
00070 static void
00071 loadProgram( CGcontext& ctx, CGprofile& profile, CGprogram& prog, const std::string& path);
00072
00073 private:
00074
00076 inline void activate() const;
00077
00079 inline void activateFBO() const;
00080
00082 inline void deactivate() const;
00083
00085 inline void deactivateFBO() const;
00086
00087 public:
00088
00090 void readbackFBO();
00091
00092
00093 void createFBO();
00094
00096 inline CGprogram* getVpProgram() { return &vp_prog; };
00097
00099 inline CGprogram* getFpProgram() { return &fp_prog; };
00100
00101 private:
00102
00104 static CGcontext ctx;
00105
00107 CGprogram fp_prog;
00108 CGprogram vp_prog;
00109
00110
00111 static CGprofile fp_profile;
00112 static CGprofile vp_profile;
00113
00115 CGparameter mv;
00117 CGparameter mvp;
00119 CGparameter p;
00120
00122 CGparameter plPos;
00123
00125 GLuint fbo;
00126 };
00127
00131 inline void
00132 IShading::checkCgError( const std::string& msg) {
00133
00134 CGerror err = cgGetError();
00135 if( GL_NO_ERROR != err) {
00136
00137 #ifdef _WIN32
00138 std::cerr << "Cg Error : " << cgGetErrorString( err) << std::endl;
00139 #else
00140 std::cerr << "Cg Error @ " << msg << " : " << cgGetErrorString( err) << std::endl;
00141 #endif
00142 }
00143 }
00144
00148 inline void
00149 IShading::activate() const {
00150
00151 cgGLEnableProfile( fp_profile);
00152 cgGLEnableProfile( vp_profile);
00153
00154 cgGLBindProgram( fp_prog);
00155 cgGLBindProgram( vp_prog);
00156 }
00157
00161 inline void
00162 IShading::activateFBO() const {
00163
00164 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo);
00165 glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT);
00166 }
00167
00171 inline void
00172 IShading::deactivate() const {
00173
00174 cgGLDisableProfile( fp_profile);
00175 cgGLDisableProfile( vp_profile);
00176 }
00177
00181 inline void
00182 IShading::deactivateFBO() const {
00183
00184 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0);
00185 glDrawBuffer( GL_BACK);
00186 }
00187
00188 #endif // _SHADING_IMPL_H_