int boundaryWidth,
int dataType, Object data, boolean useAutoMipMap) {
if (VERBOSE) System.err.println("JoglPipeline.updateTexture3DImage()");
GL2 gl = context(ctx).getGL().getGL2();
int format = 0;
int internalFormat = 0;
int type = GL2.GL_UNSIGNED_INT_8_8_8_8;
boolean forceAlphaToOne = false;
switch (textureFormat) {
case Texture.INTENSITY:
internalFormat = GL2.GL_INTENSITY;
break;
case Texture.LUMINANCE:
internalFormat = GL.GL_LUMINANCE;
break;
case Texture.ALPHA:
internalFormat = GL.GL_ALPHA;
break;
case Texture.LUMINANCE_ALPHA:
internalFormat = GL.GL_LUMINANCE_ALPHA;
break;
case Texture.RGB:
internalFormat = GL.GL_RGB;
break;
case Texture.RGBA:
internalFormat = GL.GL_RGBA;
break;
default:
assert false;
return;
}
if (useAutoMipMap) {
gl.glTexParameteri(GL2.GL_TEXTURE_3D, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE);
}
else {
gl.glTexParameteri(GL2.GL_TEXTURE_3D, GL2.GL_GENERATE_MIPMAP, GL.GL_FALSE);
}
if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) ||
(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_BUFFER)) {
switch (imageFormat) {
case ImageComponentRetained.TYPE_BYTE_BGR:
format = GL2.GL_BGR;
break;
case ImageComponentRetained.TYPE_BYTE_RGB:
format = GL.GL_RGB;
break;
case ImageComponentRetained.TYPE_BYTE_ABGR:
if (gl.isExtensionAvailable("GL_EXT_abgr")) { // If its zero, should never come here!
format = GL2.GL_ABGR_EXT;
} else {
assert false;
return;
}
break;
case ImageComponentRetained.TYPE_BYTE_RGBA:
// all RGB types are stored as RGBA
format = GL.GL_RGBA;
break;
case ImageComponentRetained.TYPE_BYTE_LA:
// all LA types are stored as LA8
format = GL.GL_LUMINANCE_ALPHA;
break;
case ImageComponentRetained.TYPE_BYTE_GRAY:
if (internalFormat == GL.GL_ALPHA) {
format = GL.GL_ALPHA;
} else {
format = GL.GL_LUMINANCE;
}
break;
case ImageComponentRetained.TYPE_USHORT_GRAY:
case ImageComponentRetained.TYPE_INT_BGR:
case ImageComponentRetained.TYPE_INT_RGB:
case ImageComponentRetained.TYPE_INT_ARGB:
default:
assert false;
return;
}
if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_BYTE_ARRAY) {
gl.glTexImage3D(GL2.GL_TEXTURE_3D,
level, internalFormat,
width, height, depth, boundaryWidth,
format, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap((byte[]) data));
}
else {
gl.glTexImage3D(GL2.GL_TEXTURE_3D,
level, internalFormat,
width, height, depth, boundaryWidth,
format, GL.GL_UNSIGNED_BYTE, (ByteBuffer) data);
}
} else if((dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) ||
(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_BUFFER)) {
switch (imageFormat) {
/* GL_BGR */
case ImageComponentRetained.TYPE_INT_BGR: /* Assume XBGR format */
format = GL.GL_RGBA;
type = GL2.GL_UNSIGNED_INT_8_8_8_8_REV;
forceAlphaToOne = true;
break;
case ImageComponentRetained.TYPE_INT_RGB: /* Assume XRGB format */
forceAlphaToOne = true;
/* Fall through to next case */
case ImageComponentRetained.TYPE_INT_ARGB:
format = GL2.GL_BGRA;
type = GL2.GL_UNSIGNED_INT_8_8_8_8_REV;
break;
/* This method only supports 3 and 4 components formats and INT types. */
case ImageComponentRetained.TYPE_BYTE_LA:
case ImageComponentRetained.TYPE_BYTE_GRAY:
case ImageComponentRetained.TYPE_USHORT_GRAY:
case ImageComponentRetained.TYPE_BYTE_BGR:
case ImageComponentRetained.TYPE_BYTE_RGB:
case ImageComponentRetained.TYPE_BYTE_RGBA:
case ImageComponentRetained.TYPE_BYTE_ABGR:
default:
assert false;
return;
}
/* Force Alpha to 1.0 if needed */
if(forceAlphaToOne) {
gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 0.0f);
gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 1.0f);
}
if(dataType == ImageComponentRetained.IMAGE_DATA_TYPE_INT_ARRAY) {
gl.glTexImage3D(GL2.GL_TEXTURE_3D,
level, internalFormat,
width, height, depth, boundaryWidth,
format, type, IntBuffer.wrap((int[]) data));
} else {
gl.glTexImage3D(GL2.GL_TEXTURE_3D,
level, internalFormat,
width, height, depth, boundaryWidth,
format, type, (Buffer) data);
}
/* Restore Alpha scale and bias */
if(forceAlphaToOne) {
gl.glPixelTransferf(GL2.GL_ALPHA_SCALE, 1.0f);
gl.glPixelTransferf(GL2.GL_ALPHA_BIAS, 0.0f);
}
} else {
assert false;
}
}