41package com.jogamp.opengl.util.texture;
43import java.io.BufferedInputStream;
44import java.io.BufferedOutputStream;
46import java.io.FileInputStream;
47import java.io.IOException;
48import java.io.InputStream;
49import java.io.OutputStream;
51import java.nio.Buffer;
52import java.nio.ByteBuffer;
53import java.nio.IntBuffer;
54import java.util.ArrayList;
55import java.util.HashMap;
56import java.util.Iterator;
60import com.jogamp.nativewindow.util.Dimension;
61import com.jogamp.nativewindow.util.DimensionImmutable;
62import com.jogamp.nativewindow.util.PixelFormat;
63import com.jogamp.opengl.GL;
64import com.jogamp.opengl.GL2;
65import com.jogamp.opengl.GL2ES3;
66import com.jogamp.opengl.GL2GL3;
67import com.jogamp.opengl.GLContext;
68import com.jogamp.opengl.GLException;
69import com.jogamp.opengl.GLProfile;
71import jogamp.opengl.Debug;
73import com.jogamp.common.util.IOUtil;
74import com.jogamp.opengl.util.GLPixelStorageModes;
75import com.jogamp.opengl.util.PNGPixelRect;
76import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
77import com.jogamp.opengl.util.texture.ImageType;
78import com.jogamp.opengl.util.texture.spi.DDSImage;
79import com.jogamp.opengl.util.texture.spi.JPEGImage;
80import com.jogamp.opengl.util.texture.spi.NetPbmTextureWriter;
81import com.jogamp.opengl.util.texture.spi.SGIImage;
82import com.jogamp.opengl.util.texture.spi.TGAImage;
83import com.jogamp.opengl.util.texture.spi.TextureProvider;
84import com.jogamp.opengl.util.texture.spi.TextureWriter;
151 public static final String
SGI =
"sgi";
195 private static final boolean DEBUG = Debug.debug(
"TextureIO");
201 private static boolean texRectEnabled =
true;
234 final boolean mipmap,
235 String fileSuffix)
throws IOException {
236 if (fileSuffix ==
null) {
237 fileSuffix = IOUtil.getFileSuffix(file);
239 return newTextureDataImpl(glp, file, 0, 0, mipmap, fileSuffix);
264 final boolean mipmap,
265 final String fileSuffix)
throws IOException {
266 return newTextureDataImpl(glp, stream, 0, 0, mipmap, fileSuffix);
291 final boolean mipmap,
292 String fileSuffix)
throws IOException {
293 if (fileSuffix ==
null) {
294 fileSuffix = IOUtil.getFileSuffix(url.getPath());
296 return newTextureDataImpl(glp, url, 0, 0, mipmap, fileSuffix);
339 final int internalFormat,
340 final int pixelFormat,
341 final boolean mipmap,
342 String fileSuffix)
throws IOException, IllegalArgumentException {
343 if ((internalFormat == 0) || (pixelFormat == 0)) {
344 throw new IllegalArgumentException(
"internalFormat and pixelFormat must be non-zero");
347 if (fileSuffix ==
null) {
348 fileSuffix = IOUtil.getFileSuffix(file);
351 return newTextureDataImpl(glp, file, internalFormat, pixelFormat, mipmap, fileSuffix);
387 final int internalFormat,
388 final int pixelFormat,
389 final boolean mipmap,
390 final String fileSuffix)
throws IOException, IllegalArgumentException {
391 if ((internalFormat == 0) || (pixelFormat == 0)) {
392 throw new IllegalArgumentException(
"internalFormat and pixelFormat must be non-zero");
395 return newTextureDataImpl(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix);
431 final int internalFormat,
432 final int pixelFormat,
433 final boolean mipmap,
434 String fileSuffix)
throws IOException, IllegalArgumentException {
435 if ((internalFormat == 0) || (pixelFormat == 0)) {
436 throw new IllegalArgumentException(
"internalFormat and pixelFormat must be non-zero");
439 if (fileSuffix ==
null) {
440 fileSuffix = IOUtil.getFileSuffix(url.getPath());
443 return newTextureDataImpl(glp, url, internalFormat, pixelFormat, mipmap, fileSuffix);
474 throw new IllegalArgumentException(
"Null TextureData");
553 if (fileSuffix ==
null) {
554 fileSuffix = IOUtil.getFileSuffix(url.getPath());
609 throw new GLException(
"Only GL_TEXTURE_2D textures are supported");
615 throw new GLException(
"Implementation only supports GL2GL3 (Use GLReadBufferUtil and the TextureData variant), have: " + _gl);
631 final ByteBuffer res = ByteBuffer.allocate(size);
634 false,
true,
true, res,
null);
636 int bytesPerPixel = 0;
637 int fetchedFormat = 0;
638 switch (internalFormat) {
653 throw new IOException(
"Unsupported texture internal format 0x" + Integer.toHexString(internalFormat));
660 final ByteBuffer res = ByteBuffer.allocate((width + (2 * border)) *
661 (height + (2 * border)) *
664 System.out.println(
"Allocated buffer of size " + res.remaining() +
" for fetched image (" +
665 ((fetchedFormat ==
GL.
GL_RGB) ?
"GL_RGB" :
"GL_RGBA") +
")");
672 false,
false,
false, res,
null);
675 System.out.println(
"data.getPixelFormat() = " +
684 for (
final Iterator<TextureWriter> iter = textureWriters.iterator(); iter.hasNext(); ) {
686 if (writer.
write(file, data)) {
691 throw new IOException(
"No suitable texture writer found for "+file.getAbsolutePath());
712 textureProviders.add(0, provider);
715 if(
null != imageTypes ) {
716 for(
int i=0; i<imageTypes.length; i++) {
717 imageType2TextureProvider.put(imageTypes[i], provider);
732 textureWriters.add(0, writer);
754 texRectEnabled = enabled;
761 return texRectEnabled;
768 private static List<TextureProvider> textureProviders =
new ArrayList<TextureProvider>();
769 private static Map<ImageType,TextureProvider> imageType2TextureProvider =
new HashMap<ImageType,TextureProvider>();
770 private static List<TextureWriter> textureWriters =
new ArrayList<TextureWriter>();
778 Class.forName(
"com.jogamp.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance();
780 }
catch (
final Exception e) {
795 if(GLProfile.isAWTAvailable()) {
798 final TextureWriter writer = (TextureWriter)
799 Class.forName(
"com.jogamp.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance();
801 }
catch (
final Exception e) {
805 }
catch (
final Error e) {
821 private static TextureData newTextureDataImpl(
final GLProfile glp, InputStream stream,
822 final int internalFormat,
823 final int pixelFormat,
824 final boolean mipmap,
825 String fileSuffix)
throws IOException {
826 if (stream ==
null) {
827 throw new IOException(
"Stream was null");
831 if (!(stream instanceof BufferedInputStream)) {
832 stream =
new BufferedInputStream(stream);
838 final ImageType imageType =
new ImageType(stream);
839 if( imageType.isDefined() ) {
840 final TextureProvider mappedProvider = imageType2TextureProvider.get(imageType);
841 if(
null != mappedProvider ) {
842 final TextureData data = mappedProvider.newTextureData(glp, stream,
848 data.srcImageType = imageType;
853 }
catch (
final IOException ioe) {
855 System.err.println(
"Caught "+ioe.getMessage());
856 ioe.printStackTrace();
860 fileSuffix = toLowerCase(fileSuffix);
862 for (
final Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) {
863 final TextureProvider provider = iter.next();
870 final ImageType[] imageTypes = provider.getImageTypes();
871 data.srcImageType =
null != imageTypes ? imageTypes[0] :
null;
876 throw new IOException(
"No suitable reader for given stream");
878 private static TextureData newTextureDataImpl(
final GLProfile glp,
final File file,
879 final int internalFormat,
880 final int pixelFormat,
881 final boolean mipmap,
882 final String fileSuffix)
throws IOException {
884 throw new IOException(
"File was null");
886 final InputStream stream =
new BufferedInputStream(
new FileInputStream(file));
888 return newTextureDataImpl( glp, stream, internalFormat, pixelFormat, mipmap,
889 (fileSuffix !=
null) ? fileSuffix : IOUtil.getFileSuffix(file) );
890 }
catch(
final IOException ioe) {
891 throw new IOException(ioe.getMessage()+
", given file "+file.getAbsolutePath(), ioe);
896 private static TextureData newTextureDataImpl(
final GLProfile glp,
final URL url,
897 final int internalFormat,
898 final int pixelFormat,
899 final boolean mipmap,
900 final String fileSuffix)
throws IOException {
902 throw new IOException(
"URL was null");
904 final InputStream stream =
new BufferedInputStream(url.openStream());
906 return newTextureDataImpl(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix);
907 }
catch(
final IOException ioe) {
908 throw new IOException(ioe.getMessage()+
", given URL "+url, ioe);
916 static class DDSTextureProvider
implements TextureProvider {
917 private static final ImageType[] imageTypes =
new ImageType[] {
new ImageType(ImageType.T_DDS) };
919 public final ImageType[] getImageTypes() {
924 public TextureData
newTextureData(
final GLProfile glp,
final InputStream stream,
925 final int internalFormat,
926 final int pixelFormat,
927 final boolean mipmap,
928 final String fileSuffix)
throws IOException {
929 if (ImageType.T_DDS.equals(fileSuffix) ||
930 ImageType.T_DDS.equals(ImageType.Util.getFileSuffix(stream))) {
931 final byte[] data = IOUtil.copyStream2ByteArray(stream);
932 final ByteBuffer buf = ByteBuffer.wrap(data);
933 final DDSImage image = DDSImage.read(buf);
934 return newTextureData(glp, image, internalFormat, pixelFormat, mipmap);
940 private TextureData
newTextureData(
final GLProfile glp,
final DDSImage image,
944 final DDSImage.ImageInfo info = image.getMipMap(0);
945 if (pixelFormat == 0) {
946 switch (image.getPixelFormat()) {
947 case DDSImage.D3DFMT_R8G8B8:
948 pixelFormat = GL.GL_RGB;
951 pixelFormat = GL.GL_RGBA;
955 if (info.isCompressed()) {
956 switch (info.getCompressionFormat()) {
957 case DDSImage.D3DFMT_DXT1:
958 internalFormat = GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
960 case DDSImage.D3DFMT_DXT3:
961 internalFormat = GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
963 case DDSImage.D3DFMT_DXT5:
964 internalFormat = GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
967 throw new RuntimeException(
"Unsupported DDS compression format \"" +
968 DDSImage.getCompressionFormatName(info.getCompressionFormat()) +
"\"");
971 if (internalFormat == 0) {
972 switch (image.getPixelFormat()) {
973 case DDSImage.D3DFMT_R8G8B8:
974 pixelFormat = GL.GL_RGB;
977 pixelFormat = GL.GL_RGBA;
981 final TextureData.Flusher flusher =
new TextureData.Flusher() {
983 public void flush() {
988 if (mipmap && image.getNumMipMaps() > 0) {
989 final Buffer[] mipmapData =
new Buffer[image.getNumMipMaps()];
990 for (
int i = 0; i < image.getNumMipMaps(); i++) {
991 mipmapData[i] = image.getMipMap(i).getData();
993 data =
new TextureData(glp, internalFormat,
1007 data =
new TextureData(glp, internalFormat,
1012 GL.GL_UNSIGNED_BYTE,
1014 info.isCompressed(),
1025 static class SGITextureProvider
implements TextureProvider {
1026 private static final ImageType[] imageTypes =
new ImageType[] {
new ImageType(ImageType.T_SGI_RGB) };
1028 public final ImageType[] getImageTypes() {
1033 public TextureData
newTextureData(
final GLProfile glp,
final InputStream stream,
1036 final boolean mipmap,
1037 final String fileSuffix)
throws IOException {
1038 if (
SGI.equals(fileSuffix) ||
1039 ImageType.T_SGI_RGB.equals(fileSuffix) ||
1040 SGI.equals(ImageType.Util.getFileSuffix(stream)) ||
1041 ImageType.T_SGI_RGB.equals(ImageType.Util.getFileSuffix(stream))) {
1042 final SGIImage image = SGIImage.read(stream);
1043 if (pixelFormat == 0) {
1044 pixelFormat = image.getFormat();
1046 if (internalFormat == 0) {
1047 internalFormat = image.getFormat();
1049 return new TextureData(glp, internalFormat,
1054 GL.GL_UNSIGNED_BYTE,
1058 ByteBuffer.wrap(image.getData()),
1068 static class TGATextureProvider
implements TextureProvider {
1069 private static final ImageType[] imageTypes =
new ImageType[] {
new ImageType(ImageType.T_TGA) };
1071 public final ImageType[] getImageTypes() {
1076 public TextureData
newTextureData(
final GLProfile glp,
final InputStream stream,
1079 final boolean mipmap,
1080 final String fileSuffix)
throws IOException {
1081 if (ImageType.T_TGA.equals(fileSuffix)) {
1082 final TGAImage image = TGAImage.read(glp, stream);
1083 if (pixelFormat == 0) {
1084 pixelFormat = image.getGLFormat();
1086 if (internalFormat == 0) {
1087 if(glp.isGL2ES3()) {
1088 internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA8:GL.GL_RGB8;
1090 internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB;
1093 return new TextureData(glp, internalFormat,
1098 GL.GL_UNSIGNED_BYTE,
1112 static class PNGTextureProvider
implements TextureProvider {
1113 private static final ImageType[] imageTypes =
new ImageType[] {
new ImageType(ImageType.T_PNG) };
1115 public final ImageType[] getImageTypes() {
1120 public TextureData
newTextureData(
final GLProfile glp,
final InputStream stream,
1123 final boolean mipmap,
1124 final String fileSuffix)
throws IOException {
1125 if (ImageType.T_PNG.equals(fileSuffix) ||
1126 ImageType.T_PNG.equals(ImageType.Util.getFileSuffix(stream))) {
1127 final PNGPixelRect image = PNGPixelRect.read(stream,
null,
true , 0 ,
true );
1128 final GLPixelAttributes glpa =
new GLPixelAttributes(glp, image.getPixelformat(),
false );
1129 if ( 0 == pixelFormat ) {
1130 pixelFormat = glpa.format;
1132 if ( 0 == internalFormat ) {
1133 final boolean hasAlpha = 4 == glpa.pfmt.comp.bytesPerPixel();
1134 if(glp.isGL2ES3()) {
1135 internalFormat = hasAlpha ? GL.GL_RGBA8 : GL.GL_RGB8;
1137 internalFormat = hasAlpha ? GL.GL_RGBA : GL.GL_RGB;
1140 return new TextureData(glp, internalFormat,
1141 image.getSize().getWidth(),
1142 image.getSize().getHeight(),
1159 static class JPGTextureProvider
implements TextureProvider {
1160 private static final ImageType[] imageTypes =
new ImageType[] {
new ImageType(ImageType.T_JPG) };
1162 public final ImageType[] getImageTypes() {
1167 public TextureData
newTextureData(
final GLProfile glp,
final InputStream stream,
1170 final boolean mipmap,
1171 final String fileSuffix)
throws IOException {
1172 if (ImageType.T_JPG.equals(fileSuffix) ||
1173 ImageType.T_JPG.equals(ImageType.Util.getFileSuffix(stream))) {
1174 final JPEGImage image = JPEGImage.read( stream);
1175 if (pixelFormat == 0) {
1176 pixelFormat = image.getGLFormat();
1178 if (internalFormat == 0) {
1179 if(glp.isGL2ES3()) {
1180 internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA8:GL.GL_RGB8;
1182 internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB;
1185 return new TextureData(glp, internalFormat,
1205 static class DDSTextureWriter
implements TextureWriter {
1207 public boolean write(
final File file,
1208 final TextureData data)
throws IOException {
1209 if (ImageType.T_DDS.equals(IOUtil.getFileSuffix(file))) {
1212 final int pixelFormat = pixelAttribs.
format;
1213 final int pixelType = pixelAttribs.type;
1214 if (pixelType != GL.GL_BYTE &&
1215 pixelType != GL.GL_UNSIGNED_BYTE) {
1216 throw new IOException(
"DDS writer only supports byte / unsigned byte textures");
1221 switch (pixelFormat) {
1222 case GL.GL_RGB: d3dFormat = DDSImage.D3DFMT_R8G8B8;
break;
1223 case GL.GL_RGBA: d3dFormat = DDSImage.D3DFMT_A8R8G8B8;
break;
1224 case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT: d3dFormat = DDSImage.D3DFMT_DXT1;
break;
1225 case GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
throw new IOException(
"RGBA DXT1 not yet supported");
1226 case GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: d3dFormat = DDSImage.D3DFMT_DXT3;
break;
1227 case GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: d3dFormat = DDSImage.D3DFMT_DXT5;
break;
1228 default:
throw new IOException(
"Unsupported pixel format 0x" + Integer.toHexString(pixelFormat) +
" by DDS writer");
1231 ByteBuffer[] mipmaps =
null;
1232 if (data.getMipmapData() !=
null) {
1233 mipmaps =
new ByteBuffer[data.getMipmapData().length];
1234 for (
int i = 0; i < mipmaps.length; i++) {
1235 mipmaps[i] = (ByteBuffer) data.getMipmapData()[i];
1238 mipmaps =
new ByteBuffer[] { (ByteBuffer) data.getBuffer() };
1241 final DDSImage image = DDSImage.createFromData(d3dFormat,
1256 static class SGITextureWriter
implements TextureWriter {
1258 public boolean write(
final File file,
1259 final TextureData data)
throws IOException {
1260 final String fileSuffix = IOUtil.getFileSuffix(file);
1261 if (
SGI.equals(fileSuffix) ||
1262 ImageType.T_SGI_RGB.equals(fileSuffix)) {
1265 final int pixelFormat = pixelAttribs.
format;
1266 final int pixelType = pixelAttribs.type;
1267 if ((pixelFormat == GL.GL_RGB ||
1268 pixelFormat == GL.GL_RGBA) &&
1269 (pixelType == GL.GL_BYTE ||
1270 pixelType == GL.GL_UNSIGNED_BYTE)) {
1271 final ByteBuffer buf = ((data.getBuffer() !=
null) ?
1272 (ByteBuffer) data.getBuffer() :
1273 (ByteBuffer) data.getMipmapData()[0]);
1275 if (buf.hasArray()) {
1276 bytes = buf.array();
1279 bytes =
new byte[buf.remaining()];
1284 final SGIImage image = SGIImage.createFromData(data.getWidth(),
1286 (pixelFormat == GL.GL_RGBA),
1288 image.write(file,
false);
1292 throw new IOException(
"SGI writer doesn't support this pixel format / type (only GL_RGB/A + bytes)");
1302 static class TGATextureWriter
implements TextureWriter {
1304 public boolean write(
final File file,
1305 final TextureData data)
throws IOException {
1306 if (ImageType.T_TGA.equals(IOUtil.getFileSuffix(file))) {
1309 final int pixelFormat = pixelAttribs.
format;
1310 final int pixelType = pixelAttribs.type;
1311 if ((pixelFormat == GL.GL_RGB ||
1312 pixelFormat == GL.GL_RGBA ||
1313 pixelFormat == GL.GL_BGR ||
1314 pixelFormat == GL.GL_BGRA ) &&
1315 (pixelType == GL.GL_BYTE ||
1316 pixelType == GL.GL_UNSIGNED_BYTE)) {
1318 ByteBuffer buf = (ByteBuffer) data.getBuffer();
1320 buf = (ByteBuffer) data.getMipmapData()[0];
1324 if( pixelFormat == GL.GL_RGB || pixelFormat == GL.GL_RGBA ) {
1326 final int skip = ((pixelFormat == GL.GL_RGB) ? 3 : 4);
1327 for (
int i = 0; i < buf.remaining(); i += skip) {
1328 final byte red = buf.get(i + 0);
1329 final byte blue = buf.get(i + 2);
1330 buf.put(i + 0, blue);
1331 buf.put(i + 2, red);
1335 final TGAImage image = TGAImage.createFromData(data.getWidth(),
1337 (pixelFormat == GL.GL_RGBA || pixelFormat == GL.GL_BGRA),
1342 throw new IOException(
"TGA writer doesn't support this pixel format 0x"+Integer.toHexString(pixelFormat)+
1343 " / type 0x"+Integer.toHexString(pixelFormat)+
" (only GL_RGB/A, GL_BGR/A + bytes)");
1353 static class PNGTextureWriter
implements TextureWriter {
1355 public boolean write(
final File file,
final TextureData data)
throws IOException {
1356 if (ImageType.T_PNG.equals(IOUtil.getFileSuffix(file))) {
1359 final int pixelFormat = pixelAttribs.
format;
1360 final int pixelType = pixelAttribs.type;
1361 final int bytesPerPixel = pixelAttribs.pfmt.comp.bytesPerPixel();
1362 final PixelFormat pixFmt = pixelAttribs.pfmt;
1363 if ( ( 1 == bytesPerPixel || 3 == bytesPerPixel || 4 == bytesPerPixel) &&
1364 ( pixelType == GL.GL_BYTE || pixelType == GL.GL_UNSIGNED_BYTE)) {
1365 Buffer buf0 = data.getBuffer();
1367 buf0 = data.getMipmapData()[0];
1369 if(
null == buf0 ) {
1370 throw new IOException(
"Pixel storage buffer is null");
1372 final DimensionImmutable size =
new Dimension(data.getWidth(), data.getHeight());
1373 if( buf0 instanceof ByteBuffer ) {
1374 final ByteBuffer buf = (ByteBuffer) buf0;
1376 final PNGPixelRect image =
new PNGPixelRect(pixFmt, size,
1377 0 , !data.getMustFlipVertically() , buf ,
1379 final OutputStream outs =
new BufferedOutputStream(IOUtil.getFileOutputStream(file,
true ));
1380 image.write(outs,
true );
1382 }
else if( buf0 instanceof IntBuffer ) {
1383 final IntBuffer buf = (IntBuffer) buf0;
1385 final OutputStream outs =
new BufferedOutputStream(IOUtil.getFileOutputStream(file,
true ));
1386 PNGPixelRect.write(pixFmt, size,
1387 0 , !data.getMustFlipVertically() , buf ,
1388 -1f, -1f, outs,
true );
1391 throw new IOException(
"PNG writer doesn't support pixel storage buffer of type "+buf0.getClass().getName());
1394 throw new IOException(
"PNG writer doesn't support this pixel format 0x"+Integer.toHexString(pixelFormat)+
1395 " / type 0x"+Integer.toHexString(pixelFormat)+
" (only GL_RGB/A, GL_BGR/A + bytes)");
1405 private static int glGetTexLevelParameteri(
final GL2GL3 gl,
final int target,
final int level,
final int pname) {
1406 final int[] tmp =
new int[1];
1407 gl.glGetTexLevelParameteriv(target, 0, pname, tmp, 0);
1411 private static String toLowerCase(
final String arg) {
1416 return arg.toLowerCase();
Abstraction for an OpenGL rendering context.
static GL getCurrentGL()
Returns the GL object bound to this thread current context.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
final int format
The OpenGL pixel data format.
Utility to safely set and restore the PACK and UNPACK pixel storage mode, regardless of the GLProfile...
final void restore(final GL gl)
Restores PACK and UNPACK pixel storage mode previously saved w/ saveAll(GL) or savePack(GL) and saveU...
final void setPackAlignment(final GL gl, final int packAlignment)
Sets the GL#GL_PACK_ALIGNMENT.
Image type classification.
static final String T_GIF
Constant which can be used as a file suffix to indicate a GIF stream, value {@value}.
static final String T_TGA
Constant which can be used as a file suffix to indicate a Targa stream, value {@value}.
static final String T_SGI_RGB
Constant which can be used as a file suffix to indicate an SGI RGB stream, value {@value}.
static final String T_PPM
Constant which can be used as a file suffix to indicate a PAM stream, NetPbm magic 6 - binary RGB.
static final String T_PNG
Constant which can be used as a file suffix to indicate a PNG stream, value {@value}.
static final String T_TIFF
Constant which can be used as a file suffix to indicate a TIFF stream, value {@value}.
static final String T_PAM
Constant which can be used as a file suffix to indicate a Portable Arbitrary Map stream,...
static final String T_DDS
Constant which can be used as a file suffix to indicate a DirectDraw Surface stream,...
static final String T_JPG
Constant which can be used as a file suffix to indicate a JPEG stream, value {@value}.
Represents the data for an OpenGL texture.
GLPixelAttributes getPixelAttributes()
Returns the intended OpenGL GLPixelAttributes of the texture data, i.e.
void flush()
Flushes resources associated with this TextureData by calling Flusher.flush().
int getPixelFormat()
Returns the intended OpenGL pixel format of the texture data using getPixelAttributes().
static TextureData newTextureData(final GLProfile glp, final InputStream stream, final boolean mipmap, final String fileSuffix)
Creates a TextureData from the given stream.
static final String TGA
Constant which can be used as a file suffix to indicate a Targa file, value {@value}.
static final String PAM
Constant which can be used as a file suffix to indicate a PAM file, NetPbm magic 7 - binary RGB and R...
static final String DDS
Constant which can be used as a file suffix to indicate a DirectDraw Surface file,...
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
static boolean isTexRectEnabled()
Indicates whether the GL_ARB_texture_rectangle extension is allowed to be used for non-power-of-two t...
static Texture newTexture(final GL gl, final TextureData data)
Creates an OpenGL texture object from the specified TextureData using the given OpenGL context.
static final String SGI
Constant which can be used as a file suffix to indicate an SGI RGB file, value {@value}.
static TextureData newTextureData(final GLProfile glp, final File file, final int internalFormat, final int pixelFormat, final boolean mipmap, String fileSuffix)
Creates a TextureData from the given file, using the specified OpenGL internal format and pixel forma...
static void addTextureWriter(final TextureWriter writer)
Adds a TextureWriter to support writing of a new file format.
static Texture newTexture(final File file, final boolean mipmap)
Creates an OpenGL texture object from the specified file using the current OpenGL context.
static TextureData newTextureData(final GLProfile glp, final URL url, final int internalFormat, final int pixelFormat, final boolean mipmap, String fileSuffix)
Creates a TextureData from the given URL, using the specified OpenGL internal format and pixel format...
static Texture newTexture(final InputStream stream, final boolean mipmap, final String fileSuffix)
Creates an OpenGL texture object from the specified stream using the current OpenGL context.
static Texture newTexture(final URL url, final boolean mipmap, String fileSuffix)
Creates an OpenGL texture object from the specified URL using the current OpenGL context.
static void write(final TextureData data, final File file)
static Texture newTexture(final int target)
Creates an OpenGL texture object associated with the given OpenGL texture target.
static void setTexRectEnabled(final boolean enabled)
Toggles the use of the GL_ARB_texture_rectangle extension by the TextureIO classes.
static final String PPM
Constant which can be used as a file suffix to indicate a PAM file, NetPbm magic 6 - binary RGB.
static final String GIF
Constant which can be used as a file suffix to indicate a GIF file, value {@value}.
static void addTextureProvider(final TextureProvider provider)
Adds a TextureProvider to support reading of a new file format.
static TextureData newTextureData(final GLProfile glp, final File file, final boolean mipmap, String fileSuffix)
Creates a TextureData from the given file.
static TextureData newTextureData(final GLProfile glp, final URL url, final boolean mipmap, String fileSuffix)
Creates a TextureData from the given URL.
static final String JPG
Constant which can be used as a file suffix to indicate a JPEG file, value {@value}.
static final String TIFF
Constant which can be used as a file suffix to indicate a TIFF file, value {@value}.
static final String SGI_RGB
Constant which can be used as a file suffix to indicate an SGI RGB file, value {@value}.
static Texture newTexture(final TextureData data)
Creates an OpenGL texture object from the specified TextureData using the current OpenGL context.
static void write(final Texture texture, final File file)
Writes the given texture to a file.
static TextureData newTextureData(final GLProfile glp, final InputStream stream, final int internalFormat, final int pixelFormat, final boolean mipmap, final String fileSuffix)
Creates a TextureData from the given stream, using the specified OpenGL internal format and pixel for...
Represents an OpenGL texture object.
static final int GL_TEXTURE_HEIGHT
GL_ES_VERSION_3_1, GL_VERSION_1_1, GL_VERSION_1_0, GL_QCOM_extended_get Alias for: GL_TEXTURE_HEIGHT_...
static final int GL_TEXTURE_WIDTH
GL_ES_VERSION_3_1, GL_VERSION_1_1, GL_VERSION_1_0, GL_QCOM_extended_get Alias for: GL_TEXTURE_WIDTH_Q...
static final int GL_TEXTURE_INTERNAL_FORMAT
GL_ES_VERSION_3_1, GL_VERSION_1_1, GL_QCOM_extended_get Alias for: GL_TEXTURE_INTERNAL_FORMAT_QCOM D...
void glGetTexImage(int target, int level, int format, int type, Buffer pixels)
Entry point to C language function: void {@native glGetTexImage}(GLenum target, GLint level,...
static final int GL_TEXTURE_COMPRESSED_IMAGE_SIZE
GL_VERSION_1_3, GL_ARB_texture_compression Alias for: GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB Define "G...
void glGetCompressedTexImage(int target, int level, Buffer img)
Entry point to C language function: void {@native glGetCompressedTexImage}(GLenum target,...
static final int GL_ABGR_EXT
GL_EXT_abgr Define "GL_ABGR_EXT" with expression '0x8000', CType: int
static final int GL_TEXTURE_BORDER
GL_VERSION_1_0 Define "GL_TEXTURE_BORDER" with expression '0x1005', CType: int
boolean isGL2GL3()
Indicates whether this GL object conforms to a GL2GL3 compatible profile.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
GL2GL3 getGL2GL3()
Casts this object to the GL2GL3 interface.
static final int GL_RGB8
GL_ES_VERSION_3_0, GL_VERSION_1_1, GL_EXT_texture, GL_OES_rgb8_rgba8, GL_OES_required_internalformat ...
static final int GL_BGRA
GL_VERSION_1_2, GL_IMG_read_format, GL_APPLE_texture_format_BGRA8888, GL_EXT_texture_format_BGRA8888,...
static final int GL_RGB
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RGB" with expression ...
static final int GL_TEXTURE_2D
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_2D" with expr...
static final int GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
GL_EXT_texture_compression_s3tc Define "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT" with expression '0x83F3',...
static final int GL_RGBA8
GL_ES_VERSION_3_0, GL_VERSION_1_1, GL_OES_rgb8_rgba8, GL_OES_required_internalformat,...
static final int GL_BGR
GL_VERSION_1_2, GL_EXT_bgra Alias for: GL_BGR_EXT Define "GL_BGR" with expression '0x80E0',...
static final int GL_RGBA
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RGBA" with expression...
static final int GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
GL_EXT_texture_compression_s3tc Define "GL_COMPRESSED_RGBA_S3TC_DXT3_EXT" with expression '0x83F2',...
static final int GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
GL_EXT_texture_compression_s3tc, GL_EXT_texture_compression_dxt1 Define "GL_COMPRESSED_RGBA_S3TC_DXT1...
static final int GL_UNSIGNED_BYTE
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_UNSIGNED_BYTE" with e...
static final int GL_COMPRESSED_RGB_S3TC_DXT1_EXT
GL_EXT_texture_compression_s3tc, GL_EXT_texture_compression_dxt1 Define "GL_COMPRESSED_RGB_S3TC_DXT1_...
Plug-in interface to TextureIO to support reading OpenGL textures from new file formats.
TextureData newTextureData(GLProfile glp, InputStream stream, int internalFormat, int pixelFormat, boolean mipmap, String fileSuffix)
Produces a TextureData object from a stream, or returns null if the file format was not supported by ...
ImageType[] getImageTypes()
Returns the known supported ImageTypes, or null if unknown.
Plug-in interface to TextureIO to support writing OpenGL textures to new file formats.
boolean write(File file, TextureData data)
Writes the given TextureData to the passed file.