在 D3DX 函数中使用相同的输入和输出参数是否安全?

发布于 2024-08-26 17:59:15 字数 358 浏览 5 评论 0原文

使用作为 directX 一部分的 D3DX 库,特别是本例中的 directx9,我想知道使用相同的矩阵(或向量等)作为输入和输出是否安全,

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

我一直在避免这样做,假设它会当计算结果时数组的一部分被部分覆盖时,会导致不好的事情发生,但我看到大量的代码正是这样做的。

一个简短的测试表明它似乎工作正常,所以我假设 D3DX 函数在必要时获取输入数据的副本,或者使用其他方法来确保它工作正常,但我在任何地方都找不到它的记录所以我不愿意依赖它来工作。

官方有没有关于使用此类功能的说明?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我最亲爱的 2024-09-02 17:59:15

是的。来自 msdn

每个函数都可以采用相同的对象作为传递的[in]和返回的[out]参数

Yes, it is. From msdn:

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

金橙橙 2024-09-02 17:59:15

我很确定答案是肯定的。然而,我找不到任何地方可以肯定地说这一点......

编辑:浏览 D3DX9Math.inl 看起来已经采取了谨慎措施以确保您可以。例如,如果我们查看 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;
}

您可以看到它将叉积执行到临时变量中,然后在最后一步中将其复制到返回值中。如果在某个地方明确地说明了这一点,那就太好了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文