Reputation: 65
I want to load an effect from a file with was already compiled to xnb.
I can use this in XNA 3.0
Effect (GraphicsDevice, Stream, CompilerOptions, EffectPool)
But I don't know how to do that in XNA 4.0, since there is no such constructor.
Any help will be much appreciated.
Finally I solve the problem by the new constructor in XNA 4.0:
public Effect(GraphicsDevice graphicsDevice, byte[] effectCode);
That is
Stream bumpStream = ... //get the file stream
byte[] buffer = new byte[bumpStream.Length];
bumpStream.Read(buffer, 0, buffer.Length);
myFx = new Effect(graphicsDevice, buffer)
Done!
Upvotes: 1
Views: 635
Reputation: 4708
If you want to load a file that's already been compiled to Xnb, then it's easy.
Here's a method that can use a FileStream
:
public static Effect FromStream(this Effect e, ContentManager content, FileStream stream)
{
return content.Load<Effect>(stream.Name);
}
You may have to do some file path parsing, but it should work.
Of course you could just skip the whole extension method thing, and put the code directly into your Game.cs
file.
Upvotes: 0