0

My goal is to test Flash 3D environment performance by generating lots of 3D cubes, rotating them and reading FPS.

I know that I can rotate 2D objects in 3D space. For example, I can construct a cube with 6 movie clips, rotating them and putting them together accordingly. Then I can generate lots of these cubes in random x,y,z locations (predefined area in front of viewport), rotate them and read fps.

But then I read about this hardware acceleration and it's unclear to me, when it is activated/used. Certain conditions must be met. I know that it must be allowed by the user (right click->settings->enable hardware acceleration) or if it is embedded through object tag, wmode=direct must be set.

That's from viewers side, but what from developers?

If I draw a simple red rectangle on stage, and user has enabled hardware acceleration, does that mean that graphic information will get rendered on GPU?

I'm reading various sources and "Adobe Flash 11 Stage3D Game Programming" book, and from what I gather, in order to render graphical information on GPU, I have to explicitly call Stage3D class in AS3, then I can draw my 2d/3d objects there.

Which is it - if I want my app to be run in hardware acceleration mode (and its enabled from viewers side), does it happen automatically no matter what the content in my flash file? Or do I have to add the Stage3D class there.

Thank you.

Will be waiting for the answer.

Starwave
  • 2,352
  • 2
  • 23
  • 30

3 Answers3

2

First off: Don't mix up 2 distinct concepts in Flash:

  • General Hardware Acceleration

This was introduced mainly for video playback in Flash Player 10. I am not sure if it used for graphics at all. It has nothing to do with rendering 3D Graphics directly on the GPU.

  • GPU Support

With Flash Player 11, Adobe introduced Stage3D. This is an interface through which Flash can render graphics utilizing the GPU, if available. On Windows it uses Direct3D, on Mac OpenGl. The classic Flash DisplayList Graphics API does not support this. You have to go through the Stage3D Api, as explained in the book you have mentioned. To use GPU Support in the browser the embed tag needs the attribute wmode set to "direct". Working directly with the Stage3D Api is not easy and you have to learn the concepts of 3D Programming, Shader Programming, etc. for doing this. There are some libraries which help working with Stage3D. For 3D there is i.e Away3D. If you just need 2D graphics with gpu support, Starling is a very popular framework these days.

otomo
  • 79
  • 4
  • FI-NA-LY! A constructive answer which shed light on this matter, those concepts are blendy, no wonder I got mixed 'em up. Yeah, got more information that everything we draw normaly in Flash is a DisplayList object, which cannot be processed on GPU, but objects drawn in Stage3D can be. Also, Stage3D objects will always be behind DisplayList objects, quite alot of discussions on that matter on the internet. But on the sidenote - what would happen if I have a full width/height stage3d drawing going on and on top of it there is a DisplayList object? Everything gets processed on GPU except DL obj? – Starwave May 28 '14 at 22:39
  • a good starting point to dive into this is probably: http://www.adobe.com/devnet/flashplayer/articles/how-stage3d-works.html – otomo May 30 '14 at 11:55
  • 1
    to answer your last question: yep! Although drawing classic DisplayList on top of Stage3D was not recommended because of performance drops. Adobe seems to have fixed this in the meantime: http://forum.starling-framework.org/topic/is-poor-performance-of-native-overlay-specific-to-starling – otomo May 30 '14 at 12:09
  • 1
    a good readup on the history of gpu support in Flash is http://blog.kaourantin.net/?p=138. – otomo May 30 '14 at 12:09
0

Here's a function that converts a movieclip into a bitmap. I use normal flash to create what is going to be shown on screen, then convert the movieclips to bitmaps and delete the movieclips:

private function fConvertClip(pClip: MovieClip, pWidth: int, pHeight: int): Bitmap {
var bd: BitmapData = new BitmapData(pWidth, pHeight, true, 0x00000000);
bd.draw(pClip, null, null, null, null, true);       
aBitmaps.push(bd);
var bmp: Bitmap = new Bitmap(bd, "auto", false);
bmp.smoothing = true;
return bmp;

}

moot
  • 653
  • 5
  • 13
-1

Don't turn on the hardware acceleration setting. In general, you control what's on the gpu with code. Bitmapdata is on the gpu so you convert everything that goes on the screen to bitmaps.

gotoandlearn.com has great tutorial videos on this.

You can create anything in normal flash - shapes, gradients, dropshadows, dynamic text, programmed coloring, etc. - and convert it all to bitmaps with programming while your game is running. You don't need to import images/spritesheets/animations. Have artists give you everything in vector. So when the user wants to change the color of a car, you simply convert the code instead of loading/importing a bitmap of the car in red.

moot
  • 653
  • 5
  • 13
  • "Don't turn on the hardware acceleration setting" - WHY? I am sorry, but this doesn't answer my question (see bold)... – Starwave May 25 '14 at 17:33
  • Because that setting does not force your rectangle to the gpu. It tries to check the user's computer and decides if the rectangle gets converted. You yourself said you saw how that setting is a decision.As I said, use code to force it to gpu. – moot May 26 '14 at 00:17
  • "Because that setting does not force your rectangle to the gpu." - good, now we are getting somewhere. Then the question is - what DOES force my rectangle to the gpu? – Starwave May 26 '14 at 00:52
  • Are "we getting somewhere?" I've answered your question (see the bitmap, gpu, tutorial, explanation of converting moviclips to bitmap, and actual code) but the problem is that you're not sure what you're asking? Post some of your code so we know what you know exactly what you're asking about. – moot May 26 '14 at 18:51
  • I found out what I wanted to know in a book, I'm currently working on putting all that on the paper, once it's done, I'll share the answer here. – Starwave May 27 '14 at 06:57