Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Do dummy sprites use video memory?

Author
Message
erebusman
13
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 8th Dec 2012 06:02
I started playing with dummy sprites and found a good use for them but I need to understand how it impacts memory?

Does anyone know if dummy sprites take Video memory?

If not how does it operate and how much memory does it take ?

Thanks for any help / answers

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 8th Dec 2012 10:59
My experince is that it is the shapes that uses resources on dummy sprites.
In my platformer so did i use shapes for all the sprites first and got extreme impact on performance.
Then i optimized the use of shapes to under half an got an high performance boost.

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
erebusman
13
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 8th Dec 2012 23:10
Thanks Cliff that tip makes some sense.

Defining the shape would be the point where it takes screen realestate.

I'm trying to figure out if for instance a PNG with transparency is less memory use than a dummy sprite on top of a flat rendered background that has the image of a button on it?

AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 9th Dec 2012 02:26 Edited at: 9th Dec 2012 02:47
I remember Paul writing once, that as soon as you call LoadImage, the image will be loaded and stored in GPU memory.

While I couldn't locate that specific post anymore, I did find a few other relevant posts that Paul has made. So I'll quote him for reference, with my notes below the quotes:

http://forum.thegamecreators.com/?m=forum_view&t=191961&b=41

Paul wrote:
"Cloning a sprite is the same as creating a new one, it just saves you having to copy the parameters. Sprites themselves don't use that much memory, the images assigned to them use far more so as long as they share images (and don't each load their own copy of the image) it should be fine."

NOTES:

The sprite data (including physics shapes) is not stored in GPU RAM. But of course general application performance will be effected when a large number of shapes is defined. (The shape data is likely recalculated when sprites containing shapes are rotated, scaled or moved, but this has no impact whatsoever on GPU memory usage.)

http://forum.thegamecreators.com/?m=forum_view&t=195060&b=41

Paul wrote:
"Currently all images are stored as 32bit RGBA images in GPU memory. Any images that aren't a power 2 in size are scaled up to the nearest power of 2 internally on mobile devices."

NOTES:

Wise usage of atlas images allows you to save GPU RAM.

Just as an example, assuming you had an image with dimensions 160x100, when loaded to GPU RAM, that image would take as much space as one that was 256x256 (the next largest dimensions for a power of 2 size image, able to contain the 160x100 image).

If you loaded TWO of those images, they would take up 2x256x256x4 (RGBA) bytes of GPU RAM. However, both images would fit on a single 256x256px atlas image (you can fit them within 256x256 in vertical alignment).

So, to repeat - in general, wise usage of Atlas images can save a lot of GPU RAM. Use them!

http://forum.thegamecreators.com/?m=forum_view&t=194664&b=41

Kamac wrote:
"Just a small counting:

One 32x32 RGBA (.png) image is 4096 bytes.
One MB is 1048576 bytes.

Then, if we have 60MB GPU memory free, we could store 15360 32x32 RGBA images."

Paul wrote:
"The math checks out. However, whilst the RAM may be hundreds on MB the graphics memory is usually smaller, for old iOS devices (e.g. 2nd gen iPod Touch) we recommend not using more than 24MB of graphics memory. Newer devices may get away with more."

NOTES:

The important thing to realize, here, is that the images will consume GPU memory, whether they contain transparency or not. The alpha channel is stored to GPU RAM along with the image data, even if it is just full of zeros! So, you do not save any GPU RAM by using transparency.

http://forum.thegamecreators.com/?m=forum_view&t=200996&b=41

Paul wrote:
"If you load too many images and overflow GPU memory then subsequent images may overwrite old ones or fail to load their pixels."

NOTES:

The important thing to note, here, is that there are currently NO commands to check the amount of GPU RAM used. Hopefully this will be fixed at some point... It should at least be simple to add an internal counter which shows how much image data has been copied to GPU RAM using LoadImage/GetImage (and other similar) commands.

But that would not reflect the total amount of GPU RAM used on a device... so, the usefulness of this solution would be limited,
but not non-existent.

http://forum.thegamecreators.com/?m=forum_view&t=195762&b=41

tessoft wrote:
"is there an internal image cache system - for example loading an image for one sprite is reused if I try to load the same image for again?"

Paul wrote:
"The image will be loaded 3 times. When we release image manipulation commands you would be able to modify the contents of an image ID so an image cache would be difficult to implement. "

NOTES:

Not much to add to that. Loading an image multiple times will consume as many times GPU memory, this should be obvious to everyone.

SUMMARY:

Dummy sprites do NOT consume GPU RAM at all - but there is an associated performance impact anyway, depending on what, and how, they are used.

Cheers,
AgentSam - the grumpy old software engineer
AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 9th Dec 2012 02:42
erebusman:

Quote: "I'm trying to figure out if for instance a PNG with transparency is less memory use than a dummy sprite on top of a flat rendered background that has the image of a button on it?"


So as not to fail to answer your actual question, I'll give a specific answer to that question:

A dummy sprite will definately consume LESS memory (both GPU and main ram), than a loaded image for a button.

It is the image resources which consume the GPU RAM (and a minor amount of main ram for the associated data structure).

Cheers,
AgentSam
erebusman
13
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 9th Dec 2012 03:39
wow AgentSam that is probably the most commanding use of the forums I've ever seen. You glued a lot together to answer my question, I am extremely appreciative thank you!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Dec 2012 10:59
Agreed, it's not often someone goes to such length. Nice work Sam!


this.mess = abs(sin(times#))
Ian Rees
AGK Developer
12
Years of Service
User Offline
Joined: 3rd May 2012
Location: Wales, UK
Posted: 19th Dec 2012 09:46 Edited at: 19th Dec 2012 09:46
There is some incredibly useful information here in this thread about image sizes - thanks very much.

I have a couple of questions - the answers may be obvious but I'm seeking clarification.

If you create a sprite from a 32x32 image and then resize the sprite to 80x80 does that result in the sprite image being resized to 128x128 in GPU RAM?

Also should the images be square, i.e. 32x32, 128x128, 256x256, etc? Would a 256x128 image be resized to 256x256?

E

http://www.superiorinteractive.com/galaforceworlds
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Dec 2012 10:45
Quote: "If you create a sprite from a 32x32 image and then resize the sprite to 80x80 does that result in the sprite image being resized to 128x128 in GPU RAM?"

No the amount of memory taken up by an image is not affected by the size of the sprite on screen.

Quote: "should the images be square, i.e. 32x32, 128x128, 256x256, etc? Would a 256x128 image be resized to 256x256?"

No, if an image is power of two to start with it will not be padded out. 1, 2, 4, 8, 16, 32, 64, 128 etc sized images are not padded. An image 112x130 for example will be padded out to 128x256.


this.mess = abs(sin(times#))
Ian Rees
AGK Developer
12
Years of Service
User Offline
Joined: 3rd May 2012
Location: Wales, UK
Posted: 19th Dec 2012 10:48
That's great - thanks baxslash! Just wanted to check...

E

http://www.superiorinteractive.com/galaforceworlds
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 24th Dec 2012 06:09
Quote: "An image 112x130 for example will be padded out to 128x256."


Quote: "Just as an example, assuming you had an image with dimensions 160x100, when loaded to GPU RAM, that image would take as much space as one that was 256x256 (the next largest dimensions for a power of 2 size image, able to contain the 160x100 image)."


So, which is correct? Sam's example essentially states that the image should be a square...


~Plystire

A rose is only a rose until it is held and cherished -- then it becomes a treasure.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 25th Dec 2012 15:34
Images don't have to be square to be power of 2. Baxslash is (as always) correct in this instance.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 27th Dec 2012 05:52 Edited at: 27th Dec 2012 06:56
Well, here's the fundamental question: "What is the power of two rule?"

And here's a fairly good article about out it, which gives you the answer:
Making better textures for games, 'power of two' and proper image dimensions

However, we still have no guarantees that the AppGameKit texture sizing algorithm is implemented exactly like this. So, excuse me while I remain skeptical until I see the source - or hear from Paul, who actually wrote it.

But, it's fairly safe to assume that the information given by Baxslash is correct.

A few links for more background information:
iPhone Development: OpenGL ES From the Ground Up, Part 6: Textures and Texture Mapping
Why do images for textures on the iPhone need to have power-of-two dimensions?

Cheers,
AgentSam

EDIT: Some hardware, texture format (especially PVRTC compression on iPhone), and OpenGL ES implementation combinations also require textures to be square.

I would not be surprised to hear that AppGameKit also scales textures to power of two squares on some hardware, but not all... So.. hello, I love you, won't you show me your source.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 27th Dec 2012 07:20
What baxslash says is accurate and for those who need proof (and have a T2 iOS setup) you can access the image pointer.

E.g


The commands of interest are ptr->GetTotalWidth() and ptr->GetTotalHeight. These functions return the padded sizes. On a Windows pc, these commands won't show any difference which is why one should try this method on iOS (maybe Android).

Picture attached.

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 27th Dec 2012 11:24 Edited at: 27th Dec 2012 11:25
Well, I don't have any proof and haven't access to tier 2 to check Hodgey's code but Paul did explain that images did not have to be square as I originally thought from the start. I only found out that the images were padded out to a none square power of two size fairly recently.

As usual though Agent Sam you have provided some very interesting links on the subject, thanks for the read!


this.mess = abs(sin(times#))
Ian Rees
AGK Developer
12
Years of Service
User Offline
Joined: 3rd May 2012
Location: Wales, UK
Posted: 25th Jan 2013 09:39
If you have an atlas image sized 1024 x 1024, that contains all your game sprites, with a "subimages.txt" to go with it and load an image from the atlas image that is 56 x 86 (using LoadSubImage), does the sub image get resized to a power of 2 - in this case 64 x 128?

E

http://www.superiorinteractive.com/galaforceworlds
AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 25th Jan 2013 10:02
Hi Ian,

No, the subimage will not be resized, nor will a new image truly be created from it. It will be applied onto your sprite as a UV-texture, from the texture atlas, which remains at the said 1024x1024 size in your case.

The coordinates in the "subimages.txt" file can be thought of as UV-coordinates. (But few people think of these sprite bitmaps as textures, though that's what they really are, under the hood in the OpenGL pipeline.. Just like your sprites are actually a couple of polygons to make up a square box, on which that texture is applied.) But again, I guess I should keep this answer simple, few people need to care about what AppGameKit does under the hood, as long as your app works.

So, I hope the answer helps...

Cheers,
AgentSam
Ian Rees
AGK Developer
12
Years of Service
User Offline
Joined: 3rd May 2012
Location: Wales, UK
Posted: 25th Jan 2013 10:07
Hi AgentSam,

Yes, thank you. That is the answer I was looking for.

Thanks for the detailed response - it is interesting to know how it is handled "under the hood",

Ian

E

http://www.superiorinteractive.com/galaforceworlds

Login to post a reply

Server time is: 2024-11-27 23:11:50
Your offset time is: 2024-11-27 23:11:50