Is it safe to use the same parameters for input and output in D3DX functions?

StackOverflow https://stackoverflow.com/questions/2506824

  •  22-09-2019
  •  | 
  •  

문제

Using the D3DX library that is a part of directX, specifically directx9 in this case, I'm wondering if it's safe to use the same matrix (or vector etc) for input and ouput

D3DXMATRIX mat;
D3DXMatrixInverse(&mat, NULL, &mat);

I've been avoiding doing so, assuming that it would result in bad things happening when parts of the array got partly overwritten as results are calculated but I see an awful lot of code around that does exactly this.

A brief test indicates that it seems to work ok, so I'm assuming that the D3DX functions take a copy where necessary of the input data, or some other method to ensure that this works ok, but I can't find it documented anywhere so I'm reluctant to rely on it working.

Is there any official statement on using the functions like this?

도움이 되었습니까?

해결책

Yes, it is. From msdn:

Each of the functions can take the same object as the passed [in] and returned [out] parameters

다른 팁

I'm pretty sure the answer is yes. I can't find anywhere where this is said for sure however ...

Edit: Flicking through D3DX9Math.inl it looks like care HAS been taken to make sure you can. For example if we look at the code for D3DXVec3Cross:

D3DXINLINE D3DXVECTOR3* D3DXVec3Cross
    ( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
{
    D3DXVECTOR3 v;

#ifdef D3DX_DEBUG
    if(!pOut || !pV1 || !pV2)
        return NULL;
#endif

    v.x = pV1->y * pV2->z - pV1->z * pV2->y;
    v.y = pV1->z * pV2->x - pV1->x * pV2->z;
    v.z = pV1->x * pV2->y - pV1->y * pV2->x;

    *pOut = v;
    return pOut;
}

You can see that it performs the cross product into a temporary and THEN, in the final step, it copies it into the return. It would be nice if this was stated somewhere for sure.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top