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 ?
6
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); } }
…
}
2