OpenGL Anisotropic texture filtering patch

I have implemented anisotropic texture filtering for OpenGL in version 1.5.3 of Panda3D. Below I include the patches to glstuff/glGraphicsStateGuardian_src.cxx and glstuff/glGraphicsStateGuardian_src.h containing the changes I made. It’s quite simple, contains checks for the availability of the required extension and works on my Linux PC with nvidia card.

It will save me some work in the future, if this could be included in the next release of Panda :slight_smile: .

glstuff/glGraphicsStateGuardian_src.cxx:

*** glstuff/glGraphicsStateGuardian_src.cxx     2008-05-06 18:27:18.000000000 +0200
--- /home/laurens/software/panda3d-1.5.3/panda/src/glstuff/glGraphicsStateGuardian_src.cxx      2008-08-23 19:57:45.000000000 +0200
*************** reset() {
*** 1328,1333 ****
--- 1328,1343 ----

  #endif

+   // Check availability of anisotropic texture filtering.
+   if (has_extension("GL_EXT_texture_filter_anisotropic")) {
+     GLfloat max_anisotropy;
+     GLP(GetFloatv)(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy);
+     _max_anisotropy = (float)max_anisotropy;
+   }
+   else {
+     _max_anisotropy = 1.0;
+   }
+
    // Now that the GSG has been initialized, make it available for
    // optimizations.
    add_gsg(this);
*************** specify_texture(Texture *tex) {
*** 6903,6908 ****
--- 6913,6927 ----
    GLP(TexParameteri)(target, GL_TEXTURE_MAG_FILTER,
                       get_texture_filter_type(magfilter, tex->get_format(), true));

+   // Set anisotropic filtering.
+   float anisotropy = tex->get_anisotropic_degree();
+   if (anisotropy>_max_anisotropy) {
+     anisotropy = _max_anisotropy;
+   }
+   if (anisotropy>1.0) {
+     GLP(TexParameterf)(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);
+   }
+
    if (tex->get_format() == Texture::F_depth_stencil) {
      GLP(TexParameteri)(target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
      if (_supports_shadow_filter) {

glstuff/glGraphicsStateGuardian_src.h:

*** glstuff/glGraphicsStateGuardian_src.h       2008-04-10 22:18:20.000000000 +0200
--- /home/laurens/software/panda3d-1.5.3/panda/src/glstuff/glGraphicsStateGuardian_src.h        2008-08-23 17:06:57.000000000 +0200
*************** protected:
*** 412,417 ****
--- 412,419 ----
    pset<string> _extensions;

  public:
+   float _max_anisotropy;
+
    bool _supports_point_parameters;
    PFNGLPOINTPARAMETERFVPROC _glPointParameterfv;

Hmm, what is this feature exactly? Does it offer more functionality over the anisotrophic filtering that panda3d already has?
panda3d.org/manual/index.php/Textu … _Filtering

It is exactly that feature, but it was only available for directx afaik. Please don’t tell me it was already implemented for OpenGL and I overlooked it :slight_smile: . It took me already a day to figure out that my graphics driver was configured to always enable anisotropic filtering :blush: .

You’re right–for some reason, we’d overlooked implementing anisotropic filtering under OpenGL. Thank you for the patch; I will apply it happily!

David

Has this been implemented in 1.5.4? And is it still called with texture.setAnisotropicDegree(#) ?

Yes; have you tried it?

David

Sorry, I’m afraid I forgot to pick it up for 1.5.4. It will be in 1.6.0, though.