Cortex  10.0.0-a4
TypedStateComponent.h
1 //
3 // Copyright (c) 2007-2013, Image Engine Design Inc. All rights reserved.
4 // Copyright (c) 2011, John Haddon. All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 //
17 // * Neither the name of Image Engine Design nor the names of any
18 // other contributors to this software may be used to endorse or
19 // promote products derived from this software without specific prior
20 // written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
35 
36 #ifndef IECOREGL_TYPEDSTATECOMPONENT_H
37 #define IECOREGL_TYPEDSTATECOMPONENT_H
38 
39 #include "IECoreGL/Export.h"
40 #include "IECoreGL/StateComponent.h"
41 
42 #include "OpenEXR/ImathColor.h"
43 #include "OpenEXR/ImathBox.h"
44 
45 namespace IECoreGL
46 {
47 
48 template<typename T, unsigned int TId>
49 class TypedStateComponent : public StateComponent
50 {
51  public :
52 
53  typedef T ValueType;
54 
55  typedef boost::intrusive_ptr<TypedStateComponent> Ptr;
56  typedef boost::intrusive_ptr<const TypedStateComponent> ConstPtr;
57 
58  TypedStateComponent();
59  TypedStateComponent( const T &value );
60 
63 
64  IECore::TypeId typeId() const override;
65  const char *typeName() const override;
66  bool isInstanceOf( IECore::TypeId typeId ) const override;
67  bool isInstanceOf( const char *typeName ) const override;
68  static IECore::TypeId staticTypeId();
69  static const char *staticTypeName();
70  static bool inheritsFrom( IECore::TypeId typeId );
71  static bool inheritsFrom( const char *typeName );
72  static IECore::TypeId baseTypeId();
73  static const char *baseTypeName();
74  typedef StateComponent BaseClass;
76 
79 
80  void bind() const override;
82 
83  const T &value() const;
84 
85  static T defaultValue();
86 
87  private :
88 
89  T m_value;
90 
91  static Description<TypedStateComponent<T, TId> > g_description;
92 
93 };
94 
96 #define IECOREGL_TYPEDSTATECOMPONENT_SPECIALISE( TYPE, BASETYPE, DEFAULTVALUE ) \
97  template<> \
98  IECOREGL_API const char *TYPE::typeName() const \
99  { \
100  return # TYPE; \
101  } \
102  \
103  template<> \
104  IECOREGL_API const char *TYPE::staticTypeName() \
105  { \
106  return # TYPE; \
107  } \
108  \
109  template<> \
110  IECOREGL_API BASETYPE TYPE::defaultValue() \
111  { \
112  return DEFAULTVALUE; \
113  }
114 
115 #define IECOREGL_TYPEDSTATECOMPONENT_SPECIALISEANDINSTANTIATE( TYPE, TYPEID, BASETYPE, DEFAULTVALUE ) \
116  IECOREGL_TYPEDSTATECOMPONENT_SPECIALISE( TYPE, BASETYPE, DEFAULTVALUE ) \
117  template IECOREGL_API class TypedStateComponent<BASETYPE, TYPEID>; \
118 
119 typedef TypedStateComponent<Imath::Color4f, ColorTypeId> Color;
120 template<>
121 IECOREGL_API void Color::bind() const;
122 
128 typedef TypedStateComponent<bool, TransparentShadingStateComponentTypeId> TransparentShadingStateComponent;
130 typedef TypedStateComponent<Imath::Color4f, BoundColorStateComponentTypeId> BoundColorStateComponent;
132 typedef TypedStateComponent<Imath::Color4f, WireframeColorStateComponentTypeId> WireframeColorStateComponent;
134 typedef TypedStateComponent<Imath::Color4f, OutlineColorStateComponentTypeId> OutlineColorStateComponent;
136 typedef TypedStateComponent<Imath::Color4f, PointColorStateComponentTypeId> PointColorStateComponent;
137 
138 enum GLPointsUsage
139 {
140  ForPointsOnly,
141  ForPointsAndDisks,
142  ForAll
143 };
144 
145 struct IECOREGL_API BlendFactors
146 {
147  BlendFactors( GLenum src, GLenum dst );
148  BlendFactors( const BlendFactors &other );
149  GLenum src;
150  GLenum dst;
151 };
152 
153 struct IECOREGL_API AlphaFunc
154 {
155  AlphaFunc( GLenum m, GLfloat value );
156  AlphaFunc( const AlphaFunc &other );
157  GLenum mode;
158  GLfloat value;
159 };
160 
161 typedef TypedStateComponent<BlendFactors, BlendFuncStateComponentTypeId> BlendFuncStateComponent;
162 template<>
163 IECOREGL_API void BlendFuncStateComponent::bind() const;
164 
165 typedef TypedStateComponent<Imath::Color4f, BlendColorStateComponentTypeId> BlendColorStateComponent;
166 template<>
167 IECOREGL_API void BlendColorStateComponent::bind() const;
168 
169 typedef TypedStateComponent<GLenum, BlendEquationStateComponentTypeId> BlendEquationStateComponent;
170 template<>
171 IECOREGL_API void BlendEquationStateComponent::bind() const;
172 
173 typedef TypedStateComponent<bool, AlphaTestStateComponentTypeId> AlphaTestStateComponent;
174 template<>
175 IECOREGL_API void AlphaTestStateComponent::bind() const;
176 
177 typedef TypedStateComponent<AlphaFunc, AlphaFuncStateComponentTypeId> AlphaFuncStateComponent;
178 template<>
179 IECOREGL_API void AlphaFuncStateComponent::bind() const;
180 
182 typedef TypedStateComponent<bool, DoubleSidedStateComponentTypeId> DoubleSidedStateComponent;
183 template<>
184 IECOREGL_API void DoubleSidedStateComponent::bind() const;
185 
188 typedef TypedStateComponent<bool, RightHandedOrientationStateComponentTypeId> RightHandedOrientationStateComponent;
189 template<>
190 IECOREGL_API void RightHandedOrientationStateComponent::bind() const;
191 
193 typedef TypedStateComponent<bool, LineSmoothingStateComponentTypeId> LineSmoothingStateComponent;
194 template<>
195 IECOREGL_API void LineSmoothingStateComponent::bind() const;
196 
198 typedef TypedStateComponent<bool, PointSmoothingStateComponentTypeId> PointSmoothingStateComponent;
199 template<>
200 IECOREGL_API void PointSmoothingStateComponent::bind() const;
201 
203 typedef TypedStateComponent<bool, PolygonSmoothingStateComponentTypeId> PolygonSmoothingStateComponent;
204 template<>
205 IECOREGL_API void PolygonSmoothingStateComponent::bind() const;
206 
208 typedef TypedStateComponent<bool, DepthTestStateComponentTypeId> DepthTestStateComponent;
209 template<>
210 IECOREGL_API void DepthTestStateComponent::bind() const;
211 
213 typedef TypedStateComponent<bool, DepthMaskStateComponentTypeId> DepthMaskStateComponent;
214 template<>
215 IECOREGL_API void DepthMaskStateComponent::bind() const;
216 
217 // \todo: implement CurrentSpace, ShaderSpace, CameraSpace, ScreenSpace, RasterSpace and NDCSpace like in Renderman interface.
218 enum RendererSpace
219 {
220  ObjectSpace,
221  WorldSpace
222 };
223 // Used to specify which space the culling bounding box is defined. Culling is applied to primitives and procedurals.
224 typedef TypedStateComponent<RendererSpace, CullingSpaceStateComponentTypeId> CullingSpaceStateComponent;
225 
226 // Defines the bounding box for culling. The space it is defined on is given by CullingSpaceStateComponent.
227 typedef TypedStateComponent<Imath::Box3f, CullingBoxStateComponentTypeId> CullingBoxStateComponent;
228 
230 typedef TypedStateComponent<bool, ProceduralThreadingStateComponentTypeId> ProceduralThreadingStateComponent;
231 
233 typedef TypedStateComponent<bool, CameraVisibilityStateComponentTypeId> CameraVisibilityStateComponent;
234 
237 typedef TypedStateComponent<bool, AutomaticInstancingStateComponentTypeId> AutomaticInstancingStateComponent;
238 
239 IE_CORE_DECLAREPTR( Color );
240 IE_CORE_DECLAREPTR( BlendColorStateComponent );
241 IE_CORE_DECLAREPTR( BlendFuncStateComponent );
242 IE_CORE_DECLAREPTR( BlendEquationStateComponent );
243 IE_CORE_DECLAREPTR( BoundColorStateComponent );
244 IE_CORE_DECLAREPTR( WireframeColorStateComponent );
245 IE_CORE_DECLAREPTR( OutlineColorStateComponent );
246 IE_CORE_DECLAREPTR( PointColorStateComponent );
247 IE_CORE_DECLAREPTR( DoubleSidedStateComponent );
248 IE_CORE_DECLAREPTR( LineSmoothingStateComponent );
249 IE_CORE_DECLAREPTR( PointSmoothingStateComponent );
250 IE_CORE_DECLAREPTR( DepthTestStateComponent );
251 IE_CORE_DECLAREPTR( DepthMaskStateComponent );
252 IE_CORE_DECLAREPTR( CullingSpaceStateComponent );
253 IE_CORE_DECLAREPTR( CullingBoxStateComponent );
254 IE_CORE_DECLAREPTR( ProceduralThreadingStateComponent );
255 IE_CORE_DECLAREPTR( CameraVisibilityStateComponent );
256 IE_CORE_DECLAREPTR( AutomaticInstancingStateComponent );
257 
258 } // namespace IECoreGL
259 
260 #include "IECoreGL/TypedStateComponent.inl"
261 
262 #endif // IECOREGL_TYPEDSTATECOMPONENT_H
TypedStateComponent< Imath::Color4f, PointColorStateComponentTypeId > PointColorStateComponent
Specifies the color to draw points in.
Definition: TypedStateComponent.h:136
TypedStateComponent< bool, DepthMaskStateComponentTypeId > DepthMaskStateComponent
Used to set glDepthMask to GL_TRUE or GL_FALSE.
Definition: TypedStateComponent.h:213
TypedStateComponent< Imath::Color4f, WireframeColorStateComponentTypeId > WireframeColorStateComponent
Specifies the color to draw wireframes in.
Definition: TypedStateComponent.h:132
TypedStateComponent< bool, ProceduralThreadingStateComponentTypeId > ProceduralThreadingStateComponent
Defines whether or not procedurals will be executed in parallel threads.
Definition: TypedStateComponent.h:230
The namespace within which all CoreGL functionality is defined.
Definition: AlphaTexture.h:41
TypedStateComponent< Imath::Color4f, BoundColorStateComponentTypeId > BoundColorStateComponent
Specifies the color to draw bounding boxes in.
Definition: TypedStateComponent.h:130
TypedStateComponent< bool, AutomaticInstancingStateComponentTypeId > AutomaticInstancingStateComponent
Definition: TypedStateComponent.h:237
TypedStateComponent< bool, PolygonSmoothingStateComponentTypeId > PolygonSmoothingStateComponent
Used to specify enable state of GL_POLYGON_SMOOTH.
Definition: TypedStateComponent.h:203
static TypeId baseTypeId(TypeId typeId)
Returns the base type of the given type, or InvalidTypeId if no such base exists. ...
TypedStateComponent< bool, CameraVisibilityStateComponentTypeId > CameraVisibilityStateComponent
Defines camera visibility.
Definition: TypedStateComponent.h:233
TypeId
Definition: TypeIds.h:46
TypedStateComponent< bool, TransparentShadingStateComponentTypeId > TransparentShadingStateComponent
Definition: TypedStateComponent.h:128
TypedStateComponent< Imath::Color4f, OutlineColorStateComponentTypeId > OutlineColorStateComponent
Specifies the color to draw outlines in.
Definition: TypedStateComponent.h:134
TypedStateComponent< bool, PointSmoothingStateComponentTypeId > PointSmoothingStateComponent
Used to specify enable state of GL_POINT_SMOOTH.
Definition: TypedStateComponent.h:198
TypedStateComponent< bool, DepthTestStateComponentTypeId > DepthTestStateComponent
Used to specify enable state of GL_DEPTH_TEST.
Definition: TypedStateComponent.h:208
TypedStateComponent< bool, RightHandedOrientationStateComponentTypeId > RightHandedOrientationStateComponent
Definition: TypedStateComponent.h:188
TypedStateComponent< bool, DoubleSidedStateComponentTypeId > DoubleSidedStateComponent
Used to specify enable state of GL_CULL_FACE.
Definition: TypedStateComponent.h:182
static bool inheritsFrom(TypeId type, TypeId baseType)
Returns true if type inherits from baseType.
TypedStateComponent< bool, LineSmoothingStateComponentTypeId > LineSmoothingStateComponent
Used to specify enable state of GL_LINE_SMOOTH.
Definition: TypedStateComponent.h:193