Class DrawContext


  • public class DrawContext
    extends java.lang.Object
    • 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
      • pickViewport

        public Viewport pickViewport
      • pickPoint

        public Vec2 pickPoint
      • pickMode

        public boolean pickMode
    • Constructor Detail

      • DrawContext

        public DrawContext()
    • 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_BUFFER
        bufferId - 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 component
        y - the screen point's Y component
        result - 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 component
        y - the screen rectangle's Y component
        width - the screen rectangle's width
        height - 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