PVRTexLib: Crash with mip maps generation

This topic contains 2 replies, has 2 voices, and was last updated by  Pierre 6 years, 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #30678

    Pierre
    Member

    Using the previous or latest version of the texture lib I have implemented for the first time the generation of mip maps with the CompressPVR function.

    The problem is the function will crash most all of the time (either static lib, 32 or 64 windows)

    Now I wonder if it is broken or if I am using it incorrectly:

        // make a CPVRTexture instance with data passed

        CPVRTexture sOriginalTexture(

          width,   // u32Width,

          height, // u32Height,

          0,               // u32MipMapCount,

          1,               // u32NumSurfaces,

          false,            // bBorder,

          false,            // bTwiddled,

          false,            // bCubeMap,

          false,            // bVolume,

          false,            // bFalseMips,

          alpha?1:0,        // bHasAlpha

          false,            // bVerticallyFlipped

          eInt8StandardPixelType,    // ePixelType,

          0.0f,             // fNormalMap,

          rgba     // pPixelData

          );

        // create texture to encode to

        CPVRTexture sCompressedTexture( sOriginalTexture.getHeader() );

        sCompressedTexture.setMipMapCount( 2 );

        sCompressedTexture.setPixelType( OGL_PVRTC4 );

        // encode texture

        PVRTextureUtilities PVRU;

        PVRU.CompressPVR( sOriginalTexture, sCompressedTexture );

    [/CODE]

    rgba is an array which always containing rgb and alpha, width*height pixels. No padding.

    I clone the format and set the map count to a value which allows generating enough levels down to 16×16 (in this example on top I placed the number 2).

    Calling CompressPVR will result in a crash. Removing the mip map count will produce nice results.

    The texture I tried it with was 512×512, but also a smaller one crashed.

    [CODE]

        // make a CPVRTexture instance with data passed

        CPVRTexture sOriginalTexture(

          width,   // u32Width,

          height, // u32Height,

          0,               // u32MipMapCount,

          1,               // u32NumSurfaces,

          false,            // bBorder,

          false,            // bTwiddled,

          false,            // bCubeMap,

          false,            // bVolume,

          false,            // bFalseMips,

          alpha?1:0,        // bHasAlpha

          false,            // bVerticallyFlipped

          eInt8StandardPixelType,    // ePixelType,

          0.0f,             // fNormalMap,

          rgba     // pPixelData

          );

        // create texture to encode to

        CPVRTexture sCompressedTexture( sOriginalTexture.getHeader() );

        sCompressedTexture.setMipMapCount( 2 );

        sCompressedTexture.setPixelType( OGL_PVRTC4 );

        // encode texture

        PVRTextureUtilities PVRU;

        PVRU.CompressPVR( sOriginalTexture, sCompressedTexture );

    [/CODE]

    rgba is an array which always containing rgb and alpha, width*height pixels. No padding.

    I clone the format and set the map count to a value which allows generating enough levels down to 16×16 (in this example on top I placed the number 2).

    Calling CompressPVR will result in a crash. Removing the mip map count will produce nice results.

    The texture I tried it with was 512×512, but also a smaller one crashed.

    #35215

    Hi Pierre,

    The function you actually want to be using is ProcessRawPVR. If you
    simply set the MipMap count, the compressor gets confused and tries to
    read data that simply doesn’t exist (I’m trying to make this more clear
    in the next version of PVRTexLib).

    If you create a new CPVRTextureHeader, and set its MIP map count to 2,
    then pass your original texture and this header into it, it will add the
    desired MIP map levels. After this, initialise your compressed texture
    and do the set-up as you are now, minus the setMipMapCount.

    In case that’s not clear:

     // make a CPVRTexture instance with data passed 
    
        CPVRTexture sOriginalTexture(
          width,   // u32Width,
          height, // u32Height,
          0,               // u32MipMapCount,
          1,               // u32NumSurfaces,
          false,            // bBorder,
          false,            // bTwiddled,
          false,            // bCubeMap,
          false,            // bVolume,
          false,            // bFalseMips,
          alpha?1:0,        // bHasAlpha
          false,            // bVerticallyFlipped
          eInt8StandardPixelType,    // ePixelType,
          0.0f,             // fNormalMap,
          rgba     // pPixelData
          );

        CPVRTextureHeader sProcessHeader( sOriginalTexture.getHeader() );
        sProcessHeader.setMipMapCount( 2 );
        PVRTextureUtilities PVRU;

        PVRU.ProcessRawPVR(sOriginalTexture,sProcessHeader,false,0.0f,0.0f,0.0f,false,eRESIZE_NEAREST);;
      // create texture to encode to
        CPVRTexture sCompressedTexture( sOriginalTexture.getHeader() );
        sCompressedTexture.setPixelType( OGL_PVRTC4 );

        // encode texture
        PVRU.CompressPVR( sOriginalTexture, sCompressedTexture );

    [/CODE]

    Hope this helps!

    Thanks,

    Tobias   
    [CODE]

     // make a CPVRTexture instance with data passed

        CPVRTexture sOriginalTexture(

          width,   // u32Width,

          height, // u32Height,

          0,               // u32MipMapCount,

          1,               // u32NumSurfaces,

          false,            // bBorder,

          false,            // bTwiddled,

          false,            // bCubeMap,

          false,            // bVolume,

          false,            // bFalseMips,

          alpha?1:0,        // bHasAlpha

          false,            // bVerticallyFlipped

          eInt8StandardPixelType,    // ePixelType,

          0.0f,             // fNormalMap,

          rgba     // pPixelData

          );



        CPVRTextureHeader sProcessHeader( sOriginalTexture.getHeader() );

        sProcessHeader.setMipMapCount( 2 );

        PVRTextureUtilities PVRU;

        PVRU.ProcessRawPVR(sOriginalTexture,sProcessHeader,false,0.0f,0.0f,0.0f,false,eRESIZE_NEAREST);;

      // create texture to encode to

        CPVRTexture sCompressedTexture( sOriginalTexture.getHeader() );

        sCompressedTexture.setPixelType( OGL_PVRTC4 );



        // encode texture

        PVRU.CompressPVR( sOriginalTexture, sCompressedTexture );

    [/CODE]

    Hope this helps!

    Thanks,

    Tobias   

    #35216

    Pierre
    Member

    Thank you Tobias, this helps a lot.

    The funny part is, it did work a few times and I actually had a nice .pvr which contained the mipmaps. Just it did not work all the time.

    And fopr me personally it was unclear. I think it would be nice if at least it would not crash but throw some error which I can catch. 🙂

    I also just noticed (and a bit too late) that the documentation is actually using it as you showed me. Just I did not see the line of code with ProcessRawPVR while flying over it. 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.