OgreGpuProgram.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-2013 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 __GpuProgram_H_
29 #define __GpuProgram_H_
30 
31 // Precompiler options
32 #include "OgrePrerequisites.h"
33 #include "OgreResource.h"
34 #include "OgreSharedPtr.h"
35 #include "OgreIteratorWrappers.h"
36 #include "OgreSerializer.h"
37 #include "OgreRenderOperation.h"
38 #include "OgreGpuProgramParams.h"
39 #include "OgreHeaderPrefix.h"
40 
41 namespace Ogre {
42 
51  {
58  };
59 
70  {
71  protected:
74  {
75  public:
76  String doGet(const void* target) const;
77  void doSet(void* target, const String& val);
78  };
80  {
81  public:
82  String doGet(const void* target) const;
83  void doSet(void* target, const String& val);
84  };
86  {
87  public:
88  String doGet(const void* target) const;
89  void doSet(void* target, const String& val);
90  };
92  {
93  public:
94  String doGet(const void* target) const;
95  void doSet(void* target, const String& val);
96  };
98  {
99  public:
100  String doGet(const void* target) const;
101  void doSet(void* target, const String& val);
102  };
104  {
105  public:
106  String doGet(const void* target) const;
107  void doSet(void* target, const String& val);
108  };
110  {
111  public:
112  String doGet(const void* target) const;
113  void doSet(void* target, const String& val);
114  };
116  {
117  public:
118  String doGet(const void* target) const;
119  void doSet(void* target, const String& val);
120  };
121  // Command object for setting / getting parameters
127  static CmdVTF msVTFCmd;
177 
178 
188 
192 
194  void loadImpl(void);
195 
197  void createParameterMappingStructures(bool recreateIfExists = true) const;
199  void createLogicalParameterMappingStructures(bool recreateIfExists = true) const;
201  void createNamedParameterMappingStructures(bool recreateIfExists = true) const;
202 
203  public:
204 
205  GpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
206  const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
207 
208  virtual ~GpuProgram() {}
209 
214  virtual void setSourceFile(const String& filename);
215 
220  virtual void setSource(const String& source);
221 
223  virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
224 
226  virtual void setSyntaxCode(const String& syntax);
227 
229  virtual const String& getSourceFile(void) const { return mFilename; }
231  virtual const String& getSource(void) const { return mSource; }
233  virtual void setType(GpuProgramType t);
235  virtual GpuProgramType getType(void) const { return mType; }
236 
241  virtual GpuProgram* _getBindingDelegate(void) { return this; }
242 
244  virtual bool isSupported(void) const;
245 
254 
261  virtual void setSkeletalAnimationIncluded(bool included)
262  { mSkeletalAnimation = included; }
263 
270  virtual bool isSkeletalAnimationIncluded(void) const { return mSkeletalAnimation; }
271 
278  virtual void setMorphAnimationIncluded(bool included)
279  { mMorphAnimation = included; }
280 
288  virtual void setPoseAnimationIncluded(ushort poseCount)
289  { mPoseAnimation = poseCount; }
290 
297  virtual bool isMorphAnimationIncluded(void) const { return mMorphAnimation; }
298 
305  virtual bool isPoseAnimationIncluded(void) const { return mPoseAnimation > 0; }
309  virtual ushort getNumberOfPosesIncluded(void) const { return mPoseAnimation; }
313  virtual void setVertexTextureFetchRequired(bool r) { mVertexTextureFetch = r; }
317  virtual bool isVertexTextureFetchRequired(void) const { return mVertexTextureFetch; }
318 
322  virtual void setAdjacencyInfoRequired(bool r) { mNeedsAdjacencyInfo = r; }
326  virtual bool isAdjacencyInfoRequired(void) const { return mNeedsAdjacencyInfo; }
327 
339 
342  virtual bool hasDefaultParameters(void) const { return !mDefaultParams.isNull(); }
343 
350  virtual bool getPassSurfaceAndLightStates(void) const { return false; }
351 
360  virtual bool getPassFogStates(void) const { return true; }
361 
368  virtual bool getPassTransformStates(void) const { return false; }
369 
373  virtual const String& getLanguage(void) const;
374 
377  virtual bool hasCompileError(void) const { return mCompileError; }
378 
381  virtual void resetCompileError(void) { mCompileError = false; }
382 
391  virtual void setManualNamedConstants(const GpuNamedConstants& namedConstants);
392 
394  virtual const GpuNamedConstants& getNamedConstants() const { return *mConstantDefs.get(); }
395 
406  virtual void setManualNamedConstantsFile(const String& paramDefFile);
407 
411  virtual const String& getManualNamedConstantsFile() const { return mManualNamedConstantsFile; }
418  virtual const GpuNamedConstants& getConstantDefinitions() const { return *mConstantDefs.get(); }
419 
421  virtual size_t calculateSize(void) const;
422 
423  protected:
425  virtual void loadFromSource(void) = 0;
426 
427  };
430 }
431 
432 #include "OgreHeaderSuffix.h"
433 
434 #endif
#define _OgreExport
Definition: OgrePlatform.h:257
void doSet(void *target, const String &val)
String doGet(const void *target) const
String doGet(const void *target) const
void doSet(void *target, const String &val)
void doSet(void *target, const String &val)
String doGet(const void *target) const
String doGet(const void *target) const
void doSet(void *target, const String &val)
void doSet(void *target, const String &val)
String doGet(const void *target) const
void doSet(void *target, const String &val)
String doGet(const void *target) const
Command object - see ParamCommand.
void doSet(void *target, const String &val)
String doGet(const void *target) const
void doSet(void *target, const String &val)
String doGet(const void *target) const
Defines a program which runs on the GPU such as a vertex or fragment program.
static CmdPose msPoseCmd
virtual GpuProgramParametersSharedPtr getDefaultParameters(void)
Get a reference to the default parameters which are to be used for all uses of this program.
virtual bool isSkeletalAnimationIncluded(void) const
Returns whether a vertex program includes the required instructions to perform skeletal animation.
void createNamedParameterMappingStructures(bool recreateIfExists=true) const
Create the internal params named mapping structures.
virtual bool getPassFogStates(void) const
Returns whether a fragment program wants fog state to be passed through fixed pipeline low level API ...
String mSyntaxCode
Syntax code e.g. arbvp1, vs_2_0 etc.
String mManualNamedConstantsFile
File from which to load named constants manually.
bool mLoadedManualNamedConstants
virtual void resetCompileError(void)
Reset a compile error if it occurred, allowing the load to be retried.
virtual const String & getSource(void) const
Gets the assembler source for this program.
virtual void setSource(const String &source)
Sets the source assembly for this program from an in-memory string.
GpuLogicalBufferStructPtr mDoubleLogicalToPhysical
Record of logical to physical buffer maps.
ushort mPoseAnimation
Does this (vertex) program include pose animation (count of number of poses supported)
virtual void setAdjacencyInfoRequired(bool r)
Sets whether this geometry program requires adjacency information from the input primitives.
void createParameterMappingStructures(bool recreateIfExists=true) const
Create the internal params logical & named mapping structures.
void loadImpl(void)
Internal implementation of the meat of the 'load' action, only called if this resource is not being l...
virtual bool hasCompileError(void) const
Did this program encounter a compile error when loading?
GpuNamedConstantsPtr mConstantDefs
Parameter name -> ConstantDefinition map, shared instance used by all parameter objects.
static CmdType msTypeCmd
virtual void setSourceFile(const String &filename)
Sets the filename of the source assembly for this program.
virtual void setVertexTextureFetchRequired(bool r)
Sets whether this vertex program requires support for vertex texture fetch from the hardware.
virtual bool hasDefaultParameters(void) const
Returns true if default parameters have been set up.
virtual void setSyntaxCode(const String &syntax)
Sets the syntax code for this program e.g.
virtual const GpuNamedConstants & getConstantDefinitions() const
Get the full list of named constants.
bool mNeedsAdjacencyInfo
Does this (geometry) program require adjacency information?
bool mLoadFromFile
Whether we need to load source from file or not.
virtual bool isMorphAnimationIncluded(void) const
Returns whether a vertex program includes the required instructions to perform morph animation.
virtual bool getPassTransformStates(void) const
Returns whether a vertex program wants transform state to be passed through fixed pipeline low level ...
virtual const String & getSyntaxCode(void) const
Gets the syntax code for this program e.g.
virtual bool isAdjacencyInfoRequired(void) const
Returns whether this geometry program requires adjacency information from the input primitives.
bool mVertexTextureFetch
Does this (vertex) program require support for vertex texture fetch?
virtual const String & getSourceFile(void) const
Gets the name of the file used as source for this program.
virtual bool isVertexTextureFetchRequired(void) const
Returns whether this vertex program requires support for vertex texture fetch from the hardware.
String mSource
The assembler source of the program (may be blank until file loaded)
static CmdMorph msMorphCmd
virtual void setMorphAnimationIncluded(bool included)
Sets whether a vertex program includes the required instructions to perform morph animation.
virtual void setPoseAnimationIncluded(ushort poseCount)
Sets whether a vertex program includes the required instructions to perform pose animation.
String mFilename
The name of the file to load source from (may be blank)
virtual const String & getManualNamedConstantsFile() const
Gets the name of a file from which to load named parameters mapping for a program which would not be ...
bool mMorphAnimation
Does this (vertex) program include morph animation?
GpuLogicalBufferStructPtr mIntLogicalToPhysical
Record of logical to physical buffer maps.
bool mSkeletalAnimation
Does this (vertex) program include skeletal animation?
virtual void setType(GpuProgramType t)
Set the program type (only valid before load)
GpuLogicalBufferStructPtr mFloatLogicalToPhysical
Record of logical to physical buffer maps.
virtual GpuProgramType getType(void) const
Get the program type.
GpuProgramParametersSharedPtr mDefaultParams
The default parameters for use with this object.
GpuProgramType mType
The type of the program.
bool mCompileError
Did we encounter a compilation error?
virtual const String & getLanguage(void) const
Returns a string that specifies the language of the gpu programs as specified in a material script.
bool isRequiredCapabilitiesSupported(void) const
Internal method returns whether required capabilities for this program is supported.
GpuProgram(ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual=false, ManualResourceLoader *loader=0)
static CmdVTF msVTFCmd
static CmdSkeletal msSkeletalCmd
virtual void setManualNamedConstants(const GpuNamedConstants &namedConstants)
Allows you to manually provide a set of named parameter mappings to a program which would not be able...
virtual const GpuNamedConstants & getNamedConstants() const
Get a read-only reference to the named constants registered for this program (manually or automatical...
static CmdAdjacency msAdjacencyCmd
virtual bool isPoseAnimationIncluded(void) const
Returns whether a vertex program includes the required instructions to perform pose animation.
static CmdManualNamedConstsFile msManNamedConstsFileCmd
void createLogicalParameterMappingStructures(bool recreateIfExists=true) const
Create the internal params logical mapping structures.
virtual ushort getNumberOfPosesIncluded(void) const
Returns the number of simultaneous poses the vertex program can blend, for use in pose animation.
virtual void setSkeletalAnimationIncluded(bool included)
Sets whether a vertex program includes the required instructions to perform skeletal animation.
virtual GpuProgramParametersSharedPtr createParameters(void)
Creates a new parameters object compatible with this program definition.
virtual bool isSupported(void) const
Returns whether this program can be supported on the current renderer and hardware.
virtual bool getPassSurfaceAndLightStates(void) const
Returns whether a vertex program wants light and material states to be passed through fixed pipeline ...
virtual GpuProgram * _getBindingDelegate(void)
Returns the GpuProgram which should be bound to the pipeline.
virtual size_t calculateSize(void) const
Calculate the size of a resource; this will only be called after 'load'.
void setupBaseParamDictionary(void)
Internal method for setting up the basic parameter definitions for a subclass.
static CmdSyntax msSyntaxCmd
virtual ~GpuProgram()
virtual void setManualNamedConstantsFile(const String &paramDefFile)
Specifies the name of a file from which to load named parameters mapping for a program which would no...
virtual void loadFromSource(void)=0
Virtual method which must be implemented by subclasses, load from mSource.
Interface describing a manual resource loader.
Definition: OgreResource.h:515
Abstract class which is command object which gets/sets parameters.
Defines a generic resource handler.
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:80
bool isNull(void) const
T * get() const
GpuProgramType
Enumerates the types of programs which can run on the GPU.
@ GPT_VERTEX_PROGRAM
@ GPT_DOMAIN_PROGRAM
@ GPT_GEOMETRY_PROGRAM
@ GPT_COMPUTE_PROGRAM
@ GPT_FRAGMENT_PROGRAM
@ GPT_HULL_PROGRAM
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
_StringBase String
unsigned short ushort
Struct collecting together the information for named constants.

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.