Issue #2950 Fix GL errors when mosaicing or using ginormous colormaps.

Former-commit-id: daff2b9d9d [formerly 67302674101992ae5416f342f92acab9233a113d]
Former-commit-id: 5328415054
This commit is contained in:
Ben Steffensmeier 2014-04-08 17:42:28 -05:00
parent b793ce20bc
commit 9c5eb936d3
3 changed files with 41 additions and 53 deletions

View file

@ -19,20 +19,24 @@
**/
package com.raytheon.viz.core.gl;
import java.nio.IntBuffer;
import javax.media.opengl.GL;
import com.raytheon.viz.core.gl.internal.GLTarget;
/**
* TODO Add Description
* Holds the results of several queries into GL to determine what level of
* capabilities are supported.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 6, 2011 mschenke Initial creation
* Date Ticket# Engineer Description
* ------------- -------- ----------- --------------------------
* Jun 06, 2011 mschenke Initial creation
* Apr 08, 2014 2950 bsteffen Add max texture size.
*
* </pre>
*
@ -59,6 +63,8 @@ public class GLCapabilities {
public boolean textureRectangleSupported;
public final int maxTextureSize;
private GLCapabilities(GL gl) {
String openGlVersion = gl.glGetString(GL.GL_VERSION);
float glVersion = Float.parseFloat(openGlVersion.substring(0, 3));
@ -86,5 +92,9 @@ public class GLCapabilities {
}
}
System.out.println("Shader supported: " + cardSupportsShaders);
IntBuffer ib = IntBuffer.allocate(1);
gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, ib);
ib.rewind();
maxTextureSize = ib.get();
}
}

View file

@ -51,6 +51,7 @@ import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.PlatformUI;
import org.geotools.coverage.grid.GeneralGridGeometry;
import com.raytheon.uf.common.colormap.Color;
import com.raytheon.uf.common.colormap.ColorMap;
import com.raytheon.uf.common.colormap.IColorMap;
import com.raytheon.uf.common.colormap.image.ColorMapData;
@ -138,10 +139,11 @@ import com.sun.opengl.util.j2d.TextRenderer;
* May 28, 2013 1638 mschenke Made sure {@link TextStyle#BLANKED} text
* is drawing correct size box around text
* Nov 04, 2013 2492 mschenke Switched colormap drawing to use 1D
* texture object for alpha mask
* texture object for alpha mask
* Mar 03, 2014 2804 mschenke Added clipping pane field to only setup
* if changed
* Apr 04, 2014 2920 bsteffen Allow strings to use mulitple styles.
* Apr 08, 2014 2950 bsteffen Reduce oversized colormaps.
*
* </pre>
*
@ -1257,6 +1259,25 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
}
protected GLTextureObject loadColormapIntoTexture(ColorMap glColorMap) {
if (glColorMap.getSize() > capabilities.maxTextureSize) {
double ratio = (glColorMap.getSize() - 1)
/ (capabilities.maxTextureSize - 1.0);
List<Color> colors = glColorMap.getColors();
List<Color> lessColors = new ArrayList<Color>(
capabilities.maxTextureSize);
for (int i = 0; i < capabilities.maxTextureSize; i += 1) {
lessColors.add(colors.get((int) (i * ratio)));
}
statusHandler.info("Reducing colormap to " + lessColors.size()
+ " colors because this graphics card only supports "
+ capabilities.maxTextureSize
+ " colors and the colormap contains "
+ glColorMap.getSize() + " colors.");
glColorMap = new ColorMap(lessColors.size());
for (int i = 0; i < lessColors.size(); i += 1) {
glColorMap.setColor(i, lessColors.get(i));
}
}
Buffer bb = glColorMap.getColorMap();
GLContextBridge.makeMasterContextCurrent();
GLTextureObject t = new GLTextureObject();
@ -1277,11 +1298,6 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget {
gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER,
GL.GL_NEAREST);
// gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER,
// GL.GL_NEAREST);
// gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER,
// GL.GL_NEAREST);
gl.glTexImage1D(GL.GL_TEXTURE_1D, 0, GL.GL_RGBA, glColorMap.getSize(),
0, GL.GL_RGBA, GL.GL_FLOAT, bb);
gl.glBindTexture(GL.GL_TEXTURE_1D, 0);

View file

@ -27,7 +27,6 @@ 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.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;
@ -40,7 +39,6 @@ import com.raytheon.viz.core.gl.glsl.GLSLStructFactory;
import com.raytheon.viz.core.gl.glsl.GLShaderProgram;
import com.raytheon.viz.core.gl.images.AbstractGLColormappedImage;
import com.raytheon.viz.core.gl.images.AbstractGLImage;
import com.raytheon.viz.core.gl.images.GLColormappedImage;
import com.raytheon.viz.core.gl.images.GLOffscreenColormappedImage;
/**
@ -58,6 +56,8 @@ import com.raytheon.viz.core.gl.images.GLOffscreenColormappedImage;
* Oct 16, 2013 2333 mschenke Cleaned up render logic, switched to use
* GLOffscreenColormappedImage
* Nov 20, 2013 2492 bsteffen Mosaic in image units.
* Apr 08, 2014 2950 bsteffen Always use float for maximum precision
* offscreen so interpolation works.
*
* </pre>
*
@ -70,13 +70,14 @@ public abstract class GLMosaicImageExtension extends
private GLOffscreenColormappedImage writeToImage;
@Override
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 when images to mosaic are set
return new GLMosaicImage(target.getExtension(
GLOffscreenRenderingExtension.class).constructOffscreenImage(
ColorMapDataType.BYTE, imageBounds, params), imageBounds,
ColorMapDataType.FLOAT, imageBounds, params), imageBounds,
imageExtent, this.getClass());
}
@ -100,7 +101,7 @@ public abstract class GLMosaicImageExtension extends
// Make sure images are staged before we mosaic them
ImagingSupport.prepareImages(target, imagesToMosaic);
writeToImage = getWriteToImage(mosaicImage);
writeToImage = mosaicImage.getWrappedImage();
if (writeToImage != null) {
GLOffscreenRenderingExtension extension = target
.getExtension(GLOffscreenRenderingExtension.class);
@ -150,45 +151,6 @@ public abstract class GLMosaicImageExtension extends
return null;
}
private GLOffscreenColormappedImage getWriteToImage(
GLMosaicImage mosaicImage) throws VizException {
ColorMapDataType neededType = null;
for (DrawableImage di : mosaicImage.getImagesToMosaic()) {
IImage image = di.getImage();
if (image.getStatus() != Status.LOADED
&& image.getStatus() != Status.STAGED) {
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();
}
}
}
if (neededType == null) {
return null;
}
GLOffscreenColormappedImage writeTo = mosaicImage.getWrappedImage();
if (neededType != null && neededType != writeTo.getColorMapDataType()) {
GLOffscreenRenderingExtension offscreenExt = target
.getExtension(GLOffscreenRenderingExtension.class);
int[] dimensions = { writeTo.getWidth(), writeTo.getHeight() };
writeTo.dispose();
writeTo = offscreenExt.constructOffscreenImage(neededType,
dimensions, writeTo.getColorMapParameters());
mosaicImage.setWrappedImage(writeTo);
}
return writeTo;
}
/*
* (non-Javadoc)
*