public class OGLRenderToTextureSupport
extends java.lang.Object
PreRenderable
and Layer.preRender(gov.nasa.worldwind.render.DrawContext)
.
Note: In order to achieve consistent results across all platforms, it is essential to clear the texture's
contents before rendering anything into the texture. Do this by invoking clear(gov.nasa.worldwind.render.DrawContext, java.awt.Color)
immediately after any call to beginRendering(gov.nasa.worldwind.render.DrawContext, int, int, int, int)
.
The common usage pattern for OGLRenderToTextureSupport is as follows: DrawContext dc = ...; // Typically
passed in as an argument to the containing method.
Texture texture = TextureIO.newTexture(new
TextureData(...);
// Setup the drawing rectangle to match the texture dimensions, and originate from the
texture's lower left corner.
OGLRenderToTextureSupport rttSupport = new OGLRenderToTextureSupport();
rttSupport.beginRendering(dc, 0, 0, texture.getWidth(), texture.getHeight());
try
{
// Bind the
texture as the destination for color pixel writes.
rttSupport.setColorTarget(dc, texture);
// Clear the
texture contents with transparent black.
rttSupport.clear(dc, new Color(0, 0, 0, 0));
// Invoke desired GL
rendering commands.
}
finally
{
rttSupport.endRendering(dc);
}
Modifier and Type | Field and Description |
---|---|
protected Texture |
colorTarget |
protected java.awt.Rectangle |
drawRegion |
protected int |
framebufferObject |
protected boolean |
isFramebufferObjectEnabled |
protected OGLStackHandler |
stackHandler |
Constructor and Description |
---|
OGLRenderToTextureSupport()
Constructs a new OGLRenderToTextureSupport, but otherwise does nothing.
|
Modifier and Type | Method and Description |
---|---|
protected void |
beginFramebufferObjectRendering(DrawContext dc) |
void |
beginRendering(DrawContext dc,
int x,
int y,
int width,
int height)
Configures the GL attached to the specified DrawContext for rendering a 2D model to a texture.
|
protected void |
bindFramebufferColorAttachment(DrawContext dc,
Texture texture) |
protected void |
checkFramebufferStatus(DrawContext dc) |
void |
clear(DrawContext dc,
java.awt.Color color)
Clears the current texture target's pixels with the specified RGBA clear color.
|
protected void |
copyScreenPixelsToTexture(DrawContext dc,
int x,
int y,
int width,
int height,
Texture texture) |
protected void |
endFramebufferObjectRendering(DrawContext dc) |
void |
endRendering(DrawContext dc)
Flushes any buffered pixel values to the appropriate texure targets, then restores the GL state to its previous
configuration before
beginRendering(gov.nasa.worldwind.render.DrawContext, int, int, int, int) was
called. |
void |
flush(DrawContext dc)
Flushes any buffered pixel values to the appropriate target textures.
|
protected void |
flushColor(DrawContext dc) |
Texture |
getColorTarget()
Returns the texture currently set as the color buffer target, or null if no texture is currently bound as the
color buffer target.
|
protected static java.lang.String |
getFramebufferStatusString(int status) |
boolean |
isEnableFramebufferObject()
Returns true if framebuffer objects are enabled for use (only applicable if the feature is available in the
current GL runtime)
|
void |
setColorTarget(DrawContext dc,
Texture texture)
Sets the specified texture as the color buffer target.
|
void |
setEnableFramebufferObject(boolean enable)
Specifies if framebuffer objects should be used if they are available in the current GL runtime.
|
protected void |
updateMipmaps(DrawContext dc,
Texture texture) |
protected boolean |
useFramebufferObject(DrawContext dc) |
protected Texture colorTarget
protected java.awt.Rectangle drawRegion
protected int framebufferObject
protected boolean isFramebufferObjectEnabled
protected OGLStackHandler stackHandler
public OGLRenderToTextureSupport()
protected void beginFramebufferObjectRendering(DrawContext dc)
public void beginRendering(DrawContext dc, int x, int y, int width, int height)
endRendering(gov.nasa.worldwind.render.DrawContext)
.dc
- the current DrawContext.x
- the x-coordinate of the draw region's lower left corner.y
- the y-coordinate of the draw region's lower left corner.width
- the draw region width.height
- the draw region height.java.lang.IllegalArgumentException
- if the DrawContext is null.protected void bindFramebufferColorAttachment(DrawContext dc, Texture texture)
protected void checkFramebufferStatus(DrawContext dc)
public void clear(DrawContext dc, java.awt.Color color)
dc
- the current DrawContext.color
- the RGBA clear color to write to the current color texture target.java.lang.IllegalArgumentException
- if either the DrawContext or the color is null.protected void copyScreenPixelsToTexture(DrawContext dc, int x, int y, int width, int height, Texture texture)
protected void endFramebufferObjectRendering(DrawContext dc)
public void endRendering(DrawContext dc)
beginRendering(gov.nasa.worldwind.render.DrawContext, int, int, int, int)
was
called. Finally, all texture targets associated with this OGLRenderToTextureSupport are unbound.dc
- the current DrawContext.java.lang.IllegalArgumentException
- if the DrawContext is null.public void flush(DrawContext dc)
dc
- the current DrawContext.java.lang.IllegalArgumentException
- if the DrawContext is null.protected void flushColor(DrawContext dc)
public Texture getColorTarget()
protected static java.lang.String getFramebufferStatusString(int status)
public boolean isEnableFramebufferObject()
public void setColorTarget(DrawContext dc, Texture texture)
isEnableFramebufferObject()
is false, the supported texture formats for the color target are limited
only by the OpenGL implementation's supported formats. If isEnableFramebufferObject()
is true and the
DrawContext supports OpenGL framebuffer objects, the supported texture formats for the color target are as
follows: dc
- the current DrawContext.texture
- the Texture to use as the destination for GL commands affecting the color buffer. A null value is
permitted.java.lang.IllegalArgumentException
- if the DrawContext is null.public void setEnableFramebufferObject(boolean enable)
enable
- true to enable framebuffer objects, false to disable them.protected void updateMipmaps(DrawContext dc, Texture texture)
protected boolean useFramebufferObject(DrawContext dc)