Example usage for org.lwjgl.opengl GL11 glTexParameteri

List of usage examples for org.lwjgl.opengl GL11 glTexParameteri

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glTexParameteri.

Prototype

public static void glTexParameteri(@NativeType("GLenum") int target, @NativeType("GLenum") int pname,
        @NativeType("GLint") int param) 

Source Link

Document

Sets the integer value of a texture parameter, which controls how the texel array is treated when specified or changed, and when applied to a fragment.

Usage

From source file:ar.com.quark.backend.lwjgl.opengl.DesktopGLES20.java

License:Apache License

/**
 * {@inheritDoc}// w  w  w .j  ava2s . c  o m
 */
@Override
public void glTexParameter(int target, int type, int value) {
    GL11.glTexParameteri(target, type, value);
}

From source file:betterfonts.GlyphCache.java

License:Open Source License

/**
 * Allocate a new OpenGL texture for caching pre-rendered glyph images. The new texture is initialized to fully transparent
 * white so the individual glyphs images within can have a transparent border between them. The new texture remains bound
 * after returning from the function./*from   www  .  j a va  2 s  . c  o  m*/
 *
 * @todo use GL_ALPHA4 if anti-alias is turned off for even smaller textures
 */
private void allocateGlyphCacheTexture() {
    /* Initialize the background to all white but fully transparent. */
    glyphCacheGraphics.clearRect(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    /* Allocate new OpenGL texure */
    singleIntBuffer.clear();
    GL11.glGenTextures(singleIntBuffer);
    textureName = singleIntBuffer.get(0);

    /* Load imageBuffer with pixel data ready for transfer to OpenGL texture */
    updateImageBuffer(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    /*
     * Initialize texture with the now cleared BufferedImage. Using a texture with GL_ALPHA8 internal format may result in
     * faster rendering since the GPU has to only fetch 1 byte per texel instead of 4 with a regular RGBA texture.
     */
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureName);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_ALPHA8, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, imageBuffer);

    /* Explicitely disable mipmap support becuase updateTexture() will only update the base level 0 */
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
}

From source file:colonialdisplay.AntDisplayGL.java

private void initTextures() {

    // enable alpha blending
    GL11.glEnable(GL11.GL_BLEND);/*from  www.j  a  v  a2 s  .c  o m*/

    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    tmap = new TextureMapper();

    tmap.initSheet(this.getClass().getResource("/colonialimages/spritesheethighres_5_2_2014.png"), "PNG");
    tmap.addSpriteLocation("sand", new Rectangle2D.Float(0f, .625f, .25f, .125f));
    tmap.addSpriteLocation("leaf", new Rectangle2D.Float(.25f, .625f, .25f, .125f));
    tmap.addSpriteLocation("stream", new Rectangle2D.Float(.5f, .5f, .25f, .125f));
    tmap.addSpriteLocation("brownleaf", new Rectangle2D.Float(0f, .75f, .25f, .125f));
    tmap.addSpriteLocation("redleaf", new Rectangle2D.Float(.25f, .75f, .25f, .125f));
    tmap.addSpriteLocation("anthill", new Rectangle2D.Float(.25f, .5f, .25f, .125f));

    tmap.addSpriteLocation("antNorth", new Rectangle2D.Float(.25f, 0, .25f, .125f));
    tmap.addSpriteLocation("antNorthEast", new Rectangle2D.Float(0, .125f, .25f, .125f));
    tmap.addSpriteLocation("antSouthEast", new Rectangle2D.Float(.25f, .125f, .25f, .125f));
    tmap.addSpriteLocation("antSouth", new Rectangle2D.Float(.5f, 0, .25f, .125f));
    tmap.addSpriteLocation("antSouthWest", new Rectangle2D.Float(.75f, 0, .25f, .125f));
    tmap.addSpriteLocation("antEast", new Rectangle2D.Float(0, 0, .25f, .125f));
    tmap.addSpriteLocation("antWest", new Rectangle2D.Float(.75f, .125f, .25f, .125f));
    tmap.addSpriteLocation("antNorthWest", new Rectangle2D.Float(.25f, .125f, .25f, .125f));

    tmap.addSpriteLocation("builderAntNorth", new Rectangle2D.Float(.5f, .625f, .25f, .125f));
    tmap.addSpriteLocation("builderAntNorthEast", new Rectangle2D.Float(.75f, .5f, .25f, .125f));
    tmap.addSpriteLocation("builderAntSouthEast", new Rectangle2D.Float(.25f, .875f, .25f, .125f));
    tmap.addSpriteLocation("builderAntSouth", new Rectangle2D.Float(.5f, .75f, .25f, .125f));
    tmap.addSpriteLocation("builderAntSouthWest", new Rectangle2D.Float(.5f, .875f, .25f, .125f));
    tmap.addSpriteLocation("builderAntEast", new Rectangle2D.Float(0, .875f, .25f, .125f));
    tmap.addSpriteLocation("builderAntWest", new Rectangle2D.Float(.75f, .75f, .25f, .125f));
    tmap.addSpriteLocation("builderAntNorthWest", new Rectangle2D.Float(.75f, .625f, .25f, .125f));

    tmap.addSpriteLocation("pheromoneReturn1", new Rectangle2D.Float(.25f, .375f, .25f, .125f));
    tmap.addSpriteLocation("pheromoneReturn2", new Rectangle2D.Float(.5f, .375f, .25f, .125f));
    tmap.addSpriteLocation("pheromoneReturn3", new Rectangle2D.Float(.75f, .25f, .25f, .125f));
    tmap.addSpriteLocation("pheromoneReturn4", new Rectangle2D.Float(.75f, .375f, .25f, .125f));
    tmap.addSpriteLocation("pheromoneFood1", new Rectangle2D.Float(0, .25f, .25f, .125f));
    tmap.addSpriteLocation("pheromoneFood2", new Rectangle2D.Float(0, .375f, .25f, .125f));
    tmap.addSpriteLocation("pheromoneFood3", new Rectangle2D.Float(.25f, .25f, .25f, .125f));
    tmap.addSpriteLocation("pheromoneFood4", new Rectangle2D.Float(.5f, .25f, .25f, .125f));
    tmap.addSpriteLocation("pheromoneNone", new Rectangle2D.Float(.75f, .875f, .25f, .125f));
    tmap.addSpriteLocation("pheromoneDanger", new Rectangle2D.Float(0, .5f, .25f, .125f));

    /*      tmap.initSheet("src/colonialimages/spritesheet2.png", "PNG");
     tmap.addSpriteLocation("sand", new Rectangle2D.Float(.5f,.5f,.25f,.25f));
     tmap.addSpriteLocation("leaf", new Rectangle2D.Float(.25f,.5f,.25f,.25f));
     tmap.addSpriteLocation("anthill", new Rectangle2D.Float(0,.5f,.25f,.25f));
                
     tmap.addSpriteLocation("antNorth", new Rectangle2D.Float(.25f,0,.25f,.25f));
     tmap.addSpriteLocation("antNorthEast", new Rectangle2D.Float(.5f,0,.25f,.25f));
     tmap.addSpriteLocation("antSouthEast", new Rectangle2D.Float(.25f,.25f,.25f,.25f));
     tmap.addSpriteLocation("antSouth", new Rectangle2D.Float(0,.25f,.25f,.25f));
     tmap.addSpriteLocation("antSouthWest", new Rectangle2D.Float(.5f,.25f,.25f,.25f));
     tmap.addSpriteLocation("antEast", new Rectangle2D.Float(0,0,.25f,.25f));
     tmap.addSpriteLocation("antWest", new Rectangle2D.Float(.75f,.25f,.25f,.25f));
     tmap.addSpriteLocation("antNorthWest", new Rectangle2D.Float(.75f,0,.25f,.25f));
                
     tmap.addSpriteLocation("pheromoneReturn", new Rectangle2D.Float(.25f,.75f,.25f,.25f));
     tmap.addSpriteLocation("pheromoneFood", new Rectangle2D.Float(0,.75f,.25f,.25f));
     tmap.addSpriteLocation("pheromoneNone", new Rectangle2D.Float(.5f,.75f,.25f,.25f));
     */
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);

    GL11.glEnable(GL11.GL_TEXTURE_2D);
}

From source file:com.adavr.player.globjects.Texture.java

License:Open Source License

public static Texture create(int internalFormat, int width, int height, int format, int type,
        ByteBuffer pixels) {//from   w  w w  . j a va 2  s  . c  om
    int id = GL11.glGenTextures();
    int target = GL11.GL_TEXTURE_2D;

    GL11.glBindTexture(target, id);

    GL11.glTexImage2D(target, 0, internalFormat, width, height, 0, format, type, pixels);

    GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

    return new Texture(id, target);
}

From source file:com.ardor3d.scene.state.lwjgl.LwjglTextureStateUtil.java

License:Open Source License

/**
 * bind texture and upload image data to card
 *///w  w  w  .  j a v  a  2 s.c om
public static void update(final Texture texture, final int unit) {
    final RenderContext context = ContextManager.getCurrentContext();
    final ContextCapabilities caps = context.getCapabilities();

    texture.getTextureKey().setClean(context.getGlContextRep());

    // our texture type:
    final Texture.Type type = texture.getType();

    // bind our texture id to this unit.
    doTextureBind(texture, unit, false);

    // pass image data to OpenGL
    final Image image = texture.getImage();
    final boolean hasBorder = texture.hasBorder();
    if (image == null) {
        logger.warning("Image data for texture is null.");
    }

    // set alignment to support images with width % 4 != 0, as images are
    // not aligned
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    // Get texture image data. Not all textures have image data.
    // For example, ApplyMode.Combine modes can use primary colors,
    // texture output, and constants to modify fragments via the
    // texture units.
    if (image != null) {
        final int maxSize = caps.getMaxTextureSize();
        final int actualWidth = image.getWidth();
        final int actualHeight = image.getHeight();

        final boolean needsPowerOfTwo = !caps.isNonPowerOfTwoTextureSupported()
                && (!MathUtils.isPowerOfTwo(image.getWidth()) || !MathUtils.isPowerOfTwo(image.getHeight()));
        if (actualWidth > maxSize || actualHeight > maxSize || needsPowerOfTwo) {
            if (needsPowerOfTwo) {
                logger.warning(
                        "(card unsupported) Attempted to apply texture with size that is not power of 2: "
                                + image.getWidth() + " x " + image.getHeight());
            }
            if (actualWidth > maxSize || actualHeight > maxSize) {
                logger.warning(
                        "(card unsupported) Attempted to apply texture with size bigger than max texture size ["
                                + maxSize + "]: " + image.getWidth() + " x " + image.getHeight());
            }

            int w = actualWidth;
            if (needsPowerOfTwo) {
                w = MathUtils.nearestPowerOfTwo(actualWidth);
            }
            if (w > maxSize) {
                w = maxSize;
            }

            int h = actualHeight;
            if (needsPowerOfTwo) {
                h = MathUtils.nearestPowerOfTwo(actualHeight);
            }
            if (h > maxSize) {
                h = maxSize;
            }
            logger.warning("Rescaling image to " + w + " x " + h + " !!!");

            // must rescale image to get "top" mipmap texture image
            final int pixFormat = LwjglTextureUtil.getGLPixelFormat(image.getDataFormat());
            final int pixDataType = LwjglTextureUtil.getGLPixelDataType(image.getDataType());
            final int bpp = ImageUtils.getPixelByteSize(image.getDataFormat(), image.getDataType());
            final ByteBuffer scaledImage = BufferUtils.createByteBuffer((w + 4) * h * bpp);
            final int error = MipMap.gluScaleImage(pixFormat, actualWidth, actualHeight, pixDataType,
                    image.getData(0), w, h, pixDataType, scaledImage);
            if (error != 0) {
                Util.checkGLError();
            }

            image.setWidth(w);
            image.setHeight(h);
            image.setData(scaledImage);
        }

        if (!texture.getMinificationFilter().usesMipMapLevels()
                && !texture.getTextureStoreFormat().isCompressed()) {

            // Load textures which do not need mipmap auto-generating and
            // which aren't using compressed images.

            switch (texture.getType()) {
            case TwoDimensional:
                // ensure the buffer is ready for reading
                image.getData(0).rewind();
                // send top level to card
                GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0,
                        LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), image.getWidth(),
                        image.getHeight(), hasBorder ? 1 : 0,
                        LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                        LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
                break;
            case OneDimensional:
                // ensure the buffer is ready for reading
                image.getData(0).rewind();
                // send top level to card
                GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0,
                        LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), image.getWidth(),
                        hasBorder ? 1 : 0, LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                        LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
                break;
            case ThreeDimensional:
                if (caps.isTexture3DSupported()) {
                    // concat data into single buffer:
                    int dSize = 0;
                    int count = 0;
                    ByteBuffer data = null;
                    for (int x = 0; x < image.getData().size(); x++) {
                        if (image.getData(x) != null) {
                            data = image.getData(x);
                            dSize += data.limit();
                            count++;
                        }
                    }
                    // reuse buffer if we can.
                    if (count != 1) {
                        data = BufferUtils.createByteBuffer(dSize);
                        for (int x = 0; x < image.getData().size(); x++) {
                            if (image.getData(x) != null) {
                                data.put(image.getData(x));
                            }
                        }
                        // ensure the buffer is ready for reading
                        data.flip();
                    }
                    // send top level to card
                    GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0,
                            LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                            image.getWidth(), image.getHeight(), image.getDepth(), hasBorder ? 1 : 0,
                            LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                            LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                } else {
                    logger.warning("This card does not support Texture3D.");
                }
                break;
            case CubeMap:
                // NOTE: Cubemaps MUST be square, so height is ignored
                // on purpose.
                if (caps.isTextureCubeMapSupported()) {
                    for (final TextureCubeMap.Face face : TextureCubeMap.Face.values()) {
                        // ensure the buffer is ready for reading
                        image.getData(face.ordinal()).rewind();
                        // send top level to card
                        GL11.glTexImage2D(getGLCubeMapFace(face), 0,
                                LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                image.getWidth(), image.getWidth(), hasBorder ? 1 : 0,
                                LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                LwjglTextureUtil.getGLPixelDataType(image.getDataType()),
                                image.getData(face.ordinal()));
                    }
                } else {
                    logger.warning("This card does not support Cubemaps.");
                }
                break;
            }
        } else if (texture.getMinificationFilter().usesMipMapLevels() && !image.hasMipmaps()
                && !texture.getTextureStoreFormat().isCompressed()) {

            // For textures which need mipmaps auto-generating and which
            // aren't using compressed images, generate the mipmaps.
            // A new mipmap builder may be needed to build mipmaps for
            // compressed textures.

            if (caps.isAutomaticMipmapsSupported()) {
                // Flag the card to generate mipmaps
                GL11.glTexParameteri(getGLType(type), SGISGenerateMipmap.GL_GENERATE_MIPMAP_SGIS, GL11.GL_TRUE);
            }

            switch (type) {
            case TwoDimensional:
                // ensure the buffer is ready for reading
                image.getData(0).rewind();
                if (caps.isAutomaticMipmapsSupported()) {
                    // send top level to card
                    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0,
                            LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                            image.getWidth(), image.getHeight(), hasBorder ? 1 : 0,
                            LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                            LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
                } else {
                    // send to card
                    GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D,
                            LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                            image.getWidth(), image.getHeight(),
                            LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                            LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
                }
                break;
            case OneDimensional:
                // ensure the buffer is ready for reading
                image.getData(0).rewind();
                if (caps.isAutomaticMipmapsSupported()) {
                    // send top level to card
                    GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0,
                            LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                            image.getWidth(), hasBorder ? 1 : 0,
                            LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                            LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
                } else {
                    // Note: LWJGL's GLU class does not support
                    // gluBuild1DMipmaps.
                    logger.warning(
                            "non-fbo 1d mipmap generation is not currently supported.  Use DDS or a non-mipmap minification filter.");
                    return;
                }
                break;
            case ThreeDimensional:
                if (caps.isTexture3DSupported()) {
                    if (caps.isAutomaticMipmapsSupported()) {
                        // concat data into single buffer:
                        int dSize = 0;
                        int count = 0;
                        ByteBuffer data = null;
                        for (int x = 0; x < image.getData().size(); x++) {
                            if (image.getData(x) != null) {
                                data = image.getData(x);
                                dSize += data.limit();
                                count++;
                            }
                        }
                        // reuse buffer if we can.
                        if (count != 1) {
                            data = BufferUtils.createByteBuffer(dSize);
                            for (int x = 0; x < image.getData().size(); x++) {
                                if (image.getData(x) != null) {
                                    data.put(image.getData(x));
                                }
                            }
                            // ensure the buffer is ready for reading
                            data.flip();
                        }
                        // send top level to card
                        GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0,
                                LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                image.getWidth(), image.getHeight(), image.getDepth(), hasBorder ? 1 : 0,
                                LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                    } else {
                        // Note: LWJGL's GLU class does not support
                        // gluBuild3DMipmaps.
                        logger.warning(
                                "non-fbo 3d mipmap generation is not currently supported.  Use DDS or a non-mipmap minification filter.");
                        return;
                    }
                } else {
                    logger.warning("This card does not support Texture3D.");
                    return;
                }
                break;
            case CubeMap:
                // NOTE: Cubemaps MUST be square, so height is ignored
                // on purpose.
                if (caps.isTextureCubeMapSupported()) {
                    if (caps.isAutomaticMipmapsSupported()) {
                        for (final TextureCubeMap.Face face : TextureCubeMap.Face.values()) {
                            // ensure the buffer is ready for reading
                            image.getData(face.ordinal()).rewind();
                            // send top level to card
                            GL11.glTexImage2D(getGLCubeMapFace(face), 0,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    image.getWidth(), image.getWidth(), hasBorder ? 1 : 0,
                                    LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                    LwjglTextureUtil.getGLPixelDataType(image.getDataType()),
                                    image.getData(face.ordinal()));
                        }
                    } else {
                        for (final TextureCubeMap.Face face : TextureCubeMap.Face.values()) {
                            // ensure the buffer is ready for reading
                            image.getData(face.ordinal()).rewind();
                            // send to card
                            GLU.gluBuild2DMipmaps(getGLCubeMapFace(face),
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    image.getWidth(), image.getWidth(),
                                    LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                    LwjglTextureUtil.getGLPixelDataType(image.getDataType()),
                                    image.getData(face.ordinal()));
                        }
                    }
                } else {
                    logger.warning("This card does not support Cubemaps.");
                    return;
                }
                break;
            }

            if (texture.getTextureMaxLevel() >= 0) {
                GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL,
                        texture.getTextureMaxLevel());
            }
        } else {
            // Here we handle textures that are either compressed or have predefined mipmaps.
            // Get mipmap data sizes and amount of mipmaps to send to opengl. Then loop through all mipmaps and send
            // them.
            int[] mipSizes = image.getMipMapByteSizes();
            ByteBuffer data = null;

            if (type == Type.CubeMap) {
                if (caps.isTextureCubeMapSupported()) {
                    for (final TextureCubeMap.Face face : TextureCubeMap.Face.values()) {
                        data = image.getData(face.ordinal());
                        int pos = 0;
                        int max = 1;

                        if (mipSizes == null) {
                            mipSizes = new int[] { data.capacity() };
                        } else if (texture.getMinificationFilter().usesMipMapLevels()) {
                            max = mipSizes.length;
                        }

                        // set max mip level
                        GL11.glTexParameteri(getGLCubeMapFace(face), GL12.GL_TEXTURE_MAX_LEVEL, max - 1);

                        for (int m = 0; m < max; m++) {
                            final int width = Math.max(1, image.getWidth() >> m);
                            final int height = Math.max(1, image.getHeight() >> m);

                            data.position(pos);
                            data.limit(pos + mipSizes[m]);

                            if (texture.getTextureStoreFormat().isCompressed()) {
                                ARBTextureCompression.glCompressedTexImage2DARB(getGLCubeMapFace(face), m,
                                        LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                        width, height, hasBorder ? 1 : 0, data);
                            } else {
                                GL11.glTexImage2D(getGLCubeMapFace(face), m,
                                        LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                        width, height, hasBorder ? 1 : 0,
                                        LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                        LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                            }
                            pos += mipSizes[m];
                        }
                    }
                } else {
                    logger.warning("This card does not support CubeMaps.");
                    return;
                }
            } else {
                data = image.getData(0);
                int pos = 0;
                int max = 1;

                if (mipSizes == null) {
                    mipSizes = new int[] { data.capacity() };
                } else if (texture.getMinificationFilter().usesMipMapLevels()) {
                    max = mipSizes.length;
                }

                // Set max mip level
                switch (type) {
                case TwoDimensional:
                    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, max - 1);
                    break;
                case ThreeDimensional:
                    GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL12.GL_TEXTURE_MAX_LEVEL, max - 1);
                    break;
                case OneDimensional:
                    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL12.GL_TEXTURE_MAX_LEVEL, max - 1);
                    break;
                }

                if (type == Type.ThreeDimensional) {
                    if (caps.isTexture3DSupported()) {
                        // concat data into single buffer:
                        int dSize = 0;
                        int count = 0;
                        for (int x = 0; x < image.getData().size(); x++) {
                            if (image.getData(x) != null) {
                                data = image.getData(x);
                                dSize += data.limit();
                                count++;
                            }
                        }
                        // reuse buffer if we can.
                        if (count != 1) {
                            data = BufferUtils.createByteBuffer(dSize);
                            for (int x = 0; x < image.getData().size(); x++) {
                                if (image.getData(x) != null) {
                                    data.put(image.getData(x));
                                }
                            }
                            // ensure the buffer is ready for reading
                            data.flip();
                        }
                    } else {
                        logger.warning("This card does not support Texture3D.");
                        return;
                    }
                }

                for (int m = 0; m < max; m++) {
                    final int width = Math.max(1, image.getWidth() >> m);
                    final int height = Math.max(1, image.getHeight() >> m);

                    data.position(pos);
                    data.limit(pos + mipSizes[m]);

                    switch (type) {
                    case TwoDimensional:
                        if (texture.getTextureStoreFormat().isCompressed()) {
                            ARBTextureCompression.glCompressedTexImage2DARB(GL11.GL_TEXTURE_2D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, height, hasBorder ? 1 : 0, data);
                        } else {
                            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, height, hasBorder ? 1 : 0,
                                    LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                    LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                        }
                        break;
                    case OneDimensional:
                        if (texture.getTextureStoreFormat().isCompressed()) {
                            ARBTextureCompression.glCompressedTexImage1DARB(GL11.GL_TEXTURE_1D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, hasBorder ? 1 : 0, data);
                        } else {
                            GL11.glTexImage1D(GL11.GL_TEXTURE_1D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, hasBorder ? 1 : 0,
                                    LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                    LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                        }
                        break;
                    case ThreeDimensional:
                        final int depth = Math.max(1, image.getDepth() >> m);
                        // already checked for support above...
                        if (texture.getTextureStoreFormat().isCompressed()) {
                            ARBTextureCompression.glCompressedTexImage3DARB(GL12.GL_TEXTURE_3D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, height, depth, hasBorder ? 1 : 0, data);
                        } else {
                            GL12.glTexImage3D(GL12.GL_TEXTURE_3D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, height, depth, hasBorder ? 1 : 0,
                                    LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                    LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                        }
                        break;
                    }
                    pos += mipSizes[m];
                }
            }
            if (data != null) {
                data.clear();
            }
        }
    }
}

From source file:com.ardor3d.scene.state.lwjgl.LwjglTextureStateUtil.java

License:Open Source License

/**
 * Check if the filter settings of this particular texture have been changed and apply as needed.
 * //from   ww w  .ja va2s  .c  om
 * @param texture
 *            our texture object
 * @param texRecord
 *            our record of the last state of the texture in gl
 * @param record
 */
public static void applyShadow(final Texture texture, final TextureRecord texRecord, final int unit,
        final TextureStateRecord record, final ContextCapabilities caps) {
    final Type type = texture.getType();

    if (caps.isDepthTextureSupported()) {
        final int depthMode = LwjglTextureUtil.getGLDepthTextureMode(texture.getDepthMode());
        // set up magnification filter
        if (!texRecord.isValid() || texRecord.depthTextureMode != depthMode) {
            checkAndSetUnit(unit, record, caps);
            GL11.glTexParameteri(getGLType(type), ARBDepthTexture.GL_DEPTH_TEXTURE_MODE_ARB, depthMode);
            texRecord.depthTextureMode = depthMode;
        }
    }

    if (caps.isARBShadowSupported()) {
        final int depthCompareMode = LwjglTextureUtil
                .getGLDepthTextureCompareMode(texture.getDepthCompareMode());
        // set up magnification filter
        if (!texRecord.isValid() || texRecord.depthTextureCompareMode != depthCompareMode) {
            checkAndSetUnit(unit, record, caps);
            GL11.glTexParameteri(getGLType(type), ARBShadow.GL_TEXTURE_COMPARE_MODE_ARB, depthCompareMode);
            texRecord.depthTextureCompareMode = depthCompareMode;
        }

        final int depthCompareFunc = LwjglTextureUtil
                .getGLDepthTextureCompareFunc(texture.getDepthCompareFunc());
        // set up magnification filter
        if (!texRecord.isValid() || texRecord.depthTextureCompareFunc != depthCompareFunc) {
            checkAndSetUnit(unit, record, caps);
            GL11.glTexParameteri(getGLType(type), ARBShadow.GL_TEXTURE_COMPARE_FUNC_ARB, depthCompareFunc);
            texRecord.depthTextureCompareFunc = depthCompareFunc;
        }
    }
}

From source file:com.ardor3d.scene.state.lwjgl.LwjglTextureStateUtil.java

License:Open Source License

/**
 * Check if the filter settings of this particular texture have been changed and apply as needed.
 * //from  www .  ja  va  2  s. c o m
 * @param texture
 *            our texture object
 * @param texRecord
 *            our record of the last state of the texture in gl
 * @param record
 */
public static void applyFilter(final Texture texture, final TextureRecord texRecord, final int unit,
        final TextureStateRecord record, final ContextCapabilities caps) {
    final Type type = texture.getType();

    final int magFilter = LwjglTextureUtil.getGLMagFilter(texture.getMagnificationFilter());
    // set up magnification filter
    if (!texRecord.isValid() || texRecord.magFilter != magFilter) {
        checkAndSetUnit(unit, record, caps);
        GL11.glTexParameteri(getGLType(type), GL11.GL_TEXTURE_MAG_FILTER, magFilter);
        texRecord.magFilter = magFilter;
    }

    final int minFilter = LwjglTextureUtil.getGLMinFilter(texture.getMinificationFilter());
    // set up mipmap filter
    if (!texRecord.isValid() || texRecord.minFilter != minFilter) {
        checkAndSetUnit(unit, record, caps);
        GL11.glTexParameteri(getGLType(type), GL11.GL_TEXTURE_MIN_FILTER, minFilter);
        texRecord.minFilter = minFilter;
    }

    // set up aniso filter
    if (caps.isAnisoSupported()) {
        float aniso = texture.getAnisotropicFilterPercent() * (caps.getMaxAnisotropic() - 1.0f);
        aniso += 1.0f;
        if (!texRecord.isValid() || (texRecord.anisoLevel - aniso > MathUtils.ZERO_TOLERANCE)) {
            checkAndSetUnit(unit, record, caps);
            GL11.glTexParameterf(getGLType(type), EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
                    aniso);
            texRecord.anisoLevel = aniso;
        }
    }
}

From source file:com.ardor3d.scene.state.lwjgl.LwjglTextureStateUtil.java

License:Open Source License

/**
 * Check if the wrap mode of this particular texture has been changed and apply as needed.
 * /*w  w  w.j  a va 2 s  .  c o  m*/
 * @param texture
 *            our texture object
 * @param texRecord
 *            our record of the last state of the unit in gl
 * @param record
 */
public static void applyWrap(final Texture3D texture, final TextureRecord texRecord, final int unit,
        final TextureStateRecord record, final ContextCapabilities caps) {
    if (!caps.isTexture3DSupported()) {
        return;
    }

    final int wrapS = getGLWrap(texture.getWrap(WrapAxis.S), caps);
    final int wrapT = getGLWrap(texture.getWrap(WrapAxis.T), caps);
    final int wrapR = getGLWrap(texture.getWrap(WrapAxis.R), caps);

    if (!texRecord.isValid() || texRecord.wrapS != wrapS) {
        checkAndSetUnit(unit, record, caps);
        GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL11.GL_TEXTURE_WRAP_S, wrapS);
        texRecord.wrapS = wrapS;
    }
    if (!texRecord.isValid() || texRecord.wrapT != wrapT) {
        checkAndSetUnit(unit, record, caps);
        GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL11.GL_TEXTURE_WRAP_T, wrapT);
        texRecord.wrapT = wrapT;
    }
    if (!texRecord.isValid() || texRecord.wrapR != wrapR) {
        checkAndSetUnit(unit, record, caps);
        GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL12.GL_TEXTURE_WRAP_R, wrapR);
        texRecord.wrapR = wrapR;
    }

}

From source file:com.ardor3d.scene.state.lwjgl.LwjglTextureStateUtil.java

License:Open Source License

/**
 * Check if the wrap mode of this particular texture has been changed and apply as needed.
 * //from  w w  w .  j  a v  a2 s .  c  o m
 * @param texture
 *            our texture object
 * @param texRecord
 *            our record of the last state of the unit in gl
 * @param record
 */
public static void applyWrap(final Texture1D texture, final TextureRecord texRecord, final int unit,
        final TextureStateRecord record, final ContextCapabilities caps) {
    final int wrapS = getGLWrap(texture.getWrap(WrapAxis.S), caps);

    if (!texRecord.isValid() || texRecord.wrapS != wrapS) {
        checkAndSetUnit(unit, record, caps);
        GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, wrapS);
        texRecord.wrapS = wrapS;
    }
}

From source file:com.ardor3d.scene.state.lwjgl.LwjglTextureStateUtil.java

License:Open Source License

/**
 * Check if the wrap mode of this particular texture has been changed and apply as needed.
 * //from ww  w.  ja  v  a 2s. c  o  m
 * @param texture
 *            our texture object
 * @param texRecord
 *            our record of the last state of the unit in gl
 * @param record
 */
public static void applyWrap(final Texture2D texture, final TextureRecord texRecord, final int unit,
        final TextureStateRecord record, final ContextCapabilities caps) {
    final int wrapS = getGLWrap(texture.getWrap(WrapAxis.S), caps);
    final int wrapT = getGLWrap(texture.getWrap(WrapAxis.T), caps);

    if (!texRecord.isValid() || texRecord.wrapS != wrapS) {
        checkAndSetUnit(unit, record, caps);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wrapS);
        texRecord.wrapS = wrapS;
    }
    if (!texRecord.isValid() || texRecord.wrapT != wrapT) {
        checkAndSetUnit(unit, record, caps);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, wrapT);
        texRecord.wrapT = wrapT;
    }

}