Skip to content

Commit

Permalink
Added image display options needed for shape dashed outlines (issue #63)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdavidc committed Sep 30, 2016
1 parent 85ea622 commit 736f031
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
43 changes: 43 additions & 0 deletions worldwind/src/main/java/gov/nasa/worldwind/WorldWind.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,49 @@ public class WorldWind {

}

/**
* {@link ResamplingMode} constant indicating bilinear image sampling.
*/
public static final int BILINEAR = 0;

/**
* {@link ResamplingMode} constant indicating nearest neighbor image sampling.
*/
public static final int NEAREST_NEIGHBOR = 1;

/**
* Resampling mode indicates the image sampling algorithm used by World Wind to display images that appear larger or
* smaller on screen than their native resolution. Accepted values are {@link WorldWind#BILINEAR} and {@link
* WorldWind#NEAREST_NEIGHBOR}.
*/
@IntDef({BILINEAR, NEAREST_NEIGHBOR})
@Retention(RetentionPolicy.SOURCE)
public @interface ResamplingMode {

}

/**
* {@link WrapMode} constant indicating that the image's edge pixels should be displayed outside of the image
* bounds.
*/
public static final int CLAMP = 0;

/**
* {@link WrapMode} constant indicating that the image should display as a repeating pattern outside of the image
* bounds.
*/
public static final int REPEAT = 1;

/**
* Wrap mode indicates how World Wind displays the contents of an image when attempting to draw a region outside of
* the image bounds. Accepted values are {@link WorldWind#CLAMP} and {@link WorldWind#REPEAT}.
*/
@IntDef({CLAMP, REPEAT})
@Retention(RetentionPolicy.SOURCE)
public @interface WrapMode {

}

/**
* Notification constant requesting that World Window instances update their display.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ public class ImageOptions {
@WorldWind.ImageConfig
public int imageConfig = WorldWind.RGBA_8888;

/**
* Indicates the image sampling algorithm used by World Wind to display images that appear larger or smaller on
* screen than their native resolution. Accepted values are {@link WorldWind#BILINEAR} and {@link
* WorldWind#NEAREST_NEIGHBOR}.
*/
@WorldWind.ResamplingMode
public int resamplingMode = WorldWind.BILINEAR;

/**
* Indicates how World Wind displays the contents of an image when attempting to draw a region outside of the image
* bounds. Accepted values are {@link WorldWind#CLAMP} and {@link WorldWind#REPEAT}.
*/
@WorldWind.WrapMode
public int wrapMode = WorldWind.CLAMP;

/**
* Constructs an image options with default values.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.opengl.GLES20;
import android.os.Handler;
import android.os.Message;

Expand Down Expand Up @@ -132,7 +133,7 @@ public Texture retrieveTexture(ImageSource imageSource, ImageOptions options) {

// Bitmap image sources are already in memory, so a texture may be created and put into the cache immediately.
if (imageSource.isBitmap()) {
Texture texture = new Texture(imageSource.asBitmap());
Texture texture = this.createTexture(imageSource, options, imageSource.asBitmap());
this.put(imageSource, texture, texture.getByteCount());
return texture;
}
Expand All @@ -143,7 +144,7 @@ public Texture retrieveTexture(ImageSource imageSource, ImageOptions options) {
// corresponding texture if found.
Bitmap bitmap = this.imageRetrieverCache.remove(imageSource);
if (bitmap != null) {
Texture texture = new Texture(bitmap);
Texture texture = this.createTexture(imageSource, options, bitmap);
this.put(imageSource, texture, texture.getByteCount());
return texture;
}
Expand All @@ -160,6 +161,22 @@ public Texture retrieveTexture(ImageSource imageSource, ImageOptions options) {
return null;
}

protected Texture createTexture(ImageSource imageSource, ImageOptions options, Bitmap bitmap) {
Texture texture = new Texture(bitmap);

if (options != null && options.resamplingMode == WorldWind.NEAREST_NEIGHBOR) {
texture.setTexParameter(GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
texture.setTexParameter(GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
}

if (options != null && options.wrapMode == WorldWind.REPEAT) {
texture.setTexParameter(GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
texture.setTexParameter(GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
}

return texture;
}

@Override
public void retrievalSucceeded(Retriever<ImageSource, ImageOptions, Bitmap> retriever, ImageSource key, ImageOptions options, Bitmap value) {
this.imageRetrieverCache.put(key, value, value.getByteCount());
Expand Down
16 changes: 14 additions & 2 deletions worldwind/src/main/java/gov/nasa/worldwind/shape/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import gov.nasa.worldwind.geom.Vec3;
import gov.nasa.worldwind.render.BasicShaderProgram;
import gov.nasa.worldwind.render.BufferObject;
import gov.nasa.worldwind.render.ImageOptions;
import gov.nasa.worldwind.render.RenderContext;
import gov.nasa.worldwind.render.Texture;
import gov.nasa.worldwind.util.FloatArray;
Expand All @@ -39,6 +40,8 @@ public class Path extends AbstractShape {

protected static final double FOLLOW_TERRAIN_SEGMENT_LENGTH = 1000.0;

protected static final ImageOptions defaultOutlineImageOptions = new ImageOptions();

protected List<Position> positions = Collections.emptyList();

protected boolean extrude;
Expand Down Expand Up @@ -71,6 +74,11 @@ protected static Object nextCacheKey() {
return new Object();
}

static {
defaultOutlineImageOptions.resamplingMode = WorldWind.NEAREST_NEIGHBOR;
defaultOutlineImageOptions.wrapMode = WorldWind.REPEAT;
}

public Path() {
}

Expand Down Expand Up @@ -190,7 +198,7 @@ protected void makeDrawable(RenderContext rc) {
if (this.activeAttributes.drawOutline && this.activeAttributes.outlineImageSource != null) {
Texture texture = rc.getTexture(this.activeAttributes.outlineImageSource);
if (texture == null) {
texture = rc.retrieveTexture(this.activeAttributes.outlineImageSource, null);
texture = rc.retrieveTexture(this.activeAttributes.outlineImageSource, defaultOutlineImageOptions);
}
if (texture != null) {
double metersPerPixel = rc.pixelSizeAtDistance(cameraDistance);
Expand Down Expand Up @@ -234,7 +242,11 @@ protected void makeDrawable(RenderContext rc) {
drawState.depthOffset = (this.altitudeMode == WorldWind.CLAMP_TO_GROUND ? CLAMP_TO_GROUND_DEPTH_OFFSET : 0);

// Enqueue the drawable for processing on the OpenGL thread.
rc.offerShapeDrawable(drawable, cameraDistance);
if (this.altitudeMode == WorldWind.CLAMP_TO_GROUND) {
rc.offerSurfaceDrawable(drawable, 0 /*zOrder*/);
} else {
rc.offerShapeDrawable(drawable, cameraDistance);
}
}

protected boolean mustAssembleGeometry(RenderContext rc) {
Expand Down

0 comments on commit 736f031

Please sign in to comment.