Game Development Community

How to load PVRTC files?

by Richard Skala · in iTorque 2D · 05/21/2011 (6:38 pm) · 15 replies

I am in the process of testing the PVRTC files, but I am not sure how to load them into the game. I have an image called 'enemy_cell_00.png', and the PVR converter tool created files called (for Perspective, 4 bits per pixel): enemy_cell_00_P4.pvr and enemy_cell_00_preview_P4.png.

Obviously, the "_preview" one is simply how it will look, but I am not sure what to do with the .pvr file.

Do I delete 'enemy_cell_00.png' and put 'enemy_cell_00_P4.pvr' in its place? Or do I do the same except rename the PVR file to 'enemy_cell_00.pvr'? Also, do I have to change all the datablocks (images and animations) from .png to .pvr?

Thanks for any help. I haven't found any resources that address these questions.

#1
05/21/2011 (8:00 pm)
I never noticed this before, but each t2dImageMapDatablock has a value called 'compressPVR'. It seems that you need to replace the '.png' file with the '.pvr' file and change the "imageName" field of the datablock to the pvr file, as well as setting 'compressPVR' to "1".

However, I am using a CELL imagemap and I keep getting an error:

t2dImageMapDatablock::calculateCellImageMap() - Invalid Cell Height of 64.
ImageMap(enemy_cell_00ImageMap)SrcBitmap(game/data/images/enemy_cell_00.pvr) Error: 'Invalid CELL Dimension!' (15)

According to the debugger, it throws this error because:
mCellHeight > mSrcBitmapHeight

mCellHeight = 64
mSrcBitmapHeight = 1

This doesn't seem right because the dimension of the source image is 512x512, and each cell is 32x64. Also, mSrcBitmapWidth = 268374014, which is also obviously incorrect.

This PVR stuff doesn't seem worth the headache.
#2
05/22/2011 (6:01 pm)
You should never add the file extension. cause if you don't add it, it will look for png in the editor (pvr don't work outside the device and simulator) but for pvr in the build. This also means that in the project pvr and png must be present
#3
05/22/2011 (10:04 pm)
So, what is the process to use these PVR files? There is no useful documentation that I can find anywhere here.

By the way, it seems that "compressPVR" value is not actually used at all in the engine.
#4
05/22/2011 (10:23 pm)
From what I can tell, you have to change the datablock image to ".pvr", otherwise "constructBitmapPVR" is never called. I am still getting that "Invalid Cell Dimension" error.
#5
05/23/2011 (2:21 pm)
I am looking into PVR this week as well. One of my colleagues wrote the following post awhile back in regards to torque and PVR: http://blog.kihongames.com/2011/labs-pvrtc-powervr-texture-compression/

He suggests removing the file extension as well. I'll confirm that this week.
#6
05/23/2011 (3:48 pm)
It works.

Torque never required file extensions, actually unless someone messed with the docs, they should clearly state to never provide the file extension as that was how it was since TGB 0.7 already and basically forever on TGE too and for iT2D since day -1 ;)

Fileextension are one of the arch nemesis if you want to have it just working.
#7
05/23/2011 (5:50 pm)
Ah, it DOES work. Thank you both. The extension under "imageName" must not be there; that is, for example, for an imagemap named 'enemy_cell_00ImageMap', with images 'enemy_cell_00.png' and 'enemy_cell_00.pvr':

imageName = "~/data/images/enemy_cell_00";

Also, I don't know if it matters, but the following values were set as such:

compressPVR = "1";
optimised = "1";
#8
05/24/2011 (9:41 am)
I have compressPVR and optimized set to 0 and judging by the MemoryMonitor in Instruments, it is working.

I am seeing a massive swing. W/ a 768x1024 JPG and a 550 x 600 PNG I am seeing 12 MB just sitting in real memory w/in instruments. Shouldn't they get dealloc after they are sent to graphics card?

When I convert both images to 1024x1024 PVR files, I am seeing less than a MB of real memory being used.

12mb swing for 2 full screen images. Does that seem correct?

Non-PVR images seem broken. After dropping in our art w/out using PVRTC we hit 70mb for just loading all menus... not even loading the first level. We are switching it to loading only the menus we need and converting to the PVR format... both of which we should have done from the onset, but at the same time I would not have expected the memory footprint to be this horrible for a handful of full screen images.

Thoughts?
#9
05/24/2011 (10:56 am)
Do you have all your imagemap datablocks' "preload" value set to "1"? From what I understand, any datablock with preload = "1" will be loaded into memory when first loading and will stay in memory.
#10
05/24/2011 (11:18 am)
Interesting. I had overlooked preload and allowUnload... did not know they existed.

They seem to only be in the .t2d files though, is that correct? If I am loading all of our menu's via GUI I am not sure this applies.

I am finding that the memory is fluctuating now that I am no longer exec on startup.

Starts around 15.5mb w/ my PVR main menu.

My level select is still using PNG

When I load level select it jumps to 24.5 mb.

When I hit back and pop the LevelSelect it drops down to roughly 15.5 again. So GUIs do seem to be unloading. I'll have to keep an eye on .t2d files once I even uncomment that code and see if allowUnload and preload is any help.

Cheers for the heads up.
#11
05/24/2011 (12:25 pm)
Yes, I believe that the datablocks stuff is only for t2d files. I don't know how to unload GUIs, though.

By the way, I noticed that you are using JPG's and non-power-of-two images. I read from various places that you should only be using PNG files, and images should always be power-of-two. Non power-of-two images will be padded to the next highest power of two. For example, your 550 x 600 PNG will be padded to 1024x1024. I know you said you are converting them to PVR, but you also mentioned that you think they are broken, so maybe that is your problem.
#12
05/24/2011 (2:04 pm)
I believe PVR is working. I thought the GUI memory was broken but I didn't fully understand how exec GUI worked.

Apparently when you exec the GUI it loads any bitmaps into memory. When you pop the gui it deallocs the memory.

So if you exec all your gui's before you need them, they will sit in memory even if you do NOT push them. Once you pop them, they will remove themselves from memory. And you can push/pop as expected from there.

Moral of the story, don't exec until you are ready to push the GUI.
#13
05/24/2011 (2:09 pm)
By the way, how do you unload GUIs? I haven't used any GUIs besides mainScreen.gui in my project because in the version of iTGB that I am using (1.4), the GUI Editor is broken (you can't select images to add).
#14
05/24/2011 (3:44 pm)
I have just been doing Canvas.pushDialog(GUIName); to show it and Canvas.popDialog(GUIName); to hide it. This seems to load and unload correctly as far as memory goes.

The GUI Editor is beyond broke ;), but you can still apply images to GUI's by handing by opening the .gui files and editing the bitmap = "" field. However, I really do not our current setup and think sticking with SceneObjects probably would have been better.
#15
05/24/2011 (4:03 pm)
Thanks for that.

We are using Scene Objects for our GUI because the GUI Editor was so broken. For the most part, it has worked well for us, but one thing that you should be aware of is that if you pause the scene (for example, by using Con::setVariable( "$timeScale", "0" ) ), then your scene objects will not move or scale at all, but they will still respond to mouse events and setImageMap().