PackagedShader.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
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 

Generated on Thu Aug 24 12:38:33 2006 for H3D API by  doxygen 1.4.5