[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] OpenGL stretch of a pygame.Surface



Ok I now create my texture once.

I'm having some issues with this

> You're creating an extra copy of the texture data here.
> To avoid that, you could use surfarray to create a surface
> backed by a numpy array, do your drawing into that, and
> then pass the numpy array directly to glTexImage2D.

As I understand it, you suggest a surface with a surfarray.pixel2d bound
to it. But I can't blit on such surface beacause it's locked. Did you
mean drawing directly in surfarray or just create and update a
surfarray.2darray which involve to do a copy of the native screen also ?


Thanks for all your advises everyone. 


Le mercredi 30 juillet 2014 Ã 11:15 +1200, Greg Ewing a Ãcrit :
> sylvain.boussekey wrote:
>  > I managed to do it in opengl but perfs are poor.
> 
> A few things to consider:
> 
>  >         textureData = pygame.image.tostring(textureSurface, "RGBA", 1)
> 
> * You're creating an extra copy of the texture data here.
> To avoid that, you could use surfarray to create a surface
> backed by a numpy array, do your drawing into that, and
> then pass the numpy array directly to glTexImage2D.
> 
>  >         texture = glGenTextures(1)
>  >         glBindTexture(GL_TEXTURE_2D, texture)
>  >         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
>  >         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
> 
> * You're creating a new OpenGL texture for each frame and
> then discarding it. Try making these calls just once
> at the beginning and re-using the texture.
> 
> * You're using a non-power-of-2 texture size. Not all
> OpenGL implementations support that; yours seemingly does,
> but it might be less efficient than a power-of-2 size.
> You could try allocating the next larger power-of-2 size and
> updating the part that you use with glTexSubImage2D().
>