#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_DIRECT3D11INDEXBUFFEROBSERVER_H
#define NUCLEX_GRAPHICS_RASTERIZATION_DIRECT3D11INDEXBUFFEROBSERVER_H
#include "Nuclex/Graphics/Config.h"
#include "Nuclex/Graphics/Rasterization/GenericIndexBuffer.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 index buffer
class Direct3D11IndexBufferObserver : public GenericIndexBuffer::Observer {
/// Initializes a new Direct3D 11 index buffer
/// Manager the index buffer belongs to
/// Index buffer the observer is attached to
public: Direct3D11IndexBufferObserver(
Direct3D11RasterizerResources &resources, GenericIndexBuffer *indexBuffer
);
/// Frees all resources owned by the index buffer observer
public: virtual ~Direct3D11IndexBufferObserver();
/// 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 index buffer being observed
/// The agnostic index buffer being observed
public: GenericIndexBuffer *GetResource() const { return this->indexBuffer; }
/// Retrieves the Direct3D index buffer the observer is managing
/// The observer's Direct3D index buffer
public: const ID3D11BufferPtr &GetDirect3DIndexBuffer() const {
return this->direct3DIndexBuffer;
}
///
/// 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 index buffer matching the observed one
private: void createDirect3DIndexBuffer();
private: Direct3D11IndexBufferObserver(const Direct3D11IndexBufferObserver &);
private: Direct3D11IndexBufferObserver &operator =(const Direct3D11IndexBufferObserver &);
/// Resource manager the index buffer observer belongs to
private: Direct3D11RasterizerResources &resources;
/// Index this observer is attached to
private: GenericIndexBuffer *indexBuffer;
/// Index buffer managed by this observer
private: ID3D11BufferPtr direct3DIndexBuffer;
/// 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_DIRECT3D11INDEXBUFFEROBSERVER_H