Skip to content

iOS Texture Compression

RayBatts edited this page May 4, 2012 · 7 revisions

Now that MonoGame supports PVR compressed textures for iOS, you may find that your textures are no longer working. There are a couple of extra steps that need to be taken in order to build the appropriate content for the platform.

While this document describes the process for iOS, note that PVR textures are also supported on some Android devices. There will be further work to implement PVR compressed texture's for the Android platform in the future.

There are a couple of steps for generating and using compressed textures on iOS

  1. Build the appropriate content processors
  2. Create a project with an IOS Build Configuration
  3. Reference the new content processors in your content project
  4. Build new, compressed content

Build Appropriate Content Processors:

Open the MonoGame.ContentPipeline/ContentProcessors/MonoGameContentProcessors.sln file in Visual Studio and build it.

(Note: If you are using an Express version of Visual Studio, you may not be able to open this solution as it has both C# and C++ projects in it. If this is the case, build the projects separately and grab their .dll's for later).

Create a project for building iOS Content

There are other ways to do this, but we found that creating a separate "dummy" project was quickest and easiest.

For this method you will have your normal MonoGame/iOS solution for your game as well as a second solution solely for building iOS-appropriate content. I copied the original MyXNAGame.sln for our game and replaced the actual MyXNAGame.csproj with a new, empty C# project for a library. Add a content reference to your content project in the new dummy project so you can build content with this new solution.

After this is done, open the new, dummy.csproj in a text editor and add a new PropertyGroup with it's Configuration set to "IOS" as well as it's output path. It should look something like this.

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'IOS|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\IOS\</OutputPath>
<DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants> ... etc etc

Make sure that your solution has set the dummy project to use this new build configuration. Open your Configuration Manager in Visual Studio and make sure that the dummy project's configuration is set to "IOS". I found it easy to create a build configuration for the solution itself in the configuration manager, but you may choose not to.

Reference the new content processors in your content project

Now you need to set up your content project to use these new content processors. First add a reference to your game's Content Project to the .dll that is built by the MonoGameContentProcessors project.

(Note, this project requires the PVRTexLibC.dll. This was built in Step #1 when you built the MonoGameContentProcessors project. Make sure either both projects are referenced, or both .dll's are in the same folder.)

Close Visual Studio and open up your Content Project in a text editor. You'll want to replace any textures that use XNA's TextureProcessor with the new MGTextureProcessor.

Build new compressed content:

Reopen your new "content building" project and make sure that it's build configuration is set to IOS. (Or at the very least, that the current solution's configuration allows the dummy project to build for "IOS"). Do a full rebuild on this project. If you're working with a lot of textures this part may take a little bit.

When this is finished you should have a Content folder in your bin/IOS/ folder with PVR compressed textures. Copy these to the appropriate place in your iOS application's package.

Notes: ResizePowerOfTwo is not implemented in MGTextureProcessor.

PVRCompressed textures must be square, power of two textures If you're using a the stock XNA Model content processor, you'll need to override it's Process to use our Material processor rather than the stock XNA one.

It's safe to build for other platforms using the same modified content project. If you're not building for IOS, it will provide the same functionality that the stock class did before.

Because of how PVR Texture Compression works, you may find that monochrome, or images without a lot of color changes appear corrupted. Your only option is to not compress the texture. You can set a Texture to not compress in IOS by changing it's "CompressionMode" property in it's content processor. This allows you to DXT compress a texture for Windows platforms but leave it uncompressed for IOS.

Clone this wiki locally