BsGpuProgram.cpp 3.8 KB

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