| 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 __D3D9HLSLProgram_H__ | 
|---|
| 30 | #define __D3D9HLSLProgram_H__ | 
|---|
| 31 |  | 
|---|
| 32 | #include "OgreD3D9Prerequisites.h" | 
|---|
| 33 | #include "OgreHighLevelGpuProgram.h" | 
|---|
| 34 |  | 
|---|
| 35 | namespace Ogre { | 
|---|
| 36 |     /** Specialisation of HighLevelGpuProgram to provide support for D3D9  | 
|---|
| 37 |         High-Level Shader Language (HLSL). | 
|---|
| 38 |     @remarks | 
|---|
| 39 |         Note that the syntax of D3D9 HLSL is identical to nVidia's Cg language, therefore | 
|---|
| 40 |         unless you know you will only ever be deploying on Direct3D, or you have some specific | 
|---|
| 41 |         reason for not wanting to use the Cg plugin, I suggest you use Cg instead since that | 
|---|
| 42 |         can produce programs for OpenGL too. | 
|---|
| 43 |     */ | 
|---|
| 44 |     class D3D9HLSLProgram : public HighLevelGpuProgram | 
|---|
| 45 |     { | 
|---|
| 46 |     public: | 
|---|
| 47 |         /// Command object for setting entry point | 
|---|
| 48 |         class CmdEntryPoint : public ParamCommand | 
|---|
| 49 |         { | 
|---|
| 50 |         public: | 
|---|
| 51 |             String doGet(const void* target) const; | 
|---|
| 52 |             void doSet(void* target, const String& val); | 
|---|
| 53 |         }; | 
|---|
| 54 |         /// Command object for setting target assembler | 
|---|
| 55 |         class CmdTarget : public ParamCommand | 
|---|
| 56 |         { | 
|---|
| 57 |         public: | 
|---|
| 58 |             String doGet(const void* target) const; | 
|---|
| 59 |             void doSet(void* target, const String& val); | 
|---|
| 60 |         }; | 
|---|
| 61 |         /// Command object for setting macro defines | 
|---|
| 62 |         class CmdPreprocessorDefines : public ParamCommand | 
|---|
| 63 |         { | 
|---|
| 64 |         public: | 
|---|
| 65 |             String doGet(const void* target) const; | 
|---|
| 66 |             void doSet(void* target, const String& val); | 
|---|
| 67 |         }; | 
|---|
| 68 |         /// Command object for setting matrix packing in column-major order | 
|---|
| 69 |         class CmdColumnMajorMatrices : public ParamCommand | 
|---|
| 70 |         { | 
|---|
| 71 |         public: | 
|---|
| 72 |             String doGet(const void* target) const; | 
|---|
| 73 |             void doSet(void* target, const String& val); | 
|---|
| 74 |         }; | 
|---|
| 75 |  | 
|---|
| 76 |     protected: | 
|---|
| 77 |  | 
|---|
| 78 |         static CmdEntryPoint msCmdEntryPoint; | 
|---|
| 79 |         static CmdTarget msCmdTarget; | 
|---|
| 80 |         static CmdPreprocessorDefines msCmdPreprocessorDefines; | 
|---|
| 81 |         static CmdColumnMajorMatrices msCmdColumnMajorMatrices; | 
|---|
| 82 |  | 
|---|
| 83 |         /** Internal load implementation, must be implemented by subclasses. | 
|---|
| 84 |         */ | 
|---|
| 85 |         void loadFromSource(void); | 
|---|
| 86 |         /** Internal method for creating an appropriate low-level program from this | 
|---|
| 87 |         high-level program, must be implemented by subclasses. */ | 
|---|
| 88 |         void createLowLevelImpl(void); | 
|---|
| 89 |         /// Internal unload implementation, must be implemented by subclasses | 
|---|
| 90 |         void unloadHighLevelImpl(void); | 
|---|
| 91 |         /// Populate the passed parameters with name->index map, must be overridden | 
|---|
| 92 |         void buildConstantDefinitions() const; | 
|---|
| 93 |  | 
|---|
| 94 |         // Recursive utility method for buildParamNameMap | 
|---|
| 95 |         void processParamElement(D3DXHANDLE parent, String prefix, unsigned int index) const; | 
|---|
| 96 |                 void populateDef(D3DXCONSTANT_DESC& d3dDesc, GpuConstantDefinition& def) const; | 
|---|
| 97 |  | 
|---|
| 98 |         String mTarget; | 
|---|
| 99 |         String mEntryPoint; | 
|---|
| 100 |         String mPreprocessorDefines; | 
|---|
| 101 |         bool mColumnMajorMatrices; | 
|---|
| 102 |  | 
|---|
| 103 |         LPD3DXBUFFER mpMicroCode; | 
|---|
| 104 |         LPD3DXCONSTANTTABLE mpConstTable; | 
|---|
| 105 |  | 
|---|
| 106 |     public: | 
|---|
| 107 |         D3D9HLSLProgram(ResourceManager* creator, const String& name, ResourceHandle handle, | 
|---|
| 108 |             const String& group, bool isManual, ManualResourceLoader* loader); | 
|---|
| 109 |         ~D3D9HLSLProgram(); | 
|---|
| 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 shader target to compile down to, e.g. 'vs_1_1'. */ | 
|---|
| 116 |         void setTarget(const String& target); | 
|---|
| 117 |         /** Gets the shader target to compile down to, e.g. 'vs_1_1'. */ | 
|---|
| 118 |         const String& getTarget(void) const { return mTarget; } | 
|---|
| 119 |         /** Sets the preprocessor defines use to compile the program. */ | 
|---|
| 120 |         void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; } | 
|---|
| 121 |         /** Sets the preprocessor defines use to compile the program. */ | 
|---|
| 122 |         const String& getPreprocessorDefines(void) const { return mPreprocessorDefines; } | 
|---|
| 123 |         /** Sets whether matrix packing in column-major order. */  | 
|---|
| 124 |         void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; } | 
|---|
| 125 |         /** Gets whether matrix packed in column-major order. */ | 
|---|
| 126 |         bool getColumnMajorMatrices(void) const { return mColumnMajorMatrices; } | 
|---|
| 127 |         /// Overridden from GpuProgram | 
|---|
| 128 |         bool isSupported(void) const; | 
|---|
| 129 |         /// Overridden from GpuProgram | 
|---|
| 130 |         GpuProgramParametersSharedPtr createParameters(void); | 
|---|
| 131 |         /// Overridden from GpuProgram | 
|---|
| 132 |         const String& getLanguage(void) const; | 
|---|
| 133 |     }; | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | #endif | 
|---|