Issue #1806 Update GL mosaicing to use dynamic data format for offscreen textures.
Change-Id: Ib756f4ce978ace6fae41dd407ab9187cd6b70d51 Former-commit-id:de02fe7922
[formerly 26baf1550ad70417a68bd0a36ea99ac83c6d39cd] Former-commit-id:e69011cdd8
This commit is contained in:
parent
93c44c94cb
commit
3cc175f373
7 changed files with 184 additions and 101 deletions
|
@ -40,6 +40,8 @@ import com.raytheon.uf.viz.core.exception.VizException;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Nov 17, 2011 mschenke Initial creation
|
||||
* Mar 21, 2013 1806 bsteffen Add ColorMapData constructor that
|
||||
* creates buffer from the dataType.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -81,6 +83,16 @@ public interface IColorMapDataRetrievalCallback {
|
|||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataType
|
||||
* @param dataBounds
|
||||
*/
|
||||
public ColorMapData(ColorMapDataType dataType, int[] dimensions) {
|
||||
this.buffer = getBuffer(dataType, dimensions);
|
||||
this.dimensions = dimensions;
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public Buffer getBuffer() {
|
||||
return buffer;
|
||||
}
|
||||
|
@ -106,6 +118,30 @@ public interface IColorMapDataRetrievalCallback {
|
|||
throw new RuntimeException("Could not find ColorMapDataType for "
|
||||
+ buffer);
|
||||
}
|
||||
|
||||
private static Buffer getBuffer(ColorMapDataType dataType,
|
||||
int[] dimensions) {
|
||||
int size = 1;
|
||||
for (int i : dimensions) {
|
||||
size *= i;
|
||||
}
|
||||
switch (dataType) {
|
||||
case BYTE:
|
||||
case SIGNED_BYTE:
|
||||
return ByteBuffer.allocate(size);
|
||||
case SHORT:
|
||||
case UNSIGNED_SHORT:
|
||||
return ShortBuffer.allocate(size);
|
||||
case FLOAT:
|
||||
return FloatBuffer.allocate(size);
|
||||
case INT:
|
||||
return IntBuffer.allocate(size);
|
||||
default:
|
||||
throw new RuntimeException("Could not find Buffer for "
|
||||
+ dataType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package com.raytheon.viz.core.gl.dataformat;
|
||||
|
||||
import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapData;
|
||||
import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapDataType;
|
||||
|
||||
/**
|
||||
* Factory class for getting GLColorMapDataFormat objects given the ColorMapData
|
||||
|
@ -32,6 +33,8 @@ import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapData
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Nov 21, 2011 mschenke Initial creation
|
||||
* Mar 21, 2013 1806 bsteffen Update GL mosaicing to use dynamic data
|
||||
* format for offscreen textures.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -43,8 +46,13 @@ public class GLColorMapDataFormatFactory {
|
|||
|
||||
public static AbstractGLColorMapDataFormat getGLColorMapDataFormat(
|
||||
ColorMapData colorMapData) {
|
||||
return getGLColorMapDataFormat(colorMapData.getDataType());
|
||||
}
|
||||
|
||||
public static AbstractGLColorMapDataFormat getGLColorMapDataFormat(
|
||||
ColorMapDataType colorMapDataType) {
|
||||
AbstractGLColorMapDataFormat dataFormat = null;
|
||||
switch (colorMapData.getDataType()) {
|
||||
switch (colorMapDataType) {
|
||||
case BYTE: {
|
||||
dataFormat = new GLByteDataFormat();
|
||||
break;
|
||||
|
|
|
@ -31,6 +31,7 @@ import javax.media.opengl.GL;
|
|||
import com.raytheon.uf.viz.core.IExtent;
|
||||
import com.raytheon.uf.viz.core.IView;
|
||||
import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback;
|
||||
import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapDataType;
|
||||
import com.raytheon.uf.viz.core.data.IRenderedImageCallback;
|
||||
import com.raytheon.uf.viz.core.drawables.ColorMapParameters;
|
||||
import com.raytheon.uf.viz.core.drawables.IImage;
|
||||
|
@ -40,6 +41,7 @@ import com.raytheon.uf.viz.core.exception.VizException;
|
|||
import com.raytheon.viz.core.gl.IGLTarget;
|
||||
import com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat;
|
||||
import com.raytheon.viz.core.gl.dataformat.GLByteDataFormat;
|
||||
import com.raytheon.viz.core.gl.dataformat.GLColorMapDataFormatFactory;
|
||||
import com.raytheon.viz.core.gl.dataformat.IGLColorMapDataFormatProvider;
|
||||
import com.raytheon.viz.core.gl.images.AbstractGLImage;
|
||||
import com.raytheon.viz.core.gl.images.GLColormappedImage;
|
||||
|
@ -60,6 +62,8 @@ import com.raytheon.viz.core.gl.internal.ext.GLColormappedImageExtension;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 10, 2012 bsteffen Initial creation
|
||||
* Mar 21, 2013 1806 bsteffen Update GL mosaicing to use dynamic data
|
||||
* format for offscreen textures.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -174,51 +178,37 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension<IGLTarget>
|
|||
}
|
||||
|
||||
public GLColormappedImage constructOffscreenImage(
|
||||
Class<? extends Buffer> dataType, int[] dimensions)
|
||||
throws VizException {
|
||||
ColorMapDataType dataType, int[] dimensions) throws VizException {
|
||||
return constructOffscreenImage(dataType, dimensions, null);
|
||||
}
|
||||
|
||||
public GLColormappedImage constructOffscreenImage(
|
||||
Class<? extends Buffer> dataType, final int[] dimensions,
|
||||
final ColorMapDataType dataType, final int[] dimensions,
|
||||
ColorMapParameters parameters) throws VizException {
|
||||
int width = dimensions[0];
|
||||
int height = dimensions[1];
|
||||
// Need to add support for multiple buffer types
|
||||
Buffer imageBuffer = null;
|
||||
if (dataType.isAssignableFrom(ByteBuffer.class)) {
|
||||
int pixels = 3;
|
||||
if (supportsLuminance) {
|
||||
pixels = 1;
|
||||
}
|
||||
byte[] buf = new byte[width * height * pixels];
|
||||
imageBuffer = ByteBuffer.wrap(buf);
|
||||
}
|
||||
GLColormappedImageExtension cmapExt = target
|
||||
.getExtension(GLColormappedImageExtension.class);
|
||||
if (!supportsLuminance) {
|
||||
return cmapExt.initializeRaster(new NoLuminanceDataCallback(
|
||||
dimensions, dataType), parameters);
|
||||
} else {
|
||||
GLColormappedImage image = cmapExt.initializeRaster(
|
||||
new IColorMapDataRetrievalCallback() {
|
||||
|
||||
if (imageBuffer != null) {
|
||||
GLColormappedImage image = null;
|
||||
final Buffer buffer = imageBuffer;
|
||||
GLColormappedImageExtension cmapExt = target
|
||||
.getExtension(GLColormappedImageExtension.class);
|
||||
if (supportsLuminance) {
|
||||
image = cmapExt.initializeRaster(
|
||||
new IColorMapDataRetrievalCallback() {
|
||||
|
||||
@Override
|
||||
public ColorMapData getColorMapData()
|
||||
throws VizException {
|
||||
return new ColorMapData(buffer, dimensions);
|
||||
}
|
||||
}, parameters);
|
||||
} else {
|
||||
image = cmapExt.initializeRaster(new GLOffscreenDataCallback(
|
||||
buffer, dimensions), parameters);
|
||||
}
|
||||
@Override
|
||||
public ColorMapData getColorMapData()
|
||||
throws VizException {
|
||||
return new ColorMapData(dataType, dimensions);
|
||||
}
|
||||
}, parameters);
|
||||
if (!checkedLuminance) {
|
||||
checkedLuminance = true;
|
||||
try {
|
||||
renderOffscreen(image);
|
||||
} catch (VizException e) {
|
||||
// Log this so it is easy to see in the console logs.
|
||||
new VizException(
|
||||
"Graphics card does not support luminance textures.",
|
||||
e).printStackTrace(System.out);
|
||||
// assume we don't support luminance
|
||||
supportsLuminance = false;
|
||||
// Reconstruct image
|
||||
|
@ -229,84 +219,76 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension<IGLTarget>
|
|||
}
|
||||
}
|
||||
return image;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class GLOffscreenDataCallback implements
|
||||
IColorMapDataRetrievalCallback, IGLColorMapDataFormatProvider {
|
||||
private static final class NoLuminanceDataFormat extends GLByteDataFormat {
|
||||
|
||||
private Buffer dataBuffer;
|
||||
// Used to get the original min/max which makes signed bytes work and
|
||||
// theoretically will give better looking results for other integer data
|
||||
// types.
|
||||
private final ColorMapDataType originalType;
|
||||
|
||||
private NoLuminanceDataFormat(ColorMapDataType originalType) {
|
||||
this.originalType = originalType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextureInternalFormat() {
|
||||
return GL.GL_RGB8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextureFormat() {
|
||||
return GL.GL_RGB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getValuesPerPixel() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDataFormatMin() {
|
||||
return getOriginalGLColorMapDataFormat().getDataFormatMin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDataFormatMax() {
|
||||
return getOriginalGLColorMapDataFormat().getDataFormatMax();
|
||||
}
|
||||
|
||||
private AbstractGLColorMapDataFormat getOriginalGLColorMapDataFormat() {
|
||||
return GLColorMapDataFormatFactory
|
||||
.getGLColorMapDataFormat(originalType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class NoLuminanceDataCallback implements
|
||||
IColorMapDataRetrievalCallback, IGLColorMapDataFormatProvider {
|
||||
|
||||
private int[] dimensions;
|
||||
|
||||
private GLOffscreenDataCallback(Buffer dataBuffer, int[] dimensions) {
|
||||
this.dataBuffer = dataBuffer;
|
||||
private final ColorMapDataType originalType;
|
||||
|
||||
private NoLuminanceDataCallback(int[] dimensions,
|
||||
ColorMapDataType type) {
|
||||
this.dimensions = dimensions;
|
||||
this.originalType = type;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.viz.core.gl.dataprep.IGLColorMapDataRetrievalCallback
|
||||
* #getGLColorMapData
|
||||
* (com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback
|
||||
* .ColorMapData)
|
||||
*/
|
||||
@Override
|
||||
public AbstractGLColorMapDataFormat getGLColorMapDataFormat(
|
||||
ColorMapData colorMapData) {
|
||||
return new GLByteDataFormat() {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.viz.core.gl.dataprep.GLByteDataFormat#
|
||||
* getTextureInternalFormat()
|
||||
*/
|
||||
@Override
|
||||
public int getTextureInternalFormat() {
|
||||
return GL.GL_RGB8;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.viz.core.gl.dataprep.AbstractGLColorMapDataFormat
|
||||
* #getTextureFormat()
|
||||
*/
|
||||
@Override
|
||||
public int getTextureFormat() {
|
||||
return GL.GL_RGB;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.viz.core.gl.dataprep.AbstractGLColorMapDataFormat
|
||||
* #getPointsPerPixel()
|
||||
*/
|
||||
@Override
|
||||
public int getValuesPerPixel() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
};
|
||||
return new NoLuminanceDataFormat(originalType);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback#
|
||||
* getColorMapData()
|
||||
*/
|
||||
@Override
|
||||
public ColorMapData getColorMapData() throws VizException {
|
||||
return new ColorMapData(dataBuffer, dimensions);
|
||||
Buffer buffer = ByteBuffer.allocate(dimensions[0] * dimensions[1]
|
||||
* 3);
|
||||
return new ColorMapData(buffer, dimensions, originalType);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import javax.media.opengl.glu.GLU;
|
|||
|
||||
import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback;
|
||||
import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapData;
|
||||
import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapDataType;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.viz.core.gl.GLContextBridge;
|
||||
import com.raytheon.viz.core.gl.dataformat.GLColorMapData;
|
||||
|
@ -49,6 +50,8 @@ import com.raytheon.viz.core.gl.objects.GLTextureObject;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Aug 2, 2011 bsteffen Initial creation
|
||||
* Mar 21, 2013 1806 bsteffen Update GL mosaicing to use dynamic data
|
||||
* format for offscreen textures.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -271,4 +274,8 @@ public class GLCMTextureData implements IImageCacheable {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public ColorMapDataType getColorMapDataType() {
|
||||
return data.getDataType();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package com.raytheon.viz.core.gl.images;
|
|||
import javax.media.opengl.GL;
|
||||
|
||||
import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback;
|
||||
import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapDataType;
|
||||
import com.raytheon.uf.viz.core.drawables.ColorMapParameters;
|
||||
import com.raytheon.uf.viz.core.drawables.IColormappedImage;
|
||||
import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension;
|
||||
|
@ -39,6 +40,8 @@ import com.sun.opengl.util.texture.TextureCoords;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 27, 2009 mschenke Initial creation
|
||||
* Mar 21, 2013 1806 bsteffen Update GL mosaicing to use dynamic data
|
||||
* format for offscreen textures.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -109,6 +112,10 @@ public class GLColormappedImage extends AbstractGLImage implements
|
|||
return data.getTextureType();
|
||||
}
|
||||
|
||||
public ColorMapDataType getColorMapDataType() {
|
||||
return data.getColorMapDataType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the texture's format
|
||||
*
|
||||
|
|
|
@ -38,6 +38,8 @@ import com.raytheon.viz.core.gl.images.GLDelegateImage;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Dec 16, 2011 mschenke Initial creation
|
||||
* Mar 21, 2013 1806 bsteffen Update GL mosaicing to use dynamic data
|
||||
* format for offscreen textures.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -165,4 +167,9 @@ public class GLMosaicImage extends GLDelegateImage<GLColormappedImage>
|
|||
return image.getValue(x, y);
|
||||
}
|
||||
|
||||
public void setWrappedImage(GLColormappedImage wrappedImage) {
|
||||
this.image.dispose();
|
||||
this.image = wrappedImage;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,15 +19,15 @@
|
|||
**/
|
||||
package com.raytheon.viz.core.gl.internal.ext.mosaic;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import javax.media.opengl.GL;
|
||||
|
||||
import com.raytheon.uf.viz.core.DrawableImage;
|
||||
import com.raytheon.uf.viz.core.IExtent;
|
||||
import com.raytheon.uf.viz.core.PixelCoverage;
|
||||
import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapDataType;
|
||||
import com.raytheon.uf.viz.core.drawables.ColorMapParameters;
|
||||
import com.raytheon.uf.viz.core.drawables.IImage;
|
||||
import com.raytheon.uf.viz.core.drawables.IImage.Status;
|
||||
import com.raytheon.uf.viz.core.drawables.ImagingSupport;
|
||||
import com.raytheon.uf.viz.core.drawables.PaintProperties;
|
||||
import com.raytheon.uf.viz.core.drawables.ext.IMosaicImageExtension;
|
||||
|
@ -36,6 +36,7 @@ import com.raytheon.viz.core.gl.ext.GLOffscreenRenderingExtension;
|
|||
import com.raytheon.viz.core.gl.glsl.AbstractGLSLImagingExtension;
|
||||
import com.raytheon.viz.core.gl.glsl.GLShaderProgram;
|
||||
import com.raytheon.viz.core.gl.images.AbstractGLImage;
|
||||
import com.raytheon.viz.core.gl.images.GLColormappedImage;
|
||||
|
||||
/**
|
||||
* Extension used for rendering radar mosaic images
|
||||
|
@ -47,6 +48,8 @@ import com.raytheon.viz.core.gl.images.AbstractGLImage;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Dec 16, 2011 mschenke Initial creation
|
||||
* Mar 21, 2013 1806 bsteffen Update GL mosaicing to use dynamic data
|
||||
* format for offscreen textures.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -57,13 +60,14 @@ import com.raytheon.viz.core.gl.images.AbstractGLImage;
|
|||
public class GLMosaicImageExtension extends AbstractGLSLImagingExtension
|
||||
implements IMosaicImageExtension {
|
||||
|
||||
private AbstractGLImage writeToImage;
|
||||
private GLColormappedImage writeToImage;
|
||||
|
||||
public GLMosaicImage initializeRaster(int[] imageBounds,
|
||||
IExtent imageExtent, ColorMapParameters params) throws VizException {
|
||||
// Since byte is the most common type of mosaic start with a byte image. It might switch later if needed.
|
||||
return new GLMosaicImage(target.getExtension(
|
||||
GLOffscreenRenderingExtension.class).constructOffscreenImage(
|
||||
ByteBuffer.class, imageBounds, params), imageBounds,
|
||||
ColorMapDataType.BYTE, imageBounds, params), imageBounds,
|
||||
imageExtent, this.getClass());
|
||||
}
|
||||
|
||||
|
@ -93,7 +97,7 @@ public class GLMosaicImageExtension extends AbstractGLSLImagingExtension
|
|||
if (image instanceof GLMosaicImage) {
|
||||
GLMosaicImage mosaicImage = (GLMosaicImage) image;
|
||||
if (mosaicImage.isRepaint()) {
|
||||
writeToImage = mosaicImage.getWrappedImage();
|
||||
writeToImage = getWriteToImage(mosaicImage);
|
||||
GLOffscreenRenderingExtension extension = target
|
||||
.getExtension(GLOffscreenRenderingExtension.class);
|
||||
try {
|
||||
|
@ -134,6 +138,38 @@ public class GLMosaicImageExtension extends AbstractGLSLImagingExtension
|
|||
}
|
||||
}
|
||||
|
||||
private GLColormappedImage getWriteToImage(GLMosaicImage mosaicImage)
|
||||
throws VizException {
|
||||
ColorMapDataType neededType = null;
|
||||
for (DrawableImage di : mosaicImage.getImagesToMosaic()) {
|
||||
IImage image = di.getImage();
|
||||
if (image.getStatus() != Status.LOADED) {
|
||||
continue;
|
||||
}
|
||||
if (image instanceof GLColormappedImage) {
|
||||
GLColormappedImage colorMapImage = (GLColormappedImage) image;
|
||||
ColorMapDataType type = colorMapImage.getColorMapDataType();
|
||||
if (neededType == null) {
|
||||
neededType = type;
|
||||
} else if (neededType != type) {
|
||||
// Mosaicing images of different types?
|
||||
// No Idea how to handle this
|
||||
return mosaicImage.getWrappedImage();
|
||||
}
|
||||
}
|
||||
}
|
||||
GLColormappedImage writeTo = mosaicImage.getWrappedImage();
|
||||
if (neededType != null && neededType != writeTo.getColorMapDataType()) {
|
||||
GLOffscreenRenderingExtension offscreenExt = target
|
||||
.getExtension(GLOffscreenRenderingExtension.class);
|
||||
int[] dimensions = { writeTo.getWidth(), writeTo.getHeight() };
|
||||
writeTo = offscreenExt.constructOffscreenImage(neededType,
|
||||
dimensions, writeTo.getColorMapParameters());
|
||||
mosaicImage.setWrappedImage(writeTo);
|
||||
}
|
||||
return writeTo;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue