Using an OpenGL texture

Picture

So recently I started reading articles on the OpenGL wiki. This is how I draw the OpenGL texture described here here . Although, a few points are not clear yet.

Will the following statements be true: false or depends?

  • Linking two textures with the same texture unit is not possible.
  • Linking two samplers with the same texture unit is not possible.
  • It is not possible to bind one texture to two different texture units.
  • It is not possible to bind one sampler to two different texture units.
  • It is the responsibility of the application to be clear about which type of sampler is being passed to which uniform variable.
  • It is the responsibility of the shader program to take the probe as the correct type of homogeneous variable.
  • the number of texture units is quite large. Let each mesh loaded into the application take up as much texture unit as possible.
  • Some Sampler parameters duplicate texture parameters. They will override the texture settings.
  • Some Sampler parameters duplicate the description of the sampler in the shader program. The Shader program description will override the sampler parameters.
+3


source to share


1 answer


Now I will talk about your statements. Sometimes I will argue with quotes from the OpenGL 4.5 core profile specification . None of this applies to GL 4.5, I just chose it because it is the most recent version.

1. Linking two textures to the same texture unit is not possible.

If I were to say “false”, it is probably misleading. The exact statement would be: "Linking two textures with the same target of the same texture unit is not possible." Technically you can say bind 2D texture and 3D texture to the same device. But you cannot use both in the same callback. Note that this is a dynamic error condition that depends on what values ​​you set the sampler formula. Quoting from Section 7.10 "Samplers" of the GL Specification:

You cannot have variables of different types of samplers pointing to the same block of textured image inside the program object. This situation can only be detected at the next render command that invokes shader calls, and an error INVALID_OPERATION

will then be generated.

So GL will detect this error condition as soon as you actually try to draw something (or otherwise trigger shader calls) with those shaders, as long as you set it up so that the two sampler shapes refer to different targets of the same devices. But this is not a mistake. If you temporarily set both uniforms to the same value, but do not attempt to draw in this state, no error is generated.

2.

You cannot link two samples to one texture unit.

You probably mean Sampling Objects (as opposed to just sampler types in GLSL), so that's true.

3.

You cannot link one texture to two different textures.

False. You can link the same texture object to as many units as available. However, this is a completely useless operation. Back in the days of the fixed function pipeline, there were some corner cases where this was of limited use. For example, I saw someone link the same texture twice and use register combining to multiply together because they needed a square operation. However, with shaders, you can try the texture once and do whatever you want with the result, so you really don't need to use.

4.

You cannot bind one sampler to two different texture units.

False. One sampler object can be referenced by multiple texture units. You can simply create a sampler object for each desired sampling state, no need to create redundant ones.



5. It is the responsibility of the application to have a clear idea of ​​which type of sampler is being passed to which uniform variable.

6. It is the responsibility of the shader program to ensure that the sampler accepts the correct homogeneous variable type.

I'm not really sure what you are asking here. The sampler variable in your shader picks the texture target and must also match the internal data from the texture object you want to use (i.e. for isampler

or usampler

, you will need unnormalized integer texture formats, otherwise the results are undefined).

But I don't know what it means "which type of sampler is passed to which uniform variable". On the client side of the GL, the opaque sampler form is just something that can be set to the index of the texture unit used, and this is done as an integer through glUniform1i

or the like. There is no "sampler type" passed to the homogeneous variable.

7. The number of texture units is large enough. Let each mesh loaded into the application take up as much texture unit as possible.

Not in general. Required GL_MAX_TEXTURE_IMAGE_UNITS

(which determines how many different texture units a fragment shader can access) according to GL 4.5 specification is 16. (There are separate restrictions for each shder stage, so there are GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS

, GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS

etc. They must all be at least 16 in the current specification.)

You usually need to switch textures between draw calls. Using arrays of arrays and texture glasses ... can further reduce the number of state switches needed (and ultimately attract calls).

Modern GPUs also support GL_ARB_bindless_texture , which completely bypasses the "texture unit" indirection layer and allows the shader to directly reference the texture object using some opaque handle (which basically boils down to mentioning the GPU virtual memory address under the hood). However, this feature is not yet part of the OpenGL standard.

8. Some Sampler parameters duplicate texture parameters. They will override the texture settings.

Yes. Traditionally, GL hasn't had separate sampler objects. Instead, sampler parameters such as filtering or wrapping modes were part of the texture object itself. But modern hardware doesn't work that way, so the Sampler Object API was introduced as an extension GL_ARB_sampler_objects

(it's currently the main function of GL). If a sampler object is bound to a texture unit, its settings will override the state of the sampler present in the texture object.

9. Some Sampler parameters duplicate the description of the sampler in the shader program. The Shader program description will override the sampler parameters.

I'm not sure what you mean by that. What is a "descripton probe", does the shader program specify? There is only a homogeneity declaration and possibly initialization via layout(binding=...)

. However, this is only an initial value. The client can update this at any time by setting the uniformity to a different value, so it doesn't really "override" anything. But I'm not sure if you mean it.

+3


source







All Articles