|
NASA World Wind | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectgov.nasa.worldwind.util.OGLRenderToTextureSupport
public class OGLRenderToTextureSupport
OGLRenderToTextureSupport encapsulates the pattern of rendering GL commands to a destination texture. Currently only the color pixel values are written to the destination texture, but other values (depth, stencil) should be possible with modification or extension.
OGLRenderToTextureSupport is compatible with GL version 1.1 or greater, but it attempts to use more recent features whenever possible. Different GL feature sets result in different approaches to rendering to texture, therefore the caller cannot depend on the mechanism by which OGLRenderToTextureSupport will write pixel values to the destination texture. For this reason, OGLRenderToTextureSupport must be used when the contents of the windowing system buffer (likely the back framebuffer) can be freely modified by OGLRenderToTextureSupport. The World Wind pre-render stage is a good example of when it is appropriate to use OGLRenderToTextureSupport. Fore more information on the pre-render stage, seePreRenderable 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);
}
| Field Summary | |
|---|---|
protected Texture |
colorTarget
|
protected Rectangle |
drawRegion
|
protected int |
framebufferObject
|
protected boolean |
isFramebufferObjectEnabled
|
protected OGLStackHandler |
stackHandler
|
| Constructor Summary | |
|---|---|
OGLRenderToTextureSupport()
Constructs a new OGLRenderToTextureSupport, but otherwise does nothing. |
|
| Method Summary | |
|---|---|
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,
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 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)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Texture colorTarget
protected Rectangle drawRegion
protected int framebufferObject
protected boolean isFramebufferObjectEnabled
protected OGLStackHandler stackHandler
| Constructor Detail |
|---|
public OGLRenderToTextureSupport()
| Method Detail |
|---|
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.
IllegalArgumentException - if the DrawContext is null.
protected void bindFramebufferColorAttachment(DrawContext dc,
Texture texture)
protected void checkFramebufferStatus(DrawContext dc)
public void clear(DrawContext dc,
Color color)
dc - the current DrawContext.color - the RGBA clear color to write to the current color texture target.
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.
IllegalArgumentException - if the DrawContext is null.public void flush(DrawContext dc)
dc - the current DrawContext.
IllegalArgumentException - if the DrawContext is null.protected void flushColor(DrawContext dc)
public Texture getColorTarget()
protected static 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.
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)
|
NASA World Wind | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||