public void setupTexture(final Texture tex) {
if (tex.getType() != Type.TwoDimensional && tex.getType() != Type.CubeMap) {
throw new IllegalArgumentException("Texture type not supported: " + tex.getType());
}
final RenderContext context = ContextManager.getCurrentContext();
final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(RenderState.StateType.Texture);
// check if we are already setup... if so, throw error.
if (tex.getTextureKey() == null) {
tex.setTextureKey(TextureKey.getRTTKey(tex.getMinificationFilter()));
} else if (tex.getTextureIdForContext(context.getGlContextRep()) != 0) {
throw new Ardor3dException("Texture is already setup and has id.");
}
// Create the texture
final IntBuffer ibuf = BufferUtils.createIntBuffer(1);
GL11.glGenTextures(ibuf);
final int textureId = ibuf.get(0);
tex.setTextureIdForContext(context.getGlContextRep(), textureId);
LwjglTextureStateUtil.doTextureBind(tex, 0, true);
// Initialize our texture with some default data.
final int internalFormat = LwjglTextureUtil.getGLInternalFormat(tex.getTextureStoreFormat());
final int dataFormat = LwjglTextureUtil.getGLPixelFormatFromStoreFormat(tex.getTextureStoreFormat());
final int pixelDataType = LwjglTextureUtil.getGLPixelDataType(tex.getRenderedTexturePixelDataType());
if (tex.getType() == Type.TwoDimensional) {
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, _width, _height, 0, dataFormat, pixelDataType,
(ByteBuffer) null);
} else {
for (final Face face : Face.values()) {
GL11.glTexImage2D(LwjglTextureStateUtil.getGLCubeMapFace(face), 0, internalFormat, _width, _height, 0,
dataFormat, pixelDataType, (ByteBuffer) null);
}
}
// Initialize mipmapping for this texture, if requested
if (tex.getMinificationFilter().usesMipMapLevels()) {
EXTFramebufferObject.glGenerateMipmapEXT(LwjglTextureStateUtil.getGLType(tex.getType()));
}
// Setup filtering and wrap
final TextureRecord texRecord = record.getTextureRecord(textureId, tex.getType());
LwjglTextureStateUtil.applyFilter(tex, texRecord, 0, record, context.getCapabilities());
LwjglTextureStateUtil.applyWrap(tex, texRecord, 0, record, context.getCapabilities());
logger.fine("setup fbo tex with id " + textureId + ": " + _width + "," + _height);
}