[1] | 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-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This program is free software you can redistribute it and/or modify it under |
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
| 12 | Foundation either version 2 of the License, or (at your option) any later |
---|
| 13 | version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 16 | ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
| 18 | |
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
| 20 | this program if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
| 23 | |
---|
| 24 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | #ifndef __CgProgram_H__ |
---|
| 30 | #define __CgProgram_H__ |
---|
| 31 | |
---|
| 32 | #include "OgreCgPrerequisites.h" |
---|
| 33 | #include "OgreHighLevelGpuProgram.h" |
---|
| 34 | #include "OgreStringVector.h" |
---|
| 35 | |
---|
| 36 | namespace Ogre { |
---|
| 37 | /** Specialisation of HighLevelGpuProgram to provide support for nVidia's CG language. |
---|
| 38 | @remarks |
---|
| 39 | Cg can be used to compile common, high-level, C-like code down to assembler |
---|
| 40 | language for both GL and Direct3D, for multiple graphics cards. You must |
---|
| 41 | supply a list of profiles which your program must support using |
---|
| 42 | setProfiles() before the program is loaded in order for this to work. The |
---|
| 43 | program will then negotiate with the renderer to compile the appropriate program |
---|
| 44 | for the API and graphics card capabilities. |
---|
| 45 | */ |
---|
| 46 | class CgProgram : public HighLevelGpuProgram |
---|
| 47 | { |
---|
| 48 | public: |
---|
| 49 | /// Command object for setting entry point |
---|
| 50 | class CmdEntryPoint : public ParamCommand |
---|
| 51 | { |
---|
| 52 | public: |
---|
| 53 | String doGet(const void* target) const; |
---|
| 54 | void doSet(void* target, const String& val); |
---|
| 55 | }; |
---|
| 56 | /// Command object for setting profiles |
---|
| 57 | class CmdProfiles : public ParamCommand |
---|
| 58 | { |
---|
| 59 | public: |
---|
| 60 | String doGet(const void* target) const; |
---|
| 61 | void doSet(void* target, const String& val); |
---|
| 62 | }; |
---|
| 63 | /// Command object for setting compilation arguments |
---|
| 64 | class CmdArgs : public ParamCommand |
---|
| 65 | { |
---|
| 66 | public: |
---|
| 67 | String doGet(const void* target) const; |
---|
| 68 | void doSet(void* target, const String& val); |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | protected: |
---|
| 72 | |
---|
| 73 | static CmdEntryPoint msCmdEntryPoint; |
---|
| 74 | static CmdProfiles msCmdProfiles; |
---|
| 75 | static CmdArgs msCmdArgs; |
---|
| 76 | |
---|
| 77 | /// The CG context to use, passed in by factory |
---|
| 78 | CGcontext mCgContext; |
---|
| 79 | /// Program handle |
---|
| 80 | CGprogram mCgProgram; |
---|
| 81 | /** Internal load implementation, must be implemented by subclasses. |
---|
| 82 | */ |
---|
| 83 | void loadFromSource(void); |
---|
| 84 | /** Internal method for creating an appropriate low-level program from this |
---|
| 85 | high-level program, must be implemented by subclasses. */ |
---|
| 86 | void createLowLevelImpl(void); |
---|
| 87 | /// Internal unload implementation, must be implemented by subclasses |
---|
| 88 | void unloadHighLevelImpl(void); |
---|
| 89 | /// Populate the passed parameters with name->index map, must be overridden |
---|
| 90 | void buildConstantDefinitions() const; |
---|
| 91 | |
---|
| 92 | /// Recurse down structures getting data on parameters |
---|
| 93 | void recurseParams(CGparameter param, size_t contextArraySize = 1) const; |
---|
| 94 | /// Turn a Cg type into a GpuConstantType and number of elements |
---|
| 95 | void mapTypeAndElementSize(CGtype cgType, bool isRegisterCombiner, GpuConstantDefinition& def) const; |
---|
| 96 | |
---|
| 97 | StringVector mProfiles; |
---|
| 98 | String mEntryPoint; |
---|
| 99 | String mSelectedProfile; |
---|
| 100 | CGprofile mSelectedCgProfile; |
---|
| 101 | String mCompileArgs; |
---|
| 102 | // Unfortunately Cg uses char** for arguments - bleh |
---|
| 103 | // This is a null-terminated list of char* (each null terminated) |
---|
| 104 | char** mCgArguments; |
---|
| 105 | |
---|
| 106 | /// Internal method which works out which profile to use for this program |
---|
| 107 | void selectProfile(void); |
---|
| 108 | /// Internal method which merges manual and automatic compile arguments |
---|
| 109 | void buildArgs(void); |
---|
| 110 | /// Releases memory for the horrible Cg char** |
---|
| 111 | void freeCgArgs(void); |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | public: |
---|
| 115 | CgProgram(ResourceManager* creator, const String& name, ResourceHandle handle, |
---|
| 116 | const String& group, bool isManual, ManualResourceLoader* loader, |
---|
| 117 | CGcontext context); |
---|
| 118 | ~CgProgram(); |
---|
| 119 | |
---|
| 120 | /** Sets the entry point for this program ie the first method called. */ |
---|
| 121 | void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; } |
---|
| 122 | /** Gets the entry point defined for this program. */ |
---|
| 123 | const String& getEntryPoint(void) const { return mEntryPoint; } |
---|
| 124 | /** Sets the Cg profiles which can be supported by the program. */ |
---|
| 125 | void setProfiles(const StringVector& profiles); |
---|
| 126 | /** Gets the Cg profiles which can be supported by the program. */ |
---|
| 127 | const StringVector& getProfiles(void) const { return mProfiles; } |
---|
| 128 | /** Sets the compilation arguments for this program ie the first method called. */ |
---|
| 129 | void setCompileArguments(const String& args) { mCompileArgs = args; } |
---|
| 130 | /** Gets the entry point defined for this program. */ |
---|
| 131 | const String& getCompileArguments(void) const { return mCompileArgs; } |
---|
| 132 | /// Overridden from GpuProgram |
---|
| 133 | bool isSupported(void) const; |
---|
| 134 | /// Overridden from GpuProgram |
---|
| 135 | const String& getLanguage(void) const; |
---|
| 136 | |
---|
| 137 | }; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | #endif |
---|