#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11RENDERTARGET2OBSERVER_H #define NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11RENDERTARGET2OBSERVER_H #include "Nuclex/Graphics/Config.h" #include "Nuclex/Graphics/Rasterization/RenderTarget2.h" #include "../Direct3D11Api.h" namespace Nuclex { namespace Graphics { namespace Rasterization { // ------------------------------------------------------------------------------------------- // class Direct3D11RasterizerResources; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Graphics::Rasterization namespace Nuclex { namespace Graphics { namespace Rasterization { // ------------------------------------------------------------------------------------------- // ///Manages an attached Direct3D 11 render target texture class Direct3D11RenderTarget2Observer : public RenderTarget2::BackingObserver { /// Initializes a new Direct3D 11 render target texture /// Render target the observer is attached to /// Manager the render target belongs to /// Swap chain the render target is part of public: Direct3D11RenderTarget2Observer( Direct3D11RasterizerResources &resources, RenderTarget2 *renderTarget, const IDXGISwapChainNPtr &swapChain ); /// Initializes a new Direct3D 11 render target texture /// Render target the observer is attached to /// Manager the render target belongs to public: Direct3D11RenderTarget2Observer( Direct3D11RasterizerResources &resources, RenderTarget2 *renderTarget ); /// Frees all resources owned by the rasterizer settings container public: virtual ~Direct3D11RenderTarget2Observer() {} /// Called right before the texture is destroyed public: void Destroying(); /// Resizes the render target to the specified width and height /// New width of the render target /// New height of the render target public: void Resized(std::size_t width, std::size_t height); /// Called when the render target has been cleared public: void Cleared(); /// Clears the render target to the specified values /// Color the render target will be cleared to /// Depth value the depth buffer will be cleared to /// Stencil bits the stencil buffer will be cleared to public: void Cleared(Color color, float depth, std::uint8_t stencil); /// Called when the render target has been modified /// Box around the changed area public: void Changed(const Box &changedBox); /// Reads the specified region of the render target /// Region of the render target that will be read /// /// Address at which the render target's pixels will be deposited /// /// Bytes required to get from one line to the next public: void Read(const Rectangle ®ion, void *target, std::size_t targetStride); /// Retrieves the agnostic render target being observed /// The agnostic render target being observed public: RenderTarget2 *GetResource() const { return this->renderTarget2; } /// Returns the active view into the render target /// The render target's active view public: const ID3D11RenderTargetViewPtr &GetDirect3DRenderTargetView() const { return this->renderTargetView; } /// Returns the active view into the depth and stencil buffer /// The depth and stencil buffer's active view public: const ID3D11DepthStencilViewPtr &GetDirect3DDepthStencilView() const { return this->depthStencilView; } /// /// Called by the rasterizer to shut down the render target before the swap chain /// is recreated. /// public: void ShutdownForSwapChainRecreation(); /// /// Called by the rasterizer after the swap chain has been recreated to create /// a new render target on the new swap chain. /// /// New width of the primary render target /// New height of the primary render target public: void RestoreAfterSwapChainRecreation(std::size_t width, std::size_t height); /// Retrieves the back buffer texture from a swap chain /// Swap chain from which the back buffer will be retrieved /// The swap chain's back buffer as a texture private: static ID3D11Texture2DPtr getTextureFromSwapChain( const IDXGISwapChainNPtr &swapChain ); /// Creates a view through which the render target can be accessed private: void createRenderTargetView(); /// Creates the depth buffer for the render target private: void createDepthBuffer(); /// Creates a view thorugh which the depth buffer can be accessed private: void createDepthView(); private: Direct3D11RenderTarget2Observer(const Direct3D11RenderTarget2Observer &); private: Direct3D11RenderTarget2Observer &operator =(const Direct3D11RenderTarget2Observer &); /// Render target this observer is attached to private: RenderTarget2 *renderTarget2; /// Swap chain whose back buffer the render target represents /// /// This field is only set if the render target is part of a swap chain (which right /// now only holds true for the primary render target) /// private: IDXGISwapChainNPtr swapChain; /// Texture holding the render target's contents private: ID3D11Texture2DPtr renderTargetTexture; /// View through which the render target can be accessed private: ID3D11RenderTargetViewPtr renderTargetView; /// Texture holding the render target's depth and stencil buffer private: ID3D11Texture2DPtr depthStencilTexture; /// View through which the render target can be accessed private: ID3D11DepthStencilViewPtr depthStencilView; /// Resource manager the render target belongs to private: Direct3D11RasterizerResources &resources; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Graphics::Rasterization #endif // NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11RENDERTARGET2OBSERVER_H