Frage

Suppose I have the following class:

class DX11ConstantBuffer
{
    public:
        ID3D11Buffer *pData;
};

I receive an array of this class in a function:

DX11ConstantBuffer **pp

My wrapper (DX11ConstantBuffer) contains a pointer to ID3D11Buffer. The following function:

pDevcon->VSSetConstantBuffers

requires a pointer to an array of ID3D11Buffers,

ID3D11Buffer *const *ppConstantBuffers

As the function receives a pointer to an array of my own wrapper, what would be the fastest way to create an array of ID3D11Buffers from it? To make it clearer:

void ...(DX11ConstantBuffer **pp, ....)
{
    ID3D11Buffer** _pp = GetAllID3D11BufferElementsFrom(pp);
    pDevcon->VSSetConstantBuffers(..., _pp, ...);
}

The function is meant to be called several times each frame.

War es hilfreich?

Lösung

The fastest way is proactively, i.e. to have maintained a contiguous array of ID3D11Buff* before needing to call VSSetConstantBuffers, for which you'd want a std::vector<ID3D11Buff*>. You could update the vector whenever DX11ConstantBuffer::pData is set, or DX11ConstantBuffer's destructor runs, and if you want better assurances around that you can make pData private and have accessor functions which can reliably intercept changes.

If you don't do it proactively, then with your current objects you've no choice but to iterate over the DX11ConstantBuffers and copy out the ID3D11Buf*s to an array/vector one-by-one....

Andere Tipps

You can make the wrapper inherites from the type it includes.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top