Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems to me you have a couple of options, here. Note that I'm primarily familiar with XNA 4.0 on the PC, so not all of these may be possible/performant in your case.</p> <p><strong>The Easy, Hacky Way</strong></p> <p>You don't appear to be using the color channel when drawing your sprites; this technique assumes that your example is representative of your real code.</p> <p>If you don't need the sprite color for tinting your sprites, you can hijack it as a way to pass per-sprite data into a custom vertex/pixel shader. For example, you could do this:</p> <pre><code>var shearX = MathHelper.ToRadians(33) / MathHelper.TwoPi; var shearY = MathHelper.ToRadians(33) / MathHelper.TwoPi; var color = new Color(shearX, shearY, 0f, 0f); _spriteBatch.Draw(_texture, rectangle, color); </code></pre> <p>This represents the x- and y-shear values as factors of <code>2 * pi</code> stored in the red and green color channels, respectively.</p> <p>Then you can create a custom vertex shader that retrieves these values and performs the shearing calculations on the fly. See Shawn Hargreaves's article <a href="http://blogs.msdn.com/b/shawnhar/archive/2010/04/05/spritebatch-and-custom-shaders-in-xna-game-studio-4-0.aspx" rel="nofollow">here</a> for information on how to do that.</p> <p><strong>Hybrid Approach</strong></p> <p>Another relatively straightforward possibility is to combine traditional sprite batching with your <code>DrawUserIndexedPrimitives</code> code. </p> <p>The key to good performance is to minimize state changes, so careful ordering of your sprites can go a long way. Organize your sprites such that you can draw all non-skewed sprites in a single pass using <code>SpriteBatch</code>, then only use the slower <code>DrawUserIndexedPrimitives</code> technique to draw the sprites that actually need it. This should significantly reduce the number of batches being sent to the GPU, assuming that most of the sprites in a given frame aren't skewed.</p> <p><strong>Batching + Custom Vertex Format</strong></p> <p>This is probably the best technique, but it also involves writing the most code. Not that any of it is particularly complex.</p> <p>The way <code>SpriteBatch</code> works internally is that it maintains a dynamic vertex buffer which is populated on the CPU and then drawn all in a single call. Shawn Hargreaves provides a high-level overview of how this sort of thing is done <a href="http://blogs.msdn.com/b/shawnhar/archive/2010/07/07/setdataoptions-nooverwrite-versus-discard.aspx" rel="nofollow">here</a>. </p> <p>The problem with extending your <code>DrawUserIndexedPrimitives</code> to use this technique is that pesky world matrix; shaders don't really have a good way to attach a particular world matrix to a particular sprite (unless you're using hardware instancing, which I don't think your platform supports). So what can you do?</p> <p>If you create a custom vertex format, you can attach shearing values to each vertex, and use those to perform the shearing in the vertex shader, as in the first technique. This will allow you to draw all of your game's sprites in a single call, which should be very fast.</p> <p>You can find information on custom vertex declarations <a href="http://msdn.microsoft.com/en-us/library/bb976065.aspx" rel="nofollow">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload