List of usage examples for org.lwjgl.opengl GL12 GL_TEXTURE_3D
int GL_TEXTURE_3D
To view the source code for org.lwjgl.opengl GL12 GL_TEXTURE_3D.
Click Source Link
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;// www . j ava 2s .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.ardor3d.scene.state.lwjgl.LwjglTextureStateUtil.java
License:Open Source License
/** * bind texture and upload image data to card *//*from w ww . j a v a2 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
private static void disableTexturing(final TextureUnitRecord unitRecord, final TextureStateRecord record, final int unit, final Type exceptedType, final ContextCapabilities caps) { if (exceptedType != Type.TwoDimensional) { if (!unitRecord.isValid() || unitRecord.enabled[Type.TwoDimensional.ordinal()]) { // Check we are in the right unit checkAndSetUnit(unit, record, caps); GL11.glDisable(GL11.GL_TEXTURE_2D); unitRecord.enabled[Type.TwoDimensional.ordinal()] = false; }/*w ww.ja va2s .c o m*/ } if (exceptedType != Type.OneDimensional) { if (!unitRecord.isValid() || unitRecord.enabled[Type.OneDimensional.ordinal()]) { // Check we are in the right unit checkAndSetUnit(unit, record, caps); GL11.glDisable(GL11.GL_TEXTURE_1D); unitRecord.enabled[Type.OneDimensional.ordinal()] = false; } } if (caps.isTexture3DSupported() && exceptedType != Type.ThreeDimensional) { if (!unitRecord.isValid() || unitRecord.enabled[Type.ThreeDimensional.ordinal()]) { // Check we are in the right unit checkAndSetUnit(unit, record, caps); GL11.glDisable(GL12.GL_TEXTURE_3D); unitRecord.enabled[Type.ThreeDimensional.ordinal()] = false; } } if (caps.isTextureCubeMapSupported() && exceptedType != Type.CubeMap) { if (!unitRecord.isValid() || unitRecord.enabled[Type.CubeMap.ordinal()]) { // Check we are in the right unit checkAndSetUnit(unit, record, caps); GL11.glDisable(ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_ARB); unitRecord.enabled[Type.CubeMap.ordinal()] = false; } } }
From source file:com.ardor3d.scene.state.lwjgl.LwjglTextureStateUtil.java
License:Open Source License
private static void disableTexturing(final TextureUnitRecord unitRecord, final TextureStateRecord record, final int unit, final ContextCapabilities caps) { if (!unitRecord.isValid() || unitRecord.enabled[Type.TwoDimensional.ordinal()]) { // Check we are in the right unit checkAndSetUnit(unit, record, caps); GL11.glDisable(GL11.GL_TEXTURE_2D); unitRecord.enabled[Type.TwoDimensional.ordinal()] = false; }// ww w . ja va2s . c o m if (!unitRecord.isValid() || unitRecord.enabled[Type.OneDimensional.ordinal()]) { // Check we are in the right unit checkAndSetUnit(unit, record, caps); GL11.glDisable(GL11.GL_TEXTURE_1D); unitRecord.enabled[Type.OneDimensional.ordinal()] = false; } if (caps.isTexture3DSupported()) { if (!unitRecord.isValid() || unitRecord.enabled[Type.ThreeDimensional.ordinal()]) { // Check we are in the right unit checkAndSetUnit(unit, record, caps); GL11.glDisable(GL12.GL_TEXTURE_3D); unitRecord.enabled[Type.ThreeDimensional.ordinal()] = false; } } if (caps.isTextureCubeMapSupported()) { if (!unitRecord.isValid() || unitRecord.enabled[Type.CubeMap.ordinal()]) { // Check we are in the right unit checkAndSetUnit(unit, record, caps); GL11.glDisable(ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_ARB); unitRecord.enabled[Type.CubeMap.ordinal()] = false; } } }
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 . ja v a 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
public static int getGLType(final Type type) { switch (type) { case TwoDimensional: return GL11.GL_TEXTURE_2D; case OneDimensional: return GL11.GL_TEXTURE_1D; case ThreeDimensional: return GL12.GL_TEXTURE_3D; case CubeMap: return ARBTextureCubeMap.GL_TEXTURE_CUBE_MAP_ARB; }/*w w w . jav a2s .c o m*/ throw new IllegalArgumentException("invalid texture type: " + type); }
From source file:com.samrj.devil.gl.Texture3D.java
Texture3D() {
super(GL12.GL_TEXTURE_3D, GL12.GL_TEXTURE_BINDING_3D);
int oldID = tempBind();
parami(GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
parami(GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
parami(GL12.GL_TEXTURE_WRAP_R, GL11.GL_REPEAT);
parami(GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
parami(GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
tempUnbind(oldID);//ww w .jav a 2s . c o m
}
From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureArray.java
License:Open Source License
public int getSizeZ() { use(0); return GL11.glGetTexLevelParameteri(GL12.GL_TEXTURE_3D, 0, GL12.GL_TEXTURE_DEPTH); }
From source file:nintendofan9797.core.textureengine.codechicken.render.TextureUtils.java
public static void prepareTexture(int target, int texture, int min_mag_filter, int wrap) { GL11.glBindTexture(target, texture); engine().resetBoundTexture();//from w ww. j a v a 2 s . co m GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, min_mag_filter); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, min_mag_filter); switch (target) { case GL12.GL_TEXTURE_3D: GL11.glTexParameteri(target, GL12.GL_TEXTURE_WRAP_R, wrap); case GL11.GL_TEXTURE_2D: GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_T, wrap); case GL11.GL_TEXTURE_1D: GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_S, wrap); } }
From source file:org.terasology.rendering.opengl.OpenGLTexture.java
License:Apache License
@Override public void reload(TextureData data) { this.width = data.getWidth(); this.height = data.getHeight(); this.depth = data.getDepth(); this.wrapMode = data.getWrapMode(); this.filterMode = data.getFilterMode(); this.textureType = data.getType(); this.textureData = data; if (id == 0) { id = glGenTextures();/*from w ww .j av a 2 s . c o m*/ } switch (textureType) { case TEXTURE2D: logger.debug("Bound texture '{}' - {}", getURI(), id); glBindTexture(GL11.GL_TEXTURE_2D, id); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, getGLMode(wrapMode)); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, getGLMode(wrapMode)); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, getGlMinFilter(filterMode)); GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, getGlMagFilter(filterMode)); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 4); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, data.getBuffers().length - 1); if (data.getBuffers().length > 0) { for (int i = 0; i < data.getBuffers().length; i++) { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, i, GL11.GL_RGBA, width >> i, height >> i, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data.getBuffers()[i]); } } else { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); } break; case TEXTURE3D: logger.debug("Bound texture '{}' - {}", getURI(), id); glBindTexture(GL12.GL_TEXTURE_3D, id); glTexParameterf(GL12.GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, getGLMode(wrapMode)); glTexParameterf(GL12.GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, getGLMode(wrapMode)); glTexParameterf(GL12.GL_TEXTURE_3D, GL12.GL_TEXTURE_WRAP_R, getGLMode(wrapMode)); GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL11.GL_TEXTURE_MIN_FILTER, getGlMinFilter(filterMode)); GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL11.GL_TEXTURE_MAG_FILTER, getGlMagFilter(filterMode)); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 4); GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL12.GL_TEXTURE_MAX_LEVEL, data.getBuffers().length - 1); if (data.getBuffers().length > 0) { for (int i = 0; i < data.getBuffers().length; i++) { GL12.glTexImage3D(GL12.GL_TEXTURE_3D, i, GL11.GL_RGBA, width, height, depth, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data.getBuffers()[i]); } } else { GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL11.GL_RGBA, width, height, depth, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); } break; } }