Help me rate this casting

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

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

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

It is found in the context of the glDrawElements call:

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

Release from the inside.

(unsigned short*)0

This is different 0to an unsigned short pointer. This will be used to calculate the memory offset, calculated in terms of unsigned short size.

3 * mesh.sBoneBatches.pnBatchOffset[batchNum]

, -, . , , , , 3, .

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

0, . , , glDrawElements, & :

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

- 3 * mesh.sBoneBatches.pnBatchOffset [batchNum] - . 0 , , .

+2

, , OpenGL Buffer Objects glDrawElements.

glDrawElements(mode, count, type, void* indices)

indices offset GL_ELEMENT_ARRAY_BUFFER_ARB

... VBO:

C ?

- . [...]

, , , .

+1

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

,

0

Source: https://habr.com/ru/post/1721417/


All Articles