(5a377a8ee) Unstable v0.9.1000.0
This commit is contained in:
@@ -1382,13 +1382,13 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
private void PlatformDrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount)
|
||||
{
|
||||
var indexCount = GetElementCountArray(primitiveType, primitiveCount);
|
||||
|
||||
lock (_d3dContext)
|
||||
{
|
||||
ApplyState(true);
|
||||
|
||||
_d3dContext.InputAssembler.PrimitiveTopology = ToPrimitiveTopology(primitiveType);
|
||||
|
||||
var indexCount = GetElementCountArray(primitiveType, primitiveCount);
|
||||
_d3dContext.DrawIndexed(indexCount, startIndex, baseVertex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
/// sent to the GPU).
|
||||
/// </summary>
|
||||
internal class SpriteBatcher
|
||||
{
|
||||
{
|
||||
/*
|
||||
* Note that this class is fundamental to high performance for SpriteBatch games. Please exercise
|
||||
* caution when making changes to this class.
|
||||
@@ -41,7 +41,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
/// Index pointer to the next available SpriteBatchItem in _batchItemList.
|
||||
/// </summary>
|
||||
private int _batchItemCount;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The target graphics device.
|
||||
/// </summary>
|
||||
@@ -54,18 +54,18 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
private VertexPositionColorTexture[] _vertexArray;
|
||||
|
||||
public SpriteBatcher (GraphicsDevice device)
|
||||
{
|
||||
public SpriteBatcher(GraphicsDevice device)
|
||||
{
|
||||
_device = device;
|
||||
|
||||
_batchItemList = new SpriteBatchItem[InitialBatchSize];
|
||||
_batchItemList = new SpriteBatchItem[InitialBatchSize];
|
||||
_batchItemCount = 0;
|
||||
|
||||
for (int i = 0; i < InitialBatchSize; i++)
|
||||
_batchItemList[i] = new SpriteBatchItem();
|
||||
|
||||
EnsureArrayCapacity(InitialBatchSize);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reuse a previously allocated SpriteBatchItem from the item pool.
|
||||
@@ -77,11 +77,11 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
if (_batchItemCount >= _batchItemList.Length)
|
||||
{
|
||||
var oldSize = _batchItemList.Length;
|
||||
var newSize = oldSize + oldSize/2; // grow by x1.5
|
||||
var newSize = oldSize + oldSize / 2; // grow by x1.5
|
||||
newSize = (newSize + 63) & (~63); // grow in chunks of 64.
|
||||
Array.Resize(ref _batchItemList, newSize);
|
||||
for(int i=oldSize; i<newSize; i++)
|
||||
_batchItemList[i]=new SpriteBatchItem();
|
||||
for (int i = oldSize; i < newSize; i++)
|
||||
_batchItemList[i] = new SpriteBatchItem();
|
||||
|
||||
EnsureArrayCapacity(Math.Min(newSize, MaxBatchSize));
|
||||
}
|
||||
@@ -137,7 +137,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
_vertexArray = new VertexPositionColorTexture[4 * numBatchItems];
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sorts the batch items and then groups batch drawing into maximal allowed batch sets that do not
|
||||
/// overflow the 16 bit array indices for vertices.
|
||||
@@ -145,36 +145,36 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
/// <param name="sortMode">The type of depth sorting desired for the rendering.</param>
|
||||
/// <param name="effect">The custom effect to apply to the drawn geometry</param>
|
||||
public unsafe void DrawBatch(SpriteSortMode sortMode, Effect effect)
|
||||
{
|
||||
{
|
||||
if (effect != null && effect.IsDisposed)
|
||||
throw new ObjectDisposedException("effect");
|
||||
|
||||
// nothing to do
|
||||
// nothing to do
|
||||
if (_batchItemCount == 0)
|
||||
return;
|
||||
|
||||
// sort the batch items
|
||||
switch ( sortMode )
|
||||
{
|
||||
case SpriteSortMode.Texture :
|
||||
case SpriteSortMode.FrontToBack :
|
||||
case SpriteSortMode.BackToFront :
|
||||
Array.Sort(_batchItemList, 0, _batchItemCount);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
|
||||
// sort the batch items
|
||||
switch (sortMode)
|
||||
{
|
||||
case SpriteSortMode.Texture:
|
||||
case SpriteSortMode.FrontToBack:
|
||||
case SpriteSortMode.BackToFront:
|
||||
Array.Sort(_batchItemList, 0, _batchItemCount);
|
||||
break;
|
||||
}
|
||||
|
||||
// Determine how many iterations through the drawing code we need to make
|
||||
int batchIndex = 0;
|
||||
int batchCount = _batchItemCount;
|
||||
|
||||
|
||||
|
||||
unchecked
|
||||
{
|
||||
_device._graphicsMetrics._spriteCount += batchCount;
|
||||
}
|
||||
|
||||
// Iterate through the batches, doing short.MaxValue sets of vertices only.
|
||||
while(batchCount > 0)
|
||||
while (batchCount > 0)
|
||||
{
|
||||
// setup the vertexArray array
|
||||
var startIndex = 0;
|
||||
@@ -208,10 +208,10 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
}
|
||||
|
||||
// store the SpriteBatchItem data in our vertexArray
|
||||
*(vertexArrayPtr+0) = item.vertexTL;
|
||||
*(vertexArrayPtr+1) = item.vertexTR;
|
||||
*(vertexArrayPtr+2) = item.vertexBL;
|
||||
*(vertexArrayPtr+3) = item.vertexBR;
|
||||
*(vertexArrayPtr + 0) = item.vertexTL;
|
||||
*(vertexArrayPtr + 1) = item.vertexTR;
|
||||
*(vertexArrayPtr + 2) = item.vertexBL;
|
||||
*(vertexArrayPtr + 3) = item.vertexBR;
|
||||
|
||||
// Release the texture.
|
||||
item.Texture = null;
|
||||
@@ -225,7 +225,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
}
|
||||
// return items to the pool.
|
||||
_batchItemCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the triangle list to the graphics device. Here is where the actual drawing starts.
|
||||
@@ -278,6 +278,5 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
VertexPositionColorTexture.VertexDeclaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user