BsGpuProgram.cpp 3.6 KB

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