Sign in to follow this  
Whogie

XNA - Texture wrapping stopped working moving from Xbox to Windows

Recommended Posts

Hi, I moved my project from 360 to Windows so I can work on it on my laptop, but texture wrapping broke. Here's my relevant code:
GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
            spriteBatch.GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
            spriteBatch.GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;
Any ideas why it's ignoring the TextureAddressMode.Wrap on Windows when it worked perfectly fine on the 360? Thanks for your help. Edit: Pics 360: http://img.photobucket.com/albums/v205/Whogie/DSCF0658.jpg PC: http://img.photobucket.com/albums/v205/Whogie/poornico.jpg [Edited by - Whogie on January 20, 2009 1:08:29 AM]

Share this post


Link to post
Share on other sites
Check the caps for your graphics card - http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.graphicsdevicecapabilities.maxtexturerepeat.aspx is probably the most important one.

I think almost every card supports wrap mode.

It may also help to use the debug directx runtimes on the PC and see if you get any error messages.

Share this post


Link to post
Share on other sites
What size are your textures? Are they non-power of 2? If so, does your card have the D3DPTEXTURECAPS_NONPOW2CONDITIONAL cap bit set? (This looks like exactly what happened when I tried a non-power of 2 texture on my ATI X300)

Share this post


Link to post
Share on other sites
Quote:
How does it look with TextureAddressMode.Mirror? Does it still clamp?


It does still clamp.

Quote:
That aside, the art looks absolutely wonderful! Especially on the tv set.


Thanks. It's my friend's work.

Quote:
Check the caps for your graphics card - http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.graphicsdevicecapabilities.maxtexturerepeat.aspx is probably the most important one.

I think almost every card supports wrap mode.


I ran that variable, and it turned up a 0. I'm probably just using it wrongly. ^^;

Quote:
It may also help to use the debug directx runtimes on the PC and see if you get any error messages.


I'm not sure what you mean by that, but the demos in the DirectX SDK Sample Browser run fine (DX9).

Quote:
What size are your textures? Are they non-power of 2? If so, does your card have the D3DPTEXTURECAPS_NONPOW2CONDITIONAL cap bit set? (This looks like exactly what happened when I tried a non-power of 2 texture on my ATI X300)


Keep in mind, I'm working with XNA, so I don't know how to call that.

This is it, though. I have an ATI x1400, and this seems to be the solution. I just tested resizing the rain, and that fixed it. I guess I have some work to do to resize the textures, unless there's another fix?

Thank you.

Share this post


Link to post
Share on other sites
Quote:
Original post by Whogie
Quote:
It may also help to use the debug directx runtimes on the PC and see if you get any error messages.


I'm not sure what you mean by that, but the demos in the DirectX SDK Sample Browser run fine (DX9).


See this.

Quote:
Original post by Whogie
Quote:
What size are your textures? Are they non-power of 2? If so, does your card have the D3DPTEXTURECAPS_NONPOW2CONDITIONAL cap bit set? (This looks like exactly what happened when I tried a non-power of 2 texture on my ATI X300)


Keep in mind, I'm working with XNA, so I don't know how to call that.


You want to check GraphicsDevice.GraphicsDeviceCapabilities.TextureCaps.SupportsNonPower2Conditional. Things like device capabilties, format capabilities, and render states in the native API mostly have equivalent versions in the XNA Graphics namespace, and they're usually very similarly named.

Also an easy way to check device caps is to use the D3D Caps Viewer that comes with the DirectX SDK.




Share this post


Link to post
Share on other sites
Ah, I see now. DebugView is quickly filling my log with stuff like:

[5060] Direct3D9: (WARN) :Ignoring redundant SetRenderState - 24 
[5060]
[5060] Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 5
[5060]
[5060] Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 6
[5060]
[5060] Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 7
[5060]
[5060] Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 8
[5060]
[5060] Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 9
[5060]


Calling it redundant is a little surprising...

I misplaced my breakpoint a bit earlier. MaxTextureRepeat = 8192
That's bigger than any one dimension of my textures for sure.

GraphicsDevice.GraphicsDeviceCapabilities.TextureCaps.SupportsNonPower2Conditional
is true.

Does this mean that I could potentially avoid resizing my textures as a workaround?

Share this post


Link to post
Share on other sites
The redundant RenderState/SamplerState warnings are just telling you that you're setting a SamplerState or RenderState to the same value it already has, so it will have no effect. They tell you this because if you have lots of RenderState or SamplerState changes it will decrease CPU performance, so in that case you'd want to remove the redundant settings (for you case though I'm sure it's not a problem).

If that cap is set to true, that means that you can't wrap non-power-of-2 textures and you can't use DXT formats.

Share this post


Link to post
Share on other sites
Quote:
Original post by Whogie
Ah, I see now. DebugView is quickly filling my log with stuff like:

[5060] Direct3D9: (WARN) :Ignoring redundant SetRenderState - 24 
[5060]
[5060] Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 5
[5060]
[5060] Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 6
[5060]
[5060] Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 7
[5060]
[5060] Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 8
[5060]
[5060] Direct3D9: (WARN) :Ignoring redundant SetSamplerState. Sampler: 0, State: 9
[5060]


Calling it redundant is a little surprising...
You can lower the debug output level on the DirectX Control Panel to get rid of that if you wish.

Quote:
Original post by Whogie
GraphicsDevice.GraphicsDeviceCapabilities.TextureCaps.SupportsNonPower2Conditional
is true.

Does this mean that I could potentially avoid resizing my textures as a workaround?
Yep. See D3DCAPS9 -> TextureCaps -> D3DPTEXTURECAPS_NONPOW2CONDITIONAL (I know it's non-MDX, but it still applies):
Quote:

D3DPTEXTURECAPS_NONPOW2CONDITIONAL
D3DPTEXTURECAPS_POW2 is also set, conditionally supports the use of 2D textures with dimensions that are not powers of two. A device that exposes this capability can use such a texture if all of the following requirements are met.

  • The texture addressing mode for the texture stage is set to D3DTADDRESS_CLAMP.
  • Texture wrapping for the texture stage is disabled (D3DRS_WRAP n set to 0).
  • Mipmapping is not in use (use magnification filter only).
  • Texture formats must not be D3DFMT_DXT1 through D3DFMT_DXT5.

If this flag is not set, and D3DPTEXTURECAPS_POW2 is also not set, then unconditional support is provided for 2D textures with dimensions that are not powers of two.

A texture that is not a power of two cannot be set at a stage that will be read based on a shader computation (such as the bem - ps and texm3x3 - ps instructions in pixel shaders versions 1_0 to 1_3). For example, these textures can be used to store bumps that will be fed into texture reads, but not the environment maps that are used in texbem - ps, texbeml - ps, and texm3x3spec - ps. This means that a texture with dimensions that are not powers of two cannot be addressed or sampled using texture coordinates computed within the shader. This type of operation is known as a dependent read and cannot be performed on these types of textures.

Share this post


Link to post
Share on other sites
Ah, so those listed conditions are what's blocking me, then. Seems I do have to have ^2 textures for my backgrounds, but it in practice it isn't so bad to fix. I just found a way to make this work with resized textures (resize them again with the draw command). Thank you for your help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this