Example usage for org.lwjgl.opengl GL11 nglTexImage2D

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

Introduction

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

Prototype

public static void nglTexImage2D(int target, int level, int internalformat, int width, int height, int border,
        int format, int type, long pixels) 

Source Link

Document

Unsafe version of: #glTexImage2D TexImage2D

Usage

From source file:com.samrj.devil.gl.Texture2DAbstract.java

License:Open Source License

/**
 * Allocates space on the GPU for an image of the given size and format, but
 * does not upload any information. Useful for attaching to frame buffers.
 * //from   ww  w.jav  a  2s  .  c  o  m
 * @param width The width of the image.
 * @param height The height of the image.
 * @param format The format of the image.
 * @return This texture.
 */
public T image(int width, int height, int format) {
    if (width <= 0 || height <= 0)
        throw new IllegalArgumentException("Illegal image dimensions.");

    int baseFormat = TexUtil.getBaseFormat(format);
    if (baseFormat == -1)
        throw new IllegalArgumentException("Illegal image format.");

    this.width = width;
    this.height = height;
    int primType = TexUtil.getPrimitiveType(format);

    int oldID = tempBind();
    GL11.nglTexImage2D(target, 0, format, width, height, 0, baseFormat, primType, MemoryUtil.NULL);
    tempUnbind(oldID);

    setVRAMUsage(TexUtil.getBits(format) * width * height);

    return getThis();
}

From source file:com.samrj.devil.gl.Texture2DAbstract.java

License:Open Source License

/**
 * Allocates space on the GPU for the image, and then uploads it, linking it
 * to this texture. After calling, the image may be safely deleted from
 * memory. Any previous image data associated with this texture is released.
 * //from w w  w. j  av  a2 s.  com
 * @param image The image to upload to the GPU.
 * @param format The texture format to store the image as.
 * @return This texture.
 */
public T image(Image image, int format) {
    if (image.deleted())
        throw new IllegalStateException("Image is deleted.");

    int dataFormat = TexUtil.getBaseFormat(format);
    if (image.bands != TexUtil.getBands(dataFormat))
        throw new IllegalArgumentException("Incompatible format bands.");

    width = image.width;
    height = image.height;
    int primType = TexUtil.getPrimitiveType(format);

    int oldID = tempBind();
    GL11.nglTexImage2D(target, 0, format, width, height, 0, dataFormat, primType, image.address());
    tempUnbind(oldID);

    setVRAMUsage(TexUtil.getBits(format) * width * height);

    return getThis();
}