简体   繁体   中英

how would i convert shared_ptr<ID3D11Buffer> to ID3D11Buffer**

There is this function that requires a **ID3D11Buffer (where vertexBuffer.get() currently is ). I have the following code:

shared_ptr<ID3D11Buffer> vertexBuffer;
this->graphicContext->GetDevice()->CreateBuffer( &bd, &srd, vertexBuffer.get() );

argument of type "ID3D11Buffer *" is incompatible with parameter of type "ID3D11Buffer **"

How would i get a pointer to a pointer? vertexBuffer.get() just returns a pointer

You have to acquire the buffer into a raw pointer:

ID3D11Buffer* vbptr;
HRESULT hr = this->graphicContext->GetDevice()->CreateBuffer( &bd, &srd, &vbptr);
IF(FAILED(hr))
{
    // an error occurred...
}

Then assign it correctly to a shared_ptr with a custom deleter that calls Release :

std::shared_ptr<ID3D11Buffer> vertexBuffer(vbptr, &ID3D11Buffer::Release);

It's not clear what the semantics of CreateBuffer is or why you would be passing it a buffer that already exists.

ID3D11Buffer* buf = vertexBuffer.get();
this->graphicContext->GetDevice()->CreateBuffer( &bd, &srd, &buf);
if (buf != vertexBuffer.get())
    vertexBuffer = new shared_ptr<ID3D11Buffer> (buf);

This requires ID3D11Buffer to have a constructor that takes ownership of an ID3D11Buffer * . Without that, this will only work if the function never creates a buffer and only takes an ID3D11Buffer ** so it can create one if one doesn't already exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM