Type casting in portal3ds

Discussion in '3DS - Homebrew Development and Emulators' started by cal64, Jan 26, 2017.

  1. cal64
    OP

    cal64 Member

    Newcomer
    43
    4
    Oct 31, 2016
    Belgium
    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, Jan 26, 2017
  2. mironicurse

    mironicurse GBAtemp Regular

    Member
    108
    37
    Sep 28, 2015
    Russia
    Maybe direct casting from given type to *u32 isn't allowed for some reason? Besides it can be a typo.
     
  3. elhobbs

    elhobbs GBAtemp Advanced Fan

    Member
    783
    292
    Jul 28, 2008
    United States
    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.
     
    mironicurse likes this.
  4. cal64
    OP

    cal64 Member

    Newcomer
    43
    4
    Oct 31, 2016
    Belgium
    Welp, thanks for clearing that up!