public class OGLUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_COMBINE_ALPHA |
static int |
DEFAULT_COMBINE_RGB |
protected static Vec4 |
DEFAULT_LIGHT_DIRECTION |
static int |
DEFAULT_SRC0_ALPHA |
static int |
DEFAULT_SRC0_RGB |
static int |
DEFAULT_SRC1_ALPHA |
static int |
DEFAULT_SRC1_RGB |
static int |
DEFAULT_SRC2_ALPHA |
static int |
DEFAULT_SRC2_RGB |
static int |
DEFAULT_TEX_ENV_MODE |
static int |
DEFAULT_TEXTURE_GEN_MODE |
static double[] |
DEFAULT_TEXTURE_GEN_S_OBJECT_PLANE |
static double[] |
DEFAULT_TEXTURE_GEN_T_OBJECT_PLANE |
protected static java.lang.String |
GL_EXT_BLEND_FUNC_SEPARATE |
Constructor and Description |
---|
OGLUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
applyBlending(com.jogamp.opengl.GL2 gl,
boolean havePremultipliedColors)
Sets the GL blending state according to the specified color mode.
|
static void |
applyColor(com.jogamp.opengl.GL2 gl,
java.awt.Color color,
boolean premultiplyColors)
Sets the GL color state to the specified
Color , and with the specified color mode. |
static void |
applyColor(com.jogamp.opengl.GL2 gl,
java.awt.Color color,
double opacity,
boolean premultiplyColors)
Sets the GL color state to the specified
Color and opacity, and with the specified color mode. |
static void |
applyLightingDirectionalFromViewer(com.jogamp.opengl.GL2 gl,
int light,
Vec4 direction)
Sets the GL lighting state to a white light originating from the eye position and pointed in the specified
direction, in model coordinates.
|
static int |
computeTexturePixelFormat(int internalFormat)
Returns an OpenGL pixel format corresponding to the specified texture internal format.
|
static int |
estimateTextureMemorySize(int internalFormat,
int width,
int height,
boolean includeMipmaps)
Returns an OpenGL pixel format corresponding to the specified texture internal format.
|
static com.jogamp.opengl.util.texture.TextureData |
newTextureData(com.jogamp.opengl.GLProfile glp,
java.io.File file,
boolean useMipMaps)
Creates TextureData from a File.
|
static com.jogamp.opengl.util.texture.TextureData |
newTextureData(com.jogamp.opengl.GLProfile glp,
java.io.InputStream stream,
boolean useMipMaps)
Creates TextureData from an InputStream.
|
static com.jogamp.opengl.util.texture.TextureData |
newTextureData(com.jogamp.opengl.GLProfile glp,
java.net.URL url,
boolean useMipMaps)
Creates TextureData from the given URL.
|
public static final int DEFAULT_COMBINE_ALPHA
public static final int DEFAULT_COMBINE_RGB
protected static final Vec4 DEFAULT_LIGHT_DIRECTION
public static final int DEFAULT_SRC0_ALPHA
public static final int DEFAULT_SRC0_RGB
public static final int DEFAULT_SRC1_ALPHA
public static final int DEFAULT_SRC1_RGB
public static final int DEFAULT_SRC2_ALPHA
public static final int DEFAULT_SRC2_RGB
public static final int DEFAULT_TEX_ENV_MODE
public static final int DEFAULT_TEXTURE_GEN_MODE
public static final double[] DEFAULT_TEXTURE_GEN_S_OBJECT_PLANE
public static final double[] DEFAULT_TEXTURE_GEN_T_OBJECT_PLANE
protected static final java.lang.String GL_EXT_BLEND_FUNC_SEPARATE
public static void applyBlending(com.jogamp.opengl.GL2 gl, boolean havePremultipliedColors)
havePremultipliedColors
is
true, this applies a blending function appropriate for colors premultiplied by the alpha component. Otherwise,
this applies a blending function appropriate for non-premultiplied colors.gl
- the GL context.havePremultipliedColors
- true to configure blending for colors premultiplied by the alpha components, and
false to configure blending for non-premultiplied colors.java.lang.IllegalArgumentException
- if the GL is null.public static void applyColor(com.jogamp.opengl.GL2 gl, java.awt.Color color, boolean premultiplyColors)
Color
, and with the specified color mode. If
premultiplyColors
is true, this premultipies the Red, Green, and Blue color values by the Alpha
value. Otherwise, this does not modify the Red, Green, and Blue color values.gl
- the GL context.color
- the Red, Green, Blue, and Alpha values to set.premultiplyColors
- true to premultiply the Red, Green and Blue color values by the Alpha value, false to
leave the Red, Green, and Blue values unmodified.java.lang.IllegalArgumentException
- if the GL is null, if the Color is null, if the opacity is less than 0, or if
the opacity is greater than 1.public static void applyColor(com.jogamp.opengl.GL2 gl, java.awt.Color color, double opacity, boolean premultiplyColors)
Color
and opacity, and with the specified color mode.
If premultiplyColors
is true, this premultipies the Red, Green, and Blue color values by the opacity
value. Otherwise, this does not modify the Red, Green, and Blue color values.gl
- the GL context.color
- the Red, Green, and Blue values to set.opacity
- the opacity to set.premultiplyColors
- true to premultiply the Red, Green, and Blue color values by the opacity value, false to
leave the Red, Green, and Blue values unmodified.java.lang.IllegalArgumentException
- if the GL is null, if the Color is null, if the opacity is less than 0, or if
the opacity is greater than 1.public static void applyLightingDirectionalFromViewer(com.jogamp.opengl.GL2 gl, int light, Vec4 direction)
gl
- the GL context.light
- the GL light name to set.direction
- the light direction in model coordinates, may be null.java.lang.IllegalArgumentException
- if the GL is null.public static int computeTexturePixelFormat(int internalFormat)
Internal Format | Pixel Format | |
---|---|---|
GL2.GL_ALPHA | GL2.GL_ALPHA | |
GL2.GL_ALPHA4 | GL2.GL_ALPHA | |
GL2.GL_ALPHA8 | GL2.GL_ALPHA | |
GL2.GL_ALPHA12 | GL2.GL_ALPHA | |
GL2.GL_ALPHA16 | GL2.GL_ALPHA | |
GL2.GL_COMPRESSED_ALPHA | GL2.GL_ALPHA | |
GL2.GL_COMPRESSED_LUMINANCE | GL2.GL_LUMINANCE | |
GL2.GL_COMPRESSED_LUMINANCE_ALPHA | GL2.GL_LUMINANCE_ALPHA | |
GL2.GL_COMPRESSED_INTENSITY | GL2.GL_RED | |
GL2.GL_COMPRESSED_RGB | GL2.GL_RGB | |
GL2.GL_COMPRESSED_RGBA | GL2.GL_RGBA | |
GL2.GL_DEPTH_COMPONENT | GL2.GL_RED | |
GL2.GL_DEPTH_COMPONENT16 | GL2.GL_RED | |
GL2.GL_DEPTH_COMPONENT24 | GL2.GL_RED | |
GL2.GL_DEPTH_COMPONENT32 | GL2.GL_RED | |
GL2.GL_LUMINANCE | GL2.GL_LUMINANCE | |
GL2.GL_LUMINANCE4 | GL2.GL_LUMINANCE | |
GL2.GL_LUMINANCE8 | GL2.GL_LUMINANCE | |
GL2.GL_LUMINANCE12 | GL2.GL_LUMINANCE | |
GL2.GL_LUMINANCE16 | GL2.GL_LUMINANCE | |
GL2.GL_LUMINANCE_ALPHA | GL2.GL_LUMINANCE_ALPHA | |
GL2.GL_LUMINANCE4_ALPHA4 | GL2.GL_LUMINANCE_ALPHA | |
GL2.GL_LUMINANCE6_ALPHA2 | GL2.GL_LUMINANCE_ALPHA | |
GL2.GL_LUMINANCE8_ALPHA8 | GL2.GL_LUMINANCE_ALPHA | |
GL2.GL_LUMINANCE12_ALPHA4 | GL2.GL_LUMINANCE_ALPHA | |
GL2.GL_LUMINANCE12_ALPHA12 | GL2.GL_LUMINANCE_ALPHA | |
GL2.GL_LUMINANCE16_ALPHA16 | GL2.GL_LUMINANCE_ALPHA | |
GL2.GL_INTENSITY | GL2.GL_RED | |
GL2.GL_INTENSITY4 | GL2.GL_RED | |
GL2.GL_INTENSITY8 | GL2.GL_RED | |
GL2.GL_INTENSITY12 | GL2.GL_RED | |
GL2.GL_INTENSITY16 | GL2.GL_RED | |
GL2.GL_R3_G3_B2 | GL2.GL_RGB | |
GL2.GL_RGB | GL2.GL_RGB | |
GL2.GL_RGB4 | GL2.GL_RGB | |
GL2.GL_RGB5 | GL2.GL_RGB | |
GL2.GL_RGB8 | GL2.GL_RGB | |
GL2.GL_RGB10 | GL2.GL_RGB | |
GL2.GL_RGB12 | GL2.GL_RGB | |
GL2.GL_RGB16 | GL2.GL_RGB | |
GL2.GL_RGBA | GL2.GL_RGBA | |
GL2.GL_RGBA2 | GL2.GL_RGBA | |
GL2.GL_RGBA4 | GL2.GL_RGBA | |
GL2.GL_RGB5_A1 | GL2.GL_RGBA | |
GL2.GL_RGBA8 | GL2.GL_RGBA | |
GL2.GL_RGB10_A2 | GL2.GL_RGBA | |
GL2.GL_RGBA12 | GL2.GL_RGBA | |
GL2.GL_RGBA16 | GL2.GL_RGBA | |
GL2.GL_SLUMINANCE | GL2.GL_LUMINANCE | |
GL2.GL_SLUMINANCE8 | GL2.GL_LUMINANCE | |
GL2.GL_SLUMINANCE_ALPHA | GL2.GL_LUMINANCE_ALPHA | |
GL2.GL_SLUMINANCE8_ALPHA8 | GL2.GL_LUMINANCE_ALPHA | |
GL2.GL_SRGB | GL2.GL_RGB | |
GL2.GL_SRGB8 | GL2.GL_RGB | |
GL2.GL_SRGB_ALPHA | GL2.GL_RGBA | |
GL2.GL_SRGB8_ALPHA8 | GL2.GL_RGBA |
This returns 0 if the internal format is not one of the recognized types.
internalFormat
- the OpenGL texture internal format.public static int estimateTextureMemorySize(int internalFormat, int width, int height, boolean includeMipmaps)
Internal Format | Estimated Bits Per Pixel | |
---|---|---|
GL2.GL_ALPHA | 8 | |
GL2.GL_ALPHA4 | 4 | |
GL2.GL_ALPHA8 | 8 | |
GL2.GL_ALPHA12 | 12 | |
GL2.GL_ALPHA16 | 16 | |
GL2.GL_COMPRESSED_ALPHA | 0 | |
GL2.GL_COMPRESSED_LUMINANCE | 0 | |
GL2.GL_COMPRESSED_LUMINANCE_ALPHA | 0 | |
GL2.GL_COMPRESSED_INTENSITY | 0 | |
GL2.GL_COMPRESSED_RGB | 0 | |
GL2.GL_COMPRESSED_RGBA | 0 | |
GL2.GL_DEPTH_COMPONENT | 24 | |
GL2.GL_DEPTH_COMPONENT16 | 16 | |
GL2.GL_DEPTH_COMPONENT24 | 24 | |
GL2.GL_DEPTH_COMPONENT32 | 32 | |
GL2.GL_LUMINANCE | 8 | |
GL2.GL_LUMINANCE4 | 4 | |
GL2.GL_LUMINANCE8 | 8 | |
GL2.GL_LUMINANCE12 | 12 | |
GL2.GL_LUMINANCE16 | 16 | |
GL2.GL_LUMINANCE_ALPHA | 16 | |
GL2.GL_LUMINANCE4_ALPHA4 | 8 | |
GL2.GL_LUMINANCE6_ALPHA2 | 8 | |
GL2.GL_LUMINANCE8_ALPHA8 | 16 | |
GL2.GL_LUMINANCE12_ALPHA4 | 16 | |
GL2.GL_LUMINANCE12_ALPHA12 | 24 | |
GL2.GL_LUMINANCE16_ALPHA16 | 32 | |
GL2.GL_INTENSITY | 8 | |
GL2.GL_INTENSITY4 | 4 | |
GL2.GL_INTENSITY8 | 8 | |
GL2.GL_INTENSITY12 | 12 | |
GL2.GL_INTENSITY16 | 16 | |
GL2.GL_R3_G3_B2 | 8 | |
GL2.GL_RGB | 24 | |
GL2.GL_RGB4 | 12 | |
GL2.GL_RGB5 | 16 (assume the driver allocates 16 bits per pixel) | |
GL2.GL_RGB8 | 24 | |
GL2.GL_RGB10 | 32 (assume the driver allocates 32 bits per pixel) | |
GL2.GL_RGB12 | 36 | |
GL2.GL_RGB16 | 48 | |
GL2.GL_RGBA | 32 | |
GL2.GL_RGBA2 | 8 | |
GL2.GL_RGBA4 | 16 | |
GL2.GL_RGB5_A1 | 16 | |
GL2.GL_RGBA8 | 32 | |
GL2.GL_RGB10_A2 | 32 | |
GL2.GL_RGBA12 | 48 | |
GL2.GL_RGBA16 | 64 | |
GL2.GL_SLUMINANCE | 8 | |
GL2.GL_SLUMINANCE8 | 8 | |
GL2.GL_SLUMINANCE_ALPHA | 16 | |
GL2.GL_SLUMINANCE8_ALPHA8 | 16 | |
GL2.GL_SRGB | 24 | |
GL2.GL_SRGB8 | 24 | |
GL2.GL_SRGB_ALPHA | 32 | |
GL2.GL_SRGB8_ALPHA8 | 32 |
The returned estimate assumes that the driver provides does not convert the formats to another supported, such
converting as GL2.GL_ALPHA4
to GL2.GL_ALPHA8
. This returns 0 if the internal format is
not one of the recognized types. This does not attempt to estimate a memory size for compressed internal
formats.
internalFormat
- the OpenGL texture internal format.width
- the texture width, in pixels.height
- the texture height, in pixels.includeMipmaps
- true to include the texture's mip map data in the estimated size; false otherwise.java.lang.IllegalArgumentException
- if either the width or height is less than or equal to zero.public static com.jogamp.opengl.util.texture.TextureData newTextureData(com.jogamp.opengl.GLProfile glp, java.io.File file, boolean useMipMaps) throws java.io.IOException
glp
- the OpenGL Profile this texture data should be created for.file
- the file from which to read the texture datauseMipMaps
- whether mipmaps should be produced for this texture either by auto-generating 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.java.io.IOException
- if an error occurred while reading the URLpublic static com.jogamp.opengl.util.texture.TextureData newTextureData(com.jogamp.opengl.GLProfile glp, java.io.InputStream stream, boolean useMipMaps) throws java.io.IOException
glp
- the OpenGL Profile this texture data should be created for.stream
- the stream from which to read the texture datauseMipMaps
- whether mipmaps should be produced for this texture either by auto-generating 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.java.io.IOException
- if an error occurred while reading the URLpublic static com.jogamp.opengl.util.texture.TextureData newTextureData(com.jogamp.opengl.GLProfile glp, java.net.URL url, boolean useMipMaps) throws java.io.IOException
glp
- the OpenGL Profile this texture data should be created for.url
- the URL from which to read the texture datauseMipMaps
- whether mipmaps should be produced for this texture either by auto-generating 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.java.io.IOException
- if an error occurred while reading the URL