H3D API  2.4.1
ShaderFunctions.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 __SHADERFUNCTIONS_H__
30 #define __SHADERFUNCTIONS_H__
31 
33 #include <GL/glew.h>
35 
36 #ifdef HAVE_CG
37 #include <Cg/cg.h>
38 #include <Cg/cgGL.h>
39 #endif
40 
41 namespace H3D {
42 
43 
45  template< class SF >
46  class SFUniform : public SF {
47  public:
48  bool actualChanged;
49 
50  SFUniform(){
51  actualChanged = true;
52  SF();
53  }
54  virtual void setValue( const typename SF::value_type &v, int id = 0 ){
55  typename SF::value_type old_value = this->value;
56  SF::setValue( v, id );
57  if( this->value == old_value ) {
58  actualChanged = false;
59  }else {
60  actualChanged = true;
61  }
62  }
63  virtual string getTypeName() { return "SFUniform"; }
64  protected:
65  virtual void update(){
66  typename SF::value_type old_value = this->value;
67  SF::update();
68  if( this->value == old_value ) {
69  actualChanged = false;
70  }else {
71  actualChanged = true;
72  }
73  }
74  };
75 
76  namespace Shaders {
77 #ifdef HAVE_CG
78  CGprofile H3DAPI_API cgProfileFromString( const string &profile,
79  const string &type );
80 
83  bool H3DAPI_API setCGUniformVariableValue( CGprogram program_handle,
84  Field *field );
85 #endif
86  // struct contains the uniform value changed tag and GLSL uniform location
87  struct UniformInfo
88  {
89  Field* field; // associated field for the uniform
90  // uniform field location in shader program, need update after re-link
91  GLint location;
92  };
100  bool H3DAPI_API setGLSLUniformVariableValue( GLhandleARB program_handle,
101  Field *field, UniformInfo* ui = NULL, bool force= false );
102 
103  void H3DAPI_API renderTextures( H3DDynamicFieldsObject *, H3DInt32* max_texture = NULL, H3DInt32* max_image = NULL );
104  void H3DAPI_API renderShaderResources( H3DDynamicFieldsObject *, const GLhandleARB program );
105  void H3DAPI_API postRenderTextures( H3DDynamicFieldsObject *, H3DInt32* max_texture = NULL );
106  void H3DAPI_API preRenderTextures( H3DDynamicFieldsObject *, H3DInt32* max_texture = NULL );
107 
108  GLbitfield H3DAPI_API getAffectedGLAttribs( H3DDynamicFieldsObject * );
109 
110  }
111 }
112 
113 #endif
Header file for H3DDynamicFieldsObject.
Header file for H3DSingleTextureNode, X3D scene-graph node.
The Field class.
Definition: Field.h:46
template class to provide value change checking after update for SField
Definition: ShaderFunctions.h:46
int H3DInt32
H3D API namespace.
Definition: Anchor.h:38