RenderSurface.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #include "../Precompiled.h"
  4. #include "../Graphics/Camera.h"
  5. #include "../Graphics/Graphics.h"
  6. #include "../Graphics/Renderer.h"
  7. #include "../GraphicsAPI/GraphicsImpl.h"
  8. #include "../GraphicsAPI/RenderSurface.h"
  9. #include "../GraphicsAPI/Texture.h"
  10. #include "../DebugNew.h"
  11. namespace Urho3D
  12. {
  13. RenderSurface::~RenderSurface()
  14. {
  15. Release();
  16. }
  17. void RenderSurface::SetNumViewports(unsigned num)
  18. {
  19. viewports_.Resize(num);
  20. }
  21. void RenderSurface::SetViewport(unsigned index, Viewport* viewport)
  22. {
  23. if (index >= viewports_.Size())
  24. viewports_.Resize(index + 1);
  25. viewports_[index] = viewport;
  26. }
  27. void RenderSurface::SetUpdateMode(RenderSurfaceUpdateMode mode)
  28. {
  29. updateMode_ = mode;
  30. }
  31. void RenderSurface::SetLinkedRenderTarget(RenderSurface* renderTarget)
  32. {
  33. if (renderTarget != this)
  34. linkedRenderTarget_ = renderTarget;
  35. }
  36. void RenderSurface::SetLinkedDepthStencil(RenderSurface* depthStencil)
  37. {
  38. if (depthStencil != this)
  39. linkedDepthStencil_ = depthStencil;
  40. }
  41. void RenderSurface::QueueUpdate()
  42. {
  43. updateQueued_ = true;
  44. }
  45. void RenderSurface::ResetUpdateQueued()
  46. {
  47. updateQueued_ = false;
  48. }
  49. int RenderSurface::GetWidth() const
  50. {
  51. return parentTexture_->GetWidth();
  52. }
  53. int RenderSurface::GetHeight() const
  54. {
  55. return parentTexture_->GetHeight();
  56. }
  57. TextureUsage RenderSurface::GetUsage() const
  58. {
  59. return parentTexture_->GetUsage();
  60. }
  61. int RenderSurface::GetMultiSample() const
  62. {
  63. return parentTexture_->GetMultiSample();
  64. }
  65. bool RenderSurface::GetAutoResolve() const
  66. {
  67. return parentTexture_->GetAutoResolve();
  68. }
  69. Viewport* RenderSurface::GetViewport(unsigned index) const
  70. {
  71. return index < viewports_.Size() ? viewports_[index] : nullptr;
  72. }
  73. RenderSurface::RenderSurface(Texture* parentTexture)
  74. {
  75. GAPI gapi = Graphics::GetGAPI();
  76. #ifdef URHO3D_OPENGL
  77. if (gapi == GAPI_OPENGL)
  78. {
  79. Constructor_OGL(parentTexture);
  80. return;
  81. }
  82. #endif
  83. #ifdef URHO3D_D3D11
  84. if (gapi == GAPI_D3D11)
  85. {
  86. Constructor_D3D11(parentTexture);
  87. return;
  88. }
  89. #endif
  90. }
  91. bool RenderSurface::CreateRenderBuffer(unsigned width, unsigned height, unsigned format, int multiSample)
  92. {
  93. GAPI gapi = Graphics::GetGAPI();
  94. #ifdef URHO3D_OPENGL
  95. if (gapi == GAPI_OPENGL)
  96. return CreateRenderBuffer_OGL(width, height, format, multiSample);
  97. #endif
  98. #ifdef URHO3D_D3D11
  99. if (gapi == GAPI_D3D11)
  100. return CreateRenderBuffer_D3D11(width, height, format, multiSample);
  101. #endif
  102. return {}; // Prevent warning
  103. }
  104. void RenderSurface::OnDeviceLost()
  105. {
  106. GAPI gapi = Graphics::GetGAPI();
  107. #ifdef URHO3D_OPENGL
  108. if (gapi == GAPI_OPENGL)
  109. return OnDeviceLost_OGL();
  110. #endif
  111. #ifdef URHO3D_D3D11
  112. if (gapi == GAPI_D3D11)
  113. return OnDeviceLost_D3D11();
  114. #endif
  115. }
  116. void RenderSurface::Release()
  117. {
  118. GAPI gapi = Graphics::GetGAPI();
  119. #ifdef URHO3D_OPENGL
  120. if (gapi == GAPI_OPENGL)
  121. return Release_OGL();
  122. #endif
  123. #ifdef URHO3D_D3D11
  124. if (gapi == GAPI_D3D11)
  125. return Release_D3D11();
  126. #endif
  127. }
  128. }