• Advertisement
Sign in to follow this  

Interest of PBO for simple texture loading

This topic is 2154 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[font=arial,helvetica,sans-serif] Hi,[/font]

[font=arial,helvetica,sans-serif] I am currently developping a general texture loader for a 3D engine, and I was wondering what would be the intersest of using Pixel Buffer Objects for doing simple static texture loading. Here is the way I go right now :[/font]
[font=arial,helvetica,sans-serif]- In a thread devoted to loading, I load the texture pixels from an image on a drive, and save it into a char* ;[/font]
[font=arial,helvetica,sans-serif]- I generate the textures :[/font]
[font=arial,helvetica,sans-serif]glGenTextures( 1, &mTextureID ) ;
glBindTexture( GL_TEXTURE_2D, mTextureID ) ;
glTexImage2D( GL_TEXTURE_2D, 0, mTextureFormat, mWidth, mHeight, 0, mPixelFormat, mDataType, mImage.GetData() ) ;
[/font]
[font=arial,helvetica,sans-serif]- I signal the rendering thread that the texture is ready for use.[/font]

[font=arial,helvetica,sans-serif]Is it a good idea to insert a PBO operation before the glTexImage2D operation ? Something like that :[/font]
[font=arial,helvetica,sans-serif]glGenTextures( 1, &mTextureID ) ;
glBindTexture( GL_TEXTURE_2D, mTextureID ) ;
glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, mPBO_ID ) ;
glBufferData( GL_PIXEL_UNPACK_BUFFER_ARB, mImage.GetDataSize(), NULL, GL_STREAM_DRAW ) ;
char* pboMemory = glMapBuffer( GL_PIXEL_UNPACK_BUFFER_ARB,GL_WRITE_ONLY ) ;
memcpy( pboMemory,mImage.GetData(), mImage.GetDataSize() ) ;
glTexImage2D( GL_TEXTURE_2D, 0, mTextureFormat, mWidth, mHeight, 0, mPixelFormat, mDataType, mImage.GetData() ) ;
[/font]

[font=arial,helvetica,sans-serif]Of course, a PBO would not be created for each texture, but only 2 or 3 (the most recently used will be [/font]queued). As I understood PBO, the pixel transfer rate make it efficient, but is the CPU [font=arial,helvetica,sans-serif]glTexImage2D operation of the first piece of code [/font]really slower than the memcpy (that has to be done anyway) of the second piece of code ? Maybe the format conversion between the pixel data and the texture is slow ?

Do you think such a changing in the code could be an optimization ?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement