Batch across skeletons.

This commit is contained in:
NathanSweet 2013-04-11 10:52:00 +02:00
parent f935a4ede0
commit 71bffc5356
3 changed files with 17 additions and 21 deletions

View File

@ -88,7 +88,9 @@ namespace Spine {
time += gameTime.ElapsedGameTime.Milliseconds / 1000f; time += gameTime.ElapsedGameTime.Milliseconds / 1000f;
animation.Apply(skeleton, time, true); animation.Apply(skeleton, time, true);
skeleton.UpdateWorldTransform(); skeleton.UpdateWorldTransform();
skeletonRenderer.Begin();
skeletonRenderer.Draw(skeleton); skeletonRenderer.Draw(skeleton);
skeletonRenderer.End();
base.Draw(gameTime); base.Draw(gameTime);
} }

View File

@ -53,12 +53,25 @@ namespace Spine {
Bone.yDown = true; Bone.yDown = true;
} }
public void Begin () {
device.RasterizerState = rasterizerState;
device.BlendState = BlendState.AlphaBlend;
}
public void End () {
foreach (EffectPass pass in effect.CurrentTechnique.Passes) {
pass.Apply();
batcher.Draw(device);
}
}
public void Draw (Skeleton skeleton) { public void Draw (Skeleton skeleton) {
List<Slot> drawOrder = skeleton.DrawOrder; List<Slot> drawOrder = skeleton.DrawOrder;
for (int i = 0, n = drawOrder.Count; i < n; i++) { for (int i = 0, n = drawOrder.Count; i < n; i++) {
Slot slot = drawOrder[i]; Slot slot = drawOrder[i];
Attachment attachment = slot.Attachment; Attachment attachment = slot.Attachment;
if (attachment == null) continue; if (attachment == null)
continue;
if (attachment is RegionAttachment) { if (attachment is RegionAttachment) {
RegionAttachment regionAttachment = (RegionAttachment)attachment; RegionAttachment regionAttachment = (RegionAttachment)attachment;
@ -112,14 +125,6 @@ namespace Spine {
item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4]; item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4];
} }
} }
device.RasterizerState = rasterizerState;
device.BlendState = BlendState.AlphaBlend;
foreach (EffectPass pass in effect.CurrentTechnique.Passes) {
pass.Apply();
batcher.Draw(device);
}
} }
} }
} }

View File

@ -77,11 +77,6 @@ namespace Spine {
/// sent to the GPU). /// sent to the GPU).
/// </summary> /// </summary>
public class SpriteBatcher { public class SpriteBatcher {
/*
* Note that this class is fundamental to high performance for SpriteBatch games. Please exercise
* caution when making changes to this class.
*/
/// <summary> /// <summary>
/// Initialization size for the batch item list and queue. /// Initialization size for the batch item list and queue.
/// </summary> /// </summary>
@ -175,11 +170,6 @@ namespace Spine {
_vertexArray = new VertexPositionColorTexture[4 * numBatchItems]; _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.
/// </summary>
/// <param name="sortMode">The type of depth sorting desired for the rendering.</param>
public void Draw (GraphicsDevice device) { public void Draw (GraphicsDevice device) {
// nothing to do // nothing to do
if (_batchItemList.Count == 0) if (_batchItemList.Count == 0)
@ -225,8 +215,7 @@ namespace Spine {
} }
// flush the remaining vertexArray data // flush the remaining vertexArray data
FlushVertexArray(device, startIndex, index); FlushVertexArray(device, startIndex, index);
// Update our batch count to continue the process of culling down // Update our batch count to continue the process of culling down large batches
// large batches
batchCount -= numBatchesToProcess; batchCount -= numBatchesToProcess;
} }
_batchItemList.Clear(); _batchItemList.Clear();