/*!*********************************************************************** @Function: PVRTGetOGLES3TextureFormat @Input: sTextureHeader @Modified: glInternalFormat @Modified: glFormat @Modified: glType @Description: Gets the OpenGLES equivalent values of internal format, format and type for this texture header. This will return any supported OpenGLES texture values, it is up to the user to decide if these are valid for their current platform. *************************************************************************/ static const void PVRTGetOGLES3TextureFormat(const PVRTextureHeaderV3& sTextureHeader, PVRTuint32& glInternalFormat, PVRTuint32& glFormat, PVRTuint32& glType) { PVRTuint64 PixelFormat = sTextureHeader.u64PixelFormat; EPVRTVariableType ChannelType = (EPVRTVariableType)sTextureHeader.u32ChannelType; EPVRTColourSpace ColourSpace = (EPVRTColourSpace)sTextureHeader.u32ColourSpace; //Initialisation. Any invalid formats will return 0 always. glFormat = 0; glType = 0; glInternalFormat=0; //Get the last 32 bits of the pixel format. PVRTuint64 PixelFormatPartHigh = PixelFormat&PVRTEX_PFHIGHMASK; //Check for a compressed format (The first 8 bytes will be 0, so the whole thing will be equal to the last 32 bits). if (PixelFormatPartHigh==0) { //Format and type == 0 for compressed textures. switch (PixelFormat) { case ePVRTPF_PVRTCI_2bpp_RGB: { if (ColourSpace == ePVRTCSpacesRGB) { //glInternalFormat=GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT; } else { glInternalFormat=GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; } return; } case ePVRTPF_PVRTCI_2bpp_RGBA: { if (ColourSpace == ePVRTCSpacesRGB) { //glInternalFormat=GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT; } else { glInternalFormat=GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; } return; } case ePVRTPF_PVRTCI_4bpp_RGB: { if (ColourSpace == ePVRTCSpacesRGB) { //glInternalFormat=GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT; } else { glInternalFormat=GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; } return; } case ePVRTPF_PVRTCI_4bpp_RGBA: { if (ColourSpace == ePVRTCSpacesRGB) { //glInternalFormat=GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT; } else { glInternalFormat=GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; } return; } #ifndef TARGET_OS_IPHONE case ePVRTPF_PVRTCII_2bpp: { if (ColourSpace == ePVRTCSpacesRGB) { //glInternalFormat=GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV2_IMG; } else { glInternalFormat=GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG; } return; } case ePVRTPF_PVRTCII_4bpp: { if (ColourSpace == ePVRTCSpacesRGB) { //glInternalFormat=GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV2_IMG; } else { glInternalFormat=GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG; } return; } case ePVRTPF_ETC1: { glInternalFormat=GL_ETC1_RGB8_OES; return; } #endif case ePVRTPF_ETC2_RGB: { if (ColourSpace==ePVRTCSpacesRGB) glInternalFormat=GL_COMPRESSED_SRGB8_ETC2; else glInternalFormat=GL_COMPRESSED_RGB8_ETC2; return; } case ePVRTPF_ETC2_RGBA: { if (ColourSpace==ePVRTCSpacesRGB) glInternalFormat=GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC; else glInternalFormat=GL_COMPRESSED_RGBA8_ETC2_EAC; return; } case ePVRTPF_ETC2_RGB_A1: { if (ColourSpace==ePVRTCSpacesRGB) glInternalFormat=GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2; else glInternalFormat=GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; return; } case ePVRTPF_EAC_R11: { if (ChannelType==ePVRTVarTypeSignedInteger || ChannelType==ePVRTVarTypeSignedIntegerNorm || ChannelType==ePVRTVarTypeSignedShort || ChannelType==ePVRTVarTypeSignedShortNorm || ChannelType==ePVRTVarTypeSignedByte || ChannelType==ePVRTVarTypeSignedByteNorm || ChannelType==ePVRTVarTypeSignedFloat) { glInternalFormat=GL_COMPRESSED_SIGNED_R11_EAC; } else { glInternalFormat=GL_COMPRESSED_R11_EAC; } return; } case ePVRTPF_EAC_RG11: { if (ChannelType==ePVRTVarTypeSignedInteger || ChannelType==ePVRTVarTypeSignedIntegerNorm || ChannelType==ePVRTVarTypeSignedShort || ChannelType==ePVRTVarTypeSignedShortNorm || ChannelType==ePVRTVarTypeSignedByte || ChannelType==ePVRTVarTypeSignedByteNorm || ChannelType==ePVRTVarTypeSignedFloat) { glInternalFormat=GL_COMPRESSED_SIGNED_RG11_EAC; } else { glInternalFormat=GL_COMPRESSED_RG11_EAC; } return; } } } else { switch (ChannelType) { case ePVRTVarTypeUnsignedFloat: if (PixelFormat==PVRTGENPIXELID3('r','g','b',11,11,10) ) { glType=GL_UNSIGNED_INT_10F_11F_11F_REV; glFormat = GL_RGB; glInternalFormat=GL_R11F_G11F_B10F; return; } break; case ePVRTVarTypeSignedFloat: { switch (PixelFormat) { //HALF_FLOAT case PVRTGENPIXELID4('r','g','b','a',16,16,16,16): { glType=GL_HALF_FLOAT; glFormat = GL_RGBA; glInternalFormat=GL_RGBA; return; } case PVRTGENPIXELID3('r','g','b',16,16,16): { glType=GL_HALF_FLOAT; glFormat = GL_RGB; glInternalFormat=GL_RGB16F; return; } case PVRTGENPIXELID2('r','g',16,16): { glType=GL_HALF_FLOAT; glFormat = GL_RG; glInternalFormat=GL_RG16F; return; } case PVRTGENPIXELID1('r',16): { glType=GL_HALF_FLOAT; glFormat = GL_RED; glInternalFormat=GL_R16F; return; } case PVRTGENPIXELID2('l','a',16,16): { glType=GL_HALF_FLOAT; glFormat = GL_LUMINANCE_ALPHA; glInternalFormat=GL_LUMINANCE_ALPHA; return; } case PVRTGENPIXELID1('l',16): { glType=GL_HALF_FLOAT; glFormat = GL_LUMINANCE; glInternalFormat=GL_LUMINANCE; return; } case PVRTGENPIXELID1('a',16): { glType=GL_HALF_FLOAT; glFormat = GL_ALPHA; glInternalFormat=GL_ALPHA; return; } //FLOAT case PVRTGENPIXELID4('r','g','b','a',32,32,32,32): { glType=GL_FLOAT; glFormat = GL_RGBA; glInternalFormat=GL_RGBA32F; return; } case PVRTGENPIXELID3('r','g','b',32,32,32): { glType=GL_FLOAT; glFormat = GL_RGB; glInternalFormat=GL_RGB32F; return; } case PVRTGENPIXELID2('r','g',32,32): { glType=GL_FLOAT; glFormat = GL_RG; glInternalFormat=GL_RG32F; return; } case PVRTGENPIXELID1('r',32): { glType=GL_FLOAT; glFormat = GL_RED; glInternalFormat=GL_R32F; return; } case PVRTGENPIXELID2('l','a',32,32): { glType=GL_FLOAT; glFormat = GL_LUMINANCE_ALPHA; glInternalFormat=GL_LUMINANCE_ALPHA; return; } case PVRTGENPIXELID1('l',32): { glType=GL_FLOAT; glFormat = GL_LUMINANCE; glInternalFormat=GL_LUMINANCE; return; } case PVRTGENPIXELID1('a',32): { glType=GL_FLOAT; glFormat = GL_ALPHA; glInternalFormat=GL_ALPHA; return; } } break; } case ePVRTVarTypeUnsignedByteNorm: { glType = GL_UNSIGNED_BYTE; switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',8,8,8,8): { glFormat = GL_RGBA; if (ColourSpace==ePVRTCSpacesRGB) glInternalFormat=GL_SRGB8_ALPHA8; else glInternalFormat=GL_RGBA8; return; } case PVRTGENPIXELID3('r','g','b',8,8,8): { glFormat = GL_RGB; if (ColourSpace==ePVRTCSpacesRGB) glInternalFormat=GL_SRGB8; else glInternalFormat=GL_RGB8; return; } case PVRTGENPIXELID2('r','g',8,8): { glFormat = GL_RG; glInternalFormat=GL_RG8; return; } case PVRTGENPIXELID1('r',8): { glFormat = GL_RED; glInternalFormat=GL_R8; return; } case PVRTGENPIXELID2('l','a',8,8): { glFormat = GL_LUMINANCE_ALPHA; glInternalFormat=GL_LUMINANCE_ALPHA; return; } case PVRTGENPIXELID1('l',8): { glFormat = GL_LUMINANCE; glInternalFormat=GL_LUMINANCE; return; } case PVRTGENPIXELID1('a',8): { glFormat = GL_ALPHA; glInternalFormat=GL_ALPHA; return; } case PVRTGENPIXELID4('b','g','r','a',8,8,8,8): { glFormat = GL_BGRA_EXT; glInternalFormat=GL_BGRA_EXT; return; } } break; } case ePVRTVarTypeSignedByteNorm: { glType = GL_BYTE; switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',8,8,8,8): { glFormat = GL_RGBA; glInternalFormat=GL_RGBA8_SNORM; return; } case PVRTGENPIXELID3('r','g','b',8,8,8): { glFormat = GL_RGB; glInternalFormat=GL_RGB8_SNORM; return; } case PVRTGENPIXELID2('r','g',8,8): { glFormat = GL_RG; glInternalFormat=GL_RGB8_SNORM; return; } case PVRTGENPIXELID1('r',8): { glFormat = GL_RED; glInternalFormat=GL_R8_SNORM; return; } } break; } case ePVRTVarTypeUnsignedByte: { glType = GL_UNSIGNED_BYTE; switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',8,8,8,8): { glFormat = GL_RGBA_INTEGER; glInternalFormat=GL_RGBA8UI; return; } case PVRTGENPIXELID3('r','g','b',8,8,8): { glFormat = GL_RGB_INTEGER; glInternalFormat=GL_RGB8UI; return; } case PVRTGENPIXELID2('r','g',8,8): { glFormat = GL_RG_INTEGER; glInternalFormat=GL_RG8UI; return; } case PVRTGENPIXELID1('r',8): { glFormat = GL_RED_INTEGER; glInternalFormat=GL_R8UI; return; } } break; } case ePVRTVarTypeSignedByte: { glType = GL_BYTE; switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',8,8,8,8): { glFormat = GL_RGBA_INTEGER; glInternalFormat=GL_RGBA8I; return; } case PVRTGENPIXELID3('r','g','b',8,8,8): { glFormat = GL_RGB_INTEGER; glInternalFormat=GL_RGB8I; return; } case PVRTGENPIXELID2('r','g',8,8): { glFormat = GL_RG_INTEGER; glInternalFormat=GL_RG8I; return; } case PVRTGENPIXELID1('r',8): { glFormat = GL_RED_INTEGER; glInternalFormat=GL_R8I; return; } } break; } case ePVRTVarTypeUnsignedShortNorm: { switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',4,4,4,4): { glType = GL_UNSIGNED_SHORT_4_4_4_4; glFormat = GL_RGBA; glInternalFormat=GL_RGBA4; return; } case PVRTGENPIXELID4('r','g','b','a',5,5,5,1): { glType = GL_UNSIGNED_SHORT_5_5_5_1; glFormat = GL_RGBA; glInternalFormat=GL_RGB5_A1; return; } case PVRTGENPIXELID3('r','g','b',5,6,5): { glType = GL_UNSIGNED_SHORT_5_6_5; glFormat = GL_RGB; glInternalFormat=GL_RGB565; return; } } break; } case ePVRTVarTypeUnsignedShort: { glType = GL_UNSIGNED_SHORT; switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',16,16,16,16): { glFormat = GL_RGBA_INTEGER; glInternalFormat=GL_RGBA16UI; return; } case PVRTGENPIXELID3('r','g','b',16,16,16): { glFormat = GL_RGB_INTEGER; glInternalFormat=GL_RGB16UI; return; } case PVRTGENPIXELID2('r','g',16,16): { glFormat = GL_RG_INTEGER; glInternalFormat=GL_RG16UI; return; } case PVRTGENPIXELID1('r',16): { glFormat = GL_RED_INTEGER; glInternalFormat=GL_R16UI; return; } } break; } case ePVRTVarTypeSignedShort: { glType = GL_SHORT; switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',16,16,16,16): { glFormat = GL_RGBA_INTEGER; glInternalFormat=GL_RGBA16I; return; } case PVRTGENPIXELID3('r','g','b',16,16,16): { glFormat = GL_RGB_INTEGER; glInternalFormat=GL_RGB16I; return; } case PVRTGENPIXELID2('r','g',16,16): { glFormat = GL_RG_INTEGER; glInternalFormat=GL_RG16I; return; } case PVRTGENPIXELID1('r',16): { glFormat = GL_RED_INTEGER; glInternalFormat=GL_R16I; return; } } break; } case ePVRTVarTypeUnsignedIntegerNorm: { if (PixelFormat==PVRTGENPIXELID4('a','b','g','r',2,10,10,10)) { glType = GL_UNSIGNED_INT_2_10_10_10_REV; glFormat = GL_RGBA; glInternalFormat=GL_RGB10_A2; return; } break; } case ePVRTVarTypeUnsignedInteger: { glType = GL_UNSIGNED_INT; switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',32,32,32,32): { glFormat = GL_RGBA_INTEGER; glInternalFormat=GL_RGBA32UI; return; } case PVRTGENPIXELID3('r','g','b',32,32,32): { glFormat = GL_RGB_INTEGER; glInternalFormat=GL_RGB32UI; return; } case PVRTGENPIXELID2('r','g',32,32): { glFormat = GL_RG_INTEGER; glInternalFormat=GL_RG32UI; return; } case PVRTGENPIXELID1('r',32): { glFormat = GL_RED_INTEGER; glInternalFormat=GL_R32UI; return; } case PVRTGENPIXELID4('a','b','g','r',2,10,10,10): { glType = GL_UNSIGNED_INT_2_10_10_10_REV; glFormat = GL_RGBA_INTEGER; glInternalFormat=GL_RGB10_A2UI; return; } } break; } case ePVRTVarTypeSignedInteger: { glType = GL_INT; switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',32,32,32,32): { glFormat = GL_RGBA_INTEGER; glInternalFormat=GL_RGBA32I; return; } case PVRTGENPIXELID3('r','g','b',32,32,32): { glFormat = GL_RGB_INTEGER; glInternalFormat=GL_RGB32I; return; } case PVRTGENPIXELID2('r','g',32,32): { glFormat = GL_RG_INTEGER; glInternalFormat=GL_RG32I; return; } case PVRTGENPIXELID1('r',32): { glFormat = GL_RED_INTEGER; glInternalFormat=GL_R32I; return; } } break; } default: { } } } //Default (erroneous) return values. glType = glFormat = glInternalFormat = 0; }
/*!*********************************************************************** @Function: PVRTGetOGLESTextureFormat @Input: sTextureHeader @Modified: internalformat @Modified: format @Modified: type @Description: Gets the OpenGLES equivalent values of internal format, format and type for this texture header. This will return any supported OpenGLES texture values, it is up to the user to decide if these are valid for their current platform. *************************************************************************/ static const void PVRTGetOGLESTextureFormat(const PVRTextureHeaderV3& sTextureHeader, PVRTuint32& internalformat, PVRTuint32& format, PVRTuint32& type) { PVRTuint64 PixelFormat = sTextureHeader.u64PixelFormat; EPVRTVariableType ChannelType = (EPVRTVariableType)sTextureHeader.u32ChannelType; //Initialisation. Any invalid formats will return 0 always. format = 0; type = 0; internalformat=0; //Get the last 32 bits of the pixel format. PVRTuint64 PixelFormatPartHigh = PixelFormat&PVRTEX_PFHIGHMASK; //Check for a compressed format (The first 8 bytes will be 0, so the whole thing will be equal to the last 32 bits). if (PixelFormatPartHigh==0) { //Format and type == 0 for compressed textures. switch (PixelFormat) { case ePVRTPF_PVRTCI_2bpp_RGB: { internalformat=GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; return; } case ePVRTPF_PVRTCI_2bpp_RGBA: { internalformat=GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; return; } case ePVRTPF_PVRTCI_4bpp_RGB: { internalformat=GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; return; } case ePVRTPF_PVRTCI_4bpp_RGBA: { internalformat=GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; return; } default: return; } } else { switch (ChannelType) { case ePVRTVarTypeUnsignedByteNorm: { type = GL_UNSIGNED_BYTE; switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',8,8,8,8): { format = internalformat = GL_RGBA; return; } case PVRTGENPIXELID3('r','g','b',8,8,8): { format = internalformat = GL_RGB; return; } case PVRTGENPIXELID2('l','a',8,8): { format = internalformat = GL_LUMINANCE_ALPHA; return; } case PVRTGENPIXELID1('l',8): { format = internalformat = GL_LUMINANCE; return; } case PVRTGENPIXELID1('a',8): { format = internalformat = GL_ALPHA; return; } case PVRTGENPIXELID4('b','g','r','a',8,8,8,8): { format = internalformat = GL_BGRA; return; } default: return; } break; } case ePVRTVarTypeUnsignedShortNorm: { switch (PixelFormat) { case PVRTGENPIXELID4('r','g','b','a',4,4,4,4): { type = GL_UNSIGNED_SHORT_4_4_4_4; format = internalformat = GL_RGBA; return; } case PVRTGENPIXELID4('r','g','b','a',5,5,5,1): { type = GL_UNSIGNED_SHORT_5_5_5_1; format = internalformat = GL_RGBA; return; } case PVRTGENPIXELID3('r','g','b',5,6,5): { type = GL_UNSIGNED_SHORT_5_6_5; format = internalformat = GL_RGB; return; } default: return; } break; } default: return; } } }