BsGpuProgram.cpp 3.9 KB

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