VVISF & VVGL
ISFScene.hpp
1 #ifndef ISFScene_hpp
2 #define ISFScene_hpp
3 
4 #include "VVISF_Base.hpp"
5 #if defined(VVGL_SDK_MAC)
6 #import <TargetConditionals.h>
7 #endif
8 
9 
10 
11 
12 namespace VVISF
13 {
14 
15 
16 using namespace std;
17 
18 
19 
20 
22 
28 class VVISF_EXPORT ISFScene : public VVGL::GLScene {
29  private:
30  bool _throwExceptions = false; // NO by default
31 
32  mutex _propertyLock; // locks the below two vars
33  //bool loadingInProgress = false;
34  ISFDocRef _doc = nullptr; // the ISFDoc being used
35 
36  // access to these vars should be restricted by the '_renderLock' var inherited from GLScene
37  VVGL::Size _renderSize = _orthoSize; // the last size at which i was requested to render a buffer (used to produce vals from normalized point inputs that need a render size to be used)
38  VVGL::Timestamp _baseTime; // used to generate time values, some of which get passed to the ISF scene
39  uint32_t _renderFrameIndex = 0; // used to pass FRAMEINDEX to shaders
40  double _renderTime = 0.; // this is the render time that gets passed to the ISF
41  double _renderTimeDelta = 0.; // this is the render time delta (frame duration) which gets passed to the ISF
42  uint32_t _passIndex = 1; // used to store the index of the rendered pass, which gets passed to the shader
43  string *_compiledInputTypeString = nullptr; // a sequence of characters, either "2" or "R" or "C", one character for each input image. describes whether the shader was compiled to work with 2D textures or RECT textures or cube textures.
44 
45  // access to these vars should be restricted by the '_renderLock' var inherited from GLScene
46  VVGL::GLCachedAttrib _vertexAttrib = VVGL::GLCachedAttrib("VERTEXDATA"); // caches the location of the attribute in the compiled GL program for the vertex input
47  VVGL::GLCachedUni _renderSizeUni = VVGL::GLCachedUni("RENDERSIZE"); // caches the location of the uniform in the compiled GL program for the render size
48  VVGL::GLCachedUni _passIndexUni = VVGL::GLCachedUni("PASSINDEX"); // caches the location of the uniform in the compiled GL program for the pass index
49  VVGL::GLCachedUni _timeUni = VVGL::GLCachedUni("TIME"); // caches the location of the uniform in the compiled GL program for the time
50  VVGL::GLCachedUni _timeDeltaUni = VVGL::GLCachedUni("TIMEDELTA"); // caches the location of the uniform in the compiled GL program for the time delta
51  VVGL::GLCachedUni _dateUni = VVGL::GLCachedUni("DATE"); // caches the location of the uniform in the compiled GL program for the date
52  VVGL::GLCachedUni _renderFrameIndexUni = VVGL::GLCachedUni("FRAMEINDEX"); // caches the location of the uniform in the compiled GL program for the frame index
53 
54  // access to these vars should be restricted by the '_renderLock' var inherited from GLScene
55  //VVGL::GLBufferRef geoXYVBO = nullptr;
56 #if !defined(VVGL_TARGETENV_GLES)
57  VVGL::GLBufferRef _vao = nullptr;
58 #endif
59  VVGL::GLBufferRef _vbo = nullptr;
60  VVGL::Quad<VVGL::VertXY> _vboContents; // the VBO owned by VAO is described by this var- we check this, and if there's a delta then we have to upload new data to the VBO
61 
62  // these vars describe some non-default/non-standard options for more unusual situations
63  bool _alwaysRenderToFloat = false; // false by default- if true, all interim buffers generated by the ISF will be float32 per component. set this before loading the doc.
64  bool _persistentToIOSurface = false; // false by default- if true, persistent buffers generated by the ISF will be backed by IOSurfaces (so they can be re-used if the underlying GL context changes to one in a different sharegroup). set this before loading the doc.
65 
66  public:
68  ISFScene();
70  ISFScene(const VVGL::GLContextRef & inCtx);
71  virtual ~ISFScene();
72 
73  virtual void prepareToBeDeleted();
74 
75 
79 
82  void useFile() noexcept(false);
84  void useFile(const string & inPath) noexcept(false);
86  void useDoc(ISFDocRef & inDoc);
88  inline ISFDocRef doc() { lock_guard<mutex> lock(_propertyLock); return _doc; }
89 
91 
92 
96 
99  void setAlwaysRenderToFloat(const bool & n) { _alwaysRenderToFloat=n; }
101  bool alwaysRenderToFloat() { return _alwaysRenderToFloat; }
103  void setPersistentToIOSurface(const bool & n) { _persistentToIOSurface=n; }
105  bool persistentToIOSurface() { return _persistentToIOSurface; }
106 
108 
109 
113 
116  void setBufferForInputNamed(const VVGL::GLBufferRef & inBuffer, const string & inName);
118  void setFilterInputBuffer(const VVGL::GLBufferRef & inBuffer);
120  void setBufferForInputImageKey(const VVGL::GLBufferRef & inBuffer, const string & inString);
122  void setBufferForAudioInputKey(const VVGL::GLBufferRef & inBuffer, const string & inString);
124  VVGL::GLBufferRef getBufferForImageInput(const string & inKey);
126  VVGL::GLBufferRef getBufferForAudioInput(const string & inKey);
128  VVGL::GLBufferRef getPersistentBufferNamed(const string & inKey);
130  VVGL::GLBufferRef getTempBufferNamed(const string & inKey);
131 
133  void setValueForInputNamed(const ISFVal & inVal, const string & inName);
135  ISFVal valueForInputNamed(const string & inName);
136 
138 
139 
143 #pragma clang diagnostic push
145 #pragma clang diagnostic ignored "-Woverloaded-virtual"
146  //virtual GLBufferRef createAndRenderABuffer(const VVGL::Size & inSize=VVGL::Size(640.,480.), const GLBufferPoolRef & inPool=nullptr);
153  virtual VVGL::GLBufferRef createAndRenderABuffer(const VVGL::Size & inSize=VVGL::Size(640.,480.), map<int32_t,VVGL::GLBufferRef> * outPassDict=nullptr, const VVGL::GLBufferPoolRef & inPoolRef=nullptr);
154  //virtual VVGL::GLBufferRef createAndRenderABuffer(const VVGL::Size & inSize, const double & inRenderTime, const VVGL::GLBufferPoolRef & inPoolRef=nullptr);
162  virtual VVGL::GLBufferRef createAndRenderABuffer(const VVGL::Size & inSize, const double & inRenderTime, map<int32_t,VVGL::GLBufferRef> * outPassDict=nullptr, const VVGL::GLBufferPoolRef & inPoolRef=nullptr);
163 #pragma clang diagnostic pop
164 
166 
167  void renderToBuffer(const VVGL::GLBufferRef & inTargetBuffer, const VVGL::Size & inRenderSize, const double & inRenderTime, map<int32_t,VVGL::GLBufferRef> * outPassDict);
168  void renderToBuffer(const VVGL::GLBufferRef & inTargetBuffer, const VVGL::Size & inRenderSize, const double & inRenderTime);
169  void renderToBuffer(const VVGL::GLBufferRef & inTargetBuffer, const VVGL::Size & inRenderSize, map<int32_t,VVGL::GLBufferRef> * outPassDict);
170  void renderToBuffer(const VVGL::GLBufferRef & inTargetBuffer, const VVGL::Size & inRenderSize);
171  void renderToBuffer(const VVGL::GLBufferRef & inTargetBuffer);
172 
173  virtual void setSize(const VVGL::Size & n);
174  VVGL::Size size() const { return _orthoSize; }
175  VVGL::Size renderSize() const { return _renderSize; }
177  inline VVGL::Timestamp getTimestamp() { return VVGL::Timestamp()-_baseTime; }
179  inline void setThrowExceptions(const bool & n) { _throwExceptions=n; }
180 
181  //virtual void renderToBuffer(const VVGL::GLBufferRef & inTargetBuffer, const VVGL::Size & inRenderSize=VVGL::Size(640.,480.), const double & inRenderTime=timestamper.nowTime().getTimeInSeconds(), map<string,VVGL::GLBufferRef> * outPassDict=nullptr);
182 
183 
187 
190  ISFAttrRef inputNamed(const string & inName);
192  vector<ISFAttrRef> inputs();
194  vector<ISFAttrRef> inputsOfType(const ISFValType & inType);
196  vector<ISFAttrRef> imageInputs();
198  vector<ISFAttrRef> audioInputs();
200  vector<ISFAttrRef> imageImports();
201 
203 
204 
206  virtual void setVertexShaderString(const string & n);
208  virtual void setFragmentShaderString(const string & n);
209 
210  protected:
211 #if !defined(VVGL_TARGETENV_GLES)
212  inline VVGL::GLBufferRef vao() const { return _vao; }
213  inline void setVAO(const VVGL::GLBufferRef & n) { _vao = n; }
214 #endif
215  inline VVGL::GLBufferRef vbo() const { return _vbo; }
216  inline void setVBO(const VVGL::GLBufferRef & n) { _vbo = n; }
217  void _setUpRenderCallback();
218  virtual void _renderPrep();
219  virtual void _initialize();
220  virtual void _renderCleanup();
221  virtual void _render(const VVGL::GLBufferRef & inTargetBuffer, const VVGL::Size & inSize, const double & inTime, map<int32_t,VVGL::GLBufferRef> * outPassDict);
222 
223 };
224 
225 
226 
227 
232 inline ISFSceneRef CreateISFSceneRef() { return make_shared<ISFScene>(); }
237 inline ISFSceneRef CreateISFSceneRefUsing(const VVGL::GLContextRef & inCtx) { return make_shared<ISFScene>(inCtx); }
238 
239 
240 
241 
242 }
243 
244 
245 
246 
247 #endif /* ISFScene_hpp */
Subclass of GLScene- the primary interface for rendering and interacting with an ISF file...
Definition: ISFScene.hpp:28
ISFSceneRef CreateISFSceneRefUsing(const VVGL::GLContextRef &inCtx)
Creates and returns an ISFScene. The scene uses the passed GL context to do its drawing.
Definition: ISFScene.hpp:237
void setAlwaysRenderToFloat(const bool &n)
Sets the receiver&#39;s _alwaysRenderToFloat flag- if true, all frames will be rendered using high-bit-de...
Definition: ISFScene.hpp:99
Subclass of GLCachedProperty that caches the location of a uniform variable in a GLSL program...
Definition: GLCachedProperty.hpp:89
STL namespace.
Definition: ISFAttr.hpp:12
Basic struct for 2D size.
Definition: VVGL_Geom.hpp:46
Subclass of GLCachedProperty that caches the location of an attribute in a GLSL program.
Definition: GLCachedProperty.hpp:66
bool alwaysRenderToFloat()
Gets the receiver&#39;s _alwaysRenderToFloat flag.
Definition: ISFScene.hpp:101
Manages drawing in a GLContext, provides a simple interface for orthographic rendering, render-to-texture operations, and loading vert/geo/frag shaders.
Definition: GLScene.hpp:33
ISFVal describes an ISF value- it has a type (ISFValType) and a type-dependent value. Intended to be immutable.
Definition: ISFVal.hpp:57
ISFValType
Enumerates the different kinds of ISF values.
Definition: ISFVal.hpp:25
std::shared_ptr< ISFScene > ISFSceneRef
ISFSceneRef is a shared pointer around an ISFScene instance.
Definition: VVISF_Base.hpp:62
ISFSceneRef CreateISFSceneRef()
Creates and returns an ISFScene. The scene makes a new GL context which shares the context of the glo...
Definition: ISFScene.hpp:232
VVGL::Timestamp getTimestamp()
Creates a a new Timestamp relative to the scene&#39;s built-in _baseTime instance. This is how the render...
Definition: ISFScene.hpp:177
void setPersistentToIOSurface(const bool &n)
Sets the receiver&#39;s _persistentToIOSurface flag- if true, all passes that are flagged as persistent w...
Definition: ISFScene.hpp:103
ISFDocRef doc()
Returns the ISFDoc currently being used by the scene. Interacting with this doc by setting the value ...
Definition: ISFScene.hpp:88
bool persistentToIOSurface()
Gets the receiver&#39;s _persistentToIOSurface flag.
Definition: ISFScene.hpp:105
void setThrowExceptions(const bool &n)
Sets the "throwExceptions" member var, which is false by default. If true, the ISFScene will throw an...
Definition: ISFScene.hpp:179