Quentin
Quentin

Reputation: 63154

How do base internal formats work?

The glTexImage2D function accepts, among others, the so-called "base internal formats" listed below:

GL_DEPTH_COMPONENT
GL_DEPTH_STENCIL
GL_RED
GL_RG
GL_RGB
GL_RGB

These appear to lack any type or size information. Quoting the documentation:

If an application wants to store the texture at a certain resolution or in a certain format, it can request the resolution and format with internalFormat. The GL will choose an internal representation that closely approximates that requested by internalFormat, but it may not match exactly. (The representations specified by GL_RED, GL_RG, GL_RGB, and GL_RGBA must match exactly.)

These formats are not listed in the documentation for glTexStorage2D, and I cannot find anything more precise about them. I've apparently made GL_RGBA work by dumb luck, but I would like to understand better what I'm doing here.

What exactly happens when I use a base internal format?
How are the type, size and layout of storage chosen?
Am I expected to query the chosen format afterwards and adjust the rest of my program, such as GLSL sampler types?

Upvotes: 1

Views: 616

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474436

The reason glTexStorage* doesn't allow "base internal formats" is because you should not be using them. It only supports internal formats with well-defined behavior.

What exactly happens when I use a base internal format?

You get an image format that is whatever the driver wants to give you, within the limits listed below.

How are the type, size and layout of storage chosen?

The "type" will for such textures always be unsigned, normalized integers. It will have at least the channels in the base internal format.

Everything else is entirely up to the driver. If the driver wants to add more channels than you specified, it can do so. If the driver wants to give you a 16-bit-per-channel format, it can do so.

Am I expected to query the chosen format afterwards and adjust the rest of my program, such as GLSL sampler types?

There's nothing to query, since they're always unsigned, normalized images. So you use sampler*, not usampler* or isampler* in shaders.

Upvotes: 2

Related Questions