Heath Feather wrote:
> Yes Samuel, Thanks for the response.
> 
> I completely agree, Once I saw this behavior and diagnosed it I switched form 
> something like this.
> 
>   for(int nY=0; nY < 10; ++nY){
>     for(int nX=0 nX < 10; ++nX){
>        image.setPixel(nX,nY,color);
>     }
>   }
> 
> To something like this 
> 
>   uchar* pBits         = image.bits();
>   int nBytesPerLine    = image.bytesPerLine();
> 
>   for(int nY=0; nY < 10; ++nY){
>     for(int nX=0 nX < 10; ++nX){
>         uchar * scanLine = pBits+nY*nBytesPerLine;
>        ((uint *)scanLine)[nX] = color;
>      }
>   }
> 
> And saw an 800x improvement. Even though this is still not optimal, it was 
> well within the performance profile I required.
> 
> I tried to avoid the QImage::scanLine() method since it too contains a 
> detach() call. (see my discussion of the double detach in setPixel())
> 
> The other thing not to miss is that when I was monitoring the 
> qt_gl_clean_cache() call, I would see it called by Qt as part of their 
> internal Backing Store machinery. A simple switching of tabs on a tab widget 
> in my application invoked 1800 calls to this (very expensive) method. And 
> just dragging your mouse across widgets causes this to be called a tremendous 
> amount too.
> 
> If you don't mind me asking. What is the exact purpose of this Texture Cache ?
> 
> Heath.

Yes, using the scanLine() function per row can also cause some overhead 
if the width of the image is small, so the absolute fastest way is to 
use bits() and compute offsets as you go, but it's a trade-off of 
maintainability/readability and performance.

The texture cache contains a mapping from QImages and QPixmaps to OpenGL 
texture ids, and its purpose is to avoid re-uploading data to texture 
memory as much as possible when using the QGL-classes. When 
images/pixmaps are no longer referenced we remove them from the cache. 
The check to see whether they are part of the cache is done when 
detach() is called on an image/pixmap that is only referenced from one 
place. Currently the check is a lot more expensive than it needs to be, 
but we are working on fixing this. As a workaround you could try to free 
any images/pixmaps that have been bound as textures when they are no 
longer in use, although this might very well be impractical in most cases.

Regards,

Samuel Rødal
_______________________________________________
Qt4-preview-feedback mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback

Reply via email to