package com.wurmonline.client; import java.util.*; import net.java.games.jogl.GLCapabilities; import net.java.games.jogl.GLCapabilitiesChooser; public class ScoreCapabilitiesChooser implements GLCapabilitiesChooser, Comparator { public int requiredAccumAlphaBits = 0; public int requiredAccumBlueBits = 0; public int requiredAccumGreenBits = 0; public int requiredAccumRedBits = 0; public int requiredAlphaBits = 0; public int requiredBlueBits = 0; public int requiredDepthBits = 0; public boolean requiredDoubleBuffered = false; public int requiredGreenBits = 0; public boolean requiredHardwareAccelerated = false; public int requiredNumSamples = 0; public boolean requiredOffscreenFloatingPointBuffers = false; public boolean requiredOffscreenRenderToTexture = false; public boolean requiredOffscreenRenderToTextureRectangle = false; public int requiredRedBits = 0; public boolean requiredSampleBuffers = false; public int requiredStencilBits = 0; public boolean requiredStereo = false; public float accumAlphaBitsScore = 0; public float accumBlueBitsScore = 0; public float accumGreenBitsScore = 0; public float accumRedBitsScore = 0; public float alphaBitsScore = 0.1f; public float blueBitsScore = 1; public float depthBitsScore = 1; public float doubleBufferedScore = 500; public float greenBitsScore = 1; public float hardwareAcceleratedScore = 10000; public float numSamplesScore = 0; public float offscreenFloatingPointBuffersScore = 0; public float offscreenRenderToTextureScore = 0; public float offscreenRenderToTextureRectangleScore = 0; public float redBitsScore = 1; public float sampleBuffersScore = 100; public float stencilBitsScore = 0.4f; public float stereoScore = 0; private float bestScore; public boolean verbose = false; // public int chooseCapabilities(GLCapabilities min, GLCapabilities[] caps) public int chooseCapabilities(GLCapabilities min, GLCapabilities[] caps, int reccomended) { List unsortedCaps = new ArrayList(Arrays.asList(caps)); List sortedCaps = new ArrayList(Arrays.asList(caps)); Collections.sort(sortedCaps, this); int selection = unsortedCaps.indexOf(sortedCaps.get(0)); bestScore = getScore((GLCapabilities)sortedCaps.get(0)); if (verbose) { System.out.println("Highest score: "+getScore((GLCapabilities)sortedCaps.get(0))); System.out.println("Lowest score: "+getScore((GLCapabilities)sortedCaps.get(sortedCaps.size()-1))); System.out.println(); System.out.println("Selection: "+selection+", reccomended: "+reccomended); // System.out.println("Selection: "+selection); } // Return the index of the best capabilities. return selection; } public int compare(Object o1, Object o2) { GLCapabilities c1 = (GLCapabilities)o1; GLCapabilities c2 = (GLCapabilities)o2; float score1 = getScore(c1); float score2 = getScore(c2); if (score1 > score2) { return -1; } else if (score1 < score2) { return 1; } else { return 0; } } private float getScore(GLCapabilities caps) { if (caps==null) return -9999999; int accumAlphaBits = caps.getAccumAlphaBits(); int accumBlueBits = caps.getAccumBlueBits(); int accumGreenBits = caps.getAccumGreenBits(); int accumRedBits = caps.getAccumRedBits(); int alphaBits = caps.getAlphaBits(); int blueBits = caps.getBlueBits(); int depthBits = caps.getDepthBits(); boolean doubleBuffered = caps.getDoubleBuffered(); int greenBits = caps.getGreenBits(); boolean hardwareAccelerated = caps.getHardwareAccelerated(); int numSamples = caps.getNumSamples(); boolean offscreenFloatingPointBuffers = caps.getOffscreenFloatingPointBuffers(); boolean offscreenRenderToTexture = caps.getOffscreenRenderToTexture(); boolean offscreenRenderToTextureRectangle = caps.getOffscreenRenderToTextureRectangle(); int redBits = caps.getRedBits(); boolean sampleBuffers = caps.getSampleBuffers(); int stencilBits = caps.getStencilBits(); boolean stereo = caps.getStereo(); // Reject (ie set as very low score) if it fails any requirements if (accumAlphaBits