XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

Using TextureAddressMode with SpriteBatch.Draw

Last post 05-12-2008 1:28 PM by Shawn Hargreaves. 5 replies.
  • 05-09-2008 2:23 PM

    Using TextureAddressMode with SpriteBatch.Draw

    I was playing around with modifying the SamplerState TextureAddressModes and was noticing some strange behavior.  When I draw some textures it correctly apply the Wrap, Border ect. settings, but other textures it will ignore the settings and render with TextureAddressMode.Clamp.

    I did a little more experimenting and found that textures with widths and heights that are a power of 2 use the TextureAddressMode settings properly, while other textures override with Clamp.  I assume this has something to do with the fact that most graphics cards only support textures with sizes that are powers of two and Texture2D and SpriteBatch are abstracting the handling of that from us and that is what is interfering, but I have no idea if it is possible to fix that.

  • 05-09-2008 2:49 PM In reply to

    Re: Using TextureAddressMode with SpriteBatch.Draw

    Your card probably doesn't have the SupportsNonPower2Conditional capability (many (most?) do not).
    XNA Framework Developer - blog - homepage
  • 05-09-2008 2:52 PM In reply to

    Re: Using TextureAddressMode with SpriteBatch.Draw

    I thought maybe I was just going crazy, so I looked for a microsoft provided sample I could play with and understand where I went wrong and found this: http://msdn.microsoft.com/en-us/library/bb975153.aspx

    The image that is being tiled in the sample is 100 x 50 pixels and when I run the unmodified sample on my computer it does the same thing I was seeing, it clamps the transparent edge rather than tiling like it should.  However, when I modify the image to be 128 x 64 and rebuild, it tiles exactly like it is supposed to.

    Do you think this is an issue specific to my video card or is this behavior just a result of having a card that doesn't support non power of 2 textures?

  • 05-09-2008 2:59 PM In reply to

    Re: Using TextureAddressMode with SpriteBatch.Draw

    Answer
    It's the result of having a card that only supports a limited set of functionality for non pow2 textures. See the SupportsNonPower2Conditional caps bit documentation for details.
    XNA Framework Developer - blog - homepage
  • 05-09-2008 3:15 PM In reply to

    Re: Using TextureAddressMode with SpriteBatch.Draw

    Shawn Hargreaves:
    It's the result of having a card that only supports a limited set of functionality for non pow2 textures. See the SupportsNonPower2Conditional caps bit documentation for details.

    I see the issue now, however I'm somewhat disappointed that the sample makes no note that this is not a good technique to use because it won't work on graphics cards that don't fully support non power of 2 textures which is most of them as far as I can tell. :(

    After reading the documentation for SupportsNonPower2Conditional basically, if your graphics card (like mine) has

    GraphicsDeviceCapabilities.TextureCapabilities.RequiresPower2 == true
    GraphicsDeviceCapabilities.TextureCapabilities.SupportsNonPower2Conditional == true

    You're limited to Clamp when drawing non power of 2 textures.

  • 05-12-2008 1:28 PM In reply to

    Re: Using TextureAddressMode with SpriteBatch.Draw

    Please file this as a bug on the Connect site: that will make sure our doc guys take a look at the issue.
    XNA Framework Developer - blog - homepage
Page 1 of 1 (6 items) Previous Next