OGLRenderSurface.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "GraphicsDefs.h"
  25. #include "Rect.h"
  26. #include "Ptr.h"
  27. class Camera;
  28. class Scene;
  29. class Texture;
  30. /// %Viewport definition either for a render surface or the backbuffer.
  31. struct Viewport
  32. {
  33. /// Construct with defaults.
  34. Viewport();
  35. /// Construct with a full rectangle.
  36. Viewport(Scene* scene, Camera* camera);
  37. /// Construct with a specified rectangle.
  38. Viewport(Scene* scene, Camera* camera, const IntRect& rect);
  39. /// Scene pointer.
  40. WeakPtr<Scene> scene_;
  41. /// Camera pointer.
  42. WeakPtr<Camera> camera_;
  43. /// Viewport rectangle.
  44. IntRect rect_;
  45. };
  46. /// %Color or depth stencil surface that can be rendered into.
  47. class RenderSurface : public RefCounted
  48. {
  49. friend class Texture2D;
  50. friend class TextureCube;
  51. public:
  52. /// Construct with parent texture and target.
  53. RenderSurface(Texture* parentTexture, unsigned target);
  54. /// Destruct.
  55. ~RenderSurface();
  56. /// Set viewport for auxiliary view rendering.
  57. void SetViewport(const Viewport& viewport);
  58. /// Set linked color buffer.
  59. void SetLinkedRenderTarget(RenderSurface* renderTarget);
  60. /// Set linked depth buffer.
  61. void SetLinkedDepthBuffer(RenderSurface* depthBuffer);
  62. /// Create a renderbuffer. Return true if successful.
  63. bool CreateRenderBuffer(unsigned width, unsigned height, unsigned format);
  64. /// Release renderbuffer if any.
  65. void Release();
  66. /// Return parent texture.
  67. Texture* GetParentTexture() const { return parentTexture_; }
  68. /// Return surface's OpenGL target.
  69. unsigned GetTarget() const { return target_; }
  70. /// Return renderbuffer if created.
  71. unsigned GetRenderBuffer() const { return renderBuffer_; }
  72. /// Return width.
  73. int GetWidth() const;
  74. /// Return height.
  75. int GetHeight() const;
  76. /// Return usage.
  77. TextureUsage GetUsage() const;
  78. /// Return auxiliary view rendering viewport.
  79. const Viewport& GetViewport() const { return viewport_; }
  80. /// Return linked color buffer.
  81. RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
  82. /// Return linked depth buffer.
  83. RenderSurface* GetLinkedDepthBuffer() const { return linkedDepthBuffer_; }
  84. private:
  85. /// Parent texture.
  86. Texture* parentTexture_;
  87. /// OpenGL target.
  88. unsigned target_;
  89. /// OpenGL renderbuffer.
  90. unsigned renderBuffer_;
  91. /// Viewport.
  92. Viewport viewport_;
  93. /// Linked color buffer.
  94. WeakPtr<RenderSurface> linkedRenderTarget_;
  95. /// Linked depth buffer.
  96. WeakPtr<RenderSurface> linkedDepthBuffer_;
  97. };