[info-performer] affecting texture loads with glPixelStore

Date view Thread view Subject view Author view

From: Patrick J Melody - CONTRACTOR (melody++at++cmf.nrl.navy.mil)
Date: 03/04/2005 14:58:42


i want to read in raw little endian PFTEX_RGB5_A1 PFTEX_UNSIGNED_SHORT_5_5_5_1
texels from disk on a big endian irix box and then have performer's call
to glTexImage2D swap them, but if i call glPixelStorei(GL_UNPACK_SWAP_BYTES,1)
even in single process mode it seems to have no effect. i call glPixelStorei
immediately after every disk to main memory load.

i thought this would work since i have a nonperformer program that reads
in raw big endian PFTEX_RGB5_A1 PFTEX_UNSIGNED_SHORT_5_5_5_1 texels into
main memory from disk and then calls glDrawPixels on that data. this
displays correctly on a little endian linux box if i first say
glPixelStorei(GL_UNPACK_SWAP_BYTES,1).

having separate databases for separate platforms probably isn't
feasible. there doesn't seem to be any pfTexture API that directly
addresses glPixelStore type issues for loading textures. (this is
actually happening in a pfCliptexture but i doubt that's relevant.) it
would seem like i would need something like that for it to not do byte
swapping on every texture i had (not desirable), but i am surprised that
i am seeing no effect at all with glPixelStore. am i pretty much going
to have to take the CPU hit doing this?

for the example code to see this: you can add the following func to clipfly

int test5551CliptextureTileReaderCallback(pfImageTile* itile, int nTexels)
{
    unsigned short* s;
    int i;

    /* load image tile with completely blue texture */
    s = (unsigned short*)pfGetImageTileMem(itile);
    for (i = 0; i < nTexels; i++) {
        *s = 0x0022;
        s++;
    }

    /* pick one... */
    switch (2) {
        case 0:
            /* no byte swap */
            break;
        case 1:
            /* OpenGL byte swap */
            glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
            break;
        case 2:
            /* CPU byte swap */
            s = (unsigned short*)pfGetImageTileMem(itile);
            for (i = 0; i < nTexels; i++) {
                unsigned char* a = (unsigned char*)s++;
                char tmp = *a;
                *a = *(a+1);
                *(a+1) = tmp;
            }
            break;
    }

    return nTexels;
}

test5551.ct is this:

    ct_version2.0
    int_format PFTEX_RGB5_A1
    ext_format PFTEX_UNSIGNED_SHORT_5_5_5_1
    img_format PFTEX_RGBA
    virt_size 131072 131072 1
    clip_size 1024
    tile_size 512 512 1
    invalid_border 8
    smallest_icache 1 1 1
    lookahead 2
    allocated_levels 16
    read_func test5551CliptextureTileReaderCallback
    tile_format dummy

then run it:
    clipfly -m 0 -M 0 test5551.ct

cpu swapping gives a green color, otherwise you get blue.

- patrick melody


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Fri Mar 04 2005 - 14:59:04 PST