@Override
    public void setTexture(int unit, Texture tex) throws TextureUnitException {
        if (unit < 0 || unit >= RenderContext.maxTextureUnits) {
            throw new TextureUnitException();
        }
        
        Image image = tex.getImage();
        if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) {
            // Check NPOT requirements
            boolean scaleToPot = false;

            try {
                checkNonPowerOfTwo(tex);
            } catch (RendererException ex) {
                if (logger.isLoggable(Level.WARNING)) {
                    int nextWidth = FastMath.nearestPowerOfTwo(tex.getImage().getWidth());
                    int nextHeight = FastMath.nearestPowerOfTwo(tex.getImage().getHeight());
                    logger.log(Level.WARNING,
                            "Non-power-of-2 textures are not supported! Scaling texture '" + tex.getName() +
                                    "' of size " + tex.getImage().getWidth() + "x" + tex.getImage().getHeight() +
                                    " to " + nextWidth + "x" + nextHeight);
                }
                scaleToPot = true;
            }

            updateTexImageData(image, tex.getType(), unit, scaleToPot);
        }

        int texId = image.getId();
        assert texId != -1;

        setupTextureParams(unit, tex);
        if (debug && caps.contains(Caps.GLDebug)) {
            if (tex.getName() != null) glext.glObjectLabel(GL.GL_TEXTURE, tex.getImage().getId(), tex.getName());
        }
    }
Uploads the given image to the GL driver.

@param img The image to upload
@param type How the data in the image argument should be interpreted.
@param unit The texture slot to be used to upload the image, not important
@param scaleToPot If true, the image will be scaled to power-of-2 dimensions
before being uploaded.
jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java