CmGpuProgramManager.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 __GpuProgramManager_H_
  25. #define __GpuProgramManager_H_
  26. // Precompiler options
  27. #include "OgrePrerequisites.h"
  28. #include "OgreException.h"
  29. #include "CmGpuProgram.h"
  30. #include "OgreSingleton.h"
  31. namespace CamelotEngine {
  32. /** \addtogroup Core
  33. * @{
  34. */
  35. /** \addtogroup Resources
  36. * @{
  37. */
  38. class CM_EXPORT GpuProgramManager : public Singleton<GpuProgramManager>
  39. {
  40. public:
  41. typedef set<String>::type SyntaxCodes;
  42. typedef map<String, GpuSharedParametersPtr>::type SharedParametersMap;
  43. protected:
  44. SharedParametersMap mSharedParametersMap;
  45. /** General create method
  46. */
  47. virtual GpuProgram* create(GpuProgramType gptype, const String& syntaxCode) = 0;
  48. public:
  49. GpuProgramManager();
  50. virtual ~GpuProgramManager();
  51. /** Loads a GPU program from a string of assembly code.
  52. @remarks
  53. The assembly code must be compatible with this manager - call the
  54. getSupportedSyntax method for details of the supported syntaxes
  55. @param name The identifying name to give this program, which can be used to
  56. retrieve this program later with getByName.
  57. @param groupName The name of the resource group
  58. @param code A string of assembly code which will form the program to run
  59. @param gptype The type of program to create.
  60. @param syntaxCode The name of the syntax to be used for this program e.g. arbvp1, vs_1_1
  61. */
  62. virtual GpuProgramPtr load(const String& code, GpuProgramType gptype,
  63. const String& syntaxCode);
  64. /** Returns the syntaxes that this manager supports. */
  65. virtual const SyntaxCodes& getSupportedSyntax(void) const;
  66. /** Returns whether a given syntax code (e.g. "ps_1_3", "fp20", "arbvp1") is supported. */
  67. virtual bool isSyntaxSupported(const String& syntaxCode) const;
  68. /** Creates a new GpuProgramParameters instance which can be used to bind
  69. parameters to your programs.
  70. @remarks
  71. Program parameters can be shared between multiple programs if you wish.
  72. */
  73. virtual GpuProgramParametersSharedPtr createParameters(void);
  74. /** Create a GPU program from a string of assembly code.
  75. @remarks
  76. Use this method in preference to the 'load' methods if you wish to define
  77. a GpuProgram, but not load it yet; useful for saving memory.
  78. @par
  79. The assembly code must be compatible with this manager - call the
  80. getSupportedSyntax method for details of the supported syntaxes
  81. @param name The identifying name to give this program, which can be used to
  82. retrieve this program later with getByName.
  83. @param groupName The name of the resource group
  84. @param code A string of assembly code which will form the program to run
  85. @param gptype The type of program to create.
  86. @param syntaxCode The name of the syntax to be used for this program e.g. arbvp1, vs_1_1
  87. */
  88. virtual GpuProgramPtr createProgram(const String& code,
  89. GpuProgramType gptype, const String& syntaxCode);
  90. /** Create a new set of shared parameters, which can be used across many
  91. GpuProgramParameters objects of different structures.
  92. @param name The name to give the shared parameters so you can refer to them
  93. later.
  94. */
  95. virtual GpuSharedParametersPtr createSharedParameters(const String& name);
  96. /** Retrieve a set of shared parameters, which can be used across many
  97. GpuProgramParameters objects of different structures.
  98. */
  99. virtual GpuSharedParametersPtr getSharedParameters(const String& name) const;
  100. /** Get (const) access to the available shared parameter sets.
  101. */
  102. virtual const SharedParametersMap& getAvailableSharedParameters() const;
  103. /** Override standard Singleton retrieval.
  104. @remarks
  105. Why do we do this? Well, it's because the Singleton
  106. implementation is in a .h file, which means it gets compiled
  107. into anybody who includes it. This is needed for the
  108. Singleton template to work, but we actually only want it
  109. compiled into the implementation of the class based on the
  110. Singleton, not all of them. If we don't change this, we get
  111. link errors when trying to use the Singleton-based class from
  112. an outside dll.
  113. @par
  114. This method just delegates to the template version anyway,
  115. but the implementation stays in this single compilation unit,
  116. preventing link errors.
  117. */
  118. static GpuProgramManager& getSingleton(void);
  119. /** Override standard Singleton retrieval.
  120. @remarks
  121. Why do we do this? Well, it's because the Singleton
  122. implementation is in a .h file, which means it gets compiled
  123. into anybody who includes it. This is needed for the
  124. Singleton template to work, but we actually only want it
  125. compiled into the implementation of the class based on the
  126. Singleton, not all of them. If we don't change this, we get
  127. link errors when trying to use the Singleton-based class from
  128. an outside dll.
  129. @par
  130. This method just delegates to the template version anyway,
  131. but the implementation stays in this single compilation unit,
  132. preventing link errors.
  133. */
  134. static GpuProgramManager* getSingletonPtr(void);
  135. };
  136. /** @} */
  137. /** @} */
  138. }
  139. #endif