throw new IllegalArgumentException("Texture type not supported: " + tex.getType());
}
final GL gl = GLContext.getCurrentGL();
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);
gl.glGenTextures(ibuf.limit(), ibuf); // TODO Check <size>
final int textureId = ibuf.get(0);
tex.setTextureIdForContext(context.getGlContextRep(), textureId);
JoglTextureStateUtil.doTextureBind(tex, 0, true);
// Initialize our texture with some default data.
final int internalFormat = JoglTextureUtil.getGLInternalFormat(tex.getTextureStoreFormat());
final int dataFormat = JoglTextureUtil.getGLPixelFormatFromStoreFormat(tex.getTextureStoreFormat());
final int pixelDataType = JoglTextureUtil.getGLPixelDataType(tex.getRenderedTexturePixelDataType());
if (tex.getType() == Type.TwoDimensional) {
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, internalFormat, _width, _height, 0, dataFormat, pixelDataType, null);
} else {
for (final Face face : Face.values()) {
gl.glTexImage2D(JoglTextureStateUtil.getGLCubeMapFace(face), 0, internalFormat, _width, _height, 0,
dataFormat, pixelDataType, null);
}
}
// Initialize mipmapping for this texture, if requested
if (tex.getMinificationFilter().usesMipMapLevels()) {
gl.glGenerateMipmap(JoglTextureStateUtil.getGLType(tex.getType()));
}
// Setup filtering and wrap
final TextureRecord texRecord = record.getTextureRecord(textureId, tex.getType());
JoglTextureStateUtil.applyFilter(tex, texRecord, 0, record, context.getCapabilities());
JoglTextureStateUtil.applyWrap(tex, texRecord, 0, record, context.getCapabilities());
logger.fine("setup fbo tex with id " + textureId + ": " + _width + "," + _height);
}