VVISF & VVGL
ISFAttr.hpp
1 #ifndef ISFAttr_hpp
2 #define ISFAttr_hpp
3 
4 #include "VVISF_Base.hpp"
5 #include <stdint.h>
6 #include <vector>
7 #include <string>
8 
9 
10 
11 
12 namespace VVISF {
13 
14 
15 
16 
17 using namespace std;
18 
19 
20 
21 
26 class VVISF_EXPORT ISFAttr {
27  protected:
28  string _name;
29  string _description;
30  string _label;
31 
33  ISFVal _currentVal = ISFNullVal();
34  ISFVal _minVal = ISFNullVal(); // if it's an audio/audiofft, it's a long-type val. otherwise, null or an ISFVal subclass of the appropriate type
35  ISFVal _maxVal = ISFNullVal(); // if it's an audio/audiofft, it's a long-type val. otherwise, null or an ISFVal subclass of the appropriate type
36  ISFVal _defaultVal = ISFNullVal();
37  ISFVal _identityVal = ISFNullVal();
38  vector<string> _labelArray; // only used if it's a LONG. vector containing strings that correspond to the values in "_valArray"
39  vector<int32_t> _valArray; // only used if it's a LONG. vector containing ints with the values that correspond to the accompanying labels
40 
41  bool _isFilterInputImage = false; // if true, this is an image-type input and is the main input for an image filter
42  bool _isTransStartImage = false; // if true, this is an image-type input and is named "startImage"
43  bool _isTransEndImage = false; // if true, this is an image-type input and is named "endImage"
44  bool _isTransProgressFloat = false; // if true, this is a float-type input and is named "progress"
45  int32_t _uniformLocation[4] = { -1, -1, -1, -1 }; // the location of this attribute in the compiled GLSL program. cached here because lookup times are costly when performed every frame. there are 4 because images require four uniforms (one of the texture name, one for the size, one for the img rect, and one for the flippedness)
46 
47  double _evalVariable = 1.0; // attribute values are available in expression evaluation- to support this, each attribute needs to maintain a double which it populates with its current value
48  public:
49 
50  /*
51  \brief You probably shouldn't be creating attributes directly- instead, you'll likely encounter it as an ISFAttrRef vended by an ISFDoc which may or may not be owned by an ISFScene. Nevertheless, this is the constructor:
52  \param inName The name of the ISF attribute
53  \param inDesc The attribute description
54  \param inLabel The attribute label
55  \param inType The attribute's value type
56  \param inMinVal The attribute's min value, or a null value if there is no min val or a min val would be inappropriate
57  \param inMaxVal The attribute's max value, or a null value if there is no max val or a max val would be inappropriate
58  \param inDefVal The attribute's default value, or a null value if there is no default val or a default val would be inappropriate
59  \param inIdenVal The attribute's identity value, or a null value if there is no identity val or an identity val would be inappropriate
60  \param inLabels A ptr to a vector containing strings with the attribute's labels, or null if the labels are inappropriate or absent. The receiver does not assume ownership of the passed ptr.
61  \param inVals A ptr to a vector containing ints with the attribute's values (presuming long-type attribute), or null if the values are inappropriate or absent. The receiver does not assume ownership of the passed ptr.
62  */
63  ISFAttr(const string & inName,
64  const string & inDesc,
65  const string & inLabel,
66  const ISFValType & inType,
67  const ISFVal & inMinVal=ISFNullVal(),
68  const ISFVal & inMaxVal=ISFNullVal(),
69  const ISFVal & inDefVal=ISFNullVal(),
70  const ISFVal & inIdenVal=ISFNullVal(),
71  const vector<string> * inLabels=nullptr,
72  const vector<int32_t> * inVals=nullptr);
73  ~ISFAttr();
74 
76  inline string & name() const { return const_cast<string&>(_name); }
78  inline string & description() const { return const_cast<string&>(_description); }
80  inline string & label() const { return const_cast<string&>(_label); }
82  inline ISFValType & type() const { return const_cast<ISFValType&>(_type); }
84  inline ISFVal & currentVal() { return _currentVal; }
86  inline void setCurrentVal(const ISFVal & n) { _currentVal=n; }
87  // updates this attribute's eval variable with the double val of "_currentVal", and returns a ptr to the eval variable
88  double * updateAndGetEvalVariable();
90  inline bool shouldHaveImageBuffer() const { return ISFValTypeUsesImage(_type); }
92  inline VVGL::GLBufferRef getCurrentImageBuffer() { if (!shouldHaveImageBuffer()) return nullptr; return _currentVal.imageBuffer(); }
94  inline void setCurrentImageBuffer(const VVGL::GLBufferRef & n) { /*cout<<__PRETTY_FUNCTION__<<"..."<<*this<<", "<<*n<<endl;*/if (shouldHaveImageBuffer()) _currentVal = ISFImageVal(n); else cout << "\terr: tried to set current image buffer in non-image attr (" << _name << ")\n"; /*cout<<"\tcurrentVal is now "<<_currentVal<<endl;*/ }
96  inline ISFVal & minVal() { return _minVal; }
98  inline ISFVal & maxVal() { return _maxVal; }
100  inline ISFVal & defaultVal() { return _defaultVal; }
102  inline ISFVal & identityVal() { return _identityVal; }
104  inline vector<string> & labelArray() { return _labelArray; }
106  inline vector<int32_t> & valArray() { return _valArray; }
108  inline bool isFilterInputImage() { return _isFilterInputImage; }
109  inline void setIsFilterInputImage(const bool & n) { _isFilterInputImage=n; }
111  inline bool isTransStartImage() { return _isTransStartImage; }
112  inline void setIsTransStartImage(const bool & n) { _isTransStartImage=n; }
114  inline bool isTransEndImage() { return _isTransEndImage; }
115  inline void setIsTransEndImage(const bool & n) { _isTransEndImage=n; }
117  inline bool isTransProgressFloat() { return _isTransProgressFloat; }
118  inline void setIsTransProgressFloat(const bool & n) { _isTransProgressFloat=n; }
119 
120  inline void clearUniformLocations() { for (int i=0; i<4; ++i) _uniformLocation[i]=0; }
121  inline void setUniformLocation(const int & inIndex, const int32_t & inNewVal) { if (inIndex<0 || inIndex>3) return; _uniformLocation[inIndex] = inNewVal; }
122  inline int32_t getUniformLocation(const int & inIndex) { if (inIndex<0 || inIndex>3) return 0; return _uniformLocation[inIndex]; }
123  //inline bool isNullVal() { return (_type==ISFValType_None); }
124 
125  VVISF_EXPORT friend ostream & operator<<(ostream & os, const ISFAttr & n);
126  void lengthyDescription();
128  string getAttrDescription();
129 };
130 
131 
132 
133 
134 }
135 
136 
137 
138 
139 #endif /* ISFAttr_hpp */
void setCurrentVal(const ISFVal &n)
Sets the attribute&#39;s current value.
Definition: ISFAttr.hpp:86
void setCurrentImageBuffer(const VVGL::GLBufferRef &n)
Sets the receiver&#39;s current value with the passed image buffer.
Definition: ISFAttr.hpp:94
bool isTransEndImage()
Returns a true if this attribute is used to send the end image to the transition. ...
Definition: ISFAttr.hpp:114
bool shouldHaveImageBuffer() const
Returns a true if this attribute&#39;s value is expressed with an image buffer.
Definition: ISFAttr.hpp:90
ISFVal & minVal()
Gets the attribute&#39;s min val.
Definition: ISFAttr.hpp:96
bool isTransProgressFloat()
Returns a true if this attribute is used to send the progress value to the transition.
Definition: ISFAttr.hpp:117
ISFVal & maxVal()
Gets the attribute&#39;s max val.
Definition: ISFAttr.hpp:98
bool isTransStartImage()
Returns a true if this attribute is used to send the start image to the transition.
Definition: ISFAttr.hpp:111
vector< int32_t > & valArray()
Gets the attribute&#39;s values as a vector of int values. Only used if the attribute is a &#39;long&#39;...
Definition: ISFAttr.hpp:106
STL namespace.
Definition: ISFAttr.hpp:12
VVGL::GLBufferRef getCurrentImageBuffer()
Returns the receiver&#39;s image buffer.
Definition: ISFAttr.hpp:92
vector< string > & labelArray()
Gets the attribute&#39;s labels as a vector of string values. Only used if the attribute is a &#39;long&#39;...
Definition: ISFAttr.hpp:104
VVISF_EXPORT ISFVal ISFImageVal(const VVGL::GLBufferRef &n)
Creates and returns an image-type ISFVal with the passed buffer.
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
Describes a single ISF attribute.
Definition: ISFAttr.hpp:26
bool isFilterInputImage()
Returns a true if this attribute is used to send the input image to the filter.
Definition: ISFAttr.hpp:108
string & description() const
Returns the attribute&#39;s description, or null.
Definition: ISFAttr.hpp:78
No data/unknown value type.
Definition: ISFVal.hpp:26
ISFValType & type() const
Returns the attribute&#39;s value type.
Definition: ISFAttr.hpp:82
ISFVal & identityVal()
Gets the attribute&#39;s identity val (the value at which this attribute&#39;s effects are indistinguishable ...
Definition: ISFAttr.hpp:102
string & label() const
Returns the attribute&#39;s label, or null.
Definition: ISFAttr.hpp:80
VVGL::GLBufferRef imageBuffer() const
Returns null if the receiver&#39;s value type cannot be represented as an image, otherwise it returns the...
bool ISFValTypeUsesImage(const ISFValType &n)
Returns a true if the passed value type uses an image for its value.
Definition: ISFVal.hpp:49
string & name() const
Returns the attribute&#39;s name, or null.
Definition: ISFAttr.hpp:76
ISFVal & currentVal()
Returns the attribute&#39;s current value.
Definition: ISFAttr.hpp:84
ISFVal & defaultVal()
Gets the attribute&#39;s default val (the value which will be assigned to the attribute when it is first ...
Definition: ISFAttr.hpp:100
VVISF_EXPORT ISFVal ISFNullVal()
Creates and returns a null-type ISFVal.