Package gov.nasa.worldwind.draw
Class DrawContext
- java.lang.Object
-
- gov.nasa.worldwind.draw.DrawContext
-
public class DrawContext extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description DrawableQueue
drawableQueue
DrawableQueue
drawableTerrain
Vec3
eyePoint
Matrix4
infiniteProjection
Matrix4
modelview
Matrix4
modelviewProjection
PickedObjectList
pickedObjects
boolean
pickMode
Vec2
pickPoint
Viewport
pickViewport
Matrix4
projection
Matrix4
screenProjection
Viewport
viewport
-
Constructor Summary
Constructors Constructor Description DrawContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activeTextureUnit(int textureUnit)
Specifies the OpenGL multitexture unit to make active.void
bindBuffer(int target, int bufferId)
Makes an OpenGL buffer object bound to a specified target buffer.void
bindFramebuffer(int framebufferId)
Makes an OpenGL framebuffer object active.void
bindTexture(int textureId)
Makes an OpenGL texture 2D object bound to the current multitexture unit.void
contextLost()
int
currentBuffer(int target)
Returns the name of the OpenGL buffer object bound to the specified target buffer.int
currentFramebuffer()
Returns the name of the OpenGL framebuffer object that is currently active.int
currentProgram()
Returns the name of the OpenGL program object that is currently active.int
currentTexture()
Returns the name of the OpenGL texture 2D object currently bound to the active multitexture unit.int
currentTexture(int textureUnit)
Returns the name of the OpenGL texture 2D object currently bound to the specified multitexture unit.int
currentTextureUnit()
Returns the OpenGL multitexture unit that is currently active.DrawableTerrain
getDrawableTerrain(int index)
int
getDrawableTerrainCount()
Drawable
peekDrawable()
Drawable
pollDrawable()
Color
readPixelColor(int x, int y, Color result)
Reads the fragment color at a screen point in the currently active OpenGL frame buffer.java.util.Set<Color>
readPixelColors(int x, int y, int width, int height)
Reads the unique fragment colors within a screen rectangle in the currently active OpenGL frame buffer.void
reset()
void
rewindDrawables()
java.nio.ByteBuffer
scratchBuffer(int capacity)
Returns a scratch NIO buffer suitable for use during drawing.Framebuffer
scratchFramebuffer()
Returns an OpenGL framebuffer object suitable for offscreen drawing.java.util.ArrayList<java.lang.Object>
scratchList()
Returns a scratch list suitable for accumulating entries during drawing.BufferObject
unitSquareBuffer()
Returns an OpenGL buffer object containing a unit square expressed as four vertices at (0, 1), (0, 0), (1, 1) and (1, 0).void
useProgram(int programId)
Makes an OpenGL program object active as part of current rendering state.
-
-
-
Field Detail
-
eyePoint
public Vec3 eyePoint
-
viewport
public final Viewport viewport
-
projection
public final Matrix4 projection
-
modelview
public final Matrix4 modelview
-
modelviewProjection
public final Matrix4 modelviewProjection
-
infiniteProjection
public final Matrix4 infiniteProjection
-
screenProjection
public final Matrix4 screenProjection
-
drawableQueue
public DrawableQueue drawableQueue
-
drawableTerrain
public DrawableQueue drawableTerrain
-
pickedObjects
public PickedObjectList pickedObjects
-
pickViewport
public Viewport pickViewport
-
pickPoint
public Vec2 pickPoint
-
pickMode
public boolean pickMode
-
-
Method Detail
-
reset
public void reset()
-
contextLost
public void contextLost()
-
peekDrawable
public Drawable peekDrawable()
-
pollDrawable
public Drawable pollDrawable()
-
rewindDrawables
public void rewindDrawables()
-
getDrawableTerrainCount
public int getDrawableTerrainCount()
-
getDrawableTerrain
public DrawableTerrain getDrawableTerrain(int index)
-
currentFramebuffer
public int currentFramebuffer()
Returns the name of the OpenGL framebuffer object that is currently active.- Returns:
- the currently active framebuffer object, or 0 if no framebuffer object is active
-
bindFramebuffer
public void bindFramebuffer(int framebufferId)
Makes an OpenGL framebuffer object active. The active framebuffer becomes the target of all OpenGL commands that render to the framebuffer or read from the framebuffer. This has no effect if the specified framebuffer object is already active. The default is framebuffer 0, indicating that the default framebuffer provided by the windowing system is active.- Parameters:
framebufferId
- the name of the OpenGL framebuffer object to make active, or 0 to make the default framebuffer provided by the windowing system active
-
scratchFramebuffer
public Framebuffer scratchFramebuffer()
Returns an OpenGL framebuffer object suitable for offscreen drawing. The framebuffer has a 32-bit color buffer and a 32-bit depth buffer, both attached as OpenGL texture 2D objects.
The framebuffer may be used by any drawable and for any purpose. However, the draw context makes no guarantees about the framebuffer's contents. Drawables must clear the framebuffer before use, and must assume its contents may be modified by another drawable, either during the current frame or in a subsequent frame.
The OpenGL framebuffer object is created on first use and cached. Subsequent calls to this method return the cached buffer object.- Returns:
- the draw context's scratch OpenGL framebuffer object
-
currentProgram
public int currentProgram()
Returns the name of the OpenGL program object that is currently active.- Returns:
- the currently active program object, or 0 if no program object is active
-
useProgram
public void useProgram(int programId)
Makes an OpenGL program object active as part of current rendering state. This has no effect if the specified program object is already active. The default is program 0, indicating that no program is active.- Parameters:
programId
- the name of the OpenGL program object to make active, or 0 to make no program active
-
currentTextureUnit
public int currentTextureUnit()
Returns the OpenGL multitexture unit that is currently active. Returns a value from the GL_TEXTUREi enumeration, where i ranges from 0 to 32.- Returns:
- the currently active multitexture unit.
-
activeTextureUnit
public void activeTextureUnit(int textureUnit)
Specifies the OpenGL multitexture unit to make active. This has no effect if the specified multitexture unit is already active. The default is GL_TEXTURE0.- Parameters:
textureUnit
- the multitexture unit, one of GL_TEXTUREi, where i ranges from 0 to 32.
-
currentTexture
public int currentTexture()
Returns the name of the OpenGL texture 2D object currently bound to the active multitexture unit. The active multitexture unit may be determined by calling currentTextureUnit.- Returns:
- the currently bound texture 2D object, or 0 if no texture object is bound
-
currentTexture
public int currentTexture(int textureUnit)
Returns the name of the OpenGL texture 2D object currently bound to the specified multitexture unit.- Parameters:
textureUnit
- the multitexture unit, one of GL_TEXTUREi, where i ranges from 0 to 32.- Returns:
- the currently bound texture 2D object, or 0 if no texture object is bound
-
bindTexture
public void bindTexture(int textureId)
Makes an OpenGL texture 2D object bound to the current multitexture unit. This has no effect if the specified texture object is already bound. The default is texture 0, indicating that no texture is bound.- Parameters:
textureId
- the name of the OpenGL texture 2D object to make active, or 0 to make no texture active
-
currentBuffer
public int currentBuffer(int target)
Returns the name of the OpenGL buffer object bound to the specified target buffer.- Parameters:
target
- the target buffer, either GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER- Returns:
- the currently bound buffer object, or 0 if no buffer object is bound
-
bindBuffer
public void bindBuffer(int target, int bufferId)
Makes an OpenGL buffer object bound to a specified target buffer. This has no effect if the specified buffer object is already bound. The default is buffer 0, indicating that no buffer object is bound.- Parameters:
target
- the target buffer, either GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFERbufferId
- the name of the OpenGL buffer object to make active
-
unitSquareBuffer
public BufferObject unitSquareBuffer()
Returns an OpenGL buffer object containing a unit square expressed as four vertices at (0, 1), (0, 0), (1, 1) and (1, 0). Each vertex is stored as two 32-bit floating point coordinates. The four vertices are in the order required by a triangle strip.
The OpenGL buffer object is created on first use and cached. Subsequent calls to this method return the cached buffer object.- Returns:
- the draw context's unit square OpenGL buffer object
-
readPixelColor
public Color readPixelColor(int x, int y, Color result)
Reads the fragment color at a screen point in the currently active OpenGL frame buffer. The X and Y components indicate OpenGL screen coordinates, which originate in the frame buffer's lower left corner.- Parameters:
x
- the screen point's X componenty
- the screen point's Y componentresult
- an optional pre-allocated Color in which to return the fragment color, or null to return a new color- Returns:
- the result argument set to the fragment color, or a new color if the result is null
-
readPixelColors
public java.util.Set<Color> readPixelColors(int x, int y, int width, int height)
Reads the unique fragment colors within a screen rectangle in the currently active OpenGL frame buffer. The components indicate OpenGL screen coordinates, which originate in the frame buffer's lower left corner.- Parameters:
x
- the screen rectangle's X componenty
- the screen rectangle's Y componentwidth
- the screen rectangle's widthheight
- the screen rectangle's height- Returns:
- a set containing the unique fragment colors
-
scratchBuffer
public java.nio.ByteBuffer scratchBuffer(int capacity)
Returns a scratch NIO buffer suitable for use during drawing. The returned buffer has capacity at least equal to the specified capacity. The buffer is cleared before each frame, otherwise its contents, position, limit and mark are undefined.- Parameters:
capacity
- the buffer's minimum capacity in bytes- Returns:
- the draw context's scratch buffer
-
scratchList
public java.util.ArrayList<java.lang.Object> scratchList()
Returns a scratch list suitable for accumulating entries during drawing. The list is cleared before each frame, otherwise its contents are undefined.- Returns:
- the draw context's scratch list
-
-