Cortex  10.0.0-a4
Shader.h
1 //
3 // Copyright (c) 2007-2013, Image Engine Design Inc. All rights reserved.
4 //
5 // Copyright 2010 Dr D Studios Pty Limited (ACN 127 184 954) (Dr. D Studios),
6 // its affiliates and/or its licensors.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // * Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
18 //
19 // * Neither the name of Image Engine Design nor the names of any
20 // other contributors to this software may be used to endorse or
21 // promote products derived from this software without specific prior
22 // written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
37 
38 #ifndef IECOREGL_SHADER_H
39 #define IECOREGL_SHADER_H
40 
41 #include <boost/utility.hpp>
42 
43 #include "IECoreGL/Export.h"
44 #include "IECoreGL/GL.h"
45 #include "IECoreGL/Bindable.h"
46 #include "IECoreGL/TypeIds.h"
47 
48 #include "IECore/CompoundData.h"
49 
50 namespace IECoreGL
51 {
52 
53 IE_CORE_FORWARDDECLARE( Shader );
54 IE_CORE_FORWARDDECLARE( Texture );
55 
57 class IECOREGL_API Shader : public IECore::RunTimeTyped
58 {
59 
60  public :
61 
62  IE_CORE_DECLARERUNTIMETYPEDEXTENSION( IECoreGL::Shader, ShaderTypeId, IECore::RunTimeTyped );
63 
67  Shader( const std::string &vertexSource, const std::string &fragmentSource );
71  Shader( const std::string &vertexSource, const std::string &geometrySource, const std::string &fragmentSource );
72  ~Shader() override;
73 
76  GLuint program() const;
77 
84 
85  const std::string &vertexSource() const;
86  const std::string &geometrySource() const;
87  const std::string &fragmentSource() const;
89 
90  struct IECOREGL_API Parameter
91  {
92 
95  GLenum type;
98  GLint size;
101  GLint location;
106  GLuint textureUnit;
107 
108  bool operator == ( const Parameter &other ) const;
109 
110  };
111 
116  void uniformParameterNames( std::vector<std::string> &names ) const;
120  const Parameter *uniformParameter( const std::string &name ) const;
121 
123  void vertexAttributeNames( std::vector<std::string> &names ) const;
127  const Parameter *vertexAttribute( const std::string &name ) const;
128 
137 
138  const Parameter *csParameter() const;
142 
149  class IECOREGL_API Setup : public IECore::RefCounted
150  {
151 
152  public :
153 
154  IE_CORE_DECLAREMEMBERPTR( Setup )
155 
156  Setup( ConstShaderPtr shader );
157  ~Setup() override;
158 
159  const Shader *shader() const;
160 
161  void addUniformParameter( const std::string &name, ConstTexturePtr value );
162  void addUniformParameter( const std::string &name, IECore::ConstDataPtr value );
165  void addVertexAttribute( const std::string &name, IECore::ConstDataPtr value, GLuint divisor = 0 );
166 
168  bool hasCsValue() const;
169 
173  class IECOREGL_API ScopedBinding
174  {
175 
176  public :
177 
183  ScopedBinding( const Setup &setup );
185  ~ScopedBinding();
186 
187  private :
188 
189  GLint m_previousProgram;
190  const Setup &m_setup;
191 
192  };
193 
194  private :
195 
196  IE_CORE_FORWARDDECLARE( MemberData );
197 
198  MemberDataPtr m_memberData;
199 
200  };
201 
202  IE_CORE_DECLAREPTR( Setup );
203 
208 
209  static const std::string &defaultVertexSource();
217  static const std::string &defaultGeometrySource();
220  static const std::string &defaultFragmentSource();
222  static const std::string &constantFragmentSource();
224  static const std::string &lambertFragmentSource();
226 
231 
232  static Shader *constant();
235  static Shader *facingRatio();
237 
238  private :
239 
240  IE_CORE_FORWARDDECLARE( Implementation )
241  ImplementationPtr m_implementation;
242 
243 };
244 
245 } // namespace IECoreGL
246 
247 #endif // IECOREGL_SHADER_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: Shader.h:149
Definition: RefCounted.h:124
Definition: RunTimeTyped.h:211