First off, I can’t use Monogames Pipeline because I am creating a game engine, there will be a folder of textures(so .png’s .jpegs etc). I have asked a similar question before about White Pixels with Texture2D.FromStream() and someone posted that they just added textures directly to the pipeline and well I have no clue how to do that at run time; So I am left with From Stream.
Here is the code, it gets rid of the whitepixels that FromStream() comes with:
public static Texture2D ConvertTexture(string filePath, CludoGame game) {
Texture2D texture = null;
try {
using(FileStream d = new FileStream(filePath, FileMode.Open)) {
texture = Texture2D.FromStream(game.GraphicsDevice, d);
Color[] data = new Color[texture.Width * texture.Height];
texture.GetData(data);
for(int i = 0; i != data.Length; ++i)
data[i] = Color.FromNonPremultiplied(data[i].ToVector4());
texture.SetData(data);
data = null;
}
} catch(System.IO.DirectoryNotFoundException) {
if(File.Exists(filePath)) {
throw new ArgumentException(“Access to: " + filePath + " is denied!”);
} else {
throw new ArgumentException(“File: " + filePath + " doesn’t exist! Make sure the file isn’t just a directory, or you have typed the filePath correctly.”);
}
}
return texture;
}
On the line of texture = Texture2D.FromStream(game.GraphicsDevice, d); the ram usage jumps up(around 30 mb’s) for a single texture. Remember that games use a lot of textures and this happens for EVERY texture(The texture is 10mb but using the monogame pipeline in another game it doesn’t do this jump…). So what can I do from this point? I’m really lost.
Thanks,
Darin/Nullz.