CmGpuProgram.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmDrawOps.h"
  4. #include "CmGpuProgramParams.h"
  5. #include "CmResource.h"
  6. #include "CmGpuParamDesc.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Types of programs that may run on GPU.
  11. */
  12. enum GpuProgramType
  13. {
  14. GPT_VERTEX_PROGRAM,
  15. GPT_FRAGMENT_PROGRAM,
  16. GPT_GEOMETRY_PROGRAM,
  17. GPT_DOMAIN_PROGRAM,
  18. GPT_HULL_PROGRAM,
  19. GPT_COMPUTE_PROGRAM
  20. };
  21. /**
  22. * @brief GPU program profiles representing supported
  23. * feature sets.
  24. */
  25. enum GpuProgramProfile
  26. {
  27. GPP_NONE,
  28. GPP_PS_1_1,
  29. GPP_PS_1_2,
  30. GPP_PS_1_3,
  31. GPP_PS_1_4,
  32. GPP_PS_2_0,
  33. GPP_PS_2_x,
  34. GPP_PS_2_a,
  35. GPP_PS_2_b,
  36. GPP_PS_3_0,
  37. GPP_PS_3_x,
  38. GPP_PS_4_0,
  39. GPP_PS_4_1,
  40. GPP_PS_5_0,
  41. GPP_VS_1_1,
  42. GPP_VS_2_0,
  43. GPP_VS_2_x,
  44. GPP_VS_2_a,
  45. GPP_VS_3_0,
  46. GPP_VS_4_0,
  47. GPP_VS_4_1,
  48. GPP_VS_5_0,
  49. GPP_GS_4_0,
  50. GPP_GS_4_1,
  51. GPP_GS_5_0,
  52. GPP_HS_5_0,
  53. GPP_DS_5_0,
  54. GPP_CS_5_0
  55. };
  56. /**
  57. * @brief Contains a low level GPU program such as vertex or fragment program.
  58. * Internal implementation of this class is render system specific,
  59. * but will normally store a compiled program.
  60. *
  61. * @note For higher level programs see HighLevelGpuProgram.
  62. * Core thread only.
  63. */
  64. class CM_EXPORT GpuProgram : public Resource
  65. {
  66. public:
  67. virtual ~GpuProgram();
  68. /**
  69. * @brief Source used for creating this program.
  70. */
  71. virtual const String& getSource() const { return mSource; }
  72. /**
  73. * @brief Type of GPU program (e.g. fragment, vertex)
  74. */
  75. virtual GpuProgramType getType() const { return mType; }
  76. /**
  77. * @brief Profile of the GPU program (e.g. VS_4_0, VS_5_0)
  78. */
  79. virtual GpuProgramProfile getProfile() const { return mProfile; }
  80. /**
  81. * @brief Name of the program entry method (e.g. "main")
  82. */
  83. virtual const String& getEntryPoint() const { return mEntryPoint; }
  84. /**
  85. * @brief Returns a delegate that will be used for actually binding the program to the pipeline.
  86. */
  87. virtual GpuProgramPtr getBindingDelegate() { return std::static_pointer_cast<GpuProgram>(getThisPtr()); }
  88. /**
  89. * @brief Returns whether this program can be supported on the current renderer and hardware.
  90. */
  91. virtual bool isSupported() const;
  92. /**
  93. * @brief Sets whether this geometry program requires adjacency information
  94. * from the input primitives.
  95. *
  96. * @note Only relevant for geometry programs.
  97. */
  98. virtual void setAdjacencyInfoRequired(bool required) { mNeedsAdjacencyInfo = required; }
  99. /**
  100. * @brief Returns whether this geometry program requires adjacency information
  101. * from the input primitives.
  102. *
  103. * @note Only relevant for geometry programs.
  104. */
  105. virtual bool isAdjacencyInfoRequired(void) const { return mNeedsAdjacencyInfo; }
  106. /**
  107. * @brief Creates a new parameters object compatible with this program definition. You
  108. * may populate the returned object with actual parameter values and bind it
  109. * to the pipeline to render an object using those values and this program.
  110. */
  111. virtual GpuParamsPtr createParameters();
  112. /**
  113. * @brief Returns description of all parameters in this GPU program.
  114. */
  115. const GpuParamDesc& getParamDesc() const { return mParametersDesc; }
  116. /**
  117. * @brief Language this shader was created from (e.g. HLSL, GLSL).
  118. */
  119. virtual const String& getLanguage() const;
  120. protected:
  121. friend class GpuProgramManager;
  122. GpuProgram(const String& source, const String& entryPoint,
  123. GpuProgramType gptype, GpuProgramProfile profile, const Vector<HGpuProgInclude>* includes,
  124. bool isAdjacencyInfoRequired = false);
  125. /**
  126. * @brief Returns whether required capabilities for this program is supported.
  127. */
  128. bool isRequiredCapabilitiesSupported(void) const;
  129. /**
  130. * @copydoc Resource::calculateSize
  131. */
  132. size_t calculateSize(void) const { return 0; } // TODO
  133. protected:
  134. GpuProgramType mType;
  135. bool mNeedsAdjacencyInfo;
  136. String mEntryPoint;
  137. GpuProgramProfile mProfile;
  138. String mSource;
  139. GpuParamDesc mParametersDesc;
  140. /************************************************************************/
  141. /* SERIALIZATION */
  142. /************************************************************************/
  143. public:
  144. friend class GpuProgramRTTI;
  145. static RTTITypeBase* getRTTIStatic();
  146. virtual RTTITypeBase* getRTTI() const;
  147. };
  148. }