NASA World Wind

gov.nasa.worldwind.util
Class OGLUtil

java.lang.Object
  extended by gov.nasa.worldwind.util.OGLUtil

public class OGLUtil
extends Object

A collection of OpenGL utility methods, all static.


Field Summary
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 String GL_EXT_BLEND_FUNC_SEPARATE
           
 
Constructor Summary
OGLUtil()
           
 
Method Summary
static void applyBlending(GL2 gl, boolean havePremultipliedColors)
          Sets the GL blending state according to the specified color mode.
static void applyColor(GL2 gl, Color color, boolean premultiplyColors)
          Sets the GL color state to the specified Color, and with the specified color mode.
static void applyColor(GL2 gl, 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(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 TextureData newTextureData(GLProfile glp, File file, boolean useMipMaps)
          Creates TextureData from a File.
static TextureData newTextureData(GLProfile glp, InputStream stream, boolean useMipMaps)
          Creates TextureData from an InputStream.
static TextureData newTextureData(GLProfile glp, URL url, boolean useMipMaps)
          Creates TextureData from the given URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COMBINE_ALPHA

public static final int DEFAULT_COMBINE_ALPHA
See Also:
Constant Field Values

DEFAULT_COMBINE_RGB

public static final int DEFAULT_COMBINE_RGB
See Also:
Constant Field Values

DEFAULT_LIGHT_DIRECTION

protected static final Vec4 DEFAULT_LIGHT_DIRECTION

DEFAULT_SRC0_ALPHA

public static final int DEFAULT_SRC0_ALPHA
See Also:
Constant Field Values

DEFAULT_SRC0_RGB

public static final int DEFAULT_SRC0_RGB
See Also:
Constant Field Values

DEFAULT_SRC1_ALPHA

public static final int DEFAULT_SRC1_ALPHA
See Also:
Constant Field Values

DEFAULT_SRC1_RGB

public static final int DEFAULT_SRC1_RGB
See Also:
Constant Field Values

DEFAULT_SRC2_ALPHA

public static final int DEFAULT_SRC2_ALPHA
See Also:
Constant Field Values

DEFAULT_SRC2_RGB

public static final int DEFAULT_SRC2_RGB
See Also:
Constant Field Values

DEFAULT_TEX_ENV_MODE

public static final int DEFAULT_TEX_ENV_MODE
See Also:
Constant Field Values

DEFAULT_TEXTURE_GEN_MODE

public static final int DEFAULT_TEXTURE_GEN_MODE
See Also:
Constant Field Values

DEFAULT_TEXTURE_GEN_S_OBJECT_PLANE

public static final double[] DEFAULT_TEXTURE_GEN_S_OBJECT_PLANE

DEFAULT_TEXTURE_GEN_T_OBJECT_PLANE

public static final double[] DEFAULT_TEXTURE_GEN_T_OBJECT_PLANE

GL_EXT_BLEND_FUNC_SEPARATE

protected static final String GL_EXT_BLEND_FUNC_SEPARATE
See Also:
Constant Field Values
Constructor Detail

OGLUtil

public OGLUtil()
Method Detail

applyBlending

public static void applyBlending(GL2 gl,
                                 boolean havePremultipliedColors)
Sets the GL blending state according to the specified color mode. If 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.

Parameters:
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.
Throws:
IllegalArgumentException - if the GL is null.

applyColor

public static void applyColor(GL2 gl,
                              Color color,
                              boolean premultiplyColors)
Sets the GL color state to the specified 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.

Parameters:
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.
Throws:
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.

applyColor

public static void applyColor(GL2 gl,
                              Color color,
                              double opacity,
                              boolean premultiplyColors)
Sets the GL color state to the specified 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.

Parameters:
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.
Throws:
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.

applyLightingDirectionalFromViewer

public static void applyLightingDirectionalFromViewer(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. The light direction is always relative to the current eye point and viewer direction. If the direction is null, this the light direction defaults to (0, 0, -1), which points directly along the forward vector form the eye point

Parameters:
gl - the GL context.
light - the GL light name to set.
direction - the light direction in model coordinates, may be null.
Throws:
IllegalArgumentException - if the GL is null.

computeTexturePixelFormat

public static int computeTexturePixelFormat(int internalFormat)
Returns an OpenGL pixel format corresponding to the specified texture internal format. This maps internal format to pixel format as follows:

This returns 0 if the internal format is not one of the recognized types.

Parameters:
internalFormat - the OpenGL texture internal format.
Returns:
a pixel format corresponding to the texture internal format, or 0 if the internal format is not recognized.

estimateTextureMemorySize

public static int estimateTextureMemorySize(int internalFormat,
                                            int width,
                                            int height,
                                            boolean includeMipmaps)
Returns an OpenGL pixel format corresponding to the specified texture internal format. This maps internal format to pixel format as follows:
Internal FormatPixel Format
GL2.GL_ALPHAGL2.GL_ALPHA
GL2.GL_ALPHA4GL2.GL_ALPHA
GL2.GL_ALPHA8GL2.GL_ALPHA
GL2.GL_ALPHA12GL2.GL_ALPHA
GL2.GL_ALPHA16GL2.GL_ALPHA
GL2.GL_COMPRESSED_ALPHAGL2.GL_ALPHA
GL2.GL_COMPRESSED_LUMINANCEGL2.GL_LUMINANCE
GL2.GL_COMPRESSED_LUMINANCE_ALPHAGL2.GL_LUMINANCE_ALPHA
GL2.GL_COMPRESSED_INTENSITYGL2.GL_RED
GL2.GL_COMPRESSED_RGBGL2.GL_RGB
GL2.GL_COMPRESSED_RGBAGL2.GL_RGBA
GL2.GL_DEPTH_COMPONENTGL2.GL_RED
GL2.GL_DEPTH_COMPONENT16GL2.GL_RED
GL2.GL_DEPTH_COMPONENT24GL2.GL_RED
GL2.GL_DEPTH_COMPONENT32GL2.GL_RED
GL2.GL_LUMINANCEGL2.GL_LUMINANCE
GL2.GL_LUMINANCE4GL2.GL_LUMINANCE
GL2.GL_LUMINANCE8GL2.GL_LUMINANCE
GL2.GL_LUMINANCE12GL2.GL_LUMINANCE
GL2.GL_LUMINANCE16GL2.GL_LUMINANCE
GL2.GL_LUMINANCE_ALPHAGL2.GL_LUMINANCE_ALPHA
GL2.GL_LUMINANCE4_ALPHA4GL2.GL_LUMINANCE_ALPHA
GL2.GL_LUMINANCE6_ALPHA2GL2.GL_LUMINANCE_ALPHA
GL2.GL_LUMINANCE8_ALPHA8GL2.GL_LUMINANCE_ALPHA
GL2.GL_LUMINANCE12_ALPHA4GL2.GL_LUMINANCE_ALPHA
GL2.GL_LUMINANCE12_ALPHA12GL2.GL_LUMINANCE_ALPHA
GL2.GL_LUMINANCE16_ALPHA16GL2.GL_LUMINANCE_ALPHA
GL2.GL_INTENSITYGL2.GL_RED
GL2.GL_INTENSITY4GL2.GL_RED
GL2.GL_INTENSITY8GL2.GL_RED
GL2.GL_INTENSITY12GL2.GL_RED
GL2.GL_INTENSITY16GL2.GL_RED
GL2.GL_R3_G3_B2GL2.GL_RGB
GL2.GL_RGBGL2.GL_RGB
GL2.GL_RGB4GL2.GL_RGB
GL2.GL_RGB5GL2.GL_RGB
GL2.GL_RGB8GL2.GL_RGB
GL2.GL_RGB10GL2.GL_RGB
GL2.GL_RGB12GL2.GL_RGB
GL2.GL_RGB16GL2.GL_RGB
GL2.GL_RGBAGL2.GL_RGBA
GL2.GL_RGBA2GL2.GL_RGBA
GL2.GL_RGBA4GL2.GL_RGBA
GL2.GL_RGB5_A1GL2.GL_RGBA
GL2.GL_RGBA8GL2.GL_RGBA
GL2.GL_RGB10_A2GL2.GL_RGBA
GL2.GL_RGBA12GL2.GL_RGBA
GL2.GL_RGBA16GL2.GL_RGBA
GL2.GL_SLUMINANCEGL2.GL_LUMINANCE
GL2.GL_SLUMINANCE8GL2.GL_LUMINANCE
GL2.GL_SLUMINANCE_ALPHAGL2.GL_LUMINANCE_ALPHA
GL2.GL_SLUMINANCE8_ALPHA8GL2.GL_LUMINANCE_ALPHA
GL2.GL_SRGBGL2.GL_RGB
GL2.GL_SRGB8GL2.GL_RGB
GL2.GL_SRGB_ALPHAGL2.GL_RGBA
GL2.GL_SRGB8_ALPHA8GL2.GL_RGBA

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.

Parameters:
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.
Returns:
a pixel format corresponding to the texture internal format, or 0 if the internal format is not recognized.
Throws:
IllegalArgumentException - if either the width or height is less than or equal to zero.

newTextureData

public static TextureData newTextureData(GLProfile glp,
                                         File file,
                                         boolean useMipMaps)
                                  throws IOException
Creates TextureData from a File. Does no OpenGL work.

Parameters:
glp - the OpenGL Profile this texture data should be created for.
file - the file from which to read the texture data
useMipMaps - 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.
Returns:
the texture data from the URL, or null if none of the registered texture providers could read the URL
Throws:
IOException - if an error occurred while reading the URL

newTextureData

public static TextureData newTextureData(GLProfile glp,
                                         InputStream stream,
                                         boolean useMipMaps)
                                  throws IOException
Creates TextureData from an InputStream. Does no OpenGL work.

Parameters:
glp - the OpenGL Profile this texture data should be created for.
stream - the stream from which to read the texture data
useMipMaps - 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.
Returns:
the texture data from the URL, or null if none of the registered texture providers could read the URL
Throws:
IOException - if an error occurred while reading the URL

newTextureData

public static TextureData newTextureData(GLProfile glp,
                                         URL url,
                                         boolean useMipMaps)
                                  throws IOException
Creates TextureData from the given URL. Does no OpenGL work.

Parameters:
glp - the OpenGL Profile this texture data should be created for.
url - the URL from which to read the texture data
useMipMaps - 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.
Returns:
the texture data from the URL, or null if none of the registered texture providers could read the URL
Throws:
IOException - if an error occurred while reading the URL

Internal FormatEstimated Bits Per Pixel
GL2.GL_ALPHA8
GL2.GL_ALPHA44
GL2.GL_ALPHA88
GL2.GL_ALPHA1212
GL2.GL_ALPHA1616
GL2.GL_COMPRESSED_ALPHA0
GL2.GL_COMPRESSED_LUMINANCE0
GL2.GL_COMPRESSED_LUMINANCE_ALPHA0
GL2.GL_COMPRESSED_INTENSITY0
GL2.GL_COMPRESSED_RGB0
GL2.GL_COMPRESSED_RGBA0
GL2.GL_DEPTH_COMPONENT24
GL2.GL_DEPTH_COMPONENT1616
GL2.GL_DEPTH_COMPONENT2424
GL2.GL_DEPTH_COMPONENT3232
GL2.GL_LUMINANCE8
GL2.GL_LUMINANCE44
GL2.GL_LUMINANCE88
GL2.GL_LUMINANCE1212
GL2.GL_LUMINANCE1616
GL2.GL_LUMINANCE_ALPHA16
GL2.GL_LUMINANCE4_ALPHA48
GL2.GL_LUMINANCE6_ALPHA28
GL2.GL_LUMINANCE8_ALPHA816
GL2.GL_LUMINANCE12_ALPHA416
GL2.GL_LUMINANCE12_ALPHA1224
GL2.GL_LUMINANCE16_ALPHA1632
GL2.GL_INTENSITY8
GL2.GL_INTENSITY44
GL2.GL_INTENSITY88
GL2.GL_INTENSITY1212
GL2.GL_INTENSITY1616
GL2.GL_R3_G3_B28
GL2.GL_RGB24
GL2.GL_RGB412
GL2.GL_RGB516 (assume the driver allocates 16 bits per pixel)
GL2.GL_RGB824
GL2.GL_RGB1032 (assume the driver allocates 32 bits per pixel)
GL2.GL_RGB1236
GL2.GL_RGB1648
GL2.GL_RGBA32
GL2.GL_RGBA28
GL2.GL_RGBA416
GL2.GL_RGB5_A116
GL2.GL_RGBA832
GL2.GL_RGB10_A232
GL2.GL_RGBA1248
GL2.GL_RGBA1664
GL2.GL_SLUMINANCE8
GL2.GL_SLUMINANCE88
GL2.GL_SLUMINANCE_ALPHA16
GL2.GL_SLUMINANCE8_ALPHA816
GL2.GL_SRGB24
GL2.GL_SRGB824
GL2.GL_SRGB_ALPHA32
GL2.GL_SRGB8_ALPHA832
NASA World Wind