OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreCgProgram.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 __CgProgram_H__
29 #define __CgProgram_H__
30 
31 #include "OgreCgPrerequisites.h"
33 #include "OgreStringVector.h"
34 
35 namespace Ogre {
46  {
47  public:
49  class CmdEntryPoint : public ParamCommand
50  {
51  public:
52  String doGet(const void* target) const;
53  void doSet(void* target, const String& val);
54  };
56  class CmdProfiles : public ParamCommand
57  {
58  public:
59  String doGet(const void* target) const;
60  void doSet(void* target, const String& val);
61  };
63  class CmdArgs : public ParamCommand
64  {
65  public:
66  String doGet(const void* target) const;
67  void doSet(void* target, const String& val);
68  };
69 
70  protected:
71 
75 
77  CGcontext mCgContext;
80  void loadFromSource(void);
83  void createLowLevelImpl(void);
85  void unloadHighLevelImpl(void);
87  void buildConstantDefinitions() const;
88 
90  void loadHighLevelSafe();
91 
93  void recurseParams(CGparameter param, size_t contextArraySize = 1);
95  void mapTypeAndElementSize(CGtype cgType, bool isRegisterCombiner, GpuConstantDefinition& def) const;
96 
103  // Unfortunately Cg uses char** for arguments - bleh
104  // This is a null-terminated list of char* (each null terminated)
105  char** mCgArguments;
106 
111 
113  void selectProfile(void);
115  void buildArgs(void);
117  void freeCgArgs(void);
118 
119  void getMicrocodeFromCache(void);
120  void compileMicrocode(void);
121  void addMicrocodeToCache();
122 
123  private:
126  String getHighLevelTarget() const;
127  void fixHighLevelOutput(String& hlSource);
128 
129 
130  public:
131  CgProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
132  const String& group, bool isManual, ManualResourceLoader* loader,
133  CGcontext context);
134  ~CgProgram();
135 
137  void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; }
139  const String& getEntryPoint(void) const { return mEntryPoint; }
141  void setProfiles(const StringVector& profiles);
143  const StringVector& getProfiles(void) const { return mProfiles; }
145  void setCompileArguments(const String& args) { mCompileArgs = args; }
147  const String& getCompileArguments(void) const { return mCompileArgs; }
149  bool isSupported(void) const;
151  const String& getLanguage(void) const;
152 
155 
156  bool isSkeletalAnimationIncluded(void) const;
157  bool isMorphAnimationIncluded(void) const;
158  bool isPoseAnimationIncluded(void) const;
159  bool isVertexTextureFetchRequired(void) const;
161  bool hasDefaultParameters(void) const;
162  bool getPassSurfaceAndLightStates(void) const;
163  bool getPassFogStates(void) const;
164  bool getPassTransformStates(void) const;
165  bool hasCompileError(void) const;
166  void resetCompileError(void);
167  size_t getSize(void) const;
168  void touch(void);
169 
171  static String resolveCgIncludes(const String& source, Resource* resourceBeingLoaded, const String& fileName);
172  };
173 }
174 
175 #endif
void touch(void)
'Touches' the resource to indicate it has been used.
static String resolveCgIncludes(const String &source, Resource *resourceBeingLoaded, const String &fileName)
Scan the file for #include and replace with source from the OGRE resources.
Command object for setting entry point.
Definition: OgreCgProgram.h:49
static CmdEntryPoint msCmdEntryPoint
Definition: OgreCgProgram.h:72
static CmdProfiles msCmdProfiles
Definition: OgreCgProgram.h:73
bool isVertexTextureFetchRequired(void) const
Returns whether this vertex program requires support for vertex texture fetch from the hardware...
map< String, int >::type mSamplerRegisterMap
const String & getEntryPoint(void) const
Gets the entry point defined for this program.
const String & getCompileArguments(void) const
Gets the entry point defined for this program.
GpuProgram * _getBindingDelegate()
Returns the GpuProgram which should be bound to the pipeline.
String getHighLevelTarget() const
void mapTypeAndElementSize(CGtype cgType, bool isRegisterCombiner, GpuConstantDefinition &def) const
Turn a Cg type into a GpuConstantType and number of elements.
Command object for setting profiles.
Definition: OgreCgProgram.h:56
void buildArgs(void)
Internal method which merges manual and automatic compile arguments.
bool isSupported(void) const
Overridden from GpuProgram.
Defines a program which runs on the GPU such as a vertex or fragment program.
bool isMorphAnimationIncluded(void) const
Returns whether a vertex program includes the required instructions to perform morph animation...
Interface describing a manual resource loader.
Definition: OgreResource.h:498
StringVector mProfiles
Definition: OgreCgProgram.h:97
static CmdArgs msCmdArgs
Definition: OgreCgProgram.h:74
void loadHighLevelSafe()
Load the high-level part in a thread-safe way, required for delegate functionality.
bool isSkeletalAnimationIncluded(void) const
Returns whether a vertex program includes the required instructions to perform skeletal animation...
void setCompileArguments(const String &args)
Sets the compilation arguments for this program ie the first method called.
void buildConstantDefinitions() const
Populate the passed parameters with name->index map, must be overridden.
void getMicrocodeFromCache(void)
char ** mCgArguments
bool getPassFogStates(void) const
Returns whether a fragment program wants fog state to be passed through fixed pipeline low level API ...
CgProgram(ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual, ManualResourceLoader *loader, CGcontext context)
void addMicrocodeToCache()
size_t getSize(void) const
Retrieves info about the size of the resource.
String doGet(const void *target) const
GpuProgramParametersSharedPtr getDefaultParameters(void)
Get a reference to the default parameters which are to be used for all uses of this program...
void setEntryPoint(const String &entryPoint)
Sets the entry point for this program ie the first method called.
Command object for setting compilation arguments.
Definition: OgreCgProgram.h:63
vector< String >::type StringVector
CGprofile mSelectedCgProfile
void recurseParams(CGparameter param, size_t contextArraySize=1)
Recurse down structures getting data on parameters.
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:77
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
const String & getLanguage(void) const
Overridden from GpuProgram.
void doSet(void *target, const String &val)
void fixHighLevelOutput(String &hlSource)
bool isPoseAnimationIncluded(void) const
Returns whether a vertex program includes the required instructions to perform pose animation...
GpuProgramParametersSharedPtr createParameters()
Creates a new parameters object compatible with this program definition.
HighLevelGpuProgramPtr mDelegate
bool hasCompileError(void) const
Did this program encounter a compile error when loading?
void setProfiles(const StringVector &profiles)
Sets the Cg profiles which can be supported by the program.
Specialisation of HighLevelGpuProgram to provide support for nVidia's CG language.
Definition: OgreCgProgram.h:45
void loadFromSource(void)
Internal load implementation, must be implemented by subclasses.
void compileMicrocode(void)
void freeCgArgs(void)
Releases memory for the horrible Cg char**.
size_t mParametersMapSizeAsBuffer
map< String, GpuConstantDefinition >::type GpuConstantDefinitionMap
void createLowLevelImpl(void)
Internal method for creating an appropriate low-level program from this high-level program...
bool getPassSurfaceAndLightStates(void) const
Returns whether a vertex program wants light and material states to be passed through fixed pipeline ...
Defines a generic resource handler.
String doGet(const void *target) const
bool hasDefaultParameters(void) const
Returns true if default parameters have been set up.
void unloadHighLevelImpl(void)
Internal unload implementation, must be implemented by subclasses.
Information about predefined program constants.
_StringBase String
Definition: OgreCommon.h:53
String getHighLevelLanguage() const
Abstract base class representing a high-level program (a vertex or fragment program).
GpuConstantDefinitionMap mParametersMap
void doSet(void *target, const String &val)
String doGet(const void *target) const
bool getPassTransformStates(void) const
Returns whether a vertex program wants transform state to be passed through fixed pipeline low level ...
String mSelectedProfile
Definition: OgreCgProgram.h:99
void resetCompileError(void)
Reset a compile error if it occurred, allowing the load to be retried.
void doSet(void *target, const String &val)
const StringVector & getProfiles(void) const
Gets the Cg profiles which can be supported by the program.
CGcontext mCgContext
The CG context to use, passed in by factory.
Definition: OgreCgProgram.h:77
Abstract class which is command object which gets/sets parameters.
void selectProfile(void)
Internal method which works out which profile to use for this program.