Gerdus van Zyl wrote:
> How can I reduce the time to blit to a texture?
> The size is 446x285 but takes 0.88 to 1.7 seconds to blit to texture.
> I am using the method used in the media player sample.
>
> The code I use, and is called in the program loop. The source
> (surf_clip) is a cairo image surface.
>
>         s = str(surf_clip.get_data())
>         pitch = sw * len('BGRA') * -1
>         imagedata = image.ImageData(sw, sh, 'BGRA', s,pitch )
>
>         texture = self.texture
>         glBindTexture(texture.target, texture.id)
>
>         #rx and ry = 0, will be used to update only part that changed
>
>         imagedata.blit_to_texture(texture.target, 0, rx, ry, 0)
>
> And the self.texture exactly like media/video:
>
>     def _get_texture(self):
>         if not self._texture:
>             glEnable(GL_TEXTURE_2D)
>             texture = image.Texture.create_for_size(GL_TEXTURE_2D,
>                 self.width, self.height, GL_RGB)
>             if texture.width != self.width or texture.height !=
> self.height:
>                 self._texture = texture.get_region(
>                     0, 0, self.width, self.height)
>             else:
>                 self._texture = texture
>         return self._texture
>     texture = property(_get_texture)
>   
ImageData does some magic behind the scenes to mash data into a format 
that GL will accept. This is really handy for the image decoders, but 
can lead to performance problems which are avoidable for this kind of thing.

The most obvious problem is using a negative pitch (top-to-bottom image 
rows) -- GL has no way of accepting this data, so ImageData splits the 
data and reorders it first.  Use a positive pitch (or better, leave 
pitch as the default, which is tightly packed) and swap the texture 
coordinates instead (to render it "upside-down").

The other problem is the image format.  We're lacking documentation on 
which formats are supported by GL and which are mashed by ImageData, but 
you can see what happens in pyglet/image/__init__.py, in 
ImageData._get_gl_format_and_type() (line 798 atm).  BGRA is not 
supported on any platform (and so will be mashed -- slowly -- by 
ImageData), so see if you can get Cairo to use a different surface 
format.  RGB or RGBA is supported everywhere, and BGR, ABGR or ARGB are 
supported  if certain GL extensions are present.

Good luck
Alex.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to