Copying from one backbuffer to another...

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

Recommended Posts

I'm trying to copy from one backbuffer surface to another using the following code:
[source lang=c#]
public void GlowMesh(SurfaceMesh mesh, Color color)
{
this.device.EndScene();
//store original buffers and data
Surface backBuffer = this.device.GetBackBuffer(0, 0, BackBufferType.Mono);
int width = backBuffer.Description.Width;
int height = backBuffer.Description.Height;
Format bbformat = backBuffer.Description.Format;
Material omat = this.device.Material;
Color clearColor = Color.Black;

//set render parameters
this.device.RenderState.Lighting = false;//disable lighting
Material mat = new Material();
mat.Ambient = color;
mat.Diffuse = color;
mat.Emissive = color;
mat.Specular = color;
this.device.Material = mat;

//render to targets
this.device.BeginScene();
this.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.Black, 1, 0);
mesh.mesh.DrawSubset(0);
this.device.EndScene();

//copy newly rendered mesh
Surface target = this.device.GetBackBuffer(0,0, BackBufferType.Mono);

//copy data to original buffers
Rectangle rec = new Rectangle(0, 0, target.Description.Width, target.Description.Height);
this.device.StretchRectangle(target, rec , backBuffer, rec, TextureFilter.None);

// place composition into render target and release memory and restore state
this.device.SetRenderTarget(0, backBuffer);
target.Dispose();
backBuffer.Dispose();
this.device.Material = omat;
this.device.BeginScene();

}


when I try the copy it get's really slow and I can't really work with it. Am I doing something wrong? I'm just trying to render to a blank area after storing the rendertarget and then copy from the first to the second. Then set the composition to the rendertarget. Thanks in advance, Devin

Share on other sites
Physically copying the data is going to give you terrible performance, since transfering those huge surfaces to and from the graphics card is extrememly slow (not to mention the time it takes to actually copy). Instead, just try rendering the current RT to the backbuffer as a textured quad. You can use ID3DXSprite for this, if you want.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631708
• Total Posts
3001837
×