XNA Creators Club Online
Page 1 of 1 (13 items)
Sort Posts: Previous Next

Content Pipeline Required?

Last post 05/11/2009 16:58 by Shawn Hargreaves. 12 replies.
  • 10/09/2009 1:31

    Content Pipeline Required?

    Ok, so I'm fairly new to XNA, and have run into a fundamental question.

    So, in a normal game, you might have a folder called "textures" sitting beside your game exe with all of your textures in it.
    When the game wants a texture, you simply load it from file.

    Now, I know you can still do this in XNA, using Texture2D.FromFile - but apparently this will not work on xbox.

    So this brings up a few questions for me...

    a) How do you get content into your game for the xbox? Do you literally fill the Content up with thousands of image, sound, model, etc. files?

    b) With files being loaded from a folder, you could simply say "load all files in this folder". Can you do something similar with the Content Pipeline? I note you can create folders in there, so I imagine this should be possible.

    c) What about files of types that aren't supported by the Content Pipeline, such as your own custom formats for storing information about units or weapons, etc.?

    d) When you build your game, it creates an xnb file per content file - what if you wanted to compress all of your textures in a single file, etc.?

    e) How are you supposed to get new content into the game, such as downloadable content, maps, mods, etc.?

    f) If I want to release a game on windows and xbox, without much modification of the code, how can I do this?

    I just don't understand how this could be a good method of managing content... perhaps someone can explain it to me a little better?

    Thanks
  • 10/09/2009 1:45 In reply to

    Re: Content Pipeline Required?

    Answer
    Reply Quote
    NightCabbage:
    a) How do you get content into your game for the xbox? Do you literally fill the Content up with thousands of image, sound, model, etc. files?
    I don't know about thousands, but yes, your content generally goes into the Content project.

    NightCabbage:
    b) With files being loaded from a folder, you could simply say "load all files in this folder". Can you do something similar with the Content Pipeline? I note you can create folders in there, so I imagine this should be possible.
    Sure. You can do something like this:

    string[] files = Directory.GetFiles(Path.Combine(StorageContainer.TitleLocation, "Content/Textures")); 
    foreach (var f in files) 
       Texture2D texture = Content.Load<Texture2D>(f); 
       // do something with the texture 

    NightCabbage:
    c) What about files of types that aren't supported by the Content Pipeline, such as your own custom formats for storing information about units or weapons, etc.?
    If you right click and choose the properties for a file, you can set the Build Action property to None and the Copy property to Copy if Newer and have the file copied over as is. Or you an learn about custom content importers and processors and put the file through the content pipeline if you want.

    NightCabbage:
    d) When you build your game, it creates an xnb file per content file - what if you wanted to compress all of your textures in a single file, etc.?
    You'll have to make a custom post-build action. If you want an example, I once maintained a project called EasyZip that scooped up all content files and put them into a ZIP file. It's not updated, but you can see all the code if you want to figure out how to do something similar: http://easyzip.codeplex.com.

    NightCabbage:
    e) How are you supposed to get new content into the game, such as downloadable content, maps, mods, etc.?
    DLC is not supported for Xbox LIVE Indie Games. You can update your game, put it through peer review, and your customers will be notified of the new update when they start your game.

    NightCabbage:
    f) If I want to release a game on windows and xbox, without much modification of the code, how can I do this?
    Pretty easily, though you'll need to ask more specific questions. In general, 90% or so of your code should be just fine going from Windows to Xbox 360. The XNA Framework does a good job of being cross platform.

    NightCabbage:
    I just don't understand how this could be a good method of managing content... perhaps someone can explain it to me a little better?
    The main benefit is preprocessing. A PNG file requires that it be read, decompressed (since PNGs are compressed), and then converted into a more GPU friendly format. The content pipeline takes that PNG at build time, does that conversion, and writes it to a compressed (if you're in release mode) XNB file which is that more GPU friendly format. This means when you go to load that in at runtime, your game just reads in the bytes and hands it to the GPU. It's more work at build time in order to reduce load times.

    You can choose to ignore all of the content pipeline if you really want, even on Xbox 360. It's 100% optional. However there are no canned methods like Texture2D.FromFile on Xbox 360 so you'd have to write your own code for reading those files in at runtime. I know someone did that for JPEG files at one point. There are some things you can't do this for (namely audio), but for all graphical assets (models, textures, and such) you could write your own code to load from whatever file formats you wanted at runtime.

    It seems weird when you start, but once you think about it it starts to make sense. Since you can't really change the content at runtime, why do you need to deploy PNG or whatever? Why not have the content pipeline do some of the work at build time to optimize your game's load times? On PC there's more argument if you plan to support modding or just want to let people poke around, but on Xbox 360, there's not really any reason not to use the content pipeline to optimize your game's content and loading.
  • 10/09/2009 1:59 In reply to

    Re: Content Pipeline Required?

    That makes a lot of sense - thank you Nick.

    I'll have a ponder on this and see how to restructure my thinking towards this type of design.

    Cheers
    Cabz
  • 11/09/2009 6:53 In reply to

    Re: Content Pipeline Required?

    Ok, so quick question...

    For my game, I'm going to need some pretty big textures.

    So I intend to do some tiling :)

    But I was wondering, what is the maximum "safe" texture size these days?
    (that will work nicely on everyone's video cards, and the xbox, etc.)

    Cheers
    Cabz
  • 11/09/2009 14:09 In reply to

    Re: Content Pipeline Required?

    Answer
    Reply Quote
    On the Xbox you can use up to 8148x8148 (or whatever power of two is nearest to that). On PC the max size is all GPU dependent. You'll need to figure out what your desired minimum specs are and then figure out what the maximum texture size for those GPUs is.
  • 11/09/2009 14:14 In reply to

    Re: Content Pipeline Required?

    Answer
    Reply Quote
    NightCabbage:
    But I was wondering, what is the maximum "safe" texture size these days?
    (that will work nicely on everyone's video cards, and the xbox, etc.)


    2048.

    XNA Framework Developer - blog - homepage
  • 17/09/2009 8:29 In reply to

    Re: Content Pipeline Required?

    Shawn Hargreaves:
    NightCabbage:
    But I was wondering, what is the maximum "safe" texture size these days?
    (that will work nicely on everyone's video cards, and the xbox, etc.)


    2048.



    Brilliant, thanks :)

    I note that even the original GeForce 256 supports this - nice.
  • 19/09/2009 10:42 In reply to

    Re: Content Pipeline Required?

    Very quick question...

    Is render to texture supported on all video cards?

    Is it safe to rely on this feature in a game?

    Thanks
  • 21/09/2009 19:16 In reply to

    Re: Content Pipeline Required?

    Answer
    Reply Quote
    NightCabbage:
    Is render to texture supported on all video cards?


    Yes.
    XNA Framework Developer - blog - homepage
  • 05/11/2009 1:24 In reply to

    Re: Content Pipeline Required?

    Hello again :)

    Ok, so I know that you have to use the content pipeline if you are developing for the xbox 360 - however my game is just being developed for the PC.

    So I am safe to use things like Texture2D.FromFile() to load my textures, instead of Content.Load().

    I now have 2 questions...

    a) Is there a similar way to load and play sound files? Or am I forced to use xact and the content pipeline for this?
    I've seen that I can not use xact by using SoundEffect - but can I load a wave file without the content pipeline?

    b) If I have some texture files in a zip file, how could I then load them for use (not using the content pipeline)?
    ie. I couldn't use Texture2D.FromFile() as I will be loading the texture from memory (after the zip has been extracted into memory).

    And I suppose the other question would be... is it a bad idea to try to use XNA without the content pipeline?
    The game I am making will be importing custom files (maps, including textures, etc.) so I can't use the content pipeline for this.

    Thanks!
  • 05/11/2009 1:57 In reply to

    Re: Content Pipeline Required?

    Answer
    Reply Quote
    NightCabbage:
    Ok, so I know that you have to use the content pipeline if you are developing for the xbox 360


    Not true.  For graphics, the Content Pipeline is entirely optional on all platforms.  It is required for building sound data however.  This is the same on Xbox 360 as it is on Windows.

    NightCabbage:
    but can I load a wave file without the content pipeline?


    Not possible.

    NightCabbage:
    If I have some texture files in a zip file, how could I then load them for use (not using the content pipeline)?


    You will have to find or write some code that loads the texture from whatever file format you are storing it in, decoding the image file format and extracting the pixel values. Then create a Texture2D object, and use SetData to store your pixel values into it.

    This is exactly the same thing the Content Pipeline does when it comes to load a texture from .xnb format. You'll just have to write your own version of this functionality that loads from whatever other format you are using.

    NightCabbage:
    And I suppose the other question would be... is it a bad idea to try to use XNA without the content pipeline?


    Not necessarily a bad idea, but it's going to be a lot of work since you will be writing all your own asset loading code, as opposed to using our built in version.
    XNA Framework Developer - blog - homepage
  • 05/11/2009 2:06 In reply to

    Re: Content Pipeline Required?

    Thank you Shawn!

    Shawn Hargreaves:
    For graphics, the Content Pipeline is entirely optional on all platforms

    Oh I didn't know that... may I ask how you can load a texture on the xbox 360 without the content pipeline?

    Shawn Hargreaves:
    Not possible.

    Ok no problems - so I'll use something like System.Media.SoundPlayer to play sounds I guess?

    Shawn Hargreaves:
    This is exactly the same thing the Content Pipeline does when it comes to load a texture from .xnb format

    Excellent to hear this :)

    Shawn Hargreaves:
    but it's going to be a lot of work since you will be writing all your own asset loading code, as opposed to using our built in version

    Agreed - I'd love to use the existing XNA code but I don't think it will do what my project requires. But still, XNA is going to save me a lot of time compared to making my project in C++.
  • 05/11/2009 16:58 In reply to

    Re: Content Pipeline Required?

    Answer
    Reply Quote
    NightCabbage:
    may I ask how you can load a texture on the xbox 360 without the content pipeline?


    Texture2D texture = new Texture2D(...);
    Color[] data = new Color[size];
    // do whatever file IO is necessary to read your chosen image format into the data array
    texture.SetData(data);
    XNA Framework Developer - blog - homepage
Page 1 of 1 (13 items) Previous Next