RE: Fastest method to copy a bitmap to Surface or Texture?



I have the same problem with D3D. Draw2D() seems to be way too slow. I am now
attempting to draw the primitives myself, and I will report results once I
get it working. I will also try a suggestion I got on my thread (look on the
first page for my name).

I cannot comment on DirectDraw as I haven't tried the latest "non-blitting"
version.

With all the changes every version and lack of good documentation, to me, it
seems like MDX is still a beta product...

"Dwight" wrote:

> Hi,
>
> I'm having fits with trying to get any performance with Managed DirectDraw
> or Direct3D.
>
> I have been profiling different methods of copying a bitmap from memory to a
> surface or Texture of a size
> 320 x 240 pixels. I am using C#.
>
> Since all blitting is gone, it seems there is only one practical way left to
> do this and that is to lock the surface memory and write the data directly.
> I've been advised on this newsgroup to use those methods. However...
>
> I have tried both the DDraw and the D3D routes. In the D3D route when I use
> the Lock method on a
> texture the frame rate is around 4 - 8 fps. In DDraw the fps is around 8
> fps.
> However, if I dispose of the offscreen surface on every frame and recreate
> it with the bitmap, I get
> rates of greater than 400 fps.
> This seems crazy and I know that someone out there has to have a better way.
>
> Here is an example of 2 different methods to fill the surface that I tested:
> (error handling removed for clarity)
> ***********************************
> Locking the Surface (fps <= 8)
> ***********************************
> private void FillSurface(Bitmap bmp)
> {
> System.Array surf;
>
> surf = surfaceBMP.Lock(LockFlags.DoNotWait);
> for(int y = 0; y < bmp.Height; y++)
> {
> for(int x = 0; x < bmp.Width; x++)
> {
> surf.SetValue((int)bmp.GetPixel(x,y).ToArgb(),x,y);
> }
> }
> surfaceBMP.Unlock(surf);
> }
>
> ****************************************
> Recreating the Surface on every render (fps > 400)
> ****************************************
>
> private void FillSurfaceNew(Bitmap bmp)
> {
> if(surfaceBMP != null)
> surfaceBMP.Dispose();
>
> SurfaceDescription desc = new SurfaceDescription();
> desc.Clear();
> desc.SurfaceCaps.OffScreenPlain = true;
> desc.Width = bmp.Width;
> desc.Height = bmp.Height;
> surfaceBMP = new Surface(bmp,desc,localDevice);
> }
>
> Like I said, I get the same type of results going D3D route using a Texture
> and Sprite except that recreating the Texture
> and or Sprite does not seem to gain any ground.
>
> Anyone have any suggestions as to a better way of handling this? Also,
> Loading BMP's from files and storing as
> resources is not an option as the pixel data is created programattically per
> frame.
> Also, I realize that there are other factors as to what's going on in the
> render function but without posting all the code
> I can tell you that they are completely stripped down to the bare essentials
> with only the minimum methods to setup the drawing along with Surface.Draw
> or Sprite.Draw methods. In the case of DDraw, just switching which methods
> fills the surface with the bitmap makes a 400 fps difference. The window
> client area is the same size as the surface.
>
> This is something that DD7 could do easily by using the Blit methods and C++
> or VB. I know there has to better way in Managed DX other than destroying
> the surface each frame. Although it seems to work, it sure seems like a
> hack.
>
> Any help would be greatly appreciated.
>
> Thanks, Dwight
>
>
>
.



Relevant Pages

  • Re: Multiple shapes performance
    ... > and use as less as possible CPU. ... > DirectDraw, ... > GDI, DirectX whatever... ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Multiple shapes performance
    ... > and use as less as possible CPU. ... > DirectDraw, ... > GDI, DirectX whatever... ...
    (microsoft.public.win32.programmer.directx.video)