How to draw many identical Bitmaps faster?

Problems with Canvas, OpenGL, etc...

How to draw many identical Bitmaps faster?

Postby gskbyte » Sat Jun 05, 2010 3:34 pm

Hi,

I have many equal Bitmaps in my app (what I really have is a Bitmap with a list of Points where it will appear). Which is the fastest way to draw it many times?

The Canvas class doesn't have a method like drawPoints(<list of positions>) to draw many pictures, so I have to call drawBitmap() each time I want to draw my Bitmap. When you have to draw 100-150 times the Bitmap, it can be expensive. Do you know a better method?

Thank you!
gskbyte
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Tue Jan 12, 2010 1:51 pm

Top

Re: How to draw many identical Bitmaps faster?

Postby ShadowKntSDS » Sat Jun 05, 2010 4:50 pm

You may want to consider using openGL. If you are drawing screen aligned bitmaps (not rotated) the drawTex extension is very fast for single bitmaps, and VBO's are very fast drawing the same bitmap multiple times.
ShadowKntSDS
Junior Developer
Junior Developer
 
Posts: 15
Joined: Wed Apr 28, 2010 10:29 pm

Re: How to draw many identical Bitmaps faster?

Postby gskbyte » Sat Jun 05, 2010 5:47 pm

Thank you very much for your answer. Do you know any tutorial to learn OpenGL for Android?

Edit: I answer to myself: viewforum.php?f=2 </facepalm>
gskbyte
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Tue Jan 12, 2010 1:51 pm

Re: How to draw many identical Bitmaps faster?

Postby impi » Sun Jun 06, 2010 12:33 pm

There is a way. If you data is static you can use the Picture class, to record calls at loading time or so, and then just call the canvas.drawPicture();

Err i don't know if you can hack scrolling like for an tilemap or culling into it, because, if you change the data of the Picture frame to frame you lose your performance advantage.

But if you want superior performance, go opengl. But if done unproperly or some devices are fucked up this can be much more worse.
impi
Developer
Developer
 
Posts: 29
Joined: Wed Apr 28, 2010 11:17 pm

Re: How to draw many identical Bitmaps faster?

Postby pskink » Sun Jun 06, 2010 1:01 pm

pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: How to draw many identical Bitmaps faster?

Postby gskbyte » Sun Jun 06, 2010 1:10 pm

That looks interesting. How can one use it? There is very few documentation about BitmapShader :S. Thank you!
gskbyte
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Tue Jan 12, 2010 1:51 pm

Top

Re: How to draw many identical Bitmaps faster?

Postby pskink » Sun Jun 06, 2010 1:26 pm

gskbyte wrote:That looks interesting. How can one use it? There is very few documentation about BitmapShader :S. Thank you!


Paint#setShader

Canvas#drawRect
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: How to draw many identical Bitmaps faster?

Postby pskink » Sun Jun 06, 2010 1:26 pm

gskbyte wrote:That looks interesting. How can one use it? There is very few documentation about BitmapShader :S. Thank you!


Paint#setShader

Canvas#drawRect / drawPaint
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: How to draw many identical Bitmaps faster?

Postby gskbyte » Sun Jun 06, 2010 1:54 pm

Thank you, but this is not useful for what I want. I have many objects whose position may vary on each frame, and may have "random" positions. Using shaders what I have is a matrix of repeated bitmaps (with repeat and mirror modes).

I think I should finally use OpenGL. Yesterday I watched this video, and it is pretty interesting for my problem:
http://www.youtube.com/watch?v=U4Bk5rmIpic

Thank you!
gskbyte
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Tue Jan 12, 2010 1:51 pm

Re: How to draw many identical Bitmaps faster?

Postby pskink » Sun Jun 06, 2010 2:17 pm

gskbyte wrote:Thank you, but this is not useful for what I want. I have many objects whose position may vary on each frame, and may have "random" positions. Using shaders what I have is a matrix of repeated bitmaps (with repeat and mirror modes).

I think I should finally use OpenGL. Yesterday I watched this video, and it is pretty interesting for my problem:
http://www.youtube.com/watch?v=U4Bk5rmIpic

Thank you!


ok, i see, but what abiut LayerRasterizer?

never used it but it sounds it could be tested...
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: How to draw many identical Bitmaps faster?

Postby gskbyte » Sun Jun 06, 2010 3:01 pm

Hi,

I have just tried the app "SpriteMethodTest" from apps-for-android (http://code.google.com/p/apps-for-andro ... MethodTest) on my HTC Tattoo and, with 100 Sprites Canvas is MUCH faster than OpenGL methods. I suppose that this is because Tattoo doesn't offer hardware acceleration.

I think the best option is to offer software and HW methods for all the games.

Thank you!
gskbyte
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Tue Jan 12, 2010 1:51 pm

Re: How to draw many identical Bitmaps faster?

Postby impi » Sun Jun 06, 2010 8:35 pm

The SpriteMethodTest code is from ages ago and implements it's own GLSurfaceView.

An android device must support OpenGL 1.0 at least, so the "Basic Vert Quads" approach should run on every phone.

Note that the implementation of the SpriteMethodTest is not an indikator for game performance, since an TileMap can easily be batched into one glDrawArrays call, and this is horrendous faster than drawing each cell with one call.

The SpriteMethodTest use one call for each Sprite, which is quite ineffective but the only method for moving Sprites (if not cached)
impi
Developer
Developer
 
Posts: 29
Joined: Wed Apr 28, 2010 11:17 pm

Re: How to draw many identical Bitmaps faster?

Postby gskbyte » Sun Jun 06, 2010 8:51 pm

Hi, I have been looking for some info about LayerRasterizer and all I have found is this:

http://groups.google.com/group/android- ... b1fd529709

I think it will not be useful, but I will try something tomorrow.

About SpriteMethodTest, thanks for the info :). Anyways, even with this "old" test I can check that HTC Magic, for example, is faster than HTC Tattoo. As I said before, Ithink it is because it lacks HW acceleration.

Thank you for your suggestions!
gskbyte
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Tue Jan 12, 2010 1:51 pm

Re: How to draw many identical Bitmaps faster?

Postby pskink » Sun Jun 06, 2010 10:01 pm

gskbyte wrote:Hi, I have been looking for some info about LayerRasterizer and all I have found is this:

http://groups.google.com/group/android- ... b1fd529709

I think it will not be useful, but I will try something tomorrow.


well, this is my post which received no response

for what i observed adding layers to LayerRasterizer duplicates operations you perform using given Paint - for example drawCircle actually draws multiple circles

try it
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: How to draw many identical Bitmaps faster?

Postby gskbyte » Mon Jun 07, 2010 12:05 am

Hi,

thank you for your suggestion but, how do you use it? Right now I'm having only one Bitmap drawn. This is my code:

Code: Select all
        mPaint.setStrokeWidth(12);
       
        LayerRasterizer lr = new LayerRasterizer();
        Paint p = new Paint();
        for(int i=0; i<NPOINTS; ++i){
            lr.addLayer(p, pointPos.get(i).x, pointPos.get(i).y);
            /*
            canvas.drawBitmap(mGreenPoint,
                    pointPos.get(i).x- mOrgRect.left - offx,
                    pointPos.get(i).y- mOrgRect.top -offy,
                    null);
                    */
        }
       
        Paint p2 = new Paint();
        p2.setRasterizer(lr);
        p2.setStrokeWidth(20);
        p2.setColor(Color.YELLOW);
        //canvas.drawBitmap(mGreenPoint, 0, 0, p2);
        canvas.drawPoint(0, 0, p2);
gskbyte
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Tue Jan 12, 2010 1:51 pm

Top
Next

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 1 guest