Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tips n tricks for fast texture loading?



Hi,

Having recently finished the port of a couple of games (Commandos 2 & 3) which do a large amount of in-level texture uploading, I can offer the following advice.

-Stick to the standard Mac formats (8888 ARGB & 1555 ARGB or 422 YUV for QuickTime movie data)
This avoids any pixel swizzling happening in the driver level which will impact your performance (requiring a copy of the data in the driver as well as the pixel swizzling itself).


ie:
			internalformat = 	GL_RGBA8;
			format = 			GL_BGRA_EXT;
			type   = 			GL_UNSIGNED_INT_8_8_8_8_REV;

for 8888 ARGB

			internalformat = 	GL_RGB5_A1;
			format = 			GL_BGRA_EXT;
			type   = 			GL_UNSIGNED_SHORT_1_5_5_5_REV;

for 1555 ARGB

			internalformat = 	GL_RGBA;
			format = 			GL_YCBCR_422_APPLE;
			type   = 			GL_UNSIGNED_SHORT_8_8_REV_APPLE;

for 422 YUV (QT movie data)

-Use rectangle textures
This is the current fast path for texturing on OS X. It does come with some possibly severe limitations like no mipmaps and only clamped wrap modes.


-Use client side storage
This removes another driver side copy of the data but does mean you are now responsible for the data and will need to synchronize access to that data.


Basically you set it all up like this:

glGenTextures( 1, &GLTextureID );

if( GLTextureID != 0 )
{
	glEnable(GL_TEXTURE_RECTANGLE_EXT);
	glBindTexture(GL_TEXTURE_RECTANGLE_EXT, GLTextureID);

// Set row pixels
glPixelStorei(GL_UNPACK_ROW_LENGTH, rowPixels);

// Set storage hint. Can also use GL_STORAGE_SHARED_APPLE see docs.
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_CACHED_APPLE);


	// Set client storage
	glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);

// Set proper state for rectangle textures
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, internalformat, Width, Height,
0, format, type, pixelData);


// turn off client storage so it doesn't get picked up for the next texture
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
}


Assuming you will changing the texture data and re-uploading it to GL using glTexSubImage2D, you will need to synchronize with the GL to ensure that you do not change the texture data while the GL is using it since we have used client storage.

There are a bunch of ways to do this but I found the most convenient to be glFinishObjectAPPLE (which can be used for pretty much any of the GL objects and not just texture objects). Basically, before you change the texture data call:

// ensure any previous use of the texture has completed
glFinishObjectAPPLE( GL_TEXTURE, GLTextureID );

This will block until the GL has finished using the texture data, at which point you are free to modify the data.

One other thing you can try is threading your texture uploads. Create a shared context on a separate thread and use it to upload all of the textures. The GL should handle the thread synchronization between the shared contexts (ie. the shared threaded upload context and the other shared contexts that would actually be using the textures. Remember never access the same context from different threads). I have not tried this approach yet although it is on my list of things to explore :)

Hope this helps.

Thierry Faucounau

Senior 3D Engineer -- Zonic
http://www.zonic.co.uk/games/

On Apr 25, 2005, at 1:05 AM, Jonathan del Strother wrote:

I'm loading textures on-the-fly - a few hundred files from harddisk, mostly around 300x300 pixels in size, as & when needed. I'm currently using Quicktime (GetGraphicsImporterForFile, GraphicsImportDraw etc) - I found this about 50% faster than loading the file into an NSImage -> TIFFRepresentation -> NSBitmapImageRep.

I could do with some suggestions on speeding this up. Are there any file formats which Quicktime will process faster than others? Any resources discussing the fastest ways of uploading the texture data to video? Any random tips I might be missing would be greatly appreciated.

Cheers,
Jon

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Mac-opengl mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden
References: 
 >Tips n tricks for fast texture loading? (From: Jonathan del Strother <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.