Homebrew Type casting in portal3ds

  • Thread starter Thread starter cal64
  • Start date Start date
  • Views Views 981
  • Replies Replies 3

cal64

Well-Known Member
Newcomer
Joined
Oct 31, 2016
Messages
65
Reaction score
8
Trophies
0
Age
33
XP
466
Country
France
I don't get why, in portal3ds, the index offset from this line:
GPU_DrawElements(GPU_UNKPRIM, (u32*)((u32)mdl->indices-md2BaseAddr), mdl->header.num_tris*3); is first converted to u32 before being converted to u32*.

Any help?
 
Last edited by cal64,
Maybe direct casting from given type to *u32 isn't allowed for some reason? Besides it can be a typo.
 
I don't get why, in portal3ds, the index offset from this line:
GPU_DrawElements(GPU_UNKPRIM, (u32*)((u32)mdl->indices-md2BaseAddr), mdl->header.num_tris*3); is first converted to u32 before being converted to u32*.

Any help?
The GPU_DrawElements call requires a u32* parameter. The actual value required is the address offset from the base address. Indices is converted to a u32 so that unsigned integer math is used to subtract the base rather than pointer math. If you subtract one from a u32* it would actually adjust the address by the sizeof(u32) which in this case is 4.
I think the original intent for the API was to just send the buffer address - but that is not what the hardware expects.
 
  • Like
Reactions: mironicurse

Site & Scene News

Popular threads in this forum