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 .
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;