在 D3DX 函数中使用相同的输入和输出参数是否安全?
使用作为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。来自 msdn:
Yes, it is. From msdn:
我很确定答案是肯定的。然而,我找不到任何地方可以肯定地说这一点......
编辑:浏览 D3DX9Math.inl 看起来已经采取了谨慎措施以确保您可以。例如,如果我们查看 D3DXVec3Cross 的代码:
您可以看到它将叉积执行到临时变量中,然后在最后一步中将其复制到返回值中。如果在某个地方明确地说明了这一点,那就太好了。
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:
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.