Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between glTexParameterf and glTexParameteri

Tags:

opengl

I'm trying to understand what the difference is between the 2 APIs. For example, both callings 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 (eg: GL_REPEAT), so it doesn't matter if it's a float or integer type.

Please explain.

like image 971
user2877748 Avatar asked Apr 28 '15 12:04

user2877748


2 Answers

It's just the integer and float versions of the function.

In the case where the pname (second) parameter is GL_TEXTURE_WRAP_S where you are passing an enum 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 a float parameter using glTexParameterf. See the linked doc for more information about whether to use the int or float version, based 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 use the glTexParameterf.

e.g (from the docs):

GL_TEXTURE_MIN_LOD Sets the minimum level-of-detail parameter. This floating-point value limits the selection of 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.

like image 167
samgak Avatar answered Nov 06 '22 03:11

samgak


@samgak's answer covers the purpose of the two functions. glTexParameteri() is for integer and enum parameters, glTexParameterf() is for float parameters. In the OpenGL 4.5 spec, the type of each parameter is listed in table 8.17 on page 225/226.

The part that was not entirely clear to me is if you have to use the function matching the type of the parameter. Or in other word, if using the "wrong" function is an error. Older versions of the spec seemed somewhat ambiguous in that respect. For example from the 3.3 spec (and many other versions I looked at):

In the first form of the command, param is a value to which to set a single-valued parameter; in the remaining forms, params is an array of parameters whose type depends on the parameter being set.

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

Starting with the 4.2 spec, there is a clear definition for this. The paragraph quoted above is followed by (copied from 4.5 spec):

Data conversions are performed as specified in section 2.2.1

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

So I believe the two functions can be used interchangeably in 4.2 and later. Of course it's still good style to use the function that matches the parameter type. Before 4.2, using the function that does not match the parameter type looks potentially unsafe.

like image 38
Reto Koradi Avatar answered Nov 06 '22 04:11

Reto Koradi