}
// if (MT4jSettings.getInstance().isOpenGlMode()){ //FIXME USE WHICH ONE?
if (this.isUseDirectGL()){
if (newTexImage instanceof GLTexture) {
GLTexture glTex = (GLTexture) newTexImage;
if (glTex.getTextureTargetEnum() == TEXTURE_TARGET.RECTANGULAR){
this.setTextureMode(PConstants.IMAGE);
if (this.getGeometryInfo().isTextureCoordsNormalized()){
//0..1 -> 0..width
this.unNormalizeFromPOTtoRectMode(newTexImage, this.getVerticesLocal());
this.getGeometryInfo().setTextureCoordsNormalized(false);
}else{
//0..oldWidth -> 0..newWidth GLTexture is NPOT but this component's texture coords have seemingly already been un-normalized
//FIXME dont do it if it has the same dimensions!
this.fromRectModeToRectMode(newTexImage, this.getVerticesLocal(), this.lastTextureDimension.x, this.lastTextureDimension.y);
}
}else{
//GLTexture is POT -> normalize tex coords if neccessary
this.setTextureMode(PConstants.NORMALIZED);
if (this.getGeometryInfo().isTextureCoordsNormalized()){
//0..1 -> 0..1
}else{
//0..width -> 0..1
this.normalizeFromRectMode(newTexImage, this.getVerticesLocal(), this.lastTextureDimension.x, this.lastTextureDimension.y);
this.getGeometryInfo().setTextureCoordsNormalized(true);
}
}
this.textureImage = newTexImage;
//FIXME always save last tex dimensions? also if POT?
this.lastTextureDimension.setXYZ(newTexImage.width, newTexImage.height, 0);
}else{
//We are in OpenGL mode but the new texture is not a GLTexture -> create new GLTexture from PImage
boolean isPOT = Tools3D.isPowerOfTwoDimension(newTexImage);
GLTextureSettings ts = new GLTextureSettings();
if (!isPOT){
ts.target = TEXTURE_TARGET.RECTANGULAR;
this.setTextureMode(PConstants.IMAGE);
if (this.getGeometryInfo().isTextureCoordsNormalized()){
//0..1 -> 0..newWidth
this.unNormalizeFromPOTtoRectMode(newTexImage, this.getVerticesLocal());
this.getGeometryInfo().setTextureCoordsNormalized(false);
}else{
//0..oldWidth -> 0..newWidth
//FIXME dont do it if it has the same dimensions!
this.fromRectModeToRectMode(newTexImage, this.getVerticesLocal(), this.lastTextureDimension.x, this.lastTextureDimension.y);
}
this.textureImage = newTexImage;
this.lastTextureDimension.setXYZ(newTexImage.width, newTexImage.height, 0);
}else{
ts.target = TEXTURE_TARGET.TEXTURE_2D;
this.setTextureMode(PConstants.NORMALIZED);
//We are in OpenGL mode, new texture is a PImage, is POT -> create POT GLTexture and un-normalize tex coords if neccessary
if (this.getGeometryInfo().isTextureCoordsNormalized()){
//0..1 -> 0..1
}else{
//normalize 0..width -> 0..1
this.normalizeFromRectMode(newTexImage, this.getVerticesLocal(), this.lastTextureDimension.x, this.lastTextureDimension.y);
this.getGeometryInfo().setTextureCoordsNormalized(true);
}
}
//Create new GLTexture from PImage
ts.shrinkFilter = SHRINKAGE_FILTER.BilinearNoMipMaps;
ts.expansionFilter = EXPANSION_FILTER.Bilinear;
ts.wrappingHorizontal = WRAP_MODE.CLAMP_TO_EDGE;
ts.wrappingVertical = WRAP_MODE.CLAMP_TO_EDGE;
GLTexture newGLTexture = new GLTexture(this.getRenderer(), newTexImage, ts);
// newGLTexture.format = newTexImage.format; //FIXME REMOVE?
this.textureImage = newGLTexture;
this.lastTextureDimension.setXYZ(newTexImage.width, newTexImage.height, 0);
}