RenderSurface.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Graphics/GraphicsDefs.h"
  24. #include "../Graphics/Viewport.h"
  25. namespace Urho3D
  26. {
  27. class Texture;
  28. /// %Color or depth-stencil surface that can be rendered into.
  29. class URHO3D_API RenderSurface : public RefCounted
  30. {
  31. friend class Texture2D;
  32. friend class Texture2DArray;
  33. friend class TextureCube;
  34. public:
  35. /// Construct with parent texture.
  36. explicit RenderSurface(Texture* parentTexture);
  37. /// Destruct.
  38. ~RenderSurface() override;
  39. /// Set number of viewports.
  40. /// @property
  41. void SetNumViewports(unsigned num);
  42. /// Set viewport.
  43. /// @property{set_viewports}
  44. void SetViewport(unsigned index, Viewport* viewport);
  45. /// Set viewport update mode. Default is to update when visible.
  46. /// @property
  47. void SetUpdateMode(RenderSurfaceUpdateMode mode);
  48. /// Set linked color rendertarget.
  49. /// @property
  50. void SetLinkedRenderTarget(RenderSurface* renderTarget);
  51. /// Set linked depth-stencil surface.
  52. /// @property
  53. void SetLinkedDepthStencil(RenderSurface* depthStencil);
  54. /// Queue manual update of the viewport(s).
  55. void QueueUpdate();
  56. /// Release surface.
  57. void Release();
  58. /// Mark the GPU resource destroyed on graphics context destruction. Only used on OpenGL.
  59. void OnDeviceLost();
  60. /// Create renderbuffer that cannot be sampled as a texture. Only used on OpenGL.
  61. bool CreateRenderBuffer(unsigned width, unsigned height, unsigned format, int multiSample);
  62. /// Return width.
  63. /// @property
  64. int GetWidth() const;
  65. /// Return height.
  66. /// @property
  67. int GetHeight() const;
  68. /// Return usage.
  69. /// @property
  70. TextureUsage GetUsage() const;
  71. /// Return multisampling level.
  72. int GetMultiSample() const;
  73. /// Return multisampling autoresolve mode.
  74. bool GetAutoResolve() const;
  75. /// Return number of viewports.
  76. /// @property
  77. unsigned GetNumViewports() const { return viewports_.Size(); }
  78. /// Return viewport by index.
  79. /// @property{get_viewports}
  80. Viewport* GetViewport(unsigned index) const;
  81. /// Return viewport update mode.
  82. /// @property
  83. RenderSurfaceUpdateMode GetUpdateMode() const { return updateMode_; }
  84. /// Return linked color rendertarget.
  85. /// @property
  86. RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
  87. /// Return linked depth-stencil surface.
  88. /// @property
  89. RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
  90. /// Return whether manual update queued. Called internally.
  91. bool IsUpdateQueued() const { return updateQueued_; }
  92. /// Reset update queued flag. Called internally.
  93. void ResetUpdateQueued();
  94. /// Return parent texture.
  95. /// @property
  96. Texture* GetParentTexture() const { return parentTexture_; }
  97. /// Return Direct3D9 surface.
  98. void* GetSurface() const { return surface_; }
  99. /// Return Direct3D11 rendertarget or depth-stencil view. Not valid on OpenGL.
  100. void* GetRenderTargetView() const { return renderTargetView_; }
  101. /// Return Direct3D11 read-only depth-stencil view. May be null if not applicable. Not valid on OpenGL.
  102. void* GetReadOnlyView() const { return readOnlyView_; }
  103. /// Return surface's OpenGL target.
  104. unsigned GetTarget() const { return target_; }
  105. /// Return OpenGL renderbuffer if created.
  106. unsigned GetRenderBuffer() const { return renderBuffer_; }
  107. /// Return whether multisampled rendertarget needs resolve.
  108. /// @property
  109. bool IsResolveDirty() const { return resolveDirty_; }
  110. /// Set or clear the need resolve flag. Called internally by Graphics.
  111. void SetResolveDirty(bool enable) { resolveDirty_ = enable; }
  112. private:
  113. /// Parent texture.
  114. Texture* parentTexture_;
  115. // https://github.com/doxygen/doxygen/issues/7623
  116. union
  117. {
  118. /// Direct3D9 surface.
  119. /// @nobind
  120. void* surface_;
  121. /// Direct3D11 rendertarget or depth-stencil view.
  122. /// @nobind
  123. void* renderTargetView_;
  124. /// OpenGL renderbuffer name.
  125. /// @nobind
  126. unsigned renderBuffer_;
  127. };
  128. // https://github.com/doxygen/doxygen/issues/7623
  129. union
  130. {
  131. /// Direct3D11 read-only depth-stencil view. Present only on depth-stencil surfaces.
  132. /// @nobind
  133. void* readOnlyView_;
  134. /// OpenGL target.
  135. /// @nobind
  136. unsigned target_;
  137. };
  138. /// Viewports.
  139. Vector<SharedPtr<Viewport> > viewports_;
  140. /// Linked color buffer.
  141. WeakPtr<RenderSurface> linkedRenderTarget_;
  142. /// Linked depth buffer.
  143. WeakPtr<RenderSurface> linkedDepthStencil_;
  144. /// Update mode for viewports.
  145. RenderSurfaceUpdateMode updateMode_{SURFACE_UPDATEVISIBLE};
  146. /// Update queued flag.
  147. bool updateQueued_{};
  148. /// Multisampled resolve dirty flag.
  149. bool resolveDirty_{};
  150. };
  151. }