The Content Pipeline
As we described in the introduction, the XNA Content Pipeline’s purpose is to transform asset files (content) in to a form most readily useable by our games. It is implemented as a separate build step that is run every time we compile our game. In fact, each XNA game is actually two projects - the Content project, and the Game project.
The pipeline is broken up into several steps:
- Importing the asset data
- Processing the asset data
- Serializing the asset data
- Loading the serialized asset data
You can see the process here:
Each of these steps is accomplished by a different class, and the data passed between the steps is also typically done as an object (defined by a class).
The two projects share a single file - the .xnb file generated from the content. This is essentially an object that has been serialized as binary data by the content serializer class, and will be deserialized back into an object by the content loader class.
An important aspect of the serialization process is that the object that is serialized into a .xnb file and the one deserialized from it don’t have to be the defined by the same class! For example, in the content pipeline simple 2d textures are represented by a
Texture2DContent instance, while in runtime projects we load the serialized data into a
Texture2D instance. The key is that the serialized data is the same for both.