OGLRenderSurface.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // Copyright (c) 2008-2014 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 "GraphicsDefs.h"
  24. #include "Viewport.h"
  25. namespace Urho3D
  26. {
  27. class Camera;
  28. class Scene;
  29. class Texture;
  30. /// %Color or depth-stencil surface that can be rendered into.
  31. class URHO3D_API RenderSurface : public RefCounted
  32. {
  33. friend class Texture2D;
  34. friend class TextureCube;
  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. /// Create a renderbuffer. Return true if successful.
  53. bool CreateRenderBuffer(unsigned width, unsigned height, unsigned format);
  54. /// Handle device loss.
  55. void OnDeviceLost();
  56. /// Release renderbuffer if any.
  57. void Release();
  58. /// Return parent texture.
  59. Texture* GetParentTexture() const { return parentTexture_; }
  60. /// Return renderbuffer if created.
  61. unsigned GetRenderBuffer() const { return renderBuffer_; }
  62. /// Return width.
  63. int GetWidth() const;
  64. /// Return height.
  65. int GetHeight() const;
  66. /// Return usage.
  67. TextureUsage GetUsage() 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 buffer.
  75. RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
  76. /// Return linked depth buffer.
  77. RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
  78. /// Set surface's OpenGL target.
  79. void SetTarget(unsigned target);
  80. /// Return surface's OpenGL target.
  81. unsigned GetTarget() const { return target_; }
  82. /// Clear update flag. Called by Renderer.
  83. void WasUpdated();
  84. private:
  85. /// Parent texture.
  86. Texture* parentTexture_;
  87. /// OpenGL target.
  88. unsigned target_;
  89. /// OpenGL renderbuffer.
  90. unsigned renderBuffer_;
  91. /// Viewports.
  92. Vector<SharedPtr<Viewport> > viewports_;
  93. /// Linked color buffer.
  94. WeakPtr<RenderSurface> linkedRenderTarget_;
  95. /// Linked depth buffer.
  96. WeakPtr<RenderSurface> linkedDepthStencil_;
  97. /// Update mode for viewports.
  98. RenderSurfaceUpdateMode updateMode_;
  99. /// Update queued flag.
  100. bool updateQueued_;
  101. };
  102. }