Jump to content
  • Advertisement
Sign in to follow this  

Creating Textures on seperate RenderTarget2D "Bleeds Through"

This topic is 2254 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


Can anyone help please ? I am creating mipmapped textures from PNG by creating a Texture2D and rendering it to a new RenderTarget2D like so;
[source lang="csharp"]Texture2D rawTexture = Texture2D.FromStream(device, memoryStream);
RenderTarget2D renderTarget = new RenderTarget2D(device, rawImage.Width, rawImage.Height, mipMap: true, preferredFormat: SurfaceFormat.Color, preferredDepthFormat: DepthFormat.None);

using (SpriteBatch sprite = new SpriteBatch(device))
sprite.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.None, RasterizerState.CullNone, effect: null);
sprite.Draw(rawTexture, new Vector2(0, 0), Color.White);

Texture2D mipmappedTexture = (Texture2D)renderTarget;

return mipmappedTexture;[/source]
My problem is that this is almost always unnoticeable, but when I have a lot of this to do, during game load, this process interferes with the visible surface - the visible surface is corrupted and is frequently cleared back to turquiose (the default back color for a new RenderTarget2D). This is all occuring on the same thread (earlier attempts to multithread didn't syncronise SamplerStates well and I abandoned them).

I thought that by using a new RenderTarget there would be no possible interference with the users' visible RenderTarget, but I seem not to be understanding the relationship between the two. A nudge in the right direction would be very helpful.


Share this post

Link to post
Share on other sites
What is going on in that memory stream?

Also, I'm not sure what you mean when you say "the visible surface". If you mean the surface your presenting to the end user (front buffer), then I'd check out what is happeneing in your BeginScene, EndScene and PresentScene. I see you set the render target to null for the device in your code, do you ever set it back to the back buffer?

The only way you can have the sprite bleed through to the backbuffer is:

  • the device is not cleared
  • render target is presented in presentscene
  • you render the sprite just like a mesh in your current loop, using blending or alpha params.

    The device is only going to present what you tell it to and where you tell it.

Share this post

Link to post
Share on other sites

Thanks for the reply. The memorystream is a byte[] buffer from a PNG resource which I'm loading through a SpriteBatch to generate a mipmap.

I thought that setting RenderTarget to null always selects the backbuffer for the next instruction, so it didn't need explicitly setting. However, I'll look up how to do that and make sure I am definitely explicitly setting the backbuffer in my main render loop.


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!