Fastest way to fill a texture (MiniB3D)

Started by JBR, August 29, 2019, 18:27:27

Previous topic - Next topic

JBR

Hi,

I've been using Krischans code to convert pixmap to texture. Basically 2 lines of GL code.

I'm wondering if there is a faster way. I've seen the Method WritePixels but I don't know how to use it or if I can even use it.

My data is held in a pixmap.

Any ideas appreciated, Jim.

angros47

Textures are often stored in the video card memory, not in regular memory (unless your system uses shared memory, or software only rendering). Since the way to access it varies according to the hardware used (as I said, in some cases there isn't even a dedicated video memory), the only way to transfer a pixmap to a texture in OpenGL is to use the tools provided by the specific driver. The command that does that transfer is glTexImage2D. If you want to transfer not the whole image, but just a part of it, you can also use glTexSubImage2D (it was often used when the texture has to have a side that is a power of two, and the picture doesn't fit that)

Since OpenB3D uses mipmapping (aka different versions of the picture, at different sizes, to optimize scaling), you should either transfer each version of the texture (some graphic formats store all of them, but I guess in your pixmap you have only one copy of the picture, at only one size), or you should tell OpenGL driver to generate all the other versions of the texture on its own (for example with glGenerateMipmap, although oldest version of OpenGL don't support it).

The command gluBuild2DMipmaps, from the GLut library, does both thing: also, it works even on older versions that didn't provide the glGenerateMipmap command.

The method WritePixels just uses glTexSubImage2D

JBR

Thanks very much for taking the time to explain it to me.

Jim