LWJGL Sampler object wrapper

Hello.

In my attempts to convert everyone to more modern OpenGL I present to you my sampler object wrapper class!

Sampler objects are used to separate how a texture is filtered (sampled) from the actual texture object. It actually makes no sense to store how the data is accessed together with the data. If we want for example different GL_NEAREST filtering when rendering a sprite, but also want to render this sprite with mipmaps and filtering (GL_LINEAR_MIPMAP_LINEAR) as an icon somewhere else we either have to have two textures or make an expensive texture bind even more expensive by having to set the filtering, clamp mode and LOD settings each time it is to be used. Sampler objects solve this problem by storing the filtering, clamp and lod settings in a separate object. This also allows you to bind the same texture to two different texture units and sample from it with two different filtering modes in a shader. Even if you don’t have a problem with how textures work at the moment, it still makes it all a bit cleaner and easier to understand.

My small wrapper class can be found here: http://www.java-gaming.org/?action=pastebin&id=211

Features:

  • Some basic documentation (JavaDoc).
  • Supported by OGL 2 hardware through extensions. Minimum requirements: Radeon HD 2000 series or Geforce 6000 series (also supported by a number of Intel cards).
  • Setters for all (most?) sampler settings available.
  • Checks for anisotropic filtering support and clamps max anisotropy value to the valid implementation specific range.

If someone could test this out I would be grateful. Example use case:


//At load time:
sampler = new Sampler();
sampler.setWrapModes(GL_CLAMP_TO_EDGE);
sampler.setMinMagFilter(GL_LINEAR, GL_LINEAR);


//When rendering:

glBindTexture(...);
sampler.bind(0); //Bind to first texture unit
//render as usual...