(f0d812055) v0.9.9.0

This commit is contained in:
Joonas Rikkonen
2020-04-23 19:19:37 +03:00
parent b647059b93
commit ac37a3b0e4
391 changed files with 15054 additions and 5420 deletions
@@ -238,6 +238,44 @@ namespace Microsoft.Xna.Framework.Graphics
}
}
public void Draw(Texture2D texture, VertexPositionColorTexture[] vertices, float layerDepth)
{
CheckValid(texture);
float sortKey = 0f;
// set SortKey based on SpriteSortMode.
switch (_sortMode)
{
// Comparison of Texture objects.
case SpriteSortMode.Texture:
sortKey = texture.SortingKey;
break;
// Comparison of Depth
case SpriteSortMode.FrontToBack:
sortKey = layerDepth;
break;
// Comparison of Depth in reverse
case SpriteSortMode.BackToFront:
sortKey = -layerDepth;
break;
}
int iters = vertices.Length / 4;
for (int i=0;i<iters;i++)
{
var item = _batcher.CreateBatchItem();
item.Texture = texture;
item.SortKey = sortKey;
item.vertexTL = vertices[(i * 4) + 0];
item.vertexTR = vertices[(i * 4) + 1];
item.vertexBL = vertices[(i * 4) + 2];
item.vertexBR = vertices[(i * 4) + 3];
}
}
/// <summary>
/// Submit a sprite for drawing in the current batch.
/// </summary>
@@ -1220,6 +1258,7 @@ namespace Microsoft.Xna.Framework.Graphics
}
}
}
_batcher.Dispose();
base.Dispose(disposing);
}
}
@@ -22,7 +22,7 @@ namespace Microsoft.Xna.Framework.Graphics
vertexBL = new VertexPositionColorTexture();
vertexBR = new VertexPositionColorTexture();
}
public void Set ( float x, float y, float dx, float dy, float w, float h, float sin, float cos, Color color, Vector2 texCoordTL, Vector2 texCoordBR, float depth )
{
// TODO, Should we be just assigning the Depth Value to Z?
@@ -13,7 +13,7 @@ namespace Microsoft.Xna.Framework.Graphics
/// batched and will process them into short.MaxValue groups (strided by 6 for the number of vertices
/// sent to the GPU).
/// </summary>
internal class SpriteBatcher
internal class SpriteBatcher : IDisposable
{
/*
* Note that this class is fundamental to high performance for SpriteBatch games. Please exercise
@@ -54,6 +54,9 @@ namespace Microsoft.Xna.Framework.Graphics
private VertexPositionColorTexture[] _vertexArray;
private VertexBuffer vertexBuffer;
private IndexBuffer indexBuffer;
public SpriteBatcher (GraphicsDevice device)
{
_device = device;
@@ -136,6 +139,12 @@ namespace Microsoft.Xna.Framework.Graphics
_index = newIndex;
_vertexArray = new VertexPositionColorTexture[4 * numBatchItems];
indexBuffer?.Dispose();
vertexBuffer?.Dispose();
indexBuffer = new IndexBuffer(_device, IndexElementSize.SixteenBits, _index.Length, BufferUsage.WriteOnly);
indexBuffer.SetData(_index);
vertexBuffer = new VertexBuffer(_device, VertexPositionColorTexture.VertexDeclaration, _vertexArray.Length, BufferUsage.WriteOnly);
}
/// <summary>
@@ -225,7 +234,8 @@ namespace Microsoft.Xna.Framework.Graphics
}
// return items to the pool.
_batchItemCount = 0;
}
_device.Textures[0] = null;
}
/// <summary>
/// Sends the triangle list to the graphics device. Here is where the actual drawing starts.
@@ -241,6 +251,7 @@ namespace Microsoft.Xna.Framework.Graphics
var vertexCount = end - start;
_device.Indices = indexBuffer;
// If the effect is not null, then apply each pass and render the geometry
if (effect != null)
{
@@ -252,31 +263,26 @@ namespace Microsoft.Xna.Framework.Graphics
// Whatever happens in pass.Apply, make sure the texture being drawn
// ends up in Textures[0].
_device.Textures[0] = texture;
_device.DrawUserIndexedPrimitives(
PrimitiveType.TriangleList,
_vertexArray,
0,
vertexCount,
_index,
0,
(vertexCount / 4) * 2,
VertexPositionColorTexture.VertexDeclaration);
vertexBuffer.SetData(_vertexArray, start, vertexCount);
_device.SetVertexBuffer(vertexBuffer);
_device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, (vertexCount / 4) * 2);
}
}
else
{
// If no custom effect is defined, then simply render.
_device.DrawUserIndexedPrimitives(
PrimitiveType.TriangleList,
_vertexArray,
0,
vertexCount,
_index,
0,
(vertexCount / 4) * 2,
VertexPositionColorTexture.VertexDeclaration);
vertexBuffer.SetData(_vertexArray, start, vertexCount);
_device.SetVertexBuffer(vertexBuffer);
_device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, (vertexCount / 4) * 2);
}
_device.Indices = null;
}
public void Dispose()
{
indexBuffer?.Dispose();
vertexBuffer?.Dispose();
}
}
}
@@ -74,7 +74,10 @@ namespace Microsoft.Xna.Framework.Graphics
lock (d3dContext)
{
d3dContext.UpdateSubresource(GetTexture(), subresourceIndex, region, dataPtr, GetPitch(w), 0);
d3dContext.GenerateMips(GetShaderResourceView());
if (_mipmap)
{
d3dContext.GenerateMips(GetShaderResourceView());
}
}
}
finally
@@ -500,19 +500,18 @@
<EmbeddedResource Include="Graphics\Effect\Resources\SpriteEffect.dx11.mgfxo" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpDX" Version="4.2.0" />
<PackageReference Include="SharpDX.Direct2D1" Version="4.2.0" />
<PackageReference Include="SharpDX.Direct3D11" Version="4.2.0" />
<PackageReference Include="SharpDX.DXGI" Version="4.2.0" />
<PackageReference Include="SharpDX.MediaFoundation" Version="4.2.0" />
<PackageReference Include="SharpDX.XInput" Version="4.2.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\XNATypes\XNATypes.csproj" />
</ItemGroup>
@@ -0,0 +1,8 @@
{
"profiles": {
"MonoGame.Framework.Windows.NetStandard": {
"commandName": "Project",
"nativeDebugging": false
}
}
}