Jump to content
  • Advertisement
Sign in to follow this  
devronious

Copying from one backbuffer to another...

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

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);
            //SurfaceLoader.FromSurface(backBuffer, target, Filter.None, clearColor.ToArgb());

            // 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 this post


Link to post
Share on other sites
Advertisement
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.

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!