Skip to content

Commit

Permalink
Add anisotropic filtering to GLES2 backend
Browse files Browse the repository at this point in the history
Move definition of rendering/quality/filters/anisotropic_filter_level to
servers/visual_server.cpp, since both GLES2 and GLES3 now use it

rasterizer_storage_gles3.cpp: Remove a spurious variable write (the
value gets overwritten soon after)
  • Loading branch information
furrykef committed Feb 2, 2021
1 parent 0b6dd92 commit 09a156e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
30 changes: 30 additions & 0 deletions drivers/gles2/rasterizer_storage_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ GLuint RasterizerStorageGLES2::system_fbo = 0;

#define _EXT_TEXTURE_CUBE_MAP_SEAMLESS 0x884F

#define _GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#define _GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF

#define _RED_OES 0x1903

#define _DEPTH_COMPONENT24_OES 0x81A6
Expand Down Expand Up @@ -749,6 +752,16 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p
glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}

if (config.use_anisotropic_filter) {

if (texture->flags & VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {

glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, config.anisotropic_level);
} else {
glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);
}
}

int mipmaps = ((texture->flags & VS::TEXTURE_FLAG_MIPMAPS) && img->has_mipmaps()) ? img->get_mipmap_count() + 1 : 1;

int w = img->get_width();
Expand Down Expand Up @@ -957,6 +970,16 @@ void RasterizerStorageGLES2::texture_set_flags(RID p_texture, uint32_t p_flags)
glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}

if (config.use_anisotropic_filter) {

if (texture->flags & VS::TEXTURE_FLAG_ANISOTROPIC_FILTER) {

glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, config.anisotropic_level);
} else {
glTexParameterf(texture->target, _GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);
}
}

if ((texture->flags & VS::TEXTURE_FLAG_MIPMAPS) && !texture->ignore_mipmaps) {
if (!had_mipmaps && texture->mipmaps == 1) {
glGenerateMipmap(texture->target);
Expand Down Expand Up @@ -6069,6 +6092,13 @@ void RasterizerStorageGLES2::initialize() {
config.rgtc_supported = config.extensions.has("GL_EXT_texture_compression_rgtc") || config.extensions.has("GL_ARB_texture_compression_rgtc") || config.extensions.has("EXT_texture_compression_rgtc");
config.bptc_supported = config.extensions.has("GL_ARB_texture_compression_bptc") || config.extensions.has("EXT_texture_compression_bptc");

config.anisotropic_level = 1.0;
config.use_anisotropic_filter = config.extensions.has("GL_EXT_texture_filter_anisotropic");
if (config.use_anisotropic_filter) {
glGetFloatv(_GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &config.anisotropic_level);
config.anisotropic_level = MIN(int(ProjectSettings::get_singleton()->get("rendering/quality/filters/anisotropic_filter_level")), config.anisotropic_level);
}

//determine formats for depth textures (or renderbuffers)
if (config.support_depth_texture) {
// Will use texture for depth
Expand Down
3 changes: 3 additions & 0 deletions drivers/gles2/rasterizer_storage_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {

bool shrink_textures_x2;
bool use_fast_texture_filter;
bool use_anisotropic_filter;
bool use_skeleton_software;
bool use_lightmap_filter_bicubic;

Expand All @@ -82,6 +83,8 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
bool use_rgba_2d_shadows;
bool use_rgba_3d_shadows;

float anisotropic_level;

bool support_32_bits_indices;
bool support_write_depth;
bool support_half_float_vertices;
Expand Down
3 changes: 0 additions & 3 deletions drivers/gles3/rasterizer_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,6 @@ void RasterizerGLES3::make_current() {
}

void RasterizerGLES3::register_config() {

GLOBAL_DEF("rendering/quality/filters/anisotropic_filter_level", 4);
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/anisotropic_filter_level", PropertyInfo(Variant::INT, "rendering/quality/filters/anisotropic_filter_level", PROPERTY_HINT_RANGE, "1,16,1"));
}

// returns NULL if no error, or an error string
Expand Down
1 change: 0 additions & 1 deletion drivers/gles3/rasterizer_storage_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8355,7 +8355,6 @@ void RasterizerStorageGLES3::initialize() {

config.shrink_textures_x2 = false;
config.use_fast_texture_filter = int(ProjectSettings::get_singleton()->get("rendering/quality/filters/use_nearest_mipmap_filter"));
config.use_anisotropic_filter = config.extensions.has("rendering/quality/filters/anisotropic_filter_level");

config.etc_supported = config.extensions.has("GL_OES_compressed_ETC1_RGB8_texture");
config.latc_supported = config.extensions.has("GL_EXT_texture_compression_latc");
Expand Down
2 changes: 2 additions & 0 deletions servers/visual_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,8 @@ VisualServer::VisualServer() {
GLOBAL_DEF("rendering/quality/depth_prepass/enable", true);
GLOBAL_DEF("rendering/quality/depth_prepass/disable_for_vendors", "PowerVR,Mali,Adreno,Apple");

GLOBAL_DEF("rendering/quality/filters/anisotropic_filter_level", 4);
ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/anisotropic_filter_level", PropertyInfo(Variant::INT, "rendering/quality/filters/anisotropic_filter_level", PROPERTY_HINT_RANGE, "1,16,1"));
GLOBAL_DEF("rendering/quality/filters/use_nearest_mipmap_filter", false);

GLOBAL_DEF("rendering/quality/skinning/software_skinning_fallback", true);
Expand Down

0 comments on commit 09a156e

Please sign in to comment.