Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8617e1a
Implement GraphicsDevice's DepthStencilState, RasterizerState, Textur…
kg Apr 1, 2013
3eac67a
Correct the number of texture stages on PlayStation Mobile.
kg Feb 10, 2013
59b40d2
Implement DepthBufferEnable and StencilEnable on PlayStation Mobile.
kg Feb 10, 2013
eb48c74
Add missing Enable calls on PlayStation Mobile
kg Apr 1, 2013
1408647
Implement GraphicsDevice.Viewport on PlayStation Mobile
kg Feb 10, 2013
03c383e
Get Effect and EffectParameter closer to actually working and remove …
kg Feb 10, 2013
b9063f3
Fix EffectParameter.InternalSet not being copied during cloning
kg Feb 10, 2013
f9fd6d9
The PSM effect reader should not be setting arbitrary states on effec…
kg Feb 10, 2013
c765c35
Add missing PSM ifdef around InternalSet for EffectParameter
kg Mar 24, 2013
ffbaba2
Merge branch 'psm_effect_fixes' into develop
kg Apr 1, 2013
4235eb5
Merge branch 'psm_input_fixes' into develop
kg Apr 1, 2013
2beac52
Remove the samples and starter kits submodules since we don't want th…
kg Apr 1, 2013
3a73669
More hacks to make it possible to use SpriteFont without SpriteBatch.
kg Feb 10, 2013
d8e37ff
Expose SpriteFont.Texture
kg Feb 10, 2013
7a44391
Make PSSHelper public
kg Feb 11, 2013
5f71276
Implement left-side overhang compensation for the first character of …
kg Feb 12, 2013
6abfc20
Add a workaround for MonoGame not properly setting states on the PSM …
kg Feb 12, 2013
ad4257a
Make various internals accessible so that Sully can run.
kg Apr 1, 2013
e7db705
Fix GraphicsDevice.SetRenderTarget and GraphicsDevice.SetRenderTarget…
kg Apr 1, 2013
c79eab8
Add an interactive test case for issue #1355.
kg Apr 29, 2013
9ce6a01
Fix DrawInto not properly handling left side overhang of characters.
kg Apr 29, 2013
520409f
Fixed a bug that prevented Texture2D (on PSM) from properly disposing…
ustor Jul 7, 2014
50c1b89
Disabled tracking of EveryPsmTextureEver.
ustor Jul 12, 2014
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
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
[submodule "ThirdParty/Libs"]
path = ThirdParty/Libs
url = https://github.com/kungfubanana/MonoGame-Dependencies.git
[submodule "Samples"]
path = Samples
url = https://github.com/CartBlanche/MonoGame-Samples.git
[submodule "StarterKits"]
path = StarterKits
url = https://github.com/kungfubanana/MonoGame-StarterKits.git
[submodule "ThirdParty/Kickstart"]
path = ThirdParty/Kickstart
url = https://github.com/OutOfOrder/MonoKickstart.git
1 change: 1 addition & 0 deletions MonoGame.Framework/Content/ContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public virtual T Load<T>(string assetName)
{
return (T)asset;
}
else { throw new Exception("Attempted to Load an asset (with ContentManager) that already exists, but as a different type! This would cause an unmanaged memory leak, so it's not allowed."); }
}

// Load the asset.
Expand Down
69 changes: 47 additions & 22 deletions MonoGame.Framework/Graphics/Effect/Effect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ private void Clone(Effect cloneSource)
break;
}
}

// HACK
if (CurrentTechnique == null)
CurrentTechnique = Techniques[0];

// Take a reference to the original shader list.
_shaderList = cloneSource._shaderList;
Expand Down Expand Up @@ -487,32 +491,14 @@ private static EffectParameterCollection ReadParameters(BinaryReader reader)
#else //PSM
internal void ReadEffect(BinaryReader reader)
{
var effectPass = new EffectPass(this, "Pass", null, null, BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullNone, new EffectAnnotationCollection());
var effectPass = new EffectPass(this, "Pass", null, null, null, null, null, new EffectAnnotationCollection());
effectPass._shaderProgram = new ShaderProgram(reader.ReadBytes((int)reader.BaseStream.Length));
var shaderProgram = effectPass._shaderProgram;
Parameters = new EffectParameterCollection();
for (int i = 0; i < shaderProgram.UniformCount; i++)
{
Parameters.Add(EffectParameterForUniform(shaderProgram, i));
}

#warning Hacks for BasicEffect as we don't have these parameters yet
Parameters.Add (new EffectParameter(
EffectParameterClass.Vector, EffectParameterType.Single, "SpecularColor",
3, 1, "float3",
new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[3]));
Parameters.Add (new EffectParameter(
EffectParameterClass.Scalar, EffectParameterType.Single, "SpecularPower",
1, 1, "float",
new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), 0.0f));
Parameters.Add (new EffectParameter(
EffectParameterClass.Vector, EffectParameterType.Single, "FogVector",
4, 1, "float4",
new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));
Parameters.Add (new EffectParameter(
EffectParameterClass.Vector, EffectParameterType.Single, "DiffuseColor",
4, 1, "float4",
new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]));

Techniques = new EffectTechniqueCollection();
var effectPassCollection = new EffectPassCollection();
Expand All @@ -534,27 +520,66 @@ internal EffectParameter EffectParameterForUniform(ShaderProgram shaderProgram,

//EffectParameter.Semantic => COLOR0 / POSITION0 etc

EffectParameter result = null;

//FIXME: bufferOffset in below lines is 0 but should probably be something else
switch (type)
{
case ShaderUniformType.Float4x4:
return new EffectParameter(
result = new EffectParameter(
EffectParameterClass.Matrix, EffectParameterType.Single, name,
4, 4, "float4x4",
new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4 * 4]);
result.InternalSet = (p, sp) => {
var pssm = PSSHelper.ToPssMatrix4((float[])p.Data);
pssm = pssm.Transpose();
sp.SetUniformValue(index, ref pssm);
};
break;
case ShaderUniformType.Float:
result = new EffectParameter(
EffectParameterClass.Scalar, EffectParameterType.Single, name,
1, 1, "float",
new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[1]);
result.InternalSet = (p, sp) =>
sp.SetUniformValue(index, (float)p.Data);
break;
case ShaderUniformType.Float2:
result = new EffectParameter(
EffectParameterClass.Vector, EffectParameterType.Single, name,
2, 1, "float2",
new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[2]);
result.InternalSet = (p, sp) =>
sp.SetUniformValue(index, (float[])p.Data);
break;
case ShaderUniformType.Float3:
result = new EffectParameter(
EffectParameterClass.Vector, EffectParameterType.Single, name,
3, 1, "float3",
new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[3]);
result.InternalSet = (p, sp) =>
sp.SetUniformValue(index, (float[])p.Data);
break;
case ShaderUniformType.Float4:
return new EffectParameter(
result = new EffectParameter(
EffectParameterClass.Vector, EffectParameterType.Single, name,
4, 1, "float4",
new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4]);
result.InternalSet = (p, sp) =>
sp.SetUniformValue(index, (float[])p.Data);
break;
case ShaderUniformType.Sampler2D:
return new EffectParameter(
result = new EffectParameter(
EffectParameterClass.Object, EffectParameterType.Texture2D, name,
1, 1, "texture2d",
new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), null);
// FIXME: No InternalSet
break;
default:
throw new Exception("Uniform Type " + type + " Not yet implemented (" + name + ")");
}

return result;
}

#endif
Expand Down
14 changes: 14 additions & 0 deletions MonoGame.Framework/Graphics/Effect/EffectParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
using System.Text;
using System.Diagnostics;

#if PSM
using Sce.PlayStation.Core.Graphics;
#endif

namespace Microsoft.Xna.Framework.Graphics
{
[DebuggerDisplay("{ParameterClass} {ParameterType} {Name} : {Semantic}")]
Expand Down Expand Up @@ -63,6 +67,10 @@ internal EffectParameter(EffectParameter cloneSource)
if (array != null)
Data = array.Clone();
StateKey = unchecked(NextStateKey++);

#if PSM
InternalSet = cloneSource.InternalSet;
#endif
}

public string Name { get; private set; }
Expand Down Expand Up @@ -600,5 +608,11 @@ public void SetValue (Vector4[] value)
Elements[i].SetValue (value[i]);
StateKey = unchecked(NextStateKey++);
}

#if PSM
internal delegate void InternalSetDelegate (EffectParameter parameter, ShaderProgram shaderProgram);

internal InternalSetDelegate InternalSet = null;
#endif
}
}
16 changes: 5 additions & 11 deletions MonoGame.Framework/Graphics/Effect/EffectPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class EffectPass
public EffectAnnotationCollection Annotations { get; private set; }

#if PSM
internal ShaderProgram _shaderProgram;
public ShaderProgram _shaderProgram;
#endif

internal EffectPass( Effect effect,
Expand Down Expand Up @@ -149,16 +149,10 @@ public void Apply()
#if PSM
_effect.GraphicsDevice._graphics.SetShaderProgram(_shaderProgram);

#warning We are only setting one hardcoded parameter here. Need to do this properly by iterating _effect.Parameters (Happens in Shader)

float[] data;
if (_effect.Parameters["WorldViewProj"] != null)
data = (float[])_effect.Parameters["WorldViewProj"].Data;
else
data = (float[])_effect.Parameters["MatrixTransform"].Data;
Sce.PlayStation.Core.Matrix4 matrix4 = PSSHelper.ToPssMatrix4(data);
matrix4 = matrix4.Transpose (); //When .Data is set the matrix is transposed, we need to do it again to undo it
_shaderProgram.SetUniformValue(0, ref matrix4);
foreach (var parameter in _effect.Parameters) {
if (parameter.InternalSet != null)
parameter.InternalSet(parameter, _shaderProgram);
}
#endif
}

Expand Down
50 changes: 35 additions & 15 deletions MonoGame.Framework/Graphics/GraphicsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ namespace Microsoft.Xna.Framework.Graphics
{
public class GraphicsDevice : IDisposable
{
#if PSM
public static GraphicsContext ExistingGraphicsContext = null;
#endif

private Viewport _viewport;

private bool _isDisposed;
Expand Down Expand Up @@ -206,7 +210,7 @@ public class GraphicsDevice : IDisposable

#elif PSM

internal GraphicsContext _graphics;
public GraphicsContext _graphics;
internal List<PssVertexBuffer> _availableVertexBuffers = new List<PssVertexBuffer>();
internal List<PssVertexBuffer> _usedVertexBuffers = new List<PssVertexBuffer>();
#endif
Expand Down Expand Up @@ -328,8 +332,13 @@ public GraphicsDevice ()
_viewport = new Viewport (0, 0,
DisplayMode.Width, DisplayMode.Height);
_viewport.MaxDepth = 1.0f;


#if PSM
MaxTextureSlots = 8;
#else
MaxTextureSlots = 16;
#endif

#if OPENGL
#if GLES
GL.GetInteger(All.MaxTextureImageUnits, ref MaxTextureSlots);
Expand Down Expand Up @@ -432,7 +441,7 @@ internal void Initialize()
#endif

#elif PSM
_graphics = new GraphicsContext();
_graphics = ExistingGraphicsContext ?? new GraphicsContext();
#elif OPENGL
_viewport = new Viewport(0, 0, PresentationParameters.BackBufferWidth, PresentationParameters.BackBufferHeight);
#endif
Expand Down Expand Up @@ -1121,6 +1130,15 @@ public void Clear(ClearOptions options, Vector4 color, float depth, int stencil)
}

#elif PSM
// Workaround for MonoGame not setting state correctly
_blendStateDirty = true;
_depthStencilStateDirty = true;
_indexBufferDirty = true;
_pixelShaderDirty = true;
_vertexShaderDirty = true;
_vertexBufferDirty = true;
_rasterizerStateDirty = true;
_scissorRectangleDirty = true;

_graphics.SetClearColor(color.ToPssVector4());
_graphics.Clear();
Expand Down Expand Up @@ -1482,6 +1500,10 @@ public Viewport Viewport
// In OpenGL we have to re-apply the special "posFixup"
// vertex shader uniform if the viewport changes.
_vertexShaderDirty = true;
#elif PSM
_graphics.SetViewport(
value.X, value.Y, value.Width, value.Height
);
#endif
}
}
Expand All @@ -1508,17 +1530,9 @@ public Rectangle ScissorRectangle
public void SetRenderTarget(RenderTarget2D renderTarget)
{
if (renderTarget == null)
#if PSM
_graphics.SetFrameBuffer(null);
#else
SetRenderTargets(null);
#endif
else
#if PSM
_graphics.SetFrameBuffer(renderTarget._frameBuffer);
#else
SetRenderTargets(new RenderTargetBinding(renderTarget));
#endif
}

public void SetRenderTarget(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)
Expand Down Expand Up @@ -1607,6 +1621,8 @@ internal void ApplyRenderTargets(RenderTargetBinding[] renderTargets)
#elif OPENGL
GL.BindFramebuffer(GLFramebuffer, this.glFramebuffer);
GraphicsExtensions.CheckGLError();
#elif PSM
_graphics.SetFrameBuffer(_graphics.Screen);
#endif

clearTarget = true;
Expand Down Expand Up @@ -1703,16 +1719,16 @@ internal void ApplyRenderTargets(RenderTargetBinding[] renderTargets)
}
throw new InvalidOperationException(message);
}

#elif PSM
var renderTarget = (RenderTarget2D)_currentRenderTargetBindings[0].RenderTarget;
_graphics.SetFrameBuffer(renderTarget._frameBuffer);
#endif

#if !PSM
// Set the viewport to the size of the first render target.
Viewport = new Viewport(0, 0, renderTarget.Width, renderTarget.Height);

// We clear the render target if asked.
clearTarget = renderTarget.RenderTargetUsage == RenderTargetUsage.DiscardContents;
#endif
}

// In XNA 4, because of hardware limitations on Xbox, when
Expand Down Expand Up @@ -1947,7 +1963,7 @@ private void ActivateShaderProgram()

public bool ResourcesLost { get; set; }

internal void ApplyState(bool applyShaders)
public void ApplyState(bool applyShaders)
{
#if DIRECTX
// NOTE: This code assumes _d3dContext has been locked by the caller.
Expand Down Expand Up @@ -2358,6 +2374,8 @@ public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertex
// Release the handles.
ibHandle.Free();
vbHandle.Free();
#else
throw new NotImplementedException("Not implemented");
#endif
}

Expand Down Expand Up @@ -2417,6 +2435,8 @@ public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertex
ibHandle.Free();
vbHandle.Free();

#else
throw new NotImplementedException("Not implemented");
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion MonoGame.Framework/Graphics/RenderTarget2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public RenderTarget2D (GraphicsDevice graphicsDevice, int width, int height, boo
// Create a view interface on the rendertarget to use on bind.
_renderTargetView = new RenderTargetView(graphicsDevice._d3dDevice, _texture);
#elif PSM
_frameBuffer = new FrameBuffer();
_frameBuffer = new FrameBuffer();
_frameBuffer.SetColorTarget(_texture2D,0);
#endif

Expand Down
31 changes: 30 additions & 1 deletion MonoGame.Framework/Graphics/SamplerStateCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ internal void Dirty()
#endif
}

internal void SetSamplers(GraphicsDevice device)
public void SetSamplers(GraphicsDevice device)
{
#if DIRECTX
// Skip out if nothing has changed.
Expand Down Expand Up @@ -169,6 +169,35 @@ internal void SetSamplers(GraphicsDevice device)
texture.glLastSamplerState = sampler;
}
}
#elif PSM
for (var i = 0; i < _samplers.Length; i++)
{
var sampler = _samplers[i];
var texture = device.Textures[i] as Texture2D;
if (texture == null)
continue;

var psmTexture = texture._texture2D;

// FIXME: Handle mip attributes

// FIXME: Separable filters
psmTexture.SetFilter(
sampler.Filter == TextureFilter.Point
? Sce.PlayStation.Core.Graphics.TextureFilterMode.Nearest
: Sce.PlayStation.Core.Graphics.TextureFilterMode.Linear
);
// FIXME: The third address mode
psmTexture.SetWrap(
sampler.AddressU == TextureAddressMode.Clamp
? Sce.PlayStation.Core.Graphics.TextureWrapMode.ClampToEdge
: Sce.PlayStation.Core.Graphics.TextureWrapMode.Repeat,
sampler.AddressV == TextureAddressMode.Clamp
? Sce.PlayStation.Core.Graphics.TextureWrapMode.ClampToEdge
: Sce.PlayStation.Core.Graphics.TextureWrapMode.Repeat
);

}
#endif
}
}
Expand Down
Loading