vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UniformUpdateCallback.h
Go to the documentation of this file.
1 #include <osg/Uniform>
2 
3 #include <vrecko/World.h>
4 #include <vrecko/Scene.h>
5 
7 
8 
9 class UniformUpdateCallback : public osg::Uniform::Callback
10 {
11 private:
12 
13  osg::ref_ptr<osg::Camera> camera;
14 
15 private:
16  // Updates viewport size
17  void updateViewport(osg::Uniform* un) const;
18  // Updates position of far clipping plane vertices
19  void updateFarPlane(osg::Uniform* un) const;
20  // Updates camera position
21  void updateCameraPos(osg::Uniform* un) const;
22 
23  void updateViewMatrix(osg::Uniform* un) const;
24  void updateViewMatrixInverse(osg::Uniform* un) const;
25 
26 public:
27  // Takes care of updating uniforms for shaders
28  UniformUpdateCallback(osg::Camera* _camera)
29  : osg::Uniform::Callback(), camera(_camera){
30  }
31 
32  // Calls appropriate function according to uniform name
33  virtual void operator() ( osg::Uniform* un, osg::NodeVisitor* nv )
34  {
35  const std::string& uniformName = un->getName();
36 
37  if ( uniformName == "viewport" ) {
38  updateViewport(un);
39  }
40  else if ( uniformName == "farPlaneVertices" ) {
41  updateFarPlane(un);
42  }
43  else if ( uniformName == "cameraPos" ) {
44  updateCameraPos(un);
45  }
46  else if ( uniformName == "viewMatrix" ) {
47  updateViewMatrix(un);
48  }
49  else if ( uniformName == "viewMatrixInverse" ) {
50  updateViewMatrixInverse(un);
51  }
52  }
53 };