Cortex  10.0.0-a4
Primitive.h
1 //
3 // Copyright (c) 2007-2012, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IECOREGL_PRIMITIVE_H
36 #define IECOREGL_PRIMITIVE_H
37 
38 #include "OpenEXR/ImathBox.h"
39 
40 #include "IECore/PrimitiveVariable.h"
41 #include "IECore/VectorTypedData.h"
42 
43 #include "IECoreGL/Export.h"
44 #include "IECoreGL/GL.h"
45 #include "IECoreGL/Renderable.h"
46 #include "IECoreGL/TypedStateComponent.h"
47 #include "IECoreGL/Shader.h"
48 
49 namespace IECoreGL
50 {
51 
52 IE_CORE_FORWARDDECLARE( State );
53 
58 class IECOREGL_API Primitive : public Renderable
59 {
60  public :
61 
62  IE_CORE_DECLARERUNTIMETYPEDEXTENSION( IECoreGL::Primitive, PrimitiveTypeId, Renderable );
63 
64  Primitive();
65  ~Primitive() override;
66 
71  virtual void addPrimitiveVariable( const std::string &name, const IECore::PrimitiveVariable &primVar ) = 0;
72 
74  Imath::Box3f bound() const override = 0;
75 
82  void render( State *currentState ) const override;
83 
116  virtual const Shader::Setup *shaderSetup( const Shader *shader, State *state ) const;
121  void addPrimitiveVariablesToShaderSetup( Shader::Setup *shaderSetup, const std::string &vertexPrefix = "vertex", GLuint vertexDivisor = 0 ) const;
129  virtual void render( const State *currentState, IECore::TypeId style ) const;
133  virtual void renderInstances( size_t numInstances = 1 ) const = 0;
135 
140 
141  typedef TypedStateComponent<bool, PrimitiveBoundTypeId> DrawBound;
142  IE_CORE_DECLAREPTR( DrawBound );
143  typedef TypedStateComponent<bool, PrimitiveWireframeTypeId> DrawWireframe;
144  IE_CORE_DECLAREPTR( DrawWireframe );
145  typedef TypedStateComponent<float, PrimitiveWireframeWidthTypeId> WireframeWidth;
146  IE_CORE_DECLAREPTR( WireframeWidth );
147  typedef TypedStateComponent<bool, PrimitiveSolidTypeId> DrawSolid;
148  IE_CORE_DECLAREPTR( DrawSolid );
149  typedef TypedStateComponent<bool, PrimitiveOutlineTypeId> DrawOutline;
150  IE_CORE_DECLAREPTR( DrawOutline );
151  typedef TypedStateComponent<float, PrimitiveOutlineWidthTypeId> OutlineWidth;
152  IE_CORE_DECLAREPTR( OutlineWidth );
153  typedef TypedStateComponent<bool, PrimitivePointsTypeId> DrawPoints;
154  IE_CORE_DECLAREPTR( DrawPoints );
155  typedef TypedStateComponent<float, PrimitivePointWidthTypeId> PointWidth;
156  IE_CORE_DECLAREPTR( PointWidth );
157  typedef TypedStateComponent<bool, PrimitiveSelectableTypeId> Selectable;
158  IE_CORE_DECLAREPTR( Selectable );
160  typedef TypedStateComponent<bool, PrimitiveTransparencySortStateComponentTypeId> TransparencySort;
161  IE_CORE_DECLAREPTR( TransparencySort );
163 
164  protected :
165 
167  void addUniformAttribute( const std::string &name, IECore::ConstDataPtr data );
169  void addVertexAttribute( const std::string &name, IECore::ConstDataPtr data );
170 
174  bool depthSortRequested( const State *state ) const;
175 
176  private :
177 
178  typedef std::vector<Shader::SetupPtr> ShaderSetupVector;
179  mutable ShaderSetupVector m_shaderSetups;
180 
181  mutable Shader::SetupPtr m_boundSetup;
182  const Shader::Setup *boundSetup() const;
183 
184  typedef std::map<std::string, IECore::ConstDataPtr> AttributeMap;
185  AttributeMap m_vertexAttributes;
186  AttributeMap m_uniformAttributes;
187 
188 };
189 
190 IE_CORE_DECLAREPTR( Primitive );
191 
192 } // namespace IECoreGL
193 
194 #endif // IECOREGL_PRIMITIVE_H
The namespace within which all CoreGL functionality is defined.
Definition: AlphaTexture.h:41
A class to represent GLSL shaders.
Definition: Shader.h:57
Definition: PrimitiveVariable.h:47
TypedStateComponent< bool, PrimitiveTransparencySortStateComponentTypeId > TransparencySort
Used to trigger sorting of the components of a primitive when the TransparentShadingStateComponent ha...
Definition: Primitive.h:160
Definition: Renderable.h:53
Definition: Shader.h:149
TypeId
Definition: TypeIds.h:46
Definition: Primitive.h:58