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

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



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().

--
Greg