Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- -----------------------------------------------------------------------------
- Filename: Buffer.hpp
- -----------------------------------------------------------------------------
- -----------------------------------------------------------------------------
- */
- // Declare Once
- #pragma once
- // Includes
- #include "Defines.hpp"
- // Namespace ------------------------------------------------------------------------------
- namespace R3D
- {
- // Class definition -------------------------------------------------------------------
- template <typename T> class Buffer
- {
- public:
- enum class Usage : UByte
- {
- Default = 0,
- Immutable = 1,
- Dynamic = 2,
- Staging = 3
- };
- enum class Type : UInt
- {
- VertexBuffer = 0x1L,
- IndexBuffer = 0x2L,
- ConstantBuffer = 0x4L,
- ShaderResource = 0x8L,
- StreamOutput = 0x10L,
- RenderTarget = 0x20L,
- DepthStencil = 0x40L,
- UnorderedAccess = 0x80L,
- Decoder = 0x200L,
- VideoEncoder = 0x400L
- };
- enum class CPUAccess : UInt
- {
- None = 0,
- Write = 0x10000L,
- Read = 0x20000L
- };
- enum class MiscFlags : UInt
- {
- None = 0,
- GenerateMips = 0x1L,
- Shared = 0x2L,
- TextureCUBE = 0x4L,
- DrawIndirectArgs = 0x10L,
- BufferAllowRawViews = 0x20L,
- BufferStructured = 0x40L,
- ResourceClamp = 0x80L,
- SharedKeyedMutex = 0x100L,
- GDICompatible = 0x200L,
- SharedNTHandle = 0x800L,
- RestrictedContent = 0x1000L,
- RestrictSharedResource = 0x2000L,
- RestrictSharedResourceDriver = 0x4000L,
- Guarded = 0x8000L,
- TilePool = 0x20000L,
- Tiled = 0x40000L
- };
- struct Description
- {
- UInt Size;
- Type Type;
- CPUAccess CPUAccess = CPUAccess::None;
- MiscFlags MiscFlags = MiscFlags::None;
- UInt StructureByteStride = 0;
- Usage Usage = Usage::Default;
- };
- struct Data
- {
- public:
- Pointer Memory = nullptr;
- UInt Width = 0;
- UInt Height = 0;
- Data(Pointer data) : Memory(data), Width(0), Height(0) {};
- };
- public:
- ID3D11Buffer* mBuffer;
- UInt Size;
- public:
- // Constructors
- Buffer() = default;
- Buffer(const Buffer& other) = delete;
- ~Buffer() { Release(); };
- // Methods
- bool Create(Buffer::Description description, Buffer::Data data = nullptr);
- void Update(Pointer data);
- Pointer Map();
- void Unmap();
- void Release() { if(mBuffer) { mBuffer->Release(); delete mBuffer; mBuffer = nullptr; } };
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement