-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello everyone !
René Dudfield wrote: > Hi, > > try using surfarray. To avoid converting the data to a python string. > pyopengl supports numpy arrays to do this. > This is very nice ! So far, I followed Brian's tip, and changed from RGBX to RGB. It is already faster. > > # something like this... untested. > w,h = surf.get_size() > data = pygame.surfarray.pixels2d(surf) > texture = glGenTextures(1) > glBindTexture(GL_TEXTURE_2D, texture) > glPixelStorei(GL_UNPACK_ALIGNMENT,1) > glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data) > # ... etc... > Since I am reading from the pygame.camera.Camera, the image has a 24 bit depth. This format is the only one that is not supported by surfarray.pixels2d. Can I change the format that the Camera gives me ? > Also to speed up image loading/decoding... > import pygame.threads > pygame.threads.init(8) > surfs = pygame.threads.tmap(pygame.image.load, your_images) > > Another thing to do is to make sure you are reusing textures (if > possible). Since allocating a new texture each time can be slow, so > if you application allows it, reuse textures. > I am much used to that kind of texture reusage. (that's one of the reasons why I am addicted to OpenGL, even when it would be better not to use it...) In this case, though, I am reading live from the camera, plus reading though a very long list of surfaces, often more than the number of textures I can store on the graphics card. Thanks a lot for helping ! alex > > > cheers, > > > On Mon, Jan 4, 2010 at 4:06 AM, Alexandre Quessy <[email protected]> wrote: >> Hello Pygame users and developers ! >> >> Is there a way I can speed up the transfert from a surface to an >> OpenGL texture ? Right now, I use the pygame.image.tostring function, >> but it seems like converting the pixels to a Python str creates a >> serious bottle neck in my stop motion application... >> >> I think that it should either be implemented directly in Pygame, (best >> option) or done using something like ctypes in my application. If none >> of these option is not easy enough, I am thinking about switching to >> Gstreamer+GTK with the GdkPixBuf, instead of Pygame surfaces. An other >> option would be to rewrite the whole application in C++... >> >> Any suggestion to fix this in a way that is not too long ? >> My frame rate drops to 4 FPS when there are more than a few surfaces in my >> list. >> Please try Toonloop to test this out. It works well on Linux. If >> someone get it to work on Mac or Windows, I would need hints for >> packaging it for those OS too. I convert the surfaces to OpenGL >> texture in texture_from_image from the file >> http://bitbucket.org/aalex/toonloop1/src/tip/toon/draw.py on what is >> currently the line 42. >> -- >> Alexandre Quessy >> http://alexandre.quessy.net/ >> > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iQIcBAEBAgAGBQJLSt6RAAoJEJQ0pOgl2qx1Js8P/2bLR2NQt5AM8lxY6fLQ6R5y LVAGSAYZM1Kn0A2Cdi4au0ua6eUrnusKFLhWs3KSZGxSWX8PNvaOypBTdQiAV31/ f9m7eC3DcqpsmYMWU7MedeqAgPwzAUtj6EW6EGvY0JFRjdN1P7o2eb96+3RJKUtv v/GwBewjdN1iHJrg0dPN5UEH9dGXl6pNBDHnsey6rhCc3d5bZhjLuXxGd7wKToCf MgCTdsiq4fQMrDUkZ157oeuWn5douROP2pTK5J78oKFXBVaA2n1skzJ92Kn3iTpY uJc2KUbFhvBXWn+n+UyFwn85T/WvB+ctpm8q+fjX78JkXvR9INxir9XN8JFLhFRu kwb36DBbbqtnniRuI0N4ZSYASK/HL1Cxea5K/ANR9pQ80DSy7w1jhfR9h1dg3gPX HOaooQ9TY2c07oFiM52s2VU8iUOWA8jL1xKcNvbYk27Lzioqj9DQtJDVjubLI9u6 fT4m06YYcZ/XWTw0EnYNjocvBIxmcEgqgnBmMJotKMPKRY1caM8C+1ueT1UltJf9 24VWI/Hce+m/e9gkz7oETGrxPcX5hmbb97Zrny7g5mBS7/owcSEu/WPB/fWqzivo HEy+nsMaLxgxjc5KNqCb8Cguv6xz8NJaaug52D2dNC1IQY2GtNZkx7MCYuwuk4KL ENhR8tSqSRFuAzssztDC =X/rK -----END PGP SIGNATURE-----
