Browse Source

Remove API-specific RenderSurface class headers and RenderSurface code duplication.

Lasse Öörni 9 years ago
parent
commit
51b0a16f9a

+ 5 - 59
Source/Urho3D/Graphics/Direct3D11/D3D11RenderSurface.cpp

@@ -43,51 +43,6 @@ RenderSurface::RenderSurface(Texture* parentTexture) :
 {
 {
 }
 }
 
 
-RenderSurface::~RenderSurface()
-{
-    Release();
-}
-
-void RenderSurface::SetNumViewports(unsigned num)
-{
-    viewports_.Resize(num);
-}
-
-void RenderSurface::SetViewport(unsigned index, Viewport* viewport)
-{
-    if (index >= viewports_.Size())
-        viewports_.Resize(index + 1);
-
-    viewports_[index] = viewport;
-}
-
-void RenderSurface::SetUpdateMode(RenderSurfaceUpdateMode mode)
-{
-    updateMode_ = mode;
-}
-
-void RenderSurface::SetLinkedRenderTarget(RenderSurface* renderTarget)
-{
-    if (renderTarget != this)
-        linkedRenderTarget_ = renderTarget;
-}
-
-void RenderSurface::SetLinkedDepthStencil(RenderSurface* depthStencil)
-{
-    if (depthStencil != this)
-        linkedDepthStencil_ = depthStencil;
-}
-
-void RenderSurface::QueueUpdate()
-{
-    updateQueued_ = true;
-}
-
-void RenderSurface::ResetUpdateQueued()
-{
-    updateQueued_ = false;
-}
-
 void RenderSurface::Release()
 void RenderSurface::Release()
 {
 {
     Graphics* graphics = parentTexture_->GetGraphics();
     Graphics* graphics = parentTexture_->GetGraphics();
@@ -107,24 +62,15 @@ void RenderSurface::Release()
     URHO3D_SAFE_RELEASE(readOnlyView_);
     URHO3D_SAFE_RELEASE(readOnlyView_);
 }
 }
 
 
-int RenderSurface::GetWidth() const
-{
-    return parentTexture_->GetWidth();
-}
-
-int RenderSurface::GetHeight() const
-{
-    return parentTexture_->GetHeight();
-}
-
-TextureUsage RenderSurface::GetUsage() const
+bool RenderSurface::CreateRenderBuffer(unsigned width, unsigned height, unsigned format)
 {
 {
-    return parentTexture_->GetUsage();
+    // Not used on Direct3D
+    return false;
 }
 }
 
 
-Viewport* RenderSurface::GetViewport(unsigned index) const
+void RenderSurface::OnDeviceLost()
 {
 {
-    return index < viewports_.Size() ? viewports_[index] : (Viewport*)0;
+    // No-op on Direct3D
 }
 }
 
 
 }
 }

+ 0 - 116
Source/Urho3D/Graphics/Direct3D11/D3D11RenderSurface.h

@@ -1,116 +0,0 @@
-//
-// Copyright (c) 2008-2016 the Urho3D project.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-#pragma once
-
-#include "../../Graphics/GraphicsDefs.h"
-#include "../../Graphics/Viewport.h"
-
-namespace Urho3D
-{
-
-class Texture;
-
-/// %Color or depth-stencil surface that can be rendered into.
-class URHO3D_API RenderSurface : public RefCounted
-{
-    friend class Texture2D;
-    friend class Texture2DArray;
-    friend class TextureCube;
-
-public:
-    /// Construct with parent texture.
-    RenderSurface(Texture* parentTexture);
-    /// Destruct.
-    ~RenderSurface();
-
-    /// Set number of viewports.
-    void SetNumViewports(unsigned num);
-    /// Set viewport.
-    void SetViewport(unsigned index, Viewport* viewport);
-    /// Set viewport update mode. Default is to update when visible.
-    void SetUpdateMode(RenderSurfaceUpdateMode mode);
-    /// Set linked color rendertarget.
-    void SetLinkedRenderTarget(RenderSurface* renderTarget);
-    /// Set linked depth-stencil surface.
-    void SetLinkedDepthStencil(RenderSurface* depthStencil);
-    /// Queue manual update of the viewport(s).
-    void QueueUpdate();
-    /// Release surface.
-    void Release();
-
-    /// Return parent texture.
-    Texture* GetParentTexture() const { return parentTexture_; }
-
-    /// Return Direct3D rendertarget or depth-stencil view.
-    void* GetRenderTargetView() const { return renderTargetView_; }
-
-    /// Return Direct3D read-only depth-stencil view. May be null if not applicable
-    void* GetReadOnlyView() const { return readOnlyView_; }
-
-    /// Return width.
-    int GetWidth() const;
-    /// Return height.
-    int GetHeight() const;
-    /// Return usage.
-    TextureUsage GetUsage() const;
-
-    /// Return number of viewports.
-    unsigned GetNumViewports() const { return viewports_.Size(); }
-
-    /// Return viewport by index.
-    Viewport* GetViewport(unsigned index) const;
-
-    /// Return viewport update mode.
-    RenderSurfaceUpdateMode GetUpdateMode() const { return updateMode_; }
-
-    /// Return linked color rendertarget.
-    RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
-
-    /// Return linked depth-stencil surface.
-    RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
-
-    /// Return whether manual update queued. Called internally.
-    bool IsUpdateQueued() const { return updateQueued_; }
-    /// Reset update queued flag. Called internally.
-    void ResetUpdateQueued();
-
-private:
-    /// Parent texture.
-    Texture* parentTexture_;
-    /// Direct3D rendertarget or depth-stencil view.
-    void* renderTargetView_;
-    /// Direct3D read-only depth-stencil view. Present only on depth-stencil surfaces.
-    void* readOnlyView_;
-    /// Viewports.
-    Vector<SharedPtr<Viewport> > viewports_;
-    /// Linked color buffer.
-    WeakPtr<RenderSurface> linkedRenderTarget_;
-    /// Linked depth buffer.
-    WeakPtr<RenderSurface> linkedDepthStencil_;
-    /// Update mode for viewports.
-    RenderSurfaceUpdateMode updateMode_;
-    /// Update queued flag.
-    bool updateQueued_;
-};
-
-}

+ 5 - 59
Source/Urho3D/Graphics/Direct3D9/D3D9RenderSurface.cpp

@@ -42,51 +42,6 @@ RenderSurface::RenderSurface(Texture* parentTexture) :
 {
 {
 }
 }
 
 
-RenderSurface::~RenderSurface()
-{
-    Release();
-}
-
-void RenderSurface::SetNumViewports(unsigned num)
-{
-    viewports_.Resize(num);
-}
-
-void RenderSurface::SetViewport(unsigned index, Viewport* viewport)
-{
-    if (index >= viewports_.Size())
-        viewports_.Resize(index + 1);
-
-    viewports_[index] = viewport;
-}
-
-void RenderSurface::SetUpdateMode(RenderSurfaceUpdateMode mode)
-{
-    updateMode_ = mode;
-}
-
-void RenderSurface::SetLinkedRenderTarget(RenderSurface* renderTarget)
-{
-    if (renderTarget != this)
-        linkedRenderTarget_ = renderTarget;
-}
-
-void RenderSurface::SetLinkedDepthStencil(RenderSurface* depthStencil)
-{
-    if (depthStencil != this)
-        linkedDepthStencil_ = depthStencil;
-}
-
-void RenderSurface::QueueUpdate()
-{
-    updateQueued_ = true;
-}
-
-void RenderSurface::ResetUpdateQueued()
-{
-    updateQueued_ = false;
-}
-
 void RenderSurface::Release()
 void RenderSurface::Release()
 {
 {
     Graphics* graphics = parentTexture_->GetGraphics();
     Graphics* graphics = parentTexture_->GetGraphics();
@@ -105,24 +60,15 @@ void RenderSurface::Release()
     URHO3D_SAFE_RELEASE(surface_);
     URHO3D_SAFE_RELEASE(surface_);
 }
 }
 
 
-int RenderSurface::GetWidth() const
-{
-    return parentTexture_->GetWidth();
-}
-
-int RenderSurface::GetHeight() const
-{
-    return parentTexture_->GetHeight();
-}
-
-TextureUsage RenderSurface::GetUsage() const
+bool RenderSurface::CreateRenderBuffer(unsigned width, unsigned height, unsigned format)
 {
 {
-    return parentTexture_->GetUsage();
+    // Not used on Direct3D
+    return false;
 }
 }
 
 
-Viewport* RenderSurface::GetViewport(unsigned index) const
+void RenderSurface::OnDeviceLost()
 {
 {
-    return index < viewports_.Size() ? viewports_[index] : (Viewport*)0;
+    // No-op on Direct3D
 }
 }
 
 
 }
 }

+ 0 - 110
Source/Urho3D/Graphics/Direct3D9/D3D9RenderSurface.h

@@ -1,110 +0,0 @@
-//
-// Copyright (c) 2008-2016 the Urho3D project.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-#pragma once
-
-#include "../../Graphics/GraphicsDefs.h"
-#include "../../Graphics/Viewport.h"
-
-namespace Urho3D
-{
-
-class Texture;
-
-/// %Color or depth-stencil surface that can be rendered into.
-class URHO3D_API RenderSurface : public RefCounted
-{
-    friend class Texture2D;
-    friend class TextureCube;
-
-public:
-    /// Construct with parent texture.
-    RenderSurface(Texture* parentTexture);
-    /// Destruct.
-    ~RenderSurface();
-
-    /// Set number of viewports.
-    void SetNumViewports(unsigned num);
-    /// Set viewport.
-    void SetViewport(unsigned index, Viewport* viewport);
-    /// Set viewport update mode. Default is to update when visible.
-    void SetUpdateMode(RenderSurfaceUpdateMode mode);
-    /// Set linked color rendertarget.
-    void SetLinkedRenderTarget(RenderSurface* renderTarget);
-    /// Set linked depth-stencil surface.
-    void SetLinkedDepthStencil(RenderSurface* depthStencil);
-    /// Queue manual update of the viewport(s).
-    void QueueUpdate();
-    /// Release surface.
-    void Release();
-
-    /// Return parent texture.
-    Texture* GetParentTexture() const { return parentTexture_; }
-
-    /// Return Direct3D surface.
-    void* GetSurface() const { return surface_; }
-
-    /// Return width.
-    int GetWidth() const;
-    /// Return height.
-    int GetHeight() const;
-    /// Return usage.
-    TextureUsage GetUsage() const;
-
-    /// Return number of viewports.
-    unsigned GetNumViewports() const { return viewports_.Size(); }
-
-    /// Return viewport by index.
-    Viewport* GetViewport(unsigned index) const;
-
-    /// Return viewport update mode.
-    RenderSurfaceUpdateMode GetUpdateMode() const { return updateMode_; }
-
-    /// Return linked color rendertarget.
-    RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
-
-    /// Return linked depth-stencil surface.
-    RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
-
-    /// Return whether manual update queued. Called internally.
-    bool IsUpdateQueued() const { return updateQueued_; }
-    /// Reset update queued flag. Called internally.
-    void ResetUpdateQueued();
-
-private:
-    /// Parent texture.
-    Texture* parentTexture_;
-    /// Direct3D surface.
-    void* surface_;
-    /// Viewports.
-    Vector<SharedPtr<Viewport> > viewports_;
-    /// Linked color buffer.
-    WeakPtr<RenderSurface> linkedRenderTarget_;
-    /// Linked depth buffer.
-    WeakPtr<RenderSurface> linkedDepthStencil_;
-    /// Update mode for viewports.
-    RenderSurfaceUpdateMode updateMode_;
-    /// Update queued flag.
-    bool updateQueued_;
-};
-
-}

+ 0 - 70
Source/Urho3D/Graphics/OpenGL/OGLRenderSurface.cpp

@@ -51,51 +51,6 @@ RenderSurface::RenderSurface(Texture* parentTexture) :
 {
 {
 }
 }
 
 
-RenderSurface::~RenderSurface()
-{
-    Release();
-}
-
-void RenderSurface::SetNumViewports(unsigned num)
-{
-    viewports_.Resize(num);
-}
-
-void RenderSurface::SetViewport(unsigned index, Viewport* viewport)
-{
-    if (index >= viewports_.Size())
-        viewports_.Resize(index + 1);
-
-    viewports_[index] = viewport;
-}
-
-void RenderSurface::SetUpdateMode(RenderSurfaceUpdateMode mode)
-{
-    updateMode_ = mode;
-}
-
-void RenderSurface::SetLinkedRenderTarget(RenderSurface* renderTarget)
-{
-    if (renderTarget != this)
-        linkedRenderTarget_ = renderTarget;
-}
-
-void RenderSurface::SetLinkedDepthStencil(RenderSurface* depthStencil)
-{
-    if (depthStencil != this)
-        linkedDepthStencil_ = depthStencil;
-}
-
-void RenderSurface::QueueUpdate()
-{
-    updateQueued_ = true;
-}
-
-void RenderSurface::ResetUpdateQueued()
-{
-    updateQueued_ = false;
-}
-
 bool RenderSurface::CreateRenderBuffer(unsigned width, unsigned height, unsigned format)
 bool RenderSurface::CreateRenderBuffer(unsigned width, unsigned height, unsigned format)
 {
 {
     Graphics* graphics = parentTexture_->GetGraphics();
     Graphics* graphics = parentTexture_->GetGraphics();
@@ -159,29 +114,4 @@ void RenderSurface::Release()
     renderBuffer_ = 0;
     renderBuffer_ = 0;
 }
 }
 
 
-int RenderSurface::GetWidth() const
-{
-    return parentTexture_->GetWidth();
-}
-
-int RenderSurface::GetHeight() const
-{
-    return parentTexture_->GetHeight();
-}
-
-TextureUsage RenderSurface::GetUsage() const
-{
-    return parentTexture_->GetUsage();
-}
-
-Viewport* RenderSurface::GetViewport(unsigned index) const
-{
-    return index < viewports_.Size() ? viewports_[index] : (Viewport*)0;
-}
-
-void RenderSurface::SetTarget(unsigned target)
-{
-    target_ = target;
-}
-
 }
 }

+ 0 - 124
Source/Urho3D/Graphics/OpenGL/OGLRenderSurface.h

@@ -1,124 +0,0 @@
-//
-// Copyright (c) 2008-2016 the Urho3D project.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-#pragma once
-
-#include "../../Graphics/GraphicsDefs.h"
-#include "../../Graphics/Viewport.h"
-
-namespace Urho3D
-{
-
-class Camera;
-class Scene;
-class Texture;
-
-/// %Color or depth-stencil surface that can be rendered into.
-class URHO3D_API RenderSurface : public RefCounted
-{
-    friend class Texture2D;
-    friend class TextureCube;
-
-public:
-    /// Construct with parent texture.
-    RenderSurface(Texture* parentTexture);
-    /// Destruct.
-    ~RenderSurface();
-
-    /// Set number of viewports.
-    void SetNumViewports(unsigned num);
-    /// Set viewport.
-    void SetViewport(unsigned index, Viewport* viewport);
-    /// Set viewport update mode. Default is to update when visible.
-    void SetUpdateMode(RenderSurfaceUpdateMode mode);
-    /// Set linked color rendertarget.
-    void SetLinkedRenderTarget(RenderSurface* renderTarget);
-    /// Set linked depth-stencil surface.
-    void SetLinkedDepthStencil(RenderSurface* depthStencil);
-    /// Queue manual update of the viewport(s).
-    void QueueUpdate();
-    /// Create a renderbuffer. Return true if successful.
-    bool CreateRenderBuffer(unsigned width, unsigned height, unsigned format);
-    /// Handle device loss.
-    void OnDeviceLost();
-    /// Release renderbuffer if any.
-    void Release();
-
-    /// Return parent texture.
-    Texture* GetParentTexture() const { return parentTexture_; }
-
-    /// Return renderbuffer if created.
-    unsigned GetRenderBuffer() const { return renderBuffer_; }
-
-    /// Return width.
-    int GetWidth() const;
-    /// Return height.
-    int GetHeight() const;
-    /// Return usage.
-    TextureUsage GetUsage() const;
-
-    /// Return number of viewports.
-    unsigned GetNumViewports() const { return viewports_.Size(); }
-
-    /// Return viewport by index.
-    Viewport* GetViewport(unsigned index) const;
-
-    /// Return viewport update mode.
-    RenderSurfaceUpdateMode GetUpdateMode() const { return updateMode_; }
-
-    /// Return linked color buffer.
-    RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
-
-    /// Return linked depth buffer.
-    RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
-
-    /// Set surface's OpenGL target.
-    void SetTarget(unsigned target);
-
-    /// Return surface's OpenGL target.
-    unsigned GetTarget() const { return target_; }
-
-    /// Return whether manual update queued. Called internally.
-    bool IsUpdateQueued() const { return updateQueued_; }
-    /// Reset update queued flag. Called internally.
-    void ResetUpdateQueued();
-
-private:
-    /// Parent texture.
-    Texture* parentTexture_;
-    /// OpenGL target.
-    unsigned target_;
-    /// OpenGL renderbuffer.
-    unsigned renderBuffer_;
-    /// Viewports.
-    Vector<SharedPtr<Viewport> > viewports_;
-    /// Linked color buffer.
-    WeakPtr<RenderSurface> linkedRenderTarget_;
-    /// Linked depth buffer.
-    WeakPtr<RenderSurface> linkedDepthStencil_;
-    /// Update mode for viewports.
-    RenderSurfaceUpdateMode updateMode_;
-    /// Update queued flag.
-    bool updateQueued_;
-};
-
-}

+ 102 - 0
Source/Urho3D/Graphics/RenderSurface.cpp

@@ -0,0 +1,102 @@
+//
+// Copyright (c) 2008-2016 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#include "../Precompiled.h"
+
+#include "../Graphics/Camera.h"
+#include "../Graphics/Graphics.h"
+#include "../Graphics/GraphicsImpl.h"
+#include "../Graphics/Renderer.h"
+#include "../Graphics/RenderSurface.h"
+#include "../Graphics/Texture.h"
+
+#include "../DebugNew.h"
+
+namespace Urho3D
+{
+
+RenderSurface::~RenderSurface()
+{
+    Release();
+}
+
+void RenderSurface::SetNumViewports(unsigned num)
+{
+    viewports_.Resize(num);
+}
+
+void RenderSurface::SetViewport(unsigned index, Viewport* viewport)
+{
+    if (index >= viewports_.Size())
+        viewports_.Resize(index + 1);
+
+    viewports_[index] = viewport;
+}
+
+void RenderSurface::SetUpdateMode(RenderSurfaceUpdateMode mode)
+{
+    updateMode_ = mode;
+}
+
+void RenderSurface::SetLinkedRenderTarget(RenderSurface* renderTarget)
+{
+    if (renderTarget != this)
+        linkedRenderTarget_ = renderTarget;
+}
+
+void RenderSurface::SetLinkedDepthStencil(RenderSurface* depthStencil)
+{
+    if (depthStencil != this)
+        linkedDepthStencil_ = depthStencil;
+}
+
+void RenderSurface::QueueUpdate()
+{
+    updateQueued_ = true;
+}
+
+void RenderSurface::ResetUpdateQueued()
+{
+    updateQueued_ = false;
+}
+
+int RenderSurface::GetWidth() const
+{
+    return parentTexture_->GetWidth();
+}
+
+int RenderSurface::GetHeight() const
+{
+    return parentTexture_->GetHeight();
+}
+
+TextureUsage RenderSurface::GetUsage() const
+{
+    return parentTexture_->GetUsage();
+}
+
+Viewport* RenderSurface::GetViewport(unsigned index) const
+{
+    return index < viewports_.Size() ? viewports_[index] : (Viewport*)0;
+}
+
+}

+ 123 - 7
Source/Urho3D/Graphics/RenderSurface.h

@@ -22,10 +22,126 @@
 
 
 #pragma once
 #pragma once
 
 
-#if defined(URHO3D_OPENGL)
-#include "OpenGL/OGLRenderSurface.h"
-#elif defined(URHO3D_D3D11)
-#include "Direct3D11/D3D11RenderSurface.h"
-#else
-#include "Direct3D9/D3D9RenderSurface.h"
-#endif
+#include "../Graphics/GraphicsDefs.h"
+#include "../Graphics/Viewport.h"
+
+namespace Urho3D
+{
+
+class Texture;
+
+/// %Color or depth-stencil surface that can be rendered into.
+class URHO3D_API RenderSurface : public RefCounted
+{
+    friend class Texture2D;
+    friend class Texture2DArray;
+    friend class TextureCube;
+
+public:
+    /// Construct with parent texture.
+    RenderSurface(Texture* parentTexture);
+    /// Destruct.
+    ~RenderSurface();
+
+    /// Set number of viewports.
+    void SetNumViewports(unsigned num);
+    /// Set viewport.
+    void SetViewport(unsigned index, Viewport* viewport);
+    /// Set viewport update mode. Default is to update when visible.
+    void SetUpdateMode(RenderSurfaceUpdateMode mode);
+    /// Set linked color rendertarget.
+    void SetLinkedRenderTarget(RenderSurface* renderTarget);
+    /// Set linked depth-stencil surface.
+    void SetLinkedDepthStencil(RenderSurface* depthStencil);
+    /// Queue manual update of the viewport(s).
+    void QueueUpdate();
+    /// Release surface.
+    void Release();
+    /// Mark the GPU resource destroyed on graphics context destruction. Only used on OpenGL.
+    void OnDeviceLost();
+    /// Create renderbuffer that cannot be sampled as a texture. Only used on OpenGL.
+    bool CreateRenderBuffer(unsigned width, unsigned height, unsigned format);
+
+    /// Return width.
+    int GetWidth() const;
+    
+    /// Return height.
+    int GetHeight() const;
+    
+    /// Return usage.
+    TextureUsage GetUsage() const;
+
+    /// Return number of viewports.
+    unsigned GetNumViewports() const { return viewports_.Size(); }
+
+    /// Return viewport by index.
+    Viewport* GetViewport(unsigned index) const;
+
+    /// Return viewport update mode.
+    RenderSurfaceUpdateMode GetUpdateMode() const { return updateMode_; }
+
+    /// Return linked color rendertarget.
+    RenderSurface* GetLinkedRenderTarget() const { return linkedRenderTarget_; }
+
+    /// Return linked depth-stencil surface.
+    RenderSurface* GetLinkedDepthStencil() const { return linkedDepthStencil_; }
+
+    /// Return whether manual update queued. Called internally.
+    bool IsUpdateQueued() const { return updateQueued_; }
+    
+    /// Reset update queued flag. Called internally.
+    void ResetUpdateQueued();
+
+    /// Return parent texture.
+    Texture* GetParentTexture() const { return parentTexture_; }
+
+    /// Return Direct3D9 surface.
+    void* GetSurface() const { return surface_; }
+
+    /// Return Direct3D11 rendertarget or depth-stencil view. Not valid on OpenGL.
+    void* GetRenderTargetView() const { return renderTargetView_; }
+
+    /// Return Direct3D11 read-only depth-stencil view. May be null if not applicable. Not valid on OpenGL.
+    void* GetReadOnlyView() const { return readOnlyView_; }
+
+    /// Return surface's OpenGL target.
+    unsigned GetTarget() const { return target_; }
+
+    /// Return OpenGL renderbuffer if created.
+    unsigned GetRenderBuffer() const { return renderBuffer_; }
+
+private:
+    /// Parent texture.
+    Texture* parentTexture_;
+
+    union
+    {
+        /// Direct3D9 surface.
+        void* surface_;
+        /// Direct3D11 rendertarget or depth-stencil view.
+        void* renderTargetView_;
+        /// OpenGL renderbuffer name.
+        unsigned renderBuffer_;
+    };
+
+    union
+    {
+        /// Direct3D11 read-only depth-stencil view. Present only on depth-stencil surfaces.
+        void* readOnlyView_;
+        /// OpenGL target.
+        unsigned target_;
+    };
+
+    /// Viewports.
+    Vector<SharedPtr<Viewport> > viewports_;
+    /// Linked color buffer.
+    WeakPtr<RenderSurface> linkedRenderTarget_;
+    /// Linked depth buffer.
+    WeakPtr<RenderSurface> linkedDepthStencil_;
+    /// Update mode for viewports.
+    RenderSurfaceUpdateMode updateMode_;
+    /// Update queued flag.
+    bool updateQueued_;
+};
+
+}

+ 1 - 1
Source/Urho3D/Graphics/TextureCube.cpp

@@ -286,7 +286,7 @@ bool TextureCube::SetSize(int size, unsigned format, TextureUsage usage)
         {
         {
             renderSurfaces_[i] = new RenderSurface(this);
             renderSurfaces_[i] = new RenderSurface(this);
 #ifdef URHO3D_OPENGL
 #ifdef URHO3D_OPENGL
-            renderSurfaces_[i]->SetTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
+            renderSurfaces_[i]->target_ = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
 #endif
 #endif
         }
         }