// Path: smartgl/src/main/java/fr/arnaudguyon/smartgl/tools/Assert.java
// public class Assert {
// 
//     public static void assertTrue(boolean condition) {
//         assertTrue("", condition);
//     }
//     public static void assertTrue(String text, boolean condition) {
//         if (!condition) {
//             doAssert(text);
//         }
//     }
//     public static void assertNotNull(Object object) {
//         assertNotNull("", object);
//     }
//     public static void assertNotNull(String text, Object object) {
//         if (object == null) {
//             doAssert(text);
//         }
//     }
// 
//     public static void assertEquals(Object object1, Object object2) {
//         if (object1 == null) {
//             if (object2 != null) {
//                 doAssert("");
//             }
//         } else {
//             if (object2 == null) {
//                 doAssert("");
//             } else {
//                 if (!object1.equals(object2)) {
//                     doAssert("");
//                 }
//             }
//         }
//     }
// 
//     private static void doAssert(String text) {
//         throw new RuntimeException(text);
//     }
// }


import android.opengl.GLES20;
import android.util.Log;
import fr.arnaudguyon.smartgl.tools.Assert;

	private int loadShader(int shaderType, String script) {

		int shader = GLES20.glCreateShader(shaderType);
		Assert.assertTrue(shader != 0);

		GLES20.glShaderSource(shader, script);
		GLES20.glCompileShader(shader);
		int[] compiled = new int[1];
		GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
		if (compiled[0] == 0) {
			Log.e(TAG, "Could not compile shader " + shaderType + " : " + GLES20.glGetShaderInfoLog(shader));
			GLES20.glDeleteShader(shader);
			shader = 0;
			Assert.assertTrue(false);
		}
		return shader;
	}

	protected void init(final int programId) {
		
		final String vertexAttribName = getVertexAttribName();
		final String uvAttribName = getUVAttribName();
		final String colorAttribName = getColorAttribName();
		final String projMatrixAttribName = getProjMatrixAttribName();

		mVertexAttribId = (vertexAttribName != null) ? GLES20.glGetAttribLocation(programId, vertexAttribName) : -1;
		mUVAttribId = (uvAttribName != null) ? GLES20.glGetAttribLocation(programId, uvAttribName) : -1;
		mColorAttribId = (colorAttribName != null) ? GLES20.glGetAttribLocation(programId, colorAttribName) : -1;
		mProjMatrixId = (projMatrixAttribName != null) ? GLES20.glGetUniformLocation(programId, projMatrixAttribName) : -1;
		Assert.assertTrue(mVertexAttribId >= 0);

// Path: smartgl/src/main/java/fr/arnaudguyon/smartgl/tools/Assert.java
// public class Assert {
// 
//     public static void assertTrue(boolean condition) {
//         assertTrue("", condition);
//     }
//     public static void assertTrue(String text, boolean condition) {
//         if (!condition) {
//             doAssert(text);
//         }
//     }
//     public static void assertNotNull(Object object) {
//         assertNotNull("", object);
//     }
//     public static void assertNotNull(String text, Object object) {
//         if (object == null) {
//             doAssert(text);
//         }
//     }
// 
//     public static void assertEquals(Object object1, Object object2) {
//         if (object1 == null) {
//             if (object2 != null) {
//                 doAssert("");
//             }
//         } else {
//             if (object2 == null) {
//                 doAssert("");
//             } else {
//                 if (!object1.equals(object2)) {
//                     doAssert("");
//                 }
//             }
//         }
//     }
// 
//     private static void doAssert(String text) {
//         throw new RuntimeException(text);
//     }
// }


// Path: smartgl/src/main/java/fr/arnaudguyon/smartgl/opengl/Shader.java
import android.opengl.GLES20;
import android.util.Log;
import fr.arnaudguyon.smartgl.tools.Assert;

	private int loadShader(int shaderType, String script) {

		int shader = GLES20.glCreateShader(shaderType);
		Assert.assertTrue(shader != 0);

		GLES20.glShaderSource(shader, script);
		GLES20.glCompileShader(shader);
		int[] compiled = new int[1];
		GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
		if (compiled[0] == 0) {
			Log.e(TAG, "Could not compile shader " + shaderType + " : " + GLES20.glGetShaderInfoLog(shader));
			GLES20.glDeleteShader(shader);
			shader = 0;
			Assert.assertTrue(false);
		}
		return shader;
	}

	protected void init(final int programId) {
		
		final String vertexAttribName = getVertexAttribName();
		final String uvAttribName = getUVAttribName();
		final String colorAttribName = getColorAttribName();
		final String projMatrixAttribName = getProjMatrixAttribName();

		mVertexAttribId = (vertexAttribName != null) ? GLES20.glGetAttribLocation(programId, vertexAttribName) : -1;
		mUVAttribId = (uvAttribName != null) ? GLES20.glGetAttribLocation(programId, uvAttribName) : -1;
		mColorAttribId = (colorAttribName != null) ? GLES20.glGetAttribLocation(programId, colorAttribName) : -1;
		mProjMatrixId = (projMatrixAttribName != null) ? GLES20.glGetUniformLocation(programId, projMatrixAttribName) : -1;
		Assert.assertTrue(mVertexAttribId >= 0);

		Assert.assertTrue((mUVAttribId >= 0) || !useTexture());
