CmHighLevelGpuProgramManager.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 CamelotEngine {
  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 HighLevelGpuProgram* create(const String& source, const String& entryPoint, GpuProgramType gptype, GpuProgramProfile profile) = 0;
  46. virtual HighLevelGpuProgram* create() = 0;
  47. void destroy(HighLevelGpuProgram* prog);
  48. virtual void destroy_internal(HighLevelGpuProgram* prog) = 0;
  49. };
  50. /** This ResourceManager manages high-level vertex and fragment programs.
  51. @remarks
  52. High-level vertex and fragment programs can be used instead of assembler programs
  53. as managed by GpuProgramManager; however they typically result in a GpuProgram
  54. being created as a derivative of the high-level program. High-level programs are
  55. easier to write, and can often be API-independent, unlike assembler programs.
  56. @par
  57. This class not only manages the programs themselves, it also manages the factory
  58. classes which allow the creation of high-level programs using a variety of high-level
  59. syntaxes. Plugins can be created which register themselves as high-level program
  60. factories and as such the engine can be extended to accept virtually any kind of
  61. program provided a plugin is written.
  62. */
  63. class CM_EXPORT HighLevelGpuProgramManager : public Module<HighLevelGpuProgramManager>
  64. {
  65. public:
  66. typedef map<String, HighLevelGpuProgramFactory*>::type FactoryMap;
  67. protected:
  68. /// Factories capable of creating HighLevelGpuProgram instances
  69. FactoryMap mFactories;
  70. /// Factory for dealing with programs for languages we can't create
  71. HighLevelGpuProgramFactory* mNullFactory;
  72. HighLevelGpuProgramFactory* getFactory(const String& language);
  73. public:
  74. HighLevelGpuProgramManager();
  75. ~HighLevelGpuProgramManager();
  76. /** Add a new factory object for high-level programs of a given language. */
  77. void addFactory(HighLevelGpuProgramFactory* factory);
  78. /** Remove a factory object for high-level programs of a given language. */
  79. void removeFactory(HighLevelGpuProgramFactory* factory);
  80. /** Returns whether a given high-level language is supported. */
  81. bool isLanguageSupported(const String& lang);
  82. /** Create a new HighLevelGpuProgram.
  83. @par
  84. This method creates a new program of the type specified as the second and third parameters.
  85. @param name The identifying name of the program
  86. @param groupName The name of the resource group which this program is
  87. to be a member of
  88. @param language Code of the language to use (e.g. "cg")
  89. @param gptype The type of program to create
  90. */
  91. HighLevelGpuProgramPtr create(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile);
  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