OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreGLSLShader.h
Go to the documentation of this file.
1 /*
2  -----------------------------------------------------------------------------
3  This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5  For the latest info, see http://www.ogre3d.org/
6 
7  Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9  Permission is hereby granted, free of charge, to any person obtaining a copy
10  of this software and associated documentation files (the "Software"), to deal
11  in the Software without restriction, including without limitation the rights
12  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  copies of the Software, and to permit persons to whom the Software is
14  furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  THE SOFTWARE.
26  -----------------------------------------------------------------------------
27 */
28 #ifndef __GLSLShader_H__
29 #define __GLSLShader_H__
30 
33 #include "OgreRenderOperation.h"
34 
35 namespace Ogre {
62  {
63  public:
65  class CmdAttach : public ParamCommand
66  {
67  public:
68  String doGet(const void* target) const;
69  void doSet(void* target, const String& shaderNames);
70  };
71 
74  {
75  public:
76  String doGet(const void* target) const;
77  void doSet(void* target, const String& val);
78  };
81  {
82  public:
83  String doGet(const void* target) const;
84  void doSet(void* target, const String& val);
85  };
88  {
89  public:
90  String doGet(const void* target) const;
91  void doSet(void* target, const String& val);
92  };
95  {
96  public:
97  String doGet(const void* target) const;
98  void doSet(void* target, const String& val);
99  };
102  {
103  public:
104  String doGet(const void* target) const;
105  void doSet(void* target, const String& val);
106  };
111  { return mInputOperationType; }
115  { return mOutputOperationType; }
119  virtual int getMaxOutputVertices(void) const { return mMaxOutputVertices; }
120 
124  { mInputOperationType = operationType; }
128  { mOutputOperationType = operationType; }
132  virtual void setMaxOutputVertices(int maxOutputVertices)
133  { mMaxOutputVertices = maxOutputVertices; }
134 
135  GLSLShader(ResourceManager* creator,
136  const String& name, ResourceHandle handle,
137  const String& group, bool isManual, ManualResourceLoader* loader);
138  // GL3PlusShader(
139  // ResourceManager* creator, const String& name,
140  // ResourceHandle handle,
141  // const String& group, bool isManual = false,
142  // ManualResourceLoader* loader = 0);
143  ~GLSLShader();
144 
145  GLuint getGLShaderHandle() const { return mGLShaderHandle; }
146  GLuint getGLProgramHandle();
147  void attachToProgramObject(const GLuint programObject);
148  void detachFromProgramObject(const GLuint programObject);
149  String getAttachedShaderNames() const { return mAttachedShaderNames; }
151  GLenum getGLShaderType(GpuProgramType programType);
154  String getShaderTypeLabel(GpuProgramType programType);
155 
157  bool getPassTransformStates(void) const;
158  bool getPassSurfaceAndLightStates(void) const;
159  bool getPassFogStates(void) const;
160 
162  void attachChildShader(const String& name);
163 
165  void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
167  const String& getPreprocessorDefines(void) const { return mPreprocessorDefines; }
168 
170  const String& getLanguage(void) const;
172  void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
174  bool getColumnMajorMatrices(void) const { return mColumnMajorMatrices; }
175 
177  GpuProgramParametersSharedPtr createParameters(void);
178 
180  bool compile( const bool checkErrors = false);
181 
182 
184  void bind(void);
186  void unbind(void);
188  void bindParameters(GpuProgramParametersSharedPtr params, uint16 mask);
190  void bindPassIterationParameters(GpuProgramParametersSharedPtr params);
192  void bindSharedParameters(GpuProgramParametersSharedPtr params, uint16 mask);
193 
194 
198  GLint isLinked(void) { return mLinked; }
199 
203  void setLinked(GLint flag) { mLinked = flag; }
204 
206  size_t calculateSize(void) const;
207 
209  GLuint getShaderID(void) const { return mShaderID; }
210 
212  GpuProgram* _getBindingDelegate(void) { return this; }
213 
214  protected:
221 
224  void loadFromSource(void);
231  void createLowLevelImpl(void);
233  void unloadHighLevelImpl(void);
235  void unloadImpl(void);
236 
238  void populateParameterNames(GpuProgramParametersSharedPtr params);
240  void buildConstantDefinitions() const;
248  void checkAndFixInvalidDefaultPrecisionError( String &message );
249 
250 
251  // /// @copydoc Resource::loadImpl
252  // void loadImpl(void) {}
253 
255  GLuint mShaderID;
256 
257  private:
260 
263 
264 
266  GLint mCompiled;
279 
281  typedef GLSLShaderContainer::iterator GLSLShaderContainerIterator;
284 
285 
287  static GLuint mVertexShaderCount;
289  static GLuint mFragmentShaderCount;
291  static GLuint mGeometryShaderCount;
293  static GLuint mHullShaderCount;
295  static GLuint mDomainShaderCount;
297  static GLuint mComputeShaderCount;
298 
302  GLint mLinked;
303  };
304 }
305 
306 #endif // __GLSLShader_H__
virtual void setOutputOperationType(RenderOperation::OperationType operationType)
Set the operation type that this geometry program will emit.
static CmdPreprocessorDefines msCmdPreprocessorDefines
virtual RenderOperation::OperationType getOutputOperationType(void) const
Returns the operation type that this geometry program will emit.
virtual RenderOperation::OperationType getInputOperationType(void) const
Returns the operation type that this geometry program expects to receive as input.
GLSLShaderContainer::iterator GLSLShaderContainerIterator
static GLuint mDomainShaderCount
Keep track of the number of tessellation domain (evaluation) shaders created.
virtual int getMaxOutputVertices(void) const
Returns the maximum number of vertices that this geometry program can output in a single run...
GpuProgramType
Enumerates the types of programs which can run on the GPU.
GLuint getGLShaderHandle() const
Defines a program which runs on the GPU such as a vertex or fragment program.
Interface describing a manual resource loader.
Definition: OgreResource.h:498
static CmdAttach msCmdAttach
Command object for attaching another GLSL Program.
const String & getPreprocessorDefines(void) const
Sets the preprocessor defines use to compile the program.
GLSLShaderContainer mAttachedGLSLShaders
Container of attached shaders.
static CmdInputOperationType msInputOperationTypeCmd
String getAttachedShaderNames() const
static GLuint mVertexShaderCount
Keep track of the number of vertex shaders created.
Command object for setting macro defines.
static CmdOutputOperationType msOutputOperationTypeCmd
Command object for setting the input operation type (geometry shader only)
void setColumnMajorMatrices(bool columnMajor)
Sets whether matrix packing in column-major order.
GpuProgram * _getBindingDelegate(void)
Since GLSL has no assembly, use this shader for binding.
virtual void setInputOperationType(RenderOperation::OperationType operationType)
Sets the operation type that this geometry program expects to receive.
GLint isLinked(void)
Return the shader link status.
Command object for setting the maximum output vertices (geometry shader only)
String mPreprocessorDefines
Preprocessor options.
GLuint mGLProgramHandle
GL handle for program object the shader is bound to.
static GLuint mGeometryShaderCount
Keep track of the number of geometry shaders created.
void setLinked(GLint flag)
Set the shader link status.
static GLuint mFragmentShaderCount
Keep track of the number of fragment shaders created.
int mMaxOutputVertices
The maximum amount of vertices that this (geometry) program can output.
bool getColumnMajorMatrices(void) const
Gets whether matrix packed in column-major order.
#define _OgreGL3PlusExport
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
static GLuint mComputeShaderCount
Keep track of the number of compute shaders created.
vector< GLSLShader * >::type GLSLShaderContainer
GLuint getShaderID(void) const
Get the OGRE assigned shader ID.
GLint mLinked
Flag indicating that the shader has been successfully linked.
RenderOperation::OperationType mInputOperationType
The input operation type for this (geometry) program.
Defines a generic resource handler.
GLuint mShaderID
OGRE assigned shader ID.
_StringBase String
Definition: OgreCommon.h:53
static CmdColumnMajorMatrices msCmdColumnMajorMatrices
void setPreprocessorDefines(const String &defines)
Sets the preprocessor defines use to compile the program.
unsigned short uint16
Definition: OgrePlatform.h:421
Abstract base class representing a high-level program (a vertex or fragment program).
bool mColumnMajorMatrices
Matrix in column major pack format?
virtual void setMaxOutputVertices(int maxOutputVertices)
Set the maximum number of vertices that a single run of this geometry program can emit...
String mAttachedShaderNames
Attached shader names.
GLint mCompiled
Flag indicating if shader object successfully compiled.
static CmdMaxOutputVertices msMaxOutputVerticesCmd
static GLuint mHullShaderCount
Keep track of the number of tessellation hull (control) shaders created.
Specialisation of HighLevelGpuProgram to encapsulate shader objects obtained from compiled shaders wr...
Command object for setting the output operation type (geometry shader only)
RenderOperation::OperationType mOutputOperationType
The output operation type for this (geometry) program.
Command object for setting matrix packing in column-major order.
Abstract class which is command object which gets/sets parameters.
OperationType
The rendering operation type to perform.
GLuint mGLShaderHandle
GL handle for shader object.