public Texture loadTexture(TextureData textureData) { return TextureIO.newTexture(textureData); }
public void screenshot(TextureData image, String testImage) throws IOException { File output = new File(testImage); if (!output.getParentFile().exists()) output.getParentFile().mkdirs(); TextureIO.write(image, output); }
public TextureData loadTextureData(String filename, GL gl) throws IOException { TextureData i2 = TextureIO.newTextureData(gl.getGLProfile(), new File(filename), true, null); return i2; }
/** * Creates an OpenGL texture object from the specified stream using * the current OpenGL context. * * @param stream the stream from which to read the texture data * @param mipmap whether mipmaps should be produced for this * texture either by autogenerating them or * reading them from the file. Some file formats * support multiple mipmaps in a single file in * which case those mipmaps will be used rather * than generating them. * @param fileSuffix the suffix of the file name to be used as a * hint of the file format to the underlying * texture provider, or null if none and should be * auto-detected (some texture providers do not * support this) * @throws IOException if an error occurred while reading the stream * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ public static Texture newTexture(final InputStream stream, final boolean mipmap, final String fileSuffix) throws IOException, GLException { final GL gl = GLContext.getCurrentGL(); final GLProfile glp = gl.getGLProfile(); final TextureData data = newTextureData(glp, stream, mipmap, fileSuffix); final Texture texture = newTexture(gl, data); data.flush(); return texture; }
final int internalFormat = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2GL3.GL_TEXTURE_INTERNAL_FORMAT); final int width = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2GL3.GL_TEXTURE_WIDTH); final int height = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2GL3.GL_TEXTURE_HEIGHT); final int border = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_BORDER); TextureData data = null; if (internalFormat == GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT || internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) { final int size = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2GL3.GL_TEXTURE_COMPRESSED_IMAGE_SIZE); final ByteBuffer res = ByteBuffer.allocate(size); gl.glGetCompressedTexImage(GL.GL_TEXTURE_2D, 0, res); final int packAlignment = glGetInteger(gl, GL.GL_PACK_ALIGNMENT); final int packRowLength = glGetInteger(gl, GL2ES3.GL_PACK_ROW_LENGTH); final int packSkipRows = glGetInteger(gl, GL2ES3.GL_PACK_SKIP_ROWS); final int packSkipPixels = glGetInteger(gl, GL2ES3.GL_PACK_SKIP_PIXELS); final int packSwapBytes = glGetInteger(gl, GL2GL3.GL_PACK_SWAP_BYTES); write(data, file);
final int internalFormat = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2ES3.GL_TEXTURE_INTERNAL_FORMAT); final int width = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2ES3.GL_TEXTURE_WIDTH); final int height = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2ES3.GL_TEXTURE_HEIGHT); final int border = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_BORDER); TextureData data = null; if (internalFormat == GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT || internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) { final int size = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2GL3.GL_TEXTURE_COMPRESSED_IMAGE_SIZE); final ByteBuffer res = ByteBuffer.allocate(size); gl.glGetCompressedTexImage(GL.GL_TEXTURE_2D, 0, res); write(data, file);
/** * Creates a TextureData from the given stream. Does no OpenGL work. * * @param glp the OpenGL Profile this texture data should be * created for. * @param stream the stream from which to read the texture data * @param mipmap whether mipmaps should be produced for this * texture either by autogenerating them or * reading them from the file. Some file formats * support multiple mipmaps in a single file in * which case those mipmaps will be used rather * than generating them. * @param fileSuffix the suffix of the file name to be used as a * hint of the file format to the underlying * texture provider, or null if none and should be * auto-detected (some texture providers do not * support this) * @return the texture data from the stream, or null if none of the * registered texture providers could read the stream * @throws IOException if an error occurred while reading the stream */ public static TextureData newTextureData(final GLProfile glp, final InputStream stream, final boolean mipmap, final String fileSuffix) throws IOException { return newTextureDataImpl(glp, stream, 0, 0, mipmap, fileSuffix); }
private static TextureData newTextureDataImpl(final GLProfile glp, final File file, final int internalFormat, final int pixelFormat, final boolean mipmap, String fileSuffix) throws IOException { if (file == null) { throw new IOException("File was null"); } fileSuffix = toLowerCase(fileSuffix); for (final Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { final TextureProvider provider = iter.next(); final TextureData data = provider.newTextureData(glp, file, internalFormat, pixelFormat, mipmap, fileSuffix); if (data != null) { return data; } } throw new IOException("No suitable reader for given file "+file.getAbsolutePath()); }
private static boolean haveTexRect(final GL gl) { return (!disableTexRect && TextureIO.isTexRectEnabled() && gl.isExtensionAvailable(GLExtensions.ARB_texture_rectangle)); }
/** * Creates an OpenGL texture object from the specified stream using * the current OpenGL context. * * @param stream the stream from which to read the texture data * @param mipmap whether mipmaps should be produced for this * texture either by autogenerating them or * reading them from the file. Some file formats * support multiple mipmaps in a single file in * which case those mipmaps will be used rather * than generating them. * @param fileSuffix the suffix of the file name to be used as a * hint of the file format to the underlying * texture provider, or null if none and should be * auto-detected (some texture providers do not * support this) * @throws IOException if an error occurred while reading the stream * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ public static Texture newTexture(final InputStream stream, final boolean mipmap, final String fileSuffix) throws IOException, GLException { final GL gl = GLContext.getCurrentGL(); final GLProfile glp = gl.getGLProfile(); final TextureData data = newTextureData(glp, stream, mipmap, fileSuffix); final Texture texture = newTexture(gl, data); data.flush(); return texture; }
/** * Creates a TextureData from the given stream. Does no OpenGL work. * * @param glp the OpenGL Profile this texture data should be * created for. * @param stream the stream from which to read the texture data * @param mipmap whether mipmaps should be produced for this * texture either by autogenerating them or * reading them from the file. Some file formats * support multiple mipmaps in a single file in * which case those mipmaps will be used rather * than generating them. * @param fileSuffix the suffix of the file name to be used as a * hint of the file format to the underlying * texture provider, or null if none and should be * auto-detected (some texture providers do not * support this) * @return the texture data from the stream, or null if none of the * registered texture providers could read the stream * @throws IOException if an error occurred while reading the stream */ public static TextureData newTextureData(final GLProfile glp, final InputStream stream, final boolean mipmap, final String fileSuffix) throws IOException { return newTextureDataImpl(glp, stream, 0, 0, mipmap, fileSuffix); }
private static TextureData newTextureDataImpl(final GLProfile glp, final URL url, final int internalFormat, final int pixelFormat, final boolean mipmap, String fileSuffix) throws IOException { if (url == null) { throw new IOException("URL was null"); } fileSuffix = toLowerCase(fileSuffix); for (final Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { final TextureProvider provider = iter.next(); final TextureData data = provider.newTextureData(glp, url, internalFormat, pixelFormat, mipmap, fileSuffix); if (data != null) { return data; } } throw new IOException("No suitable reader for given URL "+url); }
private static boolean haveTexRect(final GL gl) { return (!disableTexRect && TextureIO.isTexRectEnabled() && gl.isExtensionAvailable(GLExtensions.ARB_texture_rectangle)); }
/** * Creates an OpenGL texture object from the specified file using * the current OpenGL context. * * @param file the file from which to read the texture data * @param mipmap whether mipmaps should be produced for this * texture either by autogenerating them or * reading them from the file. Some file formats * support multiple mipmaps in a single file in * which case those mipmaps will be used rather * than generating them. * @throws IOException if an error occurred while reading the file * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ public static Texture newTexture(final File file, final boolean mipmap) throws IOException, GLException { final GL gl = GLContext.getCurrentGL(); final GLProfile glp = gl.getGLProfile(); final TextureData data = newTextureData(glp, file, mipmap, IOUtil.getFileSuffix(file)); final Texture texture = newTexture(gl, data); data.flush(); return texture; }
/** * Creates an OpenGL texture object from the specified TextureData * using the current OpenGL context. * * @param data the texture data to turn into an OpenGL texture * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred * @throws IllegalArgumentException if the passed TextureData was null */ public static Texture newTexture(final TextureData data) throws GLException, IllegalArgumentException { return newTexture(GLContext.getCurrentGL(), data); }
@Override public TextureData screenshot(File file) throws IOException { TextureData screen = screenshot(); TextureIO.write(screen, file); return screen; }
public final static TextureData createTestTextureData() { TextureData res = null; try { final URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-28x16.png", NullGLMediaPlayer.class.getClassLoader()); if(null != urlConn) { res = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, TextureIO.PNG); } } catch (final Exception e) { e.printStackTrace(); } if(null == res) { final int w = 160; final int h = 90; final ByteBuffer buffer = Buffers.newDirectByteBuffer(w*h*4); while(buffer.hasRemaining()) { buffer.put((byte) 0xEA); buffer.put((byte) 0xEA); buffer.put((byte) 0xEA); buffer.put((byte) 0xEA); } buffer.rewind(); res = new TextureData(GLProfile.getGL2ES2(), GL.GL_RGBA, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, false, false, false, buffer, null); } return res; }
return newTextureDataImpl(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix);
private static TextureData newTextureDataImpl(final GLProfile glp, InputStream stream, final int internalFormat, final int pixelFormat, final boolean mipmap, String fileSuffix) throws IOException { if (stream == null) { throw new IOException("Stream was null"); } fileSuffix = toLowerCase(fileSuffix); // Note: use of BufferedInputStream works around 4764639/4892246 if (!(stream instanceof BufferedInputStream)) { stream = new BufferedInputStream(stream); } for (final Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { final TextureProvider provider = iter.next(); final TextureData data = provider.newTextureData(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix); if (data != null) { return data; } } throw new IOException("No suitable reader for given stream"); }
/** * Creates an OpenGL texture object from the specified file using * the current OpenGL context. * * @param file the file from which to read the texture data * @param mipmap whether mipmaps should be produced for this * texture either by autogenerating them or * reading them from the file. Some file formats * support multiple mipmaps in a single file in * which case those mipmaps will be used rather * than generating them. * @throws IOException if an error occurred while reading the file * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ public static Texture newTexture(final File file, final boolean mipmap) throws IOException, GLException { final GL gl = GLContext.getCurrentGL(); final GLProfile glp = gl.getGLProfile(); final TextureData data = newTextureData(glp, file, mipmap, IOUtil.getFileSuffix(file)); final Texture texture = newTexture(gl, data); data.flush(); return texture; }