I searched a lot and just can't seem to find anything on this topic. I got a Macbook with OpenGL 4.1. I create a Texture with:
glGenTextures(1, &heightMapTexture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, heightMapTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 13);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
glUniform1i(program1->uniformLocation("heightMap"), 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16UI, heightMap.getWidth(), heightMap.getHeight(), 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, heightMap.getData().data());
glGenerateMipmap(GL_TEXTURE_2D);
This works fine but I actually would like to use GL_LINEAR. But GL_LINEAR gives me a texture with all zeros / black.
Does Mac just not support GL_LINEAR or is there an extension for it? In the official documentation i found the following piece of code:
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,
GL_TEXTURE_MIN_FILTER, GL_LINEAR);
But I can't get the extension to work either.
GL_R16UI
is an integer texture format. OpenGL does not support linear filtering of integer formats.
From section 8.17 "Texture Completeness" of the OpenGL 4.5 spec, page 252:
Using the preceding definitions, a texture is complete unless any of the following conditions hold true:
[..] The internal format of the texture is integer [..] and either the magnification filter is not NEAREST, or the minification filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST.
To use texures with 16-bit per component precision that you can sample with linear filtering, you'll need to use a normalized format like GL_R16
, or go all the way to a float with GL_R32F
.