CmHighLevelGpuProgramManager.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 __HighLevelGpuProgramManager_H__
  25. #define __HighLevelGpuProgramManager_H__
  26. #include "CmPrerequisites.h"
  27. #include "CmModule.h"
  28. #include "CmException.h"
  29. #include "CmHighLevelGpuProgram.h"
  30. namespace CamelotFramework {
  31. /** \addtogroup Core
  32. * @{
  33. */
  34. /** \addtogroup Resources
  35. * @{
  36. */
  37. /** Interface definition for factories of HighLevelGpuProgram. */
  38. class CM_EXPORT HighLevelGpuProgramFactory
  39. {
  40. public:
  41. HighLevelGpuProgramFactory() {}
  42. virtual ~HighLevelGpuProgramFactory();
  43. /// Get the name of the language this factory creates programs for
  44. virtual const String& getLanguage(void) const = 0;
  45. virtual HighLevelGpuProgramPtr create(const String& source, const String& entryPoint,
  46. GpuProgramType gptype, GpuProgramProfile profile, const Vector<HGpuProgInclude>::type* includes) = 0;
  47. virtual HighLevelGpuProgramPtr create() = 0;
  48. };
  49. /** This ResourceManager manages high-level vertex and fragment programs.
  50. @remarks
  51. High-level vertex and fragment programs can be used instead of assembler programs
  52. as managed by GpuProgramManager; however they typically result in a GpuProgram
  53. being created as a derivative of the high-level program. High-level programs are
  54. easier to write, and can often be API-independent, unlike assembler programs.
  55. @par
  56. This class not only manages the programs themselves, it also manages the factory
  57. classes which allow the creation of high-level programs using a variety of high-level
  58. syntaxes. Plugins can be created which register themselves as high-level program
  59. factories and as such the engine can be extended to accept virtually any kind of
  60. program provided a plugin is written.
  61. */
  62. class CM_EXPORT HighLevelGpuProgramManager : public Module<HighLevelGpuProgramManager>
  63. {
  64. public:
  65. typedef Map<String, HighLevelGpuProgramFactory*>::type FactoryMap;
  66. protected:
  67. /// Factories capable of creating HighLevelGpuProgram instances
  68. FactoryMap mFactories;
  69. /// Factory for dealing with programs for languages we can't create
  70. HighLevelGpuProgramFactory* mNullFactory;
  71. HighLevelGpuProgramFactory* getFactory(const String& language);
  72. public:
  73. HighLevelGpuProgramManager();
  74. ~HighLevelGpuProgramManager();
  75. /** Add a new factory object for high-level programs of a given language. */
  76. void addFactory(HighLevelGpuProgramFactory* factory);
  77. /** Remove a factory object for high-level programs of a given language. */
  78. void removeFactory(HighLevelGpuProgramFactory* factory);
  79. /** Returns whether a given high-level language is supported. */
  80. bool isLanguageSupported(const String& lang);
  81. /** Create a new HighLevelGpuProgram.
  82. @par
  83. This method creates a new program of the type specified as the second and third parameters.
  84. @param name The identifying name of the program
  85. @param groupName The name of the resource group which this program is
  86. to be a member of
  87. @param language Code of the language to use (e.g. "cg")
  88. @param gptype The type of program to create
  89. */
  90. HighLevelGpuProgramPtr create(const String& source, const String& entryPoint, const String& language,
  91. GpuProgramType gptype, GpuProgramProfile profile, const Vector<HGpuProgInclude>::type* includes);
  92. /** Create a new HighLevelGpuProgram.
  93. @par
  94. This method creates a new program of the specified language. You need to set other
  95. properties like source, entry point, type, profile manually.
  96. @param language Code of the language to use (e.g. "cg")
  97. */
  98. HighLevelGpuProgramPtr create(const String& language);
  99. /**
  100. * @brief Creates a completely empty and uninitialized HighLevelGpuProgram.
  101. * Should only be used for VERY specific purposes, like deserialization,
  102. * as it requires additional manual initialization that is not required normally.
  103. */
  104. HighLevelGpuProgramPtr createEmpty(const String& language);
  105. };
  106. /** @} */
  107. /** @} */
  108. }
  109. #endif