Java Code Examples for com.jogamp.opengl.GL3#glTexImage3D()
The following examples show how to use
com.jogamp.opengl.GL3#glTexImage3D() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlyphManagerOpenGLController.java From constellation with Apache License 2.0 | 6 votes |
private void initGlyphs(GL3 gl) { gl.glGenTextures(1, glyphsTextureName, 0); gl.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, glyphsTextureName[0]); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_S, GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_T, GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MIN_FILTER, GL3.GL_LINEAR); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MAG_FILTER, GL3.GL_LINEAR); final int width = glyphManager.getTextureWidth(); final int height = glyphManager.getTextureHeight(); final int pageCount = glyphManager.getGlyphPageCount(); gl.glTexImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, INTERNAL_FORMAT, width, height, pageCount, 0, EXTERNAL_FORMAT, GL3.GL_UNSIGNED_BYTE, null); glyphsPageCapacity = pageCount; }
Example 2
Source File: Gl_320_fbo_layered.java From jogl-samples with MIT License | 6 votes |
private boolean initTexture(GL3 gl3) { gl3.glGenTextures(1, textureColorbufferName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D_ARRAY, textureColorbufferName.get(0)); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl3.glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, GL_RGB8, framebufferSize.x, framebufferSize.y, 4, //depth 0, GL_RGB, GL_UNSIGNED_BYTE, null); return checkError(gl3, "initTexture"); }
Example 3
Source File: Gl_320_fbo_rtt_texture_array.java From jogl-samples with MIT License | 6 votes |
private boolean initTexture(GL3 gl3) { gl3.glActiveTexture(GL_TEXTURE0); gl3.glGenTextures(1, textureName); gl3.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(0)); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); gl3.glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB8, windowSize.x / FRAMEBUFFER_SIZE, windowSize.y / FRAMEBUFFER_SIZE, 3,//depth 0, GL_BGR, GL_UNSIGNED_BYTE, null); return checkError(gl3, "initTexture"); }
Example 4
Source File: GLTools.java From constellation with Apache License 2.0 | 5 votes |
/** * Load a BufferedImage array into a texture array. * <p> * Each BufferedImage must be of type BufferedImage.TYPE_4BYTE_ABGR. The * images will be loaded at 0,0 at each level of the texture array. * <p> * It appears that the images must have a row length that is a multiple of * four. This is probably due to the particular format we're using, and * could probably be worked around, but the simple fix is to check your row * length. * * @param gl the current OpenGL context. * @param textureName The name of the texture to bind to with BindTexture(). * @param images A List of BufferedImages of type * BufferedImage.TYPE_4BYTE_ABGR. * @param maxWidth The maximum width of the images. * @param maxHeight The maximum height of the images. * @param minFilter Texture selection with TEXTURE_MIN_FILTER. * @param magFilter Texture selection with TEXTURE_MAG_FILTER. * @param wrapMode texture wrap mode with TEXTURE_WRAP_S and TEXTURE_WRAP_T. */ public static void loadTextures(final GL3 gl, final int textureName, final List<BufferedImage> images, final int maxWidth, final int maxHeight, final int minFilter, final int magFilter, final int wrapMode) { gl.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, textureName); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_S, wrapMode); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_T, wrapMode); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MIN_FILTER, minFilter); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MAG_FILTER, magFilter); // Call glTexImage3D() to create the buffer here: we've assumed the internalformat and format. gl.glTexImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, GL.GL_RGBA, maxWidth, maxHeight, images.size(), 0, GL.GL_RGBA, GL3.GL_UNSIGNED_BYTE, null); int i = 0; for (BufferedImage image : images) { try { final TextureData data = AWTTextureIO.newTextureData(gl.getGLProfile(), image, false); if (data.getWidth() > maxWidth || data.getHeight() > maxHeight) { throw new RenderException(String.format("Image %d is too large", i)); } // Images are always placed at 0,0. final int xoffset = 0; final int yoffset = 0; final int zoffset = i; gl.glTexSubImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, xoffset, yoffset, zoffset, data.getWidth(), data.getHeight(), 1, data.getPixelFormat(), GL3.GL_UNSIGNED_BYTE, data.getBuffer()); data.destroy(); } catch (final RuntimeException ex) { LOGGER.log(Level.SEVERE, null, ex); } i++; } }
Example 5
Source File: GlyphManagerOpenGLController.java From constellation with Apache License 2.0 | 4 votes |
private void updateGlyphs(GL3 gl) { final int width = glyphManager.getTextureWidth(); final int height = glyphManager.getTextureHeight(); final int pageCount = glyphManager.getGlyphPageCount(); final int glyphCount = glyphManager.getGlyphCount(); // If there have been new glyphs then some of then might be on the last page // buffered to the graphics card. We need to mark this last page as unbuffered // so that it gets buffered again. if (glyphCount > glyphsGlyphsBuffered && glyphsPagesBuffered > 0) { glyphsPagesBuffered--; glyphsPageBuffers.remove(glyphsPageBuffers.size() - 1); } glyphsGlyphsBuffered = glyphCount; if (pageCount > glyphsPageCapacity) { gl.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, glyphsTextureName[0]); gl.glTexImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, INTERNAL_FORMAT, width, height, pageCount, 0, EXTERNAL_FORMAT, GL3.GL_UNSIGNED_BYTE, null); glyphsPageCapacity = pageCount; glyphsPagesBuffered = 0; } while (glyphsPagesBuffered < pageCount) { final ByteBuffer pixelBuffer; if (glyphsPageBuffers.size() > glyphsPagesBuffered) { pixelBuffer = glyphsPageBuffers.get(glyphsPagesBuffered); pixelBuffer.rewind(); } else { pixelBuffer = ByteBuffer.allocateDirect(width * height); glyphManager.readGlyphTexturePage(glyphsPagesBuffered, pixelBuffer); glyphsPageBuffers.add(pixelBuffer); pixelBuffer.flip(); } gl.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, glyphsTextureName[0]); gl.glTexSubImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, 0, 0, glyphsPagesBuffered, width, height, 1, EXTERNAL_FORMAT, GL3.GL_UNSIGNED_BYTE, pixelBuffer); glyphsPagesBuffered++; } }
Example 6
Source File: GLTools.java From constellation with Apache License 2.0 | 4 votes |
/** * Load an array of icon textures. * <p> * We assume that the textures being loaded are icons, and therefore are * roughly the same size (with a maximum of (width,height). * <p> * The array is limited to GL_MAX_ARRAY_TEXTURE_LAYERS layers. This can be * fairly low (512 on low-end systems), so icons are loaded into an 8x8 icon * matrix in each layer, thus giving a maximum of 512x8x8=32768 icons. (This * assumes that GL_MAX_3D_TEXTURE_SIZE is big enough to take that many * pixels. With the current icon size of 256x256, then * GL_MAX_3D_TEXTURE_SIZE must be at least 2048.) * <p> * Icons that are smaller than (width,height) are offset so they are * centred, so the shader can just draw the icons without worrying about * where in the texture they are. * <p> * It appears that the images must have a row length that is a multiple of * four. This is probably due to the particular format we're using, and * could probably be worked around, but the simple fix is to check your row * length. * * @param glCurrent the current OpenGL context. * @param icons a list of icons that need to added to the buffer. * @param width the width of each icon. * @param height the height of each icon. * * @return the id of the texture buffer. */ public static int loadSharedIconTextures(final GL3 glCurrent, final List<ConstellationIcon> icons, final int width, final int height) { final int[] v = new int[1]; glCurrent.glGetIntegerv(GL3.GL_MAX_ARRAY_TEXTURE_LAYERS, v, 0); final int maxIcons = v[0] * 64; if (icons.size() > maxIcons) { System.out.printf("****\n**** Warning: nIcons %d > GL_MAX_ARRAY_TEXTURE_LAYERS %d\n****\n", icons.size(), maxIcons); } final int nIcons = Math.min(icons.size(), maxIcons); glCurrent.getContext().release(); final GL3 gl = (GL3) SharedDrawable.getSharedAutoDrawable().getGL(); final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException("Could not make texture context current."); } final int[] textureName = new int[1]; try { textureName[0] = SharedDrawable.getIconTextureName(); gl.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, textureName[0]); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_S, GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_T, GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MIN_FILTER, GL3.GL_LINEAR); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MAG_FILTER, GL3.GL_LINEAR); gl.glTexImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, GL.GL_RGBA, width * 8, height * 8, (nIcons + 63) / 64, 0, GL.GL_RGBA, GL3.GL_UNSIGNED_BYTE, null); final Iterator<ConstellationIcon> iconIterator = icons.iterator(); for (int i = 0; i < nIcons; i++) { final ConstellationIcon icon = iconIterator.next(); try { BufferedImage iconImage = icon.buildBufferedImage(); if (iconImage != null) { // Appears to be a bug in JOGL where texture provider for PNG files does not flip the texture. final TextureData data = AWTTextureIO.newTextureData(gl.getGLProfile(), iconImage, false); if (data.getWidth() > width || data.getHeight() > height) { throw new RenderException(String.format("Image %d is too large (width %d>%d, height %d>%d)", i, data.getWidth(), width, data.getHeight(), height)); } // Offset each icon into an 8x8 matrix. // There are multiple icons in each // Allow for icons that are smaller than width,height. final int xoffset = (width - data.getWidth()) / 2 + (width * (i & 7)); final int yoffset = (height - data.getHeight()) / 2 + (height * ((i >>> 3) & 7)); final int zoffset = i >>> 6; gl.glTexSubImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, xoffset, yoffset, zoffset, data.getWidth(), data.getHeight(), 1, data.getPixelFormat(), GL3.GL_UNSIGNED_BYTE, data.getBuffer()); data.destroy(); } } catch (final RuntimeException ex) { System.out.printf("##%n## GLTools.loadTextures() icon %d throwable: %s%n##%n", i, ex); LOGGER.log(Level.SEVERE, null, ex); } } } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } return textureName[0]; }
Example 7
Source File: Gl_320_texture_3d.java From jogl-samples with MIT License | 4 votes |
private boolean initTexture(GL3 gl3) { int size = 32; FloatBuffer data = GLBuffers.newDirectFloatBuffer(size * size * size); for (int k = 0; k < size; ++k) { for (int j = 0; j < size; ++j) { for (int i = 0; i < size; ++i) { data.put(i + j * size + k * size * size, new Vec4(i, j, k, 0.0f).div(size / 8 - 1).simplex_()); } } } gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl3.glGenTextures(1, textureName); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_3D, textureName.get(0)); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, (int) (Math.log(256) / Math.log(2))); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gl3.glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); gl3.glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, size, size, size, 0, GL_RED, GL_FLOAT, data); gl3.glGenerateMipmap(GL_TEXTURE_3D); BufferUtils.destroyDirectBuffer(data); gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 4); return checkError(gl3, "initTexture"); }
Example 8
Source File: Gl_320_texture_lod.java From jogl-samples with MIT License | 4 votes |
private boolean initTexture(GL3 gl3) { try { gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gl3.glActiveTexture(GL_TEXTURE0); gl3.glGenTextures(Texture.MAX, textureName); jgli.Texture2d texture = new Texture2d(jgli.Load.load(TEXTURE_ROOT + "/" + TEXTURE_DIFFUSE)); jgli.Gl.Format format = jgli.Gl.translate(texture.format()); { gl3.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.ZERO)); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_LOD, 0.0f); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LOD, 0.0f); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_LOD_BIAS, 4.0f); for (int level = 0; level < texture.levels(); ++level) { gl3.glTexImage3D(GL_TEXTURE_2D_ARRAY, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 1, 0, format.external.value, format.type.value, texture.data(level)); } } { gl3.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.ONE)); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_LOD, 3.0f); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LOD, 3.0f); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_LOD_BIAS, 0.0f); for (int level = 0; level < texture.levels(); ++level) { gl3.glTexImage3D(GL_TEXTURE_2D_ARRAY, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 1, 0, format.external.value, format.type.value, texture.data(level)); } } { gl3.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.TWO)); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_LOD, 0.0f); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LOD, 10.0f); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_LOD_BIAS, 4.0f); for (int level = 0; level < texture.levels(); ++level) { gl3.glTexImage3D(GL_TEXTURE_2D_ARRAY, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 1, 0, format.external.value, format.type.value, texture.data(level)); } } { gl3.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(Texture.THREE)); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gl3.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_LOD, 0.0f); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LOD, 10.0f); gl3.glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_LOD_BIAS, 3.5f); for (int level = 0; level < texture.levels(); ++level) { gl3.glTexImage3D(GL_TEXTURE_2D_ARRAY, level, format.internal.value, texture.dimensions(level)[0], texture.dimensions(level)[1], 1, 0, format.external.value, format.type.value, texture.data(level)); } } gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D_ARRAY, 0); } catch (IOException ex) { Logger.getLogger(Gl_320_texture_lod.class.getName()).log(Level.SEVERE, null, ex); } return true; }