Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL: Why do square textures take less memory

Tags:

opengl

Question: Why does the same amount of pixels take dramatically less video memory if stored in a square texture than in a long rectangular texture?

Example: I'm creating 360 4x16384 size textures with the glTexImage2D command. Internal format is GL_RGBA. Video memory: 1328 MB.

If I'm creating 360 256x256 textures with the same data, the memory usage is less than 100MB.

Using an integrated Intel HD4000 GPU.

like image 461
Szak1 Avatar asked Aug 08 '16 09:08

Szak1


1 Answers

It's not about the texture being rectangular. It's about one of the dimensions being extremely small.

In order to select texels from textures in an optimal fashion, hardware will employ what's known as swizzling. The general idea is that it will restructure the bytes in the texture so that pixels that neighbor each other in 2 dimensions will be neighbors in memory too. But doing this requires that the texture be of a certain minimum size in both dimensions.

Now, the texture filtering hardware can ignore this minimum size and only fetch from pixels within the texture's actual size is. But that extra storage is still there, taking up space to no useful purpose.

Given what you're seeing, there's a good chance that Intel's swizzling hardware has a base minimum size of 32 or 64 pixels.

In OpenGL, there's not much you can do to detect this incongruity other than what you've done here.

like image 187
Nicol Bolas Avatar answered Oct 24 '22 06:10

Nicol Bolas