glgsg: Force nearest filtering on isampler/usampler

Without this, Intel drivers will sample (0, 0, 0, 1)
This commit is contained in:
rdb 2021-01-17 12:10:42 +01:00
parent f20d859fe2
commit 38d304f2fe
4 changed files with 39 additions and 4 deletions

View File

@ -12409,10 +12409,20 @@ specify_texture(CLP(TextureContext) *gtc, const SamplerState &sampler) {
}
}
if (Texture::is_integer(tex->get_format())) {
// Integer format textures can't have filtering enabled, and in fact, some
// drivers (looking at you, Intel) will always sample (0, 0, 0, 1) if we
// don't set this correctly!
glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
uses_mipmaps ? GL_NEAREST_MIPMAP_NEAREST
: GL_NEAREST);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
} else {
glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
get_texture_filter_type(minfilter, !uses_mipmaps));
glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
get_texture_filter_type(magfilter, true));
}
// Set anisotropic filtering.
if (_supports_anisotropy) {

View File

@ -2849,6 +2849,11 @@ update_shader_texture_bindings(ShaderContext *prev) {
}
continue;
}
else if (Texture::is_integer(tex->get_format())) {
// Required to satisfy Intel drivers, which will otherwise sample zero.
sampler.set_minfilter(sampler.uses_mipmaps() ? SamplerState::FT_nearest_mipmap_nearest : SamplerState::FT_nearest);
sampler.set_magfilter(SamplerState::FT_nearest);
}
if (tex->get_texture_type() != spec._desired_type) {
switch (spec._part) {

View File

@ -2628,6 +2628,25 @@ is_srgb(Format format) {
}
}
/**
* Returns true if the indicated format is an integer format, false otherwise.
*/
bool Texture::
is_integer(Format format) {
switch (format) {
case F_r32i:
case F_r8i:
case F_rg8i:
case F_rgb8i:
case F_rgba8i:
case F_r16i:
return true;
default:
return false;
}
}
/**
* Computes the proper size of the texture, based on the original size, the
* filename, and the resizing whims of the config file.

View File

@ -625,6 +625,7 @@ public:
static bool has_alpha(Format format);
static bool has_binary_alpha(Format format);
static bool is_srgb(Format format);
static bool is_integer(Format format);
static bool adjust_size(int &x_size, int &y_size, const std::string &name,
bool for_padding, AutoTextureScale auto_texture_scale = ATS_unspecified);