#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_CONSTANTBUFFER_H #define NUCLEX_GRAPHICS_RASTERIZATION_CONSTANTBUFFER_H #include "GenericConstantBuffer.h" #include namespace Nuclex { namespace Graphics { namespace Rasterization { // ------------------------------------------------------------------------------------------- // ///Stores constants that are used by vertex and pixel shader programs template class ConstantBuffer : public GenericConstantBuffer { /// Initializes a constant buffer for the container type public: ConstantBuffer() : GenericConstantBuffer(sizeof(TContainer)) {} /// Initializes a constant buffer by copying an existing constant buffer /// Constant buffer that will be copied public: ConstantBuffer(const ConstantBuffer &other) : GenericConstantBuffer(other) {} /// Called when the constant buffer is being destroyed public: virtual ~ConstantBuffer() { OnDestroying(); } /// Retrieves the contents of the constant buffer as a structure /// The contents of the constant buffer as a structure public: TContainer Get() const { TContainer container; auto containerMemory = reinterpret_cast(&container); std::copy_n(AccessMemory(), sizeof(TContainer), containerMemory); return container; } /// Updates the contents of the constant buffer from a structure /// Container structure the constant buffer will be set to public: void Set(const TContainer &container) { auto containerMemory = reinterpret_cast(&container); std::copy_n(containerMemory, sizeof(TContainer), AccessMemory()); OnChanged(0, sizeof(TContainer)); } /// Counts the number of elements stored in the constant buffer /// The number of elements stored in the constant buffer public: std::size_t CountElements() const { return TDescriptor::Describe().size(); } /// /// Retrieves an array describing the elements stored in the constant buffer /// /// An array describing the elements stored in the constant buffer public: const VertexElement *GetElements() const { return TDescriptor::Describe().data(); } }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Graphics::Rasterization #endif // NUCLEX_GRAPHICS_RASTERIZATION_CONSTANTBUFFER_H