RenderSurface.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Graphics/Viewport.h"
  5. #include "../GraphicsAPI/GraphicsDefs.h"
  6. namespace Urho3D
  7. {
  8. class Texture;
  9. /// %Color or depth-stencil surface that can be rendered into.
  10. class URHO3D_API RenderSurface : public RefCounted
  11. {
  12. friend class Texture2D;
  13. friend class Texture2DArray;
  14. friend class TextureCube;
  15. public:
  16. /// Construct with parent texture.
  17. explicit RenderSurface(Texture* parentTexture);
  18. /// Destruct.
  19. ~RenderSurface() override;
  20. /// Set number of viewports.
  21. /// @property
  22. void SetNumViewports(unsigned num);
  23. /// Set viewport.
  24. /// @property{set_viewports}
  25. void SetViewport(unsigned index, Viewport* viewport);
  26. /// Set viewport update mode. Default is to update when visible.
  27. /// @property
  28. void SetUpdateMode(RenderSurfaceUpdateMode mode);
  29. /// Set linked color rendertarget.
  30. /// @property
  31. void SetLinkedRenderTarget(RenderSurface* renderTarget);
  32. /// Set linked depth-stencil surface.
  33. /// @property
  34. void SetLinkedDepthStencil(RenderSurface* depthStencil);
  35. /// Queue manual update of the viewport(s).
  36. void QueueUpdate();
  37. /// Release surface.
  38. void Release();
  39. /// Mark the GPU resource destroyed on graphics context destruction. Only used on OpenGL.
  40. void OnDeviceLost();
  41. /// Create renderbuffer that cannot be sampled as a texture. Only used on OpenGL.
  42. bool CreateRenderBuffer(unsigned width, unsigned height, unsigned format, int multiSample);
  43. /// Return width.
  44. /// @property
  45. int GetWidth() const;
  46. /// Return height.
  47. /// @property
  48. int GetHeight() const;
  49. /// Return usage.
  50. /// @property
  51. TextureUsage GetUsage() const;
  52. /// Return multisampling level.
  53. int GetMultiSample() const;
  54. /// Return multisampling autoresolve mode.
  55. bool GetAutoResolve() const;
  56. /// Return number of viewports.
  57. /// @property
  58. unsigned GetNumViewports() const { return viewports_.Size(); }
  59. /// Return viewport by index.
  60. /// @property{get_viewports}
  61. Viewport* GetViewport(unsigned index) const;
  62. /// Return viewport update mode.
  63. /// @property
  64. RenderSurfaceUpdateMode GetUpdateMode() const { return updateMode_; }
  65. /// Return linked color rendertarget.
  66. /// @property
  67. RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
  68. /// Return linked depth-stencil surface.
  69. /// @property
  70. RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
  71. /// Return whether manual update queued. Called internally.
  72. bool IsUpdateQueued() const { return updateQueued_; }
  73. /// Reset update queued flag. Called internally.
  74. void ResetUpdateQueued();
  75. /// Return parent texture.
  76. /// @property
  77. Texture* GetParentTexture() const { return parentTexture_; }
  78. /// Return Direct3D9 surface.
  79. void* GetSurface() const { return surface_; }
  80. /// Return Direct3D11 rendertarget or depth-stencil view. Not valid on OpenGL.
  81. void* GetRenderTargetView() const { return renderTargetView_; }
  82. /// Return Direct3D11 read-only depth-stencil view. May be null if not applicable. Not valid on OpenGL.
  83. void* GetReadOnlyView() const { return readOnlyView_; }
  84. /// Return surface's OpenGL target.
  85. unsigned GetTarget() const { return target_; }
  86. /// Return OpenGL renderbuffer if created.
  87. unsigned GetRenderBuffer() const { return renderBuffer_; }
  88. /// Return whether multisampled rendertarget needs resolve.
  89. /// @property
  90. bool IsResolveDirty() const { return resolveDirty_; }
  91. /// Set or clear the need resolve flag. Called internally by Graphics.
  92. void SetResolveDirty(bool enable) { resolveDirty_ = enable; }
  93. private:
  94. #ifdef URHO3D_OPENGL
  95. void Constructor_OGL(Texture* parentTexture);
  96. bool CreateRenderBuffer_OGL(unsigned width, unsigned height, unsigned format, int multiSample);
  97. void OnDeviceLost_OGL();
  98. void Release_OGL();
  99. #endif // def URHO3D_OPENGL
  100. #ifdef URHO3D_D3D11
  101. void Constructor_D3D11(Texture* parentTexture);
  102. bool CreateRenderBuffer_D3D11(unsigned width, unsigned height, unsigned format, int multiSample);
  103. void OnDeviceLost_D3D11();
  104. void Release_D3D11();
  105. #endif // def URHO3D_D3D11
  106. /// Parent texture.
  107. Texture* parentTexture_;
  108. // https://github.com/doxygen/doxygen/issues/7623
  109. union
  110. {
  111. /// Direct3D9 surface.
  112. /// @nobind
  113. void* surface_;
  114. /// Direct3D11 rendertarget or depth-stencil view.
  115. /// @nobind
  116. void* renderTargetView_;
  117. /// OpenGL renderbuffer name.
  118. /// @nobind
  119. unsigned renderBuffer_;
  120. };
  121. // https://github.com/doxygen/doxygen/issues/7623
  122. union
  123. {
  124. /// Direct3D11 read-only depth-stencil view. Present only on depth-stencil surfaces.
  125. /// @nobind
  126. void* readOnlyView_;
  127. /// OpenGL target.
  128. /// @nobind
  129. unsigned target_;
  130. };
  131. /// Viewports.
  132. Vector<SharedPtr<Viewport>> viewports_;
  133. /// Linked color buffer.
  134. WeakPtr<RenderSurface> linkedRenderTarget_;
  135. /// Linked depth buffer.
  136. WeakPtr<RenderSurface> linkedDepthStencil_;
  137. /// Update mode for viewports.
  138. RenderSurfaceUpdateMode updateMode_{SURFACE_UPDATEVISIBLE};
  139. /// Update queued flag.
  140. bool updateQueued_{};
  141. /// Multisampled resolve dirty flag.
  142. bool resolveDirty_{};
  143. };
  144. }