Skip to content

Commit

Permalink
Merge pull request MonoGame#1871 from SickheadGames/d3dgarbage
Browse files Browse the repository at this point in the history
DirectX Garbage Reduction
  • Loading branch information
KonajuGames committed Jul 22, 2013
2 parents 3c01c86 + 9d59acf commit 7ec1ec8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
6 changes: 2 additions & 4 deletions MonoGame.Framework/Graphics/States/BlendState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,8 @@ internal void ApplyState(GraphicsDevice device)
// locked the d3dContext for us to use.

// Apply the state!
var d3dContext = device._d3dContext;
d3dContext.OutputMerger.BlendFactor = new SharpDX.Color4(BlendFactor.R / 255.0f, BlendFactor.G / 255.0f, BlendFactor.B / 255.0f, BlendFactor.A / 255.0f);
d3dContext.OutputMerger.BlendSampleMask = -1;
d3dContext.OutputMerger.BlendState = _state;
var blendFactor = new SharpDX.Color4(BlendFactor.R / 255.0f, BlendFactor.G / 255.0f, BlendFactor.B / 255.0f, BlendFactor.A / 255.0f);
device._d3dContext.OutputMerger.SetBlendState(_state, blendFactor);
}

internal static void ResetStates()
Expand Down
3 changes: 1 addition & 2 deletions MonoGame.Framework/Graphics/States/DepthStencilState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ internal void ApplyState(GraphicsDevice device)
// locked the d3dContext for us to use.

// Apply the state!
device._d3dContext.OutputMerger.DepthStencilReference = ReferenceStencil;
device._d3dContext.OutputMerger.DepthStencilState = _state;
device._d3dContext.OutputMerger.SetDepthStencilState(_state, ReferenceStencil);
}

internal static void ResetStates()
Expand Down
13 changes: 3 additions & 10 deletions MonoGame.Framework/Graphics/Vertices/IndexBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,12 @@ void GenerateIfRequired()
if ((options & SetDataOptions.NoOverwrite) == SetDataOptions.NoOverwrite)
mode = SharpDX.Direct3D11.MapMode.WriteNoOverwrite;

SharpDX.DataStream stream;
var d3dContext = GraphicsDevice._d3dContext;
lock (d3dContext)
{
d3dContext.MapSubresource(
_buffer,
mode,
SharpDX.Direct3D11.MapFlags.None,
out stream);

stream.Position = offsetInBytes;
stream.WriteRange(data, startIndex, elementCount);

var dataBox = d3dContext.MapSubresource(_buffer, 0, mode, SharpDX.Direct3D11.MapFlags.None);
SharpDX.Utilities.Write(IntPtr.Add(dataBox.DataPointer, offsetInBytes), data, startIndex,
elementCount);
d3dContext.UnmapSubresource(_buffer, 0);
}
}
Expand Down
13 changes: 3 additions & 10 deletions MonoGame.Framework/Graphics/Vertices/VertexBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,12 @@ void GenerateIfRequired()
if ((options & SetDataOptions.NoOverwrite) == SetDataOptions.NoOverwrite)
mode = SharpDX.Direct3D11.MapMode.WriteNoOverwrite;

SharpDX.DataStream stream;
var d3dContext = GraphicsDevice._d3dContext;
lock (d3dContext)
{
d3dContext.MapSubresource(
_buffer,
mode,
SharpDX.Direct3D11.MapFlags.None,
out stream);

stream.Position = offsetInBytes;
stream.WriteRange(data, startIndex, elementCount);

var dataBox = d3dContext.MapSubresource(_buffer, 0, mode, SharpDX.Direct3D11.MapFlags.None);
SharpDX.Utilities.Write(IntPtr.Add(dataBox.DataPointer, offsetInBytes), data, startIndex,
elementCount);
d3dContext.UnmapSubresource(_buffer, 0);
}
}
Expand Down

0 comments on commit 7ec1ec8

Please sign in to comment.