帮我评估这个选角 [英] Help me evaluate this casting

查看:69
本文介绍了帮我评估这个选角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PowerVR网格绘图代码中发现了这一点,但我真的不知道如何阅读.

I found this in the PowerVR mesh drawing code and I don't really know how to read it.

&((unsigned short*)0)[3 * mesh.sBoneBatches.pnBatchOffset[batchNum]]

这是怎么回事?这是对void的引用,将其转换为无符号短指针,然后偏移(3 * mesh(etc ...)+ batchNum)吗?真伤了我的脑筋.

What is going on here? Is this a reference to void cast as an unsigned short pointer and then offset by (3*mesh(etc...) + batchNum)? It's breaking my brain.

可以在glDrawElements调用的上下文中找到它:

It's found in the context of a glDrawElements call:

glDrawElements(GL_TRIANGLES, i32Tris * 3, GL_UNSIGNED_SHORT, 
               &((unsigned short*)0)[3 * mesh.sBoneBatches.pnBatchOffset[batchNum]]);

推荐答案

让我们由内而外.

(unsigned short*)0

这会将0强制转换为无符号的短指针.这将用于计算内存偏移量,该内存偏移量是根据无符号short的大小计算的.

This is casting 0 to an unsigned short pointer. This will be used for computing a memory offset, computed in terms of the size of an unsigned short.

3 * mesh.sBoneBatches.pnBatchOffset[batchNum]

这大概是某些三角形批次在内存中的偏移量.三角形由3个短裤组成,因此看起来它们以三角形的数量存储偏移量,然后乘以3即可得到短裤的数量.

This is, presumably, the offset in memory of some batch of triangles. A triangle is composed of 3 shorts, so it looks like they are storing an offset in terms of numbers of triangles, and then multiplying by 3 to get the number of shorts.

((unsigned short*)0)[3 * mesh.sBoneBatches.pnBatchOffset[batchNum]]

现在使用该0指针查找给定偏移量的存储位置.通常,这将返回该内存位置的值,但是他们希望将指针传递给glDrawElements,因此请使用&运算符获取指向该内存位置的指针:

This is now using that 0 pointer to find the memory location of the given offset. This would normally return the value of that memory location, but they want a pointer to pass into glDrawElements, so the use the & operator to get a pointer to that memory location:

&((unsigned short*)0)[3 * mesh.sBoneBatches.pnBatchOffset[batchNum]]

这篇关于帮我评估这个选角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆