Groups | Blog | Home
all groups > dotnet performance > november 2005 >

dotnet performance : .NET CF Drawing Problems



MoriCristian
11/20/2005 5:24:02 AM
Hi!
Since DirectX are implemented only in mobile 5.0 and I must develop for
2003, I started to create a 3d engine on my own, but I get stuck immediatly
for performance problems.

I created dif function that draw a line using a Bresenham algorithm on a
Bitmap


private void DrawLine(Bitmap bmp, int x0, int y0, int x1,int y1)
{
int ddy,ddx,yi,xi,icx,icy,e;
ddy=y1-y0;
ddx=x1-x0;
if (ddx<0) icx=-1;
else icx=1;
ddx*=icx;
if (ddy<0) icy=-1;
else icy=1;
ddy*=icy;
e=0; xi=x0; yi=y0;
bool inv=false;
if (ddy>ddx) inv=true;
bool bquit=false;
if (!inv)
{
while(bquit==false)
{
bmp.SetPixel(xi,yi,Color.Black);
e=e+ddy;
if (2*e>ddx)
{
yi+=icy;
e=e-ddx;
}
xi+=icx;
if (xi==x1)
bquit=true;
}
}
else
{
while(bquit==false)
{
bmp.SetPixel(xi,yi,Color.Black);
e=e+ddx;
if (2*e>ddy)
{
xi+=icx;
e=e-ddy;
}
yi+=icy;
if (yi==y1)
bquit=true;
}
}
}

This algorithm was a start not only for line drawing, but also to implement
the goraud shading and texture mapping.
However, it is to slow, and the bottleneck is in the Bitmap.Setpixel!!!
Unfortunately there is no LockBits method as in the full .net framework, so
I cannot speed it up using this trick.

Is there any other way to do so?

I was thinking to keep a unmanaged Bitmap created by me (but I must first
discover how) do all the processing here and then blt it on the surface of
the pockepc.

Any advice is welcome

Thanks and regards
MoriCristian
11/21/2005 3:19:04 AM
Hi Yuan, thanks for your reply

If I create a buffer, how can I convert it to a bitmap?

Anyway, I'm trying to use the GAPI as shown in the msdn .NET Compact
Framework Gaming technical article.

Thanks
Cristian Mori

[quoted text, click to view]
v-yren NO[at]SPAM microsoft.com (
11/21/2005 7:56:49 AM
Hi Cristian,

Welcome to MSDN newsgroup!

Based on my understanding, your concern is the Bitmap.Setpixel method has
the bad performance in your application. If I have misunderstood anything,
please let me know.

By using Reflector tool, you can find the Bimap.Setpixel method calls the
GdipBitmapSetPixel function which belongs to native GDI. So I think the
problem is not caused by .NET Compact Framework. As far as I know, neither
..NET CF nor EVC (Embedded Visual C++) contains LockBits method because the
platform doesn't supply it.

In the situation, I suggest we should create a buffer like the LockBits
does by ourselves. If the performance also bad, I think maybe the problem
caused by algorithm. Or you can post the issue to GDI queue and discuss
with the people who may have more experience about GDI performance.

I hope the above information helps, if you have any questions or concerns,
please do not hesitate to let me know. I am looking forward your reply.

Yuan Ren [MSFT]
Microsoft Online Support
v-yren NO[at]SPAM microsoft.com (
11/22/2005 5:52:40 AM
Hi Cristian,

Thanks for your posting!

Based on my experience, the simple way to create a buffer is using the
Graphics object to draw line, and then save the Graphics as the Bitmap. The
below article has shown us the GAPI how to create the buffer:
http://www.devx.com/Intel/Article/17711
Actually, there is not easy to use the managed code does the same thing
like GAPI does. As we all know, the performance of managed code is not good
as the unmanaged code do. So if you have more concern about the
performance, I suggest you try to use the unmanaged code. If the unmanaged
code also has bad performance, maybe the algorithm causes it which I have
said before.

If you have any concern, please for you free let me know, I'm glad to be
the future assistant.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
AddThis Social Bookmark Button