2

For a game project, I have a couple of textures coming from multiple sources and I need to pack all these within a single texture atlas.

Example for a racing game circuit, there are textures for :

  • the sky
  • the track
  • the various objects in environment

Each of the aforementioned item is a catalog containing many textures.

My problem is the following:

How should I design the ins and outs of this object, knowing that I must be able to add textures to it, then retrieve the region it has been placed in ?

I first came up with the idea using a simple string but did not like that approach regarding the usage of it throughout a code base.

Is this a case of over-engineering from me or would a simple string be sufficient for such job ?

  • 1
    Please, don't ever use string for data that is not composed of characters. – svick May 7 '15 at 0:24
  • Hence my question :D – Aybe May 7 '15 at 0:26
  • I would consider using an existing tool, like this one. – svick May 7 '15 at 0:29
  • It seems that for this particular case strings are a good fit or the only viable option, e.g. this tool generates a list of string/region pair ... like all the others in fact. I guess I'm just over-engineering ! – Aybe May 7 '15 at 0:38
  • From your question, I assumed you wanted to use the string to store the texture atlas itself, the tool I linked to uses it just to describe it. And it's still not quite clear to me what string you're talking about. – svick May 7 '15 at 0:41
1

I would first start from the interface. I think a good interface for your texture atlas would be something like:

class TextureAtlas
{
    public Texture Sky { get; }
    public Texture Track { get; }
    public Texture SomeObjectInEnvironment { get; }
}

Since you're probably going to use some tool to generate the texture atlas and that tool will provide you with the information about the position of each texture in the atlas, you could use that to generate the code of the TextureAtlas type (and to do that, you could use T4).

The generated code could look something like:

class TextureAtlas
{
    private Texture m_atlas;

    public Texture Sky { get { return m_atlas.Subtexture(1000, 0, 256, 512); } }
    …
}
  • Thanks, it's not what I was looking for but it is explanative nonetheless. That's my fault, should have expressed myself better: I generate all by code (by necessity), thus I do get these positions myself and this was that very first step. Since there's no notion of high-levelness in underlying formats (hence this need) I just ended up using a simple container with .Tag and .Name properties, quick & effective though I do have to keep a few constants in the class for names, subitems indices being in vertices. There will be less than 10 names so it's okay + I like the fact that it's generic. – Aybe May 7 '15 at 1:50
  • EDIT: actually I just managed to entirely avoid typing any string as they are fetched from the .Name which is certain to be unique so I guess it'll do ! – Aybe May 7 '15 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.