(Solved) Wii/libogc - Problem displaying color indexed textures (LUT/Palette)

Discussion in 'Nintendo Game Development' started by ArthCarvalho, Jan 17, 2018.

  1. ArthCarvalho

    ArthCarvalho Newly Registered

    Joined:
    Jun 11, 2016
    Messages:
    2
    Likes Received:
    0
    I've been experimenting with Wii homebrew a few days ago and today I ran at a problem trying to display color indexed textures using libogc. I'm not sure what I am doing wrong.

    I can display other textures just fine, but can't seem to get the LUT working, I can tell the actual texture is loaded just fine, but the lut refuses to work.

    Even when I try to generate a lut manually in memory, the results are still garbled and look like they are out of order.

    [​IMG]
    This is the texture, it's a 256 color image.
    The output I get is this:
    [​IMG]
    Note that this is running on dolphin, but the output from the real hardware is basically the same.
    Also this lasts about one frame after the image is displayed, then it goes completely black.

    The code I'm using to load the texture is this:
    Code:
    TPL_GetTextureCI(&textureTPL,5,&texObj[5], &texLutObj,GX_TLUT0);
    GX_InitTexObjLOD(&texObj[5], GX_NEAR, GX_NEAR, 0.0, 10.0, 0.0, GX_FALSE, GX_FALSE, GX_ANISO_1);
    
    GX_LoadTlut(&texLutObj,GX_TLUT0);
    GX_LoadTexObj(&texObj[5], GX_TEXMAP0);
    
    I also tried to generate a palette manually to see what would happen.
    Code:
    u8 lut_data_ptr[16] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF};
    
    GX_InitTlutObj(&texLutObj, lut_data_ptr, GX_TL_IA8, 0x10);
    GX_LoadTlut(&texLutObj,GX_TLUT0);
    GX_LoadTexObj(&texObj[5], GX_TEXMAP0);
    
    (I though making it an Intensity Alpha palette would be easier to check the results since encoding would be easier)

    The output I get is still garbled:
    [​IMG]
    Same array, but this time interpreted as RGB565:
    [​IMG]

    Other color modes will work just fine, except the indexed ones.

    I have no idea what I could be doing wrong here, anyone has any ideas? It's hard to find anything about this because most Gamecube/Wii homebrew won't use indexed textures, but for my project I want, I really wanted indexed textures so I can use effects like palette cycling/palette manipulation.

    Edit:
    After taking a look around it appears that part of the problem is that the memory is not aligned, but I'm not sure how I'm supposed to solve that.

    I took a look at libogc source and I noticed that it will shift the pointer to the right by 5 bits, truncating part of the address, that's why it's pointing in the wrong address, so the function can only accept memory addresses aligned by 32 bytes, if I understand it right. But how I'm supposed to tell the compiler to allocate elements by 32 bytes?

    Edit #2:
    I was able to get it working on Dolphin by copying the original palette from the TPL file to an array and aligning it to 32 byte addresses. But it won't work on real hardware, I can see the picture is loading fine but the colors are still completely wrong on a real Wii.

    This is the output on Dolphin:
    [​IMG]

    And here's the output on a real Wii:
    [​IMG]

    If I switch textures it works fine with the RGB version:
    [​IMG]

    Edit #3:
    Tried running again and some colors showed up, is this some kind of DMA problem?
    [​IMG]

    Solved the problem!
    Leaving the solution here so if it happens to anyone else in the future you know what's wrong:
    After loading or modifying the palette you NEED to call DCFlushRange() on your palette or it won't work properly.
    Code:
    u16 * lut_data_ptr_align = memalign(32, sizeof(u16) * 256);
    memcpy(lut_data_ptr_align, lut_data_ptr, sizeof(u16) * 256);
    DCFlushRange(lut_data_ptr_align, sizeof(u16) * 256);
    
     
    Last edited: Jan 24, 2018
sonicdude10
Draft saved Draft deleted
Insert every image as a...
  1.  0%

Share This Page