ShaderVariation.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright (c) 2008-2022 the Urho3D project
  2. // License: MIT
  3. #include "../Precompiled.h"
  4. #include "../Graphics/Graphics.h"
  5. #include "../GraphicsAPI/Shader.h"
  6. #include "../GraphicsAPI/ShaderVariation.h"
  7. #include "../DebugNew.h"
  8. namespace Urho3D
  9. {
  10. ShaderParameter::ShaderParameter(const String& name, unsigned glType, int location) : // NOLINT(hicpp-member-init)
  11. name_{name},
  12. glType_{glType},
  13. location_{location}
  14. {
  15. }
  16. ShaderParameter::ShaderParameter(ShaderType type, const String& name, unsigned offset, unsigned size, unsigned buffer) : // NOLINT(hicpp-member-init)
  17. type_{type},
  18. name_{name},
  19. offset_{offset},
  20. size_{size},
  21. buffer_{buffer}
  22. {
  23. }
  24. ShaderParameter::ShaderParameter(ShaderType type, const String& name, unsigned reg, unsigned regCount) : // NOLINT(hicpp-member-init)
  25. type_{type},
  26. name_{name},
  27. register_{reg},
  28. regCount_{regCount}
  29. {
  30. }
  31. ShaderVariation::ShaderVariation(Shader* owner, ShaderType type) :
  32. GPUObject(owner->GetSubsystem<Graphics>()),
  33. owner_(owner),
  34. type_(type)
  35. {
  36. }
  37. ShaderVariation::~ShaderVariation()
  38. {
  39. Release();
  40. }
  41. void ShaderVariation::SetName(const String& name)
  42. {
  43. name_ = name;
  44. }
  45. Shader* ShaderVariation::GetOwner() const
  46. {
  47. return owner_;
  48. }
  49. void ShaderVariation::OnDeviceLost()
  50. {
  51. GAPI gapi = Graphics::GetGAPI();
  52. #ifdef URHO3D_OPENGL
  53. if (gapi == GAPI_OPENGL)
  54. return OnDeviceLost_OGL();
  55. #endif
  56. #ifdef URHO3D_D3D9
  57. if (gapi == GAPI_D3D9)
  58. return OnDeviceLost_D3D9();
  59. #endif
  60. #ifdef URHO3D_D3D11
  61. if (gapi == GAPI_D3D11)
  62. return OnDeviceLost_D3D11();
  63. #endif
  64. }
  65. void ShaderVariation::Release()
  66. {
  67. GAPI gapi = Graphics::GetGAPI();
  68. #ifdef URHO3D_OPENGL
  69. if (gapi == GAPI_OPENGL)
  70. return Release_OGL();
  71. #endif
  72. #ifdef URHO3D_D3D9
  73. if (gapi == GAPI_D3D9)
  74. return Release_D3D9();
  75. #endif
  76. #ifdef URHO3D_D3D11
  77. if (gapi == GAPI_D3D11)
  78. return Release_D3D11();
  79. #endif
  80. }
  81. bool ShaderVariation::Create()
  82. {
  83. GAPI gapi = Graphics::GetGAPI();
  84. #ifdef URHO3D_OPENGL
  85. if (gapi == GAPI_OPENGL)
  86. return Create_OGL();
  87. #endif
  88. #ifdef URHO3D_D3D9
  89. if (gapi == GAPI_D3D9)
  90. return Create_D3D9();
  91. #endif
  92. #ifdef URHO3D_D3D11
  93. if (gapi == GAPI_D3D11)
  94. return Create_D3D11();
  95. #endif
  96. return {}; // Prevent warning
  97. }
  98. void ShaderVariation::SetDefines(const String& defines)
  99. {
  100. GAPI gapi = Graphics::GetGAPI();
  101. #ifdef URHO3D_OPENGL
  102. if (gapi == GAPI_OPENGL)
  103. return SetDefines_OGL(defines);
  104. #endif
  105. #ifdef URHO3D_D3D9
  106. if (gapi == GAPI_D3D9)
  107. return SetDefines_D3D9(defines);
  108. #endif
  109. #ifdef URHO3D_D3D11
  110. if (gapi == GAPI_D3D11)
  111. return SetDefines_D3D11(defines);
  112. #endif
  113. }
  114. }