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-2005 The OGRE Team
|
---|
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 | */
|
---|
25 | #ifndef __CgProgram_H__
|
---|
26 | #define __CgProgram_H__
|
---|
27 |
|
---|
28 | #include "OgreCgPrerequisites.h"
|
---|
29 | #include "OgreHighLevelGpuProgram.h"
|
---|
30 | #include "OgreStringVector.h"
|
---|
31 |
|
---|
32 | namespace Ogre {
|
---|
33 | /** Specialisation of HighLevelGpuProgram to provide support for nVidia's CG language.
|
---|
34 | @remarks
|
---|
35 | Cg can be used to compile common, high-level, C-like code down to assembler
|
---|
36 | language for both GL and Direct3D, for multiple graphics cards. You must
|
---|
37 | supply a list of profiles which your program must support using
|
---|
38 | setProfiles() before the program is loaded in order for this to work. The
|
---|
39 | program will then negotiate with the renderer to compile the appropriate program
|
---|
40 | for the API and graphics card capabilities.
|
---|
41 | */
|
---|
42 | class CgProgram : public HighLevelGpuProgram
|
---|
43 | {
|
---|
44 | public:
|
---|
45 | /// Command object for setting entry point
|
---|
46 | class CmdEntryPoint : public ParamCommand
|
---|
47 | {
|
---|
48 | public:
|
---|
49 | String doGet(const void* target) const;
|
---|
50 | void doSet(void* target, const String& val);
|
---|
51 | };
|
---|
52 | /// Command object for setting profiles
|
---|
53 | class CmdProfiles : public ParamCommand
|
---|
54 | {
|
---|
55 | public:
|
---|
56 | String doGet(const void* target) const;
|
---|
57 | void doSet(void* target, const String& val);
|
---|
58 | };
|
---|
59 | /// Command object for setting compilation arguments
|
---|
60 | class CmdArgs : public ParamCommand
|
---|
61 | {
|
---|
62 | public:
|
---|
63 | String doGet(const void* target) const;
|
---|
64 | void doSet(void* target, const String& val);
|
---|
65 | };
|
---|
66 |
|
---|
67 | protected:
|
---|
68 |
|
---|
69 | static CmdEntryPoint msCmdEntryPoint;
|
---|
70 | static CmdProfiles msCmdProfiles;
|
---|
71 | static CmdArgs msCmdArgs;
|
---|
72 |
|
---|
73 | /// The CG context to use, passed in by factory
|
---|
74 | CGcontext mCgContext;
|
---|
75 | /// Program handle
|
---|
76 | CGprogram mCgProgram;
|
---|
77 | /** Internal load implementation, must be implemented by subclasses.
|
---|
78 | */
|
---|
79 | void loadFromSource(void);
|
---|
80 | /** Internal method for creating an appropriate low-level program from this
|
---|
81 | high-level program, must be implemented by subclasses. */
|
---|
82 | void createLowLevelImpl(void);
|
---|
83 | /// Internal unload implementation, must be implemented by subclasses
|
---|
84 | void unloadHighLevelImpl(void);
|
---|
85 | /// Populate the passed parameters with name->index map, must be overridden
|
---|
86 | void populateParameterNames(GpuProgramParametersSharedPtr params);
|
---|
87 |
|
---|
88 | StringVector mProfiles;
|
---|
89 | String mEntryPoint;
|
---|
90 | String mSelectedProfile;
|
---|
91 | CGprofile mSelectedCgProfile;
|
---|
92 | String mCompileArgs;
|
---|
93 | // Unfortunately Cg uses char** for arguments - bleh
|
---|
94 | // This is a null-terminated list of char* (each null terminated)
|
---|
95 | char** mCgArguments;
|
---|
96 |
|
---|
97 | /// Internal method which works out which profile to use for this program
|
---|
98 | void selectProfile(void);
|
---|
99 | /// Internal method which merges manual and automatic compile arguments
|
---|
100 | void buildArgs(void);
|
---|
101 | /// Releases memory for the horrible Cg char**
|
---|
102 | void freeCgArgs(void);
|
---|
103 |
|
---|
104 |
|
---|
105 | public:
|
---|
106 | CgProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
|
---|
107 | const String& group, bool isManual, ManualResourceLoader* loader,
|
---|
108 | CGcontext context);
|
---|
109 | ~CgProgram();
|
---|
110 |
|
---|
111 | /** Sets the entry point for this program ie the first method called. */
|
---|
112 | void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; }
|
---|
113 | /** Gets the entry point defined for this program. */
|
---|
114 | const String& getEntryPoint(void) const { return mEntryPoint; }
|
---|
115 | /** Sets the Cg profiles which can be supported by the program. */
|
---|
116 | void setProfiles(const StringVector& profiles);
|
---|
117 | /** Gets the Cg profiles which can be supported by the program. */
|
---|
118 | const StringVector& getProfiles(void) const { return mProfiles; }
|
---|
119 | /** Sets the compilation arguments for this program ie the first method called. */
|
---|
120 | void setCompileArguments(const String& args) { mCompileArgs = args; }
|
---|
121 | /** Gets the entry point defined for this program. */
|
---|
122 | const String& getCompileArguments(void) const { return mCompileArgs; }
|
---|
123 | /// Overridden from GpuProgram
|
---|
124 | bool isSupported(void) const;
|
---|
125 | };
|
---|
126 | }
|
---|
127 |
|
---|
128 | #endif
|
---|