Example usage for org.lwjgl.opengl GL11 glTexSubImage1D

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

Introduction

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

Prototype

public static void glTexSubImage1D(@NativeType("GLenum") int target, @NativeType("GLint") int level,
        @NativeType("GLint") int xoffset, @NativeType("GLsizei") int width, @NativeType("GLenum") int format,
        @NativeType("GLenum") int type, @NativeType("void const *") double[] pixels) 

Source Link

Document

Array version of: #glTexSubImage1D TexSubImage1D

Usage

From source file:com.ardor3d.renderer.lwjgl.LwjglRenderer.java

License:Open Source License

private void updateTexSubImage(final Texture destination, final int dstOffsetX, final int dstOffsetY,
        final int dstOffsetZ, final int dstWidth, final int dstHeight, final int dstDepth,
        final ByteBuffer source, final int srcOffsetX, final int srcOffsetY, final int srcOffsetZ,
        final int srcTotalWidth, final int srcTotalHeight, final Face dstFace) {

    // Ignore textures that do not have an id set
    if (destination.getTextureIdForContext(ContextManager.getCurrentContext().getGlContextRep()) == 0) {
        logger.warning("Attempting to update a texture that is not currently on the card.");
        return;//from www.  j a  v a 2 s  . c  o  m
    }

    // Determine the original texture configuration, so that this method can
    // restore the texture configuration to its original state.
    final IntBuffer idBuff = BufferUtils.createIntBuffer(16);
    GL11.glGetInteger(GL11.GL_UNPACK_ALIGNMENT, idBuff);
    final int origAlignment = idBuff.get(0);
    final int origRowLength = 0;
    final int origImageHeight = 0;
    final int origSkipPixels = 0;
    final int origSkipRows = 0;
    final int origSkipImages = 0;

    final int alignment = 1;

    int rowLength;
    if (srcTotalWidth == dstWidth) {
        // When the row length is zero, then the width parameter is used.
        // We use zero in these cases in the hope that we can avoid two
        // unnecessary calls to glPixelStorei.
        rowLength = 0;
    } else {
        // The number of pixels in a row is different than the number of
        // pixels in the region to be uploaded to the texture.
        rowLength = srcTotalWidth;
    }

    int imageHeight;
    if (srcTotalHeight == dstHeight) {
        // When the image height is zero, then the height parameter is used.
        // We use zero in these cases in the hope that we can avoid two
        // unnecessary calls to glPixelStorei.
        imageHeight = 0;
    } else {
        // The number of pixels in a row is different than the number of
        // pixels in the region to be uploaded to the texture.
        imageHeight = srcTotalHeight;
    }

    // Grab pixel format
    final int pixelFormat;
    if (destination.getImage() != null) {
        pixelFormat = LwjglTextureUtil.getGLPixelFormat(destination.getImage().getDataFormat());
    } else {
        pixelFormat = LwjglTextureUtil.getGLPixelFormatFromStoreFormat(destination.getTextureStoreFormat());
    }

    // bind...
    LwjglTextureStateUtil.doTextureBind(destination, 0, false);

    // Update the texture configuration (when necessary).

    if (origAlignment != alignment) {
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, alignment);
    }
    if (origRowLength != rowLength) {
        GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, rowLength);
    }
    if (origSkipPixels != srcOffsetX) {
        GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, srcOffsetX);
    }
    // NOTE: The below will be skipped for texture types that don't support them because we are passing in 0's.
    if (origSkipRows != srcOffsetY) {
        GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, srcOffsetY);
    }
    if (origImageHeight != imageHeight) {
        GL11.glPixelStorei(GL12.GL_UNPACK_IMAGE_HEIGHT, imageHeight);
    }
    if (origSkipImages != srcOffsetZ) {
        GL11.glPixelStorei(GL12.GL_UNPACK_SKIP_IMAGES, srcOffsetZ);
    }

    // Upload the image region into the texture.
    try {
        switch (destination.getType()) {
        case TwoDimensional:
            GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, dstOffsetX, dstOffsetY, dstWidth, dstHeight,
                    pixelFormat, GL11.GL_UNSIGNED_BYTE, source);
            break;
        case OneDimensional:
            GL11.glTexSubImage1D(GL11.GL_TEXTURE_1D, 0, dstOffsetX, dstWidth, pixelFormat,
                    GL11.GL_UNSIGNED_BYTE, source);
            break;
        case ThreeDimensional:
            GL12.glTexSubImage3D(GL12.GL_TEXTURE_3D, 0, dstOffsetX, dstOffsetY, dstOffsetZ, dstWidth, dstHeight,
                    dstDepth, pixelFormat, GL11.GL_UNSIGNED_BYTE, source);
            break;
        case CubeMap:
            GL11.glTexSubImage2D(LwjglTextureStateUtil.getGLCubeMapFace(dstFace), 0, dstOffsetX, dstOffsetY,
                    dstWidth, dstHeight, pixelFormat, GL11.GL_UNSIGNED_BYTE, source);
            break;
        default:
            throw new Ardor3dException("Unsupported type for updateTextureSubImage: " + destination.getType());
        }
    } finally {
        // Restore the texture configuration (when necessary)...
        // Restore alignment.
        if (origAlignment != alignment) {
            GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, origAlignment);
        }
        // Restore row length.
        if (origRowLength != rowLength) {
            GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, origRowLength);
        }
        // Restore skip pixels.
        if (origSkipPixels != srcOffsetX) {
            GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, origSkipPixels);
        }
        // Restore skip rows.
        if (origSkipRows != srcOffsetY) {
            GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, origSkipRows);
        }
        // Restore image height.
        if (origImageHeight != imageHeight) {
            GL11.glPixelStorei(GL12.GL_UNPACK_IMAGE_HEIGHT, origImageHeight);
        }
        // Restore skip images.
        if (origSkipImages != srcOffsetZ) {
            GL11.glPixelStorei(GL12.GL_UNPACK_SKIP_IMAGES, origSkipImages);
        }
    }
}

From source file:tk.ivybits.engine.gl.GL.java

License:Open Source License

public static void glTexSubImage1D(int a, int b, int c, int d, int e, int f, ShortBuffer g) {
    GL11.glTexSubImage1D(a, b, c, d, e, f, g);
}

From source file:tk.ivybits.engine.gl.GL.java

License:Open Source License

public static void glTexSubImage1D(int a, int b, int c, int d, int e, int f, FloatBuffer g) {
    GL11.glTexSubImage1D(a, b, c, d, e, f, g);
}

From source file:tk.ivybits.engine.gl.GL.java

License:Open Source License

public static void glTexSubImage1D(int a, int b, int c, int d, int e, int f, DoubleBuffer g) {
    GL11.glTexSubImage1D(a, b, c, d, e, f, g);
}

From source file:tk.ivybits.engine.gl.GL.java

License:Open Source License

public static void glTexSubImage1D(int a, int b, int c, int d, int e, int f, ByteBuffer g) {
    GL11.glTexSubImage1D(a, b, c, d, e, f, g);
}

From source file:tk.ivybits.engine.gl.GL.java

License:Open Source License

public static void glTexSubImage1D(int a, int b, int c, int d, int e, int f, IntBuffer g) {
    GL11.glTexSubImage1D(a, b, c, d, e, f, g);
}

From source file:tk.ivybits.engine.gl.GL.java

License:Open Source License

public static void glTexSubImage1D(int a, int b, int c, int d, int e, int f, long g) {
    GL11.glTexSubImage1D(a, b, c, d, e, f, g);
}