//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// #pragma once #include "BsCorePrerequisites.h" #include "BsModule.h" #include "BsVertexBuffer.h" #include "BsIndexBuffer.h" #include "BsVertexDeclaration.h" namespace bs { struct GPU_BUFFER_DESC; struct GPU_PARAMS_DESC; /** @addtogroup RenderAPI-Internal * @{ */ /** * Handles creation of various hardware buffers. * * @note Sim thread only. */ class BS_CORE_EXPORT HardwareBufferManager : public Module { public: HardwareBufferManager(); virtual ~HardwareBufferManager(); /** * Creates a new vertex buffer used for holding number of vertices and other per-vertex data. Buffer can be bound * to the pipeline and its data can be passed to the active vertex GPU program. * * @param[in] desc Description of the buffer to create. */ SPtr createVertexBuffer(const VERTEX_BUFFER_DESC& desc); /** * Creates a new index buffer that holds indices referencing vertices in a vertex buffer. Indices are interpreted * by the pipeline and vertices are drawn in the order specified in the index buffer. * * @param[in] desc Description of the buffer to create. */ SPtr createIndexBuffer(const INDEX_BUFFER_DESC& desc); /** * Creates an GPU parameter block that you can use for setting parameters for GPU programs. Parameter blocks may be * used for sharing parameter data between multiple GPU programs, requiring you to update only one buffer for all of * them, potentially improving performance. * * @param[in] size Size of the parameter buffer in bytes. * @param[in] usage Usage that tells the hardware how will be buffer be used. */ SPtr createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC); /** * Creates a generic buffer that can be passed as a parameter to a GPU program. This type of buffer can hold various * type of data and can be used for various purposes. See GpuBufferType for explanation of different buffer types. * * @param[in] desc Description of the buffer to create. */ SPtr createGpuBuffer(const GPU_BUFFER_DESC& desc); /** * Creates a new vertex declaration from a list of vertex elements. * * @param[in] desc Description of the object to create. */ SPtr createVertexDeclaration(const SPtr& desc); /** @copydoc GpuParams::create(const SPtr&) */ SPtr createGpuParams(const SPtr& paramInfo); }; namespace ct { /** * Handles creation of various hardware buffers. * * @note Core thread only. */ class BS_CORE_EXPORT HardwareBufferManager : public Module { public: virtual ~HardwareBufferManager() { } /** * @copydoc bs::HardwareBufferManager::createVertexBuffer * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on. */ SPtr createVertexBuffer(const VERTEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT); /** * @copydoc bs::HardwareBufferManager::createIndexBuffer * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on. */ SPtr createIndexBuffer(const INDEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT); /** * @copydoc bs::HardwareBufferManager::createVertexDeclaration * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on. */ SPtr createVertexDeclaration(const SPtr& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT); /** * Creates a new vertex declaration from a list of vertex elements. * * @param[in] elements List of elements to initialize the declaration with. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on. */ SPtr createVertexDeclaration(const List& elements, GpuDeviceFlags deviceMask = GDF_DEFAULT); /** * @copydoc bs::HardwareBufferManager::createGpuParamBlockBuffer * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on. */ SPtr createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC, GpuDeviceFlags deviceMask = GDF_DEFAULT); /** * @copydoc bs::HardwareBufferManager::createGpuBuffer * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on. */ SPtr createGpuBuffer(const GPU_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT); /** @copydoc GpuParams::create(const SPtr&, GpuDeviceFlags) */ SPtr createGpuParams(const SPtr& paramInfo, GpuDeviceFlags deviceMask = GDF_DEFAULT); protected: friend class bs::IndexBuffer; friend class IndexBuffer; friend class bs::VertexBuffer; friend class VertexBuffer; friend class bs::VertexDeclaration; friend class bs::GpuParamBlockBuffer; friend class bs::GpuBuffer; friend class GpuBuffer; /** Key for use in the vertex declaration map. */ struct VertexDeclarationKey { VertexDeclarationKey(const List& elements); class HashFunction { public: size_t operator()(const VertexDeclarationKey& key) const; }; class EqualFunction { public: bool operator()(const VertexDeclarationKey& lhs, const VertexDeclarationKey& rhs) const; }; List elements; }; /** @copydoc createVertexBuffer */ virtual SPtr createVertexBufferInternal(const VERTEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0; /** @copydoc createIndexBuffer */ virtual SPtr createIndexBufferInternal(const INDEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0; /** @copydoc createGpuParamBlockBuffer */ virtual SPtr createGpuParamBlockBufferInternal(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0; /** @copydoc createGpuBuffer */ virtual SPtr createGpuBufferInternal(const GPU_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0; /** @copydoc createVertexDeclaration(const List&, GpuDeviceFlags) */ virtual SPtr createVertexDeclarationInternal(const List& elements, GpuDeviceFlags deviceMask = GDF_DEFAULT); /** @copydoc createGpuParams */ virtual SPtr createGpuParamsInternal(const SPtr& paramInfo, GpuDeviceFlags deviceMask = GDF_DEFAULT); typedef UnorderedMap, VertexDeclarationKey::HashFunction, VertexDeclarationKey::EqualFunction> DeclarationMap; DeclarationMap mCachedDeclarations; }; } /** @} */ }