ProgramShader.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 __PROGRAMSHADER_H__
00030 #define __PROGRAMSHADER_H__
00031 
00032 #include "X3DShaderNode.h"
00033 #include "ShaderProgram.h"
00034 #include "X3DProgrammableShaderObject.h"
00035 #include "DependentNodeFields.h"
00036 
00037 namespace H3D {
00038 
00062   class H3DAPI_API ProgramShader : 
00063     public X3DShaderNode {
00064   public:
00065   
00068     class H3DAPI_API MFShaderProgram: 
00069       public DependentMFNode< ShaderProgram, 
00070                               FieldRef< H3DDisplayListObject,
00071                                         H3DDisplayListObject::DisplayList,
00072                                         &H3DDisplayListObject::displayList >, 
00073                               true > {
00074     protected:
00075       virtual void onAdd( Node * n ) {
00076         DependentMFNode< ShaderProgram, 
00077                          FieldRef< H3DDisplayListObject,
00078                                    H3DDisplayListObject::DisplayList,
00079                                    &H3DDisplayListObject::displayList >, 
00080                          true >::onAdd( n );
00081 #ifdef HAVE_CG
00082         ShaderProgram *sp = dynamic_cast< ShaderProgram * >( n );
00083         if( sp ) {
00084           ProgramShader *ps = static_cast< ProgramShader * >( getOwner() );
00085           sp->setCGProfile( ps->language->getValue() );
00086         }
00087 #endif
00088       }
00089     };
00090 
00092     ProgramShader( Inst< DisplayList     > _displayList = 0,
00093                    Inst< SFNode          > _metadata    = 0,
00094                    Inst< SFBool          > _isSelected  = 0,
00095                    Inst< SFBool          > _isValid     = 0,
00096                    Inst< SFBool          > _activate    = 0,
00097                    Inst< SFString        > _language    = 0,
00098                    Inst< MFShaderProgram > _programs    = 0 );
00099     
00101     virtual bool isSupported() {
00102       const string &l = language->getValue();
00103       bool is_cg = 
00104         ( l == "CG" || l == "CG_OPENGL_ARB" || l == "CG_OPENGL_NV40" 
00105           || l == "CG_OPENGL_NV30" || l == "CG_OPENGL_NV20" );
00106 #ifndef HAVE_CG
00107       if( is_cg ) {
00108         Console(4) << "Warning: H3D API compiled without cg support. ProgramShader "
00109                    << " node will not support CG." << endl;
00110       }
00111       return false;
00112 #endif
00113       return is_cg;  
00114     }
00115 
00116 #ifdef HAVE_CG
00117 
00118     virtual void render();
00119 
00121     virtual void preRender();
00122 
00124     virtual void postRender();
00125 #endif
00126 
00132     auto_ptr< MFShaderProgram > programs;
00133 
00135     static H3DNodeDatabase database;
00136     
00137   };
00138 }
00139 
00140 #endif

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