PDA

View Full Version : Various texture questions


imikedaman
2006.07.17, 11:19 PM
As part of the optimization process, I have a few questions related to textures:

1) How can I make 2-bit/4-color textures that use a LUT? I read an article a few months ago saying they are still quite popular since it frees up some memory that can be used for larger or more textures, or for computers it could be as simple as just lowering the system requirements for the game.

2) This one is probably easier, but how about black and white textures or grayscale textures? Sometimes I have textures that are only various shades of a certain color, so I could save a lot of memory by converting the texture to grayscale and just tinting it to the right color in the program.

That should be all. Thanks!

Skorche
2006.07.17, 11:29 PM
You can create grayscale (luminance) textures. See the man page for glTexImage2D, there are a large number of modes available for the internal format. However, index color modes are not supported on OS X. I don't believe it's possible to have less than 8bit color textures. Even if you use GL_RGBA2, it's entirely possible that it will get converted to something larger anyway.

In reality, even a 16MB graphics card can hold a 16 512x512 32bit textures.

imikedaman
2006.07.17, 11:35 PM
However, index color modes are not supported on OS X. I don't believe it's possible to have less than 16bit color textures.
Drats. Oh well, no biggie. I was mainly interested in using grayscale images, as opposed to using 32-bits for what is essentially a grayscale texture anyway.

Thanks, I'll check out the different modes it supports.

imikedaman
2006.07.17, 11:48 PM
Huh, the man pages say that the luminance values are converted into RGB values, which kind of ruins the point. Am I better off just making a 16-bit grayscale image and loading it in as RGB?

OneSadCookie
2006.07.17, 11:59 PM
You're reading the man page wrong.

OpenGL lets you supply 1, 2, 3 or 4 channels of data for the texture. What is actually stored is up to the hardware. For example, my understanding is that recent NVidia cards support 1, 2 or 4 channels, so 3 will be expanded to 4 on the way to the video card.

OpenGL always works in four channels, so whenever you read a texture, you get an RGBA pixel, regardless of what the internal format of that texture is. For example, if you have a 1-channel luminance texture, when you read from it, you'll get (L, L, L, 1).

The GeForce 2 series of hardware supported paletted textures, but the extension was only available on certain older versions of Mac OS X.

You can emulate paletted textures on DX9 cards using a single-channel texture as the index, and a 1D 4-channel texture as the palette, and a fragment shader to perform the dependent texture lookup. How that interacts with filtering is not immediately obvious to me, and it's likely to be slower than just using a 4-channel texture to begin with :)

arekkusu
2006.07.18, 04:38 AM
What Keith said.

Also, you can easily check what the renderer says it promoted (or downgraded, as the case may be) the internal format to, via glGetTexLevelParameteriv and GL_TEXTURE_INTERNAL_FORMAT.

If you try submitting every possible texture format and then checking what they all ended up as, you can get a rough idea of what the renderer supports internally.

If you google around you can even find these tables already published. For example see table 5.6 in Nvidia's GPU Programming Guide (http://download.nvidia.com/developer/GPU_Programming_Guide/GPU_Programming_Guide.pdf). ATI supports a couple formats that NV doesn't, such as R3G3B2 and RGB10_A2.