CmHighLevelGpuProgram.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __HighLevelGpuProgram_H__
  25. #define __HighLevelGpuProgram_H__
  26. #include "OgrePrerequisites.h"
  27. #include "CmGpuProgram.h"
  28. namespace CamelotEngine {
  29. /** \addtogroup Core
  30. * @{
  31. */
  32. /** \addtogroup Resources
  33. * @{
  34. */
  35. /** Abstract base class representing a high-level program (a vertex or
  36. fragment program).
  37. @remarks
  38. High-level programs are vertex and fragment programs written in a high-level
  39. language such as Cg or HLSL, and as such do not require you to write assembler code
  40. like GpuProgram does. However, the high-level program does eventually
  41. get converted (compiled) into assembler and then eventually microcode which is
  42. what runs on the GPU. As well as the convenience, some high-level languages like Cg allow
  43. you to write a program which will operate under both Direct3D and OpenGL, something
  44. which you cannot do with just GpuProgram (which requires you to write 2 programs and
  45. use each in a Technique to provide cross-API compatibility). Ogre will be creating
  46. a GpuProgram for you based on the high-level program, which is compiled specifically
  47. for the API being used at the time, but this process is transparent.
  48. @par
  49. You cannot create high-level programs direct - use HighLevelGpuProgramManager instead.
  50. Plugins can register new implementations of HighLevelGpuProgramFactory in order to add
  51. support for new languages without requiring changes to the core Ogre API. To allow
  52. custom parameters to be set, this class extends StringInterface - the application
  53. can query on the available custom parameters and get/set them without having to
  54. link specifically with it.
  55. */
  56. class CM_EXPORT HighLevelGpuProgram : public GpuProgram
  57. {
  58. protected:
  59. /// Whether the high-level program (and it's parameter defs) is loaded
  60. bool mHighLevelLoaded;
  61. /// The underlying assembler program
  62. GpuProgramPtr mAssemblerProgram;
  63. /// Have we built the name->index parameter map yet?
  64. mutable bool mConstantDefsBuilt;
  65. /// Internal load high-level portion if not loaded
  66. virtual void loadHighLevel(void);
  67. /// Internal unload high-level portion if loaded
  68. virtual void unloadHighLevel(void);
  69. /** Internal load implementation, loads just the high-level portion, enough to
  70. get parameters.
  71. */
  72. virtual void loadHighLevelImpl(void);
  73. /** Internal method for creating an appropriate low-level program from this
  74. high-level program, must be implemented by subclasses. */
  75. virtual void createLowLevelImpl(void) = 0;
  76. /// Internal unload implementation, must be implemented by subclasses
  77. virtual void unloadHighLevelImpl(void) = 0;
  78. /// Populate the passed parameters with name->index map
  79. virtual void populateParameterNames(GpuProgramParametersSharedPtr params);
  80. /** Build the constant definition map, must be overridden.
  81. @note The implementation must fill in the (inherited) mConstantDefs field at a minimum,
  82. and if the program requires that parameters are bound using logical
  83. parameter indexes then the mFloatLogicalToPhysical and mIntLogicalToPhysical
  84. maps must also be populated.
  85. */
  86. virtual void buildConstantDefinitions() const = 0;
  87. public:
  88. /** Constructor, should be used only by factory classes. */
  89. HighLevelGpuProgram();
  90. ~HighLevelGpuProgram();
  91. virtual void load();
  92. virtual void unload();
  93. /** Creates a new parameters object compatible with this program definition.
  94. @remarks
  95. Unlike low-level assembly programs, parameters objects are specific to the
  96. program and therefore must be created from it rather than by the
  97. HighLevelGpuProgramManager. This method creates a new instance of a parameters
  98. object containing the definition of the parameters this program understands.
  99. */
  100. GpuProgramParametersSharedPtr createParameters(void);
  101. /** @copydoc GpuProgram::getBindingDelegate */
  102. GpuProgram* _getBindingDelegate(void) { return mAssemblerProgram.get(); }
  103. /** Get the full list of GpuConstantDefinition instances.
  104. @note
  105. Only available if this parameters object has named parameters.
  106. */
  107. const GpuNamedConstants& getConstantDefinitions() const;
  108. /// Override GpuProgram::getNamedConstants to ensure built
  109. const GpuNamedConstants& getNamedConstants() const { return getConstantDefinitions(); }
  110. };
  111. /** @} */
  112. }
  113. #endif