April 08, 2020, 07:38:58 AM

Author Topic: Fastest way to fill a texture (MiniB3D)  (Read 468 times)

Offline JBR

  • Jr. Member
  • **
  • Posts: 81
Fastest way to fill a texture (MiniB3D)
« on: August 29, 2019, 06:27:27 PM »
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.

Offline angros47

  • Jr. Member
  • **
  • Posts: 42
Re: Fastest way to fill a texture (MiniB3D)
« Reply #1 on: August 29, 2019, 07:08:33 PM »
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

Offline JBR

  • Jr. Member
  • **
  • Posts: 81
Re: Fastest way to fill a texture (MiniB3D)
« Reply #2 on: August 29, 2019, 09:51:05 PM »
Thanks very much for taking the time to explain it to me.

Jim

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal