Hi there!
Getting a little further on with my studies and I've come across something new(ish) again. I'm pretty sure I understand it but a second opinion is always nice. Have a look at the code snippet below:
The details aren't really important for this question, in case you're interested this is a class that creates a buffer for the CPU to write into which is then later read by the GPU. The byte size parts are due to the fact that (for whatever reason) if you're creating a constant buffer all data needs to be in multiples of 256 bytes. So even say a 4x4 matrix at 64 bytes gets 'promoted' to 256 bytes as per the protocol requirements. The constructor just checks a bool loaded into the constructor function to see if this is needed or not. AFAIK you don't have to do that for a vertex or index buffer.Code:template<typename T> class UploadBuffer { public: UploadBuffer(ID3D12Device* device, UNIT elementCount, bool isConstantBuffer) : mIsConstantBuffer(isConstantBuffer) { ....skipped some stuff if(isConstantBuffer) { mElementByteSize = d3dUtil::CalcConstantBufferByteSize(sizeof(T)); ....more class stuff continues
Anyways that's API specific stuff which isn't what I'm here for. I'm here to ask if the template allows for different data types to be used inside the class? Sometimes the size of the data it receives in the constructor varies, it depends what you're using the constant buffer for.
Getting a bit ahead of myself here perhaps I should now post the code that creates the class:
So I presume those two lines are just preparing a pointer in some way, and then calling the class constructor whilst at the same time telling the class what type/size of variable T is going to be.Code:std::unique_ptr<UploadBuffer<ObjectConstants>> mObjectCB = nullptr; mObjectCB = std::make_unique<UploadBuffer<ObjectConstants>>(md3dDevice.Get(), n, true);
That would make sense as the ObjectConstants struct can vary in size depending upon what you're doing with the graphics.
Hope that made sense, thanks!!![]()


Reply With Quote