Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Interest of PBO for simple texture loading


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 TomSuede   Members   -  Reputation: 100

Like
0Likes
Like

Posted 02 March 2012 - 07:17 AM

Hi,

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 :
- In a thread devoted to loading, I load the texture pixels from an image on a drive, and save it into a char* ;
- I generate the textures :
glGenTextures( 1, &mTextureID ) ;
glBindTexture( GL_TEXTURE_2D, mTextureID ) ;
glTexImage2D( GL_TEXTURE_2D, 0, mTextureFormat, mWidth, mHeight, 0, mPixelFormat, mDataType, mImage.GetData() ) ;

- I signal the rendering thread that the texture is ready for use.

Is it a good idea to insert a PBO operation before the glTexImage2D operation ? Something like that :
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() ) ;


Of course, a PBO would not be created for each texture, but only 2 or 3 (the most recently used will be queued). As I understood PBO, the pixel transfer rate make it efficient, but is the CPU glTexImage2D operation of the first piece of code 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 ?

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS