i have created a class named MipMapData to keep info about mipmaps, it keeps dimensions, datasize, and the imageformat. From another part of the code i create an array of that MipMapData objects, the problem is that each time i add a new MipMapData object into the array all the mimpamp info objects into the array gets their dimension field modified, and when i populate all the array the result is that all the objects has the same value in their dimension field as the last value added into the array. What i am doing wrong with the dimensions field?
import java.awt.Dimension;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
public class MipMapData {
private Dimension dimension;
private Long dataSize;
private Image.Format format;
//Constructor calculates size. Has this arguments to avoid the existence of mipmap incomplete data or with errors in datasize
public MipMapData(Image.Format format, Dimension dimension){
this.format=format;
setDimension(dimension);
}
public Dimension getDimension() {
return dimension;
}
public void setDimension(Dimension dimension) {
this.dimension = dimension;
if(format==Format.DXT5||format==Format.DXT3){
this.dataSize=(long) (dimension.height*dimension.width);
if(this.dataSize<16)
this.dataSize=(long) 16;
return;
}
else if(format==Format.DXT1){
this.dataSize=(long)((dimension.height*dimension.width)/2);
if(this.dataSize<8)
this.dataSize=(long) 8;
return;
}
else if(format==Format.ABGR8){
this.dataSize=(long)(dimension.height*dimension.width*4);
return;
}
else if(format==Format.Luminance8||format==Format.Depth){
this.dataSize=(long)(dimension.height*dimension.width);
return;
}
}
public Long getDataSize() {
return dataSize;
}
//The datasize of each mipmap is automatically calculated in the constructor
static MipMapData[] createMipMapDataArray(Dimension textureDimensions, int numberOfMipMaps, Image.Format imageFormat){
int width=textureDimensions.width;
int height=textureDimensions.height;
Dimension mipMapDimension= new Dimension();
MipMapData[] mipMapDataArray= new MipMapData[11];
if(imageFormat==Format.DXT5|| imageFormat==Format.DXT3){
for(int i=0;i<=10;i++){
if((width)<1)
width=1;
if((height)<1)
height=1;
mipMapDimension.height=height;
mipMapDimension.width=width;
mipMapDataArray[i]= new MipMapData(imageFormat,mipMapDimension);
//actualize dimensions for next mipmap
width/=2;
height/=2;
}
}
else if(imageFormat==Format.DXT1){
for(int i=0;i<=10;i++){
if((width)<1)
width=1;
if((height)<1)
height=1;
mipMapDimension.height=height;
mipMapDimension.width=width;
mipMapDataArray[i]= new MipMapData(imageFormat,mipMapDimension);
//actualize dimensions for next mipmap
width/=2;
height/=2;
}
}
else if(imageFormat==Format.ABGR8||imageFormat==Format.Luminance8||imageFormat==Format.Depth){
for(int i=0; i<=10;i++){
if((width)<1)
width=1;
if((height)<1)
height=1;
mipMapDimension.height=height;
mipMapDimension.width=width;
mipMapDataArray[i]= new MipMapData(imageFormat,mipMapDimension);
//actualize dimensions for next mipmap
width/=2;
height/=2;
}
}
return mipMapDataArray;
}
}