LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.05k stars 139 forks source link

Replace buffer type by bind flags #28

Closed LukasBanana closed 5 years ago

LukasBanana commented 5 years ago

Maybe the enumeration LLGL::BufferType should be replaced by LLGL::BufferFlags with additional entries to specifiy one or more purposes for binding a buffer. This will require a lot of refactoring especially in the D3D11 backend because there are multiple sub-classes of D3D11Buffer, e.g. D3D11ConstantBuffer.

This is especially helpful with the upcoming interface for indirect draw/dispatch commands. The enum BufferType and member BufferDescriptor::type will be replaced by three new enums:

LLGL::BufferDescriptor myDesc;
myDesc.size           = /* ... */;
myDesc.bindFlags      = LLGL::BindFlags::RWStorageBuffer | LLGL::BindFlags::IndirectBuffer;
myDesc.cpuAccessFlags = LLGL::CPUAccessFlags::ReadWrite;
myDesc.miscFlags      = LLGL::MiscFlags::DynamicUsage;
auto myBuffer = myRenderer->CreateBuffer(myDesc);

All these flags will also be available in the TextureDescriptor struct, but here the TextureType enum and type member will remain.

Because the dedicated sub-classes for vertex buffers typically have more payload than the other buffers, the new sub-class hierarchy could look like this:

Buffer
 |- GLBuffer
 |   `- GLBufferWithVAO (for vertex buffers)
 |- D3D11Buffer
 |   `- D3D11BufferWithRV (for storage buffers)
 |- ...
...
LukasBanana commented 5 years ago

Done with buffer-bind-flags branch.