package jp.gauzau.MikuMikuDroidmod;

import java.util.ArrayList;

import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView;

import com.example.gdc11.MultisampleConfigChooser;

public class MMGLSurfaceView extends GLSurfaceView {

	private MikuRendererBase mMikuRendarer;
	
	private static final boolean kUseMultisampling = true;
    private int mSamples = 2;

    // If |kUseMultisampling| is set, this is what chose the multisampling config.
    private MultisampleConfigChooser mConfigChooser;

	public MMGLSurfaceView(Context context, CoreLogic cl) {
		super(context);
		setRendar(context, cl);
	}

	public void setRendar(Context ctx, CoreLogic cl) {
		if (detectOpenGLES20(ctx)) {
			setEGLContextClientVersion(2);
			boolean usesCoverageAa = false;
			if (kUseMultisampling && 1 < mSamples) {
			    setEGLConfigChooser(mConfigChooser = new MultisampleConfigChooser(mSamples));
			    usesCoverageAa = mConfigChooser.usesCoverageAa();
			}
			mMikuRendarer = new MikuRendererGLES20(cl, usesCoverageAa);
			//mMikuRendarer = new MikuRenderer(cl);
		} else {
			mMikuRendarer = new MikuRenderer(cl);
		}
//		setEGLConfigChooser(5, 6, 5, 0, 24, 0);
		setRenderer(mMikuRendarer);			
	}

	private boolean detectOpenGLES20(Context ctx) {
		ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
		ConfigurationInfo info = am.getDeviceConfigurationInfo();
		return (info.reqGlEsVersion >= 0x20000);
	}

	public void deleteTextures(final ArrayList<MikuModel> mm) {
		queueEvent(new Runnable() {
			@Override
			public void run() {
				for(MikuModel m: mm) {
					mMikuRendarer.deleteTexture(m);
				}
			}
		});
	}

	public void deleteTexture(final String tex) {
		queueEvent(new Runnable() {
			@Override
			public void run() {
				mMikuRendarer.deleteTexture(tex);
			}
		});
	}

}

@@ -216,16 +216,62 @@
 ceView;%0D
+%0Aimport android.preference.PreferenceManager;%0D
 %0A%0D%0Aimpor
@@ -421,183 +421,8 @@
 r;%0D%0A
-%09%0D%0A%09private static final boolean kUseMultisampling = true;%0D%0A    private int mSamples = 2;%0D%0A%0D%0A    // If %7CkUseMultisampling%7C is set, this is what chose the multisampling config.
 %0D%0A  
@@ -745,42 +745,235 @@
 e;%0D%0A
-%09%09%09if (kUseMultisampling && 
+            int samples = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(%0D%0A                    ctx).getString(%0D%0A                    ctx.getResources().getString(R.string.pref_key_antialias), %220%22));%0D%0A%09%09%09if (
 1 %3C 
-mS
+s
 ampl
@@ -1052,18 +1052,17 @@
 Chooser(
-mS
+s
 amples))

Apply antialias level in Renderer