H3D API  2.4.1
PackagedShader.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __PACKAGEDSHADER_H__
30 #define __PACKAGEDSHADER_H__
31 
32 #include <H3D/X3DShaderNode.h>
34 #include <H3D/X3DUrlObject.h>
35 #include <GL/glew.h>
36 
37 #ifdef HAVE_CG
38 #include <Cg/cg.h>
39 #include <Cg/cgGL.h>
40 #endif
41 
42 namespace H3D {
43 
64  class H3DAPI_API PackagedShader :
65  public X3DShaderNode,
66  public X3DUrlObject,
68  public:
69 
71  PackagedShader( Inst< DisplayList > _displayList = 0,
72  Inst< SFNode > _metadata = 0,
73  Inst< SFBool > _isSelected = 0,
74  Inst< SFBool > _isValid = 0,
75  Inst< SFBool > _activate = 0,
76  Inst< SFString > _language = 0,
77  Inst< MFString > _url = 0 );
78 
80  virtual bool isSupported() {
81  const string &l = language->getValue();
82  bool is_cg =
83  ( l == "CG" || l == "CG_OPENGL_ARB" || l == "CG_OPENGL_NV40"
84  || l == "CG_OPENGL_NV30" || l == "CG_OPENGL_NV20" );
85 #ifndef HAVE_CG
86  if( is_cg ) {
87  Console(LogLevel::Error) << "Warning: H3D API compiled without cg support. PackagedShader "
88  << " node will not support CG." << endl;
89  }
90  return false;
91 #endif
92  return is_cg;
93  }
94 
95 
96 #ifdef HAVE_CG
99  virtual bool addField( const string &_name,
100  const Field::AccessType &access,
101  Field *field );
102 
104  virtual void render();
105 
107  virtual void preRender();
108 
110  virtual void postRender();
111 
113  virtual void initCGShaderProgram();
114 #endif
115 
118 
119 #ifdef HAVE_CG
120  protected:
121  CGprofile cg_vertex_profile;
122  CGprofile cg_fragment_profile;
123  CGcontext cg_context;
124  CGprogram cg_vertex_program;
125  CGprogram cg_fragment_program;
126  string source_url;
127 #endif
128  };
129 }
130 
131 #endif
132 
133 
134 
Header file for X3DProgrammableShaderObject.
Header file for X3DShaderNode, X3D scene-graph node.
Header file for X3DUrlObject, X3D scene-graph node.
The Field class.
Definition: Field.h:46
AccessType
The different access types that a field can have.
Definition: Field.h:53
A PackagedShader node describes a single file that may contain a number of shaders and combined effec...
Definition: PackagedShader.h:67
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: PackagedShader.h:117
virtual bool isSupported()
Returns true if the shader node type is supported by the browser.
Definition: PackagedShader.h:80
This abstract node type is the base type for all node types that specify arbitrary fields for interfa...
Definition: X3DProgrammableShaderObject.h:64
This abstract node type is the base type for all node types which specify a programmable shader.
Definition: X3DShaderNode.h:61
This abstract interface is inherited by all nodes that contain data located on the World Wide Web,...
Definition: X3DUrlObject.h:51
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194