import com.threed.jpct.*; import java.util.*; import java.awt.*; import java.awt.image.*; /** * a simple area based mip mapper implementation for the software renderer. * i.e: mip map level per polygon is decided according to ratio: * area of polygon on screen / area of polygon on texture * * Note: This class shouldn't be used when the hardware renderer is being used (use Config.mipmap instead). * * @author r a f t (area based algorithm, multi object support) * @author EgonOlsen (initial version, back ported to Java 1.1) */ public class MipMapper { /** the number of mipmap levels */ public static final int LEVELS=6; // enough for mip mapping a 256x256 texture to 8x8 /** the minimum mipmap size (lower isn't possible because of a jPCT limitation, higher is) */ public static final int MIN_SIZE=8; /** original texture will be used dwon to this ratio (polygon area / texture area) */ public static final float FIRST_LEVEL=1/2f; /** debug switch for showing colored mip maps */ public static boolean colorMipmaps=false; private TextureManager tm=TextureManager.getInstance(); private int[] visListData=new int[2]; private ObjectData[] changedObjects=new ObjectData[8]; private BitSet processedTextures=new BitSet(256); private Hashtable mipMappedObjs=new Hashtable(); private Hashtable textureIds=new Hashtable(); private Vector createdTextures=new Vector(); private int lastObjCnt=0; public MipMapper() {} /** adds the object to mipmap list */ public void addObject(Object3D object3d) { mipMappedObjs.put(new Integer(object3d.getID()), new ObjectData(object3d)); } /** removes the object from mipmap list */ public void removeObject(int id) { mipMappedObjs.remove(new Integer(id)); } /** creates mipmap textures if they arent already created */ private void createMipMaps(Object3D object3d) { PolygonManager pm=object3d.getPolygonManager(); for (int polygonId=0; polygonIdchangedObjects.length) { changedObjects=new ObjectData[mipMappedObjs.size()]; // resize on demand } VisList vl=world.getVisibilityList(); int size=vl.getSize(); int lastObjectId=-1; ObjectData objectData=null; lastObjCnt=0; SimpleVector[] v=new SimpleVector[3]; Camera camera=world.getCamera(); for (int i=0; iFIRST_LEVEL; ratio*=4f; } int targetTex=objectData.orgTex[polygonId][offset]; if (targetTex!=objectData.curTex[polygonId]) { if (!objectData.isChanged()) { objectData.setChanged(true); changedObjects[lastObjCnt]=objectData; lastObjCnt++; } objectData.curTex[polygonId]=targetTex; objectData.pm.setPolygonTexture(polygonId, targetTex); } } } } for (int i=0; i