List of usage examples for org.lwjgl.opengl GL12 glTexSubImage3D
public static void glTexSubImage3D(@NativeType("GLenum") int target, @NativeType("GLint") int level, @NativeType("GLint") int xoffset, @NativeType("GLint") int yoffset, @NativeType("GLint") int zoffset, @NativeType("GLsizei") int width, @NativeType("GLsizei") int height, @NativeType("GLsizei") int depth, @NativeType("GLenum") int format, @NativeType("GLenum") int type, @NativeType("void const *") double[] pixels)
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 w w w . ja v a 2 s. c om } // 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:com.badlogic.gdx.backends.jglfw.JglfwGL30.java
License:Apache License
@Override public void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, (ByteBuffer) pixels); else if (pixels instanceof ShortBuffer) GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, (ShortBuffer) pixels); else if (pixels instanceof IntBuffer) GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, (IntBuffer) pixels); else if (pixels instanceof FloatBuffer) GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, (FloatBuffer) pixels); else if (pixels instanceof DoubleBuffer) GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, (DoubleBuffer) pixels); else// w ww . ja v a2 s .c o m throw new GdxRuntimeException( "pixels must be ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer"); }
From source file:com.badlogic.gdx.backends.jglfw.JglfwGL30.java
License:Apache License
@Override public void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, int format, int type, int offset) { GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, offset); }
From source file:com.badlogic.gdx.backends.lwjgl.LwjglGL30.java
License:Apache License
@Override public void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, (ByteBuffer) pixels); else// w ww . java2 s . c o m throw new GdxRuntimeException("pixels must be byte buffer"); }
From source file:com.opengrave.og.resources.TextureAtlasEditable.java
License:Open Source License
@Override public void bind(int t) { GL13.glActiveTexture(t);/* w ww.j av a 2s. c o m*/ if (pixels != null) { id = GL11.glGenTextures(); mainBuf = BufferUtils.createByteBuffer(4 * this.size * this.size); // for (int i = this.size - 1; i >= 0; i--) { for (int i = 0; i < this.size; i++) { for (int j = 0; j < this.size; j++) { float r = 1f, g = 1f, b = 1f, a = 0f; if (i < py && j < px) { int pixel = pixels[i * px + j]; r = (float) ((pixel >> 16) & 0xFF) / 255f; g = (float) ((pixel >> 8) & 0xFF) / 255f; b = (float) (pixel & 0xFF) / 255f; a = (float) ((pixel >> 24) & 0xFF) / 255f; } addColour(r, g, b, a); } } mainBuf.flip(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, this.size, this.size, 1, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, mainBuf); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); pixels = null; } synchronized (changeList) { if (changeList.size() < 10) { GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); for (TextureEditableDeferedChanges change : changeList) { applyChangeToMainBuffer(change); ByteBuffer buf = BufferUtils.createByteBuffer(4); buf.put((byte) (255 * change.getColour().z)).put((byte) (255 * change.getColour().y)) .put((byte) (255 * change.getColour().x)).put((byte) (255 * change.getColour().w)); buf.flip(); GL11.glTexSubImage2D(GL30.GL_TEXTURE_2D_ARRAY, 0, change.getX(), change.getY(), 1, 1, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, buf); } GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); } else { // Replace the whole image. There's bound to be better ways // around this... for (TextureEditableDeferedChanges change : changeList) { applyChangeToMainBuffer(change); } mainBuf.position(0); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); Util.checkErr(); GL12.glTexSubImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, size, size, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, mainBuf); Util.checkErr(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); Util.checkErr(); } changeList.clear(); } Util.checkErr(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); lastTexNum = t; }
From source file:io.root.gfx.glutils.GL.java
License:Apache License
public static void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, (ByteBuffer) pixels); else//w w w . j a v a2 s . c om throw new RootException("pixels must be byte buffer"); }
From source file:io.root.gfx.glutils.GL.java
License:Apache License
public static void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, int format, int type, int offset) { GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, offset); }
From source file:ivengine.Util.java
License:Creative Commons License
/** * Stores a variable amount of textures defined by URLS <filenames> into a texture array. Uses a magfilter <magfilter>, a minfilter <minfilter>. * If <mipmap> is true, mipmaps will be activated. * If <anisotropic> is true, anisotropic filtering will be activated, if supported. *//*from w ww.java2 s.c o m*/ public static int loadTextureAtlasIntoTextureArray(URL[] filenames, int magfilter, int minfilter, boolean mipmap, boolean anisotropic) { int tex = GL11.glGenTextures(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, tex); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MAG_FILTER, magfilter); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MIN_FILTER, minfilter); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); ByteBuffer buf = null; PNGDecoder decoder = null; try { InputStream in = filenames[0].openStream(); decoder = new PNGDecoder(in); buf = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); buf.flip(); in.close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } int tileWidth = decoder.getWidth(); System.out.println(tileWidth); int tileHeight = decoder.getHeight(); System.out.println(tileHeight); GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, tileWidth, tileHeight, filenames.length, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); for (int i = 0; i < filenames.length; i++) { GL12.glTexSubImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, /*tileWidth*x*/0, /*tileHeight*y*/0, i, tileWidth, tileHeight, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); buf.rewind(); if (i < filenames.length - 1) loadTexture(filenames[i + 1], buf); } if (mipmap) GL30.glGenerateMipmap(GL30.GL_TEXTURE_2D_ARRAY); if (anisotropic) { if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) { float maxanis = GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); System.out.println("Anisotropic filtering activated with a resolution of " + maxanis); System.out.println(GL11.glGetError()); GL11.glTexParameterf(GL30.GL_TEXTURE_2D_ARRAY, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, maxanis); System.out.println(GL11.glGetError()); } else { System.err.println( "WARNING - Anisotropic filtering not supported by this graphics card. Setting it as disabled"); } } GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); return tex; }
From source file:playn.java.JavaGL20.java
License:Apache License
@Override public void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, int format, int type, Buffer pixels) { GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, (ByteBuffer) pixels); }
From source file:playn.java.JavaGL20.java
License:Apache License
@Override public void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, int format, int type, int pixels) { final ByteBuffer byteBuffer = BufferUtils.createByteBuffer(1); byteBuffer.putInt(pixels);/*from w w w . j a va 2 s. com*/ byteBuffer.rewind(); GL12.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, byteBuffer); }