Pixel data from GLTexFromPixmap()

BlitzMax Forums/OpenGL Module/Pixel data from GLTexFromPixmap()

plash(Posted 2008) [#1]
Is there a way to get the pixel data for a texture id obtained by using GLTexFromPixmap()?

EDIT: This is for saving/loading, how would I load the data back into a gl texture (or whatever I should be calling it.)

EDIT2: Can we just use glTexCoord2f with pixmaps? (so the data can be saved/loaded a lot easier, and so we don't have to convert it to a GL id)


ImaginaryHuman(Posted 2008) [#2]
Pixmaps are bitmaps in main memory, Textures are areas of video ram. They are connected via a bus over which the data must travel. OpenGL lives in video ram and everything it has access to has to be accessible to the graphics card GPU, thus has to be in video ram. You have to get the data from main memory to video ram by using e.g. GlTexFromPixmap. That copies the pixmap to video ram as a texture. The Graphics card then can access the texture data. It cannot access the pixmap.

Once you've generated a texture from a pixmap (i think that function returns a texture handle integer?), the pixmap still exists, and you could easily just save the pixmap. If you've thrown the pixmap away, you'll need to draw the texture image to the backbuffer and then either use GrabPixmap or GLReadPixels to transfer it to main memory, then SavePixmapPNG().

You cannot use GLTexCoord2f with pixmaps, you can only use it with textures in video ram. The whole reason there are two distinct entities - textures and pixmaps, is because the GPU graphics card can only access the special video ram that is `on board` the graphics card itself. It cannot access main memory - unless you have integrated graphics which is pretty crappy. So because the GPU has to work with video ram and know where to look for stuff, and for performance reasons, it doesn't access main memory. This creates the need for a) a storage system in main memory for bitmap data (pixmaps), and b) a bus to transfer between them. So you're pretty much stuck with two separate storage spaces.


plash(Posted 2008) [#3]
Would it be safe to hold like.. 5000 44x44-44x144 tiles in vram? :o

Can we use GLVertex2f with pixmaps? (I'd like to just deal with the pixmaps so saving/loading is easier) Obviously not..

BTW I'm saving additional information in the file aswell (eg. tile id, name, flags, and pixel data.)


plash(Posted 2008) [#4]
Here is an idea:

(I'm thinking I should keep all the pixmaps loaded and just stuff them in vram, memory taxing? :( )
When drawing a tile in the map we stick all the textures currently on-screen in vram and access them as we draw the screen.
After we are finished drawing we keep the textures in vram until the screen position changes, when it does we check to see if the texture, for a given tile, is already loaded, and if it is we skip over it, if it is not we load it AND if the texture is no longer on-screen we remove it.

That should make it fairly quick..

How do I remove a texture from vram?


ImaginaryHuman(Posted 2008) [#5]
5000 44 x 44 textures at 4-bytes per texture is about 38 megabytes. You'd need at least that much vram if not more, and you can't do it all on one texture. There's nothing stopping you other than ram requirements.