Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

digitalfreak

why D3D uses so many pointer to pointers?

This topic is 5282 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

for example, LPD3DXMESH is a pointer type that points to ID3DXMesh, then why functions like
HRESULT WINAPI 
    D3DXCreateMeshFVF(
        DWORD NumFaces, 
        DWORD NumVertices, 
        DWORD Options, 
        DWORD FVF, 
        LPDIRECT3DDEVICE9 pD3D, 
        LPD3DXMESH* ppMesh);
 
use pointer to pointer instead of just LPD3DXMESH as the last arg?

Share this post


Link to post
Share on other sites
Advertisement
Hi,
I think its for a reason similar to the fact that if you have
a class with a constructor taking a LPDIRECT3DDEVICE9 as a
parameter then it has to be created after the device is
initialized:


class X
{
public:
X(LPDIRECT3DDEVICE9 pd3dDevice)
{
m_pd3dDevice = pd3dDevice;
}

void DoSomething()
{
// m_pd3dDevice-> .etc

}
LPDIRECT3DDEVICE9 m_pd3dDevice;
};


will work if the class has been constructed after the device has
been initialized and not before, whilst:


class X
{
public:
X(LPDIRECT3DDEVICE9 *pd3dDevice)
{
m_pd3dDevice = pd3dDevice;
}

void DoSomething()
{
// (*m_pd3dDevice)-> .etc

}
LPDIRECT3DDEVICE9 *m_pd3dDevice;
};


will work if the class is created before the device has been
initialized, or if it has been initialized afterwards.
This is because the address of the device might change during
initialization.

in the case of "LPD3DXMESH* ppMesh"
The only answer I can think of is that if for some reason the
address of the mesh changed, the function would fail.
Otherwise I am not sure might just be a coding
convention.


Edits: Fixed
 tags and a spelling error

<SPAN CLASS=editedby>[edited by - ray_intellect on March 5, 2004 4:54:29 AM]</SPAN>

<SPAN CLASS=editedby>[edited by - ray_intellect on March 5, 2004 4:55:11 AM]</SPAN>


[edited by - ray_intellect on March 5, 2004 4:58:03 AM]

Share this post


Link to post
Share on other sites
The convention saves the programmer from having to allocate the memory for the classes manually (which, incidentally, is very difficult because only their interfaces are public, not the base classes themselves).
You should be happy that DX offers the service for allocating the objects

-Nik

Share this post


Link to post
Share on other sites
You are using LPD3DXMESH to access a mesh object over an interface. When you call D3DXCreateMeshFVF() the object with its interface pointer is created. To store it in a pointer variable of your application the function needs a pointer to this variable. So it has got the address of the variable, which is a pointer in this case, to store the new value to.

I hope my answer was clear enough to be understandable.

Share this post


Link to post
Share on other sites
ID3DXMesh is an interface, so you will always be using polymorphism and therefore you need it to be a pointer. As far as a pointer to a pointer, it must be this way to put the new mesh in the variable you give it and to keep it C compatible. If it were only C++, it would be better to make it a pointer to a reference, but since C doesn''t have references, we are stuck with pointers.

Share this post


Link to post
Share on other sites
May I suggest using C# and Managed DirectX to get away from the pointer madness? I''m not against C++ and have coded in it for years but if you are like me and aren''t trying to make a professional grade (performance wise) game and are just making a game for fun then you may find it increases your productivity significantly. Just a suggestion!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!