CmHighLevelGpuProgramManager.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 "OgrePrerequisites.h"
  27. #include "OgreSingleton.h"
  28. #include "OgreException.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, GpuProgramProfile profile) = 0;
  46. virtual void destroy(HighLevelGpuProgram* prog) = 0;
  47. };
  48. /** This ResourceManager manages high-level vertex and fragment programs.
  49. @remarks
  50. High-level vertex and fragment programs can be used instead of assembler programs
  51. as managed by GpuProgramManager; however they typically result in a GpuProgram
  52. being created as a derivative of the high-level program. High-level programs are
  53. easier to write, and can often be API-independent, unlike assembler programs.
  54. @par
  55. This class not only manages the programs themselves, it also manages the factory
  56. classes which allow the creation of high-level programs using a variety of high-level
  57. syntaxes. Plugins can be created which register themselves as high-level program
  58. factories and as such the engine can be extended to accept virtually any kind of
  59. program provided a plugin is written.
  60. */
  61. class CM_EXPORT HighLevelGpuProgramManager : public Singleton<HighLevelGpuProgramManager>
  62. {
  63. public:
  64. typedef map<String, HighLevelGpuProgramFactory*>::type FactoryMap;
  65. protected:
  66. /// Factories capable of creating HighLevelGpuProgram instances
  67. FactoryMap mFactories;
  68. /// Factory for dealing with programs for languages we can't create
  69. HighLevelGpuProgramFactory* mNullFactory;
  70. HighLevelGpuProgramFactory* getFactory(const String& language);
  71. public:
  72. HighLevelGpuProgramManager();
  73. ~HighLevelGpuProgramManager();
  74. /** Add a new factory object for high-level programs of a given language. */
  75. void addFactory(HighLevelGpuProgramFactory* factory);
  76. /** Remove a factory object for high-level programs of a given language. */
  77. void removeFactory(HighLevelGpuProgramFactory* factory);
  78. /** Returns whether a given high-level language is supported. */
  79. bool isLanguageSupported(const String& lang);
  80. /** Create a new, unloaded HighLevelGpuProgram.
  81. @par
  82. This method creates a new program of the type specified as the second and third parameters.
  83. You will have to call further methods on the returned program in order to
  84. define the program fully before you can load it.
  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 createProgram(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype, GpuProgramProfile profile);
  92. /** Override standard Singleton retrieval.
  93. @remarks
  94. Why do we do this? Well, it's because the Singleton
  95. implementation is in a .h file, which means it gets compiled
  96. into anybody who includes it. This is needed for the
  97. Singleton template to work, but we actually only want it
  98. compiled into the implementation of the class based on the
  99. Singleton, not all of them. If we don't change this, we get
  100. link errors when trying to use the Singleton-based class from
  101. an outside dll.
  102. @par
  103. This method just delegates to the template version anyway,
  104. but the implementation stays in this single compilation unit,
  105. preventing link errors.
  106. */
  107. static HighLevelGpuProgramManager& getSingleton(void);
  108. /** Override standard Singleton retrieval.
  109. @remarks
  110. Why do we do this? Well, it's because the Singleton
  111. implementation is in a .h file, which means it gets compiled
  112. into anybody who includes it. This is needed for the
  113. Singleton template to work, but we actually only want it
  114. compiled into the implementation of the class based on the
  115. Singleton, not all of them. If we don't change this, we get
  116. link errors when trying to use the Singleton-based class from
  117. an outside dll.
  118. @par
  119. This method just delegates to the template version anyway,
  120. but the implementation stays in this single compilation unit,
  121. preventing link errors.
  122. */
  123. static HighLevelGpuProgramManager* getSingletonPtr(void);
  124. };
  125. /** @} */
  126. /** @} */
  127. }
  128. #endif