How to use DecompressPVR from PVRTextLib?

This topic contains 5 replies, has 3 voices, and was last updated by  tingasd 8 years, 5 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #29770

    riruilo
    Member

    Hi dudes!

    I’m using PVRTextLib to decompress PVR files and use them in my OpenGL program (level editor) under Windows XP and Visual Studio 2005.

    I’d like to obtain a bytes array representing my image, someting like
    unsigned char* pixels=(unsigned char*)malloc(Width*Height*Channels);
    in order to pass it to OpenGL, like:
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,Width,Heigh,0,GL_RGBA,GL_UNSIGNED_BYTE, pixels);

    But I have some questions about usage of PVR library…

    After calling
    PVRU->DecompressPVR(sOriginalTexture,sDecompressedTexture);
    What I have in sDecompressedTexture is always raw data in a R8G8B8 or R8G8B8A8 format?
    Or should I call sDecompressedTexture.setPixelType(eInt8StandardPixelType)?

    About alpha manipulating:
    If a texture does not have alpha channel, should I always get an image with an alpha channel? In other words, should I manually discard these unused pixels if original image had 3 channels? (I have to tell opengl if it is GL_RGBA or GL_RGB and with proper data)

    If I use hasAlpha() method, I get a linker error:
    1>CTextureManager.obj : error LNK2001: unresolved external symbol “__declspec(dllimport) public: bool __thiscall pvrtexlib::CPVRTexture::hasAlpha(void)const ” (__imp_?hasAlpha@CPVRTexture@pvrtexlib@@QBE_NXZ)
    1>C:Documents and SettingsRicardoEscritorioiPhonedonkeySpanking_vsReleaseSpanking.exe : fatal error LNK1120: 1 unresolved externals

    But other methods like
    printf(“width: %dn”, sDecompressedTexture.getWidth());
    printf(“height: %dn”, sDecompressedTexture.getHeight());
    work perfectly. Perhaps there is someting wrong in the lib. Can anyone confirm if hasAlpha() works?

    Note: I’m using last version of this library.

    BTW, it seems there is a bug on setAlpha(const bool bFalseMips) method and setFlipped(const bool bFalseMips).
    Parameters seem to be wrong.

    Thanks a lot for your help.Smile
    riruilo2009-04-13 11:16:29

    #32963

    Gordon
    Moderator

    As I’ve answered in another thread (https://www.imgtec.com/forum/forum_posts.asp?TID=290) there is source code in the file PVRTools/PVRTDecompress.h/cpp in our SDKs that allows you to decompress PVRTC textures for use on platforms that don’t support PVRTC natively (like a Windows desktop). I would recommend using this instead of PVRTexLib as it is a lot simpler.

    The decompressed data after calling PVRTextureUtilities::DecompressPVR() is in one of the four standard formats that are described in the documentation. For PVRTC this will be the 32bpp format R8B8G8A8 (the first one in this list from PVRTexLibGlobals.h):

    Code:
         const PixelType eInt8StandardPixelType     = DX10_R8G8B8A8_UNORM,

                             eInt16StandardPixelType     = D3D_ABGR_16161616,

                             eInt32StandardPixelType     = DX10_R32G32B32A32_UINT,

                             eFloatStandardPixelType     = D3D_ABGR_32323232F;

    I use the hasAlpha() method from the CPVRTextureHeader/CPVRTexture class to check if the texture has alpha for this purpose. I’m not sure why you’re having trouble with this and so I’ve filed a bug (BRN27067) and will investigate this issue further. The setAlpha and setFlipped functions are fairly recent additions to the library – are you certain you have an up to date DLL?

    If you’re using the PVRTools/PVRTDecompress route then there should be a flag set in the dwpfFlags field of the PVRTextureHeader struct that indicates whether alpha is present in the .pvr file or not. You could also check the dwAlphaMask field for <32bpp formats.

    #32964

    riruilo
    Member
    Gordon wrote:
    As I’ve answered in another thread (https://www.imgtec.com/forum/forum_posts.asp?TID=290) there is source code in the file PVRTools/PVRTDecompress.h/cpp in our SDKs that allows you to decompress PVRTC textures for use on platforms that don’t support PVRTC natively (like a Windows desktop). I would recommend using this instead of PVRTexLib as it is a lot simpler.

    The decompressed data after calling PVRTextureUtilities::DecompressPVR() is in one of the four standard formats that are described in the documentation. For PVRTC this will be the 32bpp format R8B8G8A8 (the first one in this list from PVRTexLibGlobals.h):

    Code:
         const PixelType eInt8StandardPixelType     = DX10_R8G8B8A8_UNORM,

                             eInt16StandardPixelType     = D3D_ABGR_16161616,

                             eInt32StandardPixelType     = DX10_R32G32B32A32_UINT,

                             eFloatStandardPixelType     = D3D_ABGR_32323232F;

    I use the hasAlpha() method from the CPVRTextureHeader/CPVRTexture class to check if the texture has alpha for this purpose. I’m not sure why you’re having trouble with this and so I’ve filed a bug (BRN27067) and will investigate this issue further. The setAlpha and setFlipped functions are fairly recent additions to the library – are you certain you have an up to date DLL?

    If you’re using the PVRTools/PVRTDecompress route then there should be a flag set in the dwpfFlags field of the PVRTextureHeader struct that indicates whether alpha is present in the .pvr file or not. You could also check the dwAlphaMask field for <32bpp formats.

    OK, I can read a texture but if I have a texture with 3 channe4ls (no alpha), I get a data structure (getData and getDataSize) that tells me I’m loading a 4 channel texture. This is not a problem because I discard alpha pixels in this case.

    BTW, just a question, does DecompressPVR() use FlipY property to modify data? or does OpenGL use it? (I don’t think so as I don’t send header, just data)

    Thanks a lot for your help, you are very helpful for me.

    #32965

    Gordon
    Moderator

    DecompressPVR() in PVRTexLib uses the flipY property so that PVRTexTool knows which way up to show your texture (you can also check it yourself).

    PVRTexLib is designed to be used as part of an offline tool (like PVRTexTool or PVRShaman) – I didn’t really intend it to be used in games tbh.

    #32966

    riruilo
    Member
    Gordon wrote:
    DecompressPVR() in PVRTexLib uses the flipY property so that PVRTexTool knows which way up to show your texture (you can also check it yourself).

    PVRTexLib is designed to be used as part of an offline tool (like PVRTexTool or PVRShaman) – I didn’t really intend it to be used in games tbh.

    Evidently!!!

    I’m just using it for my level editor and my Windows debug game.

    Thanks for reply 😉

    #32967

    tingasd
    Member

    If I use hasAlpha() new york escort method, I get a linker error:
    1>CTextureManager.obj
    : error LNK2001: unresolved new york asian escort external symbol “__declspec(dllimport)
    public: bool __thiscall pvrtexlib::CPVRTexture::hasAlpha(void)const “
    (__imp_?hasAlpha@CPVRTexture@pvrtexlib@@QBE_NXZ)
    1>C:Documents
    and
    SettingsRicardoEscritorioiPhonedonkeySpanking_vsReleaseSpanking.exe
    : fatal error LNK1120: 1 unresolved externals

    But other new york asian escorts methods like
    printf(“width: %dn”, sDecompressedTexture.getWidth());
    printf(“height: %dn”, sDecompressedTexture.getHeight());
    work perfectly. Perhaps there is new york escorts someting wrong in the lib. Can anyone confirm if hasAlpha() works?

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