#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_DIRECT3D11VERTEXBUFFEROBSERVER_H #define NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11VERTEXBUFFEROBSERVER_H #include "Nuclex/Graphics/Config.h" #include "Nuclex/Graphics/Rasterization/GenericVertexBuffer.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 vertex buffer class Direct3D11VertexBufferObserver : public GenericVertexBuffer::Observer { /// Initializes a new Direct3D 11 vertex buffer /// Manager the vertex buffer belongs to /// Vertex buffer the observer is attached to public: Direct3D11VertexBufferObserver( Direct3D11RasterizerResources &resources, GenericVertexBuffer *vertexBuffer ); /// Frees all resources owned by the vertex buffer observer public: virtual ~Direct3D11VertexBufferObserver(); /// Called right before the buffer is destroyed public: void Destroying(); /// Called when the buffer has been cleared public: void Cleared(); /// Called when the contents of the buffer have changed /// /// Offset in the buffer from which on its contents have changed /// /// Number of bytes that have changed in the buffer public: void Changed(std::size_t offset, std::size_t count); /// Retrieves the agnostic vertex buffer being observed /// The agnostic vertex buffer being observed public: GenericVertexBuffer *GetResource() const { return this->vertexBuffer; } /// Retrieves the Direct3D vertex buffer the observer is managing /// The observer's Direct3D vertex buffer public: const ID3D11BufferPtr &GetDirect3DVertexBuffer() const { return this->direct3DVertexBuffer; } /// /// Gets and resets the 'replaced' flag that indicates whether the Direct3D buffer /// had to be recreated since the last call /// public: bool GetAndResetReplacedFlag() { bool wasReplaced = this->wasReplaced; this->wasReplaced = false; return wasReplaced; } /// Creates a Direct3D vertex buffer matching the observed one private: void createDirect3DVertexBuffer(); private: Direct3D11VertexBufferObserver(const Direct3D11VertexBufferObserver &); private: Direct3D11VertexBufferObserver &operator =(const Direct3D11VertexBufferObserver &); /// Resource manager the render target belongs to private: Direct3D11RasterizerResources &resources; /// Vertex buffer this observer is attached to private: GenericVertexBuffer *vertexBuffer; /// Vertex buffer managed by this observer private: ID3D11BufferPtr direct3DVertexBuffer; /// Number of bytes currently used by the buffer private: std::size_t usedBytes; /// Whether the observer's Direct3D buffer needed to be replaced private: bool wasReplaced; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Graphics::Rasterization #endif // NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11VERTEXBUFFEROBSERVER_H