H3D API  2.4.1
ShaderPart.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 __SHADERPART_H__
30 #define __SHADERPART_H__
31 
32 #include <H3D/X3DNode.h>
33 #include <H3D/X3DUrlObject.h>
34 #include <GL/glew.h>
35 #include <H3D/SFString.h>
36 #include <H3D/SFInt32.h>
37 #include <H3D/SFBool.h>
38 #include <H3D/DebugOptions.h>
39 
40 namespace H3D {
41  // forward declarations
42  class ComposedShader;
43 
77  class H3DAPI_API ShaderPart :
78  public X3DNode,
79  public X3DUrlObject {
80  public:
82  class H3DAPI_API SFShaderString : public TypedField< EventCollectingField< SFString >,
83  Types<MFString,SFBool>, AnyNumber< Field > > {
84  protected:
85  virtual void update();
86 
90  virtual bool doFullRebuild();
91 
92  public:
96  bool modifyShaderConstants(Field* field);
97  };
98 
100  ShaderPart( Inst< SFNode > _metadata = 0,
101  Inst< MFString > _url = 0,
102  Inst< SFString > _type = 0,
103  Inst< SFShaderString > _shaderString = 0,
104  Inst< SFBool > _forceReload = 0);
105 
109  virtual GLhandleARB compileShader();
110 
112  void setParentComposedShader( ComposedShader *s );
113 
116  return parent_composed_shader;
117  }
118 
122  bool modifyShaderConstants(Field* field);
123 
129  bool replaceString( string &string_to_update,
130  const std::string& string_start,
131  const std::string& string_end,
132  const std::string& to_insert,
133  const std::string& conditional_string = "");
134 
137  inline GLhandleARB getShaderHandle() {
138  return shader_handle;
139  }
140 
143  virtual bool isCompiled ();
144 
152  H3DUniquePtr< SFString > type;
153 
163  H3DUniquePtr< SFShaderString > shaderString;
164 
172  H3DUniquePtr< SFBool > forceReload;
173 
176  virtual string defaultXMLContainerField() {
177  return "parts";
178  }
179 
183  virtual X3DUrlObject::LoadStatus loadStatus();
184 
187 
188  protected:
191 
193  GLhandleARB shader_handle;
194  GLhandleARB compileShaderPart();
195 
197  bool getConstantVariableString(Field* const in_variable,
198  std::string& out_name, std::string& out_type, std::string& out_field_value);
199 
201  std::string shaderStringFromURL ( const std::string& shader_url );
202 
212  std::string preProcess ( const std::string& input, const std::string& _url, int depth= 0 );
213 
219  void updateShaderConstantValues( std::string &input, bool update_all_values );
220 
222  void updateSinglePassStereoValues( std::string &input );
223 
224  bool printShaderLog();
225  DebugOptions *debug_options_previous;
226  public:
227  virtual void initialize();
228  };
229 }
230 
231 #endif
Header file for DebugOptions.
Contains the SFBool field class.
Contains the SFInt32 field class.
Contains the SFString field class.
Header file for X3DNode, X3D scene-graph node.
Header file for X3DUrlObject, X3D scene-graph node.
The ComposedShader node defines a shader where the individual source files are not individually progr...
Definition: ComposedShader.h:77
Specifies parameters for if displaying debug information like bounding boxes, haptically rendered tri...
Definition: DebugOptions.h:46
The Field class.
Definition: Field.h:46
Update the string to use as shader depending from the urls given.
Definition: ShaderPart.h:83
The ShaderPart node defines the source for a single object to be used by a ComposedShader node.
Definition: ShaderPart.h:79
H3DUniquePtr< SFBool > forceReload
The forceReload field is used to force the reloading of this shaderPart and also cause the composed s...
Definition: ShaderPart.h:172
H3DUniquePtr< SFString > type
The type field indicates whether this object shall be compiled as a vertex shader,...
Definition: ShaderPart.h:152
ComposedShader * getParentComposedShader()
Get the ComposedShader instance that this ShaderPart is a child to.
Definition: ShaderPart.h:115
H3DUniquePtr< SFShaderString > shaderString
A field that contains the string loaded from file and to be used as input to the shader.
Definition: ShaderPart.h:163
virtual string defaultXMLContainerField()
Returns the default xml containerField attribute value.
Definition: ShaderPart.h:176
GLhandleARB getShaderHandle()
Get the handle to the shader object that currently is used for this ShaderPart.
Definition: ShaderPart.h:137
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: ShaderPart.h:186
GLhandleARB shader_handle
The handle to the shader object used for this ShaderPart.
Definition: ShaderPart.h:193
ComposedShader * parent_composed_shader
The ComposedShader instance that this ShaderPart is a child to.
Definition: ShaderPart.h:190
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
This abstract node type is the base type for all nodes in the X3D system.
Definition: X3DNode.h:65
This abstract interface is inherited by all nodes that contain data located on the World Wide Web,...
Definition: X3DUrlObject.h:51
LoadStatus
The load status of the given url.
Definition: X3DUrlObject.h:60
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