RenderSurface.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // Copyright (c) 2008-2017 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 Atomic
  26. {
  27. class Texture;
  28. /// %Color or depth-stencil surface that can be rendered into.
  29. class ATOMIC_API RenderSurface : public RefCounted
  30. {
  31. friend class Texture2D;
  32. friend class Texture2DArray;
  33. friend class TextureCube;
  34. ATOMIC_REFCOUNTED(RenderSurface)
  35. public:
  36. /// Construct with parent texture.
  37. RenderSurface(Texture* parentTexture);
  38. /// Destruct.
  39. ~RenderSurface();
  40. /// Set number of viewports.
  41. void SetNumViewports(unsigned num);
  42. /// Set viewport.
  43. void SetViewport(unsigned index, Viewport* viewport);
  44. /// Set viewport update mode. Default is to update when visible.
  45. void SetUpdateMode(RenderSurfaceUpdateMode mode);
  46. /// Set linked color rendertarget.
  47. void SetLinkedRenderTarget(RenderSurface* renderTarget);
  48. /// Set linked depth-stencil surface.
  49. void SetLinkedDepthStencil(RenderSurface* depthStencil);
  50. /// Queue manual update of the viewport(s).
  51. void QueueUpdate();
  52. /// Release surface.
  53. void Release();
  54. /// Mark the GPU resource destroyed on graphics context destruction. Only used on OpenGL.
  55. void OnDeviceLost();
  56. /// Create renderbuffer that cannot be sampled as a texture. Only used on OpenGL.
  57. bool CreateRenderBuffer(unsigned width, unsigned height, unsigned format, int multiSample);
  58. /// Return width.
  59. int GetWidth() const;
  60. /// Return height.
  61. int GetHeight() const;
  62. /// Return usage.
  63. TextureUsage GetUsage() const;
  64. /// Return multisampling level.
  65. int GetMultiSample() const;
  66. /// Return multisampling autoresolve mode.
  67. bool GetAutoResolve() const;
  68. /// Return number of viewports.
  69. unsigned GetNumViewports() const { return viewports_.Size(); }
  70. /// Return viewport by index.
  71. Viewport* GetViewport(unsigned index) const;
  72. /// Return viewport update mode.
  73. RenderSurfaceUpdateMode GetUpdateMode() const { return updateMode_; }
  74. /// Return linked color rendertarget.
  75. RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
  76. /// Return linked depth-stencil surface.
  77. RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
  78. /// Return whether manual update queued. Called internally.
  79. bool IsUpdateQueued() const { return updateQueued_; }
  80. /// Reset update queued flag. Called internally.
  81. void ResetUpdateQueued();
  82. /// Return parent texture.
  83. Texture* GetParentTexture() const { return parentTexture_; }
  84. /// Return Direct3D9 surface.
  85. void* GetSurface() const { return surface_; }
  86. /// Return Direct3D11 rendertarget or depth-stencil view. Not valid on OpenGL.
  87. void* GetRenderTargetView() const { return renderTargetView_; }
  88. /// Return Direct3D11 read-only depth-stencil view. May be null if not applicable. Not valid on OpenGL.
  89. void* GetReadOnlyView() const { return readOnlyView_; }
  90. /// Return surface's OpenGL target.
  91. unsigned GetTarget() const { return target_; }
  92. /// Return OpenGL renderbuffer if created.
  93. unsigned GetRenderBuffer() const { return renderBuffer_; }
  94. /// Return whether multisampled rendertarget needs resolve.
  95. bool IsResolveDirty() const { return resolveDirty_; }
  96. /// Set or clear the need resolve flag. Called internally by Graphics.
  97. void SetResolveDirty(bool enable) { resolveDirty_ = enable; }
  98. private:
  99. // ATOMIC BEGIN
  100. /// ATOMIC: changing to WeakPtr to prevent double release when parentTexture is deleted first
  101. /// Parent texture.
  102. WeakPtr<Texture> parentTexture_;
  103. // ATOMIC_END
  104. union
  105. {
  106. /// Direct3D9 surface.
  107. void* surface_;
  108. /// Direct3D11 rendertarget or depth-stencil view.
  109. void* renderTargetView_;
  110. /// OpenGL renderbuffer name.
  111. unsigned renderBuffer_;
  112. };
  113. union
  114. {
  115. /// Direct3D11 read-only depth-stencil view. Present only on depth-stencil surfaces.
  116. void* readOnlyView_;
  117. /// OpenGL target.
  118. unsigned target_;
  119. };
  120. /// Viewports.
  121. Vector<SharedPtr<Viewport> > viewports_;
  122. /// Linked color buffer.
  123. WeakPtr<RenderSurface> linkedRenderTarget_;
  124. /// Linked depth buffer.
  125. WeakPtr<RenderSurface> linkedDepthStencil_;
  126. /// Update mode for viewports.
  127. RenderSurfaceUpdateMode updateMode_;
  128. /// Update queued flag.
  129. bool updateQueued_;
  130. /// Multisampled resolve dirty flag.
  131. bool resolveDirty_;
  132. };
  133. }