JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
AWTTextureIO.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistribution of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * Neither the name of Sun Microsystems, Inc. or the names of
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * This software is provided "AS IS," without a warranty of any kind. ALL
20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
23 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
24 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
25 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
26 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
27 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
28 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
29 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
30 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31 *
32 * You acknowledge that this software is not designed or intended for use
33 * in the design, construction, operation or maintenance of any nuclear
34 * facility.
35 *
36 * Sun gratefully acknowledges that this software was originally authored
37 * and developed by Kenneth Bradley Russell and Christopher John Kline.
38 */
39
40package com.jogamp.opengl.util.texture.awt;
41
42import java.awt.image.*;
43
44import com.jogamp.opengl.*;
45import com.jogamp.opengl.util.texture.*;
46
47public class AWTTextureIO extends TextureIO {
48 /**
49 * Creates a TextureData from the given BufferedImage. Does no
50 * OpenGL work.
51 * We assume a desktop GLProfile GL2GL3, otherwise use the other factory.
52 *
53 * @param glp the OpenGL Profile this texture data should be
54 * created for.
55 * @param image the BufferedImage containing the texture data
56 * @param mipmap whether mipmaps should be produced for this
57 * texture by autogenerating them
58 * @return the texture data from the image
59 *
60 * @see #newTextureData(GLProfile, BufferedImage, boolean)
61 */
62 public static TextureData newTextureData(final GLProfile glp, final BufferedImage image,
63 final boolean mipmap) {
64 return newTextureDataImpl(glp, image, 0, 0, mipmap);
65 }
66
67 /**
68 * Creates a TextureData from the given BufferedImage, using the
69 * specified OpenGL internal format and pixel format for the texture
70 * which will eventually result. The internalFormat and pixelFormat
71 * must be specified and may not be zero; to use default values, use
72 * the variant of this method which does not take these
73 * arguments. Does no OpenGL work.
74 *
75 * @param glp the OpenGL Profile this texture data should be
76 * created for.
77 * @param image the BufferedImage containing the texture data
78 * @param internalFormat the OpenGL internal format of the texture
79 * which will eventually result from the TextureData
80 * @param pixelFormat the OpenGL pixel format of the texture
81 * which will eventually result from the TextureData
82 * @param mipmap whether mipmaps should be produced for this
83 * texture either by autogenerating them or
84 * reading them from the file. Some file formats
85 * support multiple mipmaps in a single file in
86 * which case those mipmaps will be used rather
87 * than generating them.
88 * @return the texture data from the image
89 * @throws IllegalArgumentException if either internalFormat or
90 * pixelFormat was 0
91 */
92 public static TextureData newTextureData(final GLProfile glp, final BufferedImage image,
93 final int internalFormat,
94 final int pixelFormat,
95 final boolean mipmap) throws IllegalArgumentException {
96 if ((internalFormat == 0) || (pixelFormat == 0)) {
97 throw new IllegalArgumentException("internalFormat and pixelFormat must be non-zero");
98 }
99
100 return newTextureDataImpl(glp, image, internalFormat, pixelFormat, mipmap);
101 }
102
103 /**
104 * Creates an OpenGL texture object from the specified BufferedImage
105 * using the current OpenGL context.
106 *
107 * @param glp the OpenGL Profile this texture data should be
108 * created for.
109 * @param image the BufferedImage from which to read the texture data
110 * @param mipmap whether mipmaps should be produced for this
111 * texture by autogenerating them
112 * @throws GLException if no OpenGL context is current or if an
113 * OpenGL error occurred
114 */
115 public static Texture newTexture(final GLProfile glp, final BufferedImage image, final boolean mipmap) throws GLException {
116 final TextureData data = newTextureData(glp, image, mipmap);
117 final Texture texture = newTexture(data);
118 data.flush();
119 return texture;
120 }
121
122 private static TextureData newTextureDataImpl(final GLProfile glp,
123 final BufferedImage image,
124 final int internalFormat,
125 final int pixelFormat,
126 final boolean mipmap) {
127 return new AWTTextureData(glp, internalFormat, pixelFormat, mipmap, image);
128 }
129}
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
Represents the data for an OpenGL texture.
void flush()
Flushes resources associated with this TextureData by calling Flusher.flush().
Represents an OpenGL texture object.
Definition: Texture.java:173
static Texture newTexture(final GLProfile glp, final BufferedImage image, final boolean mipmap)
Creates an OpenGL texture object from the specified BufferedImage using the current OpenGL context.
static TextureData newTextureData(final GLProfile glp, final BufferedImage image, final boolean mipmap)
Creates a TextureData from the given BufferedImage.
static TextureData newTextureData(final GLProfile glp, final BufferedImage image, final int internalFormat, final int pixelFormat, final boolean mipmap)
Creates a TextureData from the given BufferedImage, using the specified OpenGL internal format and pi...