Example usage for org.lwjgl.opengl ARBFramebufferObject glGenerateMipmap

List of usage examples for org.lwjgl.opengl ARBFramebufferObject glGenerateMipmap

Introduction

In this page you can find the example usage for org.lwjgl.opengl ARBFramebufferObject glGenerateMipmap.

Prototype

public static void glGenerateMipmap(@NativeType("GLenum") int target) 

Source Link

Document

Generate mipmaps for a specified texture target.

Usage

From source file:mwisbest.openbase.opengl.TextureLoader.java

License:Open Source License

private TextureImplementation getTexture(InputStream in, String resourceName, int target, int minFilter,
        int magFilter, boolean flipped, int[] transparent) throws IOException {
    // create the texture ID for this texture
    ByteBuffer textureBuffer;//from ww  w .  j a v  a  2  s  .co m

    LoadableImageData imageData = ImageDataFactory.getImageDataFor(resourceName);
    textureBuffer = imageData.loadImage(new BufferedInputStream(in), flipped, transparent);

    int textureID = createTextureID();
    TextureImplementation texture = new TextureImplementation(resourceName, target, textureID);
    // bind this texture
    GL11.glEnable(target);
    GL11.glBindTexture(target, textureID);

    int width;
    int height;
    int texWidth;
    int texHeight;

    ImageData.Format format;

    width = imageData.getWidth();
    height = imageData.getHeight();
    format = imageData.getFormat();

    texture.setTextureWidth(imageData.getTexWidth());
    texture.setTextureHeight(imageData.getTexHeight());

    texWidth = texture.getTextureWidth();
    texHeight = texture.getTextureHeight();

    IntBuffer temp = BufferUtils.createIntBuffer(16);
    GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE, temp);
    int max = temp.get(0);
    if (texWidth > max || texHeight > max)
        throw new IOException("Attempt to allocate a texture to big for the current hardware");

    int srcPixelFormat = format.getOGLType();

    texture.setWidth(width);
    texture.setHeight(height);
    texture.setImageFormat(format);

    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter);
    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter);

    ContextCapabilities capabilities = GLContext.getCapabilities();

    if (capabilities.OpenGL30 || capabilities.GL_EXT_framebuffer_object
            || capabilities.GL_ARB_framebuffer_object || capabilities.OpenGL14) {
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, GL11.GL_POLYGON_BIT);
        if (capabilities.OpenGL30)
            GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
        else if (capabilities.GL_EXT_framebuffer_object)
            EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D);
        else if (capabilities.GL_ARB_framebuffer_object)
            ARBFramebufferObject.glGenerateMipmap(GL11.GL_TEXTURE_2D);
        else if (capabilities.OpenGL14)
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
    }

    // produce a texture from the byte buffer
    GL11.glTexImage2D(target, 0, this.dstPixelFormat, get2Fold(width), get2Fold(height), 0, srcPixelFormat,
            GL11.GL_UNSIGNED_BYTE, textureBuffer);
    return texture;
}