Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psmobile small fixes #3283

Merged
merged 3 commits into from
Dec 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MonoGame.Framework/Graphics/Effect/BasicEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class BasicEffect : Effect, IEffectMatrices, IEffectLights, IEffectFog
#if DIRECTX
"Microsoft.Xna.Framework.Graphics.Effect.Resources.BasicEffect.dx11.mgfxo"
#elif PSM
"MonoGame.Framework.PSMobile.PSSuite.Graphics.Resources.BasicEffect.cgx" //FIXME: This shader is totally incomplete
"Microsoft.Xna.Framework.PSSuite.Graphics.Resources.BasicEffect.cgx" //FIXME: This shader is totally incomplete
#else
"Microsoft.Xna.Framework.Graphics.Effect.Resources.BasicEffect.ogl.mgfxo"
#endif
Expand Down
16 changes: 12 additions & 4 deletions MonoGame.Framework/Graphics/Effect/Effect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,31 @@ public Effect (GraphicsDevice graphicsDevice, byte[] effectCode)
// This might need to change slightly if/when we support
// shared constant buffers as 'new' should return unique
// effects without any shared instance state.


#if PSM
var effectKey = MonoGame.Utilities.Hash.ComputeHash(effectCode);
int headerSize=0;
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the goal of this alternate cache block? What is it fixing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tom,

I think that the problem is that the PSM shaders are not MGFX compliant, thus accessing to ReadHeader crashes badly. Also, there's no access to header.HeaderSize.

Would it be better setting variables first and then using the same code for both for the effect caching like this? http://pastebin.com/85LRW03w

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better setting variables first and then using the same code

Yes... the less stuff in #if blocks the better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

//Read the header
MGFXHeader header = ReadHeader(effectCode);
var effectKey = header.EffectKey;
int headerSize = header.HeaderSize;
#endif

// First look for it in the cache.
//
Effect cloneSource;
if (!EffectCache.TryGetValue(header.EffectKey, out cloneSource))
if (!EffectCache.TryGetValue(effectKey, out cloneSource))
{
using (var stream = new MemoryStream(effectCode, header.HeaderSize, effectCode.Length - header.HeaderSize, false))
using (var stream = new MemoryStream(effectCode, headerSize, effectCode.Length - headerSize, false))
using (var reader = new BinaryReader(stream))
{
// Create one.
cloneSource = new Effect(graphicsDevice);
cloneSource.ReadEffect(reader);

// Cache the effect for later in its original unmodified state.
EffectCache.Add(header.EffectKey, cloneSource);
EffectCache.Add(effectKey, cloneSource);
}
}

Expand Down
9 changes: 8 additions & 1 deletion MonoGame.Framework/Graphics/SpriteBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ public void Begin (SpriteSortMode sortMode, BlendState blendState, SamplerState
_samplerState = samplerState ?? SamplerState.LinearClamp;
_depthStencilState = depthStencilState ?? DepthStencilState.None;
_rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise;


#if PSM
if(effect == null)
_effect = _spriteEffect;
else
_effect = effect;
#else
_effect = effect;
#endif

_matrix = transformMatrix;

Expand Down
3 changes: 3 additions & 0 deletions MonoGame.Framework/Media/Song.PSM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public sealed partial class Song : IEquatable<Song>, IDisposable

private void PlatformInitialize(string fileName)
{
// PSM can only load MP3 files, but XNA XNBs use always WMA.
if (fileName!=null && Path.GetExtension(fileName).ToLower()==".wma") fileName=Path.ChangeExtension (fileName,"mp3");

_bgm = new Bgm(fileName);
}

Expand Down