Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, I'm going to give the best answer I can, but I'm limited by the amount of code you've posted. First of all, I'd direct you to <a href="https://gamedev.stackexchange.com/a/37794/288">this answer</a> for an overview of the various factors that affect performance.</p> <p>The problem you are likely to be experiencing with <code>SpriteBatch</code> is that you're forcing it to start too many batches. It must start a batch every time you change texture - and it sounds like you're using a different textures for different pixels, and then drawing them in random order.</p> <p>Sorting by texture within <code>SpriteBatch</code> (with <code>SpriteSortMode.Texture</code>) can itself be an expensive operation. Your own code for grouping like-textured sprites might be slow or incorrect - but I can't tell with the code you've given.</p> <p>A better case, rather than using many textures, would be to use a single, white texture, and then use the tint parameter to dynamically tint each sprite to the desired colour. Then every sprite can be sent in a single batch.</p> <p><strong>BUT</strong>, as well as a lot of processing to set up the vertices for so many sprites, we should consider how much data is actually being sent to the GPU. Each sprite has 4 vertices, each with a position, a colour, and a texture coordinate. That's a whopping <strong>96 bytes</strong> per pixel. And that all has to be sent to the GPU each frame!</p> <p>A texture, on the other hand, is only <strong>4 bytes</strong> per pixel. So it stands to reason that it <em>should</em> be faster.</p> <p>There are two things that could be slowing it down:</p> <p>First of all, if you are calling <code>Texture2D.SetData</code> more than you have to. Each call to <code>SetData</code> requires a fairly substantial amount of overhead. If you call it once per pixel it is going to be extremely slow. Call it once for the entire image instead. That <em>should</em> make it fast enough to be usable - although I haven't tested this myself extensively.</p> <p>The other possibility is that your GPU has a deep pipeline (hardware dependent) and is still using your texture to render frame N, while you are trying to update it for frame N+1. This forces the GPU to finish rendering frame N before it can accept the new changes. Although this seems unlikely to be a problem unless you are doing other very GPU-intensive things, or your graphics driver is doing something silly.</p>
    singulars
    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.
 

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