CmGpuProgram.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 __GpuProgram_H_
  25. #define __GpuProgram_H_
  26. // Precompiler options
  27. #include "CmPrerequisites.h"
  28. #include "CmRenderOperation.h"
  29. #include "CmGpuProgramParams.h"
  30. #include "CmResource.h"
  31. #include "CmGpuParamDesc.h"
  32. namespace CamelotEngine {
  33. /** \addtogroup Core
  34. * @{
  35. */
  36. /** \addtogroup Resources
  37. * @{
  38. */
  39. /** Enumerates the types of programs which can run on the GPU. */
  40. enum GpuProgramType
  41. {
  42. GPT_VERTEX_PROGRAM,
  43. GPT_FRAGMENT_PROGRAM,
  44. GPT_GEOMETRY_PROGRAM,
  45. GPT_DOMAIN_PROGRAM,
  46. GPT_HULL_PROGRAM,
  47. GPT_COMPUTE_PROGRAM
  48. };
  49. enum GpuProgramProfile
  50. {
  51. GPP_NONE,
  52. GPP_PS_1_1,
  53. GPP_PS_1_2,
  54. GPP_PS_1_3,
  55. GPP_PS_1_4,
  56. GPP_PS_2_0,
  57. GPP_PS_2_x,
  58. GPP_PS_2_a,
  59. GPP_PS_2_b,
  60. GPP_PS_3_0,
  61. GPP_PS_3_x,
  62. GPP_PS_4_0,
  63. GPP_PS_4_1,
  64. GPP_PS_5_0,
  65. GPP_VS_1_1,
  66. GPP_VS_2_0,
  67. GPP_VS_2_x,
  68. GPP_VS_2_a,
  69. GPP_VS_3_0,
  70. GPP_VS_4_0,
  71. GPP_VS_4_1,
  72. GPP_VS_5_0,
  73. GPP_GS_4_0,
  74. GPP_GS_4_1,
  75. GPP_GS_5_0,
  76. GPP_HS_5_0,
  77. GPP_DS_5_0,
  78. GPP_CS_5_0
  79. };
  80. /** Defines a program which runs on the GPU such as a vertex or fragment program.
  81. @remarks
  82. This class defines the low-level program in assembler code, the sort used to
  83. directly assemble into machine instructions for the GPU to execute. By nature,
  84. this means that the assembler source is rendersystem specific, which is why this
  85. is an abstract class - real instances are created through the RenderSystem.
  86. If you wish to use higher level shading languages like HLSL and Cg, you need to
  87. use the HighLevelGpuProgram class instead.
  88. */
  89. class CM_EXPORT GpuProgram : public Resource
  90. {
  91. public:
  92. virtual ~GpuProgram();
  93. /**
  94. * @brief Performs GpuProgram initialization. Only callable from the render thread.
  95. */
  96. virtual void initialize_internal();
  97. /** Gets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
  98. virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
  99. /** Gets the assembler source for this program. */
  100. virtual const String& getSource(void) const { return mSource; }
  101. /// Get the program type
  102. virtual GpuProgramType getType(void) const { return mType; }
  103. virtual GpuProgramProfile getProfile() const { return mProfile; }
  104. virtual const String& getEntryPoint() const { return mEntryPoint; }
  105. /** Returns the GpuProgram which should be bound to the pipeline.
  106. @remarks
  107. This method is simply to allow some subclasses of GpuProgram to delegate
  108. the program which is bound to the pipeline to a delegate, if required. */
  109. virtual GpuProgram* getBindingDelegate(void) { return this; }
  110. /** Returns whether this program can be supported on the current renderer and hardware. */
  111. virtual bool isSupported(void) const;
  112. /** Sets whether this geometry program requires adjacency information
  113. from the input primitives.
  114. */
  115. virtual void setAdjacencyInfoRequired(bool r) { mNeedsAdjacencyInfo = r; }
  116. /** Returns whether this geometry program requires adjacency information
  117. from the input primitives.
  118. */
  119. virtual bool isAdjacencyInfoRequired(void) const { return mNeedsAdjacencyInfo; }
  120. /** Creates a new parameters object compatible with this program definition.
  121. @remarks
  122. It is recommended that you use this method of creating parameters objects
  123. rather than going direct to GpuProgramManager, because this method will
  124. populate any implementation-specific extras (like named parameters) where
  125. they are appropriate.
  126. */
  127. virtual GpuParamsPtr createParameters();
  128. /** Returns a string that specifies the language of the gpu programs as specified
  129. in a material script. ie: asm, cg, hlsl, glsl
  130. */
  131. virtual const String& getLanguage(void) const;
  132. protected:
  133. /// The type of the program
  134. GpuProgramType mType;
  135. /// Does this (geometry) program require adjacency information?
  136. bool mNeedsAdjacencyInfo;
  137. /// Name of the shader entry method
  138. String mEntryPoint;
  139. /// Shader profiler that we are targeting (e.g. vs_1_1, etc.). Make sure profile matches the type.
  140. GpuProgramProfile mProfile;
  141. /// The assembler source of the program (may be blank until file loaded)
  142. String mSource;
  143. /// Syntax code e.g. arbvp1, vs_2_0 etc
  144. String mSyntaxCode;
  145. /**
  146. * @brief Contains information about all parameters in a shader.
  147. */
  148. GpuParamDesc mParametersDesc;
  149. /**
  150. * @brief Initializes the gpu program. This must be called right after the program is
  151. * constructed. Called by GpuManager upon creation, so usually you don't want
  152. * to call this manually.
  153. *
  154. * @note Initialization is not done immediately, and is instead just scheduled on the
  155. * render thread. Unless called from render thread, in which case it is initialized
  156. * right away.
  157. */
  158. void initialize();
  159. /**
  160. * @copydoc Resource::destroy_internal.
  161. */
  162. virtual void destroy_internal();
  163. /** Internal method returns whether required capabilities for this program is supported.
  164. */
  165. bool isRequiredCapabilitiesSupported(void) const;
  166. /// @copydoc Resource::calculateSize
  167. size_t calculateSize(void) const { return 0; } // TODO
  168. void throwIfNotRenderThread() const;
  169. protected:
  170. friend class GpuProgramManager;
  171. GpuProgram(const String& source, const String& entryPoint, const String& language,
  172. GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired = false);
  173. /************************************************************************/
  174. /* SERIALIZATION */
  175. /************************************************************************/
  176. public:
  177. friend class GpuProgramRTTI;
  178. static RTTITypeBase* getRTTIStatic();
  179. virtual RTTITypeBase* getRTTI() const;
  180. };
  181. /** @} */
  182. }
  183. #endif