VR-Forces 4.5 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtPostProcessor.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * Copyright (c) 2016 MAK Technologies, Inc.
3 * All rights reserved.
4 *****************************************************************************/
5 
6 #pragma once
7 
11 
13 
14 #include <osg/Camera>
15 #include <osg/Texture>
16 #include <osg/Program>
17 #include <osg/Shader>
18 #include <osg/Texture2D>
19 #include <osg/Geode>
20 
21 #include <map>
22 
23 #include <boost/unordered_map.hpp>
24 
25 namespace makVrv
26 {
27  class DtChannel;
28 
29  // When attaching / detaching buffers from the camera
30  // You need to call setCameraRequiresSetUp since there is (and will be)
31  // a bug in OSG's camera caching behavior
32  class DtPostProcessorCullVistorCallback : public osg::NodeCallback
33  {
34  public:
35 
37  {
38  }
39 
40  // Callback method called by the NodeVisitor when visiting a node.
41  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
42 
44  virtual void setDirty(bool flag);
45 
46  protected:
47 
48  bool myDirty;
49  };
50 
51 
62  {
63  public:
64  friend class DtPostProcessManager;
65 
69  DtPostProcessor(const std::string& postProcessType, bool handles2D);
70 
72  virtual ~DtPostProcessor();
73 
79  virtual void setFragmentShaderSource(const char *source);
80 
86  virtual void setVertexShaderSource(const char *source);
87 
93  virtual void setFragmentShaderFile(const std::string& fileName);
94 
100  virtual void setVertexShaderFile(const std::string& fileName);
101 
102 
107  virtual void setInputTexture(const DtChannel *channel, osg::Texture2D* texture);
108 
110  virtual void update(DtChannel *channel) = 0;
111 
115  virtual osg::Texture2D* outputTexture();
116 
120  virtual void setIsFinalEffect(const DtChannel *channel, bool final);
121 
124  virtual osg::Camera* cameraForChannel(const DtChannel *channel);
125 
126  virtual void releaseGLObjects();
127 
129  virtual bool hasEffect(std::string effect);
130 
132  virtual bool effectEnabled(std::string effect);
133 
135  virtual bool anyEffectEnabled();
136 
138 
139 
140 
141  virtual bool enableEffect(std::string effect);
142  virtual bool disableEffect(std::string effect);
144 
146  virtual std::list<std::string> supportedEffects();
147 
150  virtual bool handles2D() const;
151 
153  virtual const std::string& type() const;
154 
156 
157  virtual void enablePostProcessor();
158  virtual void disablePostProcessor();
160 
162  virtual bool postProcessorEnabled() const;
163 
164  protected:
165 
166  // A list of sub-effects that can be enabled/disabled
167  typedef boost::unordered_map<std::string, bool> EffectMap;
168 
169  virtual bool effectItrEnabled(EffectMap::iterator &effect);
170 
171  virtual void initialize();
172 
176  virtual void addEffect(std::string effect);
177 
179  virtual void setEnablePostProcessor(bool enabled);
180 
181  protected:
182 
183  osg::ref_ptr<osg::Texture2D> myOutputTexture, myInputTexture;
184  osg::ref_ptr<osg::Program> myProgram;
185  osg::ref_ptr<osg::Shader> myFragmentShader;
186  osg::ref_ptr<osg::Shader> myVertexShader;
187  osg::ref_ptr<osg::Geode> myQuad;
188 
189  typedef std::map<const DtChannel*, osg::ref_ptr<osg::Camera> > CameraMap;
191 
194 
195  // The category of this post effect ex. "dof", "wateronscreen"
196  std::string myType;
197 
198 
199  EffectMap myEffects; // ex. { {"rainsplash",true}, {"oceanspray",false} }
200 
201  //Needed in order to mark the correct callbacks dirty to avoid
202  // extra calls to set camera requres setup.
203  typedef osg::ref_ptr<DtPostProcessorCullVistorCallback> CallbackRefPtr;
204  typedef std::map< const DtChannel*, CallbackRefPtr > CallbackMap;
205 
207  };
208 
213  {
214  public:
217 
220 
222  virtual ~DtPostProcessorCreator();
223 
224  protected:
226  virtual DtPostProcessor* create(DtDe& de, const std::string& postProcessorType) = 0;
227  };
228 }

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)