Jump to content
  • Advertisement
Sign in to follow this  
FOOLVER

HLSL and XNA draw calls problem

This topic is 3301 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, we are writing the shadow system for our isometric tile engine using a full shader system we draw the tiles with a code "like" this
Spritebatch.Begin();

for(y;y<height;y++)
   for(x;x<width;x++)
   {
       /*here we use our shadow shader*/
      if (tile has light)
      // effect.begin etc etc etc
      // draw the tile
      // effect.end etc etc
      else
      // draw the tile

      // draw the items
  
      // draw the characters
   }

SpriteBatch.End();
the problem is this: the shader affected all the draw calls inside spritebatch.begin (every tile in various strange ways!!!!!) .. also items and characters, we tried to use renderterged 2d but is useless because the creation of every rendertarget2d want another spritebatch.begin.. and we simply can't use a begin every tiles someone know ho to solve this problem ? thanks a lot and sorry for my bad english

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Sprite Batching

In normal drawing, the SpriteBatch object does not change any render states or draw any sprites until you call End. This is known as Deferred mode. In Deferred mode, SpriteBatch saves the information from each Draw call until you call End. When you then call End, SpriteBatch changes the graphics device settings and draws each sprite in the batch. End then resets the device settings, if you specified SaveStateMode.SaveState.

If you call Begin, specifying SpriteSortMode.Immediate, it triggers Immediate mode. In Immediate mode, the SpriteBatch immediately changes the graphics device render states to begin drawing sprites. Thereafter, each call to Draw immediately draws the sprite using the current device settings. Calling End resets the device settings, if you specified SaveStateMode.SaveState.

In Immediate mode, once you call Begin on one SpriteBatch instance, do not call it on any other SpriteBatch instance until you call End for the first SpriteBatch.

Deferred mode is slower than Immediate mode, but it allows multiple instances of SpriteBatch to accept Begin and Draw calls without interfering with each other.

MSDN

so as i understand it you have to use different sprite batches if you switch the shader or maybe try using immediate mode.

Share this post


Link to post
Share on other sites
I already use immediate mode, use a batch for every tile draw is madness :(, I hope that will be another workaround

Share this post


Link to post
Share on other sites
Unless you pass SaveStateMode.SaveState when calling Effect.Begin, all of the shaders/render states/textures set by that Effect will remain set on the device after you call Effect.End.

Share this post


Link to post
Share on other sites
we already pass the savestatemode in the begin, I tried none and savestate but sprite and items are already affected by the shader (and this is the main problem) :(

Share this post


Link to post
Share on other sites
Quote:
use a batch for every tile draw is madness

i dont understand u should use a batch to pack all draw calls of similiar tiles into one batch. these should all have the same shader after u are done with the tile move onto the next with shader req. you dont have to use one batch per tile just per tile type.

Share this post


Link to post
Share on other sites
the shader is yep the same for every tile, but the parameters we inject into the shader to work correctly change every draw, I do not understand the "pack" for similar tiles, i can just "pack" into a batch every layer but the problem is not this .. the problem is that the shader affacted others draw that should not be affected by the shader

[Edited by - FOOLVER on September 11, 2009 11:45:51 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!