private void bindTextureAndUnit(int target, Image img, int unit) {
        if (context.boundTextureUnit != unit) {
            gl.glActiveTexture(GL.GL_TEXTURE0 + unit);
            context.boundTextureUnit = unit;
        }
        if (context.boundTextures[unit]==null||context.boundTextures[unit].get() != img.getWeakRef().get()) {
            gl.glBindTexture(target, img.getId());
            context.boundTextures[unit] = img.getWeakRef();
            statistics.onTextureUse(img, true);
        } else {
            statistics.onTextureUse(img, false);
        }
    }
Ensures that the texture is bound to the given unit
and that the unit is currently active (for modification).

@param target The texture target, one of GL_TEXTURE_***
@param img The image texture to bind
@param unit At what unit to bind the texture.
jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java