[148] | 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 __HighLevelGpuProgram_H__ |
---|
| 29 | #define __HighLevelGpuProgram_H__ |
---|
| 30 | |
---|
| 31 | #include "OgrePrerequisites.h" |
---|
| 32 | #include "OgreGpuProgram.h" |
---|
| 33 | |
---|
| 34 | namespace Ogre { |
---|
| 35 | |
---|
| 36 | /** \addtogroup Core |
---|
| 37 | * @{ |
---|
| 38 | */ |
---|
| 39 | /** \addtogroup Resources |
---|
| 40 | * @{ |
---|
| 41 | */ |
---|
| 42 | /** Abstract base class representing a high-level program (a vertex or |
---|
| 43 | fragment program). |
---|
| 44 | @remarks |
---|
| 45 | High-level programs are vertex and fragment programs written in a high-level |
---|
| 46 | language such as Cg or HLSL, and as such do not require you to write assembler code |
---|
| 47 | like GpuProgram does. However, the high-level program does eventually |
---|
| 48 | get converted (compiled) into assembler and then eventually microcode which is |
---|
| 49 | what runs on the GPU. As well as the convenience, some high-level languages like Cg allow |
---|
| 50 | you to write a program which will operate under both Direct3D and OpenGL, something |
---|
| 51 | which you cannot do with just GpuProgram (which requires you to write 2 programs and |
---|
| 52 | use each in a Technique to provide cross-API compatibility). Ogre will be creating |
---|
| 53 | a GpuProgram for you based on the high-level program, which is compiled specifically |
---|
| 54 | for the API being used at the time, but this process is transparent. |
---|
| 55 | @par |
---|
| 56 | You cannot create high-level programs direct - use HighLevelGpuProgramManager instead. |
---|
| 57 | Plugins can register new implementations of HighLevelGpuProgramFactory in order to add |
---|
| 58 | support for new languages without requiring changes to the core Ogre API. To allow |
---|
| 59 | custom parameters to be set, this class extends StringInterface - the application |
---|
| 60 | can query on the available custom parameters and get/set them without having to |
---|
| 61 | link specifically with it. |
---|
| 62 | */ |
---|
| 63 | class _OgreExport HighLevelGpuProgram : public GpuProgram |
---|
| 64 | { |
---|
| 65 | protected: |
---|
| 66 | /// Whether the high-level program (and it's parameter defs) is loaded |
---|
| 67 | bool mHighLevelLoaded; |
---|
| 68 | /// The underlying assembler program |
---|
| 69 | GpuProgramPtr mAssemblerProgram; |
---|
| 70 | /// Have we built the name->index parameter map yet? |
---|
| 71 | mutable bool mConstantDefsBuilt; |
---|
| 72 | |
---|
| 73 | /// Internal load high-level portion if not loaded |
---|
| 74 | virtual void loadHighLevel(void); |
---|
| 75 | /// Internal unload high-level portion if loaded |
---|
| 76 | virtual void unloadHighLevel(void); |
---|
| 77 | /** Internal load implementation, loads just the high-level portion, enough to |
---|
| 78 | get parameters. |
---|
| 79 | */ |
---|
| 80 | virtual void loadHighLevelImpl(void); |
---|
| 81 | /** Internal method for creating an appropriate low-level program from this |
---|
| 82 | high-level program, must be implemented by subclasses. */ |
---|
| 83 | virtual void createLowLevelImpl(void) = 0; |
---|
| 84 | /// Internal unload implementation, must be implemented by subclasses |
---|
| 85 | virtual void unloadHighLevelImpl(void) = 0; |
---|
| 86 | /// Populate the passed parameters with name->index map |
---|
| 87 | virtual void populateParameterNames(GpuProgramParametersSharedPtr params); |
---|
| 88 | /** Build the constant definition map, must be overridden. |
---|
| 89 | @note The implementation must fill in the (inherited) mConstantDefs field at a minimum, |
---|
| 90 | and if the program requires that parameters are bound using logical |
---|
| 91 | parameter indexes then the mFloatLogicalToPhysical and mIntLogicalToPhysical |
---|
| 92 | maps must also be populated. |
---|
| 93 | */ |
---|
| 94 | virtual void buildConstantDefinitions() const = 0; |
---|
| 95 | |
---|
| 96 | /** @copydoc Resource::loadImpl */ |
---|
| 97 | void loadImpl(); |
---|
| 98 | /** @copydoc Resource::unloadImpl */ |
---|
| 99 | void unloadImpl(); |
---|
| 100 | public: |
---|
| 101 | /** Constructor, should be used only by factory classes. */ |
---|
| 102 | HighLevelGpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle, |
---|
| 103 | const String& group, bool isManual = false, ManualResourceLoader* loader = 0); |
---|
| 104 | ~HighLevelGpuProgram(); |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | /** Creates a new parameters object compatible with this program definition. |
---|
| 108 | @remarks |
---|
| 109 | Unlike low-level assembly programs, parameters objects are specific to the |
---|
| 110 | program and therefore must be created from it rather than by the |
---|
| 111 | HighLevelGpuProgramManager. This method creates a new instance of a parameters |
---|
| 112 | object containing the definition of the parameters this program understands. |
---|
| 113 | */ |
---|
| 114 | GpuProgramParametersSharedPtr createParameters(void); |
---|
| 115 | /** @copydoc GpuProgram::_getBindingDelegate */ |
---|
| 116 | GpuProgram* _getBindingDelegate(void) { return mAssemblerProgram.getPointer(); } |
---|
| 117 | |
---|
| 118 | /** Get the full list of GpuConstantDefinition instances. |
---|
| 119 | @note |
---|
| 120 | Only available if this parameters object has named parameters. |
---|
| 121 | */ |
---|
| 122 | const GpuNamedConstants& getConstantDefinitions() const; |
---|
| 123 | |
---|
| 124 | /// Override GpuProgram::getNamedConstants to ensure built |
---|
| 125 | const GpuNamedConstants& getNamedConstants() const { return getConstantDefinitions(); } |
---|
| 126 | |
---|
| 127 | virtual size_t calculateSize(void) const; |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | }; |
---|
| 133 | /** @} */ |
---|
| 134 | /** @} */ |
---|
| 135 | |
---|
| 136 | } |
---|
| 137 | #endif |
---|