OGLRenderSurface.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // Copyright (c) 2008-2015 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 Camera;
  28. class Scene;
  29. class Texture;
  30. /// %Color or depth-stencil surface that can be rendered into.
  31. class ATOMIC_API RenderSurface : public RefCounted
  32. {
  33. friend class Texture2D;
  34. friend class TextureCube;
  35. REFCOUNTED(RenderSurface)
  36. public:
  37. /// Construct with parent texture.
  38. RenderSurface(Texture* parentTexture);
  39. /// Destruct.
  40. ~RenderSurface();
  41. /// Set number of viewports.
  42. void SetNumViewports(unsigned num);
  43. /// Set viewport.
  44. void SetViewport(unsigned index, Viewport* viewport);
  45. /// Set viewport update mode. Default is to update when visible.
  46. void SetUpdateMode(RenderSurfaceUpdateMode mode);
  47. /// Set linked color rendertarget.
  48. void SetLinkedRenderTarget(RenderSurface* renderTarget);
  49. /// Set linked depth-stencil surface.
  50. void SetLinkedDepthStencil(RenderSurface* depthStencil);
  51. /// Queue manual update of the viewport(s).
  52. void QueueUpdate();
  53. /// Create a renderbuffer. Return true if successful.
  54. bool CreateRenderBuffer(unsigned width, unsigned height, unsigned format);
  55. /// Handle device loss.
  56. void OnDeviceLost();
  57. /// Release renderbuffer if any.
  58. void Release();
  59. /// Return parent texture.
  60. Texture* GetParentTexture() const { return parentTexture_; }
  61. /// Return renderbuffer if created.
  62. unsigned GetRenderBuffer() const { return renderBuffer_; }
  63. /// Return width.
  64. int GetWidth() const;
  65. /// Return height.
  66. int GetHeight() const;
  67. /// Return usage.
  68. TextureUsage GetUsage() const;
  69. /// Return number of viewports.
  70. unsigned GetNumViewports() const { return viewports_.Size(); }
  71. /// Return viewport by index.
  72. Viewport* GetViewport(unsigned index) const;
  73. /// Return viewport update mode.
  74. RenderSurfaceUpdateMode GetUpdateMode() const { return updateMode_; }
  75. /// Return linked color buffer.
  76. RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
  77. /// Return linked depth buffer.
  78. RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
  79. /// Set surface's OpenGL target.
  80. void SetTarget(unsigned target);
  81. /// Return surface's OpenGL target.
  82. unsigned GetTarget() const { return target_; }
  83. /// Clear update flag. Called by Renderer.
  84. void WasUpdated();
  85. private:
  86. /// Parent texture.
  87. Texture* parentTexture_;
  88. /// OpenGL target.
  89. unsigned target_;
  90. /// OpenGL renderbuffer.
  91. unsigned renderBuffer_;
  92. /// Viewports.
  93. Vector<SharedPtr<Viewport> > viewports_;
  94. /// Linked color buffer.
  95. WeakPtr<RenderSurface> linkedRenderTarget_;
  96. /// Linked depth buffer.
  97. WeakPtr<RenderSurface> linkedDepthStencil_;
  98. /// Update mode for viewports.
  99. RenderSurfaceUpdateMode updateMode_;
  100. /// Update queued flag.
  101. bool updateQueued_;
  102. };
  103. }