H3D API  2.4.1
ProgramShader.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 __PROGRAMSHADER_H__
30 #define __PROGRAMSHADER_H__
31 
32 #include <H3D/X3DShaderNode.h>
33 #include <H3D/ShaderProgram.h>
36 
37 namespace H3D {
38 
66  class H3DAPI_API ProgramShader :
67  public X3DShaderNode {
68  public:
69 
72  class H3DAPI_API MFShaderProgram:
73  public DependentMFNode< ShaderProgram,
74  FieldRef< H3DDisplayListObject,
75  H3DDisplayListObject::DisplayList,
76  &H3DDisplayListObject::displayList >,
77  true > {
78  protected:
79  virtual void onAdd( Node * n ) {
84  true >::onAdd( n );
85 #ifdef HAVE_CG
86  ShaderProgram *sp = dynamic_cast< ShaderProgram * >( n );
87  if( sp ) {
88  ProgramShader *ps = static_cast< ProgramShader * >( getOwner() );
89  sp->setCGProfile( ps->language->getValue() );
90  }
91 #endif
92  }
93  };
94 
96  ProgramShader( Inst< DisplayList > _displayList = 0,
97  Inst< SFNode > _metadata = 0,
98  Inst< SFBool > _isSelected = 0,
99  Inst< SFBool > _isValid = 0,
100  Inst< SFBool > _activate = 0,
101  Inst< SFString > _language = 0,
102  Inst< MFShaderProgram > _programs = 0 );
103 
105  virtual bool isSupported() {
106  const string &l = language->getValue();
107  bool is_cg =
108  ( l == "CG" || l == "CG_OPENGL_ARB" || l == "CG_OPENGL_NV40"
109  || l == "CG_OPENGL_NV30" || l == "CG_OPENGL_NV20" );
110 #ifndef HAVE_CG
111  if( is_cg ) {
112  Console(LogLevel::Error) << "Warning: H3D API compiled without cg support. ProgramShader "
113  << " node will not support CG." << endl;
114  }
115  return false;
116 #endif
117  return is_cg;
118  }
119 
120 #ifdef HAVE_CG
122  virtual void render();
123 
125  virtual void preRender();
126 
128  virtual void postRender();
129 #endif
130 
136  H3DUniquePtr< MFShaderProgram > programs;
137 
140 
141  };
142 }
143 
144 #endif
Contains the DependentSFNode and DependentMFNode template classes.
Header file for ShaderProgram, X3D scene-graph node.
Header file for X3DProgrammableShaderObject.
Header file for X3DShaderNode, X3D scene-graph node.
DependentMFNode are modified TypedMFNode fields where the field dirty status is dependent on fields i...
Definition: DependentNodeFields.h:336
Class used for specifying a field member of a node in a DependentSFNode or DependentMFNode specificat...
Definition: DependentNodeFields.h:48
We use the Field's lazy evaluation mechanisms to manage the GL display lists for rendering,...
Definition: H3DDisplayListObject.h:60
This abstract interface class is the base class for all node types that wants to create an OpenGL dis...
Definition: H3DDisplayListObject.h:54
H3DUniquePtr< DisplayList > displayList
The DisplayList instance handling the OpenGL caching of this object.
Definition: H3DDisplayListObject.h:256
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
The MFShaderProgram class sets the profile for each ShaderProgram node that is added to it.
Definition: ProgramShader.h:77
he ProgramShader node defines a shader that can consist of one or more individually programmable,...
Definition: ProgramShader.h:67
virtual bool isSupported()
Returns true if the shader node type is supported by the browser.
Definition: ProgramShader.h:105
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: ProgramShader.h:139
H3DUniquePtr< MFShaderProgram > programs
The shader programs to use in the ProgramShader.
Definition: ProgramShader.h:136
The ShaderProgram node provides the source and interface to a self contained program that occupies on...
Definition: ShaderProgram.h:68
virtual void setCGProfile(const string &profile)
Set the cg profile to use.
Definition: ShaderProgram.cpp:233
This abstract node type is the base type for all node types which specify a programmable shader.
Definition: X3DShaderNode.h:61
H3DUniquePtr< SFString > language
The language field is used to indicate to the browser which shading language is used for the source f...
Definition: X3DShaderNode.h:131
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