00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00027
00029 #ifndef __PACKAGEDSHADER_H__
00030 #define __PACKAGEDSHADER_H__
00031
00032 #include "X3DShaderNode.h"
00033 #include "X3DProgrammableShaderObject.h"
00034 #include "X3DUrlObject.h"
00035 #include <GL/glew.h>
00036
00037 #ifdef HAVE_CG
00038 #include <Cg/cg.h>
00039 #include <Cg/cgGL.h>
00040 #endif
00041
00042 namespace H3D {
00043
00060 class H3DAPI_API PackagedShader :
00061 public X3DShaderNode,
00062 public X3DUrlObject,
00063 public X3DProgrammableShaderObject {
00064 public:
00065
00067 PackagedShader( Inst< DisplayList > _displayList = 0,
00068 Inst< SFNode > _metadata = 0,
00069 Inst< SFBool > _isSelected = 0,
00070 Inst< SFBool > _isValid = 0,
00071 Inst< SFBool > _activate = 0,
00072 Inst< SFString > _language = 0,
00073 Inst< MFString > _url = 0 );
00074
00076 virtual bool isSupported() {
00077 const string &l = language->getValue();
00078 bool is_cg =
00079 ( l == "CG" || l == "CG_OPENGL_ARB" || l == "CG_OPENGL_NV40"
00080 || l == "CG_OPENGL_NV30" || l == "CG_OPENGL_NV20" );
00081 #ifndef HAVE_CG
00082 if( is_cg ) {
00083 Console(4) << "Warning: H3D API compiled without cg support. ProgramShader "
00084 << " node will not support CG." << endl;
00085 }
00086 return false;
00087 #endif
00088 return is_cg;
00089 }
00090
00091
00092 #ifdef HAVE_CG
00095 virtual bool addField( const string &name,
00096 const Field::AccessType &access,
00097 Field *field );
00098
00100 virtual void render();
00101
00103 virtual void preRender();
00104
00106 virtual void postRender();
00107
00109 virtual void initCGShaderProgram();
00110 #endif
00111
00113 static H3DNodeDatabase database;
00114
00115 #ifdef HAVE_CG
00116 protected:
00117 CGprofile cg_vertex_profile;
00118 CGprofile cg_fragment_profile;
00119 CGcontext cg_context;
00120 CGprogram cg_vertex_program;
00121 CGprogram cg_fragment_program;
00122 string source_url;
00123 #endif
00124 };
00125 }
00126
00127 #endif
00128
00129
00130