What is the difference between glTexParameterf and glTexParameteri

I am trying to understand what is the difference between the 2 APIs. For example, both calls are the same, if I'm not mistaken:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

      

The third parameter 'param' contains constant values ​​(for example GL_REPEAT

), so it doesn't matter if it is a floating point or an integer type.

Please explain.

+4


source to share


2 answers


They are just integer and float versions of the function.

In the case where the pname (second) parameter is GL_TEXTURE_WRAP_S

where you are passing the enumeration, you should use glTexParameteri

but for other possible values, such as GL_TEXTURE_MIN_LOD

and GL_TEXTURE_MAX_LOD

it makes sense to pass the parameter with a glTexParameterf

comma using glTexParameterf

. See the linked document for more information on whether to use the int or float version, depending on which pname you are setting. When passing enums like GL_REPEAT

you should use glTexParameteri

but the driver will most likely just convert it anyway if you are using glTexParameterf

.

for example (from the docs):



GL_TEXTURE_MIN_LOD Sets the minimum detail level parameter. This floating point value limits the selection of the highest resolution mipmap (lowest mipmap level). The initial value is -1000.

GL_TEXTURE_MAX_LEVEL Sets the index of the highest defined mipmap level. This is an integer value . The initial value is 1000.

It's up to you to use the correct version based on the second parameter.

+5


source


Answer

@samgak covers the purpose of two functions. glTexParameteri()

- for parameters integer and enum, glTexParameterf()

- for parameters float. In the OpenGL 4.5 specification, the type of each parameter is shown in Table 8.17 on p. 225/226.

The part that I don't really understand is if you have to use a function that matches the type of the parameter. Or, in other words, using the "wrong" function is a mistake. Older versions of the specification are somewhat ambiguous in this regard. For example, from the 3.3 spec (and many other versions I've looked at):

In the first form of the command, param is a value for which an unambiguous parameter is set; in other forms, params is an array of parameters, the type of which depends on the parameter being set.

This suggests that the correct type should be used at least for the shape of the array. It seems somewhat ambiguous if the same applies to scalar form.



As of spec 4.2, there is a clear definition for this. The above paragraph is followed (copied from 4.5 spec):

Data transformations are performed as indicated in section 2.2.1

where section 2.2.1 includes a description of the conversion between integers and floats, as you would expect.

Therefore, I believe the two functions can be used interchangeably in 4.2 and later. Of course, this is still good style for using a function that matches a parameter type. Prior to 4.2, using a function that does not match the parameter type looks potentially dangerous.

+1


source







All Articles