I have an object called cube and I have a vector of vertices within it. Within my main DX11 project I'm making D3D11_SUBRESOURCE_DATA in order to create a vertex buffer. When I create a subresource I need to reference the vector like so:
subresourcedata.pSysMem = &vertices;
But now that the vertices are in an object I'm not sure how to do that (cube.vertices isn't the same), does the object have to be a pointer so I can use -> instead of . to reference them or is there a simple way to do what I'm doing using normal objects?
Thanks
Just add an accessor to your class to expose the vertices as a pointer. So, assuming you have a Vertex
structure, something like:
class CMyCube
{
// ... blah blah
public:
const Vertex* GetVertices() const { return &m_pVertices[0]; }
// ... blah blah
private:
std::vector<Vertex> m_pVertices;
};
Then you can do:
pSubResource.pSysMem = pSomeCubeInstance.GetVertices();
You could overload the & operator.
class cube
{
public:
vertices* operator&() const { return &_vertices[0]; }
std::vector<vertices> _vertices;
};
Then you can do this:
cube c;
subresourcedata.pSysMem = &c;
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.