Issue #2543 fix gl buffer formating problems

Change-Id: I305dfb7eadcf69b47d56e3f937abd8c2aa0edfdc

Former-commit-id: fe32d4ed93b583f0363b39edeb5b715bbe465dd8
This commit is contained in:
Ben Steffensmeier 2013-11-18 11:47:45 -06:00
parent 0a36987a01
commit 105e3e359a

View file

@ -31,9 +31,10 @@ import javax.media.opengl.GL;
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* ------------- -------- ----------- --------------------------
* Nov 21, 2011 mschenke Initial creation
* Oct 16, 2013 2333 mschenke Removed Buffer from GLColorMapData
* Nov 18, 2013 2543 bsteffen Add more buffer compatibility checks.
*
* </pre>
*
@ -165,7 +166,19 @@ public abstract class AbstractGLColorMapDataFormat {
* @return
*/
public Buffer formatForGL(Buffer buffer, GLColorMapData data) {
return handleBufferSizing(data, buffer, data.getDimensions());
buffer = handleBufferSizing(data, buffer);
if (!buffer.isDirect() && !buffer.hasArray()) {
/*
* Things like ByteBuffer.allocate(n).asFloatBuffer() cause problems
* in GL. This will copy any such buffers into a new, more
* compatible buffer.
*/
buffer.position(0);
Buffer newBuffer = getCopybackBuffer(data);
copyRow(buffer, newBuffer, 0);
buffer = newBuffer;
}
return buffer;
}
/**
@ -207,15 +220,15 @@ public abstract class AbstractGLColorMapDataFormat {
/**
* If the data needs to be padded for alignment in GL, this handles that.
*
* @param data
* - dimensions and type of the buffer.
* @param buffer
* - the original data
* @param datasetBounds
* - the bounds of this data within the totalDatasetDimensions
* @return a buffer padded appropriately, or a the same buffer if it was
* good
*/
protected Buffer handleBufferSizing(GLColorMapData data, Buffer buffer,
int[] dimensions) {
protected Buffer handleBufferSizing(GLColorMapData data, Buffer buffer) {
int[] dimensions = data.getDimensions();
int sliceWidth = dimensions[0] * getValuesPerPixel();
int sliceHeight = dimensions.length > 1 ? dimensions[1] : 1;
int paddedSliceWidth = getAlignedWidth(sliceWidth);