public PVRTexture(PVRTextureHeader headerIn, IntPtr data) { texture = pvrttCreateTextureFromHeader(headerIn.header, data); }
private SiliconStudio.Paradox.Graphics.PixelFormat RetrieveFormatFromNativeData(PVRTextureHeader header) { SiliconStudio.Paradox.Graphics.PixelFormat format = header.GetFormat(); if (format == SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_Float) { switch (header.GetChannelType()) { case EPVRTVariableType.ePVRTVarTypeFloat: return SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_Float; case EPVRTVariableType.ePVRTVarTypeUnsignedInteger: return SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_UInt; case EPVRTVariableType.ePVRTVarTypeSignedInteger: return SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_SInt; } } else if(format == SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UNorm) { switch (header.GetChannelType()) { case EPVRTVariableType.ePVRTVarTypeUnsignedShortNorm: return SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UNorm; case EPVRTVariableType.ePVRTVarTypeUnsignedShort: return SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UInt; case EPVRTVariableType.ePVRTVarTypeSignedShortNorm: return SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SNorm; case EPVRTVariableType.ePVRTVarTypeSignedShort: return SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SInt; } } else if(format == SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm) { switch (header.GetChannelType()) { case EPVRTVariableType.ePVRTVarTypeUnsignedByteNorm: { if (header.GetColourSpace() == EPVRTColourSpace.ePVRTCSpacelRGB) return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm; else return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb; } case EPVRTVariableType.ePVRTVarTypeUnsignedByte: return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UInt; case EPVRTVariableType.ePVRTVarTypeSignedByteNorm: return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SNorm; case EPVRTVariableType.ePVRTVarTypeSignedByte: return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SInt; } } return format; }
public PVRTexture(PVRTextureHeader headerIn, IntPtr data) { texture = pvrttCreateTextureFromHeader(headerIn.header, data); }
/// <summary> /// Exports the specified image. /// </summary> /// <param name="image">The image.</param> /// <param name="libraryData">The library data.</param> /// <param name="export">The export request.</param> private void Export(TexImage image, PvrTextureLibraryData libraryData, ExportRequest request) { Log.Info("Exporting to " + request.FilePath + " ..."); if (request.MinimumMipMapSize > 1) // if a mimimun mipmap size was requested { int newMipMapCount = image.MipmapCount; for (int i = image.MipmapCount - 1; i > 0; --i) // looking for the mipmap level corresponding to the minimum size requeted. { if (libraryData.Header.GetWidth((uint)i) >= request.MinimumMipMapSize || libraryData.Header.GetHeight((uint)i) >= request.MinimumMipMapSize) { break; } --newMipMapCount; } // Creating a new texture corresponding to the requested mipmap levels PVRTextureHeader header = new PVRTextureHeader(RetrieveNativeFormat(image.Format), image.Height, image.Width, image.Depth, newMipMapCount, image.ArraySize, image.FaceCount); PVRTexture texture = new PVRTexture(header, IntPtr.Zero); try { for (uint i = 0; i < image.FaceCount; ++i) { for (uint j = 0; j < image.ArraySize; ++j) { for (uint k = 0; k < newMipMapCount; ++k) { Core.Utilities.CopyMemory(texture.GetDataPtr(k, j, i), libraryData.Texture.GetDataPtr(k, j, i), (int)libraryData.Header.GetDataSize((int)k, false, false)); } } } } catch (AccessViolationException e) { texture.Dispose(); Log.Error("Failed to export texture with the mipmap minimum size request. ", e); throw new TextureToolsException("Failed to export texture with the mipmap minimum size request. ", e); } // Saving the texture into a file and deleting it texture.Save(request.FilePath); texture.Dispose(); } else { libraryData.Texture.Save(request.FilePath); } image.Save(request.FilePath); }