IndexBuffer::IndexBuffer(const ObjectFactory& factory, const void* data, size_t byteCount) { if (byteCount!=0) { D3D11_BUFFER_DESC desc; desc.ByteWidth = (UINT)byteCount; desc.Usage = D3D11_USAGE_IMMUTABLE; desc.BindFlags = D3D11_BIND_INDEX_BUFFER; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; desc.StructureByteStride = 0; D3D11_SUBRESOURCE_DATA subresData; subresData.pSysMem = data; subresData.SysMemPitch = subresData.SysMemSlicePitch = 0; _underlying = factory.CreateBuffer(&desc, &subresData); } }
ConstantBuffer::ConstantBuffer( const ObjectFactory& factory, const void* data, size_t byteCount, bool immutable) { if (byteCount!=0) { D3D11_BUFFER_DESC desc; desc.ByteWidth = (UINT)byteCount; if (data && immutable) { desc.Usage = D3D11_USAGE_IMMUTABLE; desc.CPUAccessFlags = 0; } else { desc.Usage = D3D11_USAGE_DYNAMIC; desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; } desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; desc.MiscFlags = 0; desc.StructureByteStride = 0; D3D11_SUBRESOURCE_DATA subresData; subresData.pSysMem = data; subresData.SysMemPitch = subresData.SysMemSlicePitch = 0; _underlying = factory.CreateBuffer(&desc, data?(&subresData):nullptr); } }