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, widthheight pixels. No padding.
I clone the format and set the map count to a value which allows generating enough levels down to 16x16 (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 512x512, but also a smaller one crashed.
<br />
<br /> // make a CPVRTexture instance with data passed<br />
<br /> CPVRTexture sOriginalTexture(<br />
<br /> width, // u32Width,<br />
<br /> height, // u32Height,<br />
<br /> 0, // u32MipMapCount,<br />
<br /> 1, // u32NumSurfaces,<br />
<br /> false, // bBorder,<br />
<br /> false, // bTwiddled,<br />
<br /> false, // bCubeMap,<br />
<br /> false, // bVolume,<br />
<br /> false, // bFalseMips,<br />
<br /> alpha?1:0, // bHasAlpha<br />
<br /> false, // bVerticallyFlipped<br />
<br /> eInt8StandardPixelType, // ePixelType,<br />
<br /> 0.0f, // fNormalMap,<br />
<br /> rgba // pPixelData<br />
<br /> );<br />
<br /><br />
<br /><br />
<br /> // create texture to encode to<br />
<br /> CPVRTexture sCompressedTexture( sOriginalTexture.getHeader() );<br />
<br /> sCompressedTexture.setMipMapCount( 2 );<br />
<br /> sCompressedTexture.setPixelType( OGL_PVRTC4 );<br />
<br /><br />
<br /> // encode texture<br />
<br /> PVRTextureUtilities PVRU;<br />
<br /> PVRU.CompressPVR( sOriginalTexture, sCompressedTexture );<br />
<br />
rgba is an array which always containing rgb and alpha, widthheight pixels. No padding.
I clone the format and set the map count to a value which allows generating enough levels down to 16x16 (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 512x512, but also a smaller one crashed.
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:
<pre =“BBcode”> // 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
<br><pre ="BBcode"> // make a CPVRTexture instance with data passed<br />
<br> CPVRTexture sOriginalTexture(<br />
<br> width, // u32Width,<br />
<br> height, // u32Height,<br />
<br> 0, // u32MipMapCount,<br />
<br> 1, // u32NumSurfaces,<br />
<br> false, // bBorder,<br />
<br> false, // bTwiddled,<br />
<br> false, // bCubeMap,<br />
<br> false, // bVolume,<br />
<br> false, // bFalseMips,<br />
<br> alpha?1:0, // bHasAlpha<br />
<br> false, // bVerticallyFlipped<br />
<br> eInt8StandardPixelType, // ePixelType,<br />
<br> 0.0f, // fNormalMap,<br />
<br> rgba // pPixelData<br />
<br> );<br />
<br><br />
<br> CPVRTextureHeader sProcessHeader( sOriginalTexture.getHeader() );<br />
<br> sProcessHeader.setMipMapCount( 2 );<br />
<br> PVRTextureUtilities PVRU;<br><br> PVRU.ProcessRawPVR(sOriginalTexture,sProcessHeader,false,0.0f,0.0f,0.0f,false,eRESIZE_NEAREST);;<br />
<br> // create texture to encode to<br />
<br> CPVRTexture sCompressedTexture( sOriginalTexture.getHeader() );<br />
<br> sCompressedTexture.setPixelType( OGL_PVRTC4 );<br />
<br><br />
<br> // encode texture<br />
<br> PVRU.CompressPVR( sOriginalTexture, sCompressedTexture ); </pre><br />
Hope this helps!
Thanks,
Tobias
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.