CmGpuProgram.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 "CmRenderOpMesh.h"
  29. #include "CmGpuProgramParams.h"
  30. #include "CmResource.h"
  31. #include "CmGpuParamDesc.h"
  32. namespace CamelotFramework {
  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. /** Gets the syntax code for this program e.g. arbvp1, fp20, vs_1_1 etc */
  94. virtual const String& getSyntaxCode(void) const { return mSyntaxCode; }
  95. /** Gets the assembler source for this program. */
  96. virtual const String& getSource(void) const { return mSource; }
  97. /// Get the program type
  98. virtual GpuProgramType getType(void) const { return mType; }
  99. virtual GpuProgramProfile getProfile() const { return mProfile; }
  100. virtual const String& getEntryPoint() const { return mEntryPoint; }
  101. /** Returns the GpuProgram which should be bound to the pipeline.
  102. @remarks
  103. This method is simply to allow some subclasses of GpuProgram to delegate
  104. the program which is bound to the pipeline to a delegate, if required. */
  105. virtual GpuProgramPtr getBindingDelegate(void) { return std::static_pointer_cast<GpuProgram>(getThisPtr()); }
  106. /** Returns whether this program can be supported on the current renderer and hardware. */
  107. virtual bool isSupported(void) const;
  108. /** Sets whether this geometry program requires adjacency information
  109. from the input primitives.
  110. */
  111. virtual void setAdjacencyInfoRequired(bool r) { mNeedsAdjacencyInfo = r; }
  112. /** Returns whether this geometry program requires adjacency information
  113. from the input primitives.
  114. */
  115. virtual bool isAdjacencyInfoRequired(void) const { return mNeedsAdjacencyInfo; }
  116. /** Creates a new parameters object compatible with this program definition.
  117. @remarks
  118. It is recommended that you use this method of creating parameters objects
  119. rather than going direct to GpuProgramManager, because this method will
  120. populate any implementation-specific extras (like named parameters) where
  121. they are appropriate.
  122. */
  123. virtual GpuParamsPtr createParameters();
  124. const GpuParamDesc& getParamDesc() const { return mParametersDesc; }
  125. /** Returns a string that specifies the language of the gpu programs as specified
  126. in a material script. ie: asm, cg, hlsl, glsl
  127. */
  128. virtual const String& getLanguage(void) const;
  129. protected:
  130. friend class GpuProgramManager;
  131. GpuProgram(const String& source, const String& entryPoint, const String& language,
  132. GpuProgramType gptype, GpuProgramProfile profile, const Vector<HGpuProgInclude>::type* includes,
  133. bool isAdjacencyInfoRequired = false);
  134. /** Internal method returns whether required capabilities for this program is supported.
  135. */
  136. bool isRequiredCapabilitiesSupported(void) const;
  137. /// @copydoc Resource::calculateSize
  138. size_t calculateSize(void) const { return 0; } // TODO
  139. protected:
  140. /// The type of the program
  141. GpuProgramType mType;
  142. /// Does this (geometry) program require adjacency information?
  143. bool mNeedsAdjacencyInfo;
  144. /// Name of the shader entry method
  145. String mEntryPoint;
  146. /// Shader profiler that we are targeting (e.g. vs_1_1, etc.). Make sure profile matches the type.
  147. GpuProgramProfile mProfile;
  148. /// The assembler source of the program (may be blank until file loaded)
  149. String mSource;
  150. /// Syntax code e.g. arbvp1, vs_2_0 etc
  151. String mSyntaxCode;
  152. /**
  153. * @brief Contains information about all parameters in a shader.
  154. */
  155. GpuParamDesc mParametersDesc;
  156. /************************************************************************/
  157. /* SERIALIZATION */
  158. /************************************************************************/
  159. public:
  160. friend class GpuProgramRTTI;
  161. static RTTITypeBase* getRTTIStatic();
  162. virtual RTTITypeBase* getRTTI() const;
  163. };
  164. /** @} */
  165. }
  166. #endif