BsGpuProgram.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "BsGpuProgram.h"
  2. #include "BsVector3.h"
  3. #include "BsVector4.h"
  4. #include "BsRenderAPICapabilities.h"
  5. #include "BsException.h"
  6. #include "BsRenderAPI.h"
  7. #include "BsAsyncOp.h"
  8. #include "BsGpuParams.h"
  9. #include "BsGpuProgramManager.h"
  10. #include "BsResources.h"
  11. #include "BsGpuProgramRTTI.h"
  12. namespace BansheeEngine
  13. {
  14. GpuProgramProperties::GpuProgramProperties(const String& source, const String& entryPoint,
  15. GpuProgramType gptype, GpuProgramProfile profile)
  16. :mSource(source), mEntryPoint(entryPoint), mType(gptype), mProfile(profile)
  17. { }
  18. GpuProgramCore::GpuProgramCore(const String& source, const String& entryPoint,
  19. GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired)
  20. : mProperties(source, entryPoint, gptype, profile), mIsCompiled(false),
  21. mNeedsAdjacencyInfo(isAdjacencyInfoRequired)
  22. {
  23. mParametersDesc = bs_shared_ptr_new<GpuParamDesc>();
  24. }
  25. bool GpuProgramCore::isSupported() const
  26. {
  27. if (!isRequiredCapabilitiesSupported())
  28. return false;
  29. RenderAPICore* rs = BansheeEngine::RenderAPICore::instancePtr();
  30. String profile = rs->getCapabilities()->gpuProgProfileToRSSpecificProfile(getProperties().getProfile());
  31. return rs->getCapabilities()->isShaderProfileSupported(profile);
  32. }
  33. bool GpuProgramCore::isRequiredCapabilitiesSupported() const
  34. {
  35. return true;
  36. }
  37. SPtr<GpuParamsCore> GpuProgramCore::createParameters()
  38. {
  39. return GpuParamsCore::create(mParametersDesc, hasColumnMajorMatrices());
  40. }
  41. SPtr<GpuProgramCore> GpuProgramCore::create(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype,
  42. GpuProgramProfile profile, bool requiresAdjacency)
  43. {
  44. return GpuProgramCoreManager::instance().create(source, entryPoint, language, gptype, profile, requiresAdjacency);
  45. }
  46. GpuProgram::GpuProgram(const String& source, const String& entryPoint, const String& language,
  47. GpuProgramType gptype, GpuProgramProfile profile, bool isAdjacencyInfoRequired)
  48. : mProperties(source, entryPoint, gptype, profile), mLanguage(language),
  49. mNeedsAdjacencyInfo(isAdjacencyInfoRequired)
  50. {
  51. }
  52. bool GpuProgram::isCompiled() const
  53. {
  54. return getCore()->isCompiled();
  55. }
  56. String GpuProgram::getCompileErrorMessage() const
  57. {
  58. return getCore()->getCompileErrorMessage();
  59. }
  60. GpuParamsPtr GpuProgram::createParameters()
  61. {
  62. return GpuParams::create(getCore()->getParamDesc(), getCore()->hasColumnMajorMatrices());
  63. }
  64. GpuParamDescPtr GpuProgram::getParamDesc() const
  65. {
  66. return getCore()->getParamDesc();
  67. }
  68. SPtr<GpuProgramCore> GpuProgram::getCore() const
  69. {
  70. return std::static_pointer_cast<GpuProgramCore>(mCoreSpecific);
  71. }
  72. SPtr<CoreObjectCore> GpuProgram::createCore() const
  73. {
  74. return GpuProgramCoreManager::instance().createInternal(mProperties.getSource(), mProperties.getEntryPoint(),
  75. mLanguage, mProperties.getType(), mProperties.getProfile(), mNeedsAdjacencyInfo);
  76. }
  77. GpuProgramPtr GpuProgram::create(const String& source, const String& entryPoint, const String& language, GpuProgramType gptype,
  78. GpuProgramProfile profile, bool requiresAdjacency)
  79. {
  80. return GpuProgramManager::instance().create(source, entryPoint, language, gptype, profile, requiresAdjacency);
  81. }
  82. /************************************************************************/
  83. /* SERIALIZATION */
  84. /************************************************************************/
  85. RTTITypeBase* GpuProgram::getRTTIStatic()
  86. {
  87. return GpuProgramRTTI::instance();
  88. }
  89. RTTITypeBase* GpuProgram::getRTTI() const
  90. {
  91. return GpuProgram::getRTTIStatic();
  92. }
  93. }